glsl: remove some unused linker code

These were missed when removing code in 72ad0db505.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26747>
This commit is contained in:
Timothy Arceri 2023-12-18 17:26:47 +11:00 committed by Marge Bot
parent 4584acca6b
commit 37e83a93d7
4 changed files with 0 additions and 240 deletions

View file

@ -1,122 +0,0 @@
/*
* Copyright © 2012 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "ir.h"
#include "main/shader_types.h"
static bool
link_uniform_blocks_are_compatible(const gl_uniform_block *a,
const gl_uniform_block *b)
{
assert(strcmp(a->name.string, b->name.string) == 0);
/* Page 35 (page 42 of the PDF) in section 4.3.7 of the GLSL 1.50 spec says:
*
* Matched block names within an interface (as defined above) must match
* in terms of having the same number of declarations with the same
* sequence of types and the same sequence of member names, as well as
* having the same member-wise layout qualification....if a matching
* block is declared as an array, then the array sizes must also
* match... Any mismatch will generate a link error.
*
* Arrays are not yet supported, so there is no check for that.
*/
if (a->NumUniforms != b->NumUniforms)
return false;
if (a->_Packing != b->_Packing)
return false;
if (a->_RowMajor != b->_RowMajor)
return false;
if (a->Binding != b->Binding)
return false;
for (unsigned i = 0; i < a->NumUniforms; i++) {
if (strcmp(a->Uniforms[i].Name, b->Uniforms[i].Name) != 0)
return false;
if (a->Uniforms[i].Type != b->Uniforms[i].Type)
return false;
if (a->Uniforms[i].RowMajor != b->Uniforms[i].RowMajor)
return false;
}
return true;
}
/**
* Merges a uniform block into an array of uniform blocks that may or
* may not already contain a copy of it.
*
* Returns the index of the new block in the array.
*/
int
link_cross_validate_uniform_block(void *mem_ctx,
struct gl_uniform_block **linked_blocks,
unsigned int *num_linked_blocks,
struct gl_uniform_block *new_block)
{
for (unsigned int i = 0; i < *num_linked_blocks; i++) {
struct gl_uniform_block *old_block = &(*linked_blocks)[i];
if (strcmp(old_block->name.string, new_block->name.string) == 0)
return link_uniform_blocks_are_compatible(old_block, new_block)
? i : -1;
}
*linked_blocks = reralloc(mem_ctx, *linked_blocks,
struct gl_uniform_block,
*num_linked_blocks + 1);
int linked_block_index = (*num_linked_blocks)++;
struct gl_uniform_block *linked_block = &(*linked_blocks)[linked_block_index];
memcpy(linked_block, new_block, sizeof(*new_block));
linked_block->Uniforms = ralloc_array(*linked_blocks,
struct gl_uniform_buffer_variable,
linked_block->NumUniforms);
memcpy(linked_block->Uniforms,
new_block->Uniforms,
sizeof(*linked_block->Uniforms) * linked_block->NumUniforms);
linked_block->name.string = ralloc_strdup(*linked_blocks, linked_block->name.string);
resource_name_updated(&linked_block->name);
for (unsigned int i = 0; i < linked_block->NumUniforms; i++) {
struct gl_uniform_buffer_variable *ubo_var =
&linked_block->Uniforms[i];
if (ubo_var->Name == ubo_var->IndexName) {
ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name);
ubo_var->IndexName = ubo_var->Name;
} else {
ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name);
ubo_var->IndexName = ralloc_strdup(*linked_blocks, ubo_var->IndexName);
}
}
return linked_block_index;
}

View file

@ -1109,109 +1109,6 @@ cross_validate_uniforms(const struct gl_constants *consts,
}
}
/**
* Accumulates the array of buffer blocks and checks that all definitions of
* blocks agree on their contents.
*/
static bool
interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog,
bool validate_ssbo)
{
int *ifc_blk_stage_idx[MESA_SHADER_STAGES];
struct gl_uniform_block *blks = NULL;
unsigned *num_blks = validate_ssbo ? &prog->data->NumShaderStorageBlocks :
&prog->data->NumUniformBlocks;
unsigned max_num_buffer_blocks = 0;
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
if (prog->_LinkedShaders[i]) {
if (validate_ssbo) {
max_num_buffer_blocks +=
prog->_LinkedShaders[i]->Program->info.num_ssbos;
} else {
max_num_buffer_blocks +=
prog->_LinkedShaders[i]->Program->info.num_ubos;
}
}
}
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
struct gl_linked_shader *sh = prog->_LinkedShaders[i];
ifc_blk_stage_idx[i] =
(int *) malloc(sizeof(int) * max_num_buffer_blocks);
for (unsigned int j = 0; j < max_num_buffer_blocks; j++)
ifc_blk_stage_idx[i][j] = -1;
if (sh == NULL)
continue;
unsigned sh_num_blocks;
struct gl_uniform_block **sh_blks;
if (validate_ssbo) {
sh_num_blocks = prog->_LinkedShaders[i]->Program->info.num_ssbos;
sh_blks = sh->Program->sh.ShaderStorageBlocks;
} else {
sh_num_blocks = prog->_LinkedShaders[i]->Program->info.num_ubos;
sh_blks = sh->Program->sh.UniformBlocks;
}
for (unsigned int j = 0; j < sh_num_blocks; j++) {
int index = link_cross_validate_uniform_block(prog->data, &blks,
num_blks, sh_blks[j]);
if (index == -1) {
linker_error(prog, "buffer block `%s' has mismatching "
"definitions\n", sh_blks[j]->name.string);
for (unsigned k = 0; k <= i; k++) {
free(ifc_blk_stage_idx[k]);
}
/* Reset the block count. This will help avoid various segfaults
* from api calls that assume the array exists due to the count
* being non-zero.
*/
*num_blks = 0;
return false;
}
ifc_blk_stage_idx[i][index] = j;
}
}
/* Update per stage block pointers to point to the program list.
* FIXME: We should be able to free the per stage blocks here.
*/
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
for (unsigned j = 0; j < *num_blks; j++) {
int stage_index = ifc_blk_stage_idx[i][j];
if (stage_index != -1) {
struct gl_linked_shader *sh = prog->_LinkedShaders[i];
struct gl_uniform_block **sh_blks = validate_ssbo ?
sh->Program->sh.ShaderStorageBlocks :
sh->Program->sh.UniformBlocks;
blks[j].stageref |= sh_blks[stage_index]->stageref;
sh_blks[stage_index] = &blks[j];
}
}
}
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
free(ifc_blk_stage_idx[i]);
}
if (validate_ssbo)
prog->data->ShaderStorageBlocks = blks;
else
prog->data->UniformBlocks = blks;
return true;
}
/**
* Verifies the invariance of built-in special variables.
*/
@ -3086,14 +2983,6 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
}
}
/* Process UBOs */
if (!interstage_cross_validate_uniform_blocks(prog, false))
goto done;
/* Process SSBOs */
if (!interstage_cross_validate_uniform_blocks(prog, true))
goto done;
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
if (prog->_LinkedShaders[i] == NULL)
continue;

View file

@ -35,12 +35,6 @@ extern bool
link_function_calls(gl_shader_program *prog, gl_linked_shader *main,
gl_shader **shader_list, unsigned num_shaders);
extern int
link_cross_validate_uniform_block(void *mem_ctx,
struct gl_uniform_block **linked_blocks,
unsigned int *num_linked_blocks,
struct gl_uniform_block *new_block);
bool
validate_intrastage_arrays(struct gl_shader_program *prog,
ir_variable *const var,

View file

@ -190,7 +190,6 @@ files_libglsl = files(
'linker_util.cpp',
'link_functions.cpp',
'link_interface_blocks.cpp',
'link_uniform_blocks.cpp',
'list.h',
'lower_builtins.cpp',
'lower_discard_flow.cpp',