[Mesa-dev] [PATCH 09/14] st/mesa: fix up uniform limits to be able to expose large UBOs

Marek Olšák maraeo at gmail.com
Wed Aug 8 23:55:18 UTC 2018


From: Marek Olšák <marek.olsak at amd.com>

---
 src/mesa/state_tracker/st_extensions.c | 31 +++++++++++++++++++-------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 5e580aad2e4..1a0c4500c63 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -147,20 +147,25 @@ void st_init_limits(struct pipe_screen *screen,
    c->MaxTextureLodBias =
       screen->get_paramf(screen, PIPE_CAPF_MAX_TEXTURE_LOD_BIAS);
 
    c->QuadsFollowProvokingVertexConvention =
       screen->get_param(screen,
                         PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION);
 
    c->MaxUniformBlockSize =
       screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
                                PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE);
+   /* GL45-CTS.enhanced_layouts.ssb_member_invalid_offset_alignment fails if
+    * this is larger than INT_MAX - 100. Use a nicely aligned limit.
+    */
+   c->MaxUniformBlockSize = MIN2(c->MaxUniformBlockSize, INT_MAX - 127);
+
    if (c->MaxUniformBlockSize < 16384) {
       can_ubo = FALSE;
    }
 
    for (sh = 0; sh < PIPE_SHADER_TYPES; ++sh) {
       struct gl_shader_compiler_options *options;
       struct gl_program_constants *pc;
       const nir_shader_compiler_options *nir_options = NULL;
 
       if (screen->get_compiler_options) {
@@ -203,42 +208,45 @@ void st_init_limits(struct pipe_screen *screen,
          screen->get_shader_param(screen, sh,
                                   PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS);
       pc->MaxAttribs =
       pc->MaxNativeAttribs =
          screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INPUTS);
       pc->MaxTemps =
       pc->MaxNativeTemps =
          screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEMPS);
       pc->MaxAddressRegs =
       pc->MaxNativeAddressRegs = sh == PIPE_SHADER_VERTEX ? 1 : 0;
-      pc->MaxParameters =
-      pc->MaxNativeParameters =
+
+      pc->MaxUniformComponents =
          screen->get_shader_param(screen, sh,
-                   PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE) / sizeof(float[4]);
+                                  PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE) / 4;
+      pc->MaxUniformComponents = MIN2(pc->MaxUniformComponents,
+                                      MAX_UNIFORMS * 4);
+
+      pc->MaxParameters =
+      pc->MaxNativeParameters = pc->MaxUniformComponents / 4;
       pc->MaxInputComponents =
          screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INPUTS) * 4;
       pc->MaxOutputComponents =
          screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_OUTPUTS) * 4;
 
-      pc->MaxUniformComponents =
-         4 * MIN2(pc->MaxNativeParameters, MAX_UNIFORMS);
 
       pc->MaxUniformBlocks =
          screen->get_shader_param(screen, sh,
                                   PIPE_SHADER_CAP_MAX_CONST_BUFFERS);
       if (pc->MaxUniformBlocks)
          pc->MaxUniformBlocks -= 1; /* The first one is for ordinary uniforms. */
       pc->MaxUniformBlocks = _min(pc->MaxUniformBlocks, MAX_UNIFORM_BUFFERS);
 
-      pc->MaxCombinedUniformComponents = (pc->MaxUniformComponents +
-                                          c->MaxUniformBlockSize / 4 *
-                                          pc->MaxUniformBlocks);
+      pc->MaxCombinedUniformComponents =
+         pc->MaxUniformComponents +
+         (uint64_t)c->MaxUniformBlockSize / 4 * pc->MaxUniformBlocks;
 
       temp = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS);
       if (temp) {
          /*
           * for separate atomic counters get the actual hw limits
           * per stage on atomic counters and buffers
           */
          ssbo_atomic = false;
          pc->MaxAtomicCounters = temp;
          pc->MaxAtomicBuffers = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS);
@@ -303,20 +311,27 @@ void st_init_limits(struct pipe_screen *screen,
                  65536);
       else
          options->MaxUnrollIterations =
             screen->get_shader_param(screen, sh,
                                   PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT);
 
       options->LowerCombinedClipCullDistance = true;
       options->LowerBufferInterfaceBlocks = true;
    }
 
+   c->MaxUserAssignableUniformLocations =
+      c->Program[MESA_SHADER_VERTEX].MaxUniformComponents +
+      c->Program[MESA_SHADER_TESS_CTRL].MaxUniformComponents +
+      c->Program[MESA_SHADER_TESS_EVAL].MaxUniformComponents +
+      c->Program[MESA_SHADER_GEOMETRY].MaxUniformComponents +
+      c->Program[MESA_SHADER_FRAGMENT].MaxUniformComponents;
+
    c->GLSLOptimizeConservatively =
       screen->get_param(screen, PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY);
    c->LowerTessLevel = true;
    c->LowerCsDerivedVariables = true;
    c->PrimitiveRestartForPatches =
       screen->get_param(screen, PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES);
 
    c->MaxCombinedTextureImageUnits =
          _min(c->Program[MESA_SHADER_VERTEX].MaxTextureImageUnits +
               c->Program[MESA_SHADER_TESS_CTRL].MaxTextureImageUnits +
-- 
2.17.1



More information about the mesa-dev mailing list