diff --git a/src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c b/src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c index 45ac922fcb2..259e9785855 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c +++ b/src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c @@ -66,6 +66,48 @@ legalize_txd_derivatives(nir_builder *b, nir_tex_instr *tex, UNUSED void *data) return true; } +static bool +legalize_txd_comparator(nir_builder *b, nir_tex_instr *tex, UNUSED void *data) +{ + if (tex->op != nir_texop_txd) + return false; + + if (!tex->is_shadow) + return false; + + b->cursor = nir_before_instr(&tex->instr); + + nir_def *comp = nir_steal_tex_src(tex, nir_tex_src_comparator); + assert(comp); + + int coord_index = nir_tex_instr_src_index(tex, nir_tex_src_coord); + int ddx_index = nir_tex_instr_src_index(tex, nir_tex_src_ddx); + int ddy_index = nir_tex_instr_src_index(tex, nir_tex_src_ddy); + + assert(coord_index >= 0); + assert(ddx_index >= 0); + assert(ddy_index >= 0); + + nir_def *coord = tex->src[coord_index].src.ssa; + nir_def *ddx = tex->src[ddx_index].src.ssa; + nir_def *ddy = tex->src[ddy_index].src.ssa; + + coord = nir_pad_vec4(b, coord); + coord = nir_vector_insert_imm(b, coord, comp, 3); + + /* Make nir validation happy. */ + ddx = nir_pad_vector(b, ddx, tex->is_array ? 3 : 4); + ddy = nir_pad_vector(b, ddy, tex->is_array ? 3 : 4); + + nir_src_rewrite(&tex->src[coord_index].src, coord); + nir_src_rewrite(&tex->src[ddx_index].src, ddx); + nir_src_rewrite(&tex->src[ddy_index].src, ddy); + + tex->coord_components = 4; + + return true; +} + bool etna_nir_lower_texture(nir_shader *s, struct etna_shader_key *key) { @@ -94,5 +136,8 @@ etna_nir_lower_texture(nir_shader *s, struct etna_shader_key *key) NIR_PASS(progress, s, nir_shader_tex_pass, legalize_txd_derivatives, nir_metadata_control_flow, NULL); + NIR_PASS(progress, s, nir_shader_tex_pass, legalize_txd_comparator, + nir_metadata_control_flow, NULL); + return progress; }