1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * © Copyright2018-2019 Alyssa Rosenzweig
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#ifndef PAN_RESOURCE_H
27bf215546Sopenharmony_ci#define PAN_RESOURCE_H
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "pan_screen.h"
30bf215546Sopenharmony_ci#include "pan_minmax_cache.h"
31bf215546Sopenharmony_ci#include "pan_texture.h"
32bf215546Sopenharmony_ci#include "drm-uapi/drm.h"
33bf215546Sopenharmony_ci#include "util/u_range.h"
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#define LAYOUT_CONVERT_THRESHOLD 8
36bf215546Sopenharmony_ci#define PAN_MAX_BATCHES 32
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci#define PAN_BIND_SHARED_MASK (PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_SCANOUT | \
39bf215546Sopenharmony_ci                              PIPE_BIND_SHARED)
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_cistruct panfrost_resource {
42bf215546Sopenharmony_ci        struct pipe_resource base;
43bf215546Sopenharmony_ci        struct {
44bf215546Sopenharmony_ci                struct pipe_scissor_state extent;
45bf215546Sopenharmony_ci                struct {
46bf215546Sopenharmony_ci                        bool enable;
47bf215546Sopenharmony_ci                        unsigned stride;
48bf215546Sopenharmony_ci                        unsigned size;
49bf215546Sopenharmony_ci                        BITSET_WORD *data;
50bf215546Sopenharmony_ci                } tile_map;
51bf215546Sopenharmony_ci        } damage;
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci        struct {
54bf215546Sopenharmony_ci                /** Number of batches accessing this resource. Used to check if
55bf215546Sopenharmony_ci                 * a resource is in use. */
56bf215546Sopenharmony_ci                _Atomic unsigned nr_users;
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci                /** Number of batches writing this resource. Note that only one
59bf215546Sopenharmony_ci                 * batch per context may write a resource, so this is the
60bf215546Sopenharmony_ci                 * number of contexts that have an active writer. */
61bf215546Sopenharmony_ci                _Atomic unsigned nr_writers;
62bf215546Sopenharmony_ci        } track;
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci        struct renderonly_scanout *scanout;
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci        struct panfrost_resource *separate_stencil;
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci        struct util_range valid_buffer_range;
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci        /* Description of the resource layout */
71bf215546Sopenharmony_ci        struct pan_image image;
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci        struct {
74bf215546Sopenharmony_ci                /* Is the checksum for this image valid? Implicitly refers to
75bf215546Sopenharmony_ci                 * the first slice; we only checksum non-mipmapped 2D images */
76bf215546Sopenharmony_ci                bool crc;
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci                /* Has anything been written to this slice? */
79bf215546Sopenharmony_ci                BITSET_DECLARE(data, MAX_MIP_LEVELS);
80bf215546Sopenharmony_ci        } valid;
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci        /* Whether the modifier can be changed */
83bf215546Sopenharmony_ci        bool modifier_constant;
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci        /* Used to decide when to convert to another modifier */
86bf215546Sopenharmony_ci        uint16_t modifier_updates;
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci        /* Do all pixels have the same stencil value? */
89bf215546Sopenharmony_ci        bool constant_stencil;
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci        /* The stencil value if constant_stencil is set */
92bf215546Sopenharmony_ci        uint8_t stencil_value;
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci        /* Cached min/max values for index buffers */
95bf215546Sopenharmony_ci        struct panfrost_minmax_cache *index_cache;
96bf215546Sopenharmony_ci};
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_cistatic inline struct panfrost_resource *
99bf215546Sopenharmony_cipan_resource(struct pipe_resource *p)
100bf215546Sopenharmony_ci{
101bf215546Sopenharmony_ci        return (struct panfrost_resource *)p;
102bf215546Sopenharmony_ci}
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_cistruct panfrost_transfer {
105bf215546Sopenharmony_ci        struct pipe_transfer base;
106bf215546Sopenharmony_ci        void *map;
107bf215546Sopenharmony_ci        struct {
108bf215546Sopenharmony_ci                struct pipe_resource *rsrc;
109bf215546Sopenharmony_ci                struct pipe_box box;
110bf215546Sopenharmony_ci        } staging;
111bf215546Sopenharmony_ci};
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_cistatic inline struct panfrost_transfer *
114bf215546Sopenharmony_cipan_transfer(struct pipe_transfer *p)
115bf215546Sopenharmony_ci{
116bf215546Sopenharmony_ci        return (struct panfrost_transfer *)p;
117bf215546Sopenharmony_ci}
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_civoid panfrost_resource_screen_init(struct pipe_screen *screen);
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_civoid panfrost_resource_screen_destroy(struct pipe_screen *screen);
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_civoid panfrost_resource_context_init(struct pipe_context *pctx);
124bf215546Sopenharmony_ci
125bf215546Sopenharmony_ci/* Blitting */
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_civoid
128bf215546Sopenharmony_cipanfrost_blitter_save(struct panfrost_context *ctx, bool render_cond);
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_civoid
131bf215546Sopenharmony_cipanfrost_blit(struct pipe_context *pipe,
132bf215546Sopenharmony_ci              const struct pipe_blit_info *info);
133bf215546Sopenharmony_ci
134bf215546Sopenharmony_civoid
135bf215546Sopenharmony_cipanfrost_resource_set_damage_region(struct pipe_screen *screen,
136bf215546Sopenharmony_ci                                    struct pipe_resource *res,
137bf215546Sopenharmony_ci                                    unsigned int nrects,
138bf215546Sopenharmony_ci                                    const struct pipe_box *rects);
139bf215546Sopenharmony_ci
140bf215546Sopenharmony_cistatic inline enum mali_texture_dimension
141bf215546Sopenharmony_cipanfrost_translate_texture_dimension(enum pipe_texture_target t) {
142bf215546Sopenharmony_ci        switch (t)
143bf215546Sopenharmony_ci        {
144bf215546Sopenharmony_ci        case PIPE_BUFFER:
145bf215546Sopenharmony_ci        case PIPE_TEXTURE_1D:
146bf215546Sopenharmony_ci        case PIPE_TEXTURE_1D_ARRAY:
147bf215546Sopenharmony_ci                return MALI_TEXTURE_DIMENSION_1D;
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_ci        case PIPE_TEXTURE_2D:
150bf215546Sopenharmony_ci        case PIPE_TEXTURE_2D_ARRAY:
151bf215546Sopenharmony_ci        case PIPE_TEXTURE_RECT:
152bf215546Sopenharmony_ci                return MALI_TEXTURE_DIMENSION_2D;
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_ci        case PIPE_TEXTURE_3D:
155bf215546Sopenharmony_ci                return MALI_TEXTURE_DIMENSION_3D;
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_ci        case PIPE_TEXTURE_CUBE:
158bf215546Sopenharmony_ci        case PIPE_TEXTURE_CUBE_ARRAY:
159bf215546Sopenharmony_ci                return MALI_TEXTURE_DIMENSION_CUBE;
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_ci        default:
162bf215546Sopenharmony_ci                unreachable("Unknown target");
163bf215546Sopenharmony_ci        }
164bf215546Sopenharmony_ci}
165bf215546Sopenharmony_ci
166bf215546Sopenharmony_civoid
167bf215546Sopenharmony_cipan_resource_modifier_convert(struct panfrost_context *ctx,
168bf215546Sopenharmony_ci                              struct panfrost_resource *rsrc,
169bf215546Sopenharmony_ci                              uint64_t modifier, const char *reason);
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_civoid
172bf215546Sopenharmony_cipan_legalize_afbc_format(struct panfrost_context *ctx,
173bf215546Sopenharmony_ci                         struct panfrost_resource *rsrc,
174bf215546Sopenharmony_ci                         enum pipe_format format);
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci#endif /* PAN_RESOURCE_H */
177