mesa/glspirv: Validate that there is a VS when there is a TCS, TES or GS
authorNeil Roberts <nroberts@igalia.com>
Fri, 25 May 2018 13:34:26 +0000 (15:34 +0200)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Fri, 12 Jul 2019 21:42:41 +0000 (23:42 +0200)
The shader combination tests are copied from link_shaders().

For example, it allows the following tests (when run on SPIR-V mode) to
pass:
   spec/arb_tessellation_shader/linker/no-vs
   spec/arb_tessellation_shader/linker/tcs-no-vs
   spec/arb_tessellation_shader/linker/tes-no-vs
   spec/glsl-1.50/linker/gs-without-vs

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
src/mesa/main/glspirv.c

index 9d767a108ed4213caac7d9f9073f36f74e130a59..73878d903657b0b4c5f786569c032f92d77fc1af 100644 (file)
@@ -178,6 +178,31 @@ _mesa_spirv_link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
 
    if (last_vert_stage)
       prog->last_vert_prog = prog->_LinkedShaders[last_vert_stage - 1]->Program;
+
+   /* Some shaders have to be linked with some other shaders present. */
+   if (!prog->SeparateShader) {
+      static const struct {
+         gl_shader_stage a, b;
+      } stage_pairs[] = {
+         { MESA_SHADER_GEOMETRY, MESA_SHADER_VERTEX },
+         { MESA_SHADER_TESS_EVAL, MESA_SHADER_VERTEX },
+         { MESA_SHADER_TESS_CTRL, MESA_SHADER_VERTEX },
+         { MESA_SHADER_TESS_CTRL, MESA_SHADER_TESS_EVAL },
+      };
+
+      for (unsigned i = 0; i < ARRAY_SIZE(stage_pairs); i++) {
+         gl_shader_stage a = stage_pairs[i].a;
+         gl_shader_stage b = stage_pairs[i].b;
+         if ((prog->data->linked_stages & ((1 << a) | (1 << b))) == (1 << a)) {
+            ralloc_asprintf_append(&prog->data->InfoLog,
+                                   "%s shader must be linked with %s shader\n",
+                                   _mesa_shader_stage_to_string(a),
+                                   _mesa_shader_stage_to_string(b));
+            prog->data->LinkStatus = LINKING_FAILURE;
+            return;
+         }
+      }
+   }
 }
 
 nir_shader *