Kode / Kha

Ultra-portable, high performance, open source multimedia framework.
http://kha.tech
zlib License
1.49k stars 174 forks source link

RGBA128 texture is silently changed to R8_UNORM on d3d11 #1345

Closed MoritzBrueckner closed 2 years ago

MoritzBrueckner commented 3 years ago

Describe the bug When passing an RGBA128 texture to a shader on windows-hl/d3d11, the texture format seems to get silently changed to R8_UNORM according to both RenderDoc and Intel GPA. This creates unexpected results in the shader.

I noticed that there are some places in the Kinc code where the usage of formats seemingly gets restricted (like here), however I'm not sure if the linked code is actually run in my case. Because of that, https://github.com/Kode/Kinc/issues/623 might be a related issue. I'm not sure if it is possible at all to use RGBA128 textures on all targets, but if not this is something that needs to be documented somewhere.

To Reproduce

  1. Create an RGBA128 texture:
    tex = Image.create(256, 256, TextureFormat.RGBA128);
    texData = tex.lock();
    // Write something...
    tex.unlock();
  2. Pass the texture to a shader:
    g4.setTexture(textureUnit, tex);
    // ...
    g4.drawIndexedVertices(...);
  3. Build for windows-hl with d3d11 and compile the project in Visual Studio.
  4. Open the project in a graphics debugger and inspect the texture, the format is now R8_UNORM.

Expected behavior The texture format should be DXGI_FORMAT_R32G32B32A32_FLOAT instead of DXGI_FORMAT_R8_UNORM so that you can directly sample vec4 values in the shader.

Screenshots RenderDoc screenshot

Execution Environment:

RobDangerous commented 2 years ago

This was purely an HL problem and wasn't related to any actual graphics implementation things. The HL backend isn't really actively maintained (I don't use it myself), would be great if somebody could jump in.