Mesa (master): glsl/linker: Add support for XFB varying lowering in geometry shader

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Sep 28 08:14:43 UTC 2020


Module: Mesa
Branch: master
Commit: f2b94ae085ab454944e03fbb9d91bc65bf40abc8
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f2b94ae085ab454944e03fbb9d91bc65bf40abc8

Author: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
Date:   Wed Aug 12 12:32:37 2020 -0400

glsl/linker: Add support for XFB varying lowering in geometry shader

Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6723>

---

 src/compiler/glsl/link_varyings.cpp     |  1 +
 src/compiler/glsl/lower_xfb_varying.cpp | 42 +++++++++++++++++++++++++--------
 src/mesa/state_tracker/st_extensions.c  |  2 +-
 3 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
index 7af97cddc0c..cc65810b718 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -2810,6 +2810,7 @@ assign_varying_locations(struct gl_context *ctx,
           !tfeedback_decls[i].is_aligned(dmul, matched_candidate->offset)) ||
          (matched_candidate->toplevel_var->data.explicit_location &&
           matched_candidate->toplevel_var->data.location < VARYING_SLOT_VAR0 &&
+          (!consumer || consumer->Stage == MESA_SHADER_FRAGMENT) &&
           (ctx->Const.ShaderCompilerOptions[producer->Stage].LowerBuiltinVariablesXfb &
               BITFIELD_BIT(matched_candidate->toplevel_var->data.location)));
 
diff --git a/src/compiler/glsl/lower_xfb_varying.cpp b/src/compiler/glsl/lower_xfb_varying.cpp
index d460bbd5cae..9e49a37d185 100644
--- a/src/compiler/glsl/lower_xfb_varying.cpp
+++ b/src/compiler/glsl/lower_xfb_varying.cpp
@@ -40,10 +40,13 @@ class lower_xfb_var_splicer : public ir_hierarchical_visitor
 {
 public:
    explicit lower_xfb_var_splicer(void *mem_ctx,
+                                  gl_shader_stage stage,
                                   const exec_list *instructions);
 
+   ir_visitor_status append_instructions(exec_node *node);
    virtual ir_visitor_status visit_leave(ir_return *ret);
    virtual ir_visitor_status visit_leave(ir_function_signature *sig);
+   virtual ir_visitor_status visit_leave(ir_emit_vertex *emit);
 
 private:
    /**
@@ -51,8 +54,10 @@ private:
     */
    void * const mem_ctx;
 
+   gl_shader_stage stage;
+
    /**
-    * Instructions that should be spliced into place before each return.
+    * Instructions that should be spliced into place before each return and EmitVertex().
     */
    const exec_list *instructions;
 };
@@ -60,20 +65,35 @@ private:
 } /* anonymous namespace */
 
 
-lower_xfb_var_splicer::lower_xfb_var_splicer(void *mem_ctx, const exec_list *instructions)
-   : mem_ctx(mem_ctx), instructions(instructions)
+lower_xfb_var_splicer::lower_xfb_var_splicer(void *mem_ctx, gl_shader_stage stage,
+                                             const exec_list *instructions)
+   : mem_ctx(mem_ctx), stage(stage), instructions(instructions)
 {
 }
 
 ir_visitor_status
-lower_xfb_var_splicer::visit_leave(ir_return *ret)
+lower_xfb_var_splicer::append_instructions(exec_node *node)
 {
    foreach_in_list(ir_instruction, ir, this->instructions) {
-      ret->insert_before(ir->clone(this->mem_ctx, NULL));
+      node->insert_before(ir->clone(this->mem_ctx, NULL));
    }
    return visit_continue;
 }
 
+ir_visitor_status
+lower_xfb_var_splicer::visit_leave(ir_return *ret)
+{
+   if (stage != MESA_SHADER_VERTEX)
+      return visit_continue;
+   return append_instructions(ret);
+}
+
+ir_visitor_status
+lower_xfb_var_splicer::visit_leave(ir_emit_vertex *emit)
+{
+   return append_instructions(emit);
+}
+
 /** Insert a copy-back assignment at the end of the main() function */
 ir_visitor_status
 lower_xfb_var_splicer::visit_leave(ir_function_signature *sig)
@@ -81,11 +101,13 @@ lower_xfb_var_splicer::visit_leave(ir_function_signature *sig)
    if (strcmp(sig->function_name(), "main") != 0)
       return visit_continue;
 
-   if (((ir_instruction*)sig->body.get_tail())->ir_type == ir_type_return)
-      return visit_continue;
+   if (this->stage == MESA_SHADER_VERTEX) {
+      if (((ir_instruction*)sig->body.get_tail())->ir_type == ir_type_return)
+         return visit_continue;
 
-   foreach_in_list(ir_instruction, ir, this->instructions) {
-      sig->body.push_tail(ir->clone(this->mem_ctx, NULL));
+      foreach_in_list(ir_instruction, ir, this->instructions) {
+         sig->body.push_tail(ir->clone(this->mem_ctx, NULL));
+      }
    }
 
    return visit_continue;
@@ -215,7 +237,7 @@ lower_xfb_varying(void *mem_ctx,
    ir_assignment *new_assignment = new(mem_ctx) ir_assignment(lhs, deref);
    new_instructions.push_tail(new_assignment);
 
-   lower_xfb_var_splicer splicer(mem_ctx, &new_instructions);
+   lower_xfb_var_splicer splicer(mem_ctx, shader->Stage, &new_instructions);
    visit_list_elements(&splicer, shader->ir);
 
    return new_variable;
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index f74ad5610a0..da4cfc1c469 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -335,7 +335,7 @@ void st_init_limits(struct pipe_screen *screen,
        */
       options->LowerBufferInterfaceBlocks = !prefer_nir;
 
-      if (sh == MESA_SHADER_VERTEX) {
+      if (sh == PIPE_SHADER_VERTEX || sh == PIPE_SHADER_GEOMETRY) {
          if (screen->get_param(screen, PIPE_CAP_VIEWPORT_TRANSFORM_LOWERED))
             options->LowerBuiltinVariablesXfb |= VARYING_BIT_POS;
          if (screen->get_param(screen, PIPE_CAP_PSIZ_CLAMPED))



More information about the mesa-commit mailing list