mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 19:40:10 +01:00
glsl/mesa: move parse_program_resource_name() to common linker_util code
This will be shared by a new NIR varying linking pass in following patches but probably fits better here anyway considering its also used by shader_query.cpp Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15731>
This commit is contained in:
parent
5d57bd0345
commit
23ea24e11f
6 changed files with 73 additions and 72 deletions
|
|
@ -36,6 +36,7 @@
|
|||
#include "glsl_parser_extras.h"
|
||||
#include "ir_optimization.h"
|
||||
#include "linker.h"
|
||||
#include "linker_util.h"
|
||||
#include "link_varyings.h"
|
||||
#include "main/macros.h"
|
||||
#include "util/hash_table.h"
|
||||
|
|
@ -1030,8 +1031,8 @@ tfeedback_decl::init(const struct gl_constants *consts,
|
|||
|
||||
/* Parse a declaration. */
|
||||
const char *base_name_end;
|
||||
long subscript = parse_program_resource_name(input, strlen(input),
|
||||
&base_name_end);
|
||||
long subscript = link_util_parse_program_resource_name(input, strlen(input),
|
||||
&base_name_end);
|
||||
this->var_name = ralloc_strndup(mem_ctx, input, base_name_end - input);
|
||||
if (this->var_name == NULL) {
|
||||
_mesa_error_no_memory(__func__);
|
||||
|
|
|
|||
|
|
@ -512,69 +512,6 @@ linker_warning(gl_shader_program *prog, const char *fmt, ...)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given a string identifying a program resource, break it into a base name
|
||||
* and an optional array index in square brackets.
|
||||
*
|
||||
* If an array index is present, \c out_base_name_end is set to point to the
|
||||
* "[" that precedes the array index, and the array index itself is returned
|
||||
* as a long.
|
||||
*
|
||||
* If no array index is present (or if the array index is negative or
|
||||
* mal-formed), \c out_base_name_end, is set to point to the null terminator
|
||||
* at the end of the input string, and -1 is returned.
|
||||
*
|
||||
* Only the final array index is parsed; if the string contains other array
|
||||
* indices (or structure field accesses), they are left in the base name.
|
||||
*
|
||||
* No attempt is made to check that the base name is properly formed;
|
||||
* typically the caller will look up the base name in a hash table, so
|
||||
* ill-formed base names simply turn into hash table lookup failures.
|
||||
*/
|
||||
long
|
||||
parse_program_resource_name(const GLchar *name,
|
||||
const size_t len,
|
||||
const GLchar **out_base_name_end)
|
||||
{
|
||||
/* Section 7.3.1 ("Program Interfaces") of the OpenGL 4.3 spec says:
|
||||
*
|
||||
* "When an integer array element or block instance number is part of
|
||||
* the name string, it will be specified in decimal form without a "+"
|
||||
* or "-" sign or any extra leading zeroes. Additionally, the name
|
||||
* string will not include white space anywhere in the string."
|
||||
*/
|
||||
|
||||
*out_base_name_end = name + len;
|
||||
|
||||
if (len == 0 || name[len-1] != ']')
|
||||
return -1;
|
||||
|
||||
/* Walk backwards over the string looking for a non-digit character. This
|
||||
* had better be the opening bracket for an array index.
|
||||
*
|
||||
* Initially, i specifies the location of the ']'. Since the string may
|
||||
* contain only the ']' charcater, walk backwards very carefully.
|
||||
*/
|
||||
unsigned i;
|
||||
for (i = len - 1; (i > 0) && isdigit(name[i-1]); --i)
|
||||
/* empty */ ;
|
||||
|
||||
if ((i == 0) || name[i-1] != '[')
|
||||
return -1;
|
||||
|
||||
long array_index = strtol(&name[i], NULL, 10);
|
||||
if (array_index < 0)
|
||||
return -1;
|
||||
|
||||
/* Check for leading zero */
|
||||
if (name[i] == '0' && name[i+1] != ']')
|
||||
return -1;
|
||||
|
||||
*out_base_name_end = name + (i - 1);
|
||||
return array_index;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
link_invalidate_variable_locations(exec_list *ir)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
* IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#include <ctype.h>
|
||||
|
||||
#include "glsl_types.h"
|
||||
#include "linker_util.h"
|
||||
#include "util/bitscan.h"
|
||||
|
|
@ -29,6 +31,67 @@
|
|||
#include "main/shader_types.h"
|
||||
#include "main/consts_exts.h"
|
||||
|
||||
/**
|
||||
* Given a string identifying a program resource, break it into a base name
|
||||
* and an optional array index in square brackets.
|
||||
*
|
||||
* If an array index is present, \c out_base_name_end is set to point to the
|
||||
* "[" that precedes the array index, and the array index itself is returned
|
||||
* as a long.
|
||||
*
|
||||
* If no array index is present (or if the array index is negative or
|
||||
* mal-formed), \c out_base_name_end, is set to point to the null terminator
|
||||
* at the end of the input string, and -1 is returned.
|
||||
*
|
||||
* Only the final array index is parsed; if the string contains other array
|
||||
* indices (or structure field accesses), they are left in the base name.
|
||||
*
|
||||
* No attempt is made to check that the base name is properly formed;
|
||||
* typically the caller will look up the base name in a hash table, so
|
||||
* ill-formed base names simply turn into hash table lookup failures.
|
||||
*/
|
||||
long
|
||||
link_util_parse_program_resource_name(const GLchar *name, const size_t len,
|
||||
const GLchar **out_base_name_end)
|
||||
{
|
||||
/* Section 7.3.1 ("Program Interfaces") of the OpenGL 4.3 spec says:
|
||||
*
|
||||
* "When an integer array element or block instance number is part of
|
||||
* the name string, it will be specified in decimal form without a "+"
|
||||
* or "-" sign or any extra leading zeroes. Additionally, the name
|
||||
* string will not include white space anywhere in the string."
|
||||
*/
|
||||
|
||||
*out_base_name_end = name + len;
|
||||
|
||||
if (len == 0 || name[len-1] != ']')
|
||||
return -1;
|
||||
|
||||
/* Walk backwards over the string looking for a non-digit character. This
|
||||
* had better be the opening bracket for an array index.
|
||||
*
|
||||
* Initially, i specifies the location of the ']'. Since the string may
|
||||
* contain only the ']' charcater, walk backwards very carefully.
|
||||
*/
|
||||
unsigned i;
|
||||
for (i = len - 1; (i > 0) && isdigit(name[i-1]); --i)
|
||||
/* empty */ ;
|
||||
|
||||
if ((i == 0) || name[i-1] != '[')
|
||||
return -1;
|
||||
|
||||
long array_index = strtol(&name[i], NULL, 10);
|
||||
if (array_index < 0)
|
||||
return -1;
|
||||
|
||||
/* Check for leading zero */
|
||||
if (name[i] == '0' && name[i+1] != ']')
|
||||
return -1;
|
||||
|
||||
*out_base_name_end = name + (i - 1);
|
||||
return array_index;
|
||||
}
|
||||
|
||||
/* Utility methods shared between the GLSL IR and the NIR */
|
||||
|
||||
/* From the OpenGL 4.6 specification, 7.3.1.1 Naming Active Resources:
|
||||
|
|
|
|||
|
|
@ -71,6 +71,10 @@ linker_error(struct gl_shader_program *prog, const char *fmt, ...);
|
|||
void
|
||||
linker_warning(struct gl_shader_program *prog, const char *fmt, ...);
|
||||
|
||||
long
|
||||
link_util_parse_program_resource_name(const GLchar *name, const size_t len,
|
||||
const GLchar **out_base_name_end);
|
||||
|
||||
bool
|
||||
link_util_should_add_buffer_variable(struct gl_shader_program *prog,
|
||||
struct gl_uniform_storage *uniform,
|
||||
|
|
|
|||
|
|
@ -48,8 +48,4 @@ extern void
|
|||
build_program_resource_list(const struct gl_constants *consts,
|
||||
struct gl_shader_program *shProg);
|
||||
|
||||
extern long
|
||||
parse_program_resource_name(const GLchar *name, const size_t len,
|
||||
const GLchar **out_base_name_end);
|
||||
|
||||
#endif /* GLSL_PROGRAM_H */
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
#include "main/uniforms.h"
|
||||
#include "compiler/glsl/glsl_symbol_table.h"
|
||||
#include "compiler/glsl/ir.h"
|
||||
#include "compiler/glsl/program.h"
|
||||
#include "compiler/glsl/linker_util.h"
|
||||
#include "compiler/glsl/string_to_uint_map.h"
|
||||
#include "util/mesa-sha1.h"
|
||||
#include "c99_alloca.h"
|
||||
|
|
@ -619,7 +619,7 @@ valid_array_index(const GLchar *name, int len, unsigned *array_index)
|
|||
long idx = 0;
|
||||
const GLchar *out_base_name_end;
|
||||
|
||||
idx = parse_program_resource_name(name, len, &out_base_name_end);
|
||||
idx = link_util_parse_program_resource_name(name, len, &out_base_name_end);
|
||||
if (idx < 0)
|
||||
return false;
|
||||
|
||||
|
|
@ -641,7 +641,7 @@ search_resource_hash(struct gl_shader_program *shProg,
|
|||
return NULL;
|
||||
|
||||
const char *base_name_end;
|
||||
long index = parse_program_resource_name(name, len, &base_name_end);
|
||||
long index = link_util_parse_program_resource_name(name, len, &base_name_end);
|
||||
char *name_copy;
|
||||
|
||||
/* If dealing with array, we need to get the basename. */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue