19f464c52Smaya/*
29f464c52Smaya * Copyright (C) 2019 Alyssa Rosenzweig
39f464c52Smaya * Copyright (C) 2014-2017 Broadcom
49f464c52Smaya *
59f464c52Smaya * Permission is hereby granted, free of charge, to any person obtaining a
69f464c52Smaya * copy of this software and associated documentation files (the "Software"),
79f464c52Smaya * to deal in the Software without restriction, including without limitation
89f464c52Smaya * the rights to use, copy, modify, merge, publish, distribute, sublicense,
99f464c52Smaya * and/or sell copies of the Software, and to permit persons to whom the
109f464c52Smaya * Software is furnished to do so, subject to the following conditions:
119f464c52Smaya *
129f464c52Smaya * The above copyright notice and this permission notice (including the next
139f464c52Smaya * paragraph) shall be included in all copies or substantial portions of the
149f464c52Smaya * Software.
159f464c52Smaya *
169f464c52Smaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
179f464c52Smaya * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
189f464c52Smaya * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
199f464c52Smaya * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
209f464c52Smaya * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
219f464c52Smaya * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
229f464c52Smaya * SOFTWARE.
239f464c52Smaya *
249f464c52Smaya */
259f464c52Smaya
269f464c52Smaya#ifndef __PAN_JOB_H__
279f464c52Smaya#define __PAN_JOB_H__
289f464c52Smaya
297ec681f3Smrg#include "util/u_dynarray.h"
307ec681f3Smrg#include "pipe/p_state.h"
317ec681f3Smrg#include "pan_cs.h"
327ec681f3Smrg#include "pan_mempool.h"
337ec681f3Smrg#include "pan_resource.h"
347ec681f3Smrg#include "pan_scoreboard.h"
357ec681f3Smrg
367ec681f3Smrg/* A panfrost_batch corresponds to a bound FBO we're rendering to,
379f464c52Smaya * collecting over multiple draws. */
389f464c52Smaya
397ec681f3Smrgstruct panfrost_batch {
409f464c52Smaya        struct panfrost_context *ctx;
417ec681f3Smrg        struct pipe_framebuffer_state key;
427ec681f3Smrg
437ec681f3Smrg        /* Sequence number used to implement LRU eviction when all batch slots are used */
447ec681f3Smrg        uint64_t seqnum;
459f464c52Smaya
469f464c52Smaya        /* Buffers cleared (PIPE_CLEAR_* bitmask) */
479f464c52Smaya        unsigned clear;
489f464c52Smaya
497ec681f3Smrg        /* Buffers drawn */
507ec681f3Smrg        unsigned draws;
517ec681f3Smrg
527ec681f3Smrg        /* Buffers read */
537ec681f3Smrg        unsigned read;
547ec681f3Smrg
557ec681f3Smrg        /* Buffers needing resolve to memory */
567ec681f3Smrg        unsigned resolve;
577ec681f3Smrg
587ec681f3Smrg        /* Packed clear values, indexed by both render target as well as word.
597ec681f3Smrg         * Essentially, a single pixel is packed, with some padding to bring it
607ec681f3Smrg         * up to a 32-bit interval; that pixel is then duplicated over to fill
617ec681f3Smrg         * all 16-bytes */
627ec681f3Smrg
637ec681f3Smrg        uint32_t clear_color[PIPE_MAX_COLOR_BUFS][4];
649f464c52Smaya        float clear_depth;
659f464c52Smaya        unsigned clear_stencil;
669f464c52Smaya
677ec681f3Smrg        /* Amount of thread local storage required per thread */
687ec681f3Smrg        unsigned stack_size;
697ec681f3Smrg
707ec681f3Smrg        /* Amount of shared memory needed per workgroup (for compute) */
717ec681f3Smrg        unsigned shared_size;
727ec681f3Smrg
737ec681f3Smrg        /* The bounding box covered by this job, taking scissors into account.
747ec681f3Smrg         * Basically, the bounding box we have to run fragment shaders for */
757ec681f3Smrg
767ec681f3Smrg        unsigned minx, miny;
777ec681f3Smrg        unsigned maxx, maxy;
787ec681f3Smrg
797ec681f3Smrg        /* Acts as a rasterizer discard */
807ec681f3Smrg        bool scissor_culls_everything;
817ec681f3Smrg
827ec681f3Smrg        /* BOs referenced not in the pool */
837ec681f3Smrg        int first_bo, last_bo;
847ec681f3Smrg        unsigned num_bos;
857ec681f3Smrg        struct util_sparse_array bos;
867ec681f3Smrg
877ec681f3Smrg        /* Pool owned by this batch (released when the batch is released) used for temporary descriptors */
887ec681f3Smrg        struct panfrost_pool pool;
897ec681f3Smrg
907ec681f3Smrg        /* Pool also owned by this batch that is not CPU mapped (created as
917ec681f3Smrg         * INVISIBLE) used for private GPU-internal structures, particularly
927ec681f3Smrg         * varyings */
937ec681f3Smrg        struct panfrost_pool invisible_pool;
947ec681f3Smrg
957ec681f3Smrg        /* Job scoreboarding state */
967ec681f3Smrg        struct pan_scoreboard scoreboard;
977ec681f3Smrg
987ec681f3Smrg        /* Polygon list bound to the batch, or NULL if none bound yet */
997ec681f3Smrg        struct panfrost_bo *polygon_list;
1009f464c52Smaya
1017ec681f3Smrg        /* Scratchpad BO bound to the batch, or NULL if none bound yet */
1027ec681f3Smrg        struct panfrost_bo *scratchpad;
1037ec681f3Smrg
1047ec681f3Smrg        /* Shared memory BO bound to the batch, or NULL if none bound yet */
1057ec681f3Smrg        struct panfrost_bo *shared_memory;
1067ec681f3Smrg
1077ec681f3Smrg        /* Framebuffer descriptor. */
1087ec681f3Smrg        struct panfrost_ptr framebuffer;
1097ec681f3Smrg
1107ec681f3Smrg        /* Thread local storage descriptor. */
1117ec681f3Smrg        struct panfrost_ptr tls;
1127ec681f3Smrg
1137ec681f3Smrg        /* Tiler context */
1147ec681f3Smrg        struct pan_tiler_context tiler_ctx;
1157ec681f3Smrg
1167ec681f3Smrg        /* Indirect draw data */
1177ec681f3Smrg        struct panfrost_ptr indirect_draw_ctx;
1187ec681f3Smrg        unsigned indirect_draw_job_id;
1197ec681f3Smrg
1207ec681f3Smrg        /* Keep the num_work_groups sysval around for indirect dispatch */
1217ec681f3Smrg        mali_ptr num_wg_sysval[3];
1227ec681f3Smrg
1237ec681f3Smrg        /* Cached descriptors */
1247ec681f3Smrg        mali_ptr viewport;
1257ec681f3Smrg        mali_ptr rsd[PIPE_SHADER_TYPES];
1267ec681f3Smrg        mali_ptr textures[PIPE_SHADER_TYPES];
1277ec681f3Smrg        mali_ptr samplers[PIPE_SHADER_TYPES];
1287ec681f3Smrg        mali_ptr attribs[PIPE_SHADER_TYPES];
1297ec681f3Smrg        mali_ptr attrib_bufs[PIPE_SHADER_TYPES];
1307ec681f3Smrg        mali_ptr uniform_buffers[PIPE_SHADER_TYPES];
1317ec681f3Smrg        mali_ptr push_uniforms[PIPE_SHADER_TYPES];
1327ec681f3Smrg
1337ec681f3Smrg        /* Referenced resources */
1347ec681f3Smrg        struct set *resources;
1359f464c52Smaya};
1369f464c52Smaya
1379f464c52Smaya/* Functions for managing the above */
1389f464c52Smaya
1397ec681f3Smrgstruct panfrost_batch *
1407ec681f3Smrgpanfrost_get_batch_for_fbo(struct panfrost_context *ctx);
1417ec681f3Smrg
1427ec681f3Smrgstruct panfrost_batch *
1437ec681f3Smrgpanfrost_get_fresh_batch_for_fbo(struct panfrost_context *ctx, const char *reason);
1449f464c52Smaya
1459f464c52Smayavoid
1467ec681f3Smrgpanfrost_batch_add_bo(struct panfrost_batch *batch,
1477ec681f3Smrg                      struct panfrost_bo *bo,
1487ec681f3Smrg                      enum pipe_shader_type stage);
1499f464c52Smaya
1507ec681f3Smrgvoid
1517ec681f3Smrgpanfrost_batch_read_rsrc(struct panfrost_batch *batch,
1527ec681f3Smrg                         struct panfrost_resource *rsrc,
1537ec681f3Smrg                         enum pipe_shader_type stage);
1547ec681f3Smrg
1557ec681f3Smrgvoid
1567ec681f3Smrgpanfrost_batch_write_rsrc(struct panfrost_batch *batch,
1577ec681f3Smrg                          struct panfrost_resource *rsrc,
1587ec681f3Smrg                          enum pipe_shader_type stage);
1599f464c52Smaya
1607ec681f3Smrgstruct panfrost_bo *
1617ec681f3Smrgpanfrost_batch_create_bo(struct panfrost_batch *batch, size_t size,
1627ec681f3Smrg                         uint32_t create_flags, uint32_t access_flags,
1637ec681f3Smrg                         const char *label);
1647ec681f3Smrg
1657ec681f3Smrgvoid
1667ec681f3Smrgpanfrost_flush_all_batches(struct panfrost_context *ctx, const char *reason);
1679f464c52Smaya
1689f464c52Smayavoid
1697ec681f3Smrgpanfrost_flush_batches_accessing_rsrc(struct panfrost_context *ctx,
1707ec681f3Smrg                                      struct panfrost_resource *rsrc,
1717ec681f3Smrg                                      const char *reason);
1729f464c52Smaya
1739f464c52Smayavoid
1747ec681f3Smrgpanfrost_flush_writer(struct panfrost_context *ctx,
1757ec681f3Smrg                      struct panfrost_resource *rsrc,
1767ec681f3Smrg                      const char *reason);
1777ec681f3Smrg
1787ec681f3Smrgvoid
1797ec681f3Smrgpanfrost_batch_adjust_stack_size(struct panfrost_batch *batch);
1807ec681f3Smrg
1817ec681f3Smrgstruct panfrost_bo *
1827ec681f3Smrgpanfrost_batch_get_scratchpad(struct panfrost_batch *batch, unsigned size, unsigned thread_tls_alloc, unsigned core_count);
1837ec681f3Smrg
1847ec681f3Smrgstruct panfrost_bo *
1857ec681f3Smrgpanfrost_batch_get_shared_memory(struct panfrost_batch *batch, unsigned size, unsigned workgroup_count);
1869f464c52Smaya
1879f464c52Smayavoid
1887ec681f3Smrgpanfrost_batch_clear(struct panfrost_batch *batch,
1897ec681f3Smrg                     unsigned buffers,
1907ec681f3Smrg                     const union pipe_color_union *color,
1917ec681f3Smrg                     double depth, unsigned stencil);
1929f464c52Smaya
1939f464c52Smayavoid
1947ec681f3Smrgpanfrost_batch_union_scissor(struct panfrost_batch *batch,
1957ec681f3Smrg                             unsigned minx, unsigned miny,
1967ec681f3Smrg                             unsigned maxx, unsigned maxy);
1979f464c52Smaya
1989f464c52Smaya#endif
199