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