DirectXShaderCompiler
DirectXShaderCompiler copied to clipboard
Segmentation fault/ICE when attempting a particular (invalid) code pattern
Description
AFAICT, there is no way to perform interlocked instructions on data viewed via templated loads or stores with ByteAddressBuffers. However, attempting to do so ICEs the compiler.
Steps to Reproduce
Here's a simple snippet to demonstrate the issue:
struct T
{
uint value;
};
RWByteAddressBuffer b = ResourceDescriptorHeap[0];
int original;
InterlockedMax(b.Load<T>(0).value, 1, original);
Obviously, the code above doesn't make any sense, but since the compiler ICEd instead of reporting a diagnostic, I decided to file this as an issue.
As an aside, is there a way to express the intent above with valid HLSL today? (I don't believe it's possible, but it would be nice if it was).
Environment
- DXC version trunk and 1.7
- Host Operating System Windows
As an aside, is there a way to express the intent above with valid HLSL today? (I don't believe it's possible, but it would be nice if it was).
would this satisfy you?
struct T
{
uint value;
};
RWByteAddressBuffer b = ResourceDescriptorHeap[0];
int original;
b.InterlockedMax(0, 1, original);
(not sure if 100% correct syntax, but thats what MSDN tells me)
The RWByteAddressBuffer has all atomic operations it supports as methods instead of being able to pass the result of Load a free-floating global scope atomic function.
No, the code in the original issue was simplified from the original use case, which was a templated load of a more general/complicated type. The workaround at the moment is manual byte offsets.
ah wait, you're wanting to type the buffer.
yes but you'd need to do pointer arithmetic yourself, sizeof(T)*index+offsetof(T,value) as the first argument to RWByteAddressBuffer::InterlockedMax
A made a macro+template abomination to automagically do this for me, here's my very incomplete Proof Of Concept https://godbolt.org/z/KesGq3z44
Caution: its very ugly.
Godbolt link of the original issue: https://godbolt.org/z/5n31h354h