17ec681f3Smrg/*
27ec681f3Smrg * Copyright (C) 2021 Collabora, Ltd.
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg * Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
207ec681f3Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
217ec681f3Smrg * SOFTWARE.
227ec681f3Smrg *
237ec681f3Smrg * Authors:
247ec681f3Smrg *   Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
257ec681f3Smrg *   Boris Brezillon <boris.brezillon@collabora.com>
267ec681f3Smrg */
277ec681f3Smrg
287ec681f3Smrg#ifndef __PAN_CS_H
297ec681f3Smrg#define __PAN_CS_H
307ec681f3Smrg
317ec681f3Smrg#include "genxml/gen_macros.h"
327ec681f3Smrg
337ec681f3Smrg#include "pan_texture.h"
347ec681f3Smrg
357ec681f3Smrgstruct pan_compute_dim {
367ec681f3Smrg        uint32_t x, y, z;
377ec681f3Smrg};
387ec681f3Smrg
397ec681f3Smrgstruct pan_fb_color_attachment {
407ec681f3Smrg        const struct pan_image_view *view;
417ec681f3Smrg        bool *crc_valid;
427ec681f3Smrg        bool clear;
437ec681f3Smrg        bool preload;
447ec681f3Smrg        bool discard;
457ec681f3Smrg        uint32_t clear_value[4];
467ec681f3Smrg};
477ec681f3Smrg
487ec681f3Smrgstruct pan_fb_zs_attachment {
497ec681f3Smrg        struct {
507ec681f3Smrg                const struct pan_image_view *zs, *s;
517ec681f3Smrg        } view;
527ec681f3Smrg
537ec681f3Smrg        struct {
547ec681f3Smrg                bool z, s;
557ec681f3Smrg        } clear;
567ec681f3Smrg
577ec681f3Smrg        struct {
587ec681f3Smrg                bool z, s;
597ec681f3Smrg        } discard;
607ec681f3Smrg
617ec681f3Smrg        struct {
627ec681f3Smrg                bool z, s;
637ec681f3Smrg        } preload;
647ec681f3Smrg
657ec681f3Smrg        struct {
667ec681f3Smrg                float depth;
677ec681f3Smrg                uint8_t stencil;
687ec681f3Smrg        } clear_value;
697ec681f3Smrg};
707ec681f3Smrg
717ec681f3Smrgstruct pan_tiler_context {
727ec681f3Smrg        union {
737ec681f3Smrg                mali_ptr bifrost;
747ec681f3Smrg                struct {
757ec681f3Smrg                        bool disable;
767ec681f3Smrg                        struct panfrost_bo *polygon_list;
777ec681f3Smrg                } midgard;
787ec681f3Smrg        };
797ec681f3Smrg};
807ec681f3Smrg
817ec681f3Smrgstruct pan_tls_info {
827ec681f3Smrg        struct {
837ec681f3Smrg                mali_ptr ptr;
847ec681f3Smrg                unsigned size;
857ec681f3Smrg        } tls;
867ec681f3Smrg
877ec681f3Smrg        struct {
887ec681f3Smrg                struct pan_compute_dim dim;
897ec681f3Smrg                mali_ptr ptr;
907ec681f3Smrg                unsigned size;
917ec681f3Smrg        } wls;
927ec681f3Smrg};
937ec681f3Smrg
947ec681f3Smrgstruct pan_fb_bifrost_info {
957ec681f3Smrg        struct {
967ec681f3Smrg                struct panfrost_ptr dcds;
977ec681f3Smrg                unsigned modes[3];
987ec681f3Smrg        } pre_post;
997ec681f3Smrg};
1007ec681f3Smrg
1017ec681f3Smrgstruct pan_fb_info {
1027ec681f3Smrg        unsigned width, height;
1037ec681f3Smrg        struct {
1047ec681f3Smrg                /* Max values are inclusive */
1057ec681f3Smrg                unsigned minx, miny, maxx, maxy;
1067ec681f3Smrg        } extent;
1077ec681f3Smrg        unsigned nr_samples;
1087ec681f3Smrg        unsigned rt_count;
1097ec681f3Smrg        struct pan_fb_color_attachment rts[8];
1107ec681f3Smrg        struct pan_fb_zs_attachment zs;
1117ec681f3Smrg
1127ec681f3Smrg        struct {
1137ec681f3Smrg                unsigned stride;
1147ec681f3Smrg                mali_ptr base;
1157ec681f3Smrg        } tile_map;
1167ec681f3Smrg
1177ec681f3Smrg        union {
1187ec681f3Smrg                struct pan_fb_bifrost_info bifrost;
1197ec681f3Smrg        };
1207ec681f3Smrg};
1217ec681f3Smrg
1227ec681f3Smrgstatic inline unsigned
1237ec681f3Smrgpan_wls_instances(const struct pan_compute_dim *dim)
1247ec681f3Smrg{
1257ec681f3Smrg        return util_next_power_of_two(dim->x) *
1267ec681f3Smrg               util_next_power_of_two(dim->y) *
1277ec681f3Smrg               util_next_power_of_two(dim->z);
1287ec681f3Smrg}
1297ec681f3Smrg
1307ec681f3Smrgstatic inline unsigned
1317ec681f3Smrgpan_wls_adjust_size(unsigned wls_size)
1327ec681f3Smrg{
1337ec681f3Smrg        return util_next_power_of_two(MAX2(wls_size, 128));
1347ec681f3Smrg}
1357ec681f3Smrg
1367ec681f3Smrgstatic inline unsigned
1377ec681f3Smrgpan_wls_mem_size(const struct panfrost_device *dev,
1387ec681f3Smrg                 const struct pan_compute_dim *dim,
1397ec681f3Smrg                 unsigned wls_size)
1407ec681f3Smrg{
1417ec681f3Smrg        unsigned instances = pan_wls_instances(dim);
1427ec681f3Smrg
1437ec681f3Smrg        return pan_wls_adjust_size(wls_size) * instances * dev->core_count;
1447ec681f3Smrg}
1457ec681f3Smrg
1467ec681f3Smrg#ifdef PAN_ARCH
1477ec681f3Smrgvoid
1487ec681f3SmrgGENX(pan_emit_tls)(const struct pan_tls_info *info,
1497ec681f3Smrg                   void *out);
1507ec681f3Smrg
1517ec681f3Smrgint
1527ec681f3SmrgGENX(pan_select_crc_rt)(const struct pan_fb_info *fb);
1537ec681f3Smrg
1547ec681f3Smrgstatic inline bool
1557ec681f3Smrgpan_fbd_has_zs_crc_ext(const struct pan_fb_info *fb)
1567ec681f3Smrg{
1577ec681f3Smrg        return PAN_ARCH >= 5 &&
1587ec681f3Smrg               (fb->zs.view.zs || fb->zs.view.s ||
1597ec681f3Smrg                GENX(pan_select_crc_rt)(fb) >= 0);
1607ec681f3Smrg}
1617ec681f3Smrg
1627ec681f3Smrgunsigned
1637ec681f3SmrgGENX(pan_emit_fbd)(const struct panfrost_device *dev,
1647ec681f3Smrg                   const struct pan_fb_info *fb,
1657ec681f3Smrg                   const struct pan_tls_info *tls,
1667ec681f3Smrg                   const struct pan_tiler_context *tiler_ctx,
1677ec681f3Smrg                   void *out);
1687ec681f3Smrg
1697ec681f3Smrg#if PAN_ARCH >= 6
1707ec681f3Smrgvoid
1717ec681f3SmrgGENX(pan_emit_tiler_heap)(const struct panfrost_device *dev,
1727ec681f3Smrg                          void *out);
1737ec681f3Smrg
1747ec681f3Smrgvoid
1757ec681f3SmrgGENX(pan_emit_tiler_ctx)(const struct panfrost_device *dev,
1767ec681f3Smrg                         unsigned fb_width, unsigned fb_height,
1777ec681f3Smrg                         unsigned nr_samples,
1787ec681f3Smrg                         mali_ptr heap,
1797ec681f3Smrg                         void *out);
1807ec681f3Smrg#endif
1817ec681f3Smrg
1827ec681f3Smrgvoid
1837ec681f3SmrgGENX(pan_emit_fragment_job)(const struct pan_fb_info *fb,
1847ec681f3Smrg                            mali_ptr fbd,
1857ec681f3Smrg                            void *out);
1867ec681f3Smrg#endif /* ifdef PAN_ARCH */
1877ec681f3Smrg
1887ec681f3Smrg#endif
189