-
Notifications
You must be signed in to change notification settings - Fork 706
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
[SPIR-V] [Proposal 0011] SPIR-V Type for a PhysicalStorageBuffer class OpTypePointer fails to compile because of missing offsets for a struct #6541
Comments
Its been over a year since I've checkd, but seems that still, contrary to the docs
There are no tests for this functionality in the DXC repo at all |
Thanks for reporting @devshgraphicsprogramming. You've piqued my interest with #6489 (comment) so we'll try to prioritize this. |
I can't conform to Proposal 0010 100% but I can get something that has all the functionality. One reason is that there's no reflection neither in C++ or HLSL so for structs I'd be basically defining them throuhg a macro. |
We'll want a dedicated implementation anyways, but I'm still keen to see full features done successfully in inline SPIR-V. |
NVM: got sniped by KhronosGroup/SPIRV-Registry#140 (comment) |
This seems like an issue with the layout rules not getting passed around correctly for the vk::SpirvType. Here is another case that fails. It fails differently, but it probably a related issues: https://godbolt.org/z/3vq3xWY7v. |
I'm starting to understand the problem, and I'll need to think about how to fix it. The problem in the smaller example is that the SPIR-V backend does not know how to propagate the layout rule for the In general, the layout rule for a return value in a function is There are a few options to fix this. In the expansion of the Other option involve fixing up the code after wards, either in DXC or spirv-opt. |
IIRC what happens is that for a canonical type btw I always compile my code with Surely Scalar Layout must make this a lot easier? |
As I have thought about this more, DXC does not know the correct layout for the result of a For now, I think I will write a spirv-opt pass that will fix up the result type for an OpLoad and the object type for an OpStore. I suspect that this pass will almost never have to be updated for new instructions given the specific cases it will be needed. EDIT I looked at the original test case. The problem with that one is the BitCast. The result of the |
These were my thoughts/musings related to this: |
We are able to deal with workgroup pointers, and we are adding this to the HLSL standard headers: #6873. I am coming to believe that the layout issue with storage classes that require a layout is insurmountable. We might be able to do some targeted fixes for pointer. If we have a SpirvOpqaueType tha that is a pointer, then try to deduce the layout based on the storage class. However, it would still fail for instructions that do a load or store type instruction using the pointers. There is no way to specify that the result of an vk::ext_instruction function must have a particular layout. We may need to add an attribute to indicate the layout of the result. I am not planning on doing that until it becomes something we need for the HLSL standard headers that we writing. I will close this issue, and open a new one in HLSL spec when we decide that we need the layout attribute. |
Wouldn't OpLogicalCopy be enough to copy between "related" structs but with different layouts? |
Opcopylogical only helps a little. It would not translate the data pointed to by a pointer. You would need a load. It also doesn't help with the result type for a vk::ext_instruction function. The result type is invalid even if an opcopylogical is applied afterwards. |
We have #4195 to cover this issue. |
Shouldn't this PR merge #6873 eliminate the need for you to pass the |
doesn't the |
No it does not. In SPIR-V there are certain storage class that never have a data layout (workgroup, private, function). If you do an OpLoad the layout of the result type has to match the layout of the pointer type. In the normal case, this is easy. DXC knows when it is generating an OpLoad, so it looks at the pointer type to see which layout the result needs. The problem in your case is that the instruction that does the load is opaque to the code generator, which decides the layout. So the code generator does not know how to deduce the layout type. It just opts for no layout. It works for some cases, and not for others. It is a big change to fix the way that DXC handles layouts in general. This is too big of a change to go into DXC at this point. |
Are there any holes in:
This is pure unambiguous mapping of Storage Class to Layout, DXC never respected the attribute offset annotation decoration for inline spirv. |
Yes, there is a hole. What should the layout be for a return value from a function? We chose to make it no "no layout". That is the calling convention. However, if the function call represents a single SPIR-V instruction like an OpLoad, then there is no fixed layout. The layout depends on the input. This ends up breaking the calling convention. Any solution to this is very invasive. It might also be DXC specific because I'm not sure how we will deal with this in Clang. |
Post C++11, don't functions always return r-value references when returning structs by value? so one could "walk" eventually find the layout? Second question, more to the point, this maybe would be solved if the layout was inherently baked into the type. For every offset decoration combo I can see that DXC codegen emits a separate SPIR-V struct declaration. Would treating a plain Taking a step back, the whole problem for my BDA use case seems to stem from the fact that my So maybe the only thing that needs to be fixed is how P.S. are you sure |
Description
This was already solved for
vk::RawBufferLoad<Composite>
however it rears its head again when we start usingvk::SpirvOpaqueType
to declare the same poitner typeRawBufferLoad
uses under the hood.Related to this probably: #4924 and #2411
Steps to Reproduce
This Godbolt: https://godbolt.org/z/MjdfrGjPz
Actual Behavior
Every time an
gets instantiated where
T
is a composite, we get the following errorEnvironment
The text was updated successfully, but these errors were encountered: