1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2014-2017 Broadcom
3bf215546Sopenharmony_ci * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
4bf215546Sopenharmony_ci *
5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
14bf215546Sopenharmony_ci * Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22bf215546Sopenharmony_ci * IN THE SOFTWARE.
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci#ifndef V3D_RESOURCE_H
26bf215546Sopenharmony_ci#define V3D_RESOURCE_H
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include "v3d_screen.h"
29bf215546Sopenharmony_ci#include "util/u_transfer.h"
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "broadcom/common/v3d_tiling.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_cistruct v3d_transfer {
34bf215546Sopenharmony_ci        struct pipe_transfer base;
35bf215546Sopenharmony_ci        void *map;
36bf215546Sopenharmony_ci};
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_cistruct v3d_resource_slice {
39bf215546Sopenharmony_ci        uint32_t offset;
40bf215546Sopenharmony_ci        uint32_t stride;
41bf215546Sopenharmony_ci        uint32_t padded_height;
42bf215546Sopenharmony_ci        /* Size of a single pane of the slice.  For 3D textures, there will be
43bf215546Sopenharmony_ci         * a number of panes equal to the minified, power-of-two-aligned
44bf215546Sopenharmony_ci         * depth.
45bf215546Sopenharmony_ci         */
46bf215546Sopenharmony_ci        uint32_t size;
47bf215546Sopenharmony_ci        uint8_t ub_pad;
48bf215546Sopenharmony_ci        enum v3d_tiling_mode tiling;
49bf215546Sopenharmony_ci};
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_cistruct v3d_surface {
52bf215546Sopenharmony_ci        struct pipe_surface base;
53bf215546Sopenharmony_ci        uint32_t offset;
54bf215546Sopenharmony_ci        enum v3d_tiling_mode tiling;
55bf215546Sopenharmony_ci        /**
56bf215546Sopenharmony_ci         * Output image format for TILE_RENDERING_MODE_CONFIGURATION
57bf215546Sopenharmony_ci         */
58bf215546Sopenharmony_ci        uint8_t format;
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci        /**
61bf215546Sopenharmony_ci         * Internal format of the tile buffer for
62bf215546Sopenharmony_ci         * TILE_RENDERING_MODE_CONFIGURATION.
63bf215546Sopenharmony_ci         */
64bf215546Sopenharmony_ci        uint8_t internal_type;
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci        /**
67bf215546Sopenharmony_ci         * internal bpp value (0=32bpp, 2=128bpp) for color buffers in
68bf215546Sopenharmony_ci         * TILE_RENDERING_MODE_CONFIGURATION.
69bf215546Sopenharmony_ci         */
70bf215546Sopenharmony_ci        uint8_t internal_bpp;
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci        /**
73bf215546Sopenharmony_ci         * If the R and B channels should be swapped.  On V3D 3.x, we do it in
74bf215546Sopenharmony_ci         * the shader and the blend equation.  On V3D 4.1+, we can use the new
75bf215546Sopenharmony_ci         * TLB load/store flags instead of recompiling.
76bf215546Sopenharmony_ci         */
77bf215546Sopenharmony_ci        bool swap_rb;
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci        uint32_t padded_height_of_output_image_in_uif_blocks;
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci        /* If the resource being referenced is separate stencil, then this is
82bf215546Sopenharmony_ci         * the surface to use when reading/writing stencil.
83bf215546Sopenharmony_ci         */
84bf215546Sopenharmony_ci        struct pipe_surface *separate_stencil;
85bf215546Sopenharmony_ci};
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_cistruct v3d_resource {
88bf215546Sopenharmony_ci        struct pipe_resource base;
89bf215546Sopenharmony_ci        struct v3d_bo *bo;
90bf215546Sopenharmony_ci        struct renderonly_scanout *scanout;
91bf215546Sopenharmony_ci        struct v3d_resource_slice slices[V3D_MAX_MIP_LEVELS];
92bf215546Sopenharmony_ci        uint32_t cube_map_stride;
93bf215546Sopenharmony_ci        uint32_t sand_col128_stride;
94bf215546Sopenharmony_ci        uint32_t size;
95bf215546Sopenharmony_ci        int cpp;
96bf215546Sopenharmony_ci        bool tiled;
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci        /**
99bf215546Sopenharmony_ci         * Indicates if the CS has written the resource
100bf215546Sopenharmony_ci         */
101bf215546Sopenharmony_ci        bool compute_written;
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci        /**
104bf215546Sopenharmony_ci         * Number of times the resource has been written to.
105bf215546Sopenharmony_ci         *
106bf215546Sopenharmony_ci         * This is used to track whether we need to load the surface on first
107bf215546Sopenharmony_ci         * rendering.
108bf215546Sopenharmony_ci         */
109bf215546Sopenharmony_ci        uint64_t writes;
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci        /**
112bf215546Sopenharmony_ci         * Bitmask of PIPE_CLEAR_COLOR0, PIPE_CLEAR_DEPTH, PIPE_CLEAR_STENCIL
113bf215546Sopenharmony_ci         * for which parts of the resource are defined.
114bf215546Sopenharmony_ci         *
115bf215546Sopenharmony_ci         * Used for avoiding fallback to quad clears for clearing just depth,
116bf215546Sopenharmony_ci         * when the stencil contents have never been initialized.  Note that
117bf215546Sopenharmony_ci         * we're lazy and fields not present in the buffer (DEPTH in a color
118bf215546Sopenharmony_ci         * buffer) may get marked.
119bf215546Sopenharmony_ci         */
120bf215546Sopenharmony_ci        uint32_t initialized_buffers;
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci        /**
123bf215546Sopenharmony_ci         * A serial ID that is incremented every time a new BO is bound to a
124bf215546Sopenharmony_ci         * resource. We use this to track scenarios where we might need to
125bf215546Sopenharmony_ci         * update other resources to point to the new BO (like sampler states
126bf215546Sopenharmony_ci         * when a texture BO changes).
127bf215546Sopenharmony_ci         */
128bf215546Sopenharmony_ci        uint32_t serial_id;
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ci        enum pipe_format internal_format;
131bf215546Sopenharmony_ci
132bf215546Sopenharmony_ci        /* Resource storing the S8 part of a Z32F_S8 resource, or NULL. */
133bf215546Sopenharmony_ci        struct v3d_resource *separate_stencil;
134bf215546Sopenharmony_ci};
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_cistatic inline struct v3d_resource *
137bf215546Sopenharmony_civ3d_resource(struct pipe_resource *prsc)
138bf215546Sopenharmony_ci{
139bf215546Sopenharmony_ci        return (struct v3d_resource *)prsc;
140bf215546Sopenharmony_ci}
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_cistatic inline struct v3d_surface *
143bf215546Sopenharmony_civ3d_surface(struct pipe_surface *psurf)
144bf215546Sopenharmony_ci{
145bf215546Sopenharmony_ci        return (struct v3d_surface *)psurf;
146bf215546Sopenharmony_ci}
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_cistatic inline struct v3d_transfer *
149bf215546Sopenharmony_civ3d_transfer(struct pipe_transfer *ptrans)
150bf215546Sopenharmony_ci{
151bf215546Sopenharmony_ci        return (struct v3d_transfer *)ptrans;
152bf215546Sopenharmony_ci}
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_civoid v3d_resource_screen_init(struct pipe_screen *pscreen);
155bf215546Sopenharmony_civoid v3d_resource_context_init(struct pipe_context *pctx);
156bf215546Sopenharmony_cistruct pipe_resource *v3d_resource_create(struct pipe_screen *pscreen,
157bf215546Sopenharmony_ci                                          const struct pipe_resource *tmpl);
158bf215546Sopenharmony_civoid v3d_update_shadow_texture(struct pipe_context *pctx,
159bf215546Sopenharmony_ci                               struct pipe_sampler_view *view);
160bf215546Sopenharmony_ciuint32_t v3d_layer_offset(struct pipe_resource *prsc, uint32_t level,
161bf215546Sopenharmony_ci                          uint32_t layer);
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_ci
164bf215546Sopenharmony_ci#endif /* V3D_RESOURCE_H */
165