st/mesa: allow R8 to not be exposed as renderable by driver
[mesa.git] / src / mesa / main / glspirv.c
index bb5a3f7452b004ce0f497917d45508484ad2ecac..64daf54ec422bfd0342f6f7550efa6a6b0a3d119 100644 (file)
@@ -148,9 +148,7 @@ _mesa_spirv_link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
 
       /* Create program and attach it to the linked shader */
       struct gl_program *gl_prog =
-         ctx->Driver.NewProgram(ctx,
-                                _mesa_shader_stage_to_program(shader_type),
-                                prog->Name, false);
+         ctx->Driver.NewProgram(ctx, shader_type, prog->Name, false);
       if (!gl_prog) {
          prog->data->LinkStatus = LINKING_FAILURE;
          _mesa_delete_linked_shader(ctx, linked);
@@ -178,6 +176,41 @@ _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;
+         }
+      }
+   }
+
+   /* Compute shaders have additional restrictions. */
+   if ((prog->data->linked_stages & (1 << MESA_SHADER_COMPUTE)) &&
+       (prog->data->linked_stages & ~(1 << MESA_SHADER_COMPUTE))) {
+      ralloc_asprintf_append(&prog->data->InfoLog,
+                             "Compute shaders may not be linked with any other "
+                             "type of shader\n");
+      prog->data->LinkStatus = LINKING_FAILURE;
+      return;
+   }
 }
 
 nir_shader *
@@ -204,15 +237,23 @@ _mesa_spirv_to_nir(struct gl_context *ctx,
 
    for (unsigned i = 0; i < spirv_data->NumSpecializationConstants; ++i) {
       spec_entries[i].id = spirv_data->SpecializationConstantsIndex[i];
-      spec_entries[i].data32 = spirv_data->SpecializationConstantsValue[i];
+      spec_entries[i].value.u32 = spirv_data->SpecializationConstantsValue[i];
       spec_entries[i].defined_on_module = false;
    }
 
    const struct spirv_to_nir_options spirv_options = {
       .environment = NIR_SPIRV_OPENGL,
-      .lower_workgroup_access_to_offsets = true,
-      .lower_ubo_ssbo_access_to_offsets = true,
-      .caps = ctx->Const.SpirVCapabilities
+      .frag_coord_is_sysval = ctx->Const.GLSLFragCoordIsSysVal,
+      .caps = ctx->Const.SpirVCapabilities,
+      .ubo_addr_format = nir_address_format_32bit_index_offset,
+      .ssbo_addr_format = nir_address_format_32bit_index_offset,
+
+      /* TODO: Consider changing this to an address format that has the NULL
+       * pointer equals to 0.  That might be a better format to play nice
+       * with certain code / code generators.
+       */
+      .shared_addr_format = nir_address_format_32bit_offset,
+
    };
 
    nir_shader *nir =
@@ -241,7 +282,7 @@ _mesa_spirv_to_nir(struct gl_context *ctx,
     * inline functions.  That way they get properly initialized at the top
     * of the function and not at the top of its caller.
     */
-   NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp);
+   NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp);
    NIR_PASS_V(nir, nir_lower_returns);
    NIR_PASS_V(nir, nir_inline_functions);
    NIR_PASS_V(nir, nir_opt_deref);
@@ -262,6 +303,8 @@ _mesa_spirv_to_nir(struct gl_context *ctx,
    if (nir->info.stage == MESA_SHADER_VERTEX)
       nir_remap_dual_slot_attributes(nir, &linked_shader->Program->DualSlotInputs);
 
+   NIR_PASS_V(nir, nir_lower_frexp);
+
    return nir;
 }
 
@@ -325,7 +368,7 @@ _mesa_SpecializeShaderARB(GLuint shader,
 
    for (unsigned i = 0; i < numSpecializationConstants; ++i) {
       spec_entries[i].id = pConstantIndex[i];
-      spec_entries[i].data32 = pConstantValue[i];
+      spec_entries[i].value.u32 = pConstantValue[i];
       spec_entries[i].defined_on_module = false;
    }