d3d12: Switch to nir_lower_fragcolor
Does everything your pass did, with some bug fixes. Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com> Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10411>
This commit is contained in:
parent
c84804f167
commit
aed18bca64
|
@ -848,7 +848,7 @@ select_shader_variant(struct d3d12_selection_context *sel_ctx, d3d12_shader_sele
|
|||
NIR_PASS_V(new_nir_variant, d3d12_add_missing_dual_src_target,
|
||||
key.fs.missing_dual_src_outputs);
|
||||
} else if (key.fs.frag_result_color_lowering) {
|
||||
NIR_PASS_V(new_nir_variant, d3d12_lower_frag_result,
|
||||
NIR_PASS_V(new_nir_variant, nir_lower_fragcolor,
|
||||
key.fs.frag_result_color_lowering);
|
||||
}
|
||||
|
||||
|
|
|
@ -623,73 +623,6 @@ d3d12_lower_bool_input(struct nir_shader *s)
|
|||
lower_bool_input_impl, NULL);
|
||||
}
|
||||
|
||||
static bool
|
||||
lower_color_write(nir_builder *b, struct nir_instr *instr, unsigned nr_cbufs)
|
||||
{
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
if (intr->intrinsic != nir_intrinsic_store_deref)
|
||||
return false;
|
||||
|
||||
nir_deref_instr *deref = nir_instr_as_deref(intr->src[0].ssa->parent_instr);
|
||||
nir_variable *var = nir_deref_instr_get_variable(deref);
|
||||
|
||||
if (var->data.mode != nir_var_shader_out ||
|
||||
var->data.location != FRAG_RESULT_COLOR)
|
||||
return false;
|
||||
|
||||
/* lower the original write to data #0 */
|
||||
var->name = ralloc_strdup(var, "gl_FragData[0]");
|
||||
var->data.location = FRAG_RESULT_DATA0;
|
||||
var->data.driver_location = 0;
|
||||
|
||||
b->cursor = nir_after_instr(&intr->instr);
|
||||
|
||||
/* Then create new variables and write them as well */
|
||||
nir_ssa_def *value = nir_ssa_for_src(b, intr->src[1],
|
||||
nir_src_num_components(intr->src[1]));
|
||||
unsigned writemask = nir_intrinsic_write_mask(intr);
|
||||
for (int i = 1; i < nr_cbufs; ++i) {
|
||||
char name[256];
|
||||
snprintf(name, sizeof(name), "gl_FragData[%d]", i);
|
||||
nir_variable *new_var = nir_variable_create(b->shader,
|
||||
nir_var_shader_out,
|
||||
var->type, name);
|
||||
new_var->data.location = FRAG_RESULT_DATA0 + i;
|
||||
new_var->data.driver_location = i;
|
||||
nir_store_var(b, new_var, value, writemask);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
d3d12_lower_frag_result(struct nir_shader *nir, unsigned nr_cbufs)
|
||||
{
|
||||
bool progress = false;
|
||||
if (nir->info.stage != MESA_SHADER_FRAGMENT)
|
||||
return false;
|
||||
|
||||
nir_foreach_function(function, nir) {
|
||||
if (function->impl) {
|
||||
nir_builder b;
|
||||
nir_builder_init(&b, function->impl);
|
||||
|
||||
nir_foreach_block(block, function->impl) {
|
||||
nir_foreach_instr_safe(instr, block) {
|
||||
progress |= lower_color_write(&b, instr, nr_cbufs);
|
||||
}
|
||||
}
|
||||
|
||||
nir_metadata_preserve(function->impl, nir_metadata_block_index |
|
||||
nir_metadata_dominance);
|
||||
}
|
||||
}
|
||||
return progress;
|
||||
}
|
||||
|
||||
void
|
||||
d3d12_add_missing_dual_src_target(struct nir_shader *s,
|
||||
unsigned missing_mask)
|
||||
|
|
|
@ -63,9 +63,6 @@ d3d12_lower_bool_input(struct nir_shader *s);
|
|||
void
|
||||
d3d12_lower_uint_cast(nir_shader *nir, bool is_signed);
|
||||
|
||||
bool
|
||||
d3d12_lower_frag_result(struct nir_shader *s, unsigned nr_cbufs);
|
||||
|
||||
void
|
||||
d3d12_add_missing_dual_src_target(struct nir_shader *s,
|
||||
unsigned missing_mask);
|
||||
|
|
Loading…
Reference in New Issue