From de077c20788e9cccd0efe5765bbafe2cf881eb5c Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 27 Dec 2019 12:56:03 -0500 Subject: [PATCH] panfrost: Remove mali_alt_func 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 --- src/gallium/drivers/panfrost/pan_context.c | 37 ++---------------- src/panfrost/Makefile.sources | 1 + src/panfrost/encoder/meson.build | 1 + src/panfrost/encoder/pan_encoder.h | 5 +++ src/panfrost/encoder/pan_sampler.c | 45 ++++++++++++++++++++++ src/panfrost/include/panfrost-job.h | 18 ++------- src/panfrost/pandecode/decode.c | 24 +----------- 7 files changed, 59 insertions(+), 72 deletions(-) create mode 100644 src/panfrost/encoder/pan_sampler.c diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 7421d54c42f..1446354ade0 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -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], diff --git a/src/panfrost/Makefile.sources b/src/panfrost/Makefile.sources index 5e9ad36b8b7..dbd4a8f58ff 100644 --- a/src/panfrost/Makefile.sources +++ b/src/panfrost/Makefile.sources @@ -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 diff --git a/src/panfrost/encoder/meson.build b/src/panfrost/encoder/meson.build index 35e6f2aacd5..e203e911de8 100644 --- a/src/panfrost/encoder/meson.build +++ b/src/panfrost/encoder/meson.build @@ -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', diff --git a/src/panfrost/encoder/pan_encoder.h b/src/panfrost/encoder/pan_encoder.h index 77f5b2ebb0f..2f3ab0d10a9 100644 --- a/src/panfrost/encoder/pan_encoder.h +++ b/src/panfrost/encoder/pan_encoder.h @@ -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 index 00000000000..63ddd17b816 --- /dev/null +++ b/src/panfrost/encoder/pan_sampler.c @@ -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; + } +} diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h index 6ec5a94199c..abdd804f1ce 100644 --- a/src/panfrost/include/panfrost-job.h +++ b/src/panfrost/include/panfrost-job.h @@ -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 */ diff --git a/src/panfrost/pandecode/decode.c b/src/panfrost/pandecode/decode.c index d88158a9312..126065c2b21 100644 --- a/src/panfrost/pandecode/decode.c +++ b/src/panfrost/pandecode/decode.c @@ -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"); -- 2.30.2