I'm playing around with DirectX 12 ray tracing, and I'm trying to read and write data to a 32-bit RGBA floating point RWTexture2DArray within a DirectX 12 HLSL shader. I'm getting weird corruption/noise when I read back values I've written to the texture.

I've bound the texture as a UAV, and in my shader I've tagged it with the "globallycoherent" like so:

globallycoherent RWTexture2DArray<float4>   myTextureArray;

I'm able to demonstrate the issue I'm seeing with a trivial bit of shader code:

myTextureArray[xIndex, yIndex, 0] = float4((float)xIndex / (float)xRes, (float)yIndex / (float)yRes, 0.0f, 1.0f);

myOutputTexture[xIndex, yIndex] = myTextureArray[xIndex, yIndex, 0];

For the sake of a simple demonstration, I'm just writing increasing values of red along the x axis, and increasing values of green along the y axis, and storing them into the first slice of my 32-bit floating point RGBA RWTexture2DArray. Then, I'm immediately reading the values back from the same position.

Unfortunately, even with this trivial bit of code, when I read the values back they're often garbled. I've got a screenshot of the results, notice the weird, speckled noise in the output:

Notice the weird noise?d

I'm relatively new to DirectX12/HLSL, and I have a feeling I'm likely missing something simple. I've consulted the Microsoft documentation, which states you can both read and write to a RWTexture2DArray, and I'm using the "globallycoherent" prefix as instructed.

I'm using NVidia Falcor as a wrapper for some DXR experiments, so it's possible either I've missed some specific configuration (or, there's a bug in their implementation). If you can think of anything I might have missed, or might not be understanding, I'd be very appreciative of your help! I'm trying to use an array of textures as a buffer to hold various data elements (positions, indexes, etc etc), so if there's an easier/better way, let me know!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.