microsoft/compiler: Load synthesized sysvals via lowered io

Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14175>
This commit is contained in:
Jesse Natalie 2021-12-11 10:49:21 -08:00
parent 8d5b7450a4
commit 64991d44a8
3 changed files with 44 additions and 45 deletions

View File

@ -1617,6 +1617,46 @@ dxil_nir_lower_bool_input(struct nir_shader *s)
lower_bool_input_impl, NULL);
}
static bool
lower_sysval_to_load_input_impl(nir_builder *b, nir_instr *instr, void *data)
{
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
gl_system_value sysval = SYSTEM_VALUE_MAX;
switch (intr->intrinsic) {
case nir_intrinsic_load_front_face:
sysval = SYSTEM_VALUE_FRONT_FACE;
break;
case nir_intrinsic_load_instance_id:
sysval = SYSTEM_VALUE_INSTANCE_ID;
break;
case nir_intrinsic_load_vertex_id_zero_base:
sysval = SYSTEM_VALUE_VERTEX_ID_ZERO_BASE;
break;
default:
return false;
}
nir_variable **sysval_vars = (nir_variable **)data;
nir_variable *var = sysval_vars[sysval];
assert(var);
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_rewrite_uses(&intr->dest.ssa, result);
return true;
}
bool
dxil_nir_lower_sysval_to_load_input(nir_shader *s, nir_variable **sysval_vars)
{
return nir_shader_instructions_pass(s, lower_sysval_to_load_input_impl,
nir_metadata_block_index | nir_metadata_dominance, sysval_vars);
}
/* Comparison function to sort io values so that first come normal varyings,
* then system values, and then system generated values.
*/

View File

@ -50,6 +50,7 @@ bool dxil_nir_lower_system_values_to_zero(nir_shader *shader,
uint32_t count);
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);
nir_ssa_def *
build_load_ubo_dxil(nir_builder *b, nir_ssa_def *buffer,

View File

@ -2728,42 +2728,6 @@ emit_store_output_via_intrinsic(struct ntd_context *ctx, nir_intrinsic_instr *in
return success;
}
static bool
emit_load_input_interpolated(struct ntd_context *ctx, nir_intrinsic_instr *intr, nir_variable *var)
{
assert(var);
const struct dxil_value *opcode = dxil_module_get_int32_const(&ctx->mod, DXIL_INTR_LOAD_INPUT);
const struct dxil_value *input_id = dxil_module_get_int32_const(&ctx->mod, var->data.driver_location);
const struct dxil_value *row = dxil_module_get_int32_const(&ctx->mod, 0);
const struct dxil_type *int32_type = dxil_module_get_int_type(&ctx->mod, 32);
const struct dxil_value *vertex_id = dxil_module_get_undef(&ctx->mod, int32_type);
if (!opcode || !input_id || !row || !int32_type || !vertex_id)
return false;
nir_alu_type out_type = nir_get_nir_type_for_glsl_base_type(glsl_get_base_type(var->type));
enum overload_type overload = get_overload(out_type, glsl_get_bit_size(var->type));
const struct dxil_func *func = dxil_get_function(&ctx->mod, "dx.op.loadInput", overload);
if (!func)
return false;
for (unsigned i = 0; i < nir_dest_num_components(intr->dest); ++i) {
const struct dxil_value *comp = dxil_module_get_int8_const(&ctx->mod, i);
const struct dxil_value *args[] = {
opcode, input_id, row, comp, vertex_id
};
const struct dxil_value *retval = dxil_emit_call(&ctx->mod, func, args, ARRAY_SIZE(args));
if (!retval)
return false;
store_dest(ctx, &intr->dest, i, retval, out_type);
}
return true;
}
static bool
emit_load_input_via_intrinsic(struct ntd_context *ctx, nir_intrinsic_instr *intr)
{
@ -3460,15 +3424,6 @@ emit_intrinsic(struct ntd_context *ctx, nir_intrinsic_instr *intr)
return emit_load_ubo(ctx, intr);
case nir_intrinsic_load_ubo_dxil:
return emit_load_ubo_dxil(ctx, intr);
case nir_intrinsic_load_front_face:
return emit_load_input_interpolated(ctx, intr,
ctx->system_value[SYSTEM_VALUE_FRONT_FACE]);
case nir_intrinsic_load_vertex_id_zero_base:
return emit_load_input_interpolated(ctx, intr,
ctx->system_value[SYSTEM_VALUE_VERTEX_ID_ZERO_BASE]);
case nir_intrinsic_load_instance_id:
return emit_load_input_interpolated(ctx, intr,
ctx->system_value[SYSTEM_VALUE_INSTANCE_ID]);
case nir_intrinsic_load_primitive_id:
return emit_load_unary_external_function(ctx, intr, "dx.op.primitiveID",
DXIL_INTR_PRIMITIVE_ID);
@ -4778,6 +4733,9 @@ nir_to_dxil(struct nir_shader *s, const struct nir_to_dxil_options *opts,
if (!allocate_sysvalues(ctx))
return false;
NIR_PASS_V(s, dxil_nir_lower_sysval_to_load_input, ctx->system_value);
NIR_PASS_V(s, nir_opt_dce);
if (debug_dxil & DXIL_DEBUG_VERBOSE)
nir_print_shader(s, stderr);