PoC: MVKShaderLibrary: Handle specializtion with macros #2434
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The converted MSL may use macro instead of function constants to realize spirv specialization constant for various reasons (e.g. when the constant is used as array size).
In this case, we should define the macros at shader compilation stage and generate different variants of the metal shader library depending on macro-value mapping to make specializtion work properly when we cannot rely on metal's specialization.
The current version is hacky as it scans the shader for macro each time we create the function, and guesses the macro based on spirv-cross's habit. Ideally, we should obtain the information from spirv-cross instead.
Although the current form is not ready to merge but I would like to throw it in to see how people think about the approach. I would appreciate insights and suggestions on API design and coding as I'm not an objc guru or equipped with a good knowledge of how the internal API should be.
Fixes: #2423