[Bf-blender-cvs] [ef7c9e793ec] master: Cycles: Remove separate OSL attribute map and instead always use SVM attribute map

Patrick Mours noreply at git.blender.org
Fri Sep 9 15:36:06 CEST 2022


Commit: ef7c9e793ec5331ac694eec9336565bd2254c406
Author: Patrick Mours
Date:   Fri Sep 9 11:55:35 2022 +0200
Branches: master
https://developer.blender.org/rBef7c9e793ec5331ac694eec9336565bd2254c406

Cycles: Remove separate OSL attribute map and instead always use SVM attribute map

The SVM attribute map is always generated and uses a simple
linear search to lookup by an opaque ID, so can reuse that for OSL
as well and simply use the attribute name hash as ID instead of
generating a unique value separately. This works for both object
and geometry attributes since the SVM attribute map already
stores both. Simplifies code somewhat and reduces memory
usage slightly.

This patch was split from D15902.

Differential Revision: https://developer.blender.org/D15918

===================================================================

M	intern/cycles/kernel/geom/attribute.h
M	intern/cycles/kernel/geom/primitive.h
M	intern/cycles/kernel/geom/subd_triangle.h
M	intern/cycles/kernel/geom/volume.h
M	intern/cycles/kernel/osl/globals.h
M	intern/cycles/kernel/osl/services.cpp
M	intern/cycles/kernel/osl/shader.cpp
M	intern/cycles/kernel/osl/shader.h
M	intern/cycles/kernel/types.h
M	intern/cycles/scene/geometry.cpp
M	intern/cycles/scene/geometry.h
M	intern/cycles/scene/osl.cpp
M	intern/cycles/scene/osl.h
M	intern/cycles/scene/shader.cpp
M	intern/cycles/scene/shader.h

===================================================================

diff --git a/intern/cycles/kernel/geom/attribute.h b/intern/cycles/kernel/geom/attribute.h
index 31a9e39d528..3a0ee1b09d1 100644
--- a/intern/cycles/kernel/geom/attribute.h
+++ b/intern/cycles/kernel/geom/attribute.h
@@ -16,14 +16,14 @@ CCL_NAMESPACE_BEGIN
 
 /* Patch index for triangle, -1 if not subdivision triangle */
 
-ccl_device_inline uint subd_triangle_patch(KernelGlobals kg, ccl_private const ShaderData *sd)
+ccl_device_inline uint subd_triangle_patch(KernelGlobals kg, int prim)
 {
-  return (sd->prim != PRIM_NONE) ? kernel_data_fetch(tri_patch, sd->prim) : ~0;
+  return (prim != PRIM_NONE) ? kernel_data_fetch(tri_patch, prim) : ~0;
 }
 
-ccl_device_inline uint attribute_primitive_type(KernelGlobals kg, ccl_private const ShaderData *sd)
+ccl_device_inline uint attribute_primitive_type(KernelGlobals kg, int prim, int type)
 {
-  if ((sd->type & PRIMITIVE_TRIANGLE) && subd_triangle_patch(kg, sd) != ~0) {
+  if ((type & PRIMITIVE_TRIANGLE) && subd_triangle_patch(kg, prim) != ~0) {
     return ATTR_PRIM_SUBD;
   }
   else {
@@ -45,17 +45,16 @@ ccl_device_inline uint object_attribute_map_offset(KernelGlobals kg, int object)
   return kernel_data_fetch(objects, object).attribute_map_offset;
 }
 
-ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg,
-                                                     ccl_private const ShaderData *sd,
-                                                     uint id)
+ccl_device_inline AttributeDescriptor
+find_attribute(KernelGlobals kg, int object, int prim, int type, uint64_t id)
 {
-  if (sd->object == OBJECT_NONE) {
+  if (object == OBJECT_NONE) {
     return attribute_not_found();
   }
 
   /* for SVM, find attribute by unique id */
-  uint attr_offset = object_attribute_map_offset(kg, sd->object);
-  attr_offset += attribute_primitive_type(kg, sd);
+  uint attr_offset = object_attribute_map_offset(kg, object);
+  attr_offset += attribute_primitive_type(kg, prim, type);
   AttributeMap attr_map = kernel_data_fetch(attributes_map, attr_offset);
 
   while (attr_map.id != id) {
@@ -77,7 +76,7 @@ ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg,
   AttributeDescriptor desc;
   desc.element = (AttributeElement)attr_map.element;
 
-  if (sd->prim == PRIM_NONE && desc.element != ATTR_ELEMENT_MESH &&
+  if (prim == PRIM_NONE && desc.element != ATTR_ELEMENT_MESH &&
       desc.element != ATTR_ELEMENT_VOXEL && desc.element != ATTR_ELEMENT_OBJECT) {
     return attribute_not_found();
   }
@@ -91,11 +90,16 @@ ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg,
   return desc;
 }
 
+ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg,
+                                                     ccl_private const ShaderData *sd,
+                                                     uint64_t id)
+{
+  return find_attribute(kg, sd->object, sd->prim, sd->type, id);
+}
+
 /* Transform matrix attribute on meshes */
 
-ccl_device Transform primitive_attribute_matrix(KernelGlobals kg,
-                                                ccl_private const ShaderData *sd,
-                                                const AttributeDescriptor desc)
+ccl_device Transform primitive_attribute_matrix(KernelGlobals kg, const AttributeDescriptor desc)
 {
   Transform tfm;
 
diff --git a/intern/cycles/kernel/geom/primitive.h b/intern/cycles/kernel/geom/primitive.h
index 0f1a3fc11bc..04b04ff5985 100644
--- a/intern/cycles/kernel/geom/primitive.h
+++ b/intern/cycles/kernel/geom/primitive.h
@@ -25,7 +25,7 @@ ccl_device_forceinline float primitive_surface_attribute_float(KernelGlobals kg,
                                                                ccl_private float *dy)
 {
   if (sd->type & PRIMITIVE_TRIANGLE) {
-    if (subd_triangle_patch(kg, sd) == ~0)
+    if (subd_triangle_patch(kg, sd->prim) == ~0)
       return triangle_attribute_float(kg, sd, desc, dx, dy);
     else
       return subd_triangle_attribute_float(kg, sd, desc, dx, dy);
@@ -56,7 +56,7 @@ ccl_device_forceinline float2 primitive_surface_attribute_float2(KernelGlobals k
                                                                  ccl_private float2 *dy)
 {
   if (sd->type & PRIMITIVE_TRIANGLE) {
-    if (subd_triangle_patch(kg, sd) == ~0)
+    if (subd_triangle_patch(kg, sd->prim) == ~0)
       return triangle_attribute_float2(kg, sd, desc, dx, dy);
     else
       return subd_triangle_attribute_float2(kg, sd, desc, dx, dy);
@@ -87,7 +87,7 @@ ccl_device_forceinline float3 primitive_surface_attribute_float3(KernelGlobals k
                                                                  ccl_private float3 *dy)
 {
   if (sd->type & PRIMITIVE_TRIANGLE) {
-    if (subd_triangle_patch(kg, sd) == ~0)
+    if (subd_triangle_patch(kg, sd->prim) == ~0)
       return triangle_attribute_float3(kg, sd, desc, dx, dy);
     else
       return subd_triangle_attribute_float3(kg, sd, desc, dx, dy);
@@ -118,7 +118,7 @@ ccl_device_forceinline float4 primitive_surface_attribute_float4(KernelGlobals k
                                                                  ccl_private float4 *dy)
 {
   if (sd->type & PRIMITIVE_TRIANGLE) {
-    if (subd_triangle_patch(kg, sd) == ~0)
+    if (subd_triangle_patch(kg, sd->prim) == ~0)
       return triangle_attribute_float4(kg, sd, desc, dx, dy);
     else
       return subd_triangle_attribute_float4(kg, sd, desc, dx, dy);
@@ -320,7 +320,7 @@ ccl_device_forceinline float4 primitive_motion_vector(KernelGlobals kg,
 #endif
         if (sd->type & PRIMITIVE_TRIANGLE) {
       /* Triangle */
-      if (subd_triangle_patch(kg, sd) == ~0) {
+      if (subd_triangle_patch(kg, sd->prim) == ~0) {
         motion_pre = triangle_attribute_float3(kg, sd, desc, NULL, NULL);
         desc.offset += numverts;
         motion_post = triangle_attribute_float3(kg, sd, desc, NULL, NULL);
diff --git a/intern/cycles/kernel/geom/subd_triangle.h b/intern/cycles/kernel/geom/subd_triangle.h
index c6f883461bd..784ba377318 100644
--- a/intern/cycles/kernel/geom/subd_triangle.h
+++ b/intern/cycles/kernel/geom/subd_triangle.h
@@ -87,7 +87,7 @@ ccl_device_noinline float subd_triangle_attribute_float(KernelGlobals kg,
                                                         ccl_private float *dx,
                                                         ccl_private float *dy)
 {
-  int patch = subd_triangle_patch(kg, sd);
+  int patch = subd_triangle_patch(kg, sd->prim);
 
 #ifdef __PATCH_EVAL__
   if (desc.flags & ATTR_SUBDIVIDED) {
@@ -226,7 +226,7 @@ ccl_device_noinline float2 subd_triangle_attribute_float2(KernelGlobals kg,
                                                           ccl_private float2 *dx,
                                                           ccl_private float2 *dy)
 {
-  int patch = subd_triangle_patch(kg, sd);
+  int patch = subd_triangle_patch(kg, sd->prim);
 
 #ifdef __PATCH_EVAL__
   if (desc.flags & ATTR_SUBDIVIDED) {
@@ -368,7 +368,7 @@ ccl_device_noinline float3 subd_triangle_attribute_float3(KernelGlobals kg,
                                                           ccl_private float3 *dx,
                                                           ccl_private float3 *dy)
 {
-  int patch = subd_triangle_patch(kg, sd);
+  int patch = subd_triangle_patch(kg, sd->prim);
 
 #ifdef __PATCH_EVAL__
   if (desc.flags & ATTR_SUBDIVIDED) {
@@ -509,7 +509,7 @@ ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals kg,
                                                           ccl_private float4 *dx,
                                                           ccl_private float4 *dy)
 {
-  int patch = subd_triangle_patch(kg, sd);
+  int patch = subd_triangle_patch(kg, sd->prim);
 
 #ifdef __PATCH_EVAL__
   if (desc.flags & ATTR_SUBDIVIDED) {
diff --git a/intern/cycles/kernel/geom/volume.h b/intern/cycles/kernel/geom/volume.h
index 3510a905def..885a420c97f 100644
--- a/intern/cycles/kernel/geom/volume.h
+++ b/intern/cycles/kernel/geom/volume.h
@@ -29,7 +29,7 @@ ccl_device_inline float3 volume_normalized_position(KernelGlobals kg,
   object_inverse_position_transform(kg, sd, &P);
 
   if (desc.offset != ATTR_STD_NOT_FOUND) {
-    Transform tfm = primitive_attribute_matrix(kg, sd, desc);
+    Transform tfm = primitive_attribute_matrix(kg, desc);
     P = transform_point(&tfm, P);
   }
 
diff --git a/intern/cycles/kernel/osl/globals.h b/intern/cycles/kernel/osl/globals.h
index 172091c55f5..496965a50ec 100644
--- a/intern/cycles/kernel/osl/globals.h
+++ b/intern/cycles/kernel/osl/globals.h
@@ -56,16 +56,8 @@ struct OSLGlobals {
   OSL::ShaderGroupRef background_state;
 
   /* attributes */
-  struct Attribute {
-    TypeDesc type;
-    AttributeDescriptor desc;
-    ParamValue value;
-  };
-
-  typedef unordered_map<ustring, Attribute, ustringHash> AttributeMap;
   typedef unordered_map<ustring, int, ustringHash> ObjectNameMap;
 
-  vector<AttributeMap> attribute_map;
   ObjectNameMap object_name_map;
   vector<ustring> object_names;
 };
diff --git a/intern/cycles/kernel/osl/services.cpp b/intern/cycles/kernel/osl/services.cpp
index faa027f4e1e..eef661c203e 100644
--- a/intern/cycles/kernel/osl/services.cpp
+++ b/intern/cycles/kernel/osl/services.cpp
@@ -740,76 +740,75 @@ static bool set_attribute_matrix(const Transform &tfm, TypeDesc type, void *val)
   return false;
 }
 
-static bool get_primitive_attribute(const KernelGlobalsCPU *kg,
-                                    const ShaderData *sd,
-                                    const OSLGlobals::Attribute &attr,
-                                    const TypeDesc &type,
-                                    bool derivatives,
-                                    void *val)
+static bool get_object_attribute(const KernelGlobalsCPU *kg,
+                                 ShaderData *sd,
+                                 const AttributeDescriptor &desc,
+                                 const TypeDesc &type,
+                                 bool derivatives,
+                                 void *val)
 {
-  if (attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector ||
-      attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) {
+  if (desc.type == NODE_ATTR_FLOAT3) {
     float3 fval[3];
-    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list