nir/nir_lower_tex_shadow: support tex_instr without deref src

Use texture_index if there is no deref src.

Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Reviewed-by: Emma Anholt <emma@anholt.net>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14308>
This commit is contained in:
Christian Gmeiner 2021-12-23 14:41:39 +01:00 committed by Marge Bot
parent e67bca3fe7
commit e5f9cdac1f
1 changed files with 16 additions and 12 deletions

View File

@ -85,15 +85,17 @@ nir_lower_tex_shadow_impl(nir_builder *b, nir_instr *instr, void *options)
tex->is_shadow = false;
int comp_index = nir_tex_instr_src_index(tex, nir_tex_src_comparator);
unsigned sampler_binding = tex->texture_index;
nir_deref_instr *sampler_deref = NULL;
nir_variable *sampler = NULL;
int sampler_index = nir_tex_instr_src_index(tex, nir_tex_src_sampler_deref);
assert(sampler_index >= 0);
sampler_deref = nir_instr_as_deref(tex->src[sampler_index].src.ssa->parent_instr);
sampler = nir_deref_instr_get_variable(sampler_deref);
if (sampler_index >= 0) {
sampler_deref = nir_instr_as_deref(tex->src[sampler_index].src.ssa->parent_instr);
sampler = nir_deref_instr_get_variable(sampler_deref);
sampler_binding = sampler ? sampler->data.binding : 0;
}
/* NIR expects a vec4 result from the above texture instructions */
nir_ssa_dest_init(&tex->instr, &tex->dest, 4, 32, NULL);
@ -107,8 +109,8 @@ nir_lower_tex_shadow_impl(nir_builder *b, nir_instr *instr, void *options)
nir_ssa_def * result =
nir_compare_func(b,
sampler->data.binding < state->n_states ?
state->compare_func[sampler->data.binding] : COMPARE_FUNC_ALWAYS,
sampler_binding < state->n_states ?
state->compare_func[sampler_binding] : COMPARE_FUNC_ALWAYS,
cmp, tex_r);
result = nir_b2f32(b, result);
@ -116,16 +118,18 @@ nir_lower_tex_shadow_impl(nir_builder *b, nir_instr *instr, void *options)
nir_ssa_def *zero = nir_imm_float(b, 0.0);
nir_ssa_def *lookup[6] = {result, NULL, NULL, NULL, zero, one};
nir_ssa_def *r[4] = {lookup[state->tex_swizzles[sampler->data.binding].swizzle_r],
lookup[state->tex_swizzles[sampler->data.binding].swizzle_g],
lookup[state->tex_swizzles[sampler->data.binding].swizzle_b],
lookup[state->tex_swizzles[sampler->data.binding].swizzle_a]
nir_ssa_def *r[4] = {lookup[state->tex_swizzles[sampler_binding].swizzle_r],
lookup[state->tex_swizzles[sampler_binding].swizzle_g],
lookup[state->tex_swizzles[sampler_binding].swizzle_b],
lookup[state->tex_swizzles[sampler_binding].swizzle_a]
};
result = nir_vec(b, r, num_components);
sampler->type = strip_shadow_with_array(sampler->type);
sampler_deref->type = sampler->type;
if (sampler_index >= 0) {
sampler->type = strip_shadow_with_array(sampler->type);
sampler_deref->type = sampler->type;
}
tex->is_shadow = false;
nir_tex_instr_remove_src(tex, comp_index);