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 * Number of times the resource has been written to.
105 *
106 * This is used to track whether we need to load the surface on first
107 * rendering.
108 */
109 uint64_t writes;
110
111 /**
112 * Bitmask of PIPE_CLEAR_COLOR0, PIPE_CLEAR_DEPTH, PIPE_CLEAR_STENCIL
113 * for which parts of the resource are defined.
114 *
115 * Used for avoiding fallback to quad clears for clearing just depth,
116 * when the stencil contents have never been initialized. Note that
117 * we're lazy and fields not present in the buffer (DEPTH in a color
118 * buffer) may get marked.
119 */
120 uint32_t initialized_buffers;
121
122 enum pipe_format internal_format;
123
124 /* Resource storing the S8 part of a Z32F_S8 resource, or NULL. */
125 struct v3d_resource *separate_stencil;
126 };
127
128 static inline struct v3d_resource *
v3d_resource(struct pipe_resource * prsc)129 v3d_resource(struct pipe_resource *prsc)
130 {
131 return (struct v3d_resource *)prsc;
132 }
133
134 static inline struct v3d_surface *
v3d_surface(struct pipe_surface * psurf)135 v3d_surface(struct pipe_surface *psurf)
136 {
137 return (struct v3d_surface *)psurf;
138 }
139
140 static inline struct v3d_transfer *
v3d_transfer(struct pipe_transfer * ptrans)141 v3d_transfer(struct pipe_transfer *ptrans)
142 {
143 return (struct v3d_transfer *)ptrans;
144 }
145
146 void v3d_resource_screen_init(struct pipe_screen *pscreen);
147 void v3d_resource_context_init(struct pipe_context *pctx);
148 struct pipe_resource *v3d_resource_create(struct pipe_screen *pscreen,
149 const struct pipe_resource *tmpl);
150 void v3d_update_shadow_texture(struct pipe_context *pctx,
151 struct pipe_sampler_view *view);
152 uint32_t v3d_layer_offset(struct pipe_resource *prsc, uint32_t level,
153 uint32_t layer);
154
155
156 #endif /* V3D_RESOURCE_H */
157