feat(win/video): support native YUV 4:4:4 encoding (#2533)

This commit is contained in:
ns6089 2024-08-16 20:41:27 +03:00 committed by GitHub
commit bfdfcebc80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 1454 additions and 330 deletions

View file

@ -0,0 +1,3 @@
#include "include/convert_base.hlsl"
#include "include/convert_yuv444_ps_base.hlsl"

View file

@ -0,0 +1,3 @@
#include "include/convert_linear_base.hlsl"
#include "include/convert_yuv444_ps_base.hlsl"

View file

@ -0,0 +1,10 @@
cbuffer rotate_texture_steps_cbuffer : register(b1) {
int rotate_texture_steps;
};
#include "include/base_vs.hlsl"
vertex_t main_vs(uint vertex_id : SV_VertexID)
{
return generate_fullscreen_triangle_vertex(vertex_id, rotate_texture_steps);
}

View file

@ -0,0 +1,4 @@
#include "include/convert_base.hlsl"
#define Y410
#include "include/convert_yuv444_ps_base.hlsl"

View file

@ -0,0 +1,4 @@
#include "include/convert_linear_base.hlsl"
#define Y410
#include "include/convert_yuv444_ps_base.hlsl"

View file

@ -0,0 +1,4 @@
#include "include/convert_perceptual_quantizer_base.hlsl"
#define Y410
#include "include/convert_yuv444_ps_base.hlsl"

View file

@ -0,0 +1,4 @@
#include "include/convert_base.hlsl"
#define PLANAR_VIEWPORTS
#include "include/convert_yuv444_ps_base.hlsl"

View file

@ -0,0 +1,4 @@
#include "include/convert_linear_base.hlsl"
#define PLANAR_VIEWPORTS
#include "include/convert_yuv444_ps_base.hlsl"

View file

@ -0,0 +1,4 @@
#include "include/convert_perceptual_quantizer_base.hlsl"
#define PLANAR_VIEWPORTS
#include "include/convert_yuv444_ps_base.hlsl"

View file

@ -0,0 +1,33 @@
cbuffer rotate_texture_steps_cbuffer : register(b1) {
int rotate_texture_steps;
};
cbuffer color_matrix_cbuffer : register(b3) {
float4 color_vec_y;
float4 color_vec_u;
float4 color_vec_v;
float2 range_y;
float2 range_uv;
};
#define PLANAR_VIEWPORTS
#include "include/base_vs.hlsl"
vertex_t main_vs(uint vertex_id : SV_VertexID)
{
vertex_t output = generate_fullscreen_triangle_vertex(vertex_id % 3, rotate_texture_steps);
output.viewport = vertex_id / 3;
if (output.viewport == 0) {
output.color_vec = color_vec_y;
}
else if (output.viewport == 1) {
output.color_vec = color_vec_u;
}
else {
output.color_vec = color_vec_v;
}
return output;
}

View file

@ -19,7 +19,7 @@ vertex_t generate_fullscreen_triangle_vertex(uint vertex_id, int rotate_texture_
output.viewpoint_pos = float4(-1, 3, 0, 1);
tex_coord = float2(0, -1);
}
else if (vertex_id == 2) {
else {
output.viewpoint_pos = float4(3, -1, 0, 1);
tex_coord = float2(2, 1);
}

View file

@ -9,4 +9,8 @@ struct vertex_t
#else
float2 tex_coord : TEXCOORD;
#endif
#ifdef PLANAR_VIEWPORTS
uint viewport : SV_ViewportArrayIndex;
nointerpolation float4 color_vec : COLOR0;
#endif
};

View file

@ -0,0 +1,39 @@
Texture2D image : register(t0);
SamplerState def_sampler : register(s0);
#ifndef PLANAR_VIEWPORTS
cbuffer color_matrix_cbuffer : register(b0) {
float4 color_vec_y;
float4 color_vec_u;
float4 color_vec_v;
float2 range_y;
float2 range_uv;
};
#endif
#include "include/base_vs_types.hlsl"
#ifdef PLANAR_VIEWPORTS
uint main_ps(vertex_t input) : SV_Target
#else
uint4 main_ps(vertex_t input) : SV_Target
#endif
{
float3 rgb = CONVERT_FUNCTION(image.Sample(def_sampler, input.tex_coord, 0).rgb);
#ifdef PLANAR_VIEWPORTS
// Planar R16, 10 most significant bits store the value
return uint(dot(input.color_vec.xyz, rgb) + input.color_vec.w) << 6;
#else
float y = dot(color_vec_y.xyz, rgb) + color_vec_y.w;
float u = dot(color_vec_u.xyz, rgb) + color_vec_u.w;
float v = dot(color_vec_v.xyz, rgb) + color_vec_v.w;
#ifdef Y410
return uint4(u, y, v, 0);
#else
// AYUV
return uint4(v, u, y, 0);
#endif
#endif
}