[Mesa-dev] [PATCH 4/4] mesa/st: do nir_lower_viewport_transform

Qiang Yu yuq825 at gmail.com
Wed Mar 27 03:55:05 UTC 2019


Do nir_lower_viewport_transform when driver set
PIPE_CAP_NIR_VS_LOWER_VIEWPORT_TRANSFORM in vertex
shader.

Signed-off-by: Qiang Yu <yuq825 at gmail.com>
---
 src/gallium/auxiliary/util/u_screen.c     |  3 +++
 src/gallium/include/pipe/p_defines.h      |  1 +
 src/mesa/state_tracker/st_glsl_to_nir.cpp | 23 +++++++++++++++++++++++
 src/mesa/state_tracker/st_nir.h           |  4 ++++
 src/mesa/state_tracker/st_program.c       |  1 +
 5 files changed, 32 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_screen.c b/src/gallium/auxiliary/util/u_screen.c
index b902c083ad4..c3b8252197f 100644
--- a/src/gallium/auxiliary/util/u_screen.c
+++ b/src/gallium/auxiliary/util/u_screen.c
@@ -344,6 +344,9 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen,
    case PIPE_CAP_COMPUTE_GRID_INFO_LAST_BLOCK:
       return 0;
 
+   case PIPE_CAP_NIR_VS_LOWER_VIEWPORT_TRANSFORM:
+      return 0;
+
    default:
       unreachable("bad PIPE_CAP_*");
    }
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index ebc44d7a75e..1d6b69453e8 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -864,6 +864,7 @@ enum pipe_cap
    PIPE_CAP_NIR_COMPACT_ARRAYS,
    PIPE_CAP_MAX_VARYINGS,
    PIPE_CAP_COMPUTE_GRID_INFO_LAST_BLOCK,
+   PIPE_CAP_NIR_VS_LOWER_VIEWPORT_TRANSFORM,
 };
 
 /**
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index e5d5fe21e27..87e457dccbf 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -738,6 +738,26 @@ st_nir_lower_wpos_ytransform(struct nir_shader *nir,
    }
 }
 
+void
+st_nir_lower_viewport_transform(struct nir_shader *nir,
+                                struct gl_program *prog,
+                                struct pipe_screen *pscreen)
+{
+   if (nir->info.stage != MESA_SHADER_VERTEX ||
+       !pscreen->get_param(pscreen, PIPE_CAP_NIR_VS_LOWER_VIEWPORT_TRANSFORM))
+      return;
+
+   static const nir_lower_viewport_transform_options viewport_options = {
+      .scale = { STATE_INTERNAL, STATE_VIEWPORT_SCALE },
+      .translate = { STATE_INTERNAL, STATE_VIEWPORT_TRANSLATE },
+   };
+
+   NIR_PASS_V(nir, nir_lower_viewport_transform, &viewport_options);
+
+   _mesa_add_state_reference(prog->Parameters, viewport_options.scale);
+   _mesa_add_state_reference(prog->Parameters, viewport_options.translate);
+}
+
 bool
 st_link_nir(struct gl_context *ctx,
             struct gl_shader_program *shader_program)
@@ -793,6 +813,9 @@ st_link_nir(struct gl_context *ctx,
       NIR_PASS_V(nir, st_nir_lower_wpos_ytransform, shader->Program,
                  st->pipe->screen);
 
+      NIR_PASS_V(nir, st_nir_lower_viewport_transform, shader->Program,
+                 st->pipe->screen);
+
       NIR_PASS_V(nir, nir_lower_system_values);
       NIR_PASS_V(nir, nir_lower_clip_cull_distance_arrays);
 
diff --git a/src/mesa/state_tracker/st_nir.h b/src/mesa/state_tracker/st_nir.h
index 94eae84402e..100ab0f7125 100644
--- a/src/mesa/state_tracker/st_nir.h
+++ b/src/mesa/state_tracker/st_nir.h
@@ -41,6 +41,10 @@ void st_nir_lower_wpos_ytransform(struct nir_shader *nir,
                                   struct gl_program *prog,
                                   struct pipe_screen *pscreen);
 
+void st_nir_lower_viewport_transform(struct nir_shader *nir,
+                                     struct gl_program *prog,
+                                     struct pipe_screen *pscreen);
+
 void st_finalize_nir(struct st_context *st, struct gl_program *prog,
                      struct gl_shader_program *shader_program,
                      struct nir_shader *nir);
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 9f6e492d6fb..cf1ae6e65a8 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -442,6 +442,7 @@ st_translate_prog_to_nir(struct st_context *st, struct gl_program *prog,
    nir_validate_shader(nir, "after st/ptn lower_regs_to_ssa");
 
    NIR_PASS_V(nir, st_nir_lower_wpos_ytransform, prog, st->pipe->screen);
+   NIR_PASS_V(nir, st_nir_lower_viewport_transform, prog, st->pipe->screen);
    NIR_PASS_V(nir, nir_lower_system_values);
 
    /* Optimise NIR */
-- 
2.17.1



More information about the mesa-dev mailing list