compiler/link: move add_program_resource to linker_util
So it could be used by the GLSL and NIR linker. v2: (Timothy Arceri) * Moved from compiler to compiler/glsl * Method renamed to link_util_add_program_resource Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
@@ -75,6 +75,7 @@ LIBGLSL_FILES = \
|
|||||||
glsl/linker.cpp \
|
glsl/linker.cpp \
|
||||||
glsl/linker.h \
|
glsl/linker.h \
|
||||||
glsl/linker_util.h \
|
glsl/linker_util.h \
|
||||||
|
glsl/linker_util.cpp \
|
||||||
glsl/link_atomics.cpp \
|
glsl/link_atomics.cpp \
|
||||||
glsl/link_functions.cpp \
|
glsl/link_functions.cpp \
|
||||||
glsl/link_interface_blocks.cpp \
|
glsl/link_interface_blocks.cpp \
|
||||||
|
@@ -3624,42 +3624,6 @@ should_add_buffer_variable(struct gl_shader_program *shProg,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
|
||||||
add_program_resource(struct gl_shader_program *prog,
|
|
||||||
struct set *resource_set,
|
|
||||||
GLenum type, const void *data, uint8_t stages)
|
|
||||||
{
|
|
||||||
assert(data);
|
|
||||||
|
|
||||||
/* If resource already exists, do not add it again. */
|
|
||||||
if (_mesa_set_search(resource_set, data))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
prog->data->ProgramResourceList =
|
|
||||||
reralloc(prog->data,
|
|
||||||
prog->data->ProgramResourceList,
|
|
||||||
gl_program_resource,
|
|
||||||
prog->data->NumProgramResourceList + 1);
|
|
||||||
|
|
||||||
if (!prog->data->ProgramResourceList) {
|
|
||||||
linker_error(prog, "Out of memory during linking.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct gl_program_resource *res =
|
|
||||||
&prog->data->ProgramResourceList[prog->data->NumProgramResourceList];
|
|
||||||
|
|
||||||
res->Type = type;
|
|
||||||
res->Data = data;
|
|
||||||
res->StageReferences = stages;
|
|
||||||
|
|
||||||
prog->data->NumProgramResourceList++;
|
|
||||||
|
|
||||||
_mesa_set_add(resource_set, data);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Function checks if a variable var is a packed varying and
|
/* Function checks if a variable var is a packed varying and
|
||||||
* if given name is part of packed varying's list.
|
* if given name is part of packed varying's list.
|
||||||
*
|
*
|
||||||
@@ -3953,8 +3917,8 @@ add_shader_variable(const struct gl_context *ctx,
|
|||||||
if (!sha_v)
|
if (!sha_v)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return add_program_resource(shProg, resource_set,
|
return link_util_add_program_resource(shProg, resource_set,
|
||||||
programInterface, sha_v, stage_mask);
|
programInterface, sha_v, stage_mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4383,9 +4347,9 @@ build_program_resource_list(struct gl_context *ctx,
|
|||||||
/* Add transform feedback varyings. */
|
/* Add transform feedback varyings. */
|
||||||
if (linked_xfb->NumVarying > 0) {
|
if (linked_xfb->NumVarying > 0) {
|
||||||
for (int i = 0; i < linked_xfb->NumVarying; i++) {
|
for (int i = 0; i < linked_xfb->NumVarying; i++) {
|
||||||
if (!add_program_resource(shProg, resource_set,
|
if (!link_util_add_program_resource(shProg, resource_set,
|
||||||
GL_TRANSFORM_FEEDBACK_VARYING,
|
GL_TRANSFORM_FEEDBACK_VARYING,
|
||||||
&linked_xfb->Varyings[i], 0))
|
&linked_xfb->Varyings[i], 0))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4394,9 +4358,9 @@ build_program_resource_list(struct gl_context *ctx,
|
|||||||
for (unsigned i = 0; i < ctx->Const.MaxTransformFeedbackBuffers; i++) {
|
for (unsigned i = 0; i < ctx->Const.MaxTransformFeedbackBuffers; i++) {
|
||||||
if ((linked_xfb->ActiveBuffers >> i) & 1) {
|
if ((linked_xfb->ActiveBuffers >> i) & 1) {
|
||||||
linked_xfb->Buffers[i].Binding = i;
|
linked_xfb->Buffers[i].Binding = i;
|
||||||
if (!add_program_resource(shProg, resource_set,
|
if (!link_util_add_program_resource(shProg, resource_set,
|
||||||
GL_TRANSFORM_FEEDBACK_BUFFER,
|
GL_TRANSFORM_FEEDBACK_BUFFER,
|
||||||
&linked_xfb->Buffers[i], 0))
|
&linked_xfb->Buffers[i], 0))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4432,29 +4396,29 @@ build_program_resource_list(struct gl_context *ctx,
|
|||||||
&shProg->data->UniformStorage[i]);
|
&shProg->data->UniformStorage[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!add_program_resource(shProg, resource_set, type,
|
if (!link_util_add_program_resource(shProg, resource_set, type,
|
||||||
&shProg->data->UniformStorage[i], stageref))
|
&shProg->data->UniformStorage[i], stageref))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add program uniform blocks. */
|
/* Add program uniform blocks. */
|
||||||
for (unsigned i = 0; i < shProg->data->NumUniformBlocks; i++) {
|
for (unsigned i = 0; i < shProg->data->NumUniformBlocks; i++) {
|
||||||
if (!add_program_resource(shProg, resource_set, GL_UNIFORM_BLOCK,
|
if (!link_util_add_program_resource(shProg, resource_set, GL_UNIFORM_BLOCK,
|
||||||
&shProg->data->UniformBlocks[i], 0))
|
&shProg->data->UniformBlocks[i], 0))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add program shader storage blocks. */
|
/* Add program shader storage blocks. */
|
||||||
for (unsigned i = 0; i < shProg->data->NumShaderStorageBlocks; i++) {
|
for (unsigned i = 0; i < shProg->data->NumShaderStorageBlocks; i++) {
|
||||||
if (!add_program_resource(shProg, resource_set, GL_SHADER_STORAGE_BLOCK,
|
if (!link_util_add_program_resource(shProg, resource_set, GL_SHADER_STORAGE_BLOCK,
|
||||||
&shProg->data->ShaderStorageBlocks[i], 0))
|
&shProg->data->ShaderStorageBlocks[i], 0))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add atomic counter buffers. */
|
/* Add atomic counter buffers. */
|
||||||
for (unsigned i = 0; i < shProg->data->NumAtomicBuffers; i++) {
|
for (unsigned i = 0; i < shProg->data->NumAtomicBuffers; i++) {
|
||||||
if (!add_program_resource(shProg, resource_set, GL_ATOMIC_COUNTER_BUFFER,
|
if (!link_util_add_program_resource(shProg, resource_set, GL_ATOMIC_COUNTER_BUFFER,
|
||||||
&shProg->data->AtomicBuffers[i], 0))
|
&shProg->data->AtomicBuffers[i], 0))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4470,8 +4434,8 @@ build_program_resource_list(struct gl_context *ctx,
|
|||||||
|
|
||||||
type = _mesa_shader_stage_to_subroutine_uniform((gl_shader_stage)j);
|
type = _mesa_shader_stage_to_subroutine_uniform((gl_shader_stage)j);
|
||||||
/* add shader subroutines */
|
/* add shader subroutines */
|
||||||
if (!add_program_resource(shProg, resource_set,
|
if (!link_util_add_program_resource(shProg, resource_set,
|
||||||
type, &shProg->data->UniformStorage[i], 0))
|
type, &shProg->data->UniformStorage[i], 0))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4483,8 +4447,8 @@ build_program_resource_list(struct gl_context *ctx,
|
|||||||
|
|
||||||
GLuint type = _mesa_shader_stage_to_subroutine((gl_shader_stage)i);
|
GLuint type = _mesa_shader_stage_to_subroutine((gl_shader_stage)i);
|
||||||
for (unsigned j = 0; j < p->sh.NumSubroutineFunctions; j++) {
|
for (unsigned j = 0; j < p->sh.NumSubroutineFunctions; j++) {
|
||||||
if (!add_program_resource(shProg, resource_set,
|
if (!link_util_add_program_resource(shProg, resource_set,
|
||||||
type, &p->sh.SubroutineFunctions[j], 0))
|
type, &p->sh.SubroutineFunctions[j], 0))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
64
src/compiler/glsl/linker_util.cpp
Normal file
64
src/compiler/glsl/linker_util.cpp
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2018 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 "main/mtypes.h"
|
||||||
|
#include "linker_util.h"
|
||||||
|
#include "util/set.h"
|
||||||
|
|
||||||
|
/* Utility methods shared between the GLSL IR and the NIR */
|
||||||
|
|
||||||
|
bool
|
||||||
|
link_util_add_program_resource(struct gl_shader_program *prog,
|
||||||
|
struct set *resource_set,
|
||||||
|
GLenum type, const void *data, uint8_t stages)
|
||||||
|
{
|
||||||
|
assert(data);
|
||||||
|
|
||||||
|
/* If resource already exists, do not add it again. */
|
||||||
|
if (_mesa_set_search(resource_set, data))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
prog->data->ProgramResourceList =
|
||||||
|
reralloc(prog->data,
|
||||||
|
prog->data->ProgramResourceList,
|
||||||
|
gl_program_resource,
|
||||||
|
prog->data->NumProgramResourceList + 1);
|
||||||
|
|
||||||
|
if (!prog->data->ProgramResourceList) {
|
||||||
|
linker_error(prog, "Out of memory during linking.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct gl_program_resource *res =
|
||||||
|
&prog->data->ProgramResourceList[prog->data->NumProgramResourceList];
|
||||||
|
|
||||||
|
res->Type = type;
|
||||||
|
res->Data = data;
|
||||||
|
res->StageReferences = stages;
|
||||||
|
|
||||||
|
prog->data->NumProgramResourceList++;
|
||||||
|
|
||||||
|
_mesa_set_add(resource_set, data);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
@@ -36,6 +36,11 @@ linker_error(struct gl_shader_program *prog, const char *fmt, ...);
|
|||||||
void
|
void
|
||||||
linker_warning(struct gl_shader_program *prog, const char *fmt, ...);
|
linker_warning(struct gl_shader_program *prog, const char *fmt, ...);
|
||||||
|
|
||||||
|
bool
|
||||||
|
link_util_add_program_resource(struct gl_shader_program *prog,
|
||||||
|
struct set *resource_set,
|
||||||
|
GLenum type, const void *data, uint8_t stages);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -116,6 +116,7 @@ files_libglsl = files(
|
|||||||
'linker.cpp',
|
'linker.cpp',
|
||||||
'linker.h',
|
'linker.h',
|
||||||
'linker_util.h',
|
'linker_util.h',
|
||||||
|
'linker_util.cpp',
|
||||||
'link_atomics.cpp',
|
'link_atomics.cpp',
|
||||||
'link_functions.cpp',
|
'link_functions.cpp',
|
||||||
'link_interface_blocks.cpp',
|
'link_interface_blocks.cpp',
|
||||||
|
Reference in New Issue
Block a user