iris: Flag ALL_DIRTY_BINDINGS on aux state change.
[mesa.git] / src / gallium / drivers / iris / iris_resource.h
1 /*
2 * Copyright 2017 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #ifndef IRIS_RESOURCE_H
24 #define IRIS_RESOURCE_H
25
26 #include "pipe/p_state.h"
27 #include "util/u_inlines.h"
28 #include "intel/isl/isl.h"
29
30 struct iris_batch;
31 struct iris_context;
32
33 #define IRIS_MAX_MIPLEVELS 15
34
35 struct iris_format_info {
36 enum isl_format fmt;
37 struct isl_swizzle swizzle;
38 };
39
40 #define IRIS_RESOURCE_FLAG_SHADER_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
41 #define IRIS_RESOURCE_FLAG_SURFACE_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
42 #define IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 2)
43
44 enum gen9_astc5x5_wa_tex_type {
45 GEN9_ASTC5X5_WA_TEX_TYPE_ASTC5x5 = 1 << 0,
46 GEN9_ASTC5X5_WA_TEX_TYPE_AUX = 1 << 1,
47 };
48
49 /**
50 * Resources represent a GPU buffer object or image (mipmap tree).
51 *
52 * They contain the storage (BO) and layout information (ISL surface).
53 */
54 struct iris_resource {
55 struct pipe_resource base;
56 enum pipe_format internal_format;
57
58 /**
59 * The ISL surface layout information for this resource.
60 *
61 * This is not filled out for PIPE_BUFFER resources, but is guaranteed
62 * to be zeroed. Note that this also guarantees that res->surf.tiling
63 * will be ISL_TILING_LINEAR, so it's safe to check that.
64 */
65 struct isl_surf surf;
66
67 /** Backing storage for the resource */
68 struct iris_bo *bo;
69
70 /**
71 * A bitfield of PIPE_BIND_* indicating how this resource was bound
72 * in the past. Only meaningful for PIPE_BUFFER; used for flushing.
73 */
74 unsigned bind_history;
75
76 /**
77 * Auxiliary buffer information (CCS, MCS, or HiZ).
78 */
79 struct {
80 /** The surface layout for the auxiliary buffer. */
81 struct isl_surf surf;
82
83 /** The buffer object containing the auxiliary data. */
84 struct iris_bo *bo;
85
86 /** Offset into 'bo' where the auxiliary surface starts. */
87 uint32_t offset;
88
89 /**
90 * \brief The type of auxiliary compression used by this resource.
91 *
92 * This describes the type of auxiliary compression that is intended to
93 * be used by this resource. An aux usage of ISL_AUX_USAGE_NONE means
94 * that auxiliary compression is permanently disabled. An aux usage
95 * other than ISL_AUX_USAGE_NONE does not imply that auxiliary
96 * compression will always be enabled for this surface.
97 */
98 enum isl_aux_usage usage;
99
100 /**
101 * A bitfield of ISL_AUX_* modes that might this resource might use.
102 *
103 * For example, a surface might use both CCS_E and CCS_D at times.
104 */
105 unsigned possible_usages;
106
107 /**
108 * \brief Maps miptree slices to their current aux state.
109 *
110 * This two-dimensional array is indexed as [level][layer] and stores an
111 * aux state for each slice.
112 */
113 enum isl_aux_state **state;
114
115 /**
116 * If (1 << level) is set, HiZ is enabled for that miplevel.
117 */
118 uint16_t has_hiz;
119 } aux;
120
121 /**
122 * For external surfaces, this is DRM format modifier that was used to
123 * create or import the surface. For internal surfaces, this will always
124 * be DRM_FORMAT_MOD_INVALID.
125 */
126 const struct isl_drm_modifier_info *mod_info;
127 };
128
129 /**
130 * A simple <resource, offset> tuple for storing a reference to a
131 * piece of state stored in a GPU buffer object.
132 */
133 struct iris_state_ref {
134 struct pipe_resource *res;
135 uint32_t offset;
136 };
137
138 /**
139 * Gallium CSO for sampler views (texture views).
140 *
141 * In addition to the normal pipe_resource, this adds an ISL view
142 * which may reinterpret the format or restrict levels/layers.
143 *
144 * These can also be linear texture buffers.
145 */
146 struct iris_sampler_view {
147 struct pipe_sampler_view base;
148 struct isl_view view;
149
150 /* A short-cut (not a reference) to the actual resource being viewed.
151 * Multi-planar (or depth+stencil) images may have multiple resources
152 * chained together; this skips having to traverse base->texture->*.
153 */
154 struct iris_resource *res;
155
156 /** The resource (BO) holding our SURFACE_STATE. */
157 struct iris_state_ref surface_state;
158 };
159
160 /**
161 * Gallium CSO for surfaces (framebuffer attachments).
162 *
163 * A view of a surface that can be bound to a color render target or
164 * depth/stencil attachment.
165 */
166 struct iris_surface {
167 struct pipe_surface base;
168 struct isl_view view;
169
170 /** The resource (BO) holding our SURFACE_STATE. */
171 struct iris_state_ref surface_state;
172 };
173
174 /**
175 * Transfer object - information about a buffer mapping.
176 */
177 struct iris_transfer {
178 struct pipe_transfer base;
179 struct pipe_debug_callback *dbg;
180 void *buffer;
181 void *ptr;
182
183 void (*unmap)(struct iris_transfer *);
184 };
185
186 /**
187 * Unwrap a pipe_resource to get the underlying iris_bo (for convenience).
188 */
189 static inline struct iris_bo *
190 iris_resource_bo(struct pipe_resource *p_res)
191 {
192 struct iris_resource *res = (void *) p_res;
193 return res->bo;
194 }
195
196 struct iris_format_info iris_format_for_usage(const struct gen_device_info *,
197 enum pipe_format pf,
198 isl_surf_usage_flags_t usage);
199
200 struct pipe_resource *iris_resource_get_separate_stencil(struct pipe_resource *);
201
202 void iris_get_depth_stencil_resources(struct pipe_resource *res,
203 struct iris_resource **out_z,
204 struct iris_resource **out_s);
205
206 void iris_init_screen_resource_functions(struct pipe_screen *pscreen);
207
208 void iris_flush_and_dirty_for_history(struct iris_context *ice,
209 struct iris_batch *batch,
210 struct iris_resource *res);
211
212 unsigned iris_get_num_logical_layers(const struct iris_resource *res,
213 unsigned level);
214
215 void iris_resource_disable_aux(struct iris_resource *res);
216
217 #define INTEL_REMAINING_LAYERS UINT32_MAX
218 #define INTEL_REMAINING_LEVELS UINT32_MAX
219
220 /**
221 * Prepare a miptree for access
222 *
223 * This function should be called prior to any access to miptree in order to
224 * perform any needed resolves.
225 *
226 * \param[in] start_level The first mip level to be accessed
227 *
228 * \param[in] num_levels The number of miplevels to be accessed or
229 * INTEL_REMAINING_LEVELS to indicate every level
230 * above start_level will be accessed
231 *
232 * \param[in] start_layer The first array slice or 3D layer to be accessed
233 *
234 * \param[in] num_layers The number of array slices or 3D layers be
235 * accessed or INTEL_REMAINING_LAYERS to indicate
236 * every layer above start_layer will be accessed
237 *
238 * \param[in] aux_supported Whether or not the access will support the
239 * miptree's auxiliary compression format; this
240 * must be false for uncompressed miptrees
241 *
242 * \param[in] fast_clear_supported Whether or not the access will support
243 * fast clears in the miptree's auxiliary
244 * compression format
245 */
246 void
247 iris_resource_prepare_access(struct iris_context *ice,
248 struct iris_batch *batch,
249 struct iris_resource *res,
250 uint32_t start_level, uint32_t num_levels,
251 uint32_t start_layer, uint32_t num_layers,
252 enum isl_aux_usage aux_usage,
253 bool fast_clear_supported);
254
255 /**
256 * Complete a write operation
257 *
258 * This function should be called after any operation writes to a miptree.
259 * This will update the miptree's compression state so that future resolves
260 * happen correctly. Technically, this function can be called before the
261 * write occurs but the caller must ensure that they don't interlace
262 * iris_resource_prepare_access and iris_resource_finish_write calls to
263 * overlapping layer/level ranges.
264 *
265 * \param[in] level The mip level that was written
266 *
267 * \param[in] start_layer The first array slice or 3D layer written
268 *
269 * \param[in] num_layers The number of array slices or 3D layers
270 * written or INTEL_REMAINING_LAYERS to indicate
271 * every layer above start_layer was written
272 *
273 * \param[in] written_with_aux Whether or not the write was done with
274 * auxiliary compression enabled
275 */
276 void
277 iris_resource_finish_write(struct iris_context *ice,
278 struct iris_resource *res, uint32_t level,
279 uint32_t start_layer, uint32_t num_layers,
280 enum isl_aux_usage aux_usage);
281
282 /** Get the auxiliary compression state of a miptree slice */
283 enum isl_aux_state
284 iris_resource_get_aux_state(const struct iris_resource *res,
285 uint32_t level, uint32_t layer);
286
287 /**
288 * Set the auxiliary compression state of a miptree slice range
289 *
290 * This function directly sets the auxiliary compression state of a slice
291 * range of a miptree. It only modifies data structures and does not do any
292 * resolves. This should only be called by code which directly performs
293 * compression operations such as fast clears and resolves. Most code should
294 * use iris_resource_prepare_access or iris_resource_finish_write.
295 */
296 void
297 iris_resource_set_aux_state(struct iris_context *ice,
298 struct iris_resource *res, uint32_t level,
299 uint32_t start_layer, uint32_t num_layers,
300 enum isl_aux_state aux_state);
301
302 /**
303 * Prepare a miptree for raw access
304 *
305 * This helper prepares the miptree for access that knows nothing about any
306 * sort of compression whatsoever. This is useful when mapping the surface or
307 * using it with the blitter.
308 */
309 static inline void
310 iris_resource_access_raw(struct iris_context *ice,
311 struct iris_batch *batch,
312 struct iris_resource *res,
313 uint32_t level, uint32_t layer,
314 uint32_t num_layers,
315 bool write)
316 {
317 iris_resource_prepare_access(ice, batch, res, level, 1, layer, num_layers,
318 ISL_AUX_USAGE_NONE, false);
319 if (write) {
320 iris_resource_finish_write(ice, res, level, layer, num_layers,
321 ISL_AUX_USAGE_NONE);
322 }
323 }
324
325 enum isl_aux_usage iris_resource_texture_aux_usage(struct iris_context *ice,
326 const struct iris_resource *res,
327 enum isl_format view_fmt,
328 enum gen9_astc5x5_wa_tex_type);
329 void iris_resource_prepare_texture(struct iris_context *ice,
330 struct iris_batch *batch,
331 struct iris_resource *res,
332 enum isl_format view_format,
333 uint32_t start_level, uint32_t num_levels,
334 uint32_t start_layer, uint32_t num_layers,
335 enum gen9_astc5x5_wa_tex_type);
336 void iris_resource_prepare_image(struct iris_context *ice,
337 struct iris_batch *batch,
338 struct iris_resource *res);
339
340 void iris_resource_check_level_layer(const struct iris_resource *res,
341 uint32_t level, uint32_t layer);
342
343 bool iris_resource_level_has_hiz(const struct iris_resource *res,
344 uint32_t level);
345
346 enum isl_aux_usage iris_resource_render_aux_usage(struct iris_context *ice,
347 struct iris_resource *res,
348 enum isl_format render_fmt,
349 bool blend_enabled,
350 bool draw_aux_disabled);
351 void iris_resource_prepare_render(struct iris_context *ice,
352 struct iris_batch *batch,
353 struct iris_resource *res, uint32_t level,
354 uint32_t start_layer, uint32_t layer_count,
355 enum isl_aux_usage aux_usage);
356 void iris_resource_finish_render(struct iris_context *ice,
357 struct iris_resource *res, uint32_t level,
358 uint32_t start_layer, uint32_t layer_count,
359 enum isl_aux_usage aux_usage);
360 void iris_resource_prepare_depth(struct iris_context *ice,
361 struct iris_batch *batch,
362 struct iris_resource *res, uint32_t level,
363 uint32_t start_layer, uint32_t layer_count);
364 void iris_resource_finish_depth(struct iris_context *ice,
365 struct iris_resource *res, uint32_t level,
366 uint32_t start_layer, uint32_t layer_count,
367 bool depth_written);
368 #endif