Mesa (main): asahi: Expose PIPE_CAP_CLIP_HALFZ

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun May 30 23:42:26 UTC 2021


Module: Mesa
Branch: main
Commit: 5de49375ecd47ae0710307fa57c2b92d202e4a7d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=5de49375ecd47ae0710307fa57c2b92d202e4a7d

Author: Alyssa Rosenzweig <alyssa at rosenzweig.io>
Date:   Mon May 31 01:59:37 2021 +0530

asahi: Expose PIPE_CAP_CLIP_HALFZ

Use the Zink lowering pass to handle the non-halfz case. Metal, like Vulkan,
uses half-z (and Metal is not configurable, making r/e tricky).

Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11084>

---

 src/asahi/compiler/agx_compile.c      | 7 ++++++-
 src/asahi/compiler/agx_compile.h      | 3 +++
 src/gallium/drivers/asahi/agx_pipe.c  | 1 +
 src/gallium/drivers/asahi/agx_state.c | 3 ++-
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c
index 6970e629648..7a38d63cdd5 100644
--- a/src/asahi/compiler/agx_compile.c
+++ b/src/asahi/compiler/agx_compile.c
@@ -1080,9 +1080,14 @@ agx_compile_shader_nir(nir_shader *nir,
          glsl_get_natural_size_align_bytes);
    NIR_PASS_V(nir, nir_lower_indirect_derefs, nir_var_function_temp, ~0);
 
-   if (ctx->stage == MESA_SHADER_VERTEX)
+   if (ctx->stage == MESA_SHADER_VERTEX) {
       agx_remap_varyings(nir);
 
+      /* Lower from OpenGL [-1, 1] to [0, 1] if half-z is not set */
+      if (!key->vs.clip_halfz)
+         NIR_PASS_V(nir, nir_lower_clip_halfz);
+   }
+
    NIR_PASS_V(nir, nir_split_var_copies);
    NIR_PASS_V(nir, nir_lower_global_vars_to_local);
    NIR_PASS_V(nir, nir_lower_var_copies);
diff --git a/src/asahi/compiler/agx_compile.h b/src/asahi/compiler/agx_compile.h
index 484d96e6fb9..70aed6e48a8 100644
--- a/src/asahi/compiler/agx_compile.h
+++ b/src/asahi/compiler/agx_compile.h
@@ -116,6 +116,9 @@ struct agx_vs_shader_key {
    unsigned vbuf_strides[AGX_MAX_VBUFS];
 
    struct agx_attribute attributes[AGX_MAX_ATTRIBS];
+
+   /* Set to true for clip coordinates to range [0, 1] instead of [-1, 1] */
+   bool clip_halfz : 1;
 };
 
 struct agx_fs_shader_key {
diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c
index e6c82733d71..fd61ef31f84 100644
--- a/src/gallium/drivers/asahi/agx_pipe.c
+++ b/src/gallium/drivers/asahi/agx_pipe.c
@@ -595,6 +595,7 @@ agx_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
    case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
    case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
    case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
+   case PIPE_CAP_CLIP_HALFZ:
       return 1;
 
    case PIPE_CAP_MAX_RENDER_TARGETS:
diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c
index d11cddba6c5..8b8086bfecf 100644
--- a/src/gallium/drivers/asahi/agx_state.c
+++ b/src/gallium/drivers/asahi/agx_state.c
@@ -752,7 +752,8 @@ static bool
 agx_update_vs(struct agx_context *ctx)
 {
    struct agx_vs_shader_key key = {
-      .num_vbufs = util_last_bit(ctx->vb_mask)
+      .num_vbufs = util_last_bit(ctx->vb_mask),
+      .clip_halfz = ctx->rast->base.clip_halfz,
    };
 
    memcpy(key.attributes, ctx->attributes,



More information about the mesa-commit mailing list