You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SPIR-V] Copying ConstantBuffer data doesn't actually copy anything. #6952
Description
I am trying to copy data from a ConstantBuffer fetched from the ResourceDescriptorHeap into another variable, however, the data always becomes zeroed.
I can see the ConstantBuffer in RenderDoc, but when debugging in RenderDoc, the copied values are zero.
SPIR-V can be hard to read. It loads descriptor array ResourceDescriptorHeap_0 at index 1, and then loads the member at index 1, which is data1. That is then store to the first element in storage buffer at ResourceDescritporHeap[0].
Note that this features requires VK_EXT_mutable_descriptor_type. Make sure that is enabled an correctly handled by the driver.
If the problem is that RenderDoc shows the value of tempData to be all zeros, even if the output from the shader is correct, that is because you did not generate the debug info. The compiler optimized away tempData so there is nothing for RenderDoc to see. If you want see the value even if it is optimized aways, you can try -fspv-debug=vulkan-with-source, which seem to be failing now (https://godbolt.org/z/fh9Gden6q).
We will be waiting to hear what the specific problem is.
And var in the ConstantBuffer is set to for example 5, the output of the StructuredBuffer is 0.
But if I declare the ConstantBuffer as its own binding:
ConstantBuffer<CBData> cb : register(b0, space1);
The output of the StructuredBuffer is correct.
The extension is setup properly, if the SPIR-V looks correct to you, the issue is probably elsewhere, maybe something in the driver.
Thanks for looking it over!
Now I understand the problem better. I still think the SPIR-V looks correct. However, this feature has a big caveat. It allocates two different resource arrays at the same binding, with different types. For this to work, you need to use "mutable descriptors" on the application side.
I'll close for now. Let me know if you come across a more specific problem in the spir-v that I am not seeing.
The 2 examples you gave are yielding different results:
the first one puts cb in the binding=0,descriptor=0, and sb in binging=1,descriptor=0
the second creates a single binding 0, and puts cb in DS=1, and sb in DS=0
I tried the following code, and tested in a small VK application and I do get the expected behavior: the CS contains my values, and the SB[0] entry gets written with the value in the CB.
(same result on both my AMD gpu and llvmpipe)
Activity
s-perron commentedon Oct 15, 2024
I do not see any problem in the SPIR-V. The copy is removed through copy propagation. The final spir-v is:
SPIR-V can be hard to read. It loads descriptor array
ResourceDescriptorHeap_0at index 1, and then loads the member at index1, which isdata1. That is then store to the first element in storage buffer atResourceDescritporHeap[0].I'm not sure how the code should be generated differently. This is the same code that is generated when the two resources are declared separately. See https://godbolt.org/z/TPj7qKn5h. This is also the came code as if the copy is removed: https://godbolt.org/z/rK1b7d6bb.
Note that this features requires VK_EXT_mutable_descriptor_type. Make sure that is enabled an correctly handled by the driver.
If the problem is that RenderDoc shows the value of
tempDatato be all zeros, even if the output from the shader is correct, that is because you did not generate the debug info. The compiler optimized awaytempDataso there is nothing for RenderDoc to see. If you want see the value even if it is optimized aways, you can try-fspv-debug=vulkan-with-source, which seem to be failing now (https://godbolt.org/z/fh9Gden6q).We will be waiting to hear what the specific problem is.
ChunkTreasure1 commentedon Oct 15, 2024
Hello!
Sorry, I might have been unclear.
When I do this:
And
varin the ConstantBuffer is set to for example 5, the output of the StructuredBuffer is 0.But if I declare the ConstantBuffer as its own binding:
The output of the StructuredBuffer is correct.
The extension is setup properly, if the SPIR-V looks correct to you, the issue is probably elsewhere, maybe something in the driver.
Thanks for looking it over!
s-perron commentedon Jan 22, 2025
Now I understand the problem better. I still think the SPIR-V looks correct. However, this feature has a big caveat. It allocates two different resource arrays at the same binding, with different types. For this to work, you need to use "mutable descriptors" on the application side.
I'll close for now. Let me know if you come across a more specific problem in the spir-v that I am not seeing.
Keenuts commentedon Feb 4, 2025
Hello!
The 2 examples you gave are yielding different results:
I tried the following code, and tested in a small VK application and I do get the expected behavior: the CS contains my values, and the SB[0] entry gets written with the value in the CB.
(same result on both my AMD gpu and llvmpipe)
Update submodules: DirectX-Headers to 61c77189, SPIRV-Headers to 5c60…
Update submodules: DirectX-Headers to 61c77189, SPIRV-Headers to 5c60…
Update submodules: DirectX-Headers to 61c77189, SPIRV-Headers to fb13…