Mesa (master): glsl/serialize: optimize for equal offsets in uniform remap tables

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 25 21:02:47 UTC 2019


Module: Mesa
Branch: master
Commit: 88e9042b6c0529baa3d4906800891c54226c1ead
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=88e9042b6c0529baa3d4906800891c54226c1ead

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Thu Oct 24 23:26:57 2019 -0400

glsl/serialize: optimize for equal offsets in uniform remap tables

Closes: https://gitlab.freedesktop.org/mesa/mesa/issues/1416

This decreases the shader cache size in the ticket from 1.6 MB to 40 KB.

Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>

---

 src/compiler/glsl/serialize.cpp | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/compiler/glsl/serialize.cpp b/src/compiler/glsl/serialize.cpp
index 4feea7c98a5..23a13ea38bc 100644
--- a/src/compiler/glsl/serialize.cpp
+++ b/src/compiler/glsl/serialize.cpp
@@ -568,7 +568,8 @@ enum uniform_remap_type
 {
    remap_type_inactive_explicit_location,
    remap_type_null_ptr,
-   remap_type_uniform_offset
+   remap_type_uniform_offset,
+   remap_type_uniform_offsets_equal,
 };
 
 static void
@@ -581,15 +582,32 @@ write_uniform_remap_table(struct blob *metadata,
 
    for (unsigned i = 0; i < num_entries; i++) {
       gl_uniform_storage *entry = remap_table[i];
+      uint32_t offset = entry - uniform_storage;
 
       if (entry == INACTIVE_UNIFORM_EXPLICIT_LOCATION) {
          blob_write_uint32(metadata, remap_type_inactive_explicit_location);
       } else if (entry == NULL) {
          blob_write_uint32(metadata, remap_type_null_ptr);
+      } else if (i+1 < num_entries && entry == remap_table[i+1]) {
+         blob_write_uint32(metadata, remap_type_uniform_offsets_equal);
+
+         /* If many offsets are equal, write only one offset and the number
+          * of consecutive entries being equal.
+          */
+         unsigned count = 1;
+         for (unsigned j = i + 1; j < num_entries; j++) {
+            if (entry != remap_table[j])
+               break;
+
+            count++;
+         }
+
+         blob_write_uint32(metadata, offset);
+         blob_write_uint32(metadata, count);
+         i += count - 1;
       } else {
          blob_write_uint32(metadata, remap_type_uniform_offset);
 
-         uint32_t offset = entry - uniform_storage;
          blob_write_uint32(metadata, offset);
       }
    }
@@ -634,6 +652,14 @@ read_uniform_remap_table(struct blob_reader *metadata,
          remap_table[i] = INACTIVE_UNIFORM_EXPLICIT_LOCATION;
       } else if (type == remap_type_null_ptr) {
          remap_table[i] = NULL;
+      } else if (type == remap_type_uniform_offsets_equal) {
+         uint32_t uni_offset = blob_read_uint32(metadata);
+         uint32_t count = blob_read_uint32(metadata);
+         struct gl_uniform_storage *entry = uniform_storage + uni_offset;
+
+         for (unsigned j = 0; j < count; j++)
+            remap_table[i+j] = entry;
+         i += count - 1;
       } else {
          uint32_t uni_offset = blob_read_uint32(metadata);
          remap_table[i] = uniform_storage + uni_offset;




More information about the mesa-commit mailing list