nir: fill outputs_read field and add patch outputs read (v2)
This is to be used for TCS optimisations on radv. v2: don't set written on reads (nha) Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
@@ -25,7 +25,8 @@
|
|||||||
#include "nir.h"
|
#include "nir.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_io_mask(nir_shader *shader, nir_variable *var, int offset, int len)
|
set_io_mask(nir_shader *shader, nir_variable *var, int offset, int len,
|
||||||
|
bool is_output_read)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
assert(var->data.location != -1);
|
assert(var->data.location != -1);
|
||||||
@@ -58,11 +59,20 @@ set_io_mask(nir_shader *shader, nir_variable *var, int offset, int len)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert(var->data.mode == nir_var_shader_out);
|
assert(var->data.mode == nir_var_shader_out);
|
||||||
if (is_patch_generic) {
|
if (is_output_read) {
|
||||||
shader->info.patch_outputs_written |= bitfield;
|
if (is_patch_generic) {
|
||||||
} else if (!var->data.read_only) {
|
shader->info.patch_outputs_read |= bitfield;
|
||||||
shader->info.outputs_written |= bitfield;
|
} else {
|
||||||
}
|
shader->info.outputs_read |= bitfield;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (is_patch_generic) {
|
||||||
|
shader->info.patch_outputs_written |= bitfield;
|
||||||
|
} else if (!var->data.read_only) {
|
||||||
|
shader->info.outputs_written |= bitfield;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (var->data.fb_fetch_output)
|
if (var->data.fb_fetch_output)
|
||||||
shader->info.outputs_read |= bitfield;
|
shader->info.outputs_read |= bitfield;
|
||||||
@@ -75,7 +85,7 @@ set_io_mask(nir_shader *shader, nir_variable *var, int offset, int len)
|
|||||||
* represents a shader input or output.
|
* represents a shader input or output.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
mark_whole_variable(nir_shader *shader, nir_variable *var)
|
mark_whole_variable(nir_shader *shader, nir_variable *var, bool is_output_read)
|
||||||
{
|
{
|
||||||
const struct glsl_type *type = var->type;
|
const struct glsl_type *type = var->type;
|
||||||
|
|
||||||
@@ -88,7 +98,7 @@ mark_whole_variable(nir_shader *shader, nir_variable *var)
|
|||||||
var->data.compact ? DIV_ROUND_UP(glsl_get_length(type), 4)
|
var->data.compact ? DIV_ROUND_UP(glsl_get_length(type), 4)
|
||||||
: glsl_count_attribute_slots(type, false);
|
: glsl_count_attribute_slots(type, false);
|
||||||
|
|
||||||
set_io_mask(shader, var, 0, slots);
|
set_io_mask(shader, var, 0, slots, is_output_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned
|
static unsigned
|
||||||
@@ -124,7 +134,7 @@ get_io_offset(nir_deref_var *deref)
|
|||||||
* occurs, then nothing will be marked and false will be returned.
|
* occurs, then nothing will be marked and false will be returned.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
try_mask_partial_io(nir_shader *shader, nir_deref_var *deref)
|
try_mask_partial_io(nir_shader *shader, nir_deref_var *deref, bool is_output_read)
|
||||||
{
|
{
|
||||||
nir_variable *var = deref->var;
|
nir_variable *var = deref->var;
|
||||||
const struct glsl_type *type = var->type;
|
const struct glsl_type *type = var->type;
|
||||||
@@ -186,7 +196,7 @@ try_mask_partial_io(nir_shader *shader, nir_deref_var *deref)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_io_mask(shader, var, offset, elem_width);
|
set_io_mask(shader, var, offset, elem_width, is_output_read);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,8 +219,13 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, nir_shader *shader)
|
|||||||
|
|
||||||
if (var->data.mode == nir_var_shader_in ||
|
if (var->data.mode == nir_var_shader_in ||
|
||||||
var->data.mode == nir_var_shader_out) {
|
var->data.mode == nir_var_shader_out) {
|
||||||
if (!try_mask_partial_io(shader, instr->variables[0]))
|
bool is_output_read = false;
|
||||||
mark_whole_variable(shader, var);
|
if (var->data.mode == nir_var_shader_out &&
|
||||||
|
instr->intrinsic == nir_intrinsic_load_var)
|
||||||
|
is_output_read = true;
|
||||||
|
|
||||||
|
if (!try_mask_partial_io(shader, instr->variables[0], is_output_read))
|
||||||
|
mark_whole_variable(shader, var, is_output_read);
|
||||||
|
|
||||||
/* We need to track which input_reads bits correspond to a
|
/* We need to track which input_reads bits correspond to a
|
||||||
* dvec3/dvec4 input attribute */
|
* dvec3/dvec4 input attribute */
|
||||||
@@ -340,6 +355,7 @@ nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint)
|
|||||||
shader->info.inputs_read = 0;
|
shader->info.inputs_read = 0;
|
||||||
shader->info.outputs_written = 0;
|
shader->info.outputs_written = 0;
|
||||||
shader->info.outputs_read = 0;
|
shader->info.outputs_read = 0;
|
||||||
|
shader->info.patch_outputs_read = 0;
|
||||||
shader->info.double_inputs_read = 0;
|
shader->info.double_inputs_read = 0;
|
||||||
shader->info.patch_inputs_read = 0;
|
shader->info.patch_inputs_read = 0;
|
||||||
shader->info.patch_outputs_written = 0;
|
shader->info.patch_outputs_written = 0;
|
||||||
|
@@ -66,6 +66,8 @@ typedef struct shader_info {
|
|||||||
uint32_t patch_inputs_read;
|
uint32_t patch_inputs_read;
|
||||||
/* Which patch outputs are actually written */
|
/* Which patch outputs are actually written */
|
||||||
uint32_t patch_outputs_written;
|
uint32_t patch_outputs_written;
|
||||||
|
/* Which patch outputs are read */
|
||||||
|
uint32_t patch_outputs_read;
|
||||||
|
|
||||||
/* Whether or not this shader ever uses textureGather() */
|
/* Whether or not this shader ever uses textureGather() */
|
||||||
bool uses_texture_gather;
|
bool uses_texture_gather;
|
||||||
|
Reference in New Issue
Block a user