Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/include/pipe/p_screen.h
4566 views
1
/**************************************************************************
2
*
3
* Copyright 2007 VMware, Inc.
4
* All Rights Reserved.
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the
8
* "Software"), to deal in the Software without restriction, including
9
* without limitation the rights to use, copy, modify, merge, publish,
10
* distribute, sub license, and/or sell copies of the Software, and to
11
* permit persons to whom the Software is furnished to do so, subject to
12
* the following conditions:
13
*
14
* The above copyright notice and this permission notice (including the
15
* next paragraph) shall be included in all copies or substantial portions
16
* of the Software.
17
*
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
*
26
**************************************************************************/
27
28
/**
29
* @file
30
*
31
* Screen, Adapter or GPU
32
*
33
* These are driver functions/facilities that are context independent.
34
*/
35
36
37
#ifndef P_SCREEN_H
38
#define P_SCREEN_H
39
40
41
#include "pipe/p_compiler.h"
42
#include "pipe/p_format.h"
43
#include "pipe/p_defines.h"
44
#include "pipe/p_video_enums.h"
45
46
47
48
#ifdef __cplusplus
49
extern "C" {
50
#endif
51
52
53
/** Opaque types */
54
struct winsys_handle;
55
struct pipe_fence_handle;
56
struct pipe_resource;
57
struct pipe_surface;
58
struct pipe_transfer;
59
struct pipe_box;
60
struct pipe_memory_info;
61
struct disk_cache;
62
struct driOptionCache;
63
struct u_transfer_helper;
64
65
/**
66
* Gallium screen/adapter context. Basically everything
67
* hardware-specific that doesn't actually require a rendering
68
* context.
69
*/
70
struct pipe_screen {
71
/**
72
* Atomically incremented by drivers to track the number of contexts.
73
* If it's 0, it can be assumed that contexts are not tracked.
74
* Used by some places to skip locking if num_contexts == 1.
75
*/
76
unsigned num_contexts;
77
78
/**
79
* For drivers using u_transfer_helper:
80
*/
81
struct u_transfer_helper *transfer_helper;
82
83
void (*destroy)( struct pipe_screen * );
84
85
const char *(*get_name)( struct pipe_screen * );
86
87
const char *(*get_vendor)( struct pipe_screen * );
88
89
/**
90
* Returns the device vendor.
91
*
92
* The returned value should return the actual device vendor/manufacturer,
93
* rather than a potentially generic driver string.
94
*/
95
const char *(*get_device_vendor)( struct pipe_screen * );
96
97
/**
98
* Query an integer-valued capability/parameter/limit
99
* \param param one of PIPE_CAP_x
100
*/
101
int (*get_param)( struct pipe_screen *, enum pipe_cap param );
102
103
/**
104
* Query a float-valued capability/parameter/limit
105
* \param param one of PIPE_CAP_x
106
*/
107
float (*get_paramf)( struct pipe_screen *, enum pipe_capf param );
108
109
/**
110
* Query a per-shader-stage integer-valued capability/parameter/limit
111
* \param param one of PIPE_CAP_x
112
*/
113
int (*get_shader_param)( struct pipe_screen *, enum pipe_shader_type shader,
114
enum pipe_shader_cap param );
115
116
/**
117
* Query an integer-valued capability/parameter/limit for a codec/profile
118
* \param param one of PIPE_VIDEO_CAP_x
119
*/
120
int (*get_video_param)( struct pipe_screen *,
121
enum pipe_video_profile profile,
122
enum pipe_video_entrypoint entrypoint,
123
enum pipe_video_cap param );
124
125
/**
126
* Query a compute-specific capability/parameter/limit.
127
* \param ir_type shader IR type for which the param applies, or don't care
128
* if the param is not shader related
129
* \param param one of PIPE_COMPUTE_CAP_x
130
* \param ret pointer to a preallocated buffer that will be
131
* initialized to the parameter value, or NULL.
132
* \return size in bytes of the parameter value that would be
133
* returned.
134
*/
135
int (*get_compute_param)(struct pipe_screen *,
136
enum pipe_shader_ir ir_type,
137
enum pipe_compute_cap param,
138
void *ret);
139
140
/**
141
* Get the sample pixel grid's size. This function requires
142
* PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS to be callable.
143
*
144
* \param sample_count - total number of samples
145
* \param out_width - the width of the pixel grid
146
* \param out_height - the height of the pixel grid
147
*/
148
void (*get_sample_pixel_grid)(struct pipe_screen *, unsigned sample_count,
149
unsigned *out_width, unsigned *out_height);
150
151
/**
152
* Query a timestamp in nanoseconds. The returned value should match
153
* PIPE_QUERY_TIMESTAMP. This function returns immediately and doesn't
154
* wait for rendering to complete (which cannot be achieved with queries).
155
*/
156
uint64_t (*get_timestamp)(struct pipe_screen *);
157
158
/**
159
* Create a context.
160
*
161
* \param screen pipe screen
162
* \param priv a pointer to set in pipe_context::priv
163
* \param flags a mask of PIPE_CONTEXT_* flags
164
*/
165
struct pipe_context * (*context_create)(struct pipe_screen *screen,
166
void *priv, unsigned flags);
167
168
/**
169
* Check if the given pipe_format is supported as a texture or
170
* drawing surface.
171
* \param bindings bitmask of PIPE_BIND_*
172
*/
173
bool (*is_format_supported)( struct pipe_screen *,
174
enum pipe_format format,
175
enum pipe_texture_target target,
176
unsigned sample_count,
177
unsigned storage_sample_count,
178
unsigned bindings );
179
180
/**
181
* Check if the given pipe_format is supported as output for this codec/profile.
182
* \param profile profile to check, may also be PIPE_VIDEO_PROFILE_UNKNOWN
183
*/
184
bool (*is_video_format_supported)( struct pipe_screen *,
185
enum pipe_format format,
186
enum pipe_video_profile profile,
187
enum pipe_video_entrypoint entrypoint );
188
189
/**
190
* Check if we can actually create the given resource (test the dimension,
191
* overall size, etc). Used to implement proxy textures.
192
* \return TRUE if size is OK, FALSE if too large.
193
*/
194
bool (*can_create_resource)(struct pipe_screen *screen,
195
const struct pipe_resource *templat);
196
197
/**
198
* Create a new texture object, using the given template info.
199
*/
200
struct pipe_resource * (*resource_create)(struct pipe_screen *,
201
const struct pipe_resource *templat);
202
203
struct pipe_resource * (*resource_create_front)(struct pipe_screen *,
204
const struct pipe_resource *templat,
205
const void *map_front_private);
206
207
/**
208
* Create a texture from a winsys_handle. The handle is often created in
209
* another process by first creating a pipe texture and then calling
210
* resource_get_handle.
211
*
212
* NOTE: in the case of WINSYS_HANDLE_TYPE_FD handles, the caller
213
* retains ownership of the FD. (This is consistent with
214
* EGL_EXT_image_dma_buf_import)
215
*
216
* \param usage A combination of PIPE_HANDLE_USAGE_* flags.
217
*/
218
struct pipe_resource * (*resource_from_handle)(struct pipe_screen *,
219
const struct pipe_resource *templat,
220
struct winsys_handle *handle,
221
unsigned usage);
222
223
/**
224
* Create a resource from user memory. This maps the user memory into
225
* the device address space.
226
*/
227
struct pipe_resource * (*resource_from_user_memory)(struct pipe_screen *,
228
const struct pipe_resource *t,
229
void *user_memory);
230
231
/**
232
* Unlike pipe_resource::bind, which describes what gallium frontends want,
233
* resources can have much greater capabilities in practice, often implied
234
* by the tiling layout or memory placement. This function allows querying
235
* whether a capability is supported beyond what was requested by state
236
* trackers. It's also useful for querying capabilities of imported
237
* resources where the capabilities are unknown at first.
238
*
239
* Only these flags are allowed:
240
* - PIPE_BIND_SCANOUT
241
* - PIPE_BIND_CURSOR
242
* - PIPE_BIND_LINEAR
243
*/
244
bool (*check_resource_capability)(struct pipe_screen *screen,
245
struct pipe_resource *resource,
246
unsigned bind);
247
248
/**
249
* Get a winsys_handle from a texture. Some platforms/winsys requires
250
* that the texture is created with a special usage flag like
251
* DISPLAYTARGET or PRIMARY.
252
*
253
* The context parameter can optionally be used to flush the resource and
254
* the context to make sure the resource is coherent with whatever user
255
* will use it. Some drivers may also use the context to convert
256
* the resource into a format compatible for sharing. The use case is
257
* OpenGL-OpenCL interop. The context parameter is allowed to be NULL.
258
*
259
* NOTE: for multi-planar resources (which may or may not have the planes
260
* chained through the pipe_resource next pointer) the frontend will
261
* always call this function with the first resource of the chain. It is
262
* the pipe drivers responsibility to walk the resources as needed when
263
* called with handle->plane != 0.
264
*
265
* NOTE: in the case of WINSYS_HANDLE_TYPE_FD handles, the caller
266
* takes ownership of the FD. (This is consistent with
267
* EGL_MESA_image_dma_buf_export)
268
*
269
* \param usage A combination of PIPE_HANDLE_USAGE_* flags.
270
*/
271
bool (*resource_get_handle)(struct pipe_screen *,
272
struct pipe_context *context,
273
struct pipe_resource *tex,
274
struct winsys_handle *handle,
275
unsigned usage);
276
277
/**
278
* Get info for the given pipe resource without the need to get a
279
* winsys_handle.
280
*
281
* The context parameter can optionally be used to flush the resource and
282
* the context to make sure the resource is coherent with whatever user
283
* will use it. Some drivers may also use the context to convert
284
* the resource into a format compatible for sharing. The context parameter
285
* is allowed to be NULL.
286
*/
287
bool (*resource_get_param)(struct pipe_screen *screen,
288
struct pipe_context *context,
289
struct pipe_resource *resource,
290
unsigned plane,
291
unsigned layer,
292
unsigned level,
293
enum pipe_resource_param param,
294
unsigned handle_usage,
295
uint64_t *value);
296
297
/**
298
* Get stride and offset for the given pipe resource without the need to get
299
* a winsys_handle.
300
*/
301
void (*resource_get_info)(struct pipe_screen *screen,
302
struct pipe_resource *resource,
303
unsigned *stride,
304
unsigned *offset);
305
306
/**
307
* Mark the resource as changed so derived internal resources will be
308
* recreated on next use.
309
*
310
* This is necessary when reimporting external images that can't be directly
311
* used as texture sampler source, to avoid sampling from old copies.
312
*/
313
void (*resource_changed)(struct pipe_screen *, struct pipe_resource *pt);
314
315
void (*resource_destroy)(struct pipe_screen *,
316
struct pipe_resource *pt);
317
318
319
/**
320
* Do any special operations to ensure frontbuffer contents are
321
* displayed, eg copy fake frontbuffer.
322
* \param winsys_drawable_handle an opaque handle that the calling context
323
* gets out-of-band
324
* \param subbox an optional sub region to flush
325
*/
326
void (*flush_frontbuffer)( struct pipe_screen *screen,
327
struct pipe_context *ctx,
328
struct pipe_resource *resource,
329
unsigned level, unsigned layer,
330
void *winsys_drawable_handle,
331
struct pipe_box *subbox );
332
333
/** Set ptr = fence, with reference counting */
334
void (*fence_reference)( struct pipe_screen *screen,
335
struct pipe_fence_handle **ptr,
336
struct pipe_fence_handle *fence );
337
338
/**
339
* Wait for the fence to finish.
340
*
341
* If the fence was created with PIPE_FLUSH_DEFERRED, and the context is
342
* still unflushed, and the ctx parameter of fence_finish is equal to
343
* the context where the fence was created, fence_finish will flush
344
* the context prior to waiting for the fence.
345
*
346
* In all other cases, the ctx parameter has no effect.
347
*
348
* \param timeout in nanoseconds (may be PIPE_TIMEOUT_INFINITE).
349
*/
350
bool (*fence_finish)(struct pipe_screen *screen,
351
struct pipe_context *ctx,
352
struct pipe_fence_handle *fence,
353
uint64_t timeout);
354
355
/**
356
* For fences created with PIPE_FLUSH_FENCE_FD (exported fd) or
357
* by create_fence_fd() (imported fd), return the native fence fd
358
* associated with the fence. This may return -1 for fences
359
* created with PIPE_FLUSH_DEFERRED if the fence command has not
360
* been flushed yet.
361
*/
362
int (*fence_get_fd)(struct pipe_screen *screen,
363
struct pipe_fence_handle *fence);
364
365
/**
366
* Returns a driver-specific query.
367
*
368
* If \p info is NULL, the number of available queries is returned.
369
* Otherwise, the driver query at the specified \p index is returned
370
* in \p info. The function returns non-zero on success.
371
*/
372
int (*get_driver_query_info)(struct pipe_screen *screen,
373
unsigned index,
374
struct pipe_driver_query_info *info);
375
376
/**
377
* Returns a driver-specific query group.
378
*
379
* If \p info is NULL, the number of available groups is returned.
380
* Otherwise, the driver query group at the specified \p index is returned
381
* in \p info. The function returns non-zero on success.
382
*/
383
int (*get_driver_query_group_info)(struct pipe_screen *screen,
384
unsigned index,
385
struct pipe_driver_query_group_info *info);
386
387
/**
388
* Query information about memory usage.
389
*/
390
void (*query_memory_info)(struct pipe_screen *screen,
391
struct pipe_memory_info *info);
392
393
/**
394
* Get IR specific compiler options struct. For PIPE_SHADER_IR_NIR this
395
* returns a 'struct nir_shader_compiler_options'. Drivers reporting
396
* NIR as the preferred IR must implement this.
397
*/
398
const void *(*get_compiler_options)(struct pipe_screen *screen,
399
enum pipe_shader_ir ir,
400
enum pipe_shader_type shader);
401
402
/**
403
* Returns a pointer to a driver-specific on-disk shader cache. If the
404
* driver failed to create the cache or does not support an on-disk shader
405
* cache NULL is returned. The callback itself may also be NULL if the
406
* driver doesn't support an on-disk shader cache.
407
*/
408
struct disk_cache *(*get_disk_shader_cache)(struct pipe_screen *screen);
409
410
/**
411
* Create a new texture object from the given template info, taking
412
* format modifiers into account. \p modifiers specifies a list of format
413
* modifier tokens, as defined in drm_fourcc.h. The driver then picks the
414
* best modifier among these and creates the resource. \p count must
415
* contain the size of \p modifiers array.
416
*
417
* Returns NULL if an entry in \p modifiers is unsupported by the driver,
418
* or if only DRM_FORMAT_MOD_INVALID is provided.
419
*/
420
struct pipe_resource * (*resource_create_with_modifiers)(
421
struct pipe_screen *,
422
const struct pipe_resource *templat,
423
const uint64_t *modifiers, int count);
424
425
/**
426
* Get supported modifiers for a format.
427
* If \p max is 0, the total number of supported modifiers for the supplied
428
* format is returned in \p count, with no modification to \p modifiers.
429
* Otherwise, \p modifiers is filled with upto \p max supported modifier
430
* codes, and \p count with the number of modifiers copied.
431
* The \p external_only array is used to return whether the format and
432
* modifier combination can only be used with an external texture target.
433
*/
434
void (*query_dmabuf_modifiers)(struct pipe_screen *screen,
435
enum pipe_format format, int max,
436
uint64_t *modifiers,
437
unsigned int *external_only, int *count);
438
439
/**
440
* Create a memory object from a winsys handle
441
*
442
* The underlying memory is most often allocated in by a foregin API.
443
* Then the underlying memory object is then exported through interfaces
444
* compatible with EXT_external_resources.
445
*
446
* Note: For WINSYS_HANDLE_TYPE_FD handles, the caller retains ownership
447
* of the fd.
448
*
449
* \param handle A handle representing the memory object to import
450
*/
451
struct pipe_memory_object *(*memobj_create_from_handle)(struct pipe_screen *screen,
452
struct winsys_handle *handle,
453
bool dedicated);
454
455
/**
456
* Destroy a memory object
457
*
458
* \param memobj The memory object to destroy
459
*/
460
void (*memobj_destroy)(struct pipe_screen *screen,
461
struct pipe_memory_object *memobj);
462
463
/**
464
* Create a texture from a memory object
465
*
466
* \param t texture template
467
* \param memobj The memory object used to back the texture
468
*/
469
struct pipe_resource * (*resource_from_memobj)(struct pipe_screen *screen,
470
const struct pipe_resource *t,
471
struct pipe_memory_object *memobj,
472
uint64_t offset);
473
474
/**
475
* Fill @uuid with a unique driver identifier
476
*
477
* \param uuid pointer to a memory region of PIPE_UUID_SIZE bytes
478
*/
479
void (*get_driver_uuid)(struct pipe_screen *screen, char *uuid);
480
481
/**
482
* Fill @uuid with a unique device identifier
483
*
484
* \param uuid pointer to a memory region of PIPE_UUID_SIZE bytes
485
*/
486
void (*get_device_uuid)(struct pipe_screen *screen, char *uuid);
487
488
/**
489
* Set the maximum number of parallel shader compiler threads.
490
*/
491
void (*set_max_shader_compiler_threads)(struct pipe_screen *screen,
492
unsigned max_threads);
493
494
/**
495
* Return whether parallel shader compilation has finished.
496
*/
497
bool (*is_parallel_shader_compilation_finished)(struct pipe_screen *screen,
498
void *shader,
499
unsigned shader_type);
500
501
/**
502
* Set the damage region (called when KHR_partial_update() is invoked).
503
* This function is passed an array of rectangles encoding the damage area.
504
* rects are using the bottom-left origin convention.
505
* nrects = 0 means 'reset the damage region'. What 'reset' implies is HW
506
* specific. For tile-based renderers, the damage extent is typically set
507
* to cover the whole resource with no damage rect (or a 0-size damage
508
* rect). This way, the existing resource content is reloaded into the
509
* local tile buffer for every tile thus making partial tile update
510
* possible. For HW operating in immediate mode, this reset operation is
511
* likely to be a NOOP.
512
*/
513
void (*set_damage_region)(struct pipe_screen *screen,
514
struct pipe_resource *resource,
515
unsigned int nrects,
516
const struct pipe_box *rects);
517
518
/**
519
* Run driver-specific NIR lowering and optimization passes.
520
*
521
* gallium frontends should call this before passing shaders to drivers,
522
* and ideally also before shader caching.
523
*
524
* \param optimize Whether the input shader hasn't been optimized and
525
* should be.
526
*/
527
void (*finalize_nir)(struct pipe_screen *screen, void *nir, bool optimize);
528
529
/*Separated memory/resource allocations interfaces for Vulkan */
530
531
/**
532
* Create a resource, and retrieve the required size for it but don't allocate
533
* any backing memory.
534
*/
535
struct pipe_resource * (*resource_create_unbacked)(struct pipe_screen *,
536
const struct pipe_resource *templat,
537
uint64_t *size_required);
538
539
/**
540
* Allocate backing memory to be bound to resources.
541
*/
542
struct pipe_memory_allocation *(*allocate_memory)(struct pipe_screen *screen,
543
uint64_t size);
544
/**
545
* Free previously allocated backing memory.
546
*/
547
void (*free_memory)(struct pipe_screen *screen,
548
struct pipe_memory_allocation *);
549
550
/**
551
* Bind memory to a resource.
552
*/
553
bool (*resource_bind_backing)(struct pipe_screen *screen,
554
struct pipe_resource *pt,
555
struct pipe_memory_allocation *pmem,
556
uint64_t offset);
557
558
/**
559
* Map backing memory.
560
*/
561
void *(*map_memory)(struct pipe_screen *screen,
562
struct pipe_memory_allocation *pmem);
563
564
/**
565
* Unmap backing memory.
566
*/
567
void (*unmap_memory)(struct pipe_screen *screen,
568
struct pipe_memory_allocation *pmem);
569
570
/**
571
* Determine whether the screen supports the specified modifier
572
*
573
* Query whether the driver supports a \p modifier in combination with
574
* \p format. If \p external_only is not NULL, the value it points to will
575
* be set to 0 or a non-zero value to indicate whether the modifier and
576
* format combination is supported only with external, or also with non-
577
* external texture targets respectively. The \p external_only parameter is
578
* not used when the function returns false.
579
*
580
* \return true if the format+modifier pair is supported on \p screen, false
581
* otherwise.
582
*/
583
bool (*is_dmabuf_modifier_supported)(struct pipe_screen *screen,
584
uint64_t modifier, enum pipe_format,
585
bool *external_only);
586
587
/**
588
* Get the number of planes required for a given modifier/format pair.
589
*
590
* If not NULL, this function returns the number of planes needed to
591
* represent \p format in the layout specified by \p modifier, including
592
* any driver-specific auxiliary data planes.
593
*
594
* Must only be called on a modifier supported by the screen for the
595
* specified format.
596
*
597
* If NULL, no auxiliary planes are required for any modifier+format pairs
598
* supported by \p screen. Hence, the plane count can be derived directly
599
* from \p format.
600
*
601
* \return Number of planes needed to store image data in the layout defined
602
* by \p format and \p modifier.
603
*/
604
unsigned int (*get_dmabuf_modifier_planes)(struct pipe_screen *screen,
605
uint64_t modifier,
606
enum pipe_format format);
607
};
608
609
610
/**
611
* Global configuration options for screen creation.
612
*/
613
struct pipe_screen_config {
614
const struct driOptionCache *options;
615
};
616
617
618
#ifdef __cplusplus
619
}
620
#endif
621
622
#endif /* P_SCREEN_H */
623
624