mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-22 07:00:12 +01:00
glsl: reduce memory footprint of uniform_storage struct
The uniform will only be of a single type so store the data for opaque types in a single array. Cc: Francisco Jerez <currojerez@riseup.net> Cc: Ilia Mirkin <imirkin@alum.mit.edu>
This commit is contained in:
parent
b85757bc72
commit
763cd8c080
11 changed files with 43 additions and 51 deletions
|
|
@ -110,11 +110,7 @@ struct gl_uniform_storage {
|
||||||
*/
|
*/
|
||||||
bool initialized;
|
bool initialized;
|
||||||
|
|
||||||
struct gl_opaque_uniform_index sampler[MESA_SHADER_STAGES];
|
struct gl_opaque_uniform_index opaque[MESA_SHADER_STAGES];
|
||||||
|
|
||||||
struct gl_opaque_uniform_index image[MESA_SHADER_STAGES];
|
|
||||||
|
|
||||||
struct gl_opaque_uniform_index subroutine[MESA_SHADER_STAGES];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Storage used by the driver for the uniform
|
* Storage used by the driver for the uniform
|
||||||
|
|
|
||||||
|
|
@ -134,16 +134,16 @@ set_opaque_binding(gl_shader_program *prog, const char *name, int binding)
|
||||||
|
|
||||||
if (shader) {
|
if (shader) {
|
||||||
if (storage->type->base_type == GLSL_TYPE_SAMPLER &&
|
if (storage->type->base_type == GLSL_TYPE_SAMPLER &&
|
||||||
storage->sampler[sh].active) {
|
storage->opaque[sh].active) {
|
||||||
for (unsigned i = 0; i < elements; i++) {
|
for (unsigned i = 0; i < elements; i++) {
|
||||||
const unsigned index = storage->sampler[sh].index + i;
|
const unsigned index = storage->opaque[sh].index + i;
|
||||||
shader->SamplerUnits[index] = storage->storage[i].i;
|
shader->SamplerUnits[index] = storage->storage[i].i;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (storage->type->base_type == GLSL_TYPE_IMAGE &&
|
} else if (storage->type->base_type == GLSL_TYPE_IMAGE &&
|
||||||
storage->image[sh].active) {
|
storage->opaque[sh].active) {
|
||||||
for (unsigned i = 0; i < elements; i++) {
|
for (unsigned i = 0; i < elements; i++) {
|
||||||
const unsigned index = storage->image[sh].index + i;
|
const unsigned index = storage->opaque[sh].index + i;
|
||||||
shader->ImageUnits[index] = storage->storage[i].i;
|
shader->ImageUnits[index] = storage->storage[i].i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -243,8 +243,8 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
|
||||||
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
|
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
|
||||||
gl_shader *shader = prog->_LinkedShaders[sh];
|
gl_shader *shader = prog->_LinkedShaders[sh];
|
||||||
|
|
||||||
if (shader && storage->sampler[sh].active) {
|
if (shader && storage->opaque[sh].active) {
|
||||||
unsigned index = storage->sampler[sh].index;
|
unsigned index = storage->opaque[sh].index;
|
||||||
|
|
||||||
shader->SamplerUnits[index] = storage->storage[0].i;
|
shader->SamplerUnits[index] = storage->storage[0].i;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -566,7 +566,7 @@ private:
|
||||||
struct gl_uniform_storage *uniform, const char *name)
|
struct gl_uniform_storage *uniform, const char *name)
|
||||||
{
|
{
|
||||||
if (base_type->is_sampler()) {
|
if (base_type->is_sampler()) {
|
||||||
uniform->sampler[shader_type].active = true;
|
uniform->opaque[shader_type].active = true;
|
||||||
|
|
||||||
/* Handle multiple samplers inside struct arrays */
|
/* Handle multiple samplers inside struct arrays */
|
||||||
if (this->record_array_count > 1) {
|
if (this->record_array_count > 1) {
|
||||||
|
|
@ -586,8 +586,8 @@ private:
|
||||||
/* In this case, we've already seen this uniform so we just use
|
/* In this case, we've already seen this uniform so we just use
|
||||||
* the next sampler index recorded the last time we visited.
|
* the next sampler index recorded the last time we visited.
|
||||||
*/
|
*/
|
||||||
uniform->sampler[shader_type].index = index;
|
uniform->opaque[shader_type].index = index;
|
||||||
index = inner_array_size + uniform->sampler[shader_type].index;
|
index = inner_array_size + uniform->opaque[shader_type].index;
|
||||||
this->record_next_sampler->put(index, name_copy);
|
this->record_next_sampler->put(index, name_copy);
|
||||||
|
|
||||||
ralloc_free(name_copy);
|
ralloc_free(name_copy);
|
||||||
|
|
@ -605,13 +605,13 @@ private:
|
||||||
* structs. This allows the offset to be easily calculated for
|
* structs. This allows the offset to be easily calculated for
|
||||||
* indirect indexing.
|
* indirect indexing.
|
||||||
*/
|
*/
|
||||||
uniform->sampler[shader_type].index = this->next_sampler;
|
uniform->opaque[shader_type].index = this->next_sampler;
|
||||||
this->next_sampler +=
|
this->next_sampler +=
|
||||||
inner_array_size * this->record_array_count;
|
inner_array_size * this->record_array_count;
|
||||||
|
|
||||||
/* Store the next index for future passes over the struct array
|
/* Store the next index for future passes over the struct array
|
||||||
*/
|
*/
|
||||||
index = uniform->sampler[shader_type].index + inner_array_size;
|
index = uniform->opaque[shader_type].index + inner_array_size;
|
||||||
this->record_next_sampler->put(index, name_copy);
|
this->record_next_sampler->put(index, name_copy);
|
||||||
ralloc_free(name_copy);
|
ralloc_free(name_copy);
|
||||||
}
|
}
|
||||||
|
|
@ -619,22 +619,19 @@ private:
|
||||||
/* Increment the sampler by 1 for non-arrays and by the number of
|
/* Increment the sampler by 1 for non-arrays and by the number of
|
||||||
* array elements for arrays.
|
* array elements for arrays.
|
||||||
*/
|
*/
|
||||||
uniform->sampler[shader_type].index = this->next_sampler;
|
uniform->opaque[shader_type].index = this->next_sampler;
|
||||||
this->next_sampler += MAX2(1, uniform->array_elements);
|
this->next_sampler += MAX2(1, uniform->array_elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
const gl_texture_index target = base_type->sampler_index();
|
const gl_texture_index target = base_type->sampler_index();
|
||||||
const unsigned shadow = base_type->sampler_shadow;
|
const unsigned shadow = base_type->sampler_shadow;
|
||||||
for (unsigned i = uniform->sampler[shader_type].index;
|
for (unsigned i = uniform->opaque[shader_type].index;
|
||||||
i < MIN2(this->next_sampler, MAX_SAMPLERS);
|
i < MIN2(this->next_sampler, MAX_SAMPLERS);
|
||||||
i++) {
|
i++) {
|
||||||
this->targets[i] = target;
|
this->targets[i] = target;
|
||||||
this->shader_samplers_used |= 1U << i;
|
this->shader_samplers_used |= 1U << i;
|
||||||
this->shader_shadow_samplers |= shadow << i;
|
this->shader_shadow_samplers |= shadow << i;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
uniform->sampler[shader_type].index = ~0;
|
|
||||||
uniform->sampler[shader_type].active = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -642,17 +639,14 @@ private:
|
||||||
struct gl_uniform_storage *uniform)
|
struct gl_uniform_storage *uniform)
|
||||||
{
|
{
|
||||||
if (base_type->is_image()) {
|
if (base_type->is_image()) {
|
||||||
uniform->image[shader_type].index = this->next_image;
|
uniform->opaque[shader_type].index = this->next_image;
|
||||||
uniform->image[shader_type].active = true;
|
uniform->opaque[shader_type].active = true;
|
||||||
|
|
||||||
/* Increment the image index by 1 for non-arrays and by the
|
/* Increment the image index by 1 for non-arrays and by the
|
||||||
* number of array elements for arrays.
|
* number of array elements for arrays.
|
||||||
*/
|
*/
|
||||||
this->next_image += MAX2(1, uniform->array_elements);
|
this->next_image += MAX2(1, uniform->array_elements);
|
||||||
|
|
||||||
} else {
|
|
||||||
uniform->image[shader_type].index = ~0;
|
|
||||||
uniform->image[shader_type].active = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -660,17 +654,14 @@ private:
|
||||||
struct gl_uniform_storage *uniform)
|
struct gl_uniform_storage *uniform)
|
||||||
{
|
{
|
||||||
if (base_type->is_subroutine()) {
|
if (base_type->is_subroutine()) {
|
||||||
uniform->subroutine[shader_type].index = this->next_subroutine;
|
uniform->opaque[shader_type].index = this->next_subroutine;
|
||||||
uniform->subroutine[shader_type].active = true;
|
uniform->opaque[shader_type].active = true;
|
||||||
|
|
||||||
/* Increment the subroutine index by 1 for non-arrays and by the
|
/* Increment the subroutine index by 1 for non-arrays and by the
|
||||||
* number of array elements for arrays.
|
* number of array elements for arrays.
|
||||||
*/
|
*/
|
||||||
this->next_subroutine += MAX2(1, uniform->array_elements);
|
this->next_subroutine += MAX2(1, uniform->array_elements);
|
||||||
|
|
||||||
} else {
|
|
||||||
uniform->subroutine[shader_type].index = ~0;
|
|
||||||
uniform->subroutine[shader_type].active = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -738,6 +729,10 @@ private:
|
||||||
base_type = type;
|
base_type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Initialise opaque data */
|
||||||
|
this->uniforms[id].opaque[shader_type].index = ~0;
|
||||||
|
this->uniforms[id].opaque[shader_type].active = false;
|
||||||
|
|
||||||
/* This assigns uniform indices to sampler and image uniforms. */
|
/* This assigns uniform indices to sampler and image uniforms. */
|
||||||
handle_samplers(base_type, &this->uniforms[id], name);
|
handle_samplers(base_type, &this->uniforms[id], name);
|
||||||
handle_images(base_type, &this->uniforms[id]);
|
handle_images(base_type, &this->uniforms[id]);
|
||||||
|
|
@ -1029,7 +1024,7 @@ link_set_image_access_qualifiers(struct gl_shader_program *prog)
|
||||||
assert(found);
|
assert(found);
|
||||||
(void) found;
|
(void) found;
|
||||||
const gl_uniform_storage *storage = &prog->UniformStorage[id];
|
const gl_uniform_storage *storage = &prog->UniformStorage[id];
|
||||||
const unsigned index = storage->image[i].index;
|
const unsigned index = storage->opaque[i].index;
|
||||||
const GLenum access = (var->data.image_read_only ? GL_READ_ONLY :
|
const GLenum access = (var->data.image_read_only ? GL_READ_ONLY :
|
||||||
var->data.image_write_only ? GL_WRITE_ONLY :
|
var->data.image_write_only ? GL_WRITE_ONLY :
|
||||||
GL_READ_WRITE);
|
GL_READ_WRITE);
|
||||||
|
|
@ -1238,7 +1233,7 @@ link_assign_uniform_locations(struct gl_shader_program *prog,
|
||||||
if (!sh)
|
if (!sh)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!uniforms[i].subroutine[j].active)
|
if (!uniforms[i].opaque[j].active)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* How many new entries for this uniform? */
|
/* How many new entries for this uniform? */
|
||||||
|
|
@ -1268,7 +1263,7 @@ link_assign_uniform_locations(struct gl_shader_program *prog,
|
||||||
if (!sh)
|
if (!sh)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!uniforms[i].subroutine[j].active)
|
if (!uniforms[i].opaque[j].active)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sh->SubroutineUniformRemapTable =
|
sh->SubroutineUniformRemapTable =
|
||||||
|
|
|
||||||
|
|
@ -3497,7 +3497,7 @@ build_program_resource_list(struct gl_shader_program *shProg)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int j = MESA_SHADER_VERTEX; j < MESA_SHADER_STAGES; j++) {
|
for (int j = MESA_SHADER_VERTEX; j < MESA_SHADER_STAGES; j++) {
|
||||||
if (!shProg->UniformStorage[i].subroutine[j].active)
|
if (!shProg->UniformStorage[i].opaque[j].active)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
type = _mesa_shader_stage_to_subroutine_uniform((gl_shader_stage)j);
|
type = _mesa_shader_stage_to_subroutine_uniform((gl_shader_stage)j);
|
||||||
|
|
|
||||||
|
|
@ -131,13 +131,13 @@ lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_progr
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location > shader_program->NumUniformStorage - 1 ||
|
if (location > shader_program->NumUniformStorage - 1 ||
|
||||||
!shader_program->UniformStorage[location].sampler[stage].active) {
|
!shader_program->UniformStorage[location].opaque[stage].active) {
|
||||||
assert(!"cannot return a sampler");
|
assert(!"cannot return a sampler");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
instr->sampler_index +=
|
instr->sampler_index +=
|
||||||
shader_program->UniformStorage[location].sampler[stage].index;
|
shader_program->UniformStorage[location].opaque[stage].index;
|
||||||
|
|
||||||
instr->sampler = NULL;
|
instr->sampler = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,8 +117,8 @@ establish_uniform_storage(struct gl_shader_program *prog, unsigned num_storage,
|
||||||
prog->UniformStorage[index_to_set].array_elements = array_size;
|
prog->UniformStorage[index_to_set].array_elements = array_size;
|
||||||
prog->UniformStorage[index_to_set].initialized = false;
|
prog->UniformStorage[index_to_set].initialized = false;
|
||||||
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
|
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
|
||||||
prog->UniformStorage[index_to_set].sampler[sh].index = ~0;
|
prog->UniformStorage[index_to_set].opaque[sh].index = ~0;
|
||||||
prog->UniformStorage[index_to_set].sampler[sh].active = false;
|
prog->UniformStorage[index_to_set].opaque[sh].active = false;
|
||||||
}
|
}
|
||||||
prog->UniformStorage[index_to_set].num_driver_storage = 0;
|
prog->UniformStorage[index_to_set].num_driver_storage = 0;
|
||||||
prog->UniformStorage[index_to_set].driver_storage = NULL;
|
prog->UniformStorage[index_to_set].driver_storage = NULL;
|
||||||
|
|
@ -138,8 +138,8 @@ establish_uniform_storage(struct gl_shader_program *prog, unsigned num_storage,
|
||||||
prog->UniformStorage[i].array_elements = 0;
|
prog->UniformStorage[i].array_elements = 0;
|
||||||
prog->UniformStorage[i].initialized = false;
|
prog->UniformStorage[i].initialized = false;
|
||||||
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
|
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
|
||||||
prog->UniformStorage[i].sampler[sh].index = ~0;
|
prog->UniformStorage[i].opaque[sh].index = ~0;
|
||||||
prog->UniformStorage[i].sampler[sh].active = false;
|
prog->UniformStorage[i].opaque[sh].active = false;
|
||||||
}
|
}
|
||||||
prog->UniformStorage[i].num_driver_storage = 0;
|
prog->UniformStorage[i].num_driver_storage = 0;
|
||||||
prog->UniformStorage[i].driver_storage = NULL;
|
prog->UniformStorage[i].driver_storage = NULL;
|
||||||
|
|
|
||||||
|
|
@ -1436,7 +1436,7 @@ brw_setup_image_uniform_values(gl_shader_stage stage,
|
||||||
&stage_prog_data->param[param_start_index];
|
&stage_prog_data->param[param_start_index];
|
||||||
|
|
||||||
for (unsigned i = 0; i < MAX2(storage->array_elements, 1); i++) {
|
for (unsigned i = 0; i < MAX2(storage->array_elements, 1); i++) {
|
||||||
const unsigned image_idx = storage->image[stage].index + i;
|
const unsigned image_idx = storage->opaque[stage].index + i;
|
||||||
const brw_image_param *image_param =
|
const brw_image_param *image_param =
|
||||||
&stage_prog_data->image_param[image_idx];
|
&stage_prog_data->image_param[image_idx];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2597,7 +2597,7 @@ _mesa_GetUniformSubroutineuiv(GLenum shadertype, GLint location,
|
||||||
|
|
||||||
{
|
{
|
||||||
struct gl_uniform_storage *uni = sh->SubroutineUniformRemapTable[location];
|
struct gl_uniform_storage *uni = sh->SubroutineUniformRemapTable[location];
|
||||||
int offset = location - uni->subroutine[stage].index;
|
int offset = location - uni->opaque[stage].index;
|
||||||
memcpy(params, &uni->storage[offset],
|
memcpy(params, &uni->storage[offset],
|
||||||
sizeof(GLuint));
|
sizeof(GLuint));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -804,11 +804,11 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
|
||||||
|
|
||||||
/* If the shader stage doesn't use the sampler uniform, skip this.
|
/* If the shader stage doesn't use the sampler uniform, skip this.
|
||||||
*/
|
*/
|
||||||
if (sh == NULL || !uni->sampler[i].active)
|
if (sh == NULL || !uni->opaque[i].active)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int j = 0; j < count; j++) {
|
for (int j = 0; j < count; j++) {
|
||||||
sh->SamplerUnits[uni->sampler[i].index + offset + j] =
|
sh->SamplerUnits[uni->opaque[i].index + offset + j] =
|
||||||
((unsigned *) values)[j];
|
((unsigned *) values)[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -850,11 +850,11 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
|
||||||
*/
|
*/
|
||||||
if (uni->type->is_image()) {
|
if (uni->type->is_image()) {
|
||||||
for (int i = 0; i < MESA_SHADER_STAGES; i++) {
|
for (int i = 0; i < MESA_SHADER_STAGES; i++) {
|
||||||
if (uni->image[i].active) {
|
if (uni->opaque[i].active) {
|
||||||
struct gl_shader *sh = shProg->_LinkedShaders[i];
|
struct gl_shader *sh = shProg->_LinkedShaders[i];
|
||||||
|
|
||||||
for (int j = 0; j < count; j++)
|
for (int j = 0; j < count; j++)
|
||||||
sh->ImageUnits[uni->image[i].index + offset + j] =
|
sh->ImageUnits[uni->opaque[i].index + offset + j] =
|
||||||
((GLint *) values)[j];
|
((GLint *) values)[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2352,11 +2352,12 @@ add_uniform_to_shader::visit_field(const glsl_type *type, const char *name,
|
||||||
struct gl_uniform_storage *storage =
|
struct gl_uniform_storage *storage =
|
||||||
&this->shader_program->UniformStorage[location];
|
&this->shader_program->UniformStorage[location];
|
||||||
|
|
||||||
assert(storage->sampler[shader_type].active);
|
assert(storage->type->is_sampler() &&
|
||||||
|
storage->opaque[shader_type].active);
|
||||||
|
|
||||||
for (unsigned int j = 0; j < size / 4; j++)
|
for (unsigned int j = 0; j < size / 4; j++)
|
||||||
params->ParameterValues[index + j][0].f =
|
params->ParameterValues[index + j][0].f =
|
||||||
storage->sampler[shader_type].index + j;
|
storage->opaque[shader_type].index + j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ _mesa_get_sampler_uniform_value(class ir_dereference *sampler,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shader_program->UniformStorage[location].sampler[shader].active) {
|
if (!shader_program->UniformStorage[location].opaque[shader].active) {
|
||||||
assert(0 && "cannot return a sampler");
|
assert(0 && "cannot return a sampler");
|
||||||
linker_error(shader_program,
|
linker_error(shader_program,
|
||||||
"cannot return a sampler named %s, because it is not "
|
"cannot return a sampler named %s, because it is not "
|
||||||
|
|
@ -128,7 +128,7 @@ _mesa_get_sampler_uniform_value(class ir_dereference *sampler,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return shader_program->UniformStorage[location].sampler[shader].index +
|
return shader_program->UniformStorage[location].opaque[shader].index +
|
||||||
getname.offset;
|
getname.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue