asahi: Expose PIPE_CAP_CLIP_HALFZ
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sun, 30 May 2021 20:11:37 +0000 (01:41 +0530)
committerMarge Bot <eric+marge@anholt.net>
Sun, 30 May 2021 23:32:01 +0000 (23:32 +0000)
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@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11084>

src/asahi/compiler/agx_compile.c
src/asahi/compiler/agx_compile.h
src/gallium/drivers/asahi/agx_pipe.c
src/gallium/drivers/asahi/agx_state.c

index 6970e62..7a38d63 100644 (file)
@@ -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);
index 484d96e..70aed6e 100644 (file)
@@ -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 {
index e6c8273..fd61ef3 100644 (file)
@@ -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:
index d11cddb..8b8086b 100644 (file)
@@ -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,