mirror of https://gitlab.freedesktop.org/mesa/mesa
glsl: remove now unused glsl ir block validation
We now use a NIR based implementation instead. Acked-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28538>
This commit is contained in:
parent
07078d4b8e
commit
dbaa90200c
|
@ -166,59 +166,6 @@ intrastage_match(ir_variable *a,
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if two interfaces match, according to interstage (in/out) interface
|
||||
* matching rules.
|
||||
*
|
||||
* If \c extra_array_level is true, the consumer interface is required to be
|
||||
* an array and the producer interface is required to be a non-array.
|
||||
* This is used for tessellation control and geometry shader consumers.
|
||||
*/
|
||||
static bool
|
||||
interstage_match(struct gl_shader_program *prog, ir_variable *producer,
|
||||
ir_variable *consumer, bool extra_array_level)
|
||||
{
|
||||
/* Types must match. */
|
||||
if (consumer->get_interface_type() != producer->get_interface_type()) {
|
||||
/* Exception: if both the interface blocks are implicitly declared,
|
||||
* don't force their types to match. They might mismatch due to the two
|
||||
* shaders using different GLSL versions, and that's ok.
|
||||
*
|
||||
* Also we store some member information such as interpolation in
|
||||
* glsl_type that doesn't always have to match across shader stages.
|
||||
* Therefore we make a pass over the members glsl_struct_field to make
|
||||
* sure we don't reject shaders where fields don't need to match.
|
||||
*/
|
||||
if ((consumer->data.how_declared != ir_var_declared_implicitly ||
|
||||
producer->data.how_declared != ir_var_declared_implicitly) &&
|
||||
interstage_member_mismatch(prog, consumer->get_interface_type(),
|
||||
producer->get_interface_type()))
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Ignore outermost array if geom shader */
|
||||
const glsl_type *consumer_instance_type;
|
||||
if (extra_array_level) {
|
||||
consumer_instance_type = consumer->type->fields.array;
|
||||
} else {
|
||||
consumer_instance_type = consumer->type;
|
||||
}
|
||||
|
||||
/* If a block is an array then it must match across shaders.
|
||||
* Since unsized arrays have been ruled out, we can check this by just
|
||||
* making sure the types are equal.
|
||||
*/
|
||||
if ((consumer->is_interface_instance() &&
|
||||
glsl_type_is_array(consumer_instance_type)) ||
|
||||
(producer->is_interface_instance() &&
|
||||
glsl_type_is_array(producer->type))) {
|
||||
if (consumer_instance_type != producer->type)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class keeps track of a mapping from an interface block name to the
|
||||
|
@ -365,188 +312,3 @@ validate_intrastage_interface_blocks(struct gl_shader_program *prog,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
is_builtin_gl_in_block(ir_variable *var, int consumer_stage)
|
||||
{
|
||||
return !strcmp(var->name, "gl_in") &&
|
||||
(consumer_stage == MESA_SHADER_TESS_CTRL ||
|
||||
consumer_stage == MESA_SHADER_TESS_EVAL ||
|
||||
consumer_stage == MESA_SHADER_GEOMETRY);
|
||||
}
|
||||
|
||||
void
|
||||
validate_interstage_inout_blocks(struct gl_shader_program *prog,
|
||||
const gl_linked_shader *producer,
|
||||
const gl_linked_shader *consumer)
|
||||
{
|
||||
interface_block_definitions definitions;
|
||||
/* VS -> GS, VS -> TCS, VS -> TES, TES -> GS */
|
||||
const bool extra_array_level = (producer->Stage == MESA_SHADER_VERTEX &&
|
||||
consumer->Stage != MESA_SHADER_FRAGMENT) ||
|
||||
consumer->Stage == MESA_SHADER_GEOMETRY;
|
||||
|
||||
/* Check that block re-declarations of gl_PerVertex are compatible
|
||||
* across shaders: From OpenGL Shading Language 4.5, section
|
||||
* "7.1 Built-In Language Variables", page 130 of the PDF:
|
||||
*
|
||||
* "If multiple shaders using members of a built-in block belonging
|
||||
* to the same interface are linked together in the same program,
|
||||
* they must all redeclare the built-in block in the same way, as
|
||||
* described in section 4.3.9 “Interface Blocks” for interface-block
|
||||
* matching, or a link-time error will result."
|
||||
*
|
||||
* This is done explicitly outside of iterating the member variable
|
||||
* declarations because it is possible that the variables are not used and
|
||||
* so they would have been optimised out.
|
||||
*/
|
||||
const glsl_type *consumer_iface =
|
||||
consumer->symbols->get_interface("gl_PerVertex",
|
||||
ir_var_shader_in);
|
||||
|
||||
const glsl_type *producer_iface =
|
||||
producer->symbols->get_interface("gl_PerVertex",
|
||||
ir_var_shader_out);
|
||||
|
||||
if (producer_iface && consumer_iface &&
|
||||
interstage_member_mismatch(prog, consumer_iface, producer_iface)) {
|
||||
linker_error(prog, "Incompatible or missing gl_PerVertex re-declaration "
|
||||
"in consecutive shaders");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Desktop OpenGL requires redeclaration of the built-in interfaces for
|
||||
* SSO programs. Passes above implement following rules:
|
||||
*
|
||||
* From Section 7.4 (Program Pipeline Objects) of the OpenGL 4.6 Core
|
||||
* spec:
|
||||
*
|
||||
* "To use any built-in input or output in the gl_PerVertex and
|
||||
* gl_PerFragment blocks in separable program objects, shader code
|
||||
* must redeclare those blocks prior to use. A separable program
|
||||
* will fail to link if:
|
||||
*
|
||||
* it contains multiple shaders of a single type with different
|
||||
* redeclarations of these built-in input and output blocks; or
|
||||
*
|
||||
* any shader uses a built-in block member not found in the
|
||||
* redeclaration of that block."
|
||||
*
|
||||
* ARB_separate_shader_objects issues section (issue #28) states that
|
||||
* redeclaration is not required for GLSL shaders using #version 140 or
|
||||
* earlier (since interface blocks are not possible with older versions).
|
||||
*
|
||||
* From Section 7.4.1 (Shader Interface Matching) of the OpenGL ES 3.1
|
||||
* spec:
|
||||
*
|
||||
* "Built-in inputs or outputs do not affect interface matching."
|
||||
*
|
||||
* GL_OES_shader_io_blocks adds following:
|
||||
*
|
||||
* "When using any built-in input or output in the gl_PerVertex block
|
||||
* in separable program objects, shader code may redeclare that block
|
||||
* prior to use. If the shader does not redeclare the block, the
|
||||
* intrinsically declared definition of that block will be used."
|
||||
*/
|
||||
|
||||
/* Add output interfaces from the producer to the symbol table. */
|
||||
foreach_in_list(ir_instruction, node, producer->ir) {
|
||||
ir_variable *var = node->as_variable();
|
||||
if (!var || !var->get_interface_type() || var->data.mode != ir_var_shader_out)
|
||||
continue;
|
||||
|
||||
/* Built-in interface redeclaration check. */
|
||||
if (prog->SeparateShader && !prog->IsES && prog->GLSL_Version >= 150 &&
|
||||
var->data.how_declared == ir_var_declared_implicitly &&
|
||||
var->data.used && !producer_iface) {
|
||||
linker_error(prog, "missing output builtin block %s redeclaration "
|
||||
"in separable shader program",
|
||||
glsl_get_type_name(var->get_interface_type()));
|
||||
return;
|
||||
}
|
||||
|
||||
definitions.store(var);
|
||||
}
|
||||
|
||||
/* Verify that the consumer's input interfaces match. */
|
||||
foreach_in_list(ir_instruction, node, consumer->ir) {
|
||||
ir_variable *var = node->as_variable();
|
||||
if (!var || !var->get_interface_type() || var->data.mode != ir_var_shader_in)
|
||||
continue;
|
||||
|
||||
ir_variable *producer_def = definitions.lookup(var);
|
||||
|
||||
/* Built-in interface redeclaration check. */
|
||||
if (prog->SeparateShader && !prog->IsES && prog->GLSL_Version >= 150 &&
|
||||
var->data.how_declared == ir_var_declared_implicitly &&
|
||||
var->data.used && !producer_iface) {
|
||||
linker_error(prog, "missing input builtin block %s redeclaration "
|
||||
"in separable shader program",
|
||||
glsl_get_type_name(var->get_interface_type()));
|
||||
return;
|
||||
}
|
||||
|
||||
/* The producer doesn't generate this input: fail to link. Skip built-in
|
||||
* 'gl_in[]' since that may not be present if the producer does not
|
||||
* write to any of the pre-defined outputs (e.g. if the vertex shader
|
||||
* does not write to gl_Position, etc), which is allowed and results in
|
||||
* undefined behavior.
|
||||
*
|
||||
* From Section 4.3.4 (Inputs) of the GLSL 1.50 spec:
|
||||
*
|
||||
* "Only the input variables that are actually read need to be written
|
||||
* by the previous stage; it is allowed to have superfluous
|
||||
* declarations of input variables."
|
||||
*/
|
||||
if (producer_def == NULL &&
|
||||
!is_builtin_gl_in_block(var, consumer->Stage) && var->data.used) {
|
||||
linker_error(prog, "Input block `%s' is not an output of "
|
||||
"the previous stage\n", glsl_get_type_name(var->get_interface_type()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (producer_def &&
|
||||
!interstage_match(prog, producer_def, var, extra_array_level)) {
|
||||
linker_error(prog, "definitions of interface block `%s' do not "
|
||||
"match\n", glsl_get_type_name(var->get_interface_type()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
validate_interstage_uniform_blocks(struct gl_shader_program *prog,
|
||||
gl_linked_shader **stages)
|
||||
{
|
||||
interface_block_definitions definitions;
|
||||
|
||||
for (int i = 0; i < MESA_SHADER_STAGES; i++) {
|
||||
if (stages[i] == NULL)
|
||||
continue;
|
||||
|
||||
const gl_linked_shader *stage = stages[i];
|
||||
foreach_in_list(ir_instruction, node, stage->ir) {
|
||||
ir_variable *var = node->as_variable();
|
||||
if (!var || !var->get_interface_type() ||
|
||||
(var->data.mode != ir_var_uniform &&
|
||||
var->data.mode != ir_var_shader_storage))
|
||||
continue;
|
||||
|
||||
ir_variable *old_def = definitions.lookup(var);
|
||||
if (old_def == NULL) {
|
||||
definitions.store(var);
|
||||
} else {
|
||||
/* Interstage uniform matching rules are the same as intrastage
|
||||
* uniform matchin rules (for uniforms, it is as though all
|
||||
* shaders are in the same shader stage).
|
||||
*/
|
||||
if (!intrastage_match(old_def, var, prog, false /* precision */)) {
|
||||
linker_error(prog, "definitions of uniform block `%s' do not "
|
||||
"match\n", glsl_get_type_name(var->get_interface_type()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,15 +46,6 @@ validate_intrastage_interface_blocks(struct gl_shader_program *prog,
|
|||
const gl_shader **shader_list,
|
||||
unsigned num_shaders);
|
||||
|
||||
void
|
||||
validate_interstage_inout_blocks(struct gl_shader_program *prog,
|
||||
const gl_linked_shader *producer,
|
||||
const gl_linked_shader *consumer);
|
||||
|
||||
void
|
||||
validate_interstage_uniform_blocks(struct gl_shader_program *prog,
|
||||
gl_linked_shader **stages);
|
||||
|
||||
extern struct gl_linked_shader *
|
||||
link_intrastage_shaders(void *mem_ctx,
|
||||
struct gl_context *ctx,
|
||||
|
|
Loading…
Reference in New Issue