Skip to content

Commit 43e33e1

Browse files
committed
vulkan: support VUYA
with shader
1 parent 0dcedcb commit 43e33e1

5 files changed

Lines changed: 46 additions & 0 deletions

File tree

2.71 KB
Binary file not shown.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#version 450
2+
3+
layout (local_size_x = 16, local_size_y = 16) in;
4+
5+
layout (set = 0, binding = 0) uniform sampler2D inputImage;
6+
layout (set = 1, binding = 1, rgba8) uniform image2D resultImage;
7+
8+
layout(push_constant) uniform constants
9+
{
10+
uint width;
11+
uint height;
12+
} image_size;
13+
14+
// BT.709 YUV->RGB coefficients
15+
const float Y_SCALED = 1.1643835;
16+
const float R_CR_709 = 1.7926522;
17+
const float G_CB_709 = -0.21323606;
18+
const float G_CR_709 = -0.5330038;
19+
const float B_CB_709 = 2.11242;
20+
21+
void main()
22+
{
23+
ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy);
24+
if(pixelCoords.x >= image_size.width ||
25+
pixelCoords.y >= image_size.height)
26+
return;
27+
28+
// Assuming input BGRA maps to YUVA: B=Y, G=U, R=V, A=A
29+
vec4 yuv = texelFetch(inputImage, pixelCoords, 0).bgra;
30+
31+
float y = Y_SCALED * (yuv.r - 0.0625);
32+
float u = yuv.g - 0.5;
33+
float v = yuv.b - 0.5;
34+
35+
float r = y + R_CR_709 * v;
36+
float g = y + G_CB_709 * u + G_CR_709 * v;
37+
float b = y + B_CB_709 * u;
38+
float a = yuv.a;
39+
40+
imageStore(resultImage, pixelCoords, vec4(r, g, b, a));
41+
}

src/video_display/vulkan/vulkan_sdl2.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ const std::vector<CodecToVulkanFormat>& get_ug_to_vkd_format_mapping(state_vulka
502502
{RGB, vkd::Format::RGB8},
503503
{UYVY, vkd::Format::UYVY8_422},
504504
{UYVY, vkd::Format::UYVY8_422_conv},
505+
{VUYA, vkd::Format::VUYA8_conv},
505506
{YUYV, vkd::Format::YUYV8_422},
506507
{Y216, vkd::Format::YUYV16_422},
507508
{Y416, vkd::Format::UYVA16_422_conv},

src/video_display/vulkan/vulkan_sdl3.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ const std::vector<CodecToVulkanFormat>& get_ug_to_vkd_format_mapping(state_vulka
511511
{UYVY, vkd::Format::UYVY8_422},
512512
{UYVY, vkd::Format::UYVY8_422_conv},
513513
{YUYV, vkd::Format::YUYV8_422},
514+
{VUYA, vkd::Format::VUYA8_conv},
514515
{Y216, vkd::Format::YUYV16_422},
515516
{Y416, vkd::Format::UYVA16_422_conv},
516517
{R10k, vkd::Format::RGB10A2_conv},

src/video_display/vulkan/vulkan_transfer_image.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ enum class Format{
5050
YUYV8_422,
5151
YUYV16_422,
5252
UYVA16_422_conv,
53+
VUYA8_conv,
5354
RGB10A2_conv,
5455
RGB16
5556
};
@@ -79,6 +80,7 @@ inline const FormatInfo& format_info(vulkan_display::Format format){
7980
static FormatInfo YUYV8_422 = { VkF::eG8B8G8R8422Unorm, };
8081
static FormatInfo YUYV16_422 = { VkF::eG16B16G16R16422Unorm, };
8182
static FormatInfo UYVA16_422_conv = { VkF::eR16G16B16A16Uint, {"UYVA16_conv"}, VkF::eR16G16B16A16Sfloat};
83+
static FormatInfo VUYA8_conv = { VkF::eR8G8B8A8Unorm, {"VUYA8_conv"}, VkF::eR8G8B8A8Unorm};
8284
static FormatInfo RGB10A2_conv = { VkF::eR8G8B8A8Uint, {"RGB10A2_conv"}, VkF::eA2B10G10R10UnormPack32};
8385
static FormatInfo RGB16 = { VkF::eR16G16B16Unorm };
8486
switch (format) {
@@ -90,6 +92,7 @@ inline const FormatInfo& format_info(vulkan_display::Format format){
9092
case F::YUYV8_422: return YUYV8_422;
9193
case F::YUYV16_422: return YUYV16_422;
9294
case F::UYVA16_422_conv: return UYVA16_422_conv;
95+
case F::VUYA8_conv: return VUYA8_conv;
9396
case F::RGB10A2_conv: return RGB10A2_conv;
9497
case F::RGB16: return RGB16;
9598
};

0 commit comments

Comments
 (0)