panfrost: Implement gl_FrontFacing
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 31 Jul 2019 19:24:32 +0000 (12:24 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 1 Aug 2019 23:15:03 +0000 (16:15 -0700)
Interestingly, this requires no compiler changes. It's just exposed as a
special varying.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/pan_assemble.c
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_context.h
src/gallium/drivers/panfrost/pan_screen.c

index 8b831b8f52d70392cd508604cd5b01ec85729e45..4d69cd136bd5bea5ee04529c841b69b87887d6be 100644 (file)
@@ -144,6 +144,12 @@ panfrost_shader_compile(struct panfrost_context *ctx, struct mali_shader_meta *m
                         v.swizzle = default_vec2_swizzle;
 
                         state->reads_point_coord = true;
+                } else if (location == VARYING_SLOT_FACE) {
+                        v.index = 4;
+                        v.format = MALI_R32I;
+                        v.swizzle = default_vec1_swizzle;
+
+                        state->reads_face = true;
                 } else {
                         v.index = 0;
                 }
index b37c95bcf5bb0946e5790a66986e8635066110b5..9447c1690b5515d278bc2ce88c787812eff7f10f 100644 (file)
@@ -516,6 +516,12 @@ panfrost_emit_point_coord(union mali_attr *slot)
         slot->stride = slot->size = slot->shift = slot->extra_flags = 0;
 }
 
+static void
+panfrost_emit_front_face(union mali_attr *slot)
+{
+        slot->elements = MALI_VARYING_FRONT_FACING | MALI_ATTR_INTERNAL;
+}
+
 static void
 panfrost_emit_varying_descriptor(
         struct panfrost_context *ctx,
@@ -618,11 +624,20 @@ panfrost_emit_varying_descriptor(
                 ctx->payload_tiler.primitive_size.pointer =
                         panfrost_emit_varyings(ctx, &varyings[idx++],
                                                2, vertex_count);
+        } else if (fs->reads_face) {
+                /* Dummy to advance index */
+                ++idx;
         }
 
         if (fs->reads_point_coord) {
                 /* Special descriptor */
                 panfrost_emit_point_coord(&varyings[idx++]);
+        } else if (fs->reads_face) {
+                ++idx;
+        }
+
+        if (fs->reads_face) {
+                panfrost_emit_front_face(&varyings[idx++]);
         }
 
         mali_ptr varyings_p = panfrost_upload_transient(ctx, &varyings, idx * sizeof(union mali_attr));
index 1b2689db3add9561d57cd38b68b6730de5e8ee99..e6d6ec48cc2a1ddc643f3c201478efe590c3e47b 100644 (file)
@@ -218,6 +218,7 @@ struct panfrost_shader_state {
         bool can_discard;
         bool writes_point_size;
         bool reads_point_coord;
+        bool reads_face;
 
         struct mali_attr_meta varyings[PIPE_MAX_ATTRIBS];
         gl_varying_slot varyings_loc[PIPE_MAX_ATTRIBS];
index aa39a35e9c3090465e603a6a9116368b922862ab..d8aa6e3410380469e08b640a6314a063a8a55017 100644 (file)
@@ -168,6 +168,11 @@ panfrost_get_param(struct pipe_screen *screen, enum pipe_cap param)
         case PIPE_CAP_GENERATE_MIPMAP:
                 return 1;
 
+        /* We would prefer varyings */
+        case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
+        case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
+                return 0;
+
         case PIPE_CAP_SEAMLESS_CUBE_MAP:
         case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
                 return 1;