main, glsl: Add UniformDataDefaults which stores uniform defaults
authorJordan Justen <jordan.l.justen@intel.com>
Mon, 30 Oct 2017 18:16:48 +0000 (11:16 -0700)
committerTimothy Arceri <tarceri@itsqueeze.com>
Fri, 8 Dec 2017 05:44:35 +0000 (16:44 +1100)
The ARB_get_program_binary extension requires that uniform values in a
program be restored to their initial value just after linking.

This patch saves off the initial values just after linking. When the
program is restored by glProgramBinary, we can use this to copy the
initial value of uniforms into UniformDataSlots.

V2 (Timothy Arceri):
 - Store UniformDataDefaults only when serializing GLSL as this
   is what we want for both disk cache and ARB_get_program_binary.
   This saves us having to come back later and reset the Uniforms
   on program binary restores.

Signed-off-by: Timothy Arceri <tarceri@itsqueeze.com>
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com> (v1)
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
src/compiler/glsl/link_uniform_initializers.cpp
src/compiler/glsl/link_uniforms.cpp
src/compiler/glsl/serialize.cpp
src/mesa/main/mtypes.h

index be3715cc1a3ba961d08d0c9fad9dec859d957422..97796e721bf8908d62ade0bc2150dcbd6459f709 100644 (file)
@@ -357,5 +357,7 @@ link_set_uniform_initializers(struct gl_shader_program *prog,
       }
    }
 
+   memcpy(prog->data->UniformDataDefaults, prog->data->UniformDataSlots,
+          sizeof(union gl_constant_value) * prog->data->NumUniformDataSlots);
    ralloc_free(mem_ctx);
 }
index 46c746bc701a13c019df8a2ed10c7ab005b37eb0..15813cb0aedd82297d612556e15747ba272a032f 100644 (file)
@@ -1365,6 +1365,9 @@ link_assign_uniform_storage(struct gl_context *ctx,
                                                  prog->data->NumUniformStorage);
       data = rzalloc_array(prog->data->UniformStorage,
                            union gl_constant_value, num_data_slots);
+      prog->data->UniformDataDefaults =
+         rzalloc_array(prog->data->UniformStorage,
+                       union gl_constant_value, num_data_slots);
    } else {
       data = prog->data->UniformDataSlots;
    }
index b5f68f907f584b13780388858e3ac22cbb25317c..57c91d90bb29540c1b851a5000e4085d1381de21 100644 (file)
@@ -449,7 +449,10 @@ write_uniforms(struct blob *metadata, struct gl_shader_program *prog)
          unsigned vec_size =
             prog->data->UniformStorage[i].type->component_slots() *
             MAX2(prog->data->UniformStorage[i].array_elements, 1);
-         blob_write_bytes(metadata, prog->data->UniformStorage[i].storage,
+         unsigned slot =
+            prog->data->UniformStorage[i].storage -
+            prog->data->UniformDataSlots;
+         blob_write_bytes(metadata, &prog->data->UniformDataDefaults[slot],
                           sizeof(union gl_constant_value) * vec_size);
       }
    }
@@ -472,6 +475,9 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
    data = rzalloc_array(uniforms, union gl_constant_value,
                         prog->data->NumUniformDataSlots);
    prog->data->UniformDataSlots = data;
+   prog->data->UniformDataDefaults =
+      rzalloc_array(uniforms, union gl_constant_value,
+                    prog->data->NumUniformDataSlots);
 
    prog->UniformHash = new string_to_uint_map;
 
@@ -512,14 +518,20 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
          unsigned vec_size =
             prog->data->UniformStorage[i].type->component_slots() *
             MAX2(prog->data->UniformStorage[i].array_elements, 1);
+         unsigned slot =
+            prog->data->UniformStorage[i].storage -
+            prog->data->UniformDataSlots;
          blob_copy_bytes(metadata,
-                         (uint8_t *) prog->data->UniformStorage[i].storage,
+                         (uint8_t *) &prog->data->UniformDataSlots[slot],
                          sizeof(union gl_constant_value) * vec_size);
 
         assert(vec_size + prog->data->UniformStorage[i].storage <=
                data +  prog->data->NumUniformDataSlots);
       }
    }
+
+   memcpy(prog->data->UniformDataDefaults, prog->data->UniformDataSlots,
+          sizeof(union gl_constant_value) * prog->data->NumUniformDataSlots);
 }
 
 enum uniform_remap_type
index 397b113dfbccce8d737011e612c2432869cd07b4..40f70b067e8fdd0d85cef252154f648d3e806d97 100644 (file)
@@ -2886,6 +2886,17 @@ struct gl_shader_program_data
    unsigned NumUniformDataSlots;
    union gl_constant_value *UniformDataSlots;
 
+   /* Used to hold initial uniform values for program binary restores.
+    *
+    * From the ARB_get_program_binary spec:
+    *
+    *    "A successful call to ProgramBinary will reset all uniform
+    *    variables to their initial values. The initial value is either
+    *    the value of the variable's initializer as specified in the
+    *    original shader source, or 0 if no initializer was present.
+    */
+   union gl_constant_value *UniformDataDefaults;
+
    GLboolean Validated;
 
    /** List of all active resources after linking. */