diff options
author | Michael Jones <michael_p_jones@apple.com> | 2021-10-14 15:53:40 +0300 |
---|---|---|
committer | Michael Jones <michael_p_jones@apple.com> | 2021-10-14 18:14:43 +0300 |
commit | a0f269f682dab848afc80cd322d04a0c4a815cae (patch) | |
tree | 0978b1888273fbaa2d14550bde484c5247fa89ff /intern/cycles/kernel/geom/geom_object.h | |
parent | 47caeb8c26686e24ea7e694f94fabee44f3d2dca (diff) |
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
Diffstat (limited to 'intern/cycles/kernel/geom/geom_object.h')
-rw-r--r-- | intern/cycles/kernel/geom/geom_object.h | 185 |
1 files changed, 98 insertions, 87 deletions
diff --git a/intern/cycles/kernel/geom/geom_object.h b/intern/cycles/kernel/geom/geom_object.h index 7d6ad7b4fe3..730c01d4709 100644 --- a/intern/cycles/kernel/geom/geom_object.h +++ b/intern/cycles/kernel/geom/geom_object.h @@ -37,7 +37,7 @@ enum ObjectVectorTransform { OBJECT_PASS_MOTION_PRE = 0, OBJECT_PASS_MOTION_POST /* Object to world space transformation */ -ccl_device_inline Transform object_fetch_transform(const KernelGlobals *kg, +ccl_device_inline Transform object_fetch_transform(ccl_global const KernelGlobals *kg, int object, enum ObjectTransform type) { @@ -51,7 +51,9 @@ ccl_device_inline Transform object_fetch_transform(const KernelGlobals *kg, /* Lamp to world space transformation */ -ccl_device_inline Transform lamp_fetch_transform(const KernelGlobals *kg, int lamp, bool inverse) +ccl_device_inline Transform lamp_fetch_transform(ccl_global const KernelGlobals *kg, + int lamp, + bool inverse) { if (inverse) { return kernel_tex_fetch(__lights, lamp).itfm; @@ -63,7 +65,7 @@ ccl_device_inline Transform lamp_fetch_transform(const KernelGlobals *kg, int la /* Object to world space transformation for motion vectors */ -ccl_device_inline Transform object_fetch_motion_pass_transform(const KernelGlobals *kg, +ccl_device_inline Transform object_fetch_motion_pass_transform(ccl_global const KernelGlobals *kg, int object, enum ObjectVectorTransform type) { @@ -74,12 +76,12 @@ ccl_device_inline Transform object_fetch_motion_pass_transform(const KernelGloba /* Motion blurred object transformations */ #ifdef __OBJECT_MOTION__ -ccl_device_inline Transform object_fetch_transform_motion(const KernelGlobals *kg, +ccl_device_inline Transform object_fetch_transform_motion(ccl_global const KernelGlobals *kg, int object, float time) { const uint motion_offset = kernel_tex_fetch(__objects, object).motion_offset; - const ccl_global DecomposedTransform *motion = &kernel_tex_fetch(__object_motion, motion_offset); + ccl_global const DecomposedTransform *motion = &kernel_tex_fetch(__object_motion, motion_offset); const uint num_steps = kernel_tex_fetch(__objects, object).numsteps * 2 + 1; Transform tfm; @@ -88,10 +90,10 @@ ccl_device_inline Transform object_fetch_transform_motion(const KernelGlobals *k return tfm; } -ccl_device_inline Transform object_fetch_transform_motion_test(const KernelGlobals *kg, +ccl_device_inline Transform object_fetch_transform_motion_test(ccl_global const KernelGlobals *kg, int object, float time, - Transform *itfm) + ccl_private Transform *itfm) { int object_flag = kernel_tex_fetch(__object_flag, object); if (object_flag & SD_OBJECT_MOTION) { @@ -115,7 +117,8 @@ ccl_device_inline Transform object_fetch_transform_motion_test(const KernelGloba /* Get transform matrix for shading point. */ -ccl_device_inline Transform object_get_transform(const KernelGlobals *kg, const ShaderData *sd) +ccl_device_inline Transform object_get_transform(ccl_global const KernelGlobals *kg, + ccl_private const ShaderData *sd) { #ifdef __OBJECT_MOTION__ return (sd->object_flag & SD_OBJECT_MOTION) ? @@ -126,8 +129,8 @@ ccl_device_inline Transform object_get_transform(const KernelGlobals *kg, const #endif } -ccl_device_inline Transform object_get_inverse_transform(const KernelGlobals *kg, - const ShaderData *sd) +ccl_device_inline Transform object_get_inverse_transform(ccl_global const KernelGlobals *kg, + ccl_private const ShaderData *sd) { #ifdef __OBJECT_MOTION__ return (sd->object_flag & SD_OBJECT_MOTION) ? @@ -139,9 +142,9 @@ ccl_device_inline Transform object_get_inverse_transform(const KernelGlobals *kg } /* Transform position from object to world space */ -ccl_device_inline void object_position_transform(const KernelGlobals *kg, - const ShaderData *sd, - float3 *P) +ccl_device_inline void object_position_transform(ccl_global const KernelGlobals *kg, + ccl_private const ShaderData *sd, + ccl_private float3 *P) { #ifdef __OBJECT_MOTION__ if (sd->object_flag & SD_OBJECT_MOTION) { @@ -156,9 +159,9 @@ ccl_device_inline void object_position_transform(const KernelGlobals *kg, /* Transform position from world to object space */ -ccl_device_inline void object_inverse_position_transform(const KernelGlobals *kg, - const ShaderData *sd, - float3 *P) +ccl_device_inline void object_inverse_position_transform(ccl_global const KernelGlobals *kg, + ccl_private const ShaderData *sd, + ccl_private float3 *P) { #ifdef __OBJECT_MOTION__ if (sd->object_flag & SD_OBJECT_MOTION) { @@ -173,9 +176,9 @@ ccl_device_inline void object_inverse_position_transform(const KernelGlobals *kg /* Transform normal from world to object space */ -ccl_device_inline void object_inverse_normal_transform(const KernelGlobals *kg, - const ShaderData *sd, - float3 *N) +ccl_device_inline void object_inverse_normal_transform(ccl_global const KernelGlobals *kg, + ccl_private const ShaderData *sd, + ccl_private float3 *N) { #ifdef __OBJECT_MOTION__ if (sd->object_flag & SD_OBJECT_MOTION) { @@ -198,9 +201,9 @@ ccl_device_inline void object_inverse_normal_transform(const KernelGlobals *kg, /* Transform normal from object to world space */ -ccl_device_inline void object_normal_transform(const KernelGlobals *kg, - const ShaderData *sd, - float3 *N) +ccl_device_inline void object_normal_transform(ccl_global const KernelGlobals *kg, + ccl_private const ShaderData *sd, + ccl_private float3 *N) { #ifdef __OBJECT_MOTION__ if (sd->object_flag & SD_OBJECT_MOTION) { @@ -215,9 +218,9 @@ ccl_device_inline void object_normal_transform(const KernelGlobals *kg, /* Transform direction vector from object to world space */ -ccl_device_inline void object_dir_transform(const KernelGlobals *kg, - const ShaderData *sd, - float3 *D) +ccl_device_inline void object_dir_transform(ccl_global const KernelGlobals *kg, + ccl_private const ShaderData *sd, + ccl_private float3 *D) { #ifdef __OBJECT_MOTION__ if (sd->object_flag & SD_OBJECT_MOTION) { @@ -232,9 +235,9 @@ ccl_device_inline void object_dir_transform(const KernelGlobals *kg, /* Transform direction vector from world to object space */ -ccl_device_inline void object_inverse_dir_transform(const KernelGlobals *kg, - const ShaderData *sd, - float3 *D) +ccl_device_inline void object_inverse_dir_transform(ccl_global const KernelGlobals *kg, + ccl_private const ShaderData *sd, + ccl_private float3 *D) { #ifdef __OBJECT_MOTION__ if (sd->object_flag & SD_OBJECT_MOTION) { @@ -249,7 +252,8 @@ ccl_device_inline void object_inverse_dir_transform(const KernelGlobals *kg, /* Object center position */ -ccl_device_inline float3 object_location(const KernelGlobals *kg, const ShaderData *sd) +ccl_device_inline float3 object_location(ccl_global const KernelGlobals *kg, + ccl_private const ShaderData *sd) { if (sd->object == OBJECT_NONE) return make_float3(0.0f, 0.0f, 0.0f); @@ -266,18 +270,18 @@ ccl_device_inline float3 object_location(const KernelGlobals *kg, const ShaderDa /* Color of the object */ -ccl_device_inline float3 object_color(const KernelGlobals *kg, int object) +ccl_device_inline float3 object_color(ccl_global const KernelGlobals *kg, int object) { if (object == OBJECT_NONE) return make_float3(0.0f, 0.0f, 0.0f); - const ccl_global KernelObject *kobject = &kernel_tex_fetch(__objects, object); + ccl_global const KernelObject *kobject = &kernel_tex_fetch(__objects, object); return make_float3(kobject->color[0], kobject->color[1], kobject->color[2]); } /* Pass ID number of object */ -ccl_device_inline float object_pass_id(const KernelGlobals *kg, int object) +ccl_device_inline float object_pass_id(ccl_global const KernelGlobals *kg, int object) { if (object == OBJECT_NONE) return 0.0f; @@ -287,7 +291,7 @@ ccl_device_inline float object_pass_id(const KernelGlobals *kg, int object) /* Per lamp random number for shader variation */ -ccl_device_inline float lamp_random_number(const KernelGlobals *kg, int lamp) +ccl_device_inline float lamp_random_number(ccl_global const KernelGlobals *kg, int lamp) { if (lamp == LAMP_NONE) return 0.0f; @@ -297,7 +301,7 @@ ccl_device_inline float lamp_random_number(const KernelGlobals *kg, int lamp) /* Per object random number for shader variation */ -ccl_device_inline float object_random_number(const KernelGlobals *kg, int object) +ccl_device_inline float object_random_number(ccl_global const KernelGlobals *kg, int object) { if (object == OBJECT_NONE) return 0.0f; @@ -307,7 +311,7 @@ ccl_device_inline float object_random_number(const KernelGlobals *kg, int object /* Particle ID from which this object was generated */ -ccl_device_inline int object_particle_id(const KernelGlobals *kg, int object) +ccl_device_inline int object_particle_id(ccl_global const KernelGlobals *kg, int object) { if (object == OBJECT_NONE) return 0; @@ -317,31 +321,34 @@ ccl_device_inline int object_particle_id(const KernelGlobals *kg, int object) /* Generated texture coordinate on surface from where object was instanced */ -ccl_device_inline float3 object_dupli_generated(const KernelGlobals *kg, int object) +ccl_device_inline float3 object_dupli_generated(ccl_global const KernelGlobals *kg, int object) { if (object == OBJECT_NONE) return make_float3(0.0f, 0.0f, 0.0f); - const ccl_global KernelObject *kobject = &kernel_tex_fetch(__objects, object); + ccl_global const KernelObject *kobject = &kernel_tex_fetch(__objects, object); return make_float3( kobject->dupli_generated[0], kobject->dupli_generated[1], kobject->dupli_generated[2]); } /* UV texture coordinate on surface from where object was instanced */ -ccl_device_inline float3 object_dupli_uv(const KernelGlobals *kg, int object) +ccl_device_inline float3 object_dupli_uv(ccl_global const KernelGlobals *kg, int object) { if (object == OBJECT_NONE) return make_float3(0.0f, 0.0f, 0.0f); - const ccl_global KernelObject *kobject = &kernel_tex_fetch(__objects, object); + ccl_global const KernelObject *kobject = &kernel_tex_fetch(__objects, object); return make_float3(kobject->dupli_uv[0], kobject->dupli_uv[1], 0.0f); } /* Information about mesh for motion blurred triangles and curves */ -ccl_device_inline void object_motion_info( - const KernelGlobals *kg, int object, int *numsteps, int *numverts, int *numkeys) +ccl_device_inline void object_motion_info(ccl_global const KernelGlobals *kg, + int object, + ccl_private int *numsteps, + ccl_private int *numverts, + ccl_private int *numkeys) { if (numkeys) { *numkeys = kernel_tex_fetch(__objects, object).numkeys; @@ -355,7 +362,7 @@ ccl_device_inline void object_motion_info( /* Offset to an objects patch map */ -ccl_device_inline uint object_patch_map_offset(const KernelGlobals *kg, int object) +ccl_device_inline uint object_patch_map_offset(ccl_global const KernelGlobals *kg, int object) { if (object == OBJECT_NONE) return 0; @@ -365,7 +372,7 @@ ccl_device_inline uint object_patch_map_offset(const KernelGlobals *kg, int obje /* Volume step size */ -ccl_device_inline float object_volume_density(const KernelGlobals *kg, int object) +ccl_device_inline float object_volume_density(ccl_global const KernelGlobals *kg, int object) { if (object == OBJECT_NONE) { return 1.0f; @@ -374,7 +381,7 @@ ccl_device_inline float object_volume_density(const KernelGlobals *kg, int objec return kernel_tex_fetch(__objects, object).volume_density; } -ccl_device_inline float object_volume_step_size(const KernelGlobals *kg, int object) +ccl_device_inline float object_volume_step_size(ccl_global const KernelGlobals *kg, int object) { if (object == OBJECT_NONE) { return kernel_data.background.volume_step_size; @@ -385,14 +392,14 @@ ccl_device_inline float object_volume_step_size(const KernelGlobals *kg, int obj /* Pass ID for shader */ -ccl_device int shader_pass_id(const KernelGlobals *kg, const ShaderData *sd) +ccl_device int shader_pass_id(ccl_global const KernelGlobals *kg, ccl_private const ShaderData *sd) { return kernel_tex_fetch(__shaders, (sd->shader & SHADER_MASK)).pass_id; } /* Cryptomatte ID */ -ccl_device_inline float object_cryptomatte_id(const KernelGlobals *kg, int object) +ccl_device_inline float object_cryptomatte_id(ccl_global const KernelGlobals *kg, int object) { if (object == OBJECT_NONE) return 0.0f; @@ -400,7 +407,7 @@ ccl_device_inline float object_cryptomatte_id(const KernelGlobals *kg, int objec return kernel_tex_fetch(__objects, object).cryptomatte_object; } -ccl_device_inline float object_cryptomatte_asset_id(const KernelGlobals *kg, int object) +ccl_device_inline float object_cryptomatte_asset_id(ccl_global const KernelGlobals *kg, int object) { if (object == OBJECT_NONE) return 0; @@ -410,42 +417,42 @@ ccl_device_inline float object_cryptomatte_asset_id(const KernelGlobals *kg, int /* Particle data from which object was instanced */ -ccl_device_inline uint particle_index(const KernelGlobals *kg, int particle) +ccl_device_inline uint particle_index(ccl_global const KernelGlobals *kg, int particle) { return kernel_tex_fetch(__particles, particle).index; } -ccl_device float particle_age(const KernelGlobals *kg, int particle) +ccl_device float particle_age(ccl_global const KernelGlobals *kg, int particle) { return kernel_tex_fetch(__particles, particle).age; } -ccl_device float particle_lifetime(const KernelGlobals *kg, int particle) +ccl_device float particle_lifetime(ccl_global const KernelGlobals *kg, int particle) { return kernel_tex_fetch(__particles, particle).lifetime; } -ccl_device float particle_size(const KernelGlobals *kg, int particle) +ccl_device float particle_size(ccl_global const KernelGlobals *kg, int particle) { return kernel_tex_fetch(__particles, particle).size; } -ccl_device float4 particle_rotation(const KernelGlobals *kg, int particle) +ccl_device float4 particle_rotation(ccl_global const KernelGlobals *kg, int particle) { return kernel_tex_fetch(__particles, particle).rotation; } -ccl_device float3 particle_location(const KernelGlobals *kg, int particle) +ccl_device float3 particle_location(ccl_global const KernelGlobals *kg, int particle) { return float4_to_float3(kernel_tex_fetch(__particles, particle).location); } -ccl_device float3 particle_velocity(const KernelGlobals *kg, int particle) +ccl_device float3 particle_velocity(ccl_global const KernelGlobals *kg, int particle) { return float4_to_float3(kernel_tex_fetch(__particles, particle).velocity); } -ccl_device float3 particle_angular_velocity(const KernelGlobals *kg, int particle) +ccl_device float3 particle_angular_velocity(ccl_global const KernelGlobals *kg, int particle) { return float4_to_float3(kernel_tex_fetch(__particles, particle).angular_velocity); } @@ -467,8 +474,12 @@ ccl_device_inline float3 bvh_inverse_direction(float3 dir) /* Transform ray into object space to enter static object in BVH */ -ccl_device_inline float bvh_instance_push( - const KernelGlobals *kg, int object, const Ray *ray, float3 *P, float3 *dir, float3 *idir) +ccl_device_inline float bvh_instance_push(ccl_global const KernelGlobals *kg, + int object, + ccl_private const Ray *ray, + ccl_private float3 *P, + ccl_private float3 *dir, + ccl_private float3 *idir) { Transform tfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM); @@ -483,12 +494,12 @@ ccl_device_inline float bvh_instance_push( /* Transform ray to exit static object in BVH. */ -ccl_device_inline float bvh_instance_pop(const KernelGlobals *kg, +ccl_device_inline float bvh_instance_pop(ccl_global const KernelGlobals *kg, int object, - const Ray *ray, - float3 *P, - float3 *dir, - float3 *idir, + ccl_private const Ray *ray, + ccl_private float3 *P, + ccl_private float3 *dir, + ccl_private float3 *idir, float t) { if (t != FLT_MAX) { @@ -505,13 +516,13 @@ ccl_device_inline float bvh_instance_pop(const KernelGlobals *kg, /* Same as above, but returns scale factor to apply to multiple intersection distances */ -ccl_device_inline void bvh_instance_pop_factor(const KernelGlobals *kg, +ccl_device_inline void bvh_instance_pop_factor(ccl_global const KernelGlobals *kg, int object, - const Ray *ray, - float3 *P, - float3 *dir, - float3 *idir, - float *t_fac) + ccl_private const Ray *ray, + ccl_private float3 *P, + ccl_private float3 *dir, + ccl_private float3 *idir, + ccl_private float *t_fac) { Transform tfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM); *t_fac = 1.0f / len(transform_direction(&tfm, ray->D)); @@ -524,13 +535,13 @@ ccl_device_inline void bvh_instance_pop_factor(const KernelGlobals *kg, #ifdef __OBJECT_MOTION__ /* Transform ray into object space to enter motion blurred object in BVH */ -ccl_device_inline float bvh_instance_motion_push(const KernelGlobals *kg, +ccl_device_inline float bvh_instance_motion_push(ccl_global const KernelGlobals *kg, int object, - const Ray *ray, - float3 *P, - float3 *dir, - float3 *idir, - Transform *itfm) + ccl_private const Ray *ray, + ccl_private float3 *P, + ccl_private float3 *dir, + ccl_private float3 *idir, + ccl_private Transform *itfm) { object_fetch_transform_motion_test(kg, object, ray->time, itfm); @@ -545,14 +556,14 @@ ccl_device_inline float bvh_instance_motion_push(const KernelGlobals *kg, /* Transform ray to exit motion blurred object in BVH. */ -ccl_device_inline float bvh_instance_motion_pop(const KernelGlobals *kg, +ccl_device_inline float bvh_instance_motion_pop(ccl_global const KernelGlobals *kg, int object, - const Ray *ray, - float3 *P, - float3 *dir, - float3 *idir, + ccl_private const Ray *ray, + ccl_private float3 *P, + ccl_private float3 *dir, + ccl_private float3 *idir, float t, - Transform *itfm) + ccl_private Transform *itfm) { if (t != FLT_MAX) { t /= len(transform_direction(itfm, ray->D)); @@ -567,14 +578,14 @@ ccl_device_inline float bvh_instance_motion_pop(const KernelGlobals *kg, /* Same as above, but returns scale factor to apply to multiple intersection distances */ -ccl_device_inline void bvh_instance_motion_pop_factor(const KernelGlobals *kg, +ccl_device_inline void bvh_instance_motion_pop_factor(ccl_global const KernelGlobals *kg, int object, - const Ray *ray, - float3 *P, - float3 *dir, - float3 *idir, - float *t_fac, - Transform *itfm) + ccl_private const Ray *ray, + ccl_private float3 *P, + ccl_private float3 *dir, + ccl_private float3 *idir, + ccl_private float *t_fac, + ccl_private Transform *itfm) { *t_fac = 1.0f / len(transform_direction(itfm, ray->D)); *P = ray->P; |