diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 48b414cf103..aa86d2f5618 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -5504,13 +5504,17 @@ typedef struct nir_lower_tex_options { * If true, convert yuv to rgb. */ unsigned lower_y_uv_external; + unsigned lower_y_vu_external; unsigned lower_y_u_v_external; unsigned lower_yx_xuxv_external; + unsigned lower_yx_xvxu_external; unsigned lower_xy_uxvx_external; + unsigned lower_xy_vxux_external; unsigned lower_ayuv_external; unsigned lower_xyuv_external; unsigned lower_yuv_external; unsigned lower_yu_yv_external; + unsigned lower_yv_yu_external; unsigned lower_y41x_external; unsigned bt709_external; unsigned bt2020_external; diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c index 2df08d20775..0b2427111a4 100644 --- a/src/compiler/nir/nir_lower_tex.c +++ b/src/compiler/nir/nir_lower_tex.c @@ -404,6 +404,25 @@ lower_y_uv_external(nir_builder *b, nir_tex_instr *tex, texture_index); } +static void +lower_y_vu_external(nir_builder *b, nir_tex_instr *tex, + const nir_lower_tex_options *options, + unsigned texture_index) +{ + b->cursor = nir_after_instr(&tex->instr); + + nir_ssa_def *y = sample_plane(b, tex, 0, options); + nir_ssa_def *vu = sample_plane(b, tex, 1, options); + + convert_yuv_to_rgb(b, tex, + nir_channel(b, y, 0), + nir_channel(b, vu, 1), + nir_channel(b, vu, 0), + nir_imm_float(b, 1.0f), + options, + texture_index); +} + static void lower_y_u_v_external(nir_builder *b, nir_tex_instr *tex, const nir_lower_tex_options *options, @@ -443,6 +462,25 @@ lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex, texture_index); } +static void +lower_yx_xvxu_external(nir_builder *b, nir_tex_instr *tex, + const nir_lower_tex_options *options, + unsigned texture_index) +{ + b->cursor = nir_after_instr(&tex->instr); + + nir_ssa_def *y = sample_plane(b, tex, 0, options); + nir_ssa_def *xvxu = sample_plane(b, tex, 1, options); + + convert_yuv_to_rgb(b, tex, + nir_channel(b, y, 0), + nir_channel(b, xvxu, 3), + nir_channel(b, xvxu, 1), + nir_imm_float(b, 1.0f), + options, + texture_index); +} + static void lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex, const nir_lower_tex_options *options, @@ -462,6 +500,25 @@ lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex, texture_index); } +static void +lower_xy_vxux_external(nir_builder *b, nir_tex_instr *tex, + const nir_lower_tex_options *options, + unsigned texture_index) +{ + b->cursor = nir_after_instr(&tex->instr); + + nir_ssa_def *y = sample_plane(b, tex, 0, options); + nir_ssa_def *vxux = sample_plane(b, tex, 1, options); + + convert_yuv_to_rgb(b, tex, + nir_channel(b, y, 1), + nir_channel(b, vxux, 2), + nir_channel(b, vxux, 0), + nir_imm_float(b, 1.0f), + options, + texture_index); +} + static void lower_ayuv_external(nir_builder *b, nir_tex_instr *tex, const nir_lower_tex_options *options, @@ -552,6 +609,24 @@ lower_yu_yv_external(nir_builder *b, nir_tex_instr *tex, texture_index); } +static void +lower_yv_yu_external(nir_builder *b, nir_tex_instr *tex, + const nir_lower_tex_options *options, + unsigned texture_index) +{ + b->cursor = nir_after_instr(&tex->instr); + + nir_ssa_def *yuv = sample_plane(b, tex, 0, options); + + convert_yuv_to_rgb(b, tex, + nir_channel(b, yuv, 2), + nir_channel(b, yuv, 1), + nir_channel(b, yuv, 0), + nir_imm_float(b, 1.0f), + options, + texture_index); +} + /* * Converts a nir_texop_txd instruction to nir_texop_txl with the given lod * computed from the gradients. @@ -1442,6 +1517,11 @@ nir_lower_tex_block(nir_block *block, nir_builder *b, progress = true; } + if (texture_mask & options->lower_y_vu_external) { + lower_y_vu_external(b, tex, options, texture_index); + progress = true; + } + if (texture_mask & options->lower_y_u_v_external) { lower_y_u_v_external(b, tex, options, texture_index); progress = true; @@ -1452,11 +1532,21 @@ nir_lower_tex_block(nir_block *block, nir_builder *b, progress = true; } + if (texture_mask & options->lower_yx_xvxu_external) { + lower_yx_xvxu_external(b, tex, options, texture_index); + progress = true; + } + if (texture_mask & options->lower_xy_uxvx_external) { lower_xy_uxvx_external(b, tex, options, texture_index); progress = true; } + if (texture_mask & options->lower_xy_vxux_external) { + lower_xy_vxux_external(b, tex, options, texture_index); + progress = true; + } + if (texture_mask & options->lower_ayuv_external) { lower_ayuv_external(b, tex, options, texture_index); progress = true; @@ -1477,6 +1567,11 @@ nir_lower_tex_block(nir_block *block, nir_builder *b, progress = true; } + if ((1 << tex->texture_index) & options->lower_yv_yu_external) { + lower_yv_yu_external(b, tex, options, texture_index); + progress = true; + } + if ((1 << tex->texture_index) & options->lower_y41x_external) { lower_y41x_external(b, tex, options, texture_index); progress = true;