mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 19:40:10 +01:00
microsoft/compiler: Simplify nir_intrinsic_load_front_face handling
It is invalid to have Boolean variables as either shader inputs or outputs, so there is no point to try to lower them in general. The only use for this was some two-phase lowering of nir_intrinsic_load_front_face that could be done in a single phase. Create the SYSTEM_VALUE_FRONT_FACE as a uint and compare it with zero at the same time. No shader-db or fossil-db changes on any Intel platform. v2: Remove dxil_nir_lower_bool_input from dxil_nir.h and drop it from the other caller in the spirv_to_dxil codepath. Noticed by Jesse. Fix setting bit size when loading SYSTEM_VALUE_FRONT_FACE. Caught by CI. v3: Use nir_ine_imm. Change type of gl_FrontFacing GS output in d3d12_nir_passes from Boolean to integer. Both suggested by Jesse. Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15121>
This commit is contained in:
parent
9342c14eeb
commit
1fae751d49
5 changed files with 17 additions and 55 deletions
|
|
@ -132,7 +132,6 @@ compile_nir(struct d3d12_context *ctx, struct d3d12_shader_selector *sel,
|
|||
NIR_PASS_V(nir, d3d12_lower_load_draw_params);
|
||||
NIR_PASS_V(nir, d3d12_lower_load_patch_vertices_in);
|
||||
NIR_PASS_V(nir, d3d12_lower_state_vars, shader);
|
||||
NIR_PASS_V(nir, dxil_nir_lower_bool_input);
|
||||
NIR_PASS_V(nir, dxil_nir_lower_loads_stores_to_dxil);
|
||||
NIR_PASS_V(nir, dxil_nir_lower_atomics_to_dxil);
|
||||
NIR_PASS_V(nir, dxil_nir_lower_double_math);
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ lower_load_face(nir_builder *b, struct nir_instr *instr, nir_variable *var)
|
|||
|
||||
b->cursor = nir_before_instr(&intr->instr);
|
||||
|
||||
nir_ssa_def *load = nir_load_var(b, var);
|
||||
nir_ssa_def *load = nir_ine_imm(b, nir_load_var(b, var), 0);
|
||||
|
||||
nir_ssa_def_rewrite_uses(&intr->dest.ssa, load);
|
||||
nir_instr_remove(instr);
|
||||
|
|
@ -141,7 +141,7 @@ d3d12_forward_front_face(nir_shader *nir)
|
|||
assert(nir->info.stage == MESA_SHADER_FRAGMENT);
|
||||
|
||||
nir_variable *var = nir_variable_create(nir, nir_var_shader_in,
|
||||
glsl_bool_type(),
|
||||
glsl_uint_type(),
|
||||
"gl_FrontFacing");
|
||||
var->data.location = VARYING_SLOT_VAR12;
|
||||
var->data.interpolation = INTERP_MODE_FLAT;
|
||||
|
|
|
|||
|
|
@ -1563,54 +1563,6 @@ dxil_nir_split_typed_samplers(nir_shader *nir)
|
|||
}
|
||||
|
||||
|
||||
static bool
|
||||
lower_bool_input_filter(const nir_instr *instr,
|
||||
UNUSED const void *_options)
|
||||
{
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
if (intr->intrinsic == nir_intrinsic_load_front_face)
|
||||
return true;
|
||||
|
||||
if (intr->intrinsic == nir_intrinsic_load_deref) {
|
||||
nir_deref_instr *deref = nir_instr_as_deref(intr->src[0].ssa->parent_instr);
|
||||
nir_variable *var = nir_deref_instr_get_variable(deref);
|
||||
return var->data.mode == nir_var_shader_in &&
|
||||
glsl_get_base_type(var->type) == GLSL_TYPE_BOOL;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static nir_ssa_def *
|
||||
lower_bool_input_impl(nir_builder *b, nir_instr *instr,
|
||||
UNUSED void *_options)
|
||||
{
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
|
||||
if (intr->intrinsic == nir_intrinsic_load_deref) {
|
||||
nir_deref_instr *deref = nir_instr_as_deref(intr->src[0].ssa->parent_instr);
|
||||
nir_variable *var = nir_deref_instr_get_variable(deref);
|
||||
|
||||
/* rewrite var->type */
|
||||
var->type = glsl_vector_type(GLSL_TYPE_UINT,
|
||||
glsl_get_vector_elements(var->type));
|
||||
deref->type = var->type;
|
||||
}
|
||||
|
||||
intr->dest.ssa.bit_size = 32;
|
||||
return nir_i2b(b, &intr->dest.ssa);
|
||||
}
|
||||
|
||||
bool
|
||||
dxil_nir_lower_bool_input(struct nir_shader *s)
|
||||
{
|
||||
return nir_shader_lower_instructions(s, lower_bool_input_filter,
|
||||
lower_bool_input_impl, NULL);
|
||||
}
|
||||
|
||||
static bool
|
||||
lower_sysval_to_load_input_impl(nir_builder *b, nir_instr *instr, void *data)
|
||||
{
|
||||
|
|
@ -1637,9 +1589,22 @@ lower_sysval_to_load_input_impl(nir_builder *b, nir_instr *instr, void *data)
|
|||
nir_variable *var = sysval_vars[sysval];
|
||||
assert(var);
|
||||
|
||||
const nir_alu_type dest_type = (sysval == SYSTEM_VALUE_FRONT_FACE)
|
||||
? nir_type_uint32 : nir_get_nir_type_for_glsl_type(var->type);
|
||||
const unsigned bit_size = (sysval == SYSTEM_VALUE_FRONT_FACE)
|
||||
? 32 : intr->dest.ssa.bit_size;
|
||||
|
||||
b->cursor = nir_before_instr(instr);
|
||||
nir_ssa_def *result = nir_build_load_input(b, intr->dest.ssa.num_components, intr->dest.ssa.bit_size, nir_imm_int(b, 0),
|
||||
.base = var->data.driver_location, .dest_type = nir_get_nir_type_for_glsl_type(var->type));
|
||||
nir_ssa_def *result = nir_build_load_input(b, intr->dest.ssa.num_components, bit_size, nir_imm_int(b, 0),
|
||||
.base = var->data.driver_location, .dest_type = dest_type);
|
||||
|
||||
/* The nir_type_uint32 is really a nir_type_bool32, but that type is very
|
||||
* inconvenient at this point during compilation. Convert to
|
||||
* nir_type_bool1 by comparing with zero.
|
||||
*/
|
||||
if (sysval == SYSTEM_VALUE_FRONT_FACE)
|
||||
result = nir_ine_imm(b, result, 0);
|
||||
|
||||
nir_ssa_def_rewrite_uses(&intr->dest.ssa, result);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ bool dxil_nir_lower_system_values_to_zero(nir_shader *shader,
|
|||
uint32_t count);
|
||||
bool dxil_nir_lower_system_values(nir_shader *shader);
|
||||
bool dxil_nir_split_typed_samplers(nir_shader *shader);
|
||||
bool dxil_nir_lower_bool_input(struct nir_shader *s);
|
||||
bool dxil_nir_lower_sysval_to_load_input(nir_shader *s, nir_variable **sysval_vars);
|
||||
bool dxil_nir_lower_vs_vertex_conversion(nir_shader *s, enum pipe_format target_formats[]);
|
||||
|
||||
|
|
|
|||
|
|
@ -740,7 +740,6 @@ dxil_spirv_nir_passes(nir_shader *nir,
|
|||
NIR_PASS_V(nir, dxil_nir_split_clip_cull_distance);
|
||||
NIR_PASS_V(nir, dxil_nir_lower_loads_stores_to_dxil);
|
||||
NIR_PASS_V(nir, dxil_nir_split_typed_samplers);
|
||||
NIR_PASS_V(nir, dxil_nir_lower_bool_input);
|
||||
NIR_PASS_V(nir, dxil_nir_lower_ubo_array_one_to_static);
|
||||
NIR_PASS_V(nir, nir_opt_dce);
|
||||
NIR_PASS_V(nir, nir_remove_dead_derefs);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue