[Mesa-dev] [PATCH 2/2] glsl: add constant to decide whether to cache uniform storage
Timothy Arceri
tarceri at itsqueeze.com
Fri Mar 3 05:59:49 UTC 2017
We need to cache this for i965 but gallium drivers will have
already saved this as part of the parameter list.
This should help with cache compression times.
---
src/compiler/glsl/shader_cache.cpp | 58 +++++++++++++++++++++-----------------
src/mesa/main/mtypes.h | 7 +++++
2 files changed, 39 insertions(+), 26 deletions(-)
diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 6e56d86..4450657 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -549,21 +549,22 @@ read_xfb(struct blob_reader *metadata, struct gl_shader_program *shProg)
ltf->Varyings[i].Size = blob_read_uint32(metadata);
ltf->Varyings[i].Offset = blob_read_uint32(metadata);
}
blob_copy_bytes(metadata, (uint8_t *) ltf->Buffers,
sizeof(struct gl_transform_feedback_buffer) *
MAX_FEEDBACK_BUFFERS);
}
static void
-write_uniforms(struct blob *metadata, struct gl_shader_program *prog)
+write_uniforms(struct gl_context *ctx, struct blob *metadata,
+ struct gl_shader_program *prog)
{
blob_write_uint32(metadata, prog->SamplersValidated);
blob_write_uint32(metadata, prog->data->NumUniformStorage);
blob_write_uint32(metadata, prog->data->NumUniformDataSlots);
for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
encode_type_to_blob(metadata, prog->data->UniformStorage[i].type);
blob_write_uint32(metadata, prog->data->UniformStorage[i].array_elements);
blob_write_string(metadata, prog->data->UniformStorage[i].name);
blob_write_uint32(metadata, prog->data->UniformStorage[i].storage -
@@ -587,35 +588,38 @@ write_uniforms(struct blob *metadata, struct gl_shader_program *prog)
blob_write_bytes(metadata, prog->data->UniformStorage[i].opaque,
sizeof(prog->data->UniformStorage[i].opaque));
}
/* Here we cache all uniform values. We do this to retain values for
* uniforms with initialisers and also hidden uniforms that may be lowered
* constant arrays. We could possibly just store the values we need but for
* now we just store everything.
*/
blob_write_uint32(metadata, prog->data->NumHiddenUniforms);
- for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
- if (!prog->data->UniformStorage[i].builtin &&
- !prog->data->UniformStorage[i].is_shader_storage &&
- prog->data->UniformStorage[i].block_index == -1) {
- unsigned vec_size =
- values_for_type(prog->data->UniformStorage[i].type) *
- MAX2(prog->data->UniformStorage[i].array_elements, 1);
- blob_write_bytes(metadata, prog->data->UniformStorage[i].storage,
- sizeof(union gl_constant_value) * vec_size);
+ if (ctx->Const.CacheUniformStorage) {
+ for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
+ if (!prog->data->UniformStorage[i].builtin &&
+ !prog->data->UniformStorage[i].is_shader_storage &&
+ prog->data->UniformStorage[i].block_index == -1) {
+ unsigned vec_size =
+ values_for_type(prog->data->UniformStorage[i].type) *
+ MAX2(prog->data->UniformStorage[i].array_elements, 1);
+ blob_write_bytes(metadata, prog->data->UniformStorage[i].storage,
+ sizeof(union gl_constant_value) * vec_size);
+ }
}
}
}
static void
-read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
+read_uniforms(struct gl_context *ctx, struct blob_reader *metadata,
+ struct gl_shader_program *prog)
{
struct gl_uniform_storage *uniforms;
union gl_constant_value *data;
prog->SamplersValidated = blob_read_uint32(metadata);
prog->data->NumUniformStorage = blob_read_uint32(metadata);
prog->data->NumUniformDataSlots = blob_read_uint32(metadata);
uniforms = rzalloc_array(prog, struct gl_uniform_storage,
prog->data->NumUniformStorage);
@@ -647,33 +651,35 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
uniforms[i].top_level_array_stride = blob_read_uint32(metadata);
prog->UniformHash->put(i, uniforms[i].name);
memcpy(uniforms[i].opaque,
blob_read_bytes(metadata, sizeof(uniforms[i].opaque)),
sizeof(uniforms[i].opaque));
}
/* Restore uniform values. */
prog->data->NumHiddenUniforms = blob_read_uint32(metadata);
- for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
- if (!prog->data->UniformStorage[i].builtin &&
- !prog->data->UniformStorage[i].is_shader_storage &&
- prog->data->UniformStorage[i].block_index == -1) {
- unsigned vec_size =
- values_for_type(prog->data->UniformStorage[i].type) *
- MAX2(prog->data->UniformStorage[i].array_elements, 1);
- blob_copy_bytes(metadata,
- (uint8_t *) prog->data->UniformStorage[i].storage,
- sizeof(union gl_constant_value) * vec_size);
-
- assert(vec_size + prog->data->UniformStorage[i].storage <=
- data + prog->data->NumUniformDataSlots);
+ if (ctx->Const.CacheUniformStorage) {
+ for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
+ if (!prog->data->UniformStorage[i].builtin &&
+ !prog->data->UniformStorage[i].is_shader_storage &&
+ prog->data->UniformStorage[i].block_index == -1) {
+ unsigned vec_size =
+ values_for_type(prog->data->UniformStorage[i].type) *
+ MAX2(prog->data->UniformStorage[i].array_elements, 1);
+ blob_copy_bytes(metadata,
+ (uint8_t *) prog->data->UniformStorage[i].storage,
+ sizeof(union gl_constant_value) * vec_size);
+
+ assert(vec_size + prog->data->UniformStorage[i].storage <=
+ data + prog->data->NumUniformDataSlots);
+ }
}
}
}
enum uniform_remap_type
{
remap_type_inactive_explicit_location,
remap_type_null_ptr,
remap_type_uniform_offset
};
@@ -1219,21 +1225,21 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
* generate a source from.
*
* TODO: In future we should use another method to generate a key for ff
* programs.
*/
if (*prog->data->sha1 == 0)
return;
struct blob *metadata = blob_create(NULL);
- write_uniforms(metadata, prog);
+ write_uniforms(ctx, metadata, prog);
write_hash_tables(metadata, prog);
blob_write_uint32(metadata, prog->data->Version);
blob_write_uint32(metadata, prog->data->linked_stages);
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
struct gl_linked_shader *sh = prog->_LinkedShaders[i];
if (sh) {
write_shader_metadata(metadata, sh);
@@ -1355,21 +1361,21 @@ shader_cache_read_program_metadata(struct gl_context *ctx,
if (ctx->_Shader->Flags & GLSL_CACHE_INFO) {
fprintf(stderr, "loading shader program meta data from cache: %s\n",
_mesa_sha1_format(sha1buf, prog->data->sha1));
}
struct blob_reader metadata;
blob_reader_init(&metadata, buffer, size);
assert(prog->data->UniformStorage == NULL);
- read_uniforms(&metadata, prog);
+ read_uniforms(ctx, &metadata, prog);
read_hash_tables(&metadata, prog);
prog->data->Version = blob_read_uint32(&metadata);
prog->data->linked_stages = blob_read_uint32(&metadata);
unsigned mask = prog->data->linked_stages;
while (mask) {
const int j = u_bit_scan(&mask);
create_linked_shader_and_program(ctx, (gl_shader_stage) j, prog,
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index d07391d..28be54d 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3548,20 +3548,27 @@ struct gl_constants
*/
GLboolean GLSLZeroInit;
/**
* Does the driver support real 32-bit integers? (Otherwise, integers are
* simulated via floats.)
*/
GLboolean NativeIntegers;
/**
+ * Should the shader cache copy the uniform storage allocated at link time
+ * to the cache. This is useful as some drivers will already have cached
+ * uniforms in gl_program_parameter_list and don't need to do it again.
+ */
+ bool CacheUniformStorage;
+
+ /**
* Does VertexID count from zero or from base vertex?
*
* \note
* If desktop GLSL 1.30 or GLSL ES 3.00 are not supported, this field is
* ignored and need not be set.
*/
bool VertexID_is_zero_based;
/**
* If the driver supports real 32-bit integers, what integer value should be
--
2.9.3
More information about the mesa-dev
mailing list