diff options
author | Brecht Van Lommel <brecht@blender.org> | 2022-06-16 20:02:55 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-06-17 15:08:14 +0300 |
commit | 24246d98707096f16d5ab48f673f49354eac87a1 (patch) | |
tree | 4011651b36577ecac946c6f93cf011bf951e3dd5 /intern/cycles | |
parent | 838c4a97f1d6b993f4c866c474eb02d929f0ca1d (diff) |
Cleanup: replace uint4 by AttributeMap struct
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/kernel/bvh/util.h | 12 | ||||
-rw-r--r-- | intern/cycles/kernel/geom/attribute.h | 19 | ||||
-rw-r--r-- | intern/cycles/kernel/textures.h | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/types.h | 10 | ||||
-rw-r--r-- | intern/cycles/scene/geometry.cpp | 42 | ||||
-rw-r--r-- | intern/cycles/scene/scene.h | 2 |
6 files changed, 51 insertions, 36 deletions
diff --git a/intern/cycles/kernel/bvh/util.h b/intern/cycles/kernel/bvh/util.h index 71045157372..d53198f97a3 100644 --- a/intern/cycles/kernel/bvh/util.h +++ b/intern/cycles/kernel/bvh/util.h @@ -111,16 +111,16 @@ ccl_device_inline int intersection_find_attribute(KernelGlobals kg, const uint id) { uint attr_offset = kernel_tex_fetch(__objects, object).attribute_map_offset; - uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset); + AttributeMap attr_map = kernel_tex_fetch(__attributes_map, attr_offset); - while (attr_map.x != id) { - if (UNLIKELY(attr_map.x == ATTR_STD_NONE)) { - if (UNLIKELY(attr_map.y == 0)) { + while (attr_map.id != id) { + if (UNLIKELY(attr_map.id == ATTR_STD_NONE)) { + if (UNLIKELY(attr_map.element == 0)) { return (int)ATTR_STD_NOT_FOUND; } else { /* Chain jump to a different part of the table. */ - attr_offset = attr_map.z; + attr_offset = attr_map.offset; } } else { @@ -130,7 +130,7 @@ ccl_device_inline int intersection_find_attribute(KernelGlobals kg, } /* return result */ - return (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.z; + return (attr_map.element == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.offset; } /* Transparent Shadows */ diff --git a/intern/cycles/kernel/geom/attribute.h b/intern/cycles/kernel/geom/attribute.h index da620f69e2d..774b25a76ff 100644 --- a/intern/cycles/kernel/geom/attribute.h +++ b/intern/cycles/kernel/geom/attribute.h @@ -56,16 +56,16 @@ ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg, /* for SVM, find attribute by unique id */ uint attr_offset = object_attribute_map_offset(kg, sd->object); attr_offset += attribute_primitive_type(kg, sd); - uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset); + AttributeMap attr_map = kernel_tex_fetch(__attributes_map, attr_offset); - while (attr_map.x != id) { - if (UNLIKELY(attr_map.x == ATTR_STD_NONE)) { - if (UNLIKELY(attr_map.y == 0)) { + while (attr_map.id != id) { + if (UNLIKELY(attr_map.id == ATTR_STD_NONE)) { + if (UNLIKELY(attr_map.element == 0)) { return attribute_not_found(); } else { /* Chain jump to a different part of the table. */ - attr_offset = attr_map.z; + attr_offset = attr_map.offset; } } else { @@ -75,7 +75,7 @@ ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg, } AttributeDescriptor desc; - desc.element = (AttributeElement)attr_map.y; + desc.element = (AttributeElement)attr_map.element; if (sd->prim == PRIM_NONE && desc.element != ATTR_ELEMENT_MESH && desc.element != ATTR_ELEMENT_VOXEL && desc.element != ATTR_ELEMENT_OBJECT) { @@ -83,9 +83,10 @@ ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg, } /* return result */ - desc.offset = (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.z; - desc.type = (NodeAttributeType)(attr_map.w & 0xff); - desc.flags = (AttributeFlag)(attr_map.w >> 8); + desc.offset = (attr_map.element == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : + (int)attr_map.offset; + desc.type = (NodeAttributeType)attr_map.type; + desc.flags = (AttributeFlag)attr_map.flags; return desc; } diff --git a/intern/cycles/kernel/textures.h b/intern/cycles/kernel/textures.h index 7deb589a0a9..d8ac9cbe51f 100644 --- a/intern/cycles/kernel/textures.h +++ b/intern/cycles/kernel/textures.h @@ -47,7 +47,7 @@ KERNEL_TEX(float4, __points) KERNEL_TEX(uint, __points_shader) /* attributes */ -KERNEL_TEX(uint4, __attributes_map) +KERNEL_TEX(AttributeMap, __attributes_map) KERNEL_TEX(float, __attributes_float) KERNEL_TEX(float2, __attributes_float2) KERNEL_TEX(packed_float3, __attributes_float3) diff --git a/intern/cycles/kernel/types.h b/intern/cycles/kernel/types.h index b1ca379bab8..ad022716207 100644 --- a/intern/cycles/kernel/types.h +++ b/intern/cycles/kernel/types.h @@ -670,6 +670,16 @@ typedef struct AttributeDescriptor { int offset; } AttributeDescriptor; +/* For looking up attributes on objects and geometry. */ +typedef struct AttributeMap { + uint id; /* Global unique identifier. */ + uint element; /* AttributeElement. */ + int offset; /* Offset into __attributes global arrays. */ + uint8_t type; /* NodeAttributeType. */ + uint8_t flags; /* AttributeFlag. */ + uint8_t pad[2]; +} AttributeMap; + /* Closure data */ #ifndef __MAX_CLOSURE__ diff --git a/intern/cycles/scene/geometry.cpp b/intern/cycles/scene/geometry.cpp index 9152abacbdb..2957756fe28 100644 --- a/intern/cycles/scene/geometry.cpp +++ b/intern/cycles/scene/geometry.cpp @@ -407,43 +407,47 @@ void GeometryManager::update_osl_attributes(Device *device, /* Generate a normal attribute map entry from an attribute descriptor. */ static void emit_attribute_map_entry( - uint4 *attr_map, int index, uint id, TypeDesc type, const AttributeDescriptor &desc) + AttributeMap *attr_map, int index, uint id, TypeDesc type, const AttributeDescriptor &desc) { - attr_map[index].x = id; - attr_map[index].y = desc.element; - attr_map[index].z = as_uint(desc.offset); + attr_map[index].id = id; + attr_map[index].element = desc.element; + attr_map[index].offset = as_uint(desc.offset); if (type == TypeDesc::TypeFloat) - attr_map[index].w = NODE_ATTR_FLOAT; + attr_map[index].type = NODE_ATTR_FLOAT; else if (type == TypeDesc::TypeMatrix) - attr_map[index].w = NODE_ATTR_MATRIX; + attr_map[index].type = NODE_ATTR_MATRIX; else if (type == TypeFloat2) - attr_map[index].w = NODE_ATTR_FLOAT2; + attr_map[index].type = NODE_ATTR_FLOAT2; else if (type == TypeFloat4) - attr_map[index].w = NODE_ATTR_FLOAT4; + attr_map[index].type = NODE_ATTR_FLOAT4; else if (type == TypeRGBA) - attr_map[index].w = NODE_ATTR_RGBA; + attr_map[index].type = NODE_ATTR_RGBA; else - attr_map[index].w = NODE_ATTR_FLOAT3; + attr_map[index].type = NODE_ATTR_FLOAT3; - attr_map[index].w |= desc.flags << 8; + attr_map[index].flags = desc.flags; } /* Generate an attribute map end marker, optionally including a link to another map. * Links are used to connect object attribute maps to mesh attribute maps. */ -static void emit_attribute_map_terminator(uint4 *attr_map, int index, bool chain, uint chain_link) +static void emit_attribute_map_terminator(AttributeMap *attr_map, + int index, + bool chain, + uint chain_link) { for (int j = 0; j < ATTR_PRIM_TYPES; j++) { - attr_map[index + j].x = ATTR_STD_NONE; - attr_map[index + j].y = chain; /* link is valid flag */ - attr_map[index + j].z = chain ? chain_link + j : 0; /* link to the correct sub-entry */ - attr_map[index + j].w = 0; + attr_map[index + j].id = ATTR_STD_NONE; + attr_map[index + j].element = chain; /* link is valid flag */ + attr_map[index + j].offset = chain ? chain_link + j : 0; /* link to the correct sub-entry */ + attr_map[index + j].type = 0; + attr_map[index + j].flags = 0; } } /* Generate all necessary attribute map entries from the attribute request. */ static void emit_attribute_mapping( - uint4 *attr_map, int index, Scene *scene, AttributeRequest &req, Geometry *geom) + AttributeMap *attr_map, int index, Scene *scene, AttributeRequest &req, Geometry *geom) { uint id; @@ -501,8 +505,8 @@ void GeometryManager::update_svm_attributes(Device *, } /* create attribute map */ - uint4 *attr_map = dscene->attributes_map.alloc(attr_map_size); - memset(attr_map, 0, dscene->attributes_map.size() * sizeof(uint)); + AttributeMap *attr_map = dscene->attributes_map.alloc(attr_map_size); + memset(attr_map, 0, dscene->attributes_map.size() * sizeof(*attr_map)); for (size_t i = 0; i < scene->geometry.size(); i++) { Geometry *geom = scene->geometry[i]; diff --git a/intern/cycles/scene/scene.h b/intern/cycles/scene/scene.h index a0d2f4a6c06..d04c6a27f11 100644 --- a/intern/cycles/scene/scene.h +++ b/intern/cycles/scene/scene.h @@ -98,7 +98,7 @@ class DeviceScene { device_vector<DecomposedTransform> camera_motion; /* attributes */ - device_vector<uint4> attributes_map; + device_vector<AttributeMap> attributes_map; device_vector<float> attributes_float; device_vector<float2> attributes_float2; device_vector<packed_float3> attributes_float3; |