panfrost: Remove mali_alt_func
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 27 Dec 2019 17:56:03 +0000 (12:56 -0500)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 27 Dec 2019 17:58:00 +0000 (12:58 -0500)
There's only one way to encode comparison functions in the command
stream, not two. It's just that the semantics for texture comparisons
are flipped from the semantics of stencil comparison. We can factor out
that flip to common Panfrost code, rather than tying it to a second
Gallium routine.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/pan_context.c
src/panfrost/Makefile.sources
src/panfrost/encoder/meson.build
src/panfrost/encoder/pan_encoder.h
src/panfrost/encoder/pan_sampler.c [new file with mode: 0644]
src/panfrost/include/panfrost-job.h
src/panfrost/pandecode/decode.c

index 7421d54c42f1b9de34d9cecf2feabc51dcd05b4c..1446354ade0365762acd186aeecf5681f50eaee6 100644 (file)
@@ -280,39 +280,6 @@ panfrost_translate_compare_func(enum pipe_compare_func in)
         }
 }
 
-static unsigned
-panfrost_translate_alt_compare_func(enum pipe_compare_func in)
-{
-        switch (in) {
-        case PIPE_FUNC_NEVER:
-                return MALI_ALT_FUNC_NEVER;
-
-        case PIPE_FUNC_LESS:
-                return MALI_ALT_FUNC_LESS;
-
-        case PIPE_FUNC_EQUAL:
-                return MALI_ALT_FUNC_EQUAL;
-
-        case PIPE_FUNC_LEQUAL:
-                return MALI_ALT_FUNC_LEQUAL;
-
-        case PIPE_FUNC_GREATER:
-                return MALI_ALT_FUNC_GREATER;
-
-        case PIPE_FUNC_NOTEQUAL:
-                return MALI_ALT_FUNC_NOTEQUAL;
-
-        case PIPE_FUNC_GEQUAL:
-                return MALI_ALT_FUNC_GEQUAL;
-
-        case PIPE_FUNC_ALWAYS:
-                return MALI_ALT_FUNC_ALWAYS;
-
-        default:
-                unreachable("Invalid alt func");
-        }
-}
-
 static unsigned
 panfrost_translate_stencil_op(enum pipe_stencil_op in)
 {
@@ -1781,7 +1748,9 @@ panfrost_create_sampler_state(
                 .wrap_s = translate_tex_wrap(cso->wrap_s),
                 .wrap_t = translate_tex_wrap(cso->wrap_t),
                 .wrap_r = translate_tex_wrap(cso->wrap_r),
-                .compare_func = panfrost_translate_alt_compare_func(cso->compare_func),
+                .compare_func = panfrost_flip_compare_func(
+                                panfrost_translate_compare_func(
+                                        cso->compare_func)),
                 .border_color = {
                         cso->border_color.f[0],
                         cso->border_color.f[1],
index 5e9ad36b8b76705f18d25a6d00e01cc8d71b7d8c..dbd4a8f58ff481b84ece9d0c4bed45fb82943066 100644 (file)
@@ -18,6 +18,7 @@ encoder_FILES := \
         encoder/pan_attributes.c \
         encoder/pan_encoder.h \
         encoder/pan_invocation.c \
+        encoder/pan_sampler.c
         encoder/pan_tiler.c \
         encoder/pan_scratch.c
 
index 35e6f2aacd5f421587ed7b729c843c735aeae731..e203e911de80be29dfd8ef3167a3198ee0d47c89 100644 (file)
@@ -24,6 +24,7 @@ libpanfrost_encoder_files = files(
 
   'pan_attributes.c',
   'pan_invocation.c',
+  'pan_sampler.c',
   'pan_tiler.c',
   'pan_scratch.c',
   'pan_props.c',
index 77f5b2ebb0f87d81a05d3b5a0a5a0b3e1a43d534..2f3ab0d10a98783fbaf6ad41422d8393b3d359f9 100644 (file)
@@ -102,4 +102,9 @@ panfrost_vertex_instanced(
 void panfrost_vertex_id(unsigned padded_count, union mali_attr *attr);
 void panfrost_instance_id(unsigned padded_count, union mali_attr *attr);
 
+/* Samplers */
+
+enum mali_func
+panfrost_flip_compare_func(enum mali_func f);
+
 #endif
diff --git a/src/panfrost/encoder/pan_sampler.c b/src/panfrost/encoder/pan_sampler.c
new file mode 100644 (file)
index 0000000..63ddd17
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2019 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#include "pan_encoder.h"
+
+/* Sampler comparison functions are flipped in OpenGL from the hardware, so we
+ * need to be able to flip accordingly */
+
+enum mali_func
+panfrost_flip_compare_func(enum mali_func f)
+{
+        switch (f) {
+        case MALI_FUNC_LESS:
+                return MALI_FUNC_GREATER;
+        case MALI_FUNC_GREATER:
+                return MALI_FUNC_LESS;
+        case MALI_FUNC_LEQUAL:
+                return MALI_FUNC_GEQUAL;
+        case MALI_FUNC_GEQUAL:
+                return MALI_FUNC_LEQUAL;
+        default:
+                return f;
+        }
+}
index 6ec5a94199ce6b5ddb99b6d6d755ebc736c1de37..abdd804f1cee224ac096db83d09a4376170a8e04 100644 (file)
@@ -88,19 +88,6 @@ enum mali_func {
         MALI_FUNC_ALWAYS   = 7
 };
 
-/* Same OpenGL, but mixed up. Why? Because forget me, that's why! */
-
-enum mali_alt_func {
-        MALI_ALT_FUNC_NEVER    = 0,
-        MALI_ALT_FUNC_GREATER  = 1,
-        MALI_ALT_FUNC_EQUAL    = 2,
-        MALI_ALT_FUNC_GEQUAL   = 3,
-        MALI_ALT_FUNC_LESS     = 4,
-        MALI_ALT_FUNC_NOTEQUAL = 5,
-        MALI_ALT_FUNC_LEQUAL   = 6,
-        MALI_ALT_FUNC_ALWAYS   = 7
-};
-
 /* Flags apply to unknown2_3? */
 
 #define MALI_HAS_MSAA          (1 << 0)
@@ -1290,12 +1277,13 @@ struct mali_sampler_descriptor {
         uint16_t min_lod;
         uint16_t max_lod;
 
-        /* All one word in reality, but packed a bit */
+        /* All one word in reality, but packed a bit. Comparisons are flipped
+         * from OpenGL. */
 
         enum mali_wrap_mode wrap_s : 4;
         enum mali_wrap_mode wrap_t : 4;
         enum mali_wrap_mode wrap_r : 4;
-        enum mali_alt_func compare_func : 3;
+        enum mali_func compare_func : 3;
 
         /* No effect on 2D textures. For cubemaps, set for ES3 and clear for
          * ES2, controlling seamless cubemapping */
index d88158a9312655504398bb730c9a34f54cd2b155..126065c2b2102cd7bd8ac9d8901f4be98247cf6c 100644 (file)
@@ -375,28 +375,6 @@ pandecode_func(enum mali_func mode)
 }
 #undef DEFINE_CASE
 
-/* Why is this duplicated? Who knows... */
-#define DEFINE_CASE(name) case MALI_ALT_FUNC_ ## name: return "MALI_ALT_FUNC_" #name
-static char *
-pandecode_alt_func(enum mali_alt_func mode)
-{
-        switch (mode) {
-                DEFINE_CASE(NEVER);
-                DEFINE_CASE(LESS);
-                DEFINE_CASE(EQUAL);
-                DEFINE_CASE(LEQUAL);
-                DEFINE_CASE(GREATER);
-                DEFINE_CASE(NOTEQUAL);
-                DEFINE_CASE(GEQUAL);
-                DEFINE_CASE(ALWAYS);
-
-        default:
-                pandecode_msg("XXX: invalid alt func %X\n", mode);
-                return "";
-        }
-}
-#undef DEFINE_CASE
-
 #define DEFINE_CASE(name) case MALI_STENCIL_ ## name: return "MALI_STENCIL_" #name
 static char *
 pandecode_stencil_op(enum mali_stencil_op op)
@@ -2468,7 +2446,7 @@ pandecode_vertex_tiler_postfix_pre(
                                 pandecode_prop("wrap_t = %s", pandecode_wrap_mode(s->wrap_t));
                                 pandecode_prop("wrap_r = %s", pandecode_wrap_mode(s->wrap_r));
 
-                                pandecode_prop("compare_func = %s", pandecode_alt_func(s->compare_func));
+                                pandecode_prop("compare_func = %s", pandecode_func(s->compare_func));
 
                                 if (s->zero || s->zero2) {
                                         pandecode_msg("XXX: sampler zero tripped\n");