New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MSL: Metal argument buffer use enhancements #1596
Changes from 1 commit
b53c3f1
3de6ce1
8ce92dc
5a34f32
435eb24
d236867
56482ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Add MSLTextureType enum and get_msl_texture_type() function.
- Loading branch information
There are no files selected for viewing
| @@ -12485,6 +12485,55 @@ std::string CompilerMSL::sampler_type(const SPIRType &type, uint32_t id) | ||
| return "sampler"; | ||
| } | ||
|
|
||
| MSLTextureType CompilerMSL::get_msl_texture_type(uint32_t desc_set, uint32_t binding) | ||
| { | ||
| MSLTextureType msl_tex_type = MSL_TEXTURE_TYPE_2D; | ||
| ir.for_each_typed_id<SPIRVariable>([&](uint32_t self, SPIRVariable &var) { | ||
| if (has_decoration(self, DecorationDescriptorSet) && (get_decoration(self, DecorationDescriptorSet) == desc_set) && | ||
| has_decoration(self, DecorationBinding) && (get_decoration(self, DecorationBinding) == binding)) | ||
| msl_tex_type = get_msl_texture_type(get_variable_data_type(var)); | ||
| }); | ||
| return msl_tex_type; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting. |
||
| } | ||
|
|
||
| MSLTextureType CompilerMSL::get_msl_texture_type(const SPIRType &type) | ||
| { | ||
| if (!(type.basetype == SPIRType::SampledImage || type.basetype == SPIRType::Image)) | ||
| return MSL_TEXTURE_TYPE_2D; | ||
|
|
||
| auto &img_type = get<SPIRType>(type.self).image; | ||
| switch (img_type.dim) | ||
| { | ||
| case DimBuffer: | ||
| return (msl_options.texture_buffer_native ? MSL_TEXTURE_TYPE_TEXTURE_BUFFER : MSL_TEXTURE_TYPE_2D); | ||
|
|
||
| case Dim1D: | ||
| if (msl_options.texture_1D_as_2D) | ||
| return (img_type.arrayed ? MSL_TEXTURE_TYPE_2D_ARRAY : MSL_TEXTURE_TYPE_2D); | ||
| else | ||
| return (img_type.arrayed ? MSL_TEXTURE_TYPE_1D_ARRAY : MSL_TEXTURE_TYPE_1D); | ||
|
|
||
| case Dim2D: | ||
| case DimSubpassData: | ||
| if (img_type.ms) | ||
| return (img_type.arrayed ? MSL_TEXTURE_TYPE_2D_MULTISAMPLE_ARRAY : MSL_TEXTURE_TYPE_2D_MULTISAMPLE); | ||
| else | ||
| return (img_type.arrayed ? MSL_TEXTURE_TYPE_2D_ARRAY : MSL_TEXTURE_TYPE_2D); | ||
|
|
||
| case Dim3D: | ||
| return MSL_TEXTURE_TYPE_3D; | ||
|
|
||
| case DimCube: | ||
| if (msl_options.emulate_cube_array) | ||
| return (img_type.arrayed ? MSL_TEXTURE_TYPE_2D_ARRAY : MSL_TEXTURE_TYPE_2D); | ||
| else | ||
| return (img_type.arrayed ? MSL_TEXTURE_TYPE_CUBE_ARRAY : MSL_TEXTURE_TYPE_CUBE); | ||
|
|
||
| default: | ||
| return MSL_TEXTURE_TYPE_2D; | ||
| } | ||
| } | ||
|
|
||
| // Returns an MSL string describing the SPIR-V image type | ||
| string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id) | ||
| { | ||
| @@ -95,6 +95,21 @@ enum MSLSamplerCoord | ||
| MSL_SAMPLER_INT_MAX = 0x7fffffff | ||
| }; | ||
|
|
||
| enum MSLTextureType | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this call useful? It seems like it's a convenience query for apps? |
||
| { | ||
| MSL_TEXTURE_TYPE_1D = 0, | ||
| MSL_TEXTURE_TYPE_1D_ARRAY = 1, | ||
| MSL_TEXTURE_TYPE_2D = 2, | ||
| MSL_TEXTURE_TYPE_2D_ARRAY = 3, | ||
| MSL_TEXTURE_TYPE_2D_MULTISAMPLE = 4, | ||
| MSL_TEXTURE_TYPE_2D_MULTISAMPLE_ARRAY = 5, | ||
| MSL_TEXTURE_TYPE_3D = 6, | ||
| MSL_TEXTURE_TYPE_CUBE = 7, | ||
| MSL_TEXTURE_TYPE_CUBE_ARRAY = 8, | ||
| MSL_TEXTURE_TYPE_TEXTURE_BUFFER = 9, | ||
| MSL_TEXTURE_TYPE_INT_MAX = 0x7fffffff | ||
| }; | ||
|
|
||
| enum MSLSamplerFilter | ||
| { | ||
| MSL_SAMPLER_FILTER_NEAREST = 0, | ||
| @@ -556,6 +571,9 @@ class CompilerMSL : public CompilerGLSL | ||
| // by remap_constexpr_sampler(_by_binding). | ||
| bool is_msl_resource_binding_used(spv::ExecutionModel model, uint32_t set, uint32_t binding) const; | ||
|
|
||
| // Returns the MSL texture type of the variable at the desc_set and binding | ||
| MSLTextureType get_msl_texture_type(uint32_t desc_set, uint32_t binding); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably be const? |
||
|
|
||
| // This must only be called after a successful call to CompilerMSL::compile(). | ||
| // For a variable resource ID obtained through reflection API, report the automatically assigned resource index. | ||
| // If the descriptor set was part of an argument buffer, report the [[id(N)]], | ||
| @@ -710,6 +728,7 @@ class CompilerMSL : public CompilerGLSL | ||
| // GCC workaround of lambdas calling protected functions (for older GCC versions) | ||
| std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id = 0) override; | ||
|
|
||
| MSLTextureType get_msl_texture_type(const SPIRType &type); | ||
| std::string image_type_glsl(const SPIRType &type, uint32_t id = 0) override; | ||
| std::string sampler_type(const SPIRType &type, uint32_t id); | ||
| std::string builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClass storage) override; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Braces for clarity.