Commit d43fea06 authored by Matthew Waters's avatar Matthew Waters 🐨

vkcolorconvert: add support for RGB<->NV12

parent 0cb416db
Pipeline #43666 passed with stages
in 31 minutes and 3 seconds
......@@ -8,6 +8,8 @@ gst_vulkan_shader_sources = [
'rgb_to_yuy2.frag',
'ayuv_to_rgb.frag',
'rgb_to_ayuv.frag',
'nv12_to_rgb.frag',
'rgb_to_nv12.frag',
]
bin2array = find_program('bin2array.py')
......
#version 450 core
#include "color_convert_generic.glsl"
#include "upsample_nv12.glsl"
#include "swizzle.glsl"
layout(location = 0) in vec2 inTexCoord;
layout(set = 0, binding = 0) uniform sampler2D inTexture0;
layout(set = 0, binding = 1) uniform sampler2D inTexture1;
layout(set = 0, binding = 2) uniform reorder {
ivec4 in_reorder_idx;
ivec4 out_reorder_idx;
ivec2 texSize;
ColorMatrices matrices;
};
layout(location = 0) out vec4 outColor0;
void main()
{
vec3 yuv = upsample_NV12 (inTexture0, inTexture1, inTexCoord, in_reorder_idx);
vec4 rgba = vec4(1.0);
rgba.rgb = color_convert_texel (yuv, matrices);
outColor0 = swizzle(rgba, out_reorder_idx);
}
#version 450 core
#include "color_convert_generic.glsl"
#include "swizzle.glsl"
layout(location = 0) in vec2 inTexCoord;
layout(set = 0, binding = 0) uniform sampler2D inTexture0;
layout(set = 0, binding = 1) uniform reorder {
ivec4 in_reorder_idx;
ivec4 out_reorder_idx;
ivec2 texSize;
ColorMatrices matrices;
};
layout(location = 0) out vec4 outColor0;
layout(location = 1) out vec4 outColor1;
void main()
{
vec4 texel = swizzle (texture(inTexture0, inTexCoord), in_reorder_idx);
vec4 uv_texel = swizzle (texture(inTexture0, inTexCoord * vec2(2.0)), in_reorder_idx);
vec3 yuv1 = color_convert_texel (texel.rgb, matrices);
vec3 yuv2 = color_convert_texel (uv_texel.rgb, matrices);
vec3 yuv = vec3(yuv1.x, yuv2.y, yuv2.z);
outColor0 = vec4(yuv[out_reorder_idx[0]], 0.0, 0.0, 1.0);
outColor1 = vec4(yuv[out_reorder_idx[1]], yuv[out_reorder_idx[2]], 0.0, 1.0);
}
#include "swizzle.glsl"
vec3 upsample_NV12(in sampler2D Ytex, in sampler2D UVtex, in vec2 texCoord, in ivec4 inReorderIdx)
{
vec3 yuv;
yuv.x = texture(Ytex, texCoord).x;
yuv.yz = texture(UVtex, texCoord).xy;
return swizzle(yuv, inReorderIdx.xyz);
}
This diff is collapsed.
......@@ -278,7 +278,8 @@ _create_pipeline (GstVulkanFullScreenRender * render)
VkPipelineViewportStateCreateInfo viewport_state;
VkPipelineRasterizationStateCreateInfo rasterizer;
VkPipelineMultisampleStateCreateInfo multisampling;
VkPipelineColorBlendAttachmentState color_blend_attachment;
VkPipelineColorBlendAttachmentState
color_blend_attachments[GST_VIDEO_MAX_PLANES];
VkPipelineColorBlendStateCreateInfo color_blending;
VkGraphicsPipelineCreateInfo pipeline_info;
VkPipeline pipeline;
......@@ -364,7 +365,19 @@ _create_pipeline (GstVulkanFullScreenRender * render)
.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT
};
color_blend_attachment = (VkPipelineColorBlendAttachmentState) {
color_blend_attachments[0] = (VkPipelineColorBlendAttachmentState) {
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
.blendEnable = VK_FALSE
};
color_blend_attachments[1] = (VkPipelineColorBlendAttachmentState) {
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
.blendEnable = VK_FALSE
};
color_blend_attachments[2] = (VkPipelineColorBlendAttachmentState) {
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
.blendEnable = VK_FALSE
};
color_blend_attachments[3] = (VkPipelineColorBlendAttachmentState) {
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
.blendEnable = VK_FALSE
};
......@@ -374,8 +387,8 @@ _create_pipeline (GstVulkanFullScreenRender * render)
.pNext = NULL,
.logicOpEnable = VK_FALSE,
.logicOp = VK_LOGIC_OP_COPY,
.attachmentCount = 1,
.pAttachments = &color_blend_attachment,
.attachmentCount = GST_VIDEO_INFO_N_PLANES (&render->out_info),
.pAttachments = color_blend_attachments,
.blendConstants = { 0.0f, 0.0f, 0.0f, 0.0f }
};
......@@ -832,6 +845,9 @@ gst_vulkan_full_screen_render_fill_command_buffer (GstVulkanFullScreenRender *
{
/* *INDENT-OFF* */
VkClearValue clearColor = {{{ 0.0f, 0.0f, 0.0f, 1.0f }}};
VkClearValue clearColors[GST_VIDEO_MAX_PLANES] = {
clearColor, clearColor, clearColor, clearColor,
};
VkRenderPassBeginInfo render_pass_info = {
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
.renderPass = render->render_pass,
......@@ -841,8 +857,8 @@ gst_vulkan_full_screen_render_fill_command_buffer (GstVulkanFullScreenRender *
GST_VIDEO_INFO_WIDTH (&render->out_info),
GST_VIDEO_INFO_HEIGHT (&render->out_info)
},
.clearValueCount = 1,
.pClearValues = &clearColor
.clearValueCount = GST_VIDEO_INFO_N_PLANES (&render->out_info),
.pClearValues = clearColors,
};
/* *INDENI-ON* */
VkDeviceSize offsets[] = { 0 };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment