Mesa (staging/21.0): nir/lower_tex: ignore texture_index if tex_instr has deref src
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Apr 6 17:35:38 UTC 2021
Module: Mesa
Branch: staging/21.0
Commit: 1665f478acbd18f35077404ea1d3142e7bbf7536
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=1665f478acbd18f35077404ea1d3142e7bbf7536
Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date: Tue Mar 30 21:37:32 2021 +0200
nir/lower_tex: ignore texture_index if tex_instr has deref src
texture_index is meaningless when a tex_instr has deref src.
Use var->data.binding instead.
This fixes the incorrect lowering on radeonsi where the same
lowering steps was applied to all tex_instr based on the needs
of the first one (since texture_index is always 0).
CC: mesa-stable
Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Acked-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9931>
(cherry picked from commit bc438c91d9b61bbfd3bc2436ee4ab36716540614)
---
.pick_status.json | 2 +-
src/compiler/nir/nir_lower_tex.c | 86 +++++++++++++++++++++++++---------------
2 files changed, 55 insertions(+), 33 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index f542cc01a44..3d8ca785cfc 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -148,7 +148,7 @@
"description": "nir/lower_tex: ignore texture_index if tex_instr has deref src",
"nominated": true,
"nomination_type": 0,
- "resolution": 0,
+ "resolution": 1,
"master_sha": null,
"because_sha": null
},
diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index f5708a62680..644f453109a 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -287,16 +287,17 @@ static void
convert_yuv_to_rgb(nir_builder *b, nir_tex_instr *tex,
nir_ssa_def *y, nir_ssa_def *u, nir_ssa_def *v,
nir_ssa_def *a,
- const nir_lower_tex_options *options)
+ const nir_lower_tex_options *options,
+ unsigned texture_index)
{
const float *offset_vals;
const nir_const_value_3_4 *m;
assert((options->bt709_external & options->bt2020_external) == 0);
- if (options->bt709_external & (1 << tex->texture_index)) {
+ if (options->bt709_external & (1u << texture_index)) {
m = &bt709_csc_coeffs;
offset_vals = bt709_csc_offsets;
- } else if (options->bt2020_external & (1 << tex->texture_index)) {
+ } else if (options->bt2020_external & (1u << texture_index)) {
m = &bt2020_csc_coeffs;
offset_vals = bt2020_csc_offsets;
} else {
@@ -327,7 +328,8 @@ convert_yuv_to_rgb(nir_builder *b, nir_tex_instr *tex,
static void
lower_y_uv_external(nir_builder *b, nir_tex_instr *tex,
- const nir_lower_tex_options *options)
+ const nir_lower_tex_options *options,
+ unsigned texture_index)
{
b->cursor = nir_after_instr(&tex->instr);
@@ -339,12 +341,14 @@ lower_y_uv_external(nir_builder *b, nir_tex_instr *tex,
nir_channel(b, uv, 0),
nir_channel(b, uv, 1),
nir_imm_float(b, 1.0f),
- options);
+ options,
+ texture_index);
}
static void
lower_y_u_v_external(nir_builder *b, nir_tex_instr *tex,
- const nir_lower_tex_options *options)
+ const nir_lower_tex_options *options,
+ unsigned texture_index)
{
b->cursor = nir_after_instr(&tex->instr);
@@ -357,12 +361,14 @@ lower_y_u_v_external(nir_builder *b, nir_tex_instr *tex,
nir_channel(b, u, 0),
nir_channel(b, v, 0),
nir_imm_float(b, 1.0f),
- options);
+ options,
+ texture_index);
}
static void
lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex,
- const nir_lower_tex_options *options)
+ const nir_lower_tex_options *options,
+ unsigned texture_index)
{
b->cursor = nir_after_instr(&tex->instr);
@@ -374,12 +380,14 @@ lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex,
nir_channel(b, xuxv, 1),
nir_channel(b, xuxv, 3),
nir_imm_float(b, 1.0f),
- options);
+ options,
+ texture_index);
}
static void
lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex,
- const nir_lower_tex_options *options)
+ const nir_lower_tex_options *options,
+ unsigned texture_index)
{
b->cursor = nir_after_instr(&tex->instr);
@@ -391,12 +399,14 @@ lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex,
nir_channel(b, uxvx, 0),
nir_channel(b, uxvx, 2),
nir_imm_float(b, 1.0f),
- options);
+ options,
+ texture_index);
}
static void
lower_ayuv_external(nir_builder *b, nir_tex_instr *tex,
- const nir_lower_tex_options *options)
+ const nir_lower_tex_options *options,
+ unsigned texture_index)
{
b->cursor = nir_after_instr(&tex->instr);
@@ -407,12 +417,14 @@ lower_ayuv_external(nir_builder *b, nir_tex_instr *tex,
nir_channel(b, ayuv, 1),
nir_channel(b, ayuv, 0),
nir_channel(b, ayuv, 3),
- options);
+ options,
+ texture_index);
}
static void
lower_xyuv_external(nir_builder *b, nir_tex_instr *tex,
- const nir_lower_tex_options *options)
+ const nir_lower_tex_options *options,
+ unsigned texture_index)
{
b->cursor = nir_after_instr(&tex->instr);
@@ -423,12 +435,14 @@ lower_xyuv_external(nir_builder *b, nir_tex_instr *tex,
nir_channel(b, xyuv, 1),
nir_channel(b, xyuv, 0),
nir_imm_float(b, 1.0f),
- options);
+ options,
+ texture_index);
}
static void
lower_yuv_external(nir_builder *b, nir_tex_instr *tex,
- const nir_lower_tex_options *options)
+ const nir_lower_tex_options *options,
+ unsigned texture_index)
{
b->cursor = nir_after_instr(&tex->instr);
@@ -439,7 +453,8 @@ lower_yuv_external(nir_builder *b, nir_tex_instr *tex,
nir_channel(b, yuv, 1),
nir_channel(b, yuv, 2),
nir_imm_float(b, 1.0f),
- options);
+ options,
+ texture_index);
}
/*
@@ -1052,38 +1067,45 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
progress = true;
}
- if ((1 << tex->texture_index) & options->lower_y_uv_external) {
- lower_y_uv_external(b, tex, options);
+ unsigned texture_index = tex->texture_index;
+ int tex_index = nir_tex_instr_src_index(tex, nir_tex_src_texture_deref);
+ if (tex_index >= 0) {
+ nir_deref_instr *deref = nir_src_as_deref(tex->src[tex_index].src);
+ texture_index = nir_deref_instr_get_variable(deref)->data.binding;
+ }
+
+ if ((1u << texture_index) & options->lower_y_uv_external) {
+ lower_y_uv_external(b, tex, options, texture_index);
progress = true;
}
- if ((1 << tex->texture_index) & options->lower_y_u_v_external) {
- lower_y_u_v_external(b, tex, options);
+ if ((1u << texture_index) & options->lower_y_u_v_external) {
+ lower_y_u_v_external(b, tex, options, texture_index);
progress = true;
}
- if ((1 << tex->texture_index) & options->lower_yx_xuxv_external) {
- lower_yx_xuxv_external(b, tex, options);
+ if ((1u << texture_index) & options->lower_yx_xuxv_external) {
+ lower_yx_xuxv_external(b, tex, options, texture_index);
progress = true;
}
- if ((1 << tex->texture_index) & options->lower_xy_uxvx_external) {
- lower_xy_uxvx_external(b, tex, options);
+ if ((1u << texture_index) & options->lower_xy_uxvx_external) {
+ lower_xy_uxvx_external(b, tex, options, texture_index);
progress = true;
}
- if ((1 << tex->texture_index) & options->lower_ayuv_external) {
- lower_ayuv_external(b, tex, options);
+ if ((1u << texture_index) & options->lower_ayuv_external) {
+ lower_ayuv_external(b, tex, options, texture_index);
progress = true;
}
- if ((1 << tex->texture_index) & options->lower_xyuv_external) {
- lower_xyuv_external(b, tex, options);
+ if ((1u << texture_index) & options->lower_xyuv_external) {
+ lower_xyuv_external(b, tex, options, texture_index);
progress = true;
}
if ((1 << tex->texture_index) & options->lower_yuv_external) {
- lower_yuv_external(b, tex, options);
+ lower_yuv_external(b, tex, options, texture_index);
progress = true;
}
@@ -1097,7 +1119,7 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
progress = true;
}
- if (((1 << tex->texture_index) & options->swizzle_result) &&
+ if (((1u << texture_index) & options->swizzle_result) &&
!nir_tex_instr_is_query(tex) &&
!(tex->is_shadow && tex->is_new_style_shadow)) {
swizzle_result(b, tex, options->swizzles[tex->texture_index]);
@@ -1105,7 +1127,7 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
}
/* should be after swizzle so we know which channels are rgb: */
- if (((1 << tex->texture_index) & options->lower_srgb) &&
+ if (((1u << texture_index) & options->lower_srgb) &&
!nir_tex_instr_is_query(tex) && !tex->is_shadow) {
linearize_srgb_result(b, tex);
progress = true;
More information about the mesa-commit
mailing list