How to deal with DXGI_FORMAT_B8G8R8A8_UNORM_SRGB

Started by
8 comments, last by _void_ 6 years, 6 months ago

Hello guys,

I have a texture of format DXGI_FORMAT_B8G8R8A8_UNORM_SRGB.

Is there a way to create shader resource view for the texture so that I could read it as RGBA from the shader instead of reading it specifically as BGRA?

I would like all the textures to be read as RGBA.

 

Tx

Advertisement
12 minutes ago, _void_ said:

I would like all the textures to be read as RGBA.

Why do you not use DXGI_FORMAT_R8G8B8A8_UNORM_SRGB instead of  DXGI_FORMAT_B8G8R8A8_UNORM_SRGB?

🧙

Yeah, I can convert the texture to DXGI_FORMAT_R8G8B8A8_UNORM_SRGB format.

I thought maybe there is a way to work this around using shader resource view, which I do not know about :-) 

15 minutes ago, _void_ said:

I thought maybe there is a way to work this around using shader resource view, which I do not know about :-) 

You can assign multiple shader resource views with different types to a resource, but I am not sure if you can interpret BGRA as RGBA since the underlying bytes of the resource are ordered differently.

🧙

Assuming that you are actually using D3D12 like your tag implies, you can re-order the channels on SRV loads/samples using the Shader4ComponentMapping field of the SRV desc. See D3D12_SHADER_COMPONENT_MAPPING.

@SoldierOfLightRight, thanks!

Am I being dumb, or wouldn't DXGI_FORMAT_B8G8R8A8 come through in the correct order into the shader without messing around with swizzles?

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

22 minutes ago, ajmiles said:

Am I being dumb, or wouldn't DXGI_FORMAT_B8G8R8A8 come through in the correct order into the shader without messing around with swizzles?

Heh, that's a good point. It's essentially already got the swizzling baked into it so you can read it normally. Don't know why I didn't realize that...

@ajmiles @SoldierOfLight

Thank you guys! I guess, I managed to confuse everyone :-)

This topic is closed to new replies.

Advertisement