Skip to content
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

Closed

Conversation

billhollings
Copy link
Contributor

@billhollings billhollings commented Jan 18, 2021

Add query for type of MSL texture on desc set bindings:

  • When encoding textures to argument buffers, Metal require knowledge of the type of each texture. Querying from shader conversion allows us to use that knowledge when encoding an argument buffer for a specific pipeline.

Support padding between argument buffer struct members to align arguments:

  • Metal requires knowledge of the entire argument buffer structure to understand where to populate resources. SPIR-V does not include descriptor set content that is not used by the shader being converted. This makes it impossible for MSL to use a single argument buffer, representing a single descriptor set, across multiple shaders.
  • By adding padding between known members of the descriptor set struct, we can define the full positional content of the descriptor-set argument buffer. This allows us to use the same Metal argument buffer across multiple shaders, each of which might only access a small part of the argument buffer.

@HansKristian-Work
Copy link
Contributor

@HansKristian-Work HansKristian-Work commented Jan 19, 2021

First comment right off the bat. Lots of merge commits in the PR. Please rebase the PR.

spirv_msl.hpp Outdated
@@ -556,6 +580,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);
Copy link
Contributor

@HansKristian-Work HansKristian-Work Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be const?

spirv_msl.cpp Outdated
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;
Copy link
Contributor

@HansKristian-Work HansKristian-Work Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting.

spirv_msl.cpp Outdated
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));
Copy link
Contributor

@HansKristian-Work HansKristian-Work Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Braces for clarity.

spirv_msl.hpp Outdated
@@ -95,6 +95,21 @@ enum MSLSamplerCoord
MSL_SAMPLER_INT_MAX = 0x7fffffff
};

enum MSLTextureType
Copy link
Contributor

@HansKristian-Work HansKristian-Work Jan 19, 2021

Choose a reason for hiding this comment

The 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?

bool use_array = pad_cnt > 1;
uint32_t pad_type_id = ir.increase_bound_by(use_array ? 2 : 1);
auto &pad_type = set<SPIRType>(pad_type_id);
pad_type.basetype = SPIRType::UInt64;
Copy link
Contributor

@HansKristian-Work HansKristian-Work Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is questionable. Doesn't this basically assume that descriptors take up 8 bytes? I would normally expect this kind of interface to specify the descriptor type used for specific IDs.

Copy link
Contributor

@HansKristian-Work HansKristian-Work Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMD texture descriptors are 16 or 32 bytes for example.

Copy link
Contributor

@HansKristian-Work HansKristian-Work left a comment

Comments.

@billhollings
Copy link
Contributor Author

@billhollings billhollings commented Jan 29, 2021

I pulled the texture type and handled it outside using reflection. Turns out there is also still work to be done on the question of padding. So for now, I'm going to close this PR and resubmit a variation if it turns out to be needed.

@billhollings billhollings deleted the msl-arg-buff-updates branch Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants