diff --git a/src/d3d9/shaders/d3d9_convert_common.h b/src/d3d9/shaders/d3d9_convert_common.h index b29bf59f..30f045f0 100644 --- a/src/d3d9/shaders/d3d9_convert_common.h +++ b/src/d3d9/shaders/d3d9_convert_common.h @@ -9,5 +9,21 @@ float snormalize(int value, int bits) { // Min because, -32 and -31 map to -1.0f, and we // divide by 31. - return max(float(value) / float(range), -1.0f); + return max(float(value) / float(range), -1.0); +} + +float unpackUnorm(uint p) { + return float(p) / 255.0; +} + +mat3x4 g_yuv_to_rgb = { + { 298 / 256, 0, 409 / 256, 0.5 }, + { 298 / 256, -100 / 256, -208 / 256, 0.5 }, + { 298 / 256, 516 / 256, 0, 0.5 } +}; + +vec4 convertYUV(vec3 yuv) { + vec3 value = vec4(yuv, 1 / 255.0) * g_yuv_to_rgb; + + return vec4(clamp(value, 0, 1), 1); } \ No newline at end of file diff --git a/src/d3d9/shaders/d3d9_convert_yuy2_uyvy.comp b/src/d3d9/shaders/d3d9_convert_yuy2_uyvy.comp index 1509906c..5342ad22 100644 --- a/src/d3d9/shaders/d3d9_convert_yuy2_uyvy.comp +++ b/src/d3d9/shaders/d3d9_convert_yuy2_uyvy.comp @@ -1,4 +1,7 @@ #version 450 +#extension GL_GOOGLE_include_directive : enable + +#include "d3d9_convert_common.h" layout(constant_id = 1249) const bool s_is_uyvy = false; @@ -17,18 +20,6 @@ uniform u_info_t { uvec2 extent; } u_info; -mat3x4 g_yuv_to_rgb = { - { 298 / 256, 0, 409 / 256, 0.5 }, - { 298 / 256, -100 / 256, -208 / 256, 0.5 }, - { 298 / 256, 516 / 256, 0, 0.5 } -}; - -vec4 convertYUV(vec3 cde) { - vec3 value = vec4(cde, 1 / 255.0) * g_yuv_to_rgb; - - return vec4(clamp(value, 0, 1), 1); -} - void main() { ivec3 thread_id = ivec3(gl_GlobalInvocationID); @@ -44,13 +35,13 @@ void main() { if (s_is_uyvy) data = data.yxwz; - float c0 = data.x - (16 / 255.0); - float d = data.y - (128 / 255.0); - float c1 = data.z - (16 / 255.0); - float e = data.w - (128 / 255.0); + float y0 = data.x - (16 / 255.0); + float u = data.y - (128 / 255.0); + float y1 = data.z - (16 / 255.0); + float v = data.w - (128 / 255.0); - vec4 color0 = convertYUV(vec3(c0, d, e)); - vec4 color1 = convertYUV(vec3(c1, d, e)); + vec4 color0 = convertYUV(vec3(y0, u, v)); + vec4 color1 = convertYUV(vec3(y1, u, v)); // YUY2 has a macropixel of [2, 1] // so we write 2 pixels in this run.