summaryrefslogtreecommitdiffstats
path: root/src/compiler
diff options
context:
space:
mode:
authorTapani Pälli <[email protected]>2019-02-11 09:25:18 +0200
committerTapani Pälli <[email protected]>2019-02-12 08:41:20 +0200
commit19a85a704bb163c80e9c87aa5a03da1e6574a8dd (patch)
treea50ec98791e3d5d758406b59792481c86b3c3014 /src/compiler
parent3eedc8f7b144c6bc21301a551763a53884c60fa1 (diff)
nir: add option to use scaling factor when sampling planes YUV lowering
Patch adds nir_lower_tex_options as parameter to sample_plane so that we don't need to extend nir_tex_instr for this. Signed-off-by: Tapani Pälli <[email protected]> Reviewed-by: Lionel Landwerlin <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/nir/nir.h3
-rw-r--r--src/compiler/nir/nir_lower_tex.c53
2 files changed, 35 insertions, 21 deletions
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 264e8cfee83..353a1604785 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -3095,6 +3095,9 @@ typedef struct nir_lower_tex_options {
*/
uint8_t swizzles[32][4];
+ /* Can be used to scale sampled values in range required by the format. */
+ float scale_factors[32];
+
/**
* Bitmap of textures that need srgb to linear conversion. If
* (lower_srgb & (1 << texture_index)) then the rgb (xyz) components
diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index a618b86b34c..c9fe0d74f6c 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -306,7 +306,8 @@ lower_implicit_lod(nir_builder *b, nir_tex_instr *tex)
}
static nir_ssa_def *
-sample_plane(nir_builder *b, nir_tex_instr *tex, int plane)
+sample_plane(nir_builder *b, nir_tex_instr *tex, int plane,
+ const nir_lower_tex_options *options)
{
assert(tex->dest.is_ssa);
assert(nir_tex_instr_dest_size(tex) == 4);
@@ -334,6 +335,11 @@ sample_plane(nir_builder *b, nir_tex_instr *tex, int plane)
nir_builder_instr_insert(b, &plane_tex->instr);
+ /* If scaling_factor is set, return a scaled value. */
+ if (options->scale_factors[tex->texture_index])
+ return nir_fmul_imm(b, &plane_tex->dest.ssa,
+ options->scale_factors[tex->texture_index]);
+
return &plane_tex->dest.ssa;
}
@@ -366,12 +372,13 @@ convert_yuv_to_rgb(nir_builder *b, nir_tex_instr *tex,
}
static void
-lower_y_uv_external(nir_builder *b, nir_tex_instr *tex)
+lower_y_uv_external(nir_builder *b, nir_tex_instr *tex,
+ const nir_lower_tex_options *options)
{
b->cursor = nir_after_instr(&tex->instr);
- nir_ssa_def *y = sample_plane(b, tex, 0);
- nir_ssa_def *uv = sample_plane(b, tex, 1);
+ nir_ssa_def *y = sample_plane(b, tex, 0, options);
+ nir_ssa_def *uv = sample_plane(b, tex, 1, options);
convert_yuv_to_rgb(b, tex,
nir_channel(b, y, 0),
@@ -381,13 +388,14 @@ lower_y_uv_external(nir_builder *b, nir_tex_instr *tex)
}
static void
-lower_y_u_v_external(nir_builder *b, nir_tex_instr *tex)
+lower_y_u_v_external(nir_builder *b, nir_tex_instr *tex,
+ const nir_lower_tex_options *options)
{
b->cursor = nir_after_instr(&tex->instr);
- nir_ssa_def *y = sample_plane(b, tex, 0);
- nir_ssa_def *u = sample_plane(b, tex, 1);
- nir_ssa_def *v = sample_plane(b, tex, 2);
+ nir_ssa_def *y = sample_plane(b, tex, 0, options);
+ nir_ssa_def *u = sample_plane(b, tex, 1, options);
+ nir_ssa_def *v = sample_plane(b, tex, 2, options);
convert_yuv_to_rgb(b, tex,
nir_channel(b, y, 0),
@@ -397,12 +405,13 @@ lower_y_u_v_external(nir_builder *b, nir_tex_instr *tex)
}
static void
-lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex)
+lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex,
+ const nir_lower_tex_options *options)
{
b->cursor = nir_after_instr(&tex->instr);
- nir_ssa_def *y = sample_plane(b, tex, 0);
- nir_ssa_def *xuxv = sample_plane(b, tex, 1);
+ nir_ssa_def *y = sample_plane(b, tex, 0, options);
+ nir_ssa_def *xuxv = sample_plane(b, tex, 1, options);
convert_yuv_to_rgb(b, tex,
nir_channel(b, y, 0),
@@ -412,12 +421,13 @@ lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex)
}
static void
-lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex)
+lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex,
+ const nir_lower_tex_options *options)
{
b->cursor = nir_after_instr(&tex->instr);
- nir_ssa_def *y = sample_plane(b, tex, 0);
- nir_ssa_def *uxvx = sample_plane(b, tex, 1);
+ nir_ssa_def *y = sample_plane(b, tex, 0, options);
+ nir_ssa_def *uxvx = sample_plane(b, tex, 1, options);
convert_yuv_to_rgb(b, tex,
nir_channel(b, y, 1),
@@ -427,11 +437,12 @@ lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex)
}
static void
-lower_ayuv_external(nir_builder *b, nir_tex_instr *tex)
+lower_ayuv_external(nir_builder *b, nir_tex_instr *tex,
+ const nir_lower_tex_options *options)
{
b->cursor = nir_after_instr(&tex->instr);
- nir_ssa_def *ayuv = sample_plane(b, tex, 0);
+ nir_ssa_def *ayuv = sample_plane(b, tex, 0, options);
convert_yuv_to_rgb(b, tex,
nir_channel(b, ayuv, 2),
@@ -923,27 +934,27 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
}
if ((1 << tex->texture_index) & options->lower_y_uv_external) {
- lower_y_uv_external(b, tex);
+ lower_y_uv_external(b, tex, options);
progress = true;
}
if ((1 << tex->texture_index) & options->lower_y_u_v_external) {
- lower_y_u_v_external(b, tex);
+ lower_y_u_v_external(b, tex, options);
progress = true;
}
if ((1 << tex->texture_index) & options->lower_yx_xuxv_external) {
- lower_yx_xuxv_external(b, tex);
+ lower_yx_xuxv_external(b, tex, options);
progress = true;
}
if ((1 << tex->texture_index) & options->lower_xy_uxvx_external) {
- lower_xy_uxvx_external(b, tex);
+ lower_xy_uxvx_external(b, tex, options);
progress = true;
}
if ((1 << tex->texture_index) & options->lower_ayuv_external) {
- lower_ayuv_external(b, tex);
+ lower_ayuv_external(b, tex, options);
progress = true;
}