glsl: pass UseSTD430AsDefaultPacking to where it will be used

Here we also make use of the UseSTD430AsDefaultPacking constant
and call the new get_internal_ifc_packing() helper.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
This commit is contained in:
Timothy Arceri
2017-07-24 10:24:53 +10:00
parent 12e1f0c696
commit 4c2422067b
9 changed files with 94 additions and 44 deletions

View File

@@ -146,7 +146,7 @@ bool lower_packing_builtins(exec_list *instructions, int op_mask);
void lower_shared_reference(struct gl_linked_shader *shader, void lower_shared_reference(struct gl_linked_shader *shader,
unsigned *shared_size); unsigned *shared_size);
void lower_ubo_reference(struct gl_linked_shader *shader, void lower_ubo_reference(struct gl_linked_shader *shader,
bool clamp_block_indices); bool clamp_block_indices, bool use_std430_as_default);
void lower_packed_varyings(void *mem_ctx, void lower_packed_varyings(void *mem_ctx,
unsigned locations_used, unsigned locations_used,
const uint8_t *components, const uint8_t *components,

View File

@@ -34,10 +34,12 @@ namespace {
class ubo_visitor : public program_resource_visitor { class ubo_visitor : public program_resource_visitor {
public: public:
ubo_visitor(void *mem_ctx, gl_uniform_buffer_variable *variables, ubo_visitor(void *mem_ctx, gl_uniform_buffer_variable *variables,
unsigned num_variables, struct gl_shader_program *prog) unsigned num_variables, struct gl_shader_program *prog,
bool use_std430_as_default)
: index(0), offset(0), buffer_size(0), variables(variables), : index(0), offset(0), buffer_size(0), variables(variables),
num_variables(num_variables), mem_ctx(mem_ctx), num_variables(num_variables), mem_ctx(mem_ctx),
is_array_instance(false), prog(prog) is_array_instance(false), prog(prog),
use_std430_as_default(use_std430_as_default)
{ {
/* empty */ /* empty */
} }
@@ -47,7 +49,8 @@ public:
this->offset = 0; this->offset = 0;
this->buffer_size = 0; this->buffer_size = 0;
this->is_array_instance = strchr(name, ']') != NULL; this->is_array_instance = strchr(name, ']') != NULL;
this->program_resource_visitor::process(type, name); this->program_resource_visitor::process(type, name,
use_std430_as_default);
} }
unsigned index; unsigned index;
@@ -181,6 +184,8 @@ private:
*/ */
this->buffer_size = glsl_align(this->offset, 16); this->buffer_size = glsl_align(this->offset, 16);
} }
bool use_std430_as_default;
}; };
class count_block_size : public program_resource_visitor { class count_block_size : public program_resource_visitor {
@@ -352,7 +357,8 @@ create_buffer_blocks(void *mem_ctx, struct gl_context *ctx,
/* Add each variable from each uniform block to the API tracking /* Add each variable from each uniform block to the API tracking
* structures. * structures.
*/ */
ubo_visitor parcel(blocks, variables, num_variables, prog); ubo_visitor parcel(blocks, variables, num_variables, prog,
ctx->Const.UseSTD430AsDefaultPacking);
unsigned i = 0; unsigned i = 0;
struct hash_entry *entry; struct hash_entry *entry;
@@ -438,7 +444,8 @@ link_uniform_blocks(void *mem_ctx,
} }
block_size.num_active_uniforms = 0; block_size.num_active_uniforms = 0;
block_size.process(b->type->without_array(), ""); block_size.process(b->type->without_array(), "",
ctx->Const.UseSTD430AsDefaultPacking);
if (b->array != NULL) { if (b->array != NULL) {
unsigned aoa_size = b->type->arrays_of_arrays_size(); unsigned aoa_size = b->type->arrays_of_arrays_size();

View File

@@ -43,14 +43,17 @@
#define UNMAPPED_UNIFORM_LOC ~0u #define UNMAPPED_UNIFORM_LOC ~0u
void void
program_resource_visitor::process(const glsl_type *type, const char *name) program_resource_visitor::process(const glsl_type *type, const char *name,
bool use_std430_as_default)
{ {
assert(type->without_array()->is_record() assert(type->without_array()->is_record()
|| type->without_array()->is_interface()); || type->without_array()->is_interface());
unsigned record_array_count = 1; unsigned record_array_count = 1;
char *name_copy = ralloc_strdup(NULL, name); char *name_copy = ralloc_strdup(NULL, name);
enum glsl_interface_packing packing = type->get_interface_packing();
enum glsl_interface_packing packing =
type->get_internal_ifc_packing(use_std430_as_default);
recursion(type, &name_copy, strlen(name), false, NULL, packing, false, recursion(type, &name_copy, strlen(name), false, NULL, packing, false,
record_array_count, NULL); record_array_count, NULL);
@@ -58,15 +61,16 @@ program_resource_visitor::process(const glsl_type *type, const char *name)
} }
void void
program_resource_visitor::process(ir_variable *var) program_resource_visitor::process(ir_variable *var, bool use_std430_as_default)
{ {
unsigned record_array_count = 1; unsigned record_array_count = 1;
const bool row_major = const bool row_major =
var->data.matrix_layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR; var->data.matrix_layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR;
const enum glsl_interface_packing packing = var->get_interface_type() ? enum glsl_interface_packing packing = var->get_interface_type() ?
var->get_interface_type_packing() : var->get_interface_type()->
var->type->get_interface_packing(); get_internal_ifc_packing(use_std430_as_default) :
var->type->get_internal_ifc_packing(use_std430_as_default);
const glsl_type *t = const glsl_type *t =
var->data.from_named_ifc_block ? var->get_interface_type() : var->type; var->data.from_named_ifc_block ? var->get_interface_type() : var->type;
@@ -253,12 +257,14 @@ namespace {
class count_uniform_size : public program_resource_visitor { class count_uniform_size : public program_resource_visitor {
public: public:
count_uniform_size(struct string_to_uint_map *map, count_uniform_size(struct string_to_uint_map *map,
struct string_to_uint_map *hidden_map) struct string_to_uint_map *hidden_map,
bool use_std430_as_default)
: num_active_uniforms(0), num_hidden_uniforms(0), num_values(0), : num_active_uniforms(0), num_hidden_uniforms(0), num_values(0),
num_shader_samplers(0), num_shader_images(0), num_shader_samplers(0), num_shader_images(0),
num_shader_uniform_components(0), num_shader_subroutines(0), num_shader_uniform_components(0), num_shader_subroutines(0),
is_buffer_block(false), is_shader_storage(false), map(map), is_buffer_block(false), is_shader_storage(false), map(map),
hidden_map(hidden_map), current_var(NULL) hidden_map(hidden_map), current_var(NULL),
use_std430_as_default(use_std430_as_default)
{ {
/* empty */ /* empty */
} }
@@ -278,9 +284,10 @@ public:
this->is_shader_storage = var->is_in_shader_storage_block(); this->is_shader_storage = var->is_in_shader_storage_block();
if (var->is_interface_instance()) if (var->is_interface_instance())
program_resource_visitor::process(var->get_interface_type(), program_resource_visitor::process(var->get_interface_type(),
var->get_interface_type()->name); var->get_interface_type()->name,
use_std430_as_default);
else else
program_resource_visitor::process(var); program_resource_visitor::process(var, use_std430_as_default);
} }
/** /**
@@ -393,6 +400,8 @@ private:
* Current variable being processed. * Current variable being processed.
*/ */
ir_variable *current_var; ir_variable *current_var;
bool use_std430_as_default;
}; };
} /* anonymous namespace */ } /* anonymous namespace */
@@ -417,8 +426,10 @@ public:
parcel_out_uniform_storage(struct gl_shader_program *prog, parcel_out_uniform_storage(struct gl_shader_program *prog,
struct string_to_uint_map *map, struct string_to_uint_map *map,
struct gl_uniform_storage *uniforms, struct gl_uniform_storage *uniforms,
union gl_constant_value *values) union gl_constant_value *values,
: prog(prog), map(map), uniforms(uniforms), values(values), bool use_std430_as_default)
: prog(prog), map(map), uniforms(uniforms),
use_std430_as_default(use_std430_as_default), values(values),
bindless_targets(NULL), bindless_access(NULL) bindless_targets(NULL), bindless_access(NULL)
{ {
} }
@@ -498,7 +509,8 @@ public:
if (var->is_interface_instance()) { if (var->is_interface_instance()) {
ubo_byte_offset = 0; ubo_byte_offset = 0;
process(var->get_interface_type(), process(var->get_interface_type(),
var->get_interface_type()->name); var->get_interface_type()->name,
use_std430_as_default);
} else { } else {
const struct gl_uniform_block *const block = const struct gl_uniform_block *const block =
&blks[buffer_block_index]; &blks[buffer_block_index];
@@ -509,7 +521,7 @@ public:
&block->Uniforms[var->data.location]; &block->Uniforms[var->data.location];
ubo_byte_offset = ubo_var->Offset; ubo_byte_offset = ubo_var->Offset;
process(var); process(var, use_std430_as_default);
} }
} else { } else {
/* Store any explicit location and reset data location so we can /* Store any explicit location and reset data location so we can
@@ -518,7 +530,7 @@ public:
this->explicit_location = current_var->data.location; this->explicit_location = current_var->data.location;
current_var->data.location = -1; current_var->data.location = -1;
process(var); process(var, use_std430_as_default);
} }
delete this->record_next_sampler; delete this->record_next_sampler;
delete this->record_next_bindless_sampler; delete this->record_next_bindless_sampler;
@@ -896,6 +908,8 @@ private:
unsigned next_bindless_image; unsigned next_bindless_image;
unsigned next_subroutine; unsigned next_subroutine;
bool use_std430_as_default;
/** /**
* Field counter is used to take care that uniform structures * Field counter is used to take care that uniform structures
* with explicit locations get sequential locations. * with explicit locations get sequential locations.
@@ -1333,7 +1347,8 @@ link_assign_uniform_storage(struct gl_context *ctx,
#endif #endif
parcel_out_uniform_storage parcel(prog, prog->UniformHash, parcel_out_uniform_storage parcel(prog, prog->UniformHash,
prog->data->UniformStorage, data); prog->data->UniformStorage, data,
ctx->Const.UseSTD430AsDefaultPacking);
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
struct gl_linked_shader *shader = prog->_LinkedShaders[i]; struct gl_linked_shader *shader = prog->_LinkedShaders[i];
@@ -1436,7 +1451,8 @@ link_assign_uniform_locations(struct gl_shader_program *prog,
* glGetUniformLocation. * glGetUniformLocation.
*/ */
struct string_to_uint_map *hiddenUniforms = new string_to_uint_map; struct string_to_uint_map *hiddenUniforms = new string_to_uint_map;
count_uniform_size uniform_size(prog->UniformHash, hiddenUniforms); count_uniform_size uniform_size(prog->UniformHash, hiddenUniforms,
ctx->Const.UseSTD430AsDefaultPacking);
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
struct gl_linked_shader *sh = prog->_LinkedShaders[i]; struct gl_linked_shader *sh = prog->_LinkedShaders[i];

View File

@@ -1843,7 +1843,7 @@ public:
this->toplevel_var = var; this->toplevel_var = var;
this->varying_floats = 0; this->varying_floats = 0;
program_resource_visitor::process(var); program_resource_visitor::process(var, false);
} }
private: private:

View File

@@ -4126,9 +4126,9 @@ get_array_size(struct gl_uniform_storage *uni, const glsl_struct_field *field,
} }
static int static int
get_array_stride(struct gl_uniform_storage *uni, const glsl_type *interface, get_array_stride(struct gl_context *ctx, struct gl_uniform_storage *uni,
const glsl_struct_field *field, char *interface_name, const glsl_type *interface, const glsl_struct_field *field,
char *var_name) char *interface_name, char *var_name)
{ {
/* The ARB_program_interface_query spec says: /* The ARB_program_interface_query spec says:
* *
@@ -4152,7 +4152,9 @@ get_array_stride(struct gl_uniform_storage *uni, const glsl_type *interface,
var_name)) var_name))
return 0; return 0;
if (interface->interface_packing != GLSL_INTERFACE_PACKING_STD430) { if (GLSL_INTERFACE_PACKING_STD140 ==
interface->
get_internal_ifc_packing(ctx->Const.UseSTD430AsDefaultPacking)) {
if (array_type->is_record() || array_type->is_array()) if (array_type->is_record() || array_type->is_array())
return glsl_align(array_type->std140_size(row_major), 16); return glsl_align(array_type->std140_size(row_major), 16);
else else
@@ -4165,7 +4167,8 @@ get_array_stride(struct gl_uniform_storage *uni, const glsl_type *interface,
} }
static void static void
calculate_array_size_and_stride(struct gl_shader_program *shProg, calculate_array_size_and_stride(struct gl_context *ctx,
struct gl_shader_program *shProg,
struct gl_uniform_storage *uni) struct gl_uniform_storage *uni)
{ {
int block_index = uni->block_index; int block_index = uni->block_index;
@@ -4214,7 +4217,7 @@ calculate_array_size_and_stride(struct gl_shader_program *shProg,
if (strcmp(field->name, var_name) != 0) if (strcmp(field->name, var_name) != 0)
continue; continue;
array_stride = get_array_stride(uni, interface, field, array_stride = get_array_stride(ctx, uni, interface, field,
interface_name, var_name); interface_name, var_name);
array_size = get_array_size(uni, field, interface_name, var_name); array_size = get_array_size(uni, field, interface_name, var_name);
goto write_top_level_array_size_and_stride; goto write_top_level_array_size_and_stride;
@@ -4340,7 +4343,7 @@ build_program_resource_list(struct gl_context *ctx,
continue; continue;
if (is_shader_storage) { if (is_shader_storage) {
calculate_array_size_and_stride(shProg, calculate_array_size_and_stride(ctx, shProg,
&shProg->data->UniformStorage[i]); &shProg->data->UniformStorage[i]);
} }
@@ -4642,7 +4645,8 @@ link_varyings_and_uniforms(unsigned first, unsigned last,
if (options->LowerBufferInterfaceBlocks) if (options->LowerBufferInterfaceBlocks)
lower_ubo_reference(prog->_LinkedShaders[i], lower_ubo_reference(prog->_LinkedShaders[i],
options->ClampBlockIndicesToArrayBounds); options->ClampBlockIndicesToArrayBounds,
ctx->Const.UseSTD430AsDefaultPacking);
if (i == MESA_SHADER_COMPUTE) if (i == MESA_SHADER_COMPUTE)
lower_shared_reference(prog->_LinkedShaders[i], lower_shared_reference(prog->_LinkedShaders[i],

View File

@@ -122,7 +122,7 @@ public:
* matter. For example, enumerating the names of members of the block, but * matter. For example, enumerating the names of members of the block, but
* not for determining the offsets of members. * not for determining the offsets of members.
*/ */
void process(ir_variable *var); void process(ir_variable *var, bool use_std430_as_default);
/** /**
* Begin processing a variable of a structured type. * Begin processing a variable of a structured type.
@@ -139,7 +139,8 @@ public:
* \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
* there of. * there of.
*/ */
void process(const glsl_type *type, const char *name); void process(const glsl_type *type, const char *name,
bool use_std430_as_default);
protected: protected:
/** /**

View File

@@ -58,6 +58,9 @@ public:
bool *row_major, int *matrix_columns, bool *row_major, int *matrix_columns,
const glsl_struct_field **struct_field, const glsl_struct_field **struct_field,
enum glsl_interface_packing packing); enum glsl_interface_packing packing);
protected:
bool use_std430_as_default;
}; };
} /* namespace lower_buffer_access */ } /* namespace lower_buffer_access */

View File

@@ -45,10 +45,12 @@ class lower_ubo_reference_visitor :
public lower_buffer_access::lower_buffer_access { public lower_buffer_access::lower_buffer_access {
public: public:
lower_ubo_reference_visitor(struct gl_linked_shader *shader, lower_ubo_reference_visitor(struct gl_linked_shader *shader,
bool clamp_block_indices) bool clamp_block_indices,
bool use_std430_as_default)
: shader(shader), clamp_block_indices(clamp_block_indices), : shader(shader), clamp_block_indices(clamp_block_indices),
struct_field(NULL), variable(NULL) struct_field(NULL), variable(NULL)
{ {
this->use_std430_as_default = use_std430_as_default;
} }
void handle_rvalue(ir_rvalue **rvalue); void handle_rvalue(ir_rvalue **rvalue);
@@ -345,7 +347,10 @@ lower_ubo_reference_visitor::handle_rvalue(ir_rvalue **rvalue)
unsigned const_offset; unsigned const_offset;
bool row_major; bool row_major;
int matrix_columns; int matrix_columns;
enum glsl_interface_packing packing = var->get_interface_type_packing();
enum glsl_interface_packing packing =
var->get_interface_type()->
get_internal_ifc_packing(use_std430_as_default);
this->buffer_access_type = this->buffer_access_type =
var->is_in_shader_storage_block() ? var->is_in_shader_storage_block() ?
@@ -558,7 +563,10 @@ lower_ubo_reference_visitor::write_to_memory(void *mem_ctx,
unsigned const_offset; unsigned const_offset;
bool row_major; bool row_major;
int matrix_columns; int matrix_columns;
enum glsl_interface_packing packing = var->get_interface_type_packing();
enum glsl_interface_packing packing =
var->get_interface_type()->
get_internal_ifc_packing(use_std430_as_default);
this->buffer_access_type = ssbo_store_access; this->buffer_access_type = ssbo_store_access;
this->variable = var; this->variable = var;
@@ -737,8 +745,12 @@ lower_ubo_reference_visitor::process_ssbo_unsized_array_length(ir_rvalue **rvalu
unsigned const_offset; unsigned const_offset;
bool row_major; bool row_major;
int matrix_columns; int matrix_columns;
enum glsl_interface_packing packing = var->get_interface_type_packing();
int unsized_array_stride = calculate_unsized_array_stride(deref, packing); enum glsl_interface_packing packing =
var->get_interface_type()->
get_internal_ifc_packing(use_std430_as_default);
int unsized_array_stride =
calculate_unsized_array_stride(deref, packing);
this->buffer_access_type = ssbo_unsized_array_length_access; this->buffer_access_type = ssbo_unsized_array_length_access;
this->variable = var; this->variable = var;
@@ -971,7 +983,10 @@ lower_ubo_reference_visitor::lower_ssbo_atomic_intrinsic(ir_call *ir)
unsigned const_offset; unsigned const_offset;
bool row_major; bool row_major;
int matrix_columns; int matrix_columns;
enum glsl_interface_packing packing = var->get_interface_type_packing();
enum glsl_interface_packing packing =
var->get_interface_type()->
get_internal_ifc_packing(use_std430_as_default);
this->buffer_access_type = ssbo_atomic_access; this->buffer_access_type = ssbo_atomic_access;
this->variable = var; this->variable = var;
@@ -1108,9 +1123,11 @@ lower_ubo_reference_visitor::visit_enter(ir_texture *ir)
} /* unnamed namespace */ } /* unnamed namespace */
void void
lower_ubo_reference(struct gl_linked_shader *shader, bool clamp_block_indices) lower_ubo_reference(struct gl_linked_shader *shader,
bool clamp_block_indices, bool use_std430_as_default)
{ {
lower_ubo_reference_visitor v(shader, clamp_block_indices); lower_ubo_reference_visitor v(shader, clamp_block_indices,
use_std430_as_default);
/* Loop over the instructions lowering references, because we take /* Loop over the instructions lowering references, because we take
* a deref of a UBO array using a UBO dereference as the index will * a deref of a UBO array using a UBO dereference as the index will

View File

@@ -2418,7 +2418,7 @@ class add_uniform_to_shader : public program_resource_visitor {
public: public:
add_uniform_to_shader(struct gl_shader_program *shader_program, add_uniform_to_shader(struct gl_shader_program *shader_program,
struct gl_program_parameter_list *params) struct gl_program_parameter_list *params)
: params(params), idx(-1) : ctx(ctx), params(params), idx(-1)
{ {
/* empty */ /* empty */
} }
@@ -2427,7 +2427,8 @@ public:
{ {
this->idx = -1; this->idx = -1;
this->var = var; this->var = var;
this->program_resource_visitor::process(var); this->program_resource_visitor::process(var,
ctx->Const.UseSTD430AsDefaultPacking);
var->data.param_index = this->idx; var->data.param_index = this->idx;
} }
@@ -2437,6 +2438,7 @@ private:
const enum glsl_interface_packing packing, const enum glsl_interface_packing packing,
bool last_field); bool last_field);
struct gl_context *ctx;
struct gl_program_parameter_list *params; struct gl_program_parameter_list *params;
int idx; int idx;
ir_variable *var; ir_variable *var;