panfrost: Add a panfrost_sampler_desc_init() helper
authorBoris Brezillon <boris.brezillon@collabora.com>
Thu, 5 Mar 2020 15:26:56 +0000 (16:26 +0100)
committerBoris Brezillon <boris.brezillon@collabora.com>
Tue, 10 Mar 2020 11:47:34 +0000 (12:47 +0100)
It just makes sense to group all HW descriptor initilization logic in
pan_cmdstream.c, so let's move this code out of
panfrost_create_sampler_state().

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4083>

src/gallium/drivers/panfrost/pan_cmdstream.c
src/gallium/drivers/panfrost/pan_cmdstream.h
src/gallium/drivers/panfrost/pan_context.c

index ddef5c107649146fc3e2a335e9aa6fa01ffa38b7..8d9f35539538221737698c0f233ac7dd14a53e1c 100644 (file)
@@ -120,7 +120,7 @@ panfrost_shader_meta_init(struct panfrost_context *ctx,
         meta->midgard1.uniform_buffer_count = panfrost_ubo_count(ctx, st);
 }
 
-unsigned
+static unsigned
 panfrost_translate_compare_func(enum pipe_compare_func in)
 {
         switch (in) {
@@ -186,6 +186,80 @@ panfrost_translate_stencil_op(enum pipe_stencil_op in)
         }
 }
 
+static unsigned
+translate_tex_wrap(enum pipe_tex_wrap w)
+{
+        switch (w) {
+        case PIPE_TEX_WRAP_REPEAT:
+                return MALI_WRAP_REPEAT;
+
+        case PIPE_TEX_WRAP_CLAMP:
+                return MALI_WRAP_CLAMP;
+
+        case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
+                return MALI_WRAP_CLAMP_TO_EDGE;
+
+        case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
+                return MALI_WRAP_CLAMP_TO_BORDER;
+
+        case PIPE_TEX_WRAP_MIRROR_REPEAT:
+                return MALI_WRAP_MIRRORED_REPEAT;
+
+        case PIPE_TEX_WRAP_MIRROR_CLAMP:
+                return MALI_WRAP_MIRRORED_CLAMP;
+
+        case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
+                return MALI_WRAP_MIRRORED_CLAMP_TO_EDGE;
+
+        case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
+                return MALI_WRAP_MIRRORED_CLAMP_TO_BORDER;
+
+        default:
+                unreachable("Invalid wrap");
+        }
+}
+
+void panfrost_sampler_desc_init(const struct pipe_sampler_state *cso,
+                                struct mali_sampler_descriptor *hw)
+{
+        unsigned func = panfrost_translate_compare_func(cso->compare_func);
+        bool min_nearest = cso->min_img_filter == PIPE_TEX_FILTER_NEAREST;
+        bool mag_nearest = cso->mag_img_filter == PIPE_TEX_FILTER_NEAREST;
+        bool mip_linear  = cso->min_mip_filter == PIPE_TEX_MIPFILTER_LINEAR;
+        unsigned min_filter = min_nearest ? MALI_SAMP_MIN_NEAREST : 0;
+        unsigned mag_filter = mag_nearest ? MALI_SAMP_MAG_NEAREST : 0;
+        unsigned mip_filter = mip_linear  ?
+                              (MALI_SAMP_MIP_LINEAR_1 | MALI_SAMP_MIP_LINEAR_2) : 0;
+        unsigned normalized = cso->normalized_coords ? MALI_SAMP_NORM_COORDS : 0;
+
+        *hw = (struct mali_sampler_descriptor) {
+                .filter_mode = min_filter | mag_filter | mip_filter |
+                               normalized,
+                .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_flip_compare_func(func),
+                .border_color = {
+                        cso->border_color.f[0],
+                        cso->border_color.f[1],
+                        cso->border_color.f[2],
+                        cso->border_color.f[3]
+                },
+                .min_lod = FIXED_16(cso->min_lod, false), /* clamp at 0 */
+                .max_lod = FIXED_16(cso->max_lod, false),
+                .lod_bias = FIXED_16(cso->lod_bias, true), /* can be negative */
+                .seamless_cube_map = cso->seamless_cube_map,
+        };
+
+        /* If necessary, we disable mipmapping in the sampler descriptor by
+         * clamping the LOD as tight as possible (from 0 to epsilon,
+         * essentially -- remember these are fixed point numbers, so
+         * epsilon=1/256) */
+
+        if (cso->min_mip_filter == PIPE_TEX_MIPFILTER_NONE)
+                hw->max_lod = hw->min_lod + 1;
+}
+
 static void
 panfrost_make_stencil_state(const struct pipe_stencil_state *in,
                             struct mali_stencil_test *out)
index f16e1bba9ae8c017556318960b5425881af08238..b493f91fa27107b539f21e66344b7eec5f11da6c 100644 (file)
@@ -32,8 +32,8 @@
 
 #include "pan_job.h"
 
-unsigned
-panfrost_translate_compare_func(enum pipe_compare_func in);
+void panfrost_sampler_desc_init(const struct pipe_sampler_state *cso,
+                                struct mali_sampler_descriptor *hw);
 
 void
 panfrost_vt_attach_framebuffer(struct panfrost_context *ctx,
index 0f4bca74066d1fd3e86a90c10f26afab7e723c96..05a821807b34b4dac4bd855514b344bc4de56786 100644 (file)
@@ -174,39 +174,6 @@ panfrost_emit_vertex_payload(struct panfrost_context *ctx)
         memcpy(&ctx->payloads[PIPE_SHADER_COMPUTE], &payload, sizeof(payload));
 }
 
-static unsigned
-translate_tex_wrap(enum pipe_tex_wrap w)
-{
-        switch (w) {
-        case PIPE_TEX_WRAP_REPEAT:
-                return MALI_WRAP_REPEAT;
-
-        case PIPE_TEX_WRAP_CLAMP:
-                return MALI_WRAP_CLAMP;
-
-        case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
-                return MALI_WRAP_CLAMP_TO_EDGE;
-
-        case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
-                return MALI_WRAP_CLAMP_TO_BORDER;
-
-        case PIPE_TEX_WRAP_MIRROR_REPEAT:
-                return MALI_WRAP_MIRRORED_REPEAT;
-
-        case PIPE_TEX_WRAP_MIRROR_CLAMP:
-                return MALI_WRAP_MIRRORED_CLAMP;
-
-        case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
-                return MALI_WRAP_MIRRORED_CLAMP_TO_EDGE;
-
-        case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
-                return MALI_WRAP_MIRRORED_CLAMP_TO_BORDER;
-
-        default:
-                unreachable("Invalid wrap");
-        }
-}
-
 bool
 panfrost_writes_point_size(struct panfrost_context *ctx)
 {
@@ -925,56 +892,7 @@ panfrost_create_sampler_state(
         struct panfrost_sampler_state *so = CALLOC_STRUCT(panfrost_sampler_state);
         so->base = *cso;
 
-        /* sampler_state corresponds to mali_sampler_descriptor, which we can generate entirely here */
-
-        bool min_nearest = cso->min_img_filter == PIPE_TEX_FILTER_NEAREST;
-        bool mag_nearest = cso->mag_img_filter == PIPE_TEX_FILTER_NEAREST;
-        bool mip_linear  = cso->min_mip_filter == PIPE_TEX_MIPFILTER_LINEAR;
-
-        unsigned min_filter = min_nearest ? MALI_SAMP_MIN_NEAREST : 0;
-        unsigned mag_filter = mag_nearest ? MALI_SAMP_MAG_NEAREST : 0;
-        unsigned mip_filter = mip_linear  ?
-                (MALI_SAMP_MIP_LINEAR_1 | MALI_SAMP_MIP_LINEAR_2) : 0;
-        unsigned normalized = cso->normalized_coords ? MALI_SAMP_NORM_COORDS : 0;
-
-        struct mali_sampler_descriptor sampler_descriptor = {
-                .filter_mode = min_filter | mag_filter | mip_filter | normalized,
-                .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_flip_compare_func(
-                                panfrost_translate_compare_func(
-                                        cso->compare_func)),
-                .border_color = {
-                        cso->border_color.f[0],
-                        cso->border_color.f[1],
-                        cso->border_color.f[2],
-                        cso->border_color.f[3]
-                },
-                .min_lod = FIXED_16(cso->min_lod, false), /* clamp at 0 */
-                .max_lod = FIXED_16(cso->max_lod, false),
-                .lod_bias = FIXED_16(cso->lod_bias, true), /* can be negative */
-                .seamless_cube_map = cso->seamless_cube_map,
-        };
-
-        /* If necessary, we disable mipmapping in the sampler descriptor by
-         * clamping the LOD as tight as possible (from 0 to epsilon,
-         * essentially -- remember these are fixed point numbers, so
-         * epsilon=1/256) */
-
-        if (cso->min_mip_filter == PIPE_TEX_MIPFILTER_NONE) {
-                sampler_descriptor.max_lod = sampler_descriptor.min_lod;
-
-                /* Enforce that there is something in the middle by adding epsilon*/
-
-                if (sampler_descriptor.min_lod == sampler_descriptor.max_lod)
-                        sampler_descriptor.max_lod++;
-
-                /* Sanity check */
-                assert(sampler_descriptor.max_lod > sampler_descriptor.min_lod);
-        }
-
-        so->hw = sampler_descriptor;
+        panfrost_sampler_desc_init(cso, &so->hw);
 
         return so;
 }