nir: Pass a type_size() function pointer into nir_lower_io().
Previously, there were four type_size() functions in play - the i965 compiler backend defined scalar and vec4 type_size() functions, and nir_lower_io contained its own similar functions. In fact, the i965 driver used nir_lower_io() and then looped over the components using its own type_size - meaning both were in play. The two are /basically/ the same, but not exactly in obscure cases like subroutines and images. This patch removes nir_lower_io's functions, and instead makes the driver supply a function pointer. This gives the driver ultimate flexibility in deciding how it wants to count things, reduces code duplication, and improves consistency. v2 (Jason Ekstrand): - One side-effect of passing in a function pointer is that nir_lower_io is now aware of and properly allocates space for image uniforms, allowing us to drop hacks in the backend Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com> v2 Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:

committed by
Jason Ekstrand

parent
a23f82053d
commit
6c33d6bbf9
@@ -1632,15 +1632,15 @@ void nir_lower_locals_to_regs(nir_shader *shader);
|
|||||||
|
|
||||||
void nir_assign_var_locations(struct exec_list *var_list,
|
void nir_assign_var_locations(struct exec_list *var_list,
|
||||||
unsigned *size,
|
unsigned *size,
|
||||||
bool is_scalar);
|
int (*type_size)(const struct glsl_type *));
|
||||||
void nir_assign_var_locations_direct_first(nir_shader *shader,
|
void nir_assign_var_locations_direct_first(nir_shader *shader,
|
||||||
struct exec_list *var_list,
|
struct exec_list *var_list,
|
||||||
unsigned *direct_size,
|
unsigned *direct_size,
|
||||||
unsigned *size,
|
unsigned *size,
|
||||||
bool is_scalar);
|
int (*type_size)(const struct glsl_type *));
|
||||||
|
|
||||||
void nir_lower_io(nir_shader *shader, bool is_scalar);
|
|
||||||
|
|
||||||
|
void nir_lower_io(nir_shader *shader,
|
||||||
|
int (*type_size)(const struct glsl_type *));
|
||||||
void nir_lower_vars_to_ssa(nir_shader *shader);
|
void nir_lower_vars_to_ssa(nir_shader *shader);
|
||||||
|
|
||||||
void nir_remove_dead_variables(nir_shader *shader);
|
void nir_remove_dead_variables(nir_shader *shader);
|
||||||
|
@@ -37,99 +37,12 @@
|
|||||||
struct lower_io_state {
|
struct lower_io_state {
|
||||||
nir_builder builder;
|
nir_builder builder;
|
||||||
void *mem_ctx;
|
void *mem_ctx;
|
||||||
bool is_scalar;
|
int (*type_size)(const struct glsl_type *type);
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
|
||||||
type_size_vec4(const struct glsl_type *type)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
switch (glsl_get_base_type(type)) {
|
|
||||||
case GLSL_TYPE_UINT:
|
|
||||||
case GLSL_TYPE_INT:
|
|
||||||
case GLSL_TYPE_FLOAT:
|
|
||||||
case GLSL_TYPE_BOOL:
|
|
||||||
if (glsl_type_is_matrix(type)) {
|
|
||||||
return glsl_get_matrix_columns(type);
|
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
case GLSL_TYPE_ARRAY:
|
|
||||||
return type_size_vec4(glsl_get_array_element(type)) * glsl_get_length(type);
|
|
||||||
case GLSL_TYPE_STRUCT:
|
|
||||||
size = 0;
|
|
||||||
for (i = 0; i < glsl_get_length(type); i++) {
|
|
||||||
size += type_size_vec4(glsl_get_struct_field(type, i));
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
case GLSL_TYPE_SUBROUTINE:
|
|
||||||
return 1;
|
|
||||||
case GLSL_TYPE_SAMPLER:
|
|
||||||
return 0;
|
|
||||||
case GLSL_TYPE_ATOMIC_UINT:
|
|
||||||
return 0;
|
|
||||||
case GLSL_TYPE_IMAGE:
|
|
||||||
case GLSL_TYPE_VOID:
|
|
||||||
case GLSL_TYPE_DOUBLE:
|
|
||||||
case GLSL_TYPE_ERROR:
|
|
||||||
case GLSL_TYPE_INTERFACE:
|
|
||||||
unreachable("not reached");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned
|
|
||||||
type_size_scalar(const struct glsl_type *type)
|
|
||||||
{
|
|
||||||
unsigned int size, i;
|
|
||||||
|
|
||||||
switch (glsl_get_base_type(type)) {
|
|
||||||
case GLSL_TYPE_UINT:
|
|
||||||
case GLSL_TYPE_INT:
|
|
||||||
case GLSL_TYPE_FLOAT:
|
|
||||||
case GLSL_TYPE_BOOL:
|
|
||||||
return glsl_get_components(type);
|
|
||||||
case GLSL_TYPE_ARRAY:
|
|
||||||
return type_size_scalar(glsl_get_array_element(type)) * glsl_get_length(type);
|
|
||||||
case GLSL_TYPE_STRUCT:
|
|
||||||
size = 0;
|
|
||||||
for (i = 0; i < glsl_get_length(type); i++) {
|
|
||||||
size += type_size_scalar(glsl_get_struct_field(type, i));
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
case GLSL_TYPE_SUBROUTINE:
|
|
||||||
return 1;
|
|
||||||
case GLSL_TYPE_SAMPLER:
|
|
||||||
return 0;
|
|
||||||
case GLSL_TYPE_ATOMIC_UINT:
|
|
||||||
return 0;
|
|
||||||
case GLSL_TYPE_INTERFACE:
|
|
||||||
return 0;
|
|
||||||
case GLSL_TYPE_IMAGE:
|
|
||||||
return 0;
|
|
||||||
case GLSL_TYPE_VOID:
|
|
||||||
case GLSL_TYPE_ERROR:
|
|
||||||
case GLSL_TYPE_DOUBLE:
|
|
||||||
unreachable("not reached");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned
|
|
||||||
type_size(const struct glsl_type *type, bool is_scalar)
|
|
||||||
{
|
|
||||||
if (is_scalar)
|
|
||||||
return type_size_scalar(type);
|
|
||||||
else
|
|
||||||
return type_size_vec4(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
nir_assign_var_locations(struct exec_list *var_list, unsigned *size, bool is_scalar)
|
nir_assign_var_locations(struct exec_list *var_list, unsigned *size,
|
||||||
|
int (*type_size)(const struct glsl_type *))
|
||||||
{
|
{
|
||||||
unsigned location = 0;
|
unsigned location = 0;
|
||||||
|
|
||||||
@@ -143,7 +56,7 @@ nir_assign_var_locations(struct exec_list *var_list, unsigned *size, bool is_sca
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var->data.driver_location = location;
|
var->data.driver_location = location;
|
||||||
location += type_size(var->type, is_scalar);
|
location += type_size(var->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
*size = location;
|
*size = location;
|
||||||
@@ -193,7 +106,7 @@ nir_assign_var_locations_direct_first(nir_shader *shader,
|
|||||||
struct exec_list *var_list,
|
struct exec_list *var_list,
|
||||||
unsigned *direct_size,
|
unsigned *direct_size,
|
||||||
unsigned *size,
|
unsigned *size,
|
||||||
bool is_scalar)
|
int (*type_size)(const struct glsl_type *))
|
||||||
{
|
{
|
||||||
struct set *indirect_set = _mesa_set_create(NULL, _mesa_hash_pointer,
|
struct set *indirect_set = _mesa_set_create(NULL, _mesa_hash_pointer,
|
||||||
_mesa_key_pointer_equal);
|
_mesa_key_pointer_equal);
|
||||||
@@ -215,7 +128,7 @@ nir_assign_var_locations_direct_first(nir_shader *shader,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var->data.driver_location = location;
|
var->data.driver_location = location;
|
||||||
location += type_size(var->type, is_scalar);
|
location += type_size(var->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
*direct_size = location;
|
*direct_size = location;
|
||||||
@@ -229,7 +142,7 @@ nir_assign_var_locations_direct_first(nir_shader *shader,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var->data.driver_location = location;
|
var->data.driver_location = location;
|
||||||
location += type_size(var->type, is_scalar);
|
location += type_size(var->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
*size = location;
|
*size = location;
|
||||||
@@ -254,7 +167,7 @@ get_io_offset(nir_deref_var *deref, nir_instr *instr, nir_src *indirect,
|
|||||||
|
|
||||||
if (tail->deref_type == nir_deref_type_array) {
|
if (tail->deref_type == nir_deref_type_array) {
|
||||||
nir_deref_array *deref_array = nir_deref_as_array(tail);
|
nir_deref_array *deref_array = nir_deref_as_array(tail);
|
||||||
unsigned size = type_size(tail->type, state->is_scalar);
|
unsigned size = state->type_size(tail->type);
|
||||||
|
|
||||||
base_offset += size * deref_array->base_offset;
|
base_offset += size * deref_array->base_offset;
|
||||||
|
|
||||||
@@ -275,9 +188,10 @@ get_io_offset(nir_deref_var *deref, nir_instr *instr, nir_src *indirect,
|
|||||||
} else if (tail->deref_type == nir_deref_type_struct) {
|
} else if (tail->deref_type == nir_deref_type_struct) {
|
||||||
nir_deref_struct *deref_struct = nir_deref_as_struct(tail);
|
nir_deref_struct *deref_struct = nir_deref_as_struct(tail);
|
||||||
|
|
||||||
for (unsigned i = 0; i < deref_struct->index; i++)
|
for (unsigned i = 0; i < deref_struct->index; i++) {
|
||||||
base_offset += type_size(glsl_get_struct_field(parent_type, i),
|
base_offset +=
|
||||||
state->is_scalar);
|
state->type_size(glsl_get_struct_field(parent_type, i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,13 +309,13 @@ nir_lower_io_block(nir_block *block, void *void_state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nir_lower_io_impl(nir_function_impl *impl, bool is_scalar)
|
nir_lower_io_impl(nir_function_impl *impl, int(*type_size)(const struct glsl_type *))
|
||||||
{
|
{
|
||||||
struct lower_io_state state;
|
struct lower_io_state state;
|
||||||
|
|
||||||
nir_builder_init(&state.builder, impl);
|
nir_builder_init(&state.builder, impl);
|
||||||
state.mem_ctx = ralloc_parent(impl);
|
state.mem_ctx = ralloc_parent(impl);
|
||||||
state.is_scalar = is_scalar;
|
state.type_size = type_size;
|
||||||
|
|
||||||
nir_foreach_block(impl, nir_lower_io_block, &state);
|
nir_foreach_block(impl, nir_lower_io_block, &state);
|
||||||
|
|
||||||
@@ -410,10 +324,10 @@ nir_lower_io_impl(nir_function_impl *impl, bool is_scalar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nir_lower_io(nir_shader *shader, bool is_scalar)
|
nir_lower_io(nir_shader *shader, int(*type_size)(const struct glsl_type *))
|
||||||
{
|
{
|
||||||
nir_foreach_overload(shader, overload) {
|
nir_foreach_overload(shader, overload) {
|
||||||
if (overload->impl)
|
if (overload->impl)
|
||||||
nir_lower_io_impl(overload->impl, is_scalar);
|
nir_lower_io_impl(overload->impl, type_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -239,18 +239,7 @@ fs_visitor::nir_setup_uniform(nir_variable *var)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (storage->type->is_image()) {
|
if (storage->type->is_image()) {
|
||||||
/* Images don't get a valid location assigned by nir_lower_io()
|
setup_image_uniform_values(index, storage);
|
||||||
* because their size is driver-specific, so we need to allocate
|
|
||||||
* space for them here at the end of the parameter array.
|
|
||||||
*/
|
|
||||||
var->data.driver_location = uniforms;
|
|
||||||
unsigned size =
|
|
||||||
BRW_IMAGE_PARAM_SIZE * MAX2(storage->array_elements, 1);
|
|
||||||
|
|
||||||
setup_image_uniform_values(uniforms, storage);
|
|
||||||
|
|
||||||
param_size[uniforms] = size;
|
|
||||||
uniforms += size;
|
|
||||||
} else {
|
} else {
|
||||||
unsigned slots = storage->type->component_slots();
|
unsigned slots = storage->type->component_slots();
|
||||||
if (storage->array_elements)
|
if (storage->array_elements)
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "brw_nir.h"
|
#include "brw_nir.h"
|
||||||
|
#include "brw_shader.h"
|
||||||
#include "glsl/glsl_parser_extras.h"
|
#include "glsl/glsl_parser_extras.h"
|
||||||
#include "glsl/nir/glsl_to_nir.h"
|
#include "glsl/nir/glsl_to_nir.h"
|
||||||
#include "program/prog_to_nir.h"
|
#include "program/prog_to_nir.h"
|
||||||
@@ -113,19 +114,22 @@ brw_create_nir(struct brw_context *brw,
|
|||||||
nir_assign_var_locations_direct_first(nir, &nir->uniforms,
|
nir_assign_var_locations_direct_first(nir, &nir->uniforms,
|
||||||
&nir->num_direct_uniforms,
|
&nir->num_direct_uniforms,
|
||||||
&nir->num_uniforms,
|
&nir->num_uniforms,
|
||||||
is_scalar);
|
type_size_scalar);
|
||||||
nir_assign_var_locations(&nir->outputs, &nir->num_outputs, is_scalar);
|
nir_assign_var_locations(&nir->inputs, &nir->num_inputs, type_size_scalar);
|
||||||
|
nir_assign_var_locations(&nir->outputs, &nir->num_outputs, type_size_scalar);
|
||||||
|
nir_lower_io(nir, type_size_scalar);
|
||||||
} else {
|
} else {
|
||||||
nir_assign_var_locations(&nir->uniforms,
|
nir_assign_var_locations(&nir->uniforms,
|
||||||
&nir->num_uniforms,
|
&nir->num_uniforms,
|
||||||
is_scalar);
|
type_size_vec4);
|
||||||
|
|
||||||
|
nir_assign_var_locations(&nir->inputs, &nir->num_inputs, type_size_vec4);
|
||||||
|
|
||||||
foreach_list_typed(nir_variable, var, node, &nir->outputs)
|
foreach_list_typed(nir_variable, var, node, &nir->outputs)
|
||||||
var->data.driver_location = var->data.location;
|
var->data.driver_location = var->data.location;
|
||||||
}
|
|
||||||
nir_assign_var_locations(&nir->inputs, &nir->num_inputs, is_scalar);
|
|
||||||
|
|
||||||
nir_lower_io(nir, is_scalar);
|
nir_lower_io(nir, type_size_vec4);
|
||||||
|
}
|
||||||
|
|
||||||
nir_validate_shader(nir);
|
nir_validate_shader(nir);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user