1
/**************************************************************************
3
* Copyright 2007 VMware, Inc.
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:
14
* The above copyright notice and this permission notice (including the
15
* next paragraph) shall be included in all copies or substantial portions
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.
26
**************************************************************************/
31
* Screen, Adapter or GPU
33
* These are driver functions/facilities that are context independent.
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"
55
struct pipe_fence_handle;
60
struct pipe_memory_info;
61
struct pipe_vertex_buffer;
62
struct pipe_vertex_element;
63
struct pipe_vertex_state;
65
struct driOptionCache;
66
struct u_transfer_helper;
69
typedef struct pipe_vertex_state *
70
(*pipe_create_vertex_state_func)(struct pipe_screen *screen,
71
struct pipe_vertex_buffer *buffer,
72
const struct pipe_vertex_element *elements,
73
unsigned num_elements,
74
struct pipe_resource *indexbuf,
75
uint32_t full_velem_mask);
76
typedef void (*pipe_vertex_state_destroy_func)(struct pipe_screen *screen,
77
struct pipe_vertex_state *);
80
* Gallium screen/adapter context. Basically everything
81
* hardware-specific that doesn't actually require a rendering
86
* Atomically incremented by drivers to track the number of contexts.
87
* If it's 0, it can be assumed that contexts are not tracked.
88
* Used by some places to skip locking if num_contexts == 1.
90
unsigned num_contexts;
93
* For drivers using u_transfer_helper:
95
struct u_transfer_helper *transfer_helper;
97
void (*destroy)( struct pipe_screen * );
99
const char *(*get_name)( struct pipe_screen * );
101
const char *(*get_vendor)( struct pipe_screen * );
104
* Returns the device vendor.
106
* The returned value should return the actual device vendor/manufacturer,
107
* rather than a potentially generic driver string.
109
const char *(*get_device_vendor)( struct pipe_screen * );
112
* Query an integer-valued capability/parameter/limit
113
* \param param one of PIPE_CAP_x
115
int (*get_param)( struct pipe_screen *, enum pipe_cap param );
118
* Query a float-valued capability/parameter/limit
119
* \param param one of PIPE_CAP_x
121
float (*get_paramf)( struct pipe_screen *, enum pipe_capf param );
124
* Query a per-shader-stage integer-valued capability/parameter/limit
125
* \param param one of PIPE_CAP_x
127
int (*get_shader_param)( struct pipe_screen *, enum pipe_shader_type shader,
128
enum pipe_shader_cap param );
131
* Query an integer-valued capability/parameter/limit for a codec/profile
132
* \param param one of PIPE_VIDEO_CAP_x
134
int (*get_video_param)( struct pipe_screen *,
135
enum pipe_video_profile profile,
136
enum pipe_video_entrypoint entrypoint,
137
enum pipe_video_cap param );
140
* Query a compute-specific capability/parameter/limit.
141
* \param ir_type shader IR type for which the param applies, or don't care
142
* if the param is not shader related
143
* \param param one of PIPE_COMPUTE_CAP_x
144
* \param ret pointer to a preallocated buffer that will be
145
* initialized to the parameter value, or NULL.
146
* \return size in bytes of the parameter value that would be
149
int (*get_compute_param)(struct pipe_screen *,
150
enum pipe_shader_ir ir_type,
151
enum pipe_compute_cap param,
155
* Get the sample pixel grid's size. This function requires
156
* PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS to be callable.
158
* \param sample_count - total number of samples
159
* \param out_width - the width of the pixel grid
160
* \param out_height - the height of the pixel grid
162
void (*get_sample_pixel_grid)(struct pipe_screen *, unsigned sample_count,
163
unsigned *out_width, unsigned *out_height);
166
* Query a timestamp in nanoseconds. The returned value should match
167
* PIPE_QUERY_TIMESTAMP. This function returns immediately and doesn't
168
* wait for rendering to complete (which cannot be achieved with queries).
170
uint64_t (*get_timestamp)(struct pipe_screen *);
175
* \param screen pipe screen
176
* \param priv a pointer to set in pipe_context::priv
177
* \param flags a mask of PIPE_CONTEXT_* flags
179
struct pipe_context * (*context_create)(struct pipe_screen *screen,
180
void *priv, unsigned flags);
183
* Check if the given image copy will be faster on compute
184
* \param cpu If true, this is checking against CPU fallback,
185
* otherwise the copy will be on GFX
187
bool (*is_compute_copy_faster)( struct pipe_screen *,
188
enum pipe_format src_format,
189
enum pipe_format dst_format,
196
* Check if the given pipe_format is supported as a texture or
198
* \param bindings bitmask of PIPE_BIND_*
200
bool (*is_format_supported)( struct pipe_screen *,
201
enum pipe_format format,
202
enum pipe_texture_target target,
203
unsigned sample_count,
204
unsigned storage_sample_count,
208
* Check if the given pipe_format is supported as output for this codec/profile.
209
* \param profile profile to check, may also be PIPE_VIDEO_PROFILE_UNKNOWN
211
bool (*is_video_format_supported)( struct pipe_screen *,
212
enum pipe_format format,
213
enum pipe_video_profile profile,
214
enum pipe_video_entrypoint entrypoint );
217
* Check if we can actually create the given resource (test the dimension,
218
* overall size, etc). Used to implement proxy textures.
219
* \return TRUE if size is OK, FALSE if too large.
221
bool (*can_create_resource)(struct pipe_screen *screen,
222
const struct pipe_resource *templat);
225
* Create a new texture object, using the given template info.
227
struct pipe_resource * (*resource_create)(struct pipe_screen *,
228
const struct pipe_resource *templat);
230
struct pipe_resource * (*resource_create_drawable)(struct pipe_screen *,
231
const struct pipe_resource *tmpl,
232
const void *loader_private);
234
struct pipe_resource * (*resource_create_front)(struct pipe_screen *,
235
const struct pipe_resource *templat,
236
const void *map_front_private);
239
* Create a texture from a winsys_handle. The handle is often created in
240
* another process by first creating a pipe texture and then calling
241
* resource_get_handle.
243
* NOTE: in the case of WINSYS_HANDLE_TYPE_FD handles, the caller
244
* retains ownership of the FD. (This is consistent with
245
* EGL_EXT_image_dma_buf_import)
247
* \param usage A combination of PIPE_HANDLE_USAGE_* flags.
249
struct pipe_resource * (*resource_from_handle)(struct pipe_screen *,
250
const struct pipe_resource *templat,
251
struct winsys_handle *handle,
255
* Create a resource from user memory. This maps the user memory into
256
* the device address space.
258
struct pipe_resource * (*resource_from_user_memory)(struct pipe_screen *,
259
const struct pipe_resource *t,
263
* Unlike pipe_resource::bind, which describes what gallium frontends want,
264
* resources can have much greater capabilities in practice, often implied
265
* by the tiling layout or memory placement. This function allows querying
266
* whether a capability is supported beyond what was requested by state
267
* trackers. It's also useful for querying capabilities of imported
268
* resources where the capabilities are unknown at first.
270
* Only these flags are allowed:
271
* - PIPE_BIND_SCANOUT
275
bool (*check_resource_capability)(struct pipe_screen *screen,
276
struct pipe_resource *resource,
280
* Get a winsys_handle from a texture. Some platforms/winsys requires
281
* that the texture is created with a special usage flag like
282
* DISPLAYTARGET or PRIMARY.
284
* The context parameter can optionally be used to flush the resource and
285
* the context to make sure the resource is coherent with whatever user
286
* will use it. Some drivers may also use the context to convert
287
* the resource into a format compatible for sharing. The use case is
288
* OpenGL-OpenCL interop. The context parameter is allowed to be NULL.
290
* NOTE: for multi-planar resources (which may or may not have the planes
291
* chained through the pipe_resource next pointer) the frontend will
292
* always call this function with the first resource of the chain. It is
293
* the pipe drivers responsibility to walk the resources as needed when
294
* called with handle->plane != 0.
296
* NOTE: in the case of WINSYS_HANDLE_TYPE_FD handles, the caller
297
* takes ownership of the FD. (This is consistent with
298
* EGL_MESA_image_dma_buf_export)
300
* \param usage A combination of PIPE_HANDLE_USAGE_* flags.
302
bool (*resource_get_handle)(struct pipe_screen *,
303
struct pipe_context *context,
304
struct pipe_resource *tex,
305
struct winsys_handle *handle,
309
* Get info for the given pipe resource without the need to get a
312
* The context parameter can optionally be used to flush the resource and
313
* the context to make sure the resource is coherent with whatever user
314
* will use it. Some drivers may also use the context to convert
315
* the resource into a format compatible for sharing. The context parameter
316
* is allowed to be NULL.
318
bool (*resource_get_param)(struct pipe_screen *screen,
319
struct pipe_context *context,
320
struct pipe_resource *resource,
324
enum pipe_resource_param param,
325
unsigned handle_usage,
329
* Get stride and offset for the given pipe resource without the need to get
332
void (*resource_get_info)(struct pipe_screen *screen,
333
struct pipe_resource *resource,
338
* Mark the resource as changed so derived internal resources will be
339
* recreated on next use.
341
* This is necessary when reimporting external images that can't be directly
342
* used as texture sampler source, to avoid sampling from old copies.
344
void (*resource_changed)(struct pipe_screen *, struct pipe_resource *pt);
346
void (*resource_destroy)(struct pipe_screen *,
347
struct pipe_resource *pt);
351
* Do any special operations to ensure frontbuffer contents are
352
* displayed, eg copy fake frontbuffer.
353
* \param winsys_drawable_handle an opaque handle that the calling context
355
* \param subbox an optional sub region to flush
357
void (*flush_frontbuffer)( struct pipe_screen *screen,
358
struct pipe_context *ctx,
359
struct pipe_resource *resource,
360
unsigned level, unsigned layer,
361
void *winsys_drawable_handle,
362
struct pipe_box *subbox );
364
/** Set ptr = fence, with reference counting */
365
void (*fence_reference)( struct pipe_screen *screen,
366
struct pipe_fence_handle **ptr,
367
struct pipe_fence_handle *fence );
370
* Wait for the fence to finish.
372
* If the fence was created with PIPE_FLUSH_DEFERRED, and the context is
373
* still unflushed, and the ctx parameter of fence_finish is equal to
374
* the context where the fence was created, fence_finish will flush
375
* the context prior to waiting for the fence.
377
* In all other cases, the ctx parameter has no effect.
379
* \param timeout in nanoseconds (may be PIPE_TIMEOUT_INFINITE).
381
bool (*fence_finish)(struct pipe_screen *screen,
382
struct pipe_context *ctx,
383
struct pipe_fence_handle *fence,
387
* For fences created with PIPE_FLUSH_FENCE_FD (exported fd) or
388
* by create_fence_fd() (imported fd), return the native fence fd
389
* associated with the fence. This may return -1 for fences
390
* created with PIPE_FLUSH_DEFERRED if the fence command has not
393
int (*fence_get_fd)(struct pipe_screen *screen,
394
struct pipe_fence_handle *fence);
397
* Returns a driver-specific query.
399
* If \p info is NULL, the number of available queries is returned.
400
* Otherwise, the driver query at the specified \p index is returned
401
* in \p info. The function returns non-zero on success.
403
int (*get_driver_query_info)(struct pipe_screen *screen,
405
struct pipe_driver_query_info *info);
408
* Returns a driver-specific query group.
410
* If \p info is NULL, the number of available groups is returned.
411
* Otherwise, the driver query group at the specified \p index is returned
412
* in \p info. The function returns non-zero on success.
414
int (*get_driver_query_group_info)(struct pipe_screen *screen,
416
struct pipe_driver_query_group_info *info);
419
* Query information about memory usage.
421
void (*query_memory_info)(struct pipe_screen *screen,
422
struct pipe_memory_info *info);
425
* Get IR specific compiler options struct. For PIPE_SHADER_IR_NIR this
426
* returns a 'struct nir_shader_compiler_options'. Drivers reporting
427
* NIR as the preferred IR must implement this.
429
const void *(*get_compiler_options)(struct pipe_screen *screen,
430
enum pipe_shader_ir ir,
431
enum pipe_shader_type shader);
434
* Returns a pointer to a driver-specific on-disk shader cache. If the
435
* driver failed to create the cache or does not support an on-disk shader
436
* cache NULL is returned. The callback itself may also be NULL if the
437
* driver doesn't support an on-disk shader cache.
439
struct disk_cache *(*get_disk_shader_cache)(struct pipe_screen *screen);
442
* Create a new texture object from the given template info, taking
443
* format modifiers into account. \p modifiers specifies a list of format
444
* modifier tokens, as defined in drm_fourcc.h. The driver then picks the
445
* best modifier among these and creates the resource. \p count must
446
* contain the size of \p modifiers array.
448
* Returns NULL if an entry in \p modifiers is unsupported by the driver,
449
* or if only DRM_FORMAT_MOD_INVALID is provided.
451
struct pipe_resource * (*resource_create_with_modifiers)(
452
struct pipe_screen *,
453
const struct pipe_resource *templat,
454
const uint64_t *modifiers, int count);
457
* Get supported modifiers for a format.
458
* If \p max is 0, the total number of supported modifiers for the supplied
459
* format is returned in \p count, with no modification to \p modifiers.
460
* Otherwise, \p modifiers is filled with upto \p max supported modifier
461
* codes, and \p count with the number of modifiers copied.
462
* The \p external_only array is used to return whether the format and
463
* modifier combination can only be used with an external texture target.
465
void (*query_dmabuf_modifiers)(struct pipe_screen *screen,
466
enum pipe_format format, int max,
468
unsigned int *external_only, int *count);
471
* Create a memory object from a winsys handle
473
* The underlying memory is most often allocated in by a foregin API.
474
* Then the underlying memory object is then exported through interfaces
475
* compatible with EXT_external_resources.
477
* Note: For WINSYS_HANDLE_TYPE_FD handles, the caller retains ownership
480
* \param handle A handle representing the memory object to import
482
struct pipe_memory_object *(*memobj_create_from_handle)(struct pipe_screen *screen,
483
struct winsys_handle *handle,
487
* Destroy a memory object
489
* \param memobj The memory object to destroy
491
void (*memobj_destroy)(struct pipe_screen *screen,
492
struct pipe_memory_object *memobj);
495
* Create a texture from a memory object
497
* \param t texture template
498
* \param memobj The memory object used to back the texture
500
struct pipe_resource * (*resource_from_memobj)(struct pipe_screen *screen,
501
const struct pipe_resource *t,
502
struct pipe_memory_object *memobj,
506
* Fill @uuid with a unique driver identifier
508
* \param uuid pointer to a memory region of PIPE_UUID_SIZE bytes
510
void (*get_driver_uuid)(struct pipe_screen *screen, char *uuid);
513
* Fill @uuid with a unique device identifier
515
* \param uuid pointer to a memory region of PIPE_UUID_SIZE bytes
517
void (*get_device_uuid)(struct pipe_screen *screen, char *uuid);
520
* Set the maximum number of parallel shader compiler threads.
522
void (*set_max_shader_compiler_threads)(struct pipe_screen *screen,
523
unsigned max_threads);
526
* Return whether parallel shader compilation has finished.
528
bool (*is_parallel_shader_compilation_finished)(struct pipe_screen *screen,
530
unsigned shader_type);
533
* Set the damage region (called when KHR_partial_update() is invoked).
534
* This function is passed an array of rectangles encoding the damage area.
535
* rects are using the bottom-left origin convention.
536
* nrects = 0 means 'reset the damage region'. What 'reset' implies is HW
537
* specific. For tile-based renderers, the damage extent is typically set
538
* to cover the whole resource with no damage rect (or a 0-size damage
539
* rect). This way, the existing resource content is reloaded into the
540
* local tile buffer for every tile thus making partial tile update
541
* possible. For HW operating in immediate mode, this reset operation is
542
* likely to be a NOOP.
544
void (*set_damage_region)(struct pipe_screen *screen,
545
struct pipe_resource *resource,
547
const struct pipe_box *rects);
550
* Run driver-specific NIR lowering and optimization passes.
552
* gallium frontends should call this before passing shaders to drivers,
553
* and ideally also before shader caching.
555
* The driver may return a non-NULL string to trigger GLSL link failure and
556
* logging of that message in the GLSL linker log.
558
char *(*finalize_nir)(struct pipe_screen *screen, void *nir);
560
/*Separated memory/resource allocations interfaces for Vulkan */
563
* Create a resource, and retrieve the required size for it but don't allocate
564
* any backing memory.
566
struct pipe_resource * (*resource_create_unbacked)(struct pipe_screen *,
567
const struct pipe_resource *templat,
568
uint64_t *size_required);
571
* Allocate backing memory to be bound to resources.
573
struct pipe_memory_allocation *(*allocate_memory)(struct pipe_screen *screen,
576
* Free previously allocated backing memory.
578
void (*free_memory)(struct pipe_screen *screen,
579
struct pipe_memory_allocation *);
582
* Allocate fd-based memory to be bound to resources.
584
struct pipe_memory_allocation *(*allocate_memory_fd)(struct pipe_screen *screen,
589
* Import memory from an fd-handle.
591
bool (*import_memory_fd)(struct pipe_screen *screen,
593
struct pipe_memory_allocation **pmem,
597
* Free previously allocated fd-based memory.
599
void (*free_memory_fd)(struct pipe_screen *screen,
600
struct pipe_memory_allocation *pmem);
603
* Bind memory to a resource.
605
bool (*resource_bind_backing)(struct pipe_screen *screen,
606
struct pipe_resource *pt,
607
struct pipe_memory_allocation *pmem,
611
* Map backing memory.
613
void *(*map_memory)(struct pipe_screen *screen,
614
struct pipe_memory_allocation *pmem);
617
* Unmap backing memory.
619
void (*unmap_memory)(struct pipe_screen *screen,
620
struct pipe_memory_allocation *pmem);
623
* Determine whether the screen supports the specified modifier
625
* Query whether the driver supports a \p modifier in combination with
626
* \p format. If \p external_only is not NULL, the value it points to will
627
* be set to 0 or a non-zero value to indicate whether the modifier and
628
* format combination is supported only with external, or also with non-
629
* external texture targets respectively. The \p external_only parameter is
630
* not used when the function returns false.
632
* \return true if the format+modifier pair is supported on \p screen, false
635
bool (*is_dmabuf_modifier_supported)(struct pipe_screen *screen,
636
uint64_t modifier, enum pipe_format,
637
bool *external_only);
640
* Get the number of planes required for a given modifier/format pair.
642
* If not NULL, this function returns the number of planes needed to
643
* represent \p format in the layout specified by \p modifier, including
644
* any driver-specific auxiliary data planes.
646
* Must only be called on a modifier supported by the screen for the
649
* If NULL, no auxiliary planes are required for any modifier+format pairs
650
* supported by \p screen. Hence, the plane count can be derived directly
653
* \return Number of planes needed to store image data in the layout defined
654
* by \p format and \p modifier.
656
unsigned int (*get_dmabuf_modifier_planes)(struct pipe_screen *screen,
658
enum pipe_format format);
661
* Get supported page sizes for sparse texture.
663
* \p size is the array size of \p x, \p y and \p z.
665
* \p offset sets an offset into the possible format page size array,
666
* used to pick a specific xyz size combination.
668
* \return Number of supported page sizes, 0 means not support.
670
int (*get_sparse_texture_virtual_page_size)(struct pipe_screen *screen,
671
enum pipe_texture_target target,
673
enum pipe_format format,
674
unsigned offset, unsigned size,
675
int *x, int *y, int *z);
678
* Vertex state CSO functions for precomputing vertex and index buffer
679
* states for display lists.
681
pipe_create_vertex_state_func create_vertex_state;
682
pipe_vertex_state_destroy_func vertex_state_destroy;
687
* Global configuration options for screen creation.
689
struct pipe_screen_config {
690
struct driOptionCache *options;
691
const struct driOptionCache *options_info;
699
#endif /* P_SCREEN_H */