Is there some reason for not being able to write or perform interlocked operations to an UAV using unknown values for the indexes and even for the value to write?
I only can write to UAV if the index is known like:
uint u_addr = 5;
uint u_wr = 1;
mybuffer[u_addr] = u_wr;
Otherwise it does not work. Completely useless for me. And the thing is that it fails to compile the shader, before trying to attach the shader to a PSO. (VisualStudio, both cs_5_0 and cs_5_1 fail)
uint u_addr = uint_may_be_anything;
uint u_wr = uint_read_from_texture;
mybuffer[u_addr] = u_wr; // can't compile
Even when only the value to write is not known it fails:
uint u_addr = 5;
uint u_wr = uint_read_from_texture;
mybuffer[u_addr] = u_wr; // can't compile
It works too when the index is coming directly from the SV_ variables.
I was two days trying to make it work and googling about it, before asking here. I even just drag a random compute shader from the examples of microsoft to the shaders folder and it compiles well. But if i put some unknown value for the indexing, it fails. I change only this in the examples of microsoft and it fails to compile.
I am trying to make it work with RWBuffer and RWByteAddressBuffer, because i don't need structures. In the examples of microsoft RWStructuredBuffer fails with an unknown index too.
Can not compile writes to UAVs
Can you provide a shader that doesn't compile and we might be able to help?
Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group
Sorry for the late answer! I wanted to test it 20 times. Here it is:
Texture2D<uint4> intexture : register(t0);
RWBuffer<uint> mybuffer : register(u0);
[numthreads(256, 1, 1)]
void CSMain(uint3 DTid : SV_DispatchThreadID)
{
uint u_1 = 2;
uint4 u4_1 = intexture.Load(int3(0,0,0));
uint u_2 = u4_1.r;
//mybuffer[u_1] = u_2; // failing line
//mybuffer[u_2] = u_2; // failing line
u_1 = DTid.x;
mybuffer[u_1] = u_2; // compiles
u_2 = mybuffer[u_2]; // unknow index for reads compile always
}
I see SV_DispatchThreadID makes sure nobody is writing to the same place simultaneously. Other SV_ variables are failing.
Sorry, my fault, not exactly, because it is not flaten, Only one of the dimensions. Sorry for that last assumption! Other SV_ variables still are failing.
This shader compiles just fine for me even if I uncomment the two lines you've marked as "failing line".
What compile error are you getting?
Are you using fxc from the Windows SDK? The one I'm using is:
C:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64>fxc /?
Microsoft (R) Direct3D Shader Compiler 10.1 (using C:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64\D3DCOMPILER_47.dll)
Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group
No, i am using the compile-from-file inside C++.
I switched to the last Wundows10 two weeks ago. And had some minor issues.
For example, I had to change to D3D12SerializeVersionedRootSignature commands, because the old commands was making my app just break without any errors. So i changed to the versioned root serialize commands and it stopped hanging. Now this....
I will check the DLL I use...
I upgraded the project from 10.15xx to 10.17xx, and no change.
I enabled the debug layer successfully. And then in the problematic place i used ThrowIfFailed to throw an exception, but it is not failing that way.
I started it in graphics debug mode, but nothing.
Where are the error messages form the debug layer being displayed, @Hodgman?
Then i disabled the debug layer and tried to catch the error in the fashion i always used:
if (FAILED(D3DCompileFromFile(...)) {
// print ugly message
} else {
// print pretty message
}
It fails the way it was failing before.
But when I use ThrowIfFailed(without the debug layer enabled and with it enabled is the same) I can uncomment the both lines in the shader and it doesn't catch any error. Then i break the name of a variable and it fails to compile.
So it does catch errors in the shader, but no longer that two lines..?!
I don't understand why "if(FAILED(.." reports error while "ThrolIfFailed" does not. ThrowIfFailed uses the same if (FAILED( inside... Could it be that it catches a warning? But the code is the same - if (FAILED
I wish to check somehow the ID3DBlob of the error, but google is some times completely useless for directx.
The compiler reports it's own error messages via the "out_opt ID3DBlob ppErrorMsgs" argument. These will include line numbers, syntax error descriptions, etc... It's pretty hard to program without access to your compiler's error messages! You just need something like:
ID3DBlob* errorBlob = nullptr;
D3DCompileFromFile( ..., &errorBlob );
if ( errorBlob )
{
OutputDebugStringA( (char*)errorBlob->GetBufferPointer() );
errorBlob->Release();
}
. 22 Racing Series .
Thank you very much, @Hodgman !!
I was able to catch the "error".
From the compiler's error blob:
"warning X3583: race condition writing to shared resource detected, note that threads will be writing the same value, but performance may be diminished due to contention."So, "if(FAILED(.." catches the warnings as errors too. While "ThrowIfFailed(" catches only the errors....for some reason.
Edit:
The way I was checking for error while compiling the shaders has the fault for the confusion about ThrowIfFailed:
if (FAILED(..) {
// print ugly message
} else if (errorBlob) {
// print the same ugly message
}
Now the two cases print different clearer messages and it all makes sense. I am sorry if i confused somebody about this!
Mea culpa.