diff options
author | Rhys Perry <pendingchaos02@gmail.com> | 2021-04-05 14:56:46 +0100 |
---|---|---|
committer | Dylan Baker <dylan.c.baker@intel.com> | 2021-04-07 10:24:24 -0700 |
commit | c4214ca9db2141785aa876e646ce374315f865df (patch) | |
tree | 99f5b1505392c76aa2d7da7b0000cfefd3a6d317 | |
parent | 89078aeedb039d276e4ca28d547ec3eafea5d128 (diff) |
nir/lower_tex: handle deref casts
A RDR2 shader has a undef->texture cast which is eventually optimized out.
Without handling NULL from nir_deref_instr_get_variable(), compiling this
shader will result in a crash.
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Fixes: bc438c91d9b ("nir/lower_tex: ignore texture_index if tex_instr has deref src")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10038>
(cherry picked from commit 292ac71a4a8eedcccce49bb9440b3b9445aeef91)
-rw-r--r-- | .pick_status.json | 2 | ||||
-rw-r--r-- | src/compiler/nir/nir_lower_tex.c | 23 |
2 files changed, 14 insertions, 11 deletions
diff --git a/.pick_status.json b/.pick_status.json index 105f1031636..f7d3ab67770 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -508,7 +508,7 @@ "description": "nir/lower_tex: handle deref casts", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "master_sha": null, "because_sha": "bc438c91d9b61bbfd3bc2436ee4ab36716540614" }, diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c index 644f453109a..a3c16c16f33 100644 --- a/src/compiler/nir/nir_lower_tex.c +++ b/src/compiler/nir/nir_lower_tex.c @@ -1068,43 +1068,46 @@ nir_lower_tex_block(nir_block *block, nir_builder *b, } unsigned texture_index = tex->texture_index; + uint32_t texture_mask = 1u << 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; + nir_variable *var = nir_deref_instr_get_variable(deref); + texture_index = var ? var->data.binding : 0; + texture_mask = var ? (1u << texture_index) : 0u; } - if ((1u << texture_index) & options->lower_y_uv_external) { + if (texture_mask & options->lower_y_uv_external) { lower_y_uv_external(b, tex, options, texture_index); progress = true; } - if ((1u << texture_index) & options->lower_y_u_v_external) { + if (texture_mask & options->lower_y_u_v_external) { lower_y_u_v_external(b, tex, options, texture_index); progress = true; } - if ((1u << texture_index) & options->lower_yx_xuxv_external) { + if (texture_mask & options->lower_yx_xuxv_external) { lower_yx_xuxv_external(b, tex, options, texture_index); progress = true; } - if ((1u << texture_index) & options->lower_xy_uxvx_external) { + if (texture_mask & options->lower_xy_uxvx_external) { lower_xy_uxvx_external(b, tex, options, texture_index); progress = true; } - if ((1u << texture_index) & options->lower_ayuv_external) { + if (texture_mask & options->lower_ayuv_external) { lower_ayuv_external(b, tex, options, texture_index); progress = true; } - if ((1u << texture_index) & options->lower_xyuv_external) { + if (texture_mask & options->lower_xyuv_external) { lower_xyuv_external(b, tex, options, texture_index); progress = true; } - if ((1 << tex->texture_index) & options->lower_yuv_external) { + if (texture_mask & options->lower_yuv_external) { lower_yuv_external(b, tex, options, texture_index); progress = true; } @@ -1119,7 +1122,7 @@ nir_lower_tex_block(nir_block *block, nir_builder *b, progress = true; } - if (((1u << texture_index) & options->swizzle_result) && + if ((texture_mask & 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]); @@ -1127,7 +1130,7 @@ nir_lower_tex_block(nir_block *block, nir_builder *b, } /* should be after swizzle so we know which channels are rgb: */ - if (((1u << texture_index) & options->lower_srgb) && + if ((texture_mask & options->lower_srgb) && !nir_tex_instr_is_query(tex) && !tex->is_shadow) { linearize_srgb_result(b, tex); progress = true; |