Blender V4.3
kernel/geom/attribute.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
8
9/* Attributes
10 *
11 * We support an arbitrary number of attributes on various mesh elements.
12 * On vertices, triangles, curve keys, curves, meshes and volume grids.
13 * Most of the code for attribute reading is in the primitive files.
14 *
15 * Lookup of attributes is different between OSL and SVM, as OSL is ustring
16 * based while for SVM we use integer ids. */
17
18/* Patch index for triangle, -1 if not subdivision triangle */
19
21{
22 return (prim != PRIM_NONE) ? kernel_data_fetch(tri_patch, prim) : ~0;
23}
24
26{
27 if ((type & PRIMITIVE_TRIANGLE) && subd_triangle_patch(kg, prim) != ~0) {
28 return ATTR_PRIM_SUBD;
29 }
30 else {
31 return ATTR_PRIM_GEOMETRY;
32 }
33}
34
41
42/* Find attribute based on ID */
43
45{
46 return kernel_data_fetch(objects, object).attribute_map_offset;
47}
48
50find_attribute(KernelGlobals kg, int object, int prim, int type, uint64_t id)
51{
52 if (object == OBJECT_NONE) {
53 return attribute_not_found();
54 }
55
56 /* for SVM, find attribute by unique id */
57 uint attr_offset = object_attribute_map_offset(kg, object);
58 attr_offset += attribute_primitive_type(kg, prim, type);
59 AttributeMap attr_map = kernel_data_fetch(attributes_map, attr_offset);
60
61 while (attr_map.id != id) {
62 if (UNLIKELY(attr_map.id == ATTR_STD_NONE)) {
63 if (UNLIKELY(attr_map.element == 0)) {
64 return attribute_not_found();
65 }
66 else {
67 /* Chain jump to a different part of the table. */
68 attr_offset = attr_map.offset;
69 }
70 }
71 else {
72 attr_offset += ATTR_PRIM_TYPES;
73 }
74 attr_map = kernel_data_fetch(attributes_map, attr_offset);
75 }
76
78 desc.element = (AttributeElement)attr_map.element;
79
80 if (prim == PRIM_NONE && desc.element != ATTR_ELEMENT_MESH &&
82 {
83 return attribute_not_found();
84 }
85
86 /* return result */
87 desc.offset = (attr_map.element == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND :
88 (int)attr_map.offset;
89 desc.type = (NodeAttributeType)attr_map.type;
90 desc.flags = (AttributeFlag)attr_map.flags;
91
92 return desc;
93}
94
96 ccl_private const ShaderData *sd,
97 uint64_t id)
98{
99 return find_attribute(kg, sd->object, sd->prim, sd->type, id);
100}
101
102/* Transform matrix attribute on meshes */
103
105{
106 Transform tfm;
107
108 tfm.x = kernel_data_fetch(attributes_float4, desc.offset + 0);
109 tfm.y = kernel_data_fetch(attributes_float4, desc.offset + 1);
110 tfm.z = kernel_data_fetch(attributes_float4, desc.offset + 2);
111
112 return tfm;
113}
114
unsigned int uint
#define UNLIKELY(x)
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define kernel_data_fetch(name, index)
#define ccl_device
#define ccl_private
#define ccl_device_inline
#define CCL_NAMESPACE_END
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline uint attribute_primitive_type(KernelGlobals kg, int prim, int type)
ccl_device_inline AttributeDescriptor attribute_not_found()
ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg, int object, int prim, int type, uint64_t id)
ccl_device_inline uint object_attribute_map_offset(KernelGlobals kg, int object)
ccl_device Transform primitive_attribute_matrix(KernelGlobals kg, const AttributeDescriptor desc)
CCL_NAMESPACE_BEGIN ccl_device_inline uint subd_triangle_patch(KernelGlobals kg, int prim)
NodeAttributeType
@ PRIMITIVE_TRIANGLE
@ ATTR_STD_NOT_FOUND
@ ATTR_STD_NONE
#define PRIM_NONE
AttributeFlag
#define OBJECT_NONE
ShaderData
AttributeElement
@ ATTR_ELEMENT_NONE
@ ATTR_ELEMENT_VOXEL
@ ATTR_ELEMENT_OBJECT
@ ATTR_ELEMENT_MESH
@ ATTR_PRIM_SUBD
@ ATTR_PRIM_TYPES
@ ATTR_PRIM_GEOMETRY
unsigned __int64 uint64_t
Definition stdint.h:90
AttributeElement element
NodeAttributeType type
uint16_t element
float4 y
Definition transform.h:24
float4 x
Definition transform.h:24
float4 z
Definition transform.h:24