mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 00:58:05 +02:00
glsl: move geom input array sizing to nir linker
Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29256>
This commit is contained in:
parent
08659a0baa
commit
795057d44e
4 changed files with 17 additions and 74 deletions
|
|
@ -653,6 +653,19 @@ resize_tes_inputs(const struct gl_constants *consts,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
set_geom_shader_input_array_size(struct gl_shader_program *prog)
|
||||
{
|
||||
if (prog->_LinkedShaders[MESA_SHADER_GEOMETRY] == NULL)
|
||||
return;
|
||||
|
||||
/* Set the size of geometry shader input arrays */
|
||||
nir_shader *nir = prog->_LinkedShaders[MESA_SHADER_GEOMETRY]->Program->nir;
|
||||
unsigned num_vertices =
|
||||
mesa_vertices_per_prim(nir->info.gs.input_primitive);
|
||||
resize_input_array(nir, prog, MESA_SHADER_GEOMETRY, num_vertices);
|
||||
}
|
||||
|
||||
static bool
|
||||
validate_explicit_variable_location(const struct gl_constants *consts,
|
||||
struct explicit_location_info explicit_locations[][4],
|
||||
|
|
|
|||
|
|
@ -220,6 +220,9 @@ void
|
|||
resize_tes_inputs(const struct gl_constants *consts,
|
||||
struct gl_shader_program *prog);
|
||||
|
||||
void
|
||||
set_geom_shader_input_array_size(struct gl_shader_program *prog);
|
||||
|
||||
bool
|
||||
gl_assign_attribute_or_color_locations(const struct gl_constants *consts,
|
||||
struct gl_shader_program *prog);
|
||||
|
|
|
|||
|
|
@ -2784,6 +2784,7 @@ gl_nir_link_glsl(struct gl_context *ctx, struct gl_shader_program *prog)
|
|||
}
|
||||
|
||||
resize_tes_inputs(consts, prog);
|
||||
set_geom_shader_input_array_size(prog);
|
||||
|
||||
/* Validate the inputs of each stage with the output of the preceding
|
||||
* stage.
|
||||
|
|
|
|||
|
|
@ -124,69 +124,6 @@ public:
|
|||
};
|
||||
|
||||
|
||||
class array_resize_visitor : public deref_type_updater {
|
||||
public:
|
||||
using deref_type_updater::visit;
|
||||
|
||||
unsigned num_vertices;
|
||||
gl_shader_program *prog;
|
||||
gl_shader_stage stage;
|
||||
|
||||
array_resize_visitor(unsigned num_vertices,
|
||||
gl_shader_program *prog,
|
||||
gl_shader_stage stage)
|
||||
{
|
||||
this->num_vertices = num_vertices;
|
||||
this->prog = prog;
|
||||
this->stage = stage;
|
||||
}
|
||||
|
||||
virtual ~array_resize_visitor()
|
||||
{
|
||||
/* empty */
|
||||
}
|
||||
|
||||
virtual ir_visitor_status visit(ir_variable *var)
|
||||
{
|
||||
if (!glsl_type_is_array(var->type) || var->data.mode != ir_var_shader_in ||
|
||||
var->data.patch)
|
||||
return visit_continue;
|
||||
|
||||
unsigned size = var->type->length;
|
||||
|
||||
if (stage == MESA_SHADER_GEOMETRY) {
|
||||
/* Generate a link error if the shader has declared this array with
|
||||
* an incorrect size.
|
||||
*/
|
||||
if (!var->data.implicit_sized_array &&
|
||||
size && size != this->num_vertices) {
|
||||
linker_error(this->prog, "size of array %s declared as %u, "
|
||||
"but number of input vertices is %u\n",
|
||||
var->name, size, this->num_vertices);
|
||||
return visit_continue;
|
||||
}
|
||||
|
||||
/* Generate a link error if the shader attempts to access an input
|
||||
* array using an index too large for its actual size assigned at
|
||||
* link time.
|
||||
*/
|
||||
if (var->data.max_array_access >= (int)this->num_vertices) {
|
||||
linker_error(this->prog, "%s shader accesses element %i of "
|
||||
"%s, but only %i input vertices\n",
|
||||
_mesa_shader_stage_to_string(this->stage),
|
||||
var->data.max_array_access, var->name, this->num_vertices);
|
||||
return visit_continue;
|
||||
}
|
||||
}
|
||||
|
||||
var->type = glsl_array_type(var->type->fields.array,
|
||||
this->num_vertices, 0);
|
||||
var->data.max_array_access = this->num_vertices - 1;
|
||||
|
||||
return visit_continue;
|
||||
}
|
||||
};
|
||||
|
||||
class array_length_to_const_visitor : public ir_rvalue_visitor {
|
||||
public:
|
||||
array_length_to_const_visitor()
|
||||
|
|
@ -1778,17 +1715,6 @@ link_intrastage_shaders(void *mem_ctx,
|
|||
*/
|
||||
validate_ir_tree(linked->ir);
|
||||
|
||||
/* Set the size of geometry shader input arrays */
|
||||
if (linked->Stage == MESA_SHADER_GEOMETRY) {
|
||||
unsigned num_vertices =
|
||||
mesa_vertices_per_prim(gl_prog->info.gs.input_primitive);
|
||||
array_resize_visitor input_resize_visitor(num_vertices, prog,
|
||||
MESA_SHADER_GEOMETRY);
|
||||
foreach_in_list(ir_instruction, ir, linked->ir) {
|
||||
ir->accept(&input_resize_visitor);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the linked source BLAKE3. */
|
||||
if (num_shaders == 1) {
|
||||
memcpy(linked->linked_source_blake3, shader_list[0]->compiled_source_blake3,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue