[Mesa-dev] [PATCH v2 01/21] mesa/main: Add a 'spirv' flag to gl_shader_program_data

Alejandro Piñeiro apinheiro at igalia.com
Sat May 12 09:40:39 UTC 2018


From: Eduardo Lima Mitev <elima at igalia.com>

This will be used by the linker code to differentiate between programs
made out of SPIR-V or GLSL shaders.

This was rejected in the past, assuming that it was equivalent to
check for "shProg->_LinkedShaders[stage]->spirv_data != NULL". But:

  * At some points of the linking process it would be needed to check
    if _LinkerShaders[stage] is present, so the full check would be:

    "shProg->_LinkedShaders[stage] != NULL &&
     shProg->_LinkedShaders[stage]->spirv_data != NULL"

  * Sometimes you would like to do some specific to SPIR-V
    independently of the stage, or for any stage. For example, "link
    all the uniforms, for all stages". In that case checking for the
    flag would be equivalent to iterate all the _LinkedShaders and
    check if there is any spirv_data available.

The former makes readibility really worse. Both could be solved by
adding two helpers. But adding a flag seems really more simple and
readable.

v2: added justification for the flag on the commit message (Alejandro)

Signed-off-by: Eduardo Lima <elima at igalia.com>
Signed-off-by: Alejandro Piñeiro <apinheiro at igalia.com>
---
 src/mesa/main/mtypes.h          | 6 ++++++
 src/mesa/program/ir_to_mesa.cpp | 1 +
 2 files changed, 7 insertions(+)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 2ef12a444ea..236ed3e7f63 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2889,6 +2889,12 @@ struct gl_shader_program_data
 
    /* Mask of stages this program was linked against */
    unsigned linked_stages;
+
+   /* Whether the shaders of this program are loaded from SPIR-V binaries
+    * (all have the SPIR_V_BINARY_ARB state). This was introduced by the
+    * ARB_gl_spirv extension.
+    */
+   bool spirv;
 };
 
 /**
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 60fb24bf664..2908819d28e 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -3153,6 +3153,7 @@ _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
                       "SPIR_V_BINARY_ARB state");
       }
    }
+   prog->data->spirv = spirv;
 
    if (prog->data->LinkStatus) {
       if (!spirv)
-- 
2.14.1



More information about the mesa-dev mailing list