[Mesa-dev] [PATCH 08/40] glsl: Serialize three additional hash tables with program metadata
Anuj Phogat
anuj.phogat at gmail.com
Wed Feb 8 19:14:51 UTC 2017
On Mon, Feb 6, 2017 at 7:42 PM, Timothy Arceri <tarceri at itsqueeze.com> wrote:
> From: Carl Worth <cworth at cworth.org>
>
> The three additional tables are AttributeBindings, FragDataBindings,
> and FragDataIndexBindings.
>
> The first table (AttributeBindings) was identified as missing by
> trying to test the shader cache with a program that called
> glGetAttribLocation.
>
> Many thanks to Tapani Pälli <tapani.palli at intel.com>, as it was review
> of related work that he had done previously that pointed me to the
> necessity to also save and restore FragDataBindings and
> FragDataIndexBindings.
> ---
> src/compiler/glsl/shader_cache.cpp | 74 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 74 insertions(+)
>
> diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
> index 91f8d99..ba05655 100644
> --- a/src/compiler/glsl/shader_cache.cpp
> +++ b/src/compiler/glsl/shader_cache.cpp
> @@ -303,6 +303,76 @@ read_uniform_remap_table(struct blob_reader *metadata,
> }
> }
>
> +struct whte_closure
> +{
> + struct blob *blob;
> + size_t num_entries;
> +};
> +
> +static void
> +write_hash_table_entry(const char *key, unsigned value, void *closure)
> +{
> + struct whte_closure *whte = (struct whte_closure *) closure;
> +
> + blob_write_string(whte->blob, key);
> + blob_write_uint32(whte->blob, value);
> +
> + whte->num_entries++;
> +}
> +
> +static void
> +write_hash_table(struct blob *metadata, struct string_to_uint_map *hash)
> +{
> + size_t offset;
> + struct whte_closure whte;
> +
> + whte.blob = metadata;
> + whte.num_entries = 0;
> +
> + offset = metadata->size;
> +
> + /* Write a placeholder for the hashtable size. */
> + blob_write_uint32 (metadata, 0);
> +
> + hash->iterate(write_hash_table_entry, &whte);
> +
> + /* Overwrite with the computed number of entires written. */
s/entires/entries
> + blob_overwrite_uint32 (metadata, offset, whte.num_entries);
> +}
> +
> +static void
> +read_hash_table(struct blob_reader *metadata, struct string_to_uint_map *hash)
> +{
> + size_t i, num_entries;
> + const char *key;
> + uint32_t value;
> +
> + num_entries = blob_read_uint32 (metadata);
> +
> + for (i = 0; i < num_entries; i++) {
> + key = blob_read_string(metadata);
> + value = blob_read_uint32(metadata);
> +
> + hash->put(value, key);
> + }
> +}
> +
> +static void
> +write_hash_tables(struct blob *metadata, struct gl_shader_program *prog)
> +{
> + write_hash_table(metadata, prog->AttributeBindings);
> + write_hash_table(metadata, prog->FragDataBindings);
> + write_hash_table(metadata, prog->FragDataIndexBindings);
> +}
> +
> +static void
> +read_hash_tables(struct blob_reader *metadata, struct gl_shader_program *prog)
> +{
> + read_hash_table(metadata, prog->AttributeBindings);
> + read_hash_table(metadata, prog->FragDataBindings);
> + read_hash_table(metadata, prog->FragDataIndexBindings);
> +}
> +
> static void
> write_shader_parameters(struct blob *metadata,
> struct gl_program_parameter_list *params)
> @@ -445,6 +515,8 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
>
> write_uniforms(metadata, prog);
>
> + write_hash_tables(metadata, prog);
> +
> blob_write_uint32(metadata, prog->data->Version);
> blob_write_uint32(metadata, prog->data->linked_stages);
>
> @@ -563,6 +635,8 @@ shader_cache_read_program_metadata(struct gl_context *ctx,
>
> read_uniforms(&metadata, prog);
>
> + read_hash_tables(&metadata, prog);
> +
> prog->data->Version = blob_read_uint32(&metadata);
> prog->data->linked_stages = blob_read_uint32(&metadata);
>
> --
> 2.9.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list