Mesa (master): glsl/linker: Fix xfb stride alignment for buffers containing 64bit types

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Apr 1 17:39:01 UTC 2021


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

Author: Andrii Simiklit <andrii.simiklit at globallogic.com>
Date:   Wed Feb 24 14:30:25 2021 +0200

glsl/linker: Fix xfb stride alignment for buffers containing 64bit types

Per OpenGL 4.6 spec:
"If no xfb_stride qualifier is specified for a
 binding point, the stride is derived by identifying the variable associated with the
 binding point having the largest offset, and then adding the offset and the size of
 the variable, in basic machine units. If any variable associated with the binding
 point contains double-precision floating-point components, the derived stride is
 aligned to the next multiple of eight basic machine units. If a binding point has no
 xfb_stride qualifier and no associated output variables, its stride is zero."

Reviewed-by: Tapani Pälli <tapani.palli at intel.com>
Signed-off-by: Andrii Simiklit <andrii.simiklit at globallogic.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2333>

---

 src/compiler/glsl/link_varyings.cpp | 25 ++++++++++++++++++-------
 src/compiler/glsl/link_varyings.h   |  4 ++--
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
index 2f59967339e..dc5cb65612a 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -1219,8 +1219,8 @@ tfeedback_decl::store(struct gl_context *ctx, struct gl_shader_program *prog,
                       unsigned buffer, unsigned buffer_index,
                       const unsigned max_outputs,
                       BITSET_WORD *used_components[MAX_FEEDBACK_BUFFERS],
-                      bool *explicit_stride, bool has_xfb_qualifiers,
-                      const void* mem_ctx) const
+                      bool *explicit_stride, unsigned *max_member_alignment,
+                      bool has_xfb_qualifiers, const void* mem_ctx) const
 {
    unsigned xfb_offset = 0;
    unsigned size = this->size;
@@ -1402,7 +1402,14 @@ tfeedback_decl::store(struct gl_context *ctx, struct gl_shader_program *prog,
          return false;
       }
    } else {
-      info->Buffers[buffer].Stride = xfb_offset;
+      if (max_member_alignment && has_xfb_qualifiers) {
+         max_member_alignment[buffer] = MAX2(max_member_alignment[buffer],
+                                             this->is_64bit() ? 2 : 1);
+         info->Buffers[buffer].Stride = ALIGN(xfb_offset,
+                                              max_member_alignment[buffer]);
+      } else {
+         info->Buffers[buffer].Stride = xfb_offset;
+      }
    }
 
  store_varying:
@@ -1591,7 +1598,7 @@ store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
          if (!tfeedback_decls[i].store(ctx, prog,
                                        xfb_prog->sh.LinkedTransformFeedback,
                                        num_buffers, num_buffers, num_outputs,
-                                       used_components, NULL,
+                                       used_components, NULL, NULL,
                                        has_xfb_qualifiers, mem_ctx))
             return false;
 
@@ -1605,7 +1612,7 @@ store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
       unsigned buffer =
          num_tfeedback_decls ? tfeedback_decls[0].get_buffer() : 0;
       bool explicit_stride[MAX_FEEDBACK_BUFFERS] = { false };
-
+      unsigned max_member_alignment[MAX_FEEDBACK_BUFFERS] = { 1, 1, 1, 1 };
       /* Apply any xfb_stride global qualifiers */
       if (has_xfb_qualifiers) {
          for (unsigned j = 0; j < MAX_FEEDBACK_BUFFERS; j++) {
@@ -1630,7 +1637,9 @@ store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
                                           xfb_prog->sh.LinkedTransformFeedback,
                                           buffer, num_buffers, num_outputs,
                                           used_components, explicit_stride,
-                                          has_xfb_qualifiers, mem_ctx))
+                                          max_member_alignment,
+                                          has_xfb_qualifiers,
+                                          mem_ctx))
                return false;
             num_buffers++;
             buffer_stream_id = -1;
@@ -1672,7 +1681,9 @@ store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
                                        xfb_prog->sh.LinkedTransformFeedback,
                                        buffer, num_buffers, num_outputs,
                                        used_components, explicit_stride,
-                                       has_xfb_qualifiers, mem_ctx))
+                                       max_member_alignment,
+                                       has_xfb_qualifiers,
+                                       mem_ctx))
             return false;
       }
    }
diff --git a/src/compiler/glsl/link_varyings.h b/src/compiler/glsl/link_varyings.h
index 7bad222f132..87d7f43998e 100644
--- a/src/compiler/glsl/link_varyings.h
+++ b/src/compiler/glsl/link_varyings.h
@@ -106,8 +106,8 @@ public:
               struct gl_transform_feedback_info *info, unsigned buffer,
               unsigned buffer_index, const unsigned max_outputs,
               BITSET_WORD *used_components[MAX_FEEDBACK_BUFFERS],
-              bool *explicit_stride, bool has_xfb_qualifiers,
-              const void *mem_ctx) const;
+              bool *explicit_stride, unsigned *max_member_alignment,
+              bool has_xfb_qualifiers, const void *mem_ctx) const;
    const tfeedback_candidate *find_candidate(gl_shader_program *prog,
                                              hash_table *tfeedback_candidates);
    void set_lowered_candidate(const tfeedback_candidate *candidate);



More information about the mesa-commit mailing list