From: Ilia Mirkin Date: Mon, 2 Mar 2020 02:55:59 +0000 (-0500) Subject: st/mesa: allow TXB2/TXL2 to work with cube array shadow textures X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=11a06dfd4ba4351848422eba357a8b41dd3b78df;p=mesa.git st/mesa: allow TXB2/TXL2 to work with cube array shadow textures It's a bit asymmetric, but it's such a contrived use-case, and not a lot of drivers will support it. Signed-off-by: Ilia Mirkin Reviewed-by: Dave Airlie Part-of: --- diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst index e053e821ecd..1e80edb8f07 100644 --- a/src/gallium/docs/source/tgsi.rst +++ b/src/gallium/docs/source/tgsi.rst @@ -735,7 +735,8 @@ This instruction replicates its result. Presumably shadow 2d arrays and shadow 3d targets could use this encoding too, but this is not legal. - shadow cube map arrays are neither possible nor required. + if the target is a shadow cube map array, the reference value is in + src1.y. .. math:: @@ -826,7 +827,8 @@ This instruction replicates its result. Presumably shadow 3d / 2d array / cube targets could use this encoding too, but this is not legal. - shadow cube map arrays are neither possible nor required. + if the target is a shadow cube map array, the reference value is in + src1.y. .. math:: diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 952327a3b20..6c531ca5365 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -4300,14 +4300,13 @@ glsl_to_tgsi_visitor::visit(ir_texture *ir) enum tgsi_opcode opcode = TGSI_OPCODE_NOP; const glsl_type *sampler_type = ir->sampler->type; unsigned sampler_array_size = 1, sampler_base = 0; - bool is_cube_array = false, is_cube_shadow = false; + bool is_cube_array = false; ir_variable *var = ir->sampler->variable_referenced(); unsigned i; /* if we are a cube array sampler or a cube shadow */ if (sampler_type->sampler_dimensionality == GLSL_SAMPLER_DIM_CUBE) { is_cube_array = sampler_type->sampler_array; - is_cube_shadow = sampler_type->sampler_shadow; } if (ir->coordinate) { @@ -4345,7 +4344,8 @@ glsl_to_tgsi_visitor::visit(ir_texture *ir) } break; case ir_txb: - if (is_cube_array || is_cube_shadow) { + if (is_cube_array || + (sampler_type->sampler_shadow && sampler_type->coordinate_components() >= 3)) { opcode = TGSI_OPCODE_TXB2; } else { @@ -4362,7 +4362,7 @@ glsl_to_tgsi_visitor::visit(ir_texture *ir) if (this->has_tex_txf_lz && ir->lod_info.lod->is_zero()) { opcode = TGSI_OPCODE_TEX_LZ; } else { - opcode = is_cube_array ? TGSI_OPCODE_TXL2 : TGSI_OPCODE_TXL; + opcode = (is_cube_array || (sampler_type->sampler_shadow && sampler_type->coordinate_components() >= 3)) ? TGSI_OPCODE_TXL2 : TGSI_OPCODE_TXL; ir->lod_info.lod->accept(this); lod_info = this->result; } @@ -4500,11 +4500,21 @@ glsl_to_tgsi_visitor::visit(ir_texture *ir) ir->shadow_comparator->accept(this); if (is_cube_array) { - cube_sc = get_temp(glsl_type::float_type); - cube_sc_dst = st_dst_reg(cube_sc); - cube_sc_dst.writemask = WRITEMASK_X; + if (lod_info.file != PROGRAM_UNDEFINED) { + // If we have both a cube array *and* a bias/lod, stick the + // comparator into the .Y of the second argument. + st_src_reg tmp = get_temp(glsl_type::vec2_type); + cube_sc_dst = st_dst_reg(tmp); + cube_sc_dst.writemask = WRITEMASK_X; + emit_asm(ir, TGSI_OPCODE_MOV, cube_sc_dst, lod_info); + lod_info = tmp; + cube_sc_dst.writemask = WRITEMASK_Y; + } else { + cube_sc = get_temp(glsl_type::float_type); + cube_sc_dst = st_dst_reg(cube_sc); + cube_sc_dst.writemask = WRITEMASK_X; + } emit_asm(ir, TGSI_OPCODE_MOV, cube_sc_dst, this->result); - cube_sc_dst.writemask = WRITEMASK_X; } else { if ((sampler_type->sampler_dimensionality == GLSL_SAMPLER_DIM_2D &&