diff --git a/src/d3d9/d3d9_common_texture.cpp b/src/d3d9/d3d9_common_texture.cpp index 49cf03ff..14862fdc 100644 --- a/src/d3d9/d3d9_common_texture.cpp +++ b/src/d3d9/d3d9_common_texture.cpp @@ -189,7 +189,7 @@ namespace dxvk { const uint32_t planeCount = m_mapping.ConversionFormatInfo.PlaneCount; - return planeCount + return std::min(planeCount, 2u) * formatInfo.elementSize * blockCount.width * blockCount.height diff --git a/src/d3d9/d3d9_format.cpp b/src/d3d9/d3d9_format.cpp index eead1a73..a51faba7 100644 --- a/src/d3d9/d3d9_format.cpp +++ b/src/d3d9/d3d9_format.cpp @@ -411,6 +411,15 @@ namespace dxvk { { D3D9ConversionFormat_NV12, 2u, VK_FORMAT_B8G8R8A8_UNORM } }; + case D3D9Format::YV12: return { + VK_FORMAT_R8_UNORM, + VK_FORMAT_UNDEFINED, + VK_IMAGE_ASPECT_COLOR_BIT, + { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, + VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY }, + { D3D9ConversionFormat_YV12, 3u, VK_FORMAT_B8G8R8A8_UNORM } + }; + case D3D9Format::RAWZ: return {}; // Unsupported default: diff --git a/src/d3d9/d3d9_format.h b/src/d3d9/d3d9_format.h index ea4d9420..5fecc5e5 100644 --- a/src/d3d9/d3d9_format.h +++ b/src/d3d9/d3d9_format.h @@ -135,6 +135,7 @@ namespace dxvk { D3D9ConversionFormat_X8L8V8U8, D3D9ConversionFormat_A2W10V10U10, D3D9ConversionFormat_NV12, + D3D9ConversionFormat_YV12, D3D9ConversionFormat_Count }; diff --git a/src/d3d9/d3d9_format_helpers.cpp b/src/d3d9/d3d9_format_helpers.cpp index 4b40ba8f..77a1eecb 100644 --- a/src/d3d9/d3d9_format_helpers.cpp +++ b/src/d3d9/d3d9_format_helpers.cpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace dxvk { @@ -40,6 +41,10 @@ namespace dxvk { ConvertGenericFormat(conversionFormat, dstImage, dstSubresource, srcBuffer, VK_FORMAT_R16_UINT, 0, { 2u, 1u }); break; + case D3D9ConversionFormat_YV12: + ConvertGenericFormat(conversionFormat, dstImage, dstSubresource, srcBuffer, VK_FORMAT_R8_UINT, 0, { 1u, 1u }); + break; + case D3D9ConversionFormat_L6V5U5: ConvertGenericFormat(conversionFormat, dstImage, dstSubresource, srcBuffer, VK_FORMAT_R16_UINT, 0, { 1u, 1u }); break; @@ -115,6 +120,7 @@ namespace dxvk { m_shaders[D3D9ConversionFormat_X8L8V8U8] = InitShader(d3d9_convert_x8l8v8u8); m_shaders[D3D9ConversionFormat_A2W10V10U10] = InitShader(d3d9_convert_a2w10v10u10); m_shaders[D3D9ConversionFormat_NV12] = InitShader(d3d9_convert_nv12); + m_shaders[D3D9ConversionFormat_YV12] = InitShader(d3d9_convert_yv12); } diff --git a/src/d3d9/meson.build b/src/d3d9/meson.build index eb08e457..428df079 100644 --- a/src/d3d9/meson.build +++ b/src/d3d9/meson.build @@ -7,7 +7,8 @@ d3d9_shaders = files([ 'shaders/d3d9_convert_l6v5u5.comp', 'shaders/d3d9_convert_x8l8v8u8.comp', 'shaders/d3d9_convert_a2w10v10u10.comp', - 'shaders/d3d9_convert_nv12.comp' + 'shaders/d3d9_convert_nv12.comp', + 'shaders/d3d9_convert_yv12.comp' ]) d3d9_src = [ diff --git a/src/d3d9/shaders/d3d9_convert_yv12.comp b/src/d3d9/shaders/d3d9_convert_yv12.comp new file mode 100644 index 00000000..ad3822ab --- /dev/null +++ b/src/d3d9/shaders/d3d9_convert_yv12.comp @@ -0,0 +1,58 @@ +#version 450 +#extension GL_GOOGLE_include_directive : enable + +#include "d3d9_convert_common.h" + +layout( + local_size_x = 8, + local_size_y = 8, + local_size_z = 1) in; + +layout(binding = 0) +writeonly uniform image2D dst; + +layout(binding = 1) uniform usamplerBuffer src; + +layout(push_constant) +uniform u_info_t { + uvec2 extent; +} u_info; + +// Format is: +// YYYYYYYY... +// VVVV... +// UUUU... + +float fetchUnorm(usamplerBuffer source, uint offset) { + return unpackUnorm(texelFetch(src, int(offset)).r); +} + +void main() { + ivec3 thread_id = ivec3(gl_GlobalInvocationID); + + if (all(lessThan(thread_id.xy, u_info.extent))) { + uvec2 pitch = uvec2(u_info.extent.x, u_info.extent.y); + + uint offset = thread_id.x + + thread_id.y * pitch.x; + + // Fetch a Y, luminance sample. + float y = fetchUnorm(src, offset) - (16 / 255.0); + + // Go into the second plane to get a V, chroma sample + offset = (thread_id.x / 2) + + (thread_id.y / 2) * (pitch.x / 2) + + pitch.x * pitch.y; + + float v = fetchUnorm(src, offset) - (128 / 255.0); + + // Go into the third plane to get a U, chroma sample + offset += (pitch.x / 2) * (pitch.y / 2); + float u = fetchUnorm(src, offset) - (128 / 255.0); + + // TODO: Is this the right color space? + vec4 color = convertBT_709(vec3(y, u, v)); + + imageStore(dst, thread_id.xy, color); + } +}