glsl: Use UniformBooleanTrue value for uniform initializers.
authorMatt Turner <mattst88@gmail.com>
Sat, 9 Aug 2014 02:46:05 +0000 (19:46 -0700)
committerMatt Turner <mattst88@gmail.com>
Tue, 19 Aug 2014 01:35:48 +0000 (18:35 -0700)
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
src/glsl/link_uniform_initializers.cpp
src/glsl/link_uniforms.cpp
src/glsl/linker.cpp
src/glsl/linker.h
src/glsl/tests/copy_constant_to_storage_tests.cpp
src/glsl/tests/set_uniform_initializer_tests.cpp
src/glsl/tests/uniform_initializer_utils.cpp
src/glsl/tests/uniform_initializer_utils.h

index c6fe6a9ad679535106dd9466d98499ff85a1617f..a745c7cace3d8515de59bf21aa3c75a348785de3 100644 (file)
@@ -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);
          }
       }
    }
index 3251097bc304c9a3bf962b06db01bffac0a0543c..ddb2056586647507f707ae384fd521d8a7f1919d 100644 (file)
@@ -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;
 }
index 497a77aeab4a4eef05bba3e665200309821e6b6b..d5473adc36ee70f3b8f73437e4655a6cf2d26308 100644 (file)
@@ -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);
 
index 8851da6c8b4a40ca66c66eee881874157412fb61..beb9bb216957a914e489ad86a46227dddd5849c8 100644 (file)
@@ -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,
index 65a9d502d47338bac7c3072017443c81a35019a8..acf2789f2b51ffc378de733c05487847c766f369 100644 (file)
@@ -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)
index 1d4169b037a9da2333213b1d1214fd5e743ce1d2..d3fdeb3a844e2386fe36b12f11d8534e4a32fd70 100644 (file)
@@ -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)
index c61ef0d71cbd0479a44f367615a6190fc6d05b36..6f47acd4cad857061458a9af737b7f8e23eb942f 100644 (file)
@@ -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:
index f8c06d29c5596de78ae0062ab2fe067d19d461e2..b4d0c10220fe64c4a0fa289e254452be4e1e6f8d 100644 (file)
@@ -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);