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:
parent
e67bca3fe7
commit
e5f9cdac1f
|
@ -85,15 +85,17 @@ nir_lower_tex_shadow_impl(nir_builder *b, nir_instr *instr, void *options)
|
||||||
tex->is_shadow = false;
|
tex->is_shadow = false;
|
||||||
|
|
||||||
int comp_index = nir_tex_instr_src_index(tex, nir_tex_src_comparator);
|
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_deref_instr *sampler_deref = NULL;
|
||||||
nir_variable *sampler = NULL;
|
nir_variable *sampler = NULL;
|
||||||
|
|
||||||
int sampler_index = nir_tex_instr_src_index(tex, nir_tex_src_sampler_deref);
|
int sampler_index = nir_tex_instr_src_index(tex, nir_tex_src_sampler_deref);
|
||||||
assert(sampler_index >= 0);
|
if (sampler_index >= 0) {
|
||||||
|
|
||||||
sampler_deref = nir_instr_as_deref(tex->src[sampler_index].src.ssa->parent_instr);
|
sampler_deref = nir_instr_as_deref(tex->src[sampler_index].src.ssa->parent_instr);
|
||||||
sampler = nir_deref_instr_get_variable(sampler_deref);
|
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 expects a vec4 result from the above texture instructions */
|
||||||
nir_ssa_dest_init(&tex->instr, &tex->dest, 4, 32, NULL);
|
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_ssa_def * result =
|
||||||
nir_compare_func(b,
|
nir_compare_func(b,
|
||||||
sampler->data.binding < state->n_states ?
|
sampler_binding < state->n_states ?
|
||||||
state->compare_func[sampler->data.binding] : COMPARE_FUNC_ALWAYS,
|
state->compare_func[sampler_binding] : COMPARE_FUNC_ALWAYS,
|
||||||
cmp, tex_r);
|
cmp, tex_r);
|
||||||
|
|
||||||
result = nir_b2f32(b, result);
|
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 *zero = nir_imm_float(b, 0.0);
|
||||||
|
|
||||||
nir_ssa_def *lookup[6] = {result, NULL, NULL, NULL, zero, one};
|
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],
|
nir_ssa_def *r[4] = {lookup[state->tex_swizzles[sampler_binding].swizzle_r],
|
||||||
lookup[state->tex_swizzles[sampler->data.binding].swizzle_g],
|
lookup[state->tex_swizzles[sampler_binding].swizzle_g],
|
||||||
lookup[state->tex_swizzles[sampler->data.binding].swizzle_b],
|
lookup[state->tex_swizzles[sampler_binding].swizzle_b],
|
||||||
lookup[state->tex_swizzles[sampler->data.binding].swizzle_a]
|
lookup[state->tex_swizzles[sampler_binding].swizzle_a]
|
||||||
};
|
};
|
||||||
|
|
||||||
result = nir_vec(b, r, num_components);
|
result = nir_vec(b, r, num_components);
|
||||||
|
|
||||||
|
if (sampler_index >= 0) {
|
||||||
sampler->type = strip_shadow_with_array(sampler->type);
|
sampler->type = strip_shadow_with_array(sampler->type);
|
||||||
sampler_deref->type = sampler->type;
|
sampler_deref->type = sampler->type;
|
||||||
|
}
|
||||||
|
|
||||||
tex->is_shadow = false;
|
tex->is_shadow = false;
|
||||||
nir_tex_instr_remove_src(tex, comp_index);
|
nir_tex_instr_remove_src(tex, comp_index);
|
||||||
|
|
Loading…
Reference in New Issue