void lower_shared_reference(struct gl_linked_shader *shader,
unsigned *shared_size);
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,
unsigned locations_used,
const uint8_t *components,
class ubo_visitor : public program_resource_visitor {
public:
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),
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 */
}
this->offset = 0;
this->buffer_size = 0;
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;
*/
this->buffer_size = glsl_align(this->offset, 16);
}
+
+ bool use_std430_as_default;
};
class count_block_size : public program_resource_visitor {
/* Add each variable from each uniform block to the API tracking
* structures.
*/
- ubo_visitor parcel(blocks, variables, num_variables, prog);
+ ubo_visitor parcel(blocks, variables, num_variables, prog,
+ ctx->Const.UseSTD430AsDefaultPacking);
unsigned i = 0;
struct hash_entry *entry;
}
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) {
unsigned aoa_size = b->type->arrays_of_arrays_size();
#define UNMAPPED_UNIFORM_LOC ~0u
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()
|| type->without_array()->is_interface());
unsigned record_array_count = 1;
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,
record_array_count, NULL);
}
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;
const bool row_major =
var->data.matrix_layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR;
- const enum glsl_interface_packing packing = var->get_interface_type() ?
- var->get_interface_type_packing() :
- var->type->get_interface_packing();
+ enum glsl_interface_packing packing = var->get_interface_type() ?
+ var->get_interface_type()->
+ get_internal_ifc_packing(use_std430_as_default) :
+ var->type->get_internal_ifc_packing(use_std430_as_default);
const glsl_type *t =
var->data.from_named_ifc_block ? var->get_interface_type() : var->type;
class count_uniform_size : public program_resource_visitor {
public:
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_shader_samplers(0), num_shader_images(0),
num_shader_uniform_components(0), num_shader_subroutines(0),
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 */
}
this->is_shader_storage = var->is_in_shader_storage_block();
if (var->is_interface_instance())
program_resource_visitor::process(var->get_interface_type(),
- var->get_interface_type()->name);
+ var->get_interface_type()->name,
+ use_std430_as_default);
else
- program_resource_visitor::process(var);
+ program_resource_visitor::process(var, use_std430_as_default);
}
/**
* Current variable being processed.
*/
ir_variable *current_var;
+
+ bool use_std430_as_default;
};
} /* anonymous namespace */
parcel_out_uniform_storage(struct gl_shader_program *prog,
struct string_to_uint_map *map,
struct gl_uniform_storage *uniforms,
- union gl_constant_value *values)
- : prog(prog), map(map), uniforms(uniforms), values(values),
+ union gl_constant_value *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)
{
}
if (var->is_interface_instance()) {
ubo_byte_offset = 0;
process(var->get_interface_type(),
- var->get_interface_type()->name);
+ var->get_interface_type()->name,
+ use_std430_as_default);
} else {
const struct gl_uniform_block *const block =
&blks[buffer_block_index];
&block->Uniforms[var->data.location];
ubo_byte_offset = ubo_var->Offset;
- process(var);
+ process(var, use_std430_as_default);
}
} else {
/* Store any explicit location and reset data location so we can
this->explicit_location = current_var->data.location;
current_var->data.location = -1;
- process(var);
+ process(var, use_std430_as_default);
}
delete this->record_next_sampler;
delete this->record_next_bindless_sampler;
unsigned next_bindless_image;
unsigned next_subroutine;
+ bool use_std430_as_default;
+
/**
* Field counter is used to take care that uniform structures
* with explicit locations get sequential locations.
#endif
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++) {
struct gl_linked_shader *shader = prog->_LinkedShaders[i];
* glGetUniformLocation.
*/
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++) {
struct gl_linked_shader *sh = prog->_LinkedShaders[i];
this->toplevel_var = var;
this->varying_floats = 0;
- program_resource_visitor::process(var);
+ program_resource_visitor::process(var, false);
}
private:
}
static int
-get_array_stride(struct gl_uniform_storage *uni, const glsl_type *interface,
- const glsl_struct_field *field, char *interface_name,
- char *var_name)
+get_array_stride(struct gl_context *ctx, struct gl_uniform_storage *uni,
+ const glsl_type *interface, const glsl_struct_field *field,
+ char *interface_name, char *var_name)
{
/* The ARB_program_interface_query spec says:
*
var_name))
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())
return glsl_align(array_type->std140_size(row_major), 16);
else
}
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)
{
int block_index = uni->block_index;
if (strcmp(field->name, var_name) != 0)
continue;
- array_stride = get_array_stride(uni, interface, field,
+ array_stride = get_array_stride(ctx, uni, interface, field,
interface_name, var_name);
array_size = get_array_size(uni, field, interface_name, var_name);
goto write_top_level_array_size_and_stride;
continue;
if (is_shader_storage) {
- calculate_array_size_and_stride(shProg,
+ calculate_array_size_and_stride(ctx, shProg,
&shProg->data->UniformStorage[i]);
}
if (options->LowerBufferInterfaceBlocks)
lower_ubo_reference(prog->_LinkedShaders[i],
- options->ClampBlockIndicesToArrayBounds);
+ options->ClampBlockIndicesToArrayBounds,
+ ctx->Const.UseSTD430AsDefaultPacking);
if (i == MESA_SHADER_COMPUTE)
lower_shared_reference(prog->_LinkedShaders[i],
* matter. For example, enumerating the names of members of the block, but
* 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.
* \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
* 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:
/**
bool *row_major, int *matrix_columns,
const glsl_struct_field **struct_field,
enum glsl_interface_packing packing);
+
+protected:
+ bool use_std430_as_default;
};
} /* namespace lower_buffer_access */
public lower_buffer_access::lower_buffer_access {
public:
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),
struct_field(NULL), variable(NULL)
{
+ this->use_std430_as_default = use_std430_as_default;
}
void handle_rvalue(ir_rvalue **rvalue);
unsigned const_offset;
bool row_major;
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 =
var->is_in_shader_storage_block() ?
unsigned const_offset;
bool row_major;
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->variable = var;
unsigned const_offset;
bool row_major;
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->variable = var;
unsigned const_offset;
bool row_major;
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->variable = var;
} /* unnamed namespace */
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
* a deref of a UBO array using a UBO dereference as the index will
public:
add_uniform_to_shader(struct gl_shader_program *shader_program,
struct gl_program_parameter_list *params)
- : params(params), idx(-1)
+ : ctx(ctx), params(params), idx(-1)
{
/* empty */
}
{
this->idx = -1;
this->var = var;
- this->program_resource_visitor::process(var);
+ this->program_resource_visitor::process(var,
+ ctx->Const.UseSTD430AsDefaultPacking);
var->data.param_index = this->idx;
}
const enum glsl_interface_packing packing,
bool last_field);
+ struct gl_context *ctx;
struct gl_program_parameter_list *params;
int idx;
ir_variable *var;