[Metal] Fix top level argument buffer indexing when creating descriptors#998
[Metal] Fix top level argument buffer indexing when creating descriptors#998kcloudy0717 wants to merge 4 commits intollvm:mainfrom
Conversation
|
Pinging @bob80905, @farzonl, @llvm-beanz for review. |
|
Would it also be possible to integrate |
|
Thinking about this more, I think we should consider using the explicit root signature binding model from the metal shader converter as that will give us most flexibility when configuring resources. Using the explicit model will make future tests such as unbound resource arrays or dynamic resource indexing via Metal's explicit root signature binding model is exactly the same as D3D12's root signature model, the only caveat is that we need to convert DXIL -> AIR on the fly because setting the root signature is only available during shader conversion through either the API or command line. See https://developer.apple.com/metal/shader-converter/#binding-model for more info. |
|
@kcloudy0717 - this PR is marked as draft. If you're ready for it to be reviewed, can you click the "Ready for review" button please? |
0784078 to
7fa395b
Compare
| // From metal_irconverter.h which is not part of the third-party | ||
| enum IRResourceType { |
There was a problem hiding this comment.
Should we include metal_irconvert.h as a dependency in third-party?
There was a problem hiding this comment.
That would be preferred. This task was originally for looking into mac issues, adding a whole 3rd party library probably should in a separate task?
| if (auto Err = createDescriptor(R, IS, HeapIndex++)) | ||
| return Err; | ||
|
|
||
| if (P.isCompute()) { |
There was a problem hiding this comment.
Is this only applicable to compute pipelines? I would imagine the same issue would pop up for graphics and ray tracing pipelines.
There was a problem hiding this comment.
No, it's applicable to other stages too, but that was something I didn't look into because the reflection generated is separate. Ideally we use explicit root signature binding model when using the Metal Shader Converter as suggested in #998 (comment).
…s for different types Tests that are failing have same register but they are separate resource types (SRV vs UAV), the TLABIndexMap didn't account for that which caused resources with same register & space to be created in the same location.
ae9446d to
d807b29
Compare
Yes, we can and should integrate
I agree here too. Explicit root signatures is a better mapping of how these tests are written than trying to remap the bindings like we're doing here, and I would prefer that approach. Are you willing to take that on? Should we abandon this PR in preference of using that approach, or does it make sense to go with this in the short term and follow up with that later? |
Sure, I can take on implementing the explicit root signature approach. I think we can abandon this PR, this PR served it's purpose on figuring out why most of the metal tests are failing. I don't think it make sense for this PR to be merged in the short term since once we integrated the RS approach, the code would most likely be removed. |
|
Closing this PR in favor of implementing the explicit RS approach for Metal shader converter that I'll be working on. |
I looked deeper into why some tests fails on Metal and I think found the reason why.
The Metal backend generates a automatic linear layout of the resources into the top-level argument buffer, but the actual heap index of the resources seems to be sorted by the resource type in the metal shader reflection. Given the following declarations:
when compiled with
-metaland-Freoptions, we get the following in the metal json reflection:From the reflection data we can see
InandUInSRV resource descriptors should be created at index 0 and 1, but this is not the case in the backend because it assumes heap index is 1:1 to the order they are declared in theDescriptorSets -> Resourcesfield.The PR fixes this by adding a hash map using
SlotandSpacevalues in the reflection as keys that maps to the actual index of the top level argument buffer when creating descriptors.With the above changes, I get the following on my local machine: