Corrupt values when writing and reading from the same RWTexture2D in HLSL/DirectX?

Computer Graphics Asked by b1skit on August 27, 2021

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!

Add your own answers!

Related Questions

BRDF for point lights should not return values over 1

1  Asked on August 27, 2021 by emil-kabirov


Dynamic Array in GLSL

3  Asked on January 13, 2021 by archmede


Combine box shadow with a signed distance field

0  Asked on January 2, 2021 by weichsem


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir