Commit: ee6b989f8e2ae99c28441ab8663a99bfd16b6c65 Author: Brecht Van Lommel Date: Mon Oct 26 18:13:53 2020 +0100 Branches: master https://developer.blender.org/rBee6b989f8e2ae99c28441ab8663a99bfd16b6c65
Cycles: refactor to split surface and volume attribute lookup more This avoids OpenCL inlining heavy volume interpolation code once for every data type, which could cause a performance regression when we add a float4 data type in the next commit. Ref D2057 =================================================================== M intern/cycles/kernel/geom/geom_primitive.h M intern/cycles/kernel/geom/geom_volume.h M intern/cycles/kernel/osl/osl_services.cpp M intern/cycles/kernel/svm/svm_attribute.h M intern/cycles/kernel/svm/svm_vertex_color.h =================================================================== diff --git a/intern/cycles/kernel/geom/geom_primitive.h b/intern/cycles/kernel/geom/geom_primitive.h index 997abf438d0..2c31e5cee03 100644 --- a/intern/cycles/kernel/geom/geom_primitive.h +++ b/intern/cycles/kernel/geom/geom_primitive.h @@ -21,38 +21,11 @@ CCL_NAMESPACE_BEGIN -/* Generic primitive attribute reading functions */ -ccl_device_inline float primitive_attribute_float( - KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor desc, float *dx, float *dy) -{ - if (sd->type & PRIMITIVE_ALL_TRIANGLE) { - if (subd_triangle_patch(kg, sd) == ~0) - return triangle_attribute_float(kg, sd, desc, dx, dy); - else - return subd_triangle_attribute_float(kg, sd, desc, dx, dy); - } -#ifdef __HAIR__ - else if (sd->type & PRIMITIVE_ALL_CURVE) { - return curve_attribute_float(kg, sd, desc, dx, dy); - } -#endif -#ifdef __VOLUME__ - else if (sd->object != OBJECT_NONE && desc.element == ATTR_ELEMENT_VOXEL) { - if (dx) - *dx = 0.0f; - if (dy) - *dy = 0.0f; - return volume_attribute_float(kg, sd, desc); - } -#endif - else { - if (dx) - *dx = 0.0f; - if (dy) - *dy = 0.0f; - return 0.0f; - } -} +/* Surface Attributes + * + * Read geometry attributes for surface shading. This is distinct from volume + * attributes for performance, mainly for GPU performance to avoid bringing in + * heavy volume interpolation code. */ ccl_device_inline float primitive_surface_attribute_float( KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor desc, float *dx, float *dy) @@ -77,25 +50,11 @@ ccl_device_inline float primitive_surface_attribute_float( } } -#ifdef __VOLUME__ -ccl_device_inline float primitive_volume_attribute_float(KernelGlobals *kg, - const ShaderData *sd, - const AttributeDescriptor desc) -{ - if (sd->object != OBJECT_NONE && desc.element == ATTR_ELEMENT_VOXEL) { - return volume_attribute_float(kg, sd, desc); - } - else { - return 0.0f; - } -} -#endif - -ccl_device_inline float2 primitive_attribute_float2(KernelGlobals *kg, - const ShaderData *sd, - const AttributeDescriptor desc, - float2 *dx, - float2 *dy) +ccl_device_inline float2 primitive_surface_attribute_float2(KernelGlobals *kg, + const ShaderData *sd, + const AttributeDescriptor desc, + float2 *dx, + float2 *dy) { if (sd->type & PRIMITIVE_ALL_TRIANGLE) { if (subd_triangle_patch(kg, sd) == ~0) @@ -107,16 +66,6 @@ ccl_device_inline float2 primitive_attribute_float2(KernelGlobals *kg, else if (sd->type & PRIMITIVE_ALL_CURVE) { return curve_attribute_float2(kg, sd, desc, dx, dy); } -#endif -#ifdef __VOLUME__ - else if (sd->object != OBJECT_NONE && desc.element == ATTR_ELEMENT_VOXEL) { - kernel_assert(0); - if (dx) - *dx = make_float2(0.0f, 0.0f); - if (dy) - *dy = make_float2(0.0f, 0.0f); - return make_float2(0.0f, 0.0f); - } #endif else { if (dx) @@ -127,11 +76,11 @@ ccl_device_inline float2 primitive_attribute_float2(KernelGlobals *kg, } } -ccl_device_inline float3 primitive_attribute_float3(KernelGlobals *kg, - const ShaderData *sd, - const AttributeDescriptor desc, - float3 *dx, - float3 *dy) +ccl_device_inline float3 primitive_surface_attribute_float3(KernelGlobals *kg, + const ShaderData *sd, + const AttributeDescriptor desc, + float3 *dx, + float3 *dy) { if (sd->type & PRIMITIVE_ALL_TRIANGLE) { if (subd_triangle_patch(kg, sd) == ~0) @@ -143,15 +92,6 @@ ccl_device_inline float3 primitive_attribute_float3(KernelGlobals *kg, else if (sd->type & PRIMITIVE_ALL_CURVE) { return curve_attribute_float3(kg, sd, desc, dx, dy); } -#endif -#ifdef __VOLUME__ - else if (sd->object != OBJECT_NONE && desc.element == ATTR_ELEMENT_VOXEL) { - if (dx) - *dx = make_float3(0.0f, 0.0f, 0.0f); - if (dy) - *dy = make_float3(0.0f, 0.0f, 0.0f); - return volume_attribute_float3(kg, sd, desc); - } #endif else { if (dx) @@ -162,11 +102,11 @@ ccl_device_inline float3 primitive_attribute_float3(KernelGlobals *kg, } } -ccl_device_inline float4 primitive_attribute_float4(KernelGlobals *kg, - const ShaderData *sd, - const AttributeDescriptor desc, - float4 *dx, - float4 *dy) +ccl_device_inline float4 primitive_surface_attribute_float4(KernelGlobals *kg, + const ShaderData *sd, + const AttributeDescriptor desc, + float4 *dx, + float4 *dy) { if (sd->type & PRIMITIVE_ALL_TRIANGLE) { if (subd_triangle_patch(kg, sd) == ~0) @@ -188,68 +128,52 @@ ccl_device_inline float4 primitive_attribute_float4(KernelGlobals *kg, } } -ccl_device_inline float2 primitive_surface_attribute_float2(KernelGlobals *kg, - const ShaderData *sd, - const AttributeDescriptor desc, - float2 *dx, - float2 *dy) +#ifdef __VOLUME__ +/* Volume Attributes + * + * Read geometry attributes for volume shading. This is distinct from surface + * attributes for performance, mainly for GPU performance to avoid bringing in + * heavy volume interpolation code. */ + +ccl_device_inline bool primitive_is_volume_attribute(const ShaderData *sd, + const AttributeDescriptor desc) { - if (sd->type & PRIMITIVE_ALL_TRIANGLE) { - if (subd_triangle_patch(kg, sd) == ~0) - return triangle_attribute_float2(kg, sd, desc, dx, dy); - else - return subd_triangle_attribute_float2(kg, sd, desc, dx, dy); - } -#ifdef __HAIR__ - else if (sd->type & PRIMITIVE_ALL_CURVE) { - return curve_attribute_float2(kg, sd, desc, dx, dy); + return (sd->object != OBJECT_NONE && desc.element == ATTR_ELEMENT_VOXEL); +} + +ccl_device_inline float primitive_volume_attribute_float(KernelGlobals *kg, + const ShaderData *sd, + const AttributeDescriptor desc) +{ + if (primitive_is_volume_attribute(sd, desc)) { + return volume_attribute_value_to_float(volume_attribute_float4(kg, sd, desc)); } -#endif else { - if (dx) - *dx = make_float2(0.0f, 0.0f); - if (dy) - *dy = make_float2(0.0f, 0.0f); - return make_float2(0.0f, 0.0f); + return 0.0f; } } -ccl_device_inline float3 primitive_surface_attribute_float3(KernelGlobals *kg, - const ShaderData *sd, - const AttributeDescriptor desc, - float3 *dx, - float3 *dy) +ccl_device_inline float3 primitive_volume_attribute_float3(KernelGlobals *kg, + const ShaderData *sd, + const AttributeDescriptor desc) { - if (sd->type & PRIMITIVE_ALL_TRIANGLE) { - if (subd_triangle_patch(kg, sd) == ~0) - return triangle_attribute_float3(kg, sd, desc, dx, dy); - else - return subd_triangle_attribute_float3(kg, sd, desc, dx, dy); - } -#ifdef __HAIR__ - else if (sd->type & PRIMITIVE_ALL_CURVE) { - return curve_attribute_float3(kg, sd, desc, dx, dy); + if (primitive_is_volume_attribute(sd, desc)) { + return volume_attribute_value_to_float3(volume_attribute_float4(kg, sd, desc)); } -#endif else { - if (dx) - *dx = make_float3(0.0f, 0.0f, 0.0f); - if (dy) - *dy = make_float3(0.0f, 0.0f, 0.0f); return make_float3(0.0f, 0.0f, 0.0f); } } -#ifdef __VOLUME__ -ccl_device_inline float3 primitive_volume_attribute_float3(KernelGlobals *kg, +ccl_device_inline float4 primitive_volume_attribute_float4(KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor desc) { - if (sd->object != OBJECT_NONE && desc.element == ATTR_ELEMENT_VOXEL) { - return volume_attribute_float3(kg, sd, desc); + if (primitive_is_volume_attribute(sd, desc)) { + return volume_attribute_float4(kg, sd, desc); } else { - return make_float3(0.0f, 0.0f, 0.0f); + return make_float4(0.0f, 0.0f, 0.0f, 0.0f); } } #endif diff --git a/intern/cycles/kernel/geom/geom_volume.h b/intern/cycles/kernel/geom/geom_volume.h index f43a7841b46..13b027a5f6c 100644 --- a/intern/cycles/kernel/geom/geom_volume.h +++ b/intern/cycles/kernel/geom/geom_volume.h @@ -47,38 +47,39 @@ ccl_device_inline float3 volume_normalized_position(KernelGlobals *kg, return P; } -ccl_device float volume_attribute_float(KernelGlobals * @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs