glsl/linker: add check for compute shared memory size
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Tue, 10 Oct 2017 11:58:43 +0000 (13:58 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Tue, 10 Oct 2017 11:58:43 +0000 (13:58 +0200)
Unlike uniforms, the limit on shared memory size is not called out
explicitly in the list of things that cause linker errors, but presumably
that's just an oversight in the spec.

Fixes dEQP-GLES31.functional.debug.negative_coverage.{callbacks,get_error,log}.compute.exceed_shared_memory_size_limit

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/compiler/glsl/ir_optimization.h
src/compiler/glsl/linker.cpp
src/compiler/glsl/lower_shared_reference.cpp

index 38fb54990ea2d49219b895dba181279221a6f9e1..eb3ec3b0c7d10e64a2b774aeaad17a11eea41aca 100644 (file)
@@ -143,8 +143,9 @@ bool lower_clip_cull_distance(struct gl_shader_program *prog,
                               gl_linked_shader *shader);
 void lower_output_reads(unsigned stage, exec_list *instructions);
 bool lower_packing_builtins(exec_list *instructions, int op_mask);
-void lower_shared_reference(struct gl_linked_shader *shader,
-                            unsigned *shared_size);
+void lower_shared_reference(struct gl_context *ctx,
+                            struct gl_shader_program *prog,
+                            struct gl_linked_shader *shader);
 void lower_ubo_reference(struct gl_linked_shader *shader,
                          bool clamp_block_indices, bool use_std430_as_default);
 void lower_packed_varyings(void *mem_ctx,
index f352c5385ca501b52533279bc60915a18018556c..03eb05bf637651aed1d0a7f44b1e027d28a61110 100644 (file)
@@ -4657,8 +4657,7 @@ link_varyings_and_uniforms(unsigned first, unsigned last,
                              ctx->Const.UseSTD430AsDefaultPacking);
 
       if (i == MESA_SHADER_COMPUTE)
-         lower_shared_reference(prog->_LinkedShaders[i],
-                                &prog->Comp.SharedSize);
+         lower_shared_reference(ctx, prog, prog->_LinkedShaders[i]);
 
       lower_vector_derefs(prog->_LinkedShaders[i]);
       do_vec_index_to_swizzle(prog->_LinkedShaders[i]->ir);
index b9098913af84f524f0618325d3085c6408fdf4d2..a1b3f7df47e7d439475167e4f147e577e259964b 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "lower_buffer_access.h"
 #include "ir_builder.h"
+#include "linker.h"
 #include "main/macros.h"
 #include "util/list.h"
 #include "glsl_parser_extras.h"
@@ -478,7 +479,9 @@ lower_shared_reference_visitor::visit_enter(ir_call *ir)
 } /* unnamed namespace */
 
 void
-lower_shared_reference(struct gl_linked_shader *shader, unsigned *shared_size)
+lower_shared_reference(struct gl_context *ctx,
+                       struct gl_shader_program *prog,
+                       struct gl_linked_shader *shader)
 {
    if (shader->Stage != MESA_SHADER_COMPUTE)
       return;
@@ -495,5 +498,19 @@ lower_shared_reference(struct gl_linked_shader *shader, unsigned *shared_size)
       visit_list_elements(&v, shader->ir);
    } while (v.progress);
 
-   *shared_size = v.shared_size;
+   prog->Comp.SharedSize = v.shared_size;
+
+   /* Section 19.1 (Compute Shader Variables) of the OpenGL 4.5 (Core Profile)
+    * specification says:
+    *
+    *   "There is a limit to the total size of all variables declared as
+    *    shared in a single program object. This limit, expressed in units of
+    *    basic machine units, may be queried as the value of
+    *    MAX_COMPUTE_SHARED_MEMORY_SIZE."
+    */
+   if (prog->Comp.SharedSize > ctx->Const.MaxComputeSharedMemorySize) {
+      linker_error(prog, "Too much shared memory used (%u/%u)\n",
+                   prog->Comp.SharedSize,
+                   ctx->Const.MaxComputeSharedMemorySize);
+   }
 }