Commit 2180fbb4 authored by Matthew Waters's avatar Matthew Waters 🐨

vulkancolorconvert: support RGB <-> AYUV/YUY2/UYVY

parent dbf60a17
#version 450 core
#include "color_convert_generic.glsl"
#include "upsample_ayuv.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;
void main()
{
vec4 yuva = upsample_AYUV (inTexture0, inTexCoord, in_reorder_idx);
vec4 rgba = vec4(1.0);
rgba.a = yuva.a;
rgba.rgb = color_convert_texel (yuva.xyz, matrices);
outColor0 = /*vec4(yuv.x * 0.0, yuv.y * 0.0, yuv.z * 1.0, 1.0);*/swizzle(rgba, out_reorder_idx);
}
struct ColorMatrices
{
mat4 to_RGB_matrix;
mat4 primaries_matrix;
mat4 to_YUV_matrix;
};
vec3 color_matrix_convert (in vec3 texel, in mat4 color_matrix)
{
vec4 rgb_ = color_matrix * vec4(texel, 1.0);
return rgb_.rgb;
}
vec3 color_convert_texel (in vec3 texel, in ColorMatrices m)
{
/* FIXME: need to add gamma remapping between these stages */
vec3 tmp = color_matrix_convert (texel, m.to_RGB_matrix);
tmp = color_matrix_convert (tmp, m.primaries_matrix);
return color_matrix_convert (tmp, m.to_YUV_matrix);
}
#include "swizzle.glsl"
vec4 downsample_AYUV(in sampler2D tex, in vec2 texCoord, in ivec4 inReorderIdx)
{
vec4 yuva = texture(tex, texCoord);
return swizzle(yuva, inReorderIdx);
}
......@@ -4,6 +4,10 @@ gst_vulkan_shader_sources = [
'identity.vert',
'swizzle.frag',
'swizzle_and_clobber_alpha.frag',
'yuy2_to_rgb.frag',
'rgb_to_yuy2.frag',
'ayuv_to_rgb.frag',
'rgb_to_ayuv.frag',
]
bin2array = find_program('bin2array.py')
......
#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;
void main()
{
vec4 rgba = swizzle (texture (inTexture0, inTexCoord), in_reorder_idx);
vec4 yuva = vec4(1.0);
yuva.w = rgba.a;
yuva.xyz = color_convert_texel (rgba.rgb, matrices);
outColor0 = swizzle(yuva, 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;
void main()
{
float inorder = mod (inTexCoord.x * texSize.x, 2.0);
float fx = inTexCoord.x;
float dx = -1.0 / texSize.x;
if (inorder > 1.0)
dx = -dx;
vec4 texel1 = swizzle (texture(inTexture0, inTexCoord), in_reorder_idx);
vec4 texel2 = swizzle (texture(inTexture0, inTexCoord + vec2(dx, 0.0)), in_reorder_idx);
vec3 yuv1 = color_convert_texel (texel1.rgb, matrices);
vec3 yuv2 = color_convert_texel (texel2.rgb, matrices);
vec3 yuv;
yuv.x = yuv1.x;
yuv.yz = (yuv1.yz + yuv2.yz) * 0.5;
if (inorder < 1.0)
outColor0 = vec4(yuv[out_reorder_idx[0]], yuv[out_reorder_idx[1]], 0.0, 1.0);
else
outColor0 = vec4(yuv[out_reorder_idx[2]], yuv[out_reorder_idx[3]], 0.0, 1.0);
}
#ifndef _SWIZZLE_H_
#define _SWIZZLE_H_
vec4 swizzle(in vec4 texel, in ivec4 swizzle_idx)
{
return vec4(texel[swizzle_idx[0]], texel[swizzle_idx[1]], texel[swizzle_idx[2]], texel[swizzle_idx[3]]);
}
vec3 swizzle(in vec3 texel, in ivec3 swizzle_idx)
{
return vec3(texel[swizzle_idx[0]], texel[swizzle_idx[1]], texel[swizzle_idx[2]]);
}
#endif
#include "swizzle.glsl"
vec4 upsample_AYUV(in sampler2D tex, in vec2 texCoord, in ivec4 inReorderIdx)
{
vec4 yuva = texture(tex, texCoord);
return swizzle(yuva, inReorderIdx);
}
vec3 upsample_YUY2(in sampler2D tex, in vec2 texCoord, in vec2 texSize, in ivec4 inReorderIdx)
{
vec2 dx = vec2(-1.0 / texSize.x, 0.0);
if (mod (texCoord.x * texSize.x, 2.0) < 1.0) {
dx[1] = -dx[0];
dx[0] = 0.0;
}
vec3 yuv;
yuv.x = texture(tex, texCoord)[inReorderIdx[0]];
/* FIXME: should get cosited sampling right... */
vec4 texel;
texel.xy = texture(tex, texCoord + vec2(dx[0], 0.0)).rg;
texel.zw = texture(tex, texCoord + vec2(dx[1], 0.0)).rg;
yuv.y = texel[inReorderIdx[1]];
yuv.z = texel[inReorderIdx[3]];
return yuv;
}
#version 450 core
#include "yuy2_uyvy_to_rgb.glsl"
layout(location = 0) in vec2 inTexCoord;
layout(set = 0, binding = 0) uniform sampler2D inTexture0;
layout(set = 0, binding = 1) uniform YUVCoefficients_ubo { YUVCoefficients coeff; };
layout(set = 0, binding = 2) uniform TexelOrdering
{
vec2 tex_size;
vec2 poffset;
ivec4 in_reorder_idx;
ivec4 out_reorder_idx;
} ordering;
layout(location = 0) out vec4 outColor0;
void main()
{
float dx;
if (mod (inTexCoord.x * ordering.tex_size.x, 2.0) < 1.0) {
dx = -ordering.poffset.x;
} else {
dx = 0.0;
}
outColor0 = YUY2_UYVY_to_RGB (inTexture0, inTexCoord, dx, coeff, ordering.in_reorder_idx, ordering.out_reorder_idx);
}
#version 450 core
#include "color_convert_generic.glsl"
#include "upsample_yuy2.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;
void main()
{
vec3 yuv = upsample_YUY2 (inTexture0, inTexCoord, texSize, in_reorder_idx);
vec4 rgba = vec4(1.0);
rgba.rgb = color_convert_texel (yuv, matrices);
outColor0 = swizzle(rgba, out_reorder_idx);
}
This diff is collapsed.
......@@ -37,15 +37,23 @@ G_BEGIN_DECLS
typedef struct _GstVulkanColorConvert GstVulkanColorConvert;
typedef struct _GstVulkanColorConvertClass GstVulkanColorConvertClass;
typedef gboolean (*CommandStateUpdate) (GstVulkanColorConvert * conv, VkCommandBuffer cmd, GstVulkanImageMemory ** src_mems, GstVulkanImageMemory ** dest_mems);
#define MAX_PUSH_CONSTANTS 4
struct shader_info
typedef struct _shader_info shader_info;
typedef gboolean (*CommandStateUpdate) (GstVulkanColorConvert * conv, VkCommandBuffer cmd, shader_info * sinfo, GstVulkanImageMemory ** src_mems, GstVulkanImageMemory ** dest_mems);
struct _shader_info
{
GstVideoFormat from;
GstVideoFormat to;
CommandStateUpdate cmd_state_update;
gchar *frag_code;
gsize frag_size;
VkPushConstantRange push_constant_ranges[MAX_PUSH_CONSTANTS];
gsize uniform_size;
GDestroyNotify notify;
gpointer user_data;
};
struct _GstVulkanColorConvert
......@@ -64,7 +72,8 @@ struct _GstVulkanColorConvert
VkDescriptorSetLayoutBinding sampler_layout_binding;
VkDescriptorSetLayoutCreateInfo layout_info;
struct shader_info *current_shader;
shader_info *current_shader;
GstMemory *uniform;
};
struct _GstVulkanColorConvertClass
......
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