summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorMatt Turner <[email protected]>2014-08-08 19:46:05 -0700
committerMatt Turner <[email protected]>2014-08-18 18:35:48 -0700
commit9e2e7c7dc0ff08a2066435dd519502340955bbd2 (patch)
tree11865fdb82419c8a2a23a47470766cac5d0f846d /src/glsl
parent6df0fd8fe9ccf5c927797897277343f068420a45 (diff)
glsl: Use UniformBooleanTrue value for uniform initializers.
Reviewed-by: Anuj Phogat <[email protected]>
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/link_uniform_initializers.cpp24
-rw-r--r--src/glsl/link_uniforms.cpp5
-rw-r--r--src/glsl/linker.cpp2
-rw-r--r--src/glsl/linker.h6
-rw-r--r--src/glsl/tests/copy_constant_to_storage_tests.cpp28
-rw-r--r--src/glsl/tests/set_uniform_initializer_tests.cpp11
-rw-r--r--src/glsl/tests/uniform_initializer_utils.cpp7
-rw-r--r--src/glsl/tests/uniform_initializer_utils.h3
8 files changed, 52 insertions, 34 deletions
diff --git a/src/glsl/link_uniform_initializers.cpp b/src/glsl/link_uniform_initializers.cpp
index c6fe6a9ad67..a745c7cace3 100644
--- a/src/glsl/link_uniform_initializers.cpp
+++ b/src/glsl/link_uniform_initializers.cpp
@@ -60,7 +60,8 @@ void
copy_constant_to_storage(union gl_constant_value *storage,
const ir_constant *val,
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++) {
switch (base_type) {
@@ -75,7 +76,7 @@ copy_constant_to_storage(union gl_constant_value *storage,
storage[i].f = val->value.f[i];
break;
case GLSL_TYPE_BOOL:
- storage[i].b = int(val->value.b[i]);
+ storage[i].b = val->value.b[i] ? boolean_true : 0;
break;
case GLSL_TYPE_ARRAY:
case GLSL_TYPE_STRUCT:
@@ -156,7 +157,7 @@ set_block_binding(gl_shader_program *prog, const char *block_name, int binding)
void
set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
const char *name, const glsl_type *type,
- ir_constant *val)
+ ir_constant *val, unsigned int boolean_true)
{
if (type->is_record()) {
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,
type->fields.structure[i].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;
}
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);
set_uniform_initializer(mem_ctx, prog, element_name,
- element_type, val->array_elements[i]);
+ element_type, val->array_elements[i],
+ boolean_true);
}
return;
}
@@ -204,7 +206,8 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
copy_constant_to_storage(& storage->storage[idx],
val->array_elements[i],
base_type,
- elements);
+ elements,
+ boolean_true);
idx += elements;
}
@@ -212,7 +215,8 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
copy_constant_to_storage(storage->storage,
val,
val->type->base_type,
- val->type->components());
+ val->type->components(),
+ boolean_true);
if (storage->type->is_sampler()) {
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
@@ -232,7 +236,8 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
}
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;
@@ -301,7 +306,8 @@ link_set_uniform_initializers(struct gl_shader_program *prog)
}
} else if (var->constant_value) {
linker::set_uniform_initializer(mem_ctx, prog, var->name,
- var->type, var->constant_value);
+ var->type, var->constant_value,
+ boolean_true);
}
}
}
diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index 3251097bc30..ddb20565866 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -841,7 +841,8 @@ link_set_image_access_qualifiers(struct gl_shader_program *prog)
}
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);
prog->UniformStorage = NULL;
@@ -1014,7 +1015,7 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
prog->UniformStorage = uniforms;
link_set_image_access_qualifiers(prog);
- link_set_uniform_initializers(prog);
+ link_set_uniform_initializers(prog, boolean_true);
return;
}
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 497a77aeab4..d5473adc36e 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -2821,7 +2821,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
goto done;
update_array_sizes(prog);
- link_assign_uniform_locations(prog);
+ link_assign_uniform_locations(prog, ctx->Const.UniformBooleanTrue);
link_assign_atomic_counter_resources(ctx, prog);
store_fragdepth_layout(prog);
diff --git a/src/glsl/linker.h b/src/glsl/linker.h
index 8851da6c8b4..beb9bb21695 100644
--- a/src/glsl/linker.h
+++ b/src/glsl/linker.h
@@ -34,10 +34,12 @@ extern void
link_invalidate_variable_locations(exec_list *ir);
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
-link_set_uniform_initializers(struct gl_shader_program *prog);
+link_set_uniform_initializers(struct gl_shader_program *prog,
+ unsigned int boolean_true);
extern int
link_cross_validate_uniform_block(void *mem_ctx,
diff --git a/src/glsl/tests/copy_constant_to_storage_tests.cpp b/src/glsl/tests/copy_constant_to_storage_tests.cpp
index 65a9d502d47..acf2789f2b5 100644
--- a/src/glsl/tests/copy_constant_to_storage_tests.cpp
+++ b/src/glsl/tests/copy_constant_to_storage_tests.cpp
@@ -32,7 +32,8 @@ extern void
copy_constant_to_storage(union gl_constant_value *storage,
const ir_constant *val,
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 {
@@ -77,9 +78,10 @@ copy_constant_to_storage::int_test(unsigned rows)
linker::copy_constant_to_storage(storage,
val,
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
@@ -96,9 +98,10 @@ copy_constant_to_storage::uint_test(unsigned rows)
linker::copy_constant_to_storage(storage,
val,
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
@@ -115,9 +118,10 @@ copy_constant_to_storage::float_test(unsigned columns, unsigned rows)
linker::copy_constant_to_storage(storage,
val,
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
@@ -134,9 +138,10 @@ copy_constant_to_storage::bool_test(unsigned rows)
linker::copy_constant_to_storage(storage,
val,
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,
val,
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)
diff --git a/src/glsl/tests/set_uniform_initializer_tests.cpp b/src/glsl/tests/set_uniform_initializer_tests.cpp
index 1d4169b037a..d3fdeb3a844 100644
--- a/src/glsl/tests/set_uniform_initializer_tests.cpp
+++ b/src/glsl/tests/set_uniform_initializer_tests.cpp
@@ -31,7 +31,7 @@ namespace linker {
extern void
set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
const char *name, const glsl_type *type,
- ir_constant *val);
+ ir_constant *val, unsigned int boolean_true);
}
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;
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_data(prog->UniformStorage[actual_index].storage, 0, val,
- red_zone_components);
+ red_zone_components, 0xF00F);
}
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,
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_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)
diff --git a/src/glsl/tests/uniform_initializer_utils.cpp b/src/glsl/tests/uniform_initializer_utils.cpp
index c61ef0d71cb..6f47acd4cad 100644
--- a/src/glsl/tests/uniform_initializer_utils.cpp
+++ b/src/glsl/tests/uniform_initializer_utils.cpp
@@ -187,14 +187,15 @@ generate_array_data(void *mem_ctx, enum glsl_base_type base_type,
*/
void
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) {
const glsl_type *const element_type = val->array_elements[0]->type;
for (unsigned i = 0; i < storage_array_size; i++) {
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();
@@ -217,7 +218,7 @@ verify_data(gl_constant_value *storage, unsigned storage_array_size,
EXPECT_EQ(val->value.f[i], storage[i].f);
break;
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;
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_STRUCT:
diff --git a/src/glsl/tests/uniform_initializer_utils.h b/src/glsl/tests/uniform_initializer_utils.h
index f8c06d29c55..b4d0c10220f 100644
--- a/src/glsl/tests/uniform_initializer_utils.h
+++ b/src/glsl/tests/uniform_initializer_utils.h
@@ -44,4 +44,5 @@ generate_array_data(void *mem_ctx, enum glsl_base_type base_type,
extern void
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);