2

I'm investigating Direct3D11 for displaying video output; in particular, I'm trying to figure out if there's a way to give a YUV surface to Direct3D11 and have it automatically (i.e. in hardware) convert it to RGB and present it as such. The documentation of DXGI_MODE_DESC states:

Because of the relaxed render target creation rules that Direct3D 11 has for back buffers, applications can create a DXGI_FORMAT_B8G8R8A8_UNORM_SRGB render target view from a DXGI_FORMAT_B8G8R8A8_UNORM swap chain so they can use automatic color space conversion when they render the swap chain.

What does this "automatic color space conversion" refer to? Is there anything in Direct3D11 that does what I'm looking for or must this be performed either pre-render or through a shader?

Asik
  • 21,506
  • 6
  • 72
  • 131
  • AFAIK, this "automatic" color-space conversion is referring to sRGB and linear-to-gamma space conversion, and not YUV-to-RGB. Also, I myself consider employing a simple fragment shader as close to "in hardware" as you can get. – yzt Jun 05 '14 at 22:46

1 Answers1

2

When creating a texture in DX11 you can choose a number of formats that will inform shaders about the data structures. These formats belong to DXGI_FORMAT enum. They are basically various configurations of ARGB color format, so they allow you to specify for example a B8G8R8A8 or R16G16B16A16. There is however no option for YUV format.

The best thing you can do is passing your YUV data to the shader pipeline, "pretending" that they're RGB. Then in the pixel shader perform a conversion to the real RGB format. This solution should be sufficiently efficient because the conversion will be executed on GPU, in parallel for every visible pixel of your texture.

Elvithari
  • 834
  • 1
  • 8
  • 13
  • Yes that's what I've been attempting to do (http://stackoverflow.com/questions/24093491/strange-smeared-edges-pattern-using-hlsl-for-yuv-to-rgb-conversion), but thanks! – Asik Jun 08 '14 at 14:21
  • @Elvithadri, I know this has been answered 3 years ago, but would you please provide some tips on how to use shader in order to achieve that? –  Mar 29 '17 at 12:24
  • @moose, Well it's not too complicated. This site: http://www.equasys.de/colorconversion.html provides the matrix equation to compute RGB colors given YUV. If you're texture is in fact YUV and you need to display it as RGB apply this transform in pixel shader. – Elvithari Mar 29 '17 at 19:43
  • @Elvithari, I'm familiar with the YUV->RGB math, but not with the shaders. I can ask a new question here on how to use shaders. For instance, do I need vertex shader and pixel shader, or just the latter one? I will fill the RGBA surface with the YUV values, because I cannot create a YUV surface. Therefore, shader will probably receive float4 for the color, because it thinks it's the RGBA. I should convert that to RGBA, but the return value should be 2 x float4 because YUYV == 2pixels, etc.... I would appreciate a lot if you could assist on this. –  Mar 30 '17 at 08:28