Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/iris/iris_resource.h
4565 views
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 "util/u_range.h"
29
#include "util/u_threaded_context.h"
30
#include "intel/isl/isl.h"
31
#include "iris_bufmgr.h"
32
33
struct iris_batch;
34
struct iris_context;
35
struct shader_info;
36
37
#define IRIS_MAX_MIPLEVELS 15
38
39
struct iris_format_info {
40
enum isl_format fmt;
41
struct isl_swizzle swizzle;
42
};
43
44
#define IRIS_RESOURCE_FLAG_SHADER_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
45
#define IRIS_RESOURCE_FLAG_SURFACE_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
46
#define IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 2)
47
#define IRIS_RESOURCE_FLAG_BINDLESS_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 3)
48
#define IRIS_RESOURCE_FLAG_DEVICE_MEM (PIPE_RESOURCE_FLAG_DRV_PRIV << 4)
49
50
/**
51
* Resources represent a GPU buffer object or image (mipmap tree).
52
*
53
* They contain the storage (BO) and layout information (ISL surface).
54
*/
55
struct iris_resource {
56
struct threaded_resource base;
57
enum pipe_format internal_format;
58
59
/**
60
* The ISL surface layout information for this resource.
61
*
62
* This is not filled out for PIPE_BUFFER resources, but is guaranteed
63
* to be zeroed. Note that this also guarantees that res->surf.tiling
64
* will be ISL_TILING_LINEAR, so it's safe to check that.
65
*/
66
struct isl_surf surf;
67
68
/** Backing storage for the resource */
69
struct iris_bo *bo;
70
71
/** offset at which data starts in the BO */
72
uint64_t offset;
73
74
/**
75
* A bitfield of PIPE_BIND_* indicating how this resource was bound
76
* in the past. Only meaningful for PIPE_BUFFER; used for flushing.
77
*/
78
unsigned bind_history;
79
80
/**
81
* A bitfield of MESA_SHADER_* stages indicating where this resource
82
* was bound.
83
*/
84
unsigned bind_stages;
85
86
/**
87
* For PIPE_BUFFER resources, a range which may contain valid data.
88
*
89
* This is a conservative estimate of what part of the buffer contains
90
* valid data that we have to preserve. The rest of the buffer is
91
* considered invalid, and we can promote writes to that region to
92
* be unsynchronized writes, avoiding blit copies.
93
*/
94
struct util_range valid_buffer_range;
95
96
/**
97
* Auxiliary buffer information (CCS, MCS, or HiZ).
98
*/
99
struct {
100
/** The surface layout for the auxiliary buffer. */
101
struct isl_surf surf;
102
103
/** The buffer object containing the auxiliary data. */
104
struct iris_bo *bo;
105
106
/** Offset into 'bo' where the auxiliary surface starts. */
107
uint32_t offset;
108
109
struct {
110
struct isl_surf surf;
111
112
/** Offset into 'bo' where the auxiliary surface starts. */
113
uint32_t offset;
114
} extra_aux;
115
116
/**
117
* Fast clear color for this surface. For depth surfaces, the clear
118
* value is stored as a float32 in the red component.
119
*/
120
union isl_color_value clear_color;
121
122
/** Buffer object containing the indirect clear color. */
123
struct iris_bo *clear_color_bo;
124
125
/** Offset into bo where the clear color can be found. */
126
uint64_t clear_color_offset;
127
128
/**
129
* \brief The type of auxiliary compression used by this resource.
130
*
131
* This describes the type of auxiliary compression that is intended to
132
* be used by this resource. An aux usage of ISL_AUX_USAGE_NONE means
133
* that auxiliary compression is permanently disabled. An aux usage
134
* other than ISL_AUX_USAGE_NONE does not imply that auxiliary
135
* compression will always be enabled for this surface.
136
*/
137
enum isl_aux_usage usage;
138
139
/**
140
* A bitfield of ISL_AUX_* modes that might this resource might use.
141
*
142
* For example, a surface might use both CCS_E and CCS_D at times.
143
*/
144
unsigned possible_usages;
145
146
/**
147
* Same as possible_usages, but only with modes supported for sampling.
148
*/
149
unsigned sampler_usages;
150
151
/**
152
* \brief Maps miptree slices to their current aux state.
153
*
154
* This two-dimensional array is indexed as [level][layer] and stores an
155
* aux state for each slice.
156
*/
157
enum isl_aux_state **state;
158
} aux;
159
160
/**
161
* For external surfaces, this is format that was used to create or import
162
* the surface. For internal surfaces, this will always be
163
* PIPE_FORMAT_NONE.
164
*/
165
enum pipe_format external_format;
166
167
/**
168
* For external surfaces, this is DRM format modifier that was used to
169
* create or import the surface. For internal surfaces, this will always
170
* be DRM_FORMAT_MOD_INVALID.
171
*/
172
const struct isl_drm_modifier_info *mod_info;
173
174
/**
175
* The screen the resource was originally created with, stored for refcounting.
176
*/
177
struct pipe_screen *orig_screen;
178
};
179
180
/**
181
* A simple <resource, offset> tuple for storing a reference to a
182
* piece of state stored in a GPU buffer object.
183
*/
184
struct iris_state_ref {
185
struct pipe_resource *res;
186
uint32_t offset;
187
};
188
189
/**
190
* The SURFACE_STATE descriptors for a resource.
191
*/
192
struct iris_surface_state {
193
/**
194
* CPU-side copy of the packed SURFACE_STATE structures, already
195
* aligned so they can be uploaded as a contiguous pile of bytes.
196
*
197
* This can be updated and re-uploaded if (e.g.) addresses need to change.
198
*/
199
uint32_t *cpu;
200
201
/**
202
* How many states are there? (Each aux mode has its own state.)
203
*/
204
unsigned num_states;
205
206
/**
207
* Address of the resource (res->bo->gtt_offset). Note that "Surface
208
* Base Address" may be offset from this value.
209
*/
210
uint64_t bo_address;
211
212
/** A reference to the GPU buffer holding our uploaded SURFACE_STATE */
213
struct iris_state_ref ref;
214
};
215
216
/**
217
* Gallium CSO for sampler views (texture views).
218
*
219
* In addition to the normal pipe_resource, this adds an ISL view
220
* which may reinterpret the format or restrict levels/layers.
221
*
222
* These can also be linear texture buffers.
223
*/
224
struct iris_sampler_view {
225
struct pipe_sampler_view base;
226
struct isl_view view;
227
228
union isl_color_value clear_color;
229
230
/* A short-cut (not a reference) to the actual resource being viewed.
231
* Multi-planar (or depth+stencil) images may have multiple resources
232
* chained together; this skips having to traverse base->texture->*.
233
*/
234
struct iris_resource *res;
235
236
/** The resource (BO) holding our SURFACE_STATE. */
237
struct iris_surface_state surface_state;
238
};
239
240
/**
241
* Image view representation.
242
*/
243
struct iris_image_view {
244
struct pipe_image_view base;
245
246
/** The resource (BO) holding our SURFACE_STATE. */
247
struct iris_surface_state surface_state;
248
};
249
250
/**
251
* Gallium CSO for surfaces (framebuffer attachments).
252
*
253
* A view of a surface that can be bound to a color render target or
254
* depth/stencil attachment.
255
*/
256
struct iris_surface {
257
struct pipe_surface base;
258
struct isl_view view;
259
struct isl_view read_view;
260
union isl_color_value clear_color;
261
262
/** The resource (BO) holding our SURFACE_STATE. */
263
struct iris_surface_state surface_state;
264
/** The resource (BO) holding our SURFACE_STATE for read. */
265
struct iris_surface_state surface_state_read;
266
};
267
268
/**
269
* Transfer object - information about a buffer mapping.
270
*/
271
struct iris_transfer {
272
struct threaded_transfer base;
273
struct pipe_debug_callback *dbg;
274
void *buffer;
275
void *ptr;
276
277
/** A linear staging resource for GPU-based copy_region transfers. */
278
struct pipe_resource *staging;
279
struct blorp_context *blorp;
280
struct iris_batch *batch;
281
282
bool dest_had_defined_contents;
283
284
void (*unmap)(struct iris_transfer *);
285
};
286
287
/**
288
* Memory Object
289
*/
290
struct iris_memory_object {
291
struct pipe_memory_object b;
292
struct iris_bo *bo;
293
uint64_t format;
294
unsigned stride;
295
};
296
297
/**
298
* Unwrap a pipe_resource to get the underlying iris_bo (for convenience).
299
*/
300
static inline struct iris_bo *
301
iris_resource_bo(struct pipe_resource *p_res)
302
{
303
struct iris_resource *res = (void *) p_res;
304
return res->bo;
305
}
306
307
static inline uint32_t
308
iris_mocs(const struct iris_bo *bo,
309
const struct isl_device *dev,
310
isl_surf_usage_flags_t usage)
311
{
312
return isl_mocs(dev, usage, bo && iris_bo_is_external(bo));
313
}
314
315
struct iris_format_info iris_format_for_usage(const struct intel_device_info *,
316
enum pipe_format pf,
317
isl_surf_usage_flags_t usage);
318
319
struct pipe_resource *iris_resource_get_separate_stencil(struct pipe_resource *);
320
321
void iris_get_depth_stencil_resources(struct pipe_resource *res,
322
struct iris_resource **out_z,
323
struct iris_resource **out_s);
324
bool iris_resource_set_clear_color(struct iris_context *ice,
325
struct iris_resource *res,
326
union isl_color_value color);
327
union isl_color_value
328
iris_resource_get_clear_color(const struct iris_resource *res,
329
struct iris_bo **clear_color_bo,
330
uint64_t *clear_color_offset);
331
332
void iris_replace_buffer_storage(struct pipe_context *ctx,
333
struct pipe_resource *dst,
334
struct pipe_resource *src,
335
unsigned num_rebinds,
336
uint32_t rebind_mask,
337
uint32_t delete_buffer_id);
338
339
340
void iris_init_screen_resource_functions(struct pipe_screen *pscreen);
341
342
void iris_dirty_for_history(struct iris_context *ice,
343
struct iris_resource *res);
344
uint32_t iris_flush_bits_for_history(struct iris_context *ice,
345
struct iris_resource *res);
346
347
void iris_flush_and_dirty_for_history(struct iris_context *ice,
348
struct iris_batch *batch,
349
struct iris_resource *res,
350
uint32_t extra_flags,
351
const char *reason);
352
353
unsigned iris_get_num_logical_layers(const struct iris_resource *res,
354
unsigned level);
355
356
void iris_resource_disable_aux(struct iris_resource *res);
357
358
#define INTEL_REMAINING_LAYERS UINT32_MAX
359
#define INTEL_REMAINING_LEVELS UINT32_MAX
360
361
void
362
iris_hiz_exec(struct iris_context *ice,
363
struct iris_batch *batch,
364
struct iris_resource *res,
365
unsigned int level, unsigned int start_layer,
366
unsigned int num_layers, enum isl_aux_op op,
367
bool update_clear_depth);
368
369
/**
370
* Prepare a miptree for access
371
*
372
* This function should be called prior to any access to miptree in order to
373
* perform any needed resolves.
374
*
375
* \param[in] start_level The first mip level to be accessed
376
*
377
* \param[in] num_levels The number of miplevels to be accessed or
378
* INTEL_REMAINING_LEVELS to indicate every level
379
* above start_level will be accessed
380
*
381
* \param[in] start_layer The first array slice or 3D layer to be accessed
382
*
383
* \param[in] num_layers The number of array slices or 3D layers be
384
* accessed or INTEL_REMAINING_LAYERS to indicate
385
* every layer above start_layer will be accessed
386
*
387
* \param[in] aux_supported Whether or not the access will support the
388
* miptree's auxiliary compression format; this
389
* must be false for uncompressed miptrees
390
*
391
* \param[in] fast_clear_supported Whether or not the access will support
392
* fast clears in the miptree's auxiliary
393
* compression format
394
*/
395
void
396
iris_resource_prepare_access(struct iris_context *ice,
397
struct iris_resource *res,
398
uint32_t start_level, uint32_t num_levels,
399
uint32_t start_layer, uint32_t num_layers,
400
enum isl_aux_usage aux_usage,
401
bool fast_clear_supported);
402
403
/**
404
* Complete a write operation
405
*
406
* This function should be called after any operation writes to a miptree.
407
* This will update the miptree's compression state so that future resolves
408
* happen correctly. Technically, this function can be called before the
409
* write occurs but the caller must ensure that they don't interlace
410
* iris_resource_prepare_access and iris_resource_finish_write calls to
411
* overlapping layer/level ranges.
412
*
413
* \param[in] level The mip level that was written
414
*
415
* \param[in] start_layer The first array slice or 3D layer written
416
*
417
* \param[in] num_layers The number of array slices or 3D layers
418
* written or INTEL_REMAINING_LAYERS to indicate
419
* every layer above start_layer was written
420
*
421
* \param[in] written_with_aux Whether or not the write was done with
422
* auxiliary compression enabled
423
*/
424
void
425
iris_resource_finish_write(struct iris_context *ice,
426
struct iris_resource *res, uint32_t level,
427
uint32_t start_layer, uint32_t num_layers,
428
enum isl_aux_usage aux_usage);
429
430
/** Get the auxiliary compression state of a miptree slice */
431
enum isl_aux_state
432
iris_resource_get_aux_state(const struct iris_resource *res,
433
uint32_t level, uint32_t layer);
434
435
/**
436
* Set the auxiliary compression state of a miptree slice range
437
*
438
* This function directly sets the auxiliary compression state of a slice
439
* range of a miptree. It only modifies data structures and does not do any
440
* resolves. This should only be called by code which directly performs
441
* compression operations such as fast clears and resolves. Most code should
442
* use iris_resource_prepare_access or iris_resource_finish_write.
443
*/
444
void
445
iris_resource_set_aux_state(struct iris_context *ice,
446
struct iris_resource *res, uint32_t level,
447
uint32_t start_layer, uint32_t num_layers,
448
enum isl_aux_state aux_state);
449
450
/**
451
* Prepare a miptree for raw access
452
*
453
* This helper prepares the miptree for access that knows nothing about any
454
* sort of compression whatsoever. This is useful when mapping the surface or
455
* using it with the blitter.
456
*/
457
static inline void
458
iris_resource_access_raw(struct iris_context *ice,
459
struct iris_resource *res,
460
uint32_t level, uint32_t layer,
461
uint32_t num_layers,
462
bool write)
463
{
464
iris_resource_prepare_access(ice, res, level, 1, layer, num_layers,
465
ISL_AUX_USAGE_NONE, false);
466
if (write) {
467
iris_resource_finish_write(ice, res, level, layer, num_layers,
468
ISL_AUX_USAGE_NONE);
469
}
470
}
471
472
enum isl_aux_usage iris_resource_texture_aux_usage(struct iris_context *ice,
473
const struct iris_resource *res,
474
enum isl_format view_fmt);
475
void iris_resource_prepare_texture(struct iris_context *ice,
476
struct iris_resource *res,
477
enum isl_format view_format,
478
uint32_t start_level, uint32_t num_levels,
479
uint32_t start_layer, uint32_t num_layers);
480
481
enum isl_aux_usage iris_image_view_aux_usage(struct iris_context *ice,
482
const struct pipe_image_view *pview,
483
const struct shader_info *info);
484
enum isl_format iris_image_view_get_format(struct iris_context *ice,
485
const struct pipe_image_view *img);
486
487
static inline bool
488
iris_resource_unfinished_aux_import(struct iris_resource *res)
489
{
490
return res->aux.bo == NULL && res->mod_info &&
491
res->mod_info->aux_usage != ISL_AUX_USAGE_NONE;
492
}
493
494
void iris_resource_finish_aux_import(struct pipe_screen *pscreen,
495
struct iris_resource *res);
496
497
bool iris_has_invalid_primary(const struct iris_resource *res,
498
unsigned start_level, unsigned num_levels,
499
unsigned start_layer, unsigned num_layers);
500
501
void iris_resource_check_level_layer(const struct iris_resource *res,
502
uint32_t level, uint32_t layer);
503
504
bool iris_resource_level_has_hiz(const struct iris_resource *res,
505
uint32_t level);
506
507
bool iris_sample_with_depth_aux(const struct intel_device_info *devinfo,
508
const struct iris_resource *res);
509
510
bool iris_can_sample_mcs_with_clear(const struct intel_device_info *devinfo,
511
const struct iris_resource *res);
512
513
bool iris_has_color_unresolved(const struct iris_resource *res,
514
unsigned start_level, unsigned num_levels,
515
unsigned start_layer, unsigned num_layers);
516
517
bool iris_render_formats_color_compatible(enum isl_format a,
518
enum isl_format b,
519
union isl_color_value color);
520
enum isl_aux_usage iris_resource_render_aux_usage(struct iris_context *ice,
521
struct iris_resource *res,
522
uint32_t level,
523
enum isl_format render_fmt,
524
bool draw_aux_disabled);
525
void iris_resource_prepare_render(struct iris_context *ice,
526
struct iris_resource *res, uint32_t level,
527
uint32_t start_layer, uint32_t layer_count,
528
enum isl_aux_usage aux_usage);
529
void iris_resource_finish_render(struct iris_context *ice,
530
struct iris_resource *res, uint32_t level,
531
uint32_t start_layer, uint32_t layer_count,
532
enum isl_aux_usage aux_usage);
533
#endif
534
535