nir/lower_input_attachments: Refactor to use an options struct
While we're at it, fold the details of how to load the fragcoord into load_fragcoord(). Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5719>
This commit is contained in:
@@ -505,7 +505,10 @@ radv_shader_compile_to_nir(struct radv_device *device,
|
|||||||
!radv_use_llvm_for_stage(device, nir->info.stage))
|
!radv_use_llvm_for_stage(device, nir->info.stage))
|
||||||
NIR_PASS_V(nir, nir_lower_io_to_vector, nir_var_shader_out);
|
NIR_PASS_V(nir, nir_lower_io_to_vector, nir_var_shader_out);
|
||||||
if (nir->info.stage == MESA_SHADER_FRAGMENT)
|
if (nir->info.stage == MESA_SHADER_FRAGMENT)
|
||||||
NIR_PASS_V(nir, nir_lower_input_attachments, true);
|
NIR_PASS_V(nir, nir_lower_input_attachments,
|
||||||
|
&(nir_input_attachment_options) {
|
||||||
|
.use_fragcoord_sysval = true,
|
||||||
|
});
|
||||||
|
|
||||||
NIR_PASS_V(nir, nir_remove_dead_variables,
|
NIR_PASS_V(nir, nir_remove_dead_variables,
|
||||||
nir_var_shader_in | nir_var_shader_out | nir_var_system_value | nir_var_mem_shared,
|
nir_var_shader_in | nir_var_shader_out | nir_var_system_value | nir_var_mem_shared,
|
||||||
|
@@ -4458,7 +4458,12 @@ enum nir_lower_idiv_path {
|
|||||||
|
|
||||||
bool nir_lower_idiv(nir_shader *shader, enum nir_lower_idiv_path path);
|
bool nir_lower_idiv(nir_shader *shader, enum nir_lower_idiv_path path);
|
||||||
|
|
||||||
bool nir_lower_input_attachments(nir_shader *shader, bool use_fragcoord_sysval);
|
typedef struct nir_input_attachment_options {
|
||||||
|
bool use_fragcoord_sysval;
|
||||||
|
} nir_input_attachment_options;
|
||||||
|
|
||||||
|
bool nir_lower_input_attachments(nir_shader *shader,
|
||||||
|
const nir_input_attachment_options *options);
|
||||||
|
|
||||||
bool nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables,
|
bool nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables,
|
||||||
bool use_vars,
|
bool use_vars,
|
||||||
|
@@ -25,8 +25,11 @@
|
|||||||
#include "nir_builder.h"
|
#include "nir_builder.h"
|
||||||
|
|
||||||
static nir_ssa_def *
|
static nir_ssa_def *
|
||||||
load_frag_coord(nir_builder *b)
|
load_frag_coord(const nir_input_attachment_options *options, nir_builder *b)
|
||||||
{
|
{
|
||||||
|
if (options->use_fragcoord_sysval)
|
||||||
|
return nir_load_frag_coord(b);
|
||||||
|
|
||||||
nir_variable *pos =
|
nir_variable *pos =
|
||||||
nir_find_variable_with_location(b->shader, nir_var_shader_in,
|
nir_find_variable_with_location(b->shader, nir_var_shader_in,
|
||||||
VARYING_SLOT_POS);
|
VARYING_SLOT_POS);
|
||||||
@@ -49,7 +52,7 @@ load_frag_coord(nir_builder *b)
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
try_lower_input_load(nir_function_impl *impl, nir_intrinsic_instr *load,
|
try_lower_input_load(nir_function_impl *impl, nir_intrinsic_instr *load,
|
||||||
bool use_fragcoord_sysval)
|
const nir_input_attachment_options *options)
|
||||||
{
|
{
|
||||||
nir_deref_instr *deref = nir_src_as_deref(load->src[0]);
|
nir_deref_instr *deref = nir_src_as_deref(load->src[0]);
|
||||||
assert(glsl_type_is_image(deref->type));
|
assert(glsl_type_is_image(deref->type));
|
||||||
@@ -65,8 +68,7 @@ try_lower_input_load(nir_function_impl *impl, nir_intrinsic_instr *load,
|
|||||||
nir_builder_init(&b, impl);
|
nir_builder_init(&b, impl);
|
||||||
b.cursor = nir_instr_remove(&load->instr);
|
b.cursor = nir_instr_remove(&load->instr);
|
||||||
|
|
||||||
nir_ssa_def *frag_coord = use_fragcoord_sysval ? nir_load_frag_coord(&b)
|
nir_ssa_def *frag_coord = load_frag_coord(options, &b);
|
||||||
: load_frag_coord(&b);
|
|
||||||
frag_coord = nir_f2i32(&b, frag_coord);
|
frag_coord = nir_f2i32(&b, frag_coord);
|
||||||
nir_ssa_def *offset = nir_ssa_for_src(&b, load->src[1], 2);
|
nir_ssa_def *offset = nir_ssa_for_src(&b, load->src[1], 2);
|
||||||
nir_ssa_def *pos = nir_iadd(&b, frag_coord, offset);
|
nir_ssa_def *pos = nir_iadd(&b, frag_coord, offset);
|
||||||
@@ -128,7 +130,7 @@ try_lower_input_load(nir_function_impl *impl, nir_intrinsic_instr *load,
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
try_lower_input_texop(nir_function_impl *impl, nir_tex_instr *tex,
|
try_lower_input_texop(nir_function_impl *impl, nir_tex_instr *tex,
|
||||||
bool use_fragcoord_sysval)
|
const nir_input_attachment_options *options)
|
||||||
{
|
{
|
||||||
nir_deref_instr *deref = nir_src_as_deref(tex->src[0].src);
|
nir_deref_instr *deref = nir_src_as_deref(tex->src[0].src);
|
||||||
|
|
||||||
@@ -139,8 +141,7 @@ try_lower_input_texop(nir_function_impl *impl, nir_tex_instr *tex,
|
|||||||
nir_builder_init(&b, impl);
|
nir_builder_init(&b, impl);
|
||||||
b.cursor = nir_before_instr(&tex->instr);
|
b.cursor = nir_before_instr(&tex->instr);
|
||||||
|
|
||||||
nir_ssa_def *frag_coord = use_fragcoord_sysval ? nir_load_frag_coord(&b)
|
nir_ssa_def *frag_coord = load_frag_coord(options, &b);
|
||||||
: load_frag_coord(&b);
|
|
||||||
frag_coord = nir_f2i32(&b, frag_coord);
|
frag_coord = nir_f2i32(&b, frag_coord);
|
||||||
|
|
||||||
nir_ssa_def *layer = nir_load_layer_id(&b);
|
nir_ssa_def *layer = nir_load_layer_id(&b);
|
||||||
@@ -155,7 +156,8 @@ try_lower_input_texop(nir_function_impl *impl, nir_tex_instr *tex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
nir_lower_input_attachments(nir_shader *shader, bool use_fragcoord_sysval)
|
nir_lower_input_attachments(nir_shader *shader,
|
||||||
|
const nir_input_attachment_options *options)
|
||||||
{
|
{
|
||||||
assert(shader->info.stage == MESA_SHADER_FRAGMENT);
|
assert(shader->info.stage == MESA_SHADER_FRAGMENT);
|
||||||
bool progress = false;
|
bool progress = false;
|
||||||
@@ -173,7 +175,7 @@ nir_lower_input_attachments(nir_shader *shader, bool use_fragcoord_sysval)
|
|||||||
if (tex->op == nir_texop_fragment_mask_fetch ||
|
if (tex->op == nir_texop_fragment_mask_fetch ||
|
||||||
tex->op == nir_texop_fragment_fetch) {
|
tex->op == nir_texop_fragment_fetch) {
|
||||||
progress |= try_lower_input_texop(function->impl, tex,
|
progress |= try_lower_input_texop(function->impl, tex,
|
||||||
use_fragcoord_sysval);
|
options);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -182,7 +184,7 @@ nir_lower_input_attachments(nir_shader *shader, bool use_fragcoord_sysval)
|
|||||||
|
|
||||||
if (load->intrinsic == nir_intrinsic_image_deref_load) {
|
if (load->intrinsic == nir_intrinsic_image_deref_load) {
|
||||||
progress |= try_lower_input_load(function->impl, load,
|
progress |= try_lower_input_load(function->impl, load,
|
||||||
use_fragcoord_sysval);
|
options);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -770,8 +770,12 @@ tu_shader_create(struct tu_device *dev,
|
|||||||
NIR_PASS_V(nir, nir_lower_system_values);
|
NIR_PASS_V(nir, nir_lower_system_values);
|
||||||
NIR_PASS_V(nir, nir_lower_frexp);
|
NIR_PASS_V(nir, nir_lower_frexp);
|
||||||
|
|
||||||
if (stage == MESA_SHADER_FRAGMENT)
|
if (stage == MESA_SHADER_FRAGMENT) {
|
||||||
NIR_PASS_V(nir, nir_lower_input_attachments, true);
|
NIR_PASS_V(nir, nir_lower_input_attachments,
|
||||||
|
&(nir_input_attachment_options) {
|
||||||
|
.use_fragcoord_sysval = true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
NIR_PASS_V(nir, nir_lower_explicit_io,
|
NIR_PASS_V(nir, nir_lower_explicit_io,
|
||||||
nir_var_mem_ubo | nir_var_mem_ssbo,
|
nir_var_mem_ubo | nir_var_mem_ssbo,
|
||||||
|
@@ -744,7 +744,10 @@ anv_pipeline_lower_nir(struct anv_pipeline *pipeline,
|
|||||||
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
|
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
|
||||||
NIR_PASS_V(nir, nir_lower_wpos_center,
|
NIR_PASS_V(nir, nir_lower_wpos_center,
|
||||||
anv_pipeline_to_graphics(pipeline)->sample_shading_enable);
|
anv_pipeline_to_graphics(pipeline)->sample_shading_enable);
|
||||||
NIR_PASS_V(nir, nir_lower_input_attachments, true);
|
NIR_PASS_V(nir, nir_lower_input_attachments,
|
||||||
|
&(nir_input_attachment_options) {
|
||||||
|
.use_fragcoord_sysval = true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
NIR_PASS_V(nir, anv_nir_lower_ycbcr_textures, layout);
|
NIR_PASS_V(nir, anv_nir_lower_ycbcr_textures, layout);
|
||||||
|
Reference in New Issue
Block a user