3

Note: I distinguish sample from fetch in the title, since in my tests this behavior seems to differ between the two.

Possible answers:

  • The [0..2^32] range is scaled down to [0..1] (I think OpenGL works this way)
  • The uint32s are casted to float32s (which, incidentally, means that some precision is lost).
  • Other?
Stefan Monov
  • 11,332
  • 10
  • 63
  • 120

2 Answers2

2

I made a test with renderdoc.

When using fetch, and the texture is defined with Texture2D<uint>, the fetch functions simply return a uint instead of a float4.

Stefan Monov
  • 11,332
  • 10
  • 63
  • 120
0

I assume that your texture/view format is R32_UINT.

If you do :

uint value = texture.Load(pixelLocation);

it will return you uint (just exact same value)

If you do :

float value = texture.Load(pixelLocation);

It will perform a cast (potential precision issue)

If you try to sample, it will do other, as sampling on uint format is normally not allowed (can go from wrong value to driver crash).

Case 1 (scaled down range): is not available with R32, only with R16 or R8 in that case you need to use DXGI_FORMAT_R16_UNORM instead of UINT for the shader view (or texture format). Sample of course works in that case.

mrvux
  • 8,523
  • 1
  • 27
  • 61