[Mesa-dev] [PATCH 4/8] glsl: add has_uniform_storage() helper to shader cache
Timothy Arceri
tarceri at itsqueeze.com
Sun Aug 13 23:49:03 UTC 2017
---
src/compiler/glsl/shader_cache.cpp | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 6c878dae37..2fbab86d30 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -589,20 +589,31 @@ read_xfb(struct blob_reader *metadata, struct gl_shader_program *shProg)
ltf->Varyings[i].BufferIndex = blob_read_uint32(metadata);
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 bool
+has_uniform_storage(struct gl_shader_program *prog, unsigned idx)
+{
+ if (!prog->data->UniformStorage[idx].builtin &&
+ !prog->data->UniformStorage[idx].is_shader_storage &&
+ prog->data->UniformStorage[idx].block_index == -1)
+ return true;
+
+ return false;
+}
+
static void
write_uniforms(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);
@@ -631,23 +642,21 @@ write_uniforms(struct blob *metadata, struct gl_shader_program *prog)
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) {
+ if (has_uniform_storage(prog, i)) {
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,
sizeof(union gl_constant_value) * vec_size);
}
}
}
static void
@@ -693,23 +702,21 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
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) {
+ if (has_uniform_storage(prog, i)) {
unsigned vec_size =
prog->data->UniformStorage[i].type->component_slots() *
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);
}
--
2.13.4
More information about the mesa-dev
mailing list