Commit 7100a06a authored by Louis-Francis Ratté-Boulianne's avatar Louis-Francis Ratté-Boulianne Committed by Erik Faye-Lund
Browse files

d3d12: Only create variables once in triangle strip lowering pass

parent 02a38478
......@@ -736,7 +736,7 @@ d3d12_lower_primitive_id(nir_shader *shader)
static void
lower_triangle_strip_store(nir_builder *b, nir_intrinsic_instr *intr,
nir_variable *vertex_count_var,
nir_deref_instr **varyings)
nir_variable **varyings)
{
/**
* tmp_varying[slot][min(vertex_count, 2)] = src
......@@ -748,7 +748,7 @@ lower_triangle_strip_store(nir_builder *b, nir_intrinsic_instr *intr,
if (var->data.mode != nir_var_shader_out)
return;
nir_deref_instr *deref = nir_build_deref_array(b, varyings[var->data.location], index);
nir_deref_instr *deref = nir_build_deref_array(b, nir_build_deref_var(b, varyings[var->data.location]), index);
nir_ssa_def *value = nir_ssa_for_src(b, intr->src[1], intr->num_components);
nir_store_deref(b, deref, value, 0xf);
nir_instr_remove(&intr->instr);
......@@ -767,8 +767,8 @@ nir_emit_vertex(nir_builder *b, unsigned stream_id)
static void
lower_triangle_strip_emit_vertex(nir_builder *b, nir_intrinsic_instr *intr,
nir_variable *vertex_count_var,
nir_deref_instr **varyings,
nir_deref_instr **out_varyings)
nir_variable **varyings,
nir_variable **out_varyings)
{
// TODO xfb + flat shading + last_pv
/**
......@@ -795,7 +795,8 @@ lower_triangle_strip_emit_vertex(nir_builder *b, nir_intrinsic_instr *intr,
for (int i = 0; i < VARYING_SLOT_MAX; ++i) {
if (!varyings[i])
continue;
nir_copy_deref(b, out_varyings[i], nir_build_deref_array_imm(b, varyings[i], j));
nir_copy_deref(b, nir_build_deref_var(b, out_varyings[i]),
nir_build_deref_array_imm(b, nir_build_deref_var(b, varyings[i]), j));
}
nir_emit_vertex(b, 0);
}
......@@ -803,8 +804,8 @@ lower_triangle_strip_emit_vertex(nir_builder *b, nir_intrinsic_instr *intr,
for (int i = 0; i < VARYING_SLOT_MAX; ++i) {
if (!varyings[i])
continue;
nir_copy_deref(b, nir_build_deref_array(b, varyings[i], nir_umod(b, vertex_count, two)),
nir_build_deref_array(b, varyings[i], two));
nir_copy_deref(b, nir_build_deref_array(b, nir_build_deref_var(b, varyings[i]), nir_umod(b, vertex_count, two)),
nir_build_deref_array(b, nir_build_deref_var(b, varyings[i]), two));
}
instr = nir_intrinsic_instr_create(b->shader, nir_intrinsic_end_primitive);
......@@ -835,27 +836,25 @@ d3d12_lower_triangle_strip(nir_shader *shader)
{
nir_builder b;
nir_function_impl *impl = nir_shader_get_entrypoint(shader);
nir_deref_instr *tmp_vars[VARYING_SLOT_MAX] = {0};
nir_deref_instr *out_vars[VARYING_SLOT_MAX] = {0};
nir_variable *tmp_vars[VARYING_SLOT_MAX] = {0};
nir_variable *out_vars[VARYING_SLOT_MAX] = {0};
nir_builder_init(&b, impl);
shader->info.gs.vertices_out = (shader->info.gs.vertices_out - 2) * 3;
nir_foreach_block(block, impl) {
b.cursor = nir_before_block(block);
uint64_t outputs_written = shader->info.outputs_written;
nir_foreach_variable(var, &b.shader->outputs) {
const struct glsl_type *type = glsl_array_type(var->type, 3, 0);
tmp_vars[var->data.location] = nir_build_deref_var(&b, nir_local_variable_create(impl, type, "tmp_var"));
out_vars[var->data.location] = nir_build_deref_var(&b, var);
}
nir_variable *vertex_count_var =
nir_local_variable_create(impl, glsl_uint_type(), "vertex_count");
/* Temporary variable */
nir_variable *vertex_count_var =
nir_local_variable_create(impl, glsl_uint_type(), "vertex_count");
nir_store_var(&b, vertex_count_var, nir_imm_int(&b, 0), 1);
nir_block *first = nir_start_block(impl);
b.cursor = nir_before_block(first);
nir_foreach_variable(var, &b.shader->outputs) {
const struct glsl_type *type = glsl_array_type(var->type, 3, 0);
tmp_vars[var->data.location] = nir_local_variable_create(impl, type, "tmp_var");
out_vars[var->data.location] = var;
}
nir_store_var(&b, vertex_count_var, nir_imm_int(&b, 0), 1);
nir_foreach_block(block, impl) {
nir_foreach_instr_safe(instr, block) {
if (instr->type != nir_instr_type_intrinsic)
continue;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment