Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_shader_interface.hh
| Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
| * In future, argument buffers may be extended to support other resource | * In future, argument buffers may be extended to support other resource | ||||
| * types, if overall bind limits are ever increased within Blender. | * types, if overall bind limits are ever increased within Blender. | ||||
| * | * | ||||
| * The #ArgumentEncoder cache used to store the generated #ArgumentEncoders for a given | * The #ArgumentEncoder cache used to store the generated #ArgumentEncoders for a given | ||||
| * shader permutation. The #ArgumentEncoder is the resource used to write resource binding | * shader permutation. The #ArgumentEncoder is the resource used to write resource binding | ||||
| * information to a specified buffer, and is unique to the shader's resource interface. | * information to a specified buffer, and is unique to the shader's resource interface. | ||||
| */ | */ | ||||
| enum class ShaderStage : uint32_t { | enum class ShaderStage : uint8_t { | ||||
| VERTEX = 1 << 0, | VERTEX = 1 << 0, | ||||
| FRAGMENT = 1 << 1, | FRAGMENT = 1 << 1, | ||||
| BOTH = (ShaderStage::VERTEX | ShaderStage::FRAGMENT), | COMPUTE = 2 << 1, | ||||
| ANY = (ShaderStage::VERTEX | ShaderStage::FRAGMENT | ShaderStage::COMPUTE), | |||||
| }; | }; | ||||
| ENUM_OPERATORS(ShaderStage, ShaderStage::BOTH); | ENUM_OPERATORS(ShaderStage, ShaderStage::ANY); | ||||
| inline uint get_shader_stage_index(ShaderStage stage) | inline uint get_shader_stage_index(ShaderStage stage) | ||||
| { | { | ||||
| switch (stage) { | switch (stage) { | ||||
| case ShaderStage::VERTEX: | case ShaderStage::VERTEX: | ||||
| return 0; | return 0; | ||||
| case ShaderStage::FRAGMENT: | case ShaderStage::FRAGMENT: | ||||
| return 1; | return 1; | ||||
| case ShaderStage::COMPUTE: | |||||
| return 2; | |||||
| default: | default: | ||||
| BLI_assert_unreachable(); | BLI_assert_unreachable(); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* Shader input/output binding information. */ | /* Shader input/output binding information. */ | ||||
| ▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | private: | ||||
| /* Textures support explicit binding indices, so some texture slots | /* Textures support explicit binding indices, so some texture slots | ||||
| * remain unused. */ | * remain unused. */ | ||||
| uint32_t total_textures_; | uint32_t total_textures_; | ||||
| int max_texture_index_; | int max_texture_index_; | ||||
| MTLShaderTexture textures_[MTL_MAX_TEXTURE_SLOTS]; | MTLShaderTexture textures_[MTL_MAX_TEXTURE_SLOTS]; | ||||
| /* Whether argument buffers are used for sampler bindings. */ | /* Whether argument buffers are used for sampler bindings. */ | ||||
| bool sampler_use_argument_buffer_; | bool sampler_use_argument_buffer_; | ||||
| int sampler_argument_buffer_bind_index_vert_; | int sampler_argument_buffer_bind_index_[3]; | ||||
| int sampler_argument_buffer_bind_index_frag_; | |||||
| /* Attribute Mask. */ | /* Attribute Mask. */ | ||||
| uint32_t enabled_attribute_mask_; | uint32_t enabled_attribute_mask_; | ||||
| /* Debug. */ | /* Debug. */ | ||||
| char name[256]; | char name[256]; | ||||
| public: | public: | ||||
| MTLShaderInterface(const char *name); | MTLShaderInterface(const char *name); | ||||
| ~MTLShaderInterface(); | ~MTLShaderInterface(); | ||||
| void init(); | void init(); | ||||
| void add_input_attribute(uint32_t name_offset, | void add_input_attribute(uint32_t name_offset, | ||||
| uint32_t attribute_location, | uint32_t attribute_location, | ||||
| MTLVertexFormat format, | MTLVertexFormat format, | ||||
| uint32_t buffer_index, | uint32_t buffer_index, | ||||
| uint32_t size, | uint32_t size, | ||||
| uint32_t offset, | uint32_t offset, | ||||
| int matrix_element_count = 1); | int matrix_element_count = 1); | ||||
| uint32_t add_uniform_block(uint32_t name_offset, | uint32_t add_uniform_block(uint32_t name_offset, | ||||
| uint32_t buffer_index, | uint32_t buffer_index, | ||||
| uint32_t size, | uint32_t size, | ||||
| ShaderStage stage_mask = ShaderStage::BOTH); | ShaderStage stage_mask = ShaderStage::ANY); | ||||
| void add_uniform(uint32_t name_offset, eMTLDataType type, int array_len = 1); | void add_uniform(uint32_t name_offset, eMTLDataType type, int array_len = 1); | ||||
| void add_texture(uint32_t name_offset, | void add_texture(uint32_t name_offset, | ||||
| uint32_t texture_slot, | uint32_t texture_slot, | ||||
| eGPUTextureType tex_binding_type, | eGPUTextureType tex_binding_type, | ||||
| eGPUSamplerFormat sampler_format, | eGPUSamplerFormat sampler_format, | ||||
| ShaderStage stage_mask = ShaderStage::FRAGMENT); | ShaderStage stage_mask = ShaderStage::FRAGMENT); | ||||
| void add_push_constant_block(uint32_t name_offset); | void add_push_constant_block(uint32_t name_offset); | ||||
| /* Resolve and cache locations of builtin uniforms and uniform blocks. */ | /* Resolve and cache locations of builtin uniforms and uniform blocks. */ | ||||
| void map_builtins(); | void map_builtins(); | ||||
| void set_sampler_properties(bool use_argument_buffer, | void set_sampler_properties(bool use_argument_buffer, | ||||
| uint32_t argument_buffer_bind_index_vert, | uint32_t argument_buffer_bind_index_vert, | ||||
| uint32_t argument_buffer_bind_index_frag); | uint32_t argument_buffer_bind_index_frag, | ||||
| uint32_t argument_buffer_bind_index_compute); | |||||
| /* Prepare #ShaderInput interface for binding resolution. */ | /* Prepare #ShaderInput interface for binding resolution. */ | ||||
| void prepare_common_shader_inputs(); | void prepare_common_shader_inputs(); | ||||
| /* Fetch Uniforms. */ | /* Fetch Uniforms. */ | ||||
| const MTLShaderUniform &get_uniform(uint index) const; | const MTLShaderUniform &get_uniform(uint index) const; | ||||
| uint32_t get_total_uniforms() const; | uint32_t get_total_uniforms() const; | ||||
| /* Fetch Uniform Blocks. */ | /* Fetch Uniform Blocks. */ | ||||
| const MTLShaderUniformBlock &get_uniform_block(uint index) const; | const MTLShaderUniformBlock &get_uniform_block(uint index) const; | ||||
| uint32_t get_total_uniform_blocks() const; | uint32_t get_total_uniform_blocks() const; | ||||
| uint32_t get_max_ubo_index() const; | uint32_t get_max_ubo_index() const; | ||||
| bool has_uniform_block(uint32_t block_index) const; | bool has_uniform_block(uint32_t block_index) const; | ||||
| uint32_t get_uniform_block_size(uint32_t block_index) const; | uint32_t get_uniform_block_size(uint32_t block_index) const; | ||||
| /* Push constant uniform data block should always be available. */ | /* Push constant uniform data block should always be available. */ | ||||
| const MTLShaderUniformBlock &get_push_constant_block() const; | const MTLShaderUniformBlock &get_push_constant_block() const; | ||||
| /* Fetch textures. */ | /* Fetch textures. */ | ||||
| const MTLShaderTexture &get_texture(uint index) const; | const MTLShaderTexture &get_texture(uint index) const; | ||||
| uint32_t get_total_textures() const; | uint32_t get_total_textures() const; | ||||
| uint32_t get_max_texture_index() const; | uint32_t get_max_texture_index() const; | ||||
| bool get_use_argument_buffer_for_samplers(int *vertex_arg_buffer_bind_index, | bool uses_argument_buffer_for_samplers() const; | ||||
| int *fragment_arg_buffer_bind_index) const; | int get_argument_buffer_bind_index(ShaderStage stage) const; | ||||
| /* Fetch Attributes. */ | /* Fetch Attributes. */ | ||||
| const MTLShaderInputAttribute &get_attribute(uint index) const; | const MTLShaderInputAttribute &get_attribute(uint index) const; | ||||
| uint32_t get_total_attributes() const; | uint32_t get_total_attributes() const; | ||||
| uint32_t get_total_vertex_stride() const; | uint32_t get_total_vertex_stride() const; | ||||
| uint32_t get_enabled_attribute_mask() const; | uint32_t get_enabled_attribute_mask() const; | ||||
| /* Name buffer fetching. */ | /* Name buffer fetching. */ | ||||
| Show All 17 Lines | |||||