[Mesa-dev] [PATCH 2/5] nir: Store some geometry shader data in nir_shader.

Kenneth Graunke kenneth at whitecape.org
Thu Sep 3 01:48:47 PDT 2015


This makes it possible for NIR shaders to know the number of output
vertices and the number of invocations.  Drivers could also access
these directly without going through gl_program.

We should probably add InputType and OutputType here too, but currently
those are stored as GL_* enums, and I wanted to avoid using those in
NIR, as I suspect Vulkan/SPIR-V will use different enums.  (We should
probably make our own.)

We could add VerticesIn, but it's easily computable from the input
topology, so I'm not sure whether it's worth it.  It's also currently
not stored in gl_shader (only gl_shader_program), which would require
changes to the glsl_to_nir interface or require us to store it there.

This is a bit of duplication of data...ideally, we would factor these
substructs out of gl_program, gl_shader_program, and nir_shader, creating
a gl_geometry_info class...but it would need to go in a new place (in
src/glsl?) that isn't mtypes.h nor nir.h.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/glsl/nir/glsl_to_nir.cpp | 3 +++
 src/glsl/nir/nir.c           | 3 +++
 src/glsl/nir/nir.h           | 8 ++++++++
 3 files changed, 14 insertions(+)

diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
index 5fb4ee2..b0774b8 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -138,6 +138,9 @@ glsl_to_nir(struct gl_shader *sh, const nir_shader_compiler_options *options)
    v2.run(sh->ir);
    visit_exec_list(sh->ir, &v1);
 
+   shader->gs.vertices_out = sh->Geom.VerticesOut;
+   shader->gs.invocations = sh->Geom.Invocations;
+
    return shader;
 }
 
diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index 3f4bec4..a55d6f8 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -54,6 +54,9 @@ nir_shader_create(void *mem_ctx,
 
    shader->stage = stage;
 
+   shader->gs.vertices_out = 0;
+   shader->gs.invocations = 0;
+
    return shader;
 }
 
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index e73b7fb..570a33c 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1477,6 +1477,14 @@ typedef struct nir_shader {
 
    /** The shader stage, such as MESA_SHADER_VERTEX. */
    gl_shader_stage stage;
+
+   struct {
+      /** The maximum number of vertices the geometry shader might write. */
+      unsigned vertices_out;
+
+      /** 1 .. MAX_GEOMETRY_SHADER_INVOCATIONS */
+      unsigned invocations;
+   } gs;
 } nir_shader;
 
 #define nir_foreach_overload(shader, overload)                        \
-- 
2.5.0



More information about the mesa-dev mailing list