glsl: Use UniformBooleanTrue value for uniform initializers.
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
This commit is contained in:
@@ -60,7 +60,8 @@ void
|
|||||||
copy_constant_to_storage(union gl_constant_value *storage,
|
copy_constant_to_storage(union gl_constant_value *storage,
|
||||||
const ir_constant *val,
|
const ir_constant *val,
|
||||||
const enum glsl_base_type base_type,
|
const enum glsl_base_type base_type,
|
||||||
const unsigned int elements)
|
const unsigned int elements,
|
||||||
|
unsigned int boolean_true)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < elements; i++) {
|
for (unsigned int i = 0; i < elements; i++) {
|
||||||
switch (base_type) {
|
switch (base_type) {
|
||||||
@@ -75,7 +76,7 @@ copy_constant_to_storage(union gl_constant_value *storage,
|
|||||||
storage[i].f = val->value.f[i];
|
storage[i].f = val->value.f[i];
|
||||||
break;
|
break;
|
||||||
case GLSL_TYPE_BOOL:
|
case GLSL_TYPE_BOOL:
|
||||||
storage[i].b = int(val->value.b[i]);
|
storage[i].b = val->value.b[i] ? boolean_true : 0;
|
||||||
break;
|
break;
|
||||||
case GLSL_TYPE_ARRAY:
|
case GLSL_TYPE_ARRAY:
|
||||||
case GLSL_TYPE_STRUCT:
|
case GLSL_TYPE_STRUCT:
|
||||||
@@ -156,7 +157,7 @@ set_block_binding(gl_shader_program *prog, const char *block_name, int binding)
|
|||||||
void
|
void
|
||||||
set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
|
set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
|
||||||
const char *name, const glsl_type *type,
|
const char *name, const glsl_type *type,
|
||||||
ir_constant *val)
|
ir_constant *val, unsigned int boolean_true)
|
||||||
{
|
{
|
||||||
if (type->is_record()) {
|
if (type->is_record()) {
|
||||||
ir_constant *field_constant;
|
ir_constant *field_constant;
|
||||||
@@ -168,7 +169,7 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
|
|||||||
const char *field_name = ralloc_asprintf(mem_ctx, "%s.%s", name,
|
const char *field_name = ralloc_asprintf(mem_ctx, "%s.%s", name,
|
||||||
type->fields.structure[i].name);
|
type->fields.structure[i].name);
|
||||||
set_uniform_initializer(mem_ctx, prog, field_name,
|
set_uniform_initializer(mem_ctx, prog, field_name,
|
||||||
field_type, field_constant);
|
field_type, field_constant, boolean_true);
|
||||||
field_constant = (ir_constant *)field_constant->next;
|
field_constant = (ir_constant *)field_constant->next;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -179,7 +180,8 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
|
|||||||
const char *element_name = ralloc_asprintf(mem_ctx, "%s[%d]", name, i);
|
const char *element_name = ralloc_asprintf(mem_ctx, "%s[%d]", name, i);
|
||||||
|
|
||||||
set_uniform_initializer(mem_ctx, prog, element_name,
|
set_uniform_initializer(mem_ctx, prog, element_name,
|
||||||
element_type, val->array_elements[i]);
|
element_type, val->array_elements[i],
|
||||||
|
boolean_true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -204,7 +206,8 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
|
|||||||
copy_constant_to_storage(& storage->storage[idx],
|
copy_constant_to_storage(& storage->storage[idx],
|
||||||
val->array_elements[i],
|
val->array_elements[i],
|
||||||
base_type,
|
base_type,
|
||||||
elements);
|
elements,
|
||||||
|
boolean_true);
|
||||||
|
|
||||||
idx += elements;
|
idx += elements;
|
||||||
}
|
}
|
||||||
@@ -212,7 +215,8 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
|
|||||||
copy_constant_to_storage(storage->storage,
|
copy_constant_to_storage(storage->storage,
|
||||||
val,
|
val,
|
||||||
val->type->base_type,
|
val->type->base_type,
|
||||||
val->type->components());
|
val->type->components(),
|
||||||
|
boolean_true);
|
||||||
|
|
||||||
if (storage->type->is_sampler()) {
|
if (storage->type->is_sampler()) {
|
||||||
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
|
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
|
||||||
@@ -232,7 +236,8 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
link_set_uniform_initializers(struct gl_shader_program *prog)
|
link_set_uniform_initializers(struct gl_shader_program *prog,
|
||||||
|
unsigned int boolean_true)
|
||||||
{
|
{
|
||||||
void *mem_ctx = NULL;
|
void *mem_ctx = NULL;
|
||||||
|
|
||||||
@@ -301,7 +306,8 @@ link_set_uniform_initializers(struct gl_shader_program *prog)
|
|||||||
}
|
}
|
||||||
} else if (var->constant_value) {
|
} else if (var->constant_value) {
|
||||||
linker::set_uniform_initializer(mem_ctx, prog, var->name,
|
linker::set_uniform_initializer(mem_ctx, prog, var->name,
|
||||||
var->type, var->constant_value);
|
var->type, var->constant_value,
|
||||||
|
boolean_true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -841,7 +841,8 @@ link_set_image_access_qualifiers(struct gl_shader_program *prog)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
link_assign_uniform_locations(struct gl_shader_program *prog)
|
link_assign_uniform_locations(struct gl_shader_program *prog,
|
||||||
|
unsigned int boolean_true)
|
||||||
{
|
{
|
||||||
ralloc_free(prog->UniformStorage);
|
ralloc_free(prog->UniformStorage);
|
||||||
prog->UniformStorage = NULL;
|
prog->UniformStorage = NULL;
|
||||||
@@ -1014,7 +1015,7 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
|
|||||||
prog->UniformStorage = uniforms;
|
prog->UniformStorage = uniforms;
|
||||||
|
|
||||||
link_set_image_access_qualifiers(prog);
|
link_set_image_access_qualifiers(prog);
|
||||||
link_set_uniform_initializers(prog);
|
link_set_uniform_initializers(prog, boolean_true);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -2821,7 +2821,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
|
|||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
update_array_sizes(prog);
|
update_array_sizes(prog);
|
||||||
link_assign_uniform_locations(prog);
|
link_assign_uniform_locations(prog, ctx->Const.UniformBooleanTrue);
|
||||||
link_assign_atomic_counter_resources(ctx, prog);
|
link_assign_atomic_counter_resources(ctx, prog);
|
||||||
store_fragdepth_layout(prog);
|
store_fragdepth_layout(prog);
|
||||||
|
|
||||||
|
@@ -34,10 +34,12 @@ extern void
|
|||||||
link_invalidate_variable_locations(exec_list *ir);
|
link_invalidate_variable_locations(exec_list *ir);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
link_assign_uniform_locations(struct gl_shader_program *prog);
|
link_assign_uniform_locations(struct gl_shader_program *prog,
|
||||||
|
unsigned int boolean_true);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
link_set_uniform_initializers(struct gl_shader_program *prog);
|
link_set_uniform_initializers(struct gl_shader_program *prog,
|
||||||
|
unsigned int boolean_true);
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
link_cross_validate_uniform_block(void *mem_ctx,
|
link_cross_validate_uniform_block(void *mem_ctx,
|
||||||
|
@@ -32,7 +32,8 @@ extern void
|
|||||||
copy_constant_to_storage(union gl_constant_value *storage,
|
copy_constant_to_storage(union gl_constant_value *storage,
|
||||||
const ir_constant *val,
|
const ir_constant *val,
|
||||||
const enum glsl_base_type base_type,
|
const enum glsl_base_type base_type,
|
||||||
const unsigned int elements);
|
const unsigned int elements,
|
||||||
|
unsigned int boolean_true);
|
||||||
}
|
}
|
||||||
|
|
||||||
class copy_constant_to_storage : public ::testing::Test {
|
class copy_constant_to_storage : public ::testing::Test {
|
||||||
@@ -77,9 +78,10 @@ copy_constant_to_storage::int_test(unsigned rows)
|
|||||||
linker::copy_constant_to_storage(storage,
|
linker::copy_constant_to_storage(storage,
|
||||||
val,
|
val,
|
||||||
val->type->base_type,
|
val->type->base_type,
|
||||||
val->type->components());
|
val->type->components(),
|
||||||
|
0xF00F);
|
||||||
|
|
||||||
verify_data(storage, 0, val, red_zone_size);
|
verify_data(storage, 0, val, red_zone_size, 0xF00F);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -96,9 +98,10 @@ copy_constant_to_storage::uint_test(unsigned rows)
|
|||||||
linker::copy_constant_to_storage(storage,
|
linker::copy_constant_to_storage(storage,
|
||||||
val,
|
val,
|
||||||
val->type->base_type,
|
val->type->base_type,
|
||||||
val->type->components());
|
val->type->components(),
|
||||||
|
0xF00F);
|
||||||
|
|
||||||
verify_data(storage, 0, val, red_zone_size);
|
verify_data(storage, 0, val, red_zone_size, 0xF00F);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -115,9 +118,10 @@ copy_constant_to_storage::float_test(unsigned columns, unsigned rows)
|
|||||||
linker::copy_constant_to_storage(storage,
|
linker::copy_constant_to_storage(storage,
|
||||||
val,
|
val,
|
||||||
val->type->base_type,
|
val->type->base_type,
|
||||||
val->type->components());
|
val->type->components(),
|
||||||
|
0xF00F);
|
||||||
|
|
||||||
verify_data(storage, 0, val, red_zone_size);
|
verify_data(storage, 0, val, red_zone_size, 0xF00F);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -134,9 +138,10 @@ copy_constant_to_storage::bool_test(unsigned rows)
|
|||||||
linker::copy_constant_to_storage(storage,
|
linker::copy_constant_to_storage(storage,
|
||||||
val,
|
val,
|
||||||
val->type->base_type,
|
val->type->base_type,
|
||||||
val->type->components());
|
val->type->components(),
|
||||||
|
0xF00F);
|
||||||
|
|
||||||
verify_data(storage, 0, val, red_zone_size);
|
verify_data(storage, 0, val, red_zone_size, 0xF00F);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,9 +163,10 @@ copy_constant_to_storage::sampler_test(void)
|
|||||||
linker::copy_constant_to_storage(storage,
|
linker::copy_constant_to_storage(storage,
|
||||||
val,
|
val,
|
||||||
GLSL_TYPE_SAMPLER,
|
GLSL_TYPE_SAMPLER,
|
||||||
val->type->components());
|
val->type->components(),
|
||||||
|
0xF00F);
|
||||||
|
|
||||||
verify_data(storage, 0, val, red_zone_size);
|
verify_data(storage, 0, val, red_zone_size, 0xF00F);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, bool_uniform)
|
TEST_F(copy_constant_to_storage, bool_uniform)
|
||||||
|
@@ -31,7 +31,7 @@ namespace linker {
|
|||||||
extern void
|
extern void
|
||||||
set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
|
set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
|
||||||
const char *name, const glsl_type *type,
|
const char *name, const glsl_type *type,
|
||||||
ir_constant *val);
|
ir_constant *val, unsigned int boolean_true);
|
||||||
}
|
}
|
||||||
|
|
||||||
class set_uniform_initializer : public ::testing::Test {
|
class set_uniform_initializer : public ::testing::Test {
|
||||||
@@ -179,11 +179,11 @@ non_array_test(void *mem_ctx, struct gl_shader_program *prog,
|
|||||||
ir_constant *val;
|
ir_constant *val;
|
||||||
generate_data(mem_ctx, base_type, columns, rows, val);
|
generate_data(mem_ctx, base_type, columns, rows, val);
|
||||||
|
|
||||||
linker::set_uniform_initializer(mem_ctx, prog, name, type, val);
|
linker::set_uniform_initializer(mem_ctx, prog, name, type, val, 0xF00F);
|
||||||
|
|
||||||
verify_initialization(prog, actual_index);
|
verify_initialization(prog, actual_index);
|
||||||
verify_data(prog->UniformStorage[actual_index].storage, 0, val,
|
verify_data(prog->UniformStorage[actual_index].storage, 0, val,
|
||||||
red_zone_components);
|
red_zone_components, 0xF00F);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, int_uniform)
|
TEST_F(set_uniform_initializer, int_uniform)
|
||||||
@@ -335,11 +335,12 @@ array_test(void *mem_ctx, struct gl_shader_program *prog,
|
|||||||
generate_array_data(mem_ctx, base_type, columns, rows,
|
generate_array_data(mem_ctx, base_type, columns, rows,
|
||||||
array_size + excess_data_size, val);
|
array_size + excess_data_size, val);
|
||||||
|
|
||||||
linker::set_uniform_initializer(mem_ctx, prog, name, element_type, val);
|
linker::set_uniform_initializer(mem_ctx, prog, name, element_type, val,
|
||||||
|
0xF00F);
|
||||||
|
|
||||||
verify_initialization(prog, actual_index);
|
verify_initialization(prog, actual_index);
|
||||||
verify_data(prog->UniformStorage[actual_index].storage, array_size,
|
verify_data(prog->UniformStorage[actual_index].storage, array_size,
|
||||||
val, red_zone_components);
|
val, red_zone_components, 0xF00F);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, int_array_uniform)
|
TEST_F(set_uniform_initializer, int_array_uniform)
|
||||||
|
@@ -187,14 +187,15 @@ generate_array_data(void *mem_ctx, enum glsl_base_type base_type,
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
verify_data(gl_constant_value *storage, unsigned storage_array_size,
|
verify_data(gl_constant_value *storage, unsigned storage_array_size,
|
||||||
ir_constant *val, unsigned red_zone_size)
|
ir_constant *val, unsigned red_zone_size,
|
||||||
|
unsigned int boolean_true)
|
||||||
{
|
{
|
||||||
if (val->type->base_type == GLSL_TYPE_ARRAY) {
|
if (val->type->base_type == GLSL_TYPE_ARRAY) {
|
||||||
const glsl_type *const element_type = val->array_elements[0]->type;
|
const glsl_type *const element_type = val->array_elements[0]->type;
|
||||||
|
|
||||||
for (unsigned i = 0; i < storage_array_size; i++) {
|
for (unsigned i = 0; i < storage_array_size; i++) {
|
||||||
verify_data(storage + (i * element_type->components()), 0,
|
verify_data(storage + (i * element_type->components()), 0,
|
||||||
val->array_elements[i], 0);
|
val->array_elements[i], 0, boolean_true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned components = element_type->components();
|
const unsigned components = element_type->components();
|
||||||
@@ -217,7 +218,7 @@ verify_data(gl_constant_value *storage, unsigned storage_array_size,
|
|||||||
EXPECT_EQ(val->value.f[i], storage[i].f);
|
EXPECT_EQ(val->value.f[i], storage[i].f);
|
||||||
break;
|
break;
|
||||||
case GLSL_TYPE_BOOL:
|
case GLSL_TYPE_BOOL:
|
||||||
EXPECT_EQ(int(val->value.b[i]), storage[i].i);
|
EXPECT_EQ(val->value.b[i] ? boolean_true : 0, storage[i].i);
|
||||||
break;
|
break;
|
||||||
case GLSL_TYPE_ATOMIC_UINT:
|
case GLSL_TYPE_ATOMIC_UINT:
|
||||||
case GLSL_TYPE_STRUCT:
|
case GLSL_TYPE_STRUCT:
|
||||||
|
@@ -44,4 +44,5 @@ generate_array_data(void *mem_ctx, enum glsl_base_type base_type,
|
|||||||
|
|
||||||
extern void
|
extern void
|
||||||
verify_data(gl_constant_value *storage, unsigned storage_array_size,
|
verify_data(gl_constant_value *storage, unsigned storage_array_size,
|
||||||
ir_constant *val, unsigned red_zone_size);
|
ir_constant *val, unsigned red_zone_size,
|
||||||
|
unsigned int boolean_true);
|
||||||
|
Reference in New Issue
Block a user