Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/doitsujin/dxvk.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Ashton <joshua@froggi.es>2020-08-16 17:13:30 +0300
committerJoshua Ashton <joshua@froggi.es>2020-08-17 23:30:57 +0300
commita19a2b29520c4d419831aacef15063b1aa508d85 (patch)
tree3d07ef98b524ea498534400210fe55f78dbaf678
parent89d36e1d7f125bf66650e4d98c74ac6b7cb30b33 (diff)
[d3d9] Implement YV12 video formatimplement-yv12
Needed for #1726 otherwise it will upload dump that upload garbage in a YUV2 texture.
-rw-r--r--src/d3d9/d3d9_common_texture.cpp2
-rw-r--r--src/d3d9/d3d9_format.cpp9
-rw-r--r--src/d3d9/d3d9_format.h1
-rw-r--r--src/d3d9/d3d9_format_helpers.cpp6
-rw-r--r--src/d3d9/meson.build3
-rw-r--r--src/d3d9/shaders/d3d9_convert_yv12.comp58
6 files changed, 77 insertions, 2 deletions
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 <d3d9_convert_x8l8v8u8.h>
#include <d3d9_convert_a2w10v10u10.h>
#include <d3d9_convert_nv12.h>
+#include <d3d9_convert_yv12.h>
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);
+ }
+}