compiler/glsl: refactor empty_uniform_block utilities to linker_util
This includes: * Move the defition of empty_uniform_block to linker_util.h * Move find_empty_block (with a rename) to linker_util.h * Refactor some code at linker.cpp to a new method at linker_util.h (link_util_update_empty_uniform_locations) So all that code could be used by the GLSL linker and the NIR linker used for ARB_gl_spirv. v2: include just "ir_uniform.h" (Timothy Arceri) Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
@@ -1153,38 +1153,6 @@ assign_hidden_uniform_slot_id(const char *name, unsigned hidden_id,
|
|||||||
uniform_size->map->put(hidden_uniform_start + hidden_id, name);
|
uniform_size->map->put(hidden_uniform_start + hidden_id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Search through the list of empty blocks to find one that fits the current
|
|
||||||
* uniform.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
find_empty_block(struct gl_shader_program *prog,
|
|
||||||
struct gl_uniform_storage *uniform)
|
|
||||||
{
|
|
||||||
const unsigned entries = MAX2(1, uniform->array_elements);
|
|
||||||
|
|
||||||
foreach_list_typed(struct empty_uniform_block, block, link,
|
|
||||||
&prog->EmptyUniformLocations) {
|
|
||||||
/* Found a block with enough slots to fit the uniform */
|
|
||||||
if (block->slots == entries) {
|
|
||||||
unsigned start = block->start;
|
|
||||||
exec_node_remove(&block->link);
|
|
||||||
ralloc_free(block);
|
|
||||||
|
|
||||||
return start;
|
|
||||||
/* Found a block with more slots than needed. It can still be used. */
|
|
||||||
} else if (block->slots > entries) {
|
|
||||||
unsigned start = block->start;
|
|
||||||
block->start += entries;
|
|
||||||
block->slots -= entries;
|
|
||||||
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
link_setup_uniform_remap_tables(struct gl_context *ctx,
|
link_setup_uniform_remap_tables(struct gl_context *ctx,
|
||||||
struct gl_shader_program *prog)
|
struct gl_shader_program *prog)
|
||||||
@@ -1239,7 +1207,7 @@ link_setup_uniform_remap_tables(struct gl_context *ctx,
|
|||||||
int chosen_location = -1;
|
int chosen_location = -1;
|
||||||
|
|
||||||
if (empty_locs)
|
if (empty_locs)
|
||||||
chosen_location = find_empty_block(prog, &prog->data->UniformStorage[i]);
|
chosen_location = link_util_find_empty_block(prog, &prog->data->UniformStorage[i]);
|
||||||
|
|
||||||
/* Add new entries to the total amount of entries. */
|
/* Add new entries to the total amount of entries. */
|
||||||
total_entries += entries;
|
total_entries += entries;
|
||||||
|
@@ -76,6 +76,7 @@
|
|||||||
#include "util/set.h"
|
#include "util/set.h"
|
||||||
#include "string_to_uint_map.h"
|
#include "string_to_uint_map.h"
|
||||||
#include "linker.h"
|
#include "linker.h"
|
||||||
|
#include "linker_util.h"
|
||||||
#include "link_varyings.h"
|
#include "link_varyings.h"
|
||||||
#include "ir_optimization.h"
|
#include "ir_optimization.h"
|
||||||
#include "ir_rvalue_visitor.h"
|
#include "ir_rvalue_visitor.h"
|
||||||
@@ -3527,23 +3528,7 @@ check_explicit_uniform_locations(struct gl_context *ctx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct empty_uniform_block *current_block = NULL;
|
link_util_update_empty_uniform_locations(prog);
|
||||||
|
|
||||||
for (unsigned i = 0; i < prog->NumUniformRemapTable; i++) {
|
|
||||||
/* We found empty space in UniformRemapTable. */
|
|
||||||
if (prog->UniformRemapTable[i] == NULL) {
|
|
||||||
/* We've found the beginning of a new continous block of empty slots */
|
|
||||||
if (!current_block || current_block->start + current_block->slots != i) {
|
|
||||||
current_block = rzalloc(prog, struct empty_uniform_block);
|
|
||||||
current_block->start = i;
|
|
||||||
exec_list_push_tail(&prog->EmptyUniformLocations,
|
|
||||||
¤t_block->link);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The current block continues, so we simply increment its slots */
|
|
||||||
current_block->slots++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete uniform_map;
|
delete uniform_map;
|
||||||
prog->NumExplicitUniformLocations = entries_total;
|
prog->NumExplicitUniformLocations = entries_total;
|
||||||
|
@@ -194,17 +194,4 @@ private:
|
|||||||
const glsl_struct_field *named_ifc_member);
|
const glsl_struct_field *named_ifc_member);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Sometimes there are empty slots left over in UniformRemapTable after we
|
|
||||||
* allocate slots to explicit locations. This struct represents a single
|
|
||||||
* continouous block of empty slots in UniformRemapTable.
|
|
||||||
*/
|
|
||||||
struct empty_uniform_block {
|
|
||||||
struct exec_node link;
|
|
||||||
/* The start location of the block */
|
|
||||||
unsigned start;
|
|
||||||
/* The number of slots in the block */
|
|
||||||
unsigned slots;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* GLSL_LINKER_H */
|
#endif /* GLSL_LINKER_H */
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#include "main/mtypes.h"
|
#include "main/mtypes.h"
|
||||||
#include "linker_util.h"
|
#include "linker_util.h"
|
||||||
#include "util/set.h"
|
#include "util/set.h"
|
||||||
|
#include "ir_uniform.h" /* for gl_uniform_storage */
|
||||||
|
|
||||||
/* Utility methods shared between the GLSL IR and the NIR */
|
/* Utility methods shared between the GLSL IR and the NIR */
|
||||||
|
|
||||||
@@ -62,3 +63,57 @@ link_util_add_program_resource(struct gl_shader_program *prog,
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search through the list of empty blocks to find one that fits the current
|
||||||
|
* uniform.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
link_util_find_empty_block(struct gl_shader_program *prog,
|
||||||
|
struct gl_uniform_storage *uniform)
|
||||||
|
{
|
||||||
|
const unsigned entries = MAX2(1, uniform->array_elements);
|
||||||
|
|
||||||
|
foreach_list_typed(struct empty_uniform_block, block, link,
|
||||||
|
&prog->EmptyUniformLocations) {
|
||||||
|
/* Found a block with enough slots to fit the uniform */
|
||||||
|
if (block->slots == entries) {
|
||||||
|
unsigned start = block->start;
|
||||||
|
exec_node_remove(&block->link);
|
||||||
|
ralloc_free(block);
|
||||||
|
|
||||||
|
return start;
|
||||||
|
/* Found a block with more slots than needed. It can still be used. */
|
||||||
|
} else if (block->slots > entries) {
|
||||||
|
unsigned start = block->start;
|
||||||
|
block->start += entries;
|
||||||
|
block->slots -= entries;
|
||||||
|
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
link_util_update_empty_uniform_locations(struct gl_shader_program *prog)
|
||||||
|
{
|
||||||
|
struct empty_uniform_block *current_block = NULL;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < prog->NumUniformRemapTable; i++) {
|
||||||
|
/* We found empty space in UniformRemapTable. */
|
||||||
|
if (prog->UniformRemapTable[i] == NULL) {
|
||||||
|
/* We've found the beginning of a new continous block of empty slots */
|
||||||
|
if (!current_block || current_block->start + current_block->slots != i) {
|
||||||
|
current_block = rzalloc(prog, struct empty_uniform_block);
|
||||||
|
current_block->start = i;
|
||||||
|
exec_list_push_tail(&prog->EmptyUniformLocations,
|
||||||
|
¤t_block->link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The current block continues, so we simply increment its slots */
|
||||||
|
current_block->slots++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -25,11 +25,25 @@
|
|||||||
#define GLSL_LINKER_UTIL_H
|
#define GLSL_LINKER_UTIL_H
|
||||||
|
|
||||||
struct gl_shader_program;
|
struct gl_shader_program;
|
||||||
|
struct gl_uniform_storage;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sometimes there are empty slots left over in UniformRemapTable after we
|
||||||
|
* allocate slots to explicit locations. This struct represents a single
|
||||||
|
* continouous block of empty slots in UniformRemapTable.
|
||||||
|
*/
|
||||||
|
struct empty_uniform_block {
|
||||||
|
struct exec_node link;
|
||||||
|
/* The start location of the block */
|
||||||
|
unsigned start;
|
||||||
|
/* The number of slots in the block */
|
||||||
|
unsigned slots;
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
linker_error(struct gl_shader_program *prog, const char *fmt, ...);
|
linker_error(struct gl_shader_program *prog, const char *fmt, ...);
|
||||||
|
|
||||||
@@ -41,6 +55,13 @@ link_util_add_program_resource(struct gl_shader_program *prog,
|
|||||||
struct set *resource_set,
|
struct set *resource_set,
|
||||||
GLenum type, const void *data, uint8_t stages);
|
GLenum type, const void *data, uint8_t stages);
|
||||||
|
|
||||||
|
int
|
||||||
|
link_util_find_empty_block(struct gl_shader_program *prog,
|
||||||
|
struct gl_uniform_storage *uniform);
|
||||||
|
|
||||||
|
void
|
||||||
|
link_util_update_empty_uniform_locations(struct gl_shader_program *prog);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user