Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_pso_descriptor_state.hh
| Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | |||||
| }; | }; | ||||
| struct MTLVertexDescriptor { | struct MTLVertexDescriptor { | ||||
| /* Core Vertex Attributes. */ | /* Core Vertex Attributes. */ | ||||
| MTLVertexAttributeDescriptorPSO attributes[GPU_VERT_ATTR_MAX_LEN]; | MTLVertexAttributeDescriptorPSO attributes[GPU_VERT_ATTR_MAX_LEN]; | ||||
| MTLVertexBufferLayoutDescriptorPSO | MTLVertexBufferLayoutDescriptorPSO | ||||
| buffer_layouts[GPU_BATCH_VBO_MAX_LEN + GPU_BATCH_INST_VBO_MAX_LEN]; | buffer_layouts[GPU_BATCH_VBO_MAX_LEN + GPU_BATCH_INST_VBO_MAX_LEN]; | ||||
| int num_attributes; | int max_attribute_value; | ||||
| int total_attributes; | |||||
| int num_vert_buffers; | int num_vert_buffers; | ||||
| MTLPrimitiveTopologyClass prim_topology_class; | MTLPrimitiveTopologyClass prim_topology_class; | ||||
| /* WORKAROUND: SSBO Vertex-fetch attributes -- These follow the same structure | /* WORKAROUND: SSBO Vertex-fetch attributes -- These follow the same structure | ||||
| * but have slightly different binding rules, passed in via uniform | * but have slightly different binding rules, passed in via uniform | ||||
| * push constant data block. */ | * push constant data block. */ | ||||
| bool uses_ssbo_vertex_fetch; | bool uses_ssbo_vertex_fetch; | ||||
| MTLSSBOAttribute ssbo_attributes[GPU_VERT_ATTR_MAX_LEN]; | MTLSSBOAttribute ssbo_attributes[GPU_VERT_ATTR_MAX_LEN]; | ||||
| int num_ssbo_attributes; | int num_ssbo_attributes; | ||||
| bool operator==(const MTLVertexDescriptor &other) const | bool operator==(const MTLVertexDescriptor &other) const | ||||
| { | { | ||||
| if ((this->num_attributes != other.num_attributes) || | if ((this->max_attribute_value != other.max_attribute_value) || | ||||
| (this->total_attributes != other.total_attributes) || | |||||
| (this->num_vert_buffers != other.num_vert_buffers)) { | (this->num_vert_buffers != other.num_vert_buffers)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (this->prim_topology_class != other.prim_topology_class) { | if (this->prim_topology_class != other.prim_topology_class) { | ||||
| return false; | return false; | ||||
| }; | }; | ||||
| for (const int a : IndexRange(this->num_attributes)) { | for (const int a : IndexRange(this->max_attribute_value + 1)) { | ||||
| if (!(this->attributes[a] == other.attributes[a])) { | if (!(this->attributes[a] == other.attributes[a])) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| for (const int b : IndexRange(this->num_vert_buffers)) { | for (const int b : IndexRange(this->num_vert_buffers)) { | ||||
| if (!(this->buffer_layouts[b] == other.buffer_layouts[b])) { | if (!(this->buffer_layouts[b] == other.buffer_layouts[b])) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| /* NOTE: No need to compare SSBO attributes, as these will match attribute bindings for the | /* NOTE: No need to compare SSBO attributes, as these will match attribute bindings for the | ||||
| * given shader. These are simply extra pre-resolved properties we want to include in the | * given shader. These are simply extra pre-resolved properties we want to include in the | ||||
| * cache. */ | * cache. */ | ||||
| return true; | return true; | ||||
| } | } | ||||
| uint64_t hash() const | uint64_t hash() const | ||||
| { | { | ||||
| uint64_t hash = (uint64_t)(this->num_attributes ^ this->num_vert_buffers); | uint64_t hash = (uint64_t)(this->max_attribute_value ^ this->num_vert_buffers); | ||||
| for (const int a : IndexRange(this->num_attributes)) { | for (const int a : IndexRange(this->max_attribute_value + 1)) { | ||||
| hash ^= this->attributes[a].hash() << a; | hash ^= this->attributes[a].hash() << a; | ||||
| } | } | ||||
| for (const int b : IndexRange(this->num_vert_buffers)) { | for (const int b : IndexRange(this->num_vert_buffers)) { | ||||
| hash ^= this->buffer_layouts[b].hash() << (b + 10); | hash ^= this->buffer_layouts[b].hash() << (b + 10); | ||||
| } | } | ||||
| /* NOTE: SSBO vertex fetch members not hashed as these will match attribute bindings. */ | /* NOTE: SSBO vertex fetch members not hashed as these will match attribute bindings. */ | ||||
| ▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | uint64_t hash() const | ||||
| hash ^= uint64_t(this->point_size); | hash ^= uint64_t(this->point_size); | ||||
| return hash; | return hash; | ||||
| } | } | ||||
| /* Reset the Vertex Descriptor to default. */ | /* Reset the Vertex Descriptor to default. */ | ||||
| void reset_vertex_descriptor() | void reset_vertex_descriptor() | ||||
| { | { | ||||
| vertex_descriptor.num_attributes = 0; | vertex_descriptor.total_attributes = 0; | ||||
| vertex_descriptor.max_attribute_value = 0; | |||||
| vertex_descriptor.num_vert_buffers = 0; | vertex_descriptor.num_vert_buffers = 0; | ||||
| for (int i = 0; i < GPU_VERT_ATTR_MAX_LEN; i++) { | for (int i = 0; i < GPU_VERT_ATTR_MAX_LEN; i++) { | ||||
| vertex_descriptor.attributes[i].format = MTLVertexFormatInvalid; | vertex_descriptor.attributes[i].format = MTLVertexFormatInvalid; | ||||
| vertex_descriptor.attributes[i].offset = 0; | vertex_descriptor.attributes[i].offset = 0; | ||||
| } | } | ||||
| vertex_descriptor.uses_ssbo_vertex_fetch = false; | vertex_descriptor.uses_ssbo_vertex_fetch = false; | ||||
| vertex_descriptor.num_ssbo_attributes = 0; | vertex_descriptor.num_ssbo_attributes = 0; | ||||
| } | } | ||||
| }; | }; | ||||
| } // namespace blender::gpu | } // namespace blender::gpu | ||||