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
;
62 struct driOptionCache
;
63 struct u_transfer_helper
;
66 * Gallium screen/adapter context. Basically everything
67 * hardware-specific that doesn't actually require a rendering
73 * For drivers using u_transfer_helper:
75 struct u_transfer_helper
*transfer_helper
;
77 void (*destroy
)( struct pipe_screen
* );
79 const char *(*get_name
)( struct pipe_screen
* );
81 const char *(*get_vendor
)( struct pipe_screen
* );
84 * Returns the device vendor.
86 * The returned value should return the actual device vendor/manufacturer,
87 * rather than a potentially generic driver string.
89 const char *(*get_device_vendor
)( struct pipe_screen
* );
92 * Query an integer-valued capability/parameter/limit
93 * \param param one of PIPE_CAP_x
95 int (*get_param
)( struct pipe_screen
*, enum pipe_cap param
);
98 * Query a float-valued capability/parameter/limit
99 * \param param one of PIPE_CAP_x
101 float (*get_paramf
)( struct pipe_screen
*, enum pipe_capf param
);
104 * Query a per-shader-stage integer-valued capability/parameter/limit
105 * \param param one of PIPE_CAP_x
107 int (*get_shader_param
)( struct pipe_screen
*, enum pipe_shader_type shader
,
108 enum pipe_shader_cap param
);
111 * Query an integer-valued capability/parameter/limit for a codec/profile
112 * \param param one of PIPE_VIDEO_CAP_x
114 int (*get_video_param
)( struct pipe_screen
*,
115 enum pipe_video_profile profile
,
116 enum pipe_video_entrypoint entrypoint
,
117 enum pipe_video_cap param
);
120 * Query a compute-specific capability/parameter/limit.
121 * \param ir_type shader IR type for which the param applies, or don't care
122 * if the param is not shader related
123 * \param param one of PIPE_COMPUTE_CAP_x
124 * \param ret pointer to a preallocated buffer that will be
125 * initialized to the parameter value, or NULL.
126 * \return size in bytes of the parameter value that would be
129 int (*get_compute_param
)(struct pipe_screen
*,
130 enum pipe_shader_ir ir_type
,
131 enum pipe_compute_cap param
,
135 * Get the sample pixel grid's size. This function requires
136 * PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS to be callable.
138 * \param sample_count - total number of samples
139 * \param out_width - the width of the pixel grid
140 * \param out_height - the height of the pixel grid
142 void (*get_sample_pixel_grid
)(struct pipe_screen
*, unsigned sample_count
,
143 unsigned *out_width
, unsigned *out_height
);
146 * Query a timestamp in nanoseconds. The returned value should match
147 * PIPE_QUERY_TIMESTAMP. This function returns immediately and doesn't
148 * wait for rendering to complete (which cannot be achieved with queries).
150 uint64_t (*get_timestamp
)(struct pipe_screen
*);
155 * \param screen pipe screen
156 * \param priv a pointer to set in pipe_context::priv
157 * \param flags a mask of PIPE_CONTEXT_* flags
159 struct pipe_context
* (*context_create
)(struct pipe_screen
*screen
,
160 void *priv
, unsigned flags
);
163 * Check if the given pipe_format is supported as a texture or
165 * \param bindings bitmask of PIPE_BIND_*
167 bool (*is_format_supported
)( struct pipe_screen
*,
168 enum pipe_format format
,
169 enum pipe_texture_target target
,
170 unsigned sample_count
,
171 unsigned storage_sample_count
,
175 * Check if the given pipe_format is supported as output for this codec/profile.
176 * \param profile profile to check, may also be PIPE_VIDEO_PROFILE_UNKNOWN
178 bool (*is_video_format_supported
)( struct pipe_screen
*,
179 enum pipe_format format
,
180 enum pipe_video_profile profile
,
181 enum pipe_video_entrypoint entrypoint
);
184 * Check if we can actually create the given resource (test the dimension,
185 * overall size, etc). Used to implement proxy textures.
186 * \return TRUE if size is OK, FALSE if too large.
188 bool (*can_create_resource
)(struct pipe_screen
*screen
,
189 const struct pipe_resource
*templat
);
192 * Create a new texture object, using the given template info.
194 struct pipe_resource
* (*resource_create
)(struct pipe_screen
*,
195 const struct pipe_resource
*templat
);
197 struct pipe_resource
* (*resource_create_front
)(struct pipe_screen
*,
198 const struct pipe_resource
*templat
,
199 const void *map_front_private
);
202 * Create a texture from a winsys_handle. The handle is often created in
203 * another process by first creating a pipe texture and then calling
204 * resource_get_handle.
206 * NOTE: in the case of WINSYS_HANDLE_TYPE_FD handles, the caller
207 * retains ownership of the FD. (This is consistent with
208 * EGL_EXT_image_dma_buf_import)
210 * \param usage A combination of PIPE_HANDLE_USAGE_* flags.
212 struct pipe_resource
* (*resource_from_handle
)(struct pipe_screen
*,
213 const struct pipe_resource
*templat
,
214 struct winsys_handle
*handle
,
218 * Create a resource from user memory. This maps the user memory into
219 * the device address space.
221 struct pipe_resource
* (*resource_from_user_memory
)(struct pipe_screen
*,
222 const struct pipe_resource
*t
,
226 * Unlike pipe_resource::bind, which describes what state trackers want,
227 * resources can have much greater capabilities in practice, often implied
228 * by the tiling layout or memory placement. This function allows querying
229 * whether a capability is supported beyond what was requested by state
230 * trackers. It's also useful for querying capabilities of imported
231 * resources where the capabilities are unknown at first.
233 * Only these flags are allowed:
234 * - PIPE_BIND_SCANOUT
238 bool (*check_resource_capability
)(struct pipe_screen
*screen
,
239 struct pipe_resource
*resource
,
243 * Get a winsys_handle from a texture. Some platforms/winsys requires
244 * that the texture is created with a special usage flag like
245 * DISPLAYTARGET or PRIMARY.
247 * The context parameter can optionally be used to flush the resource and
248 * the context to make sure the resource is coherent with whatever user
249 * will use it. Some drivers may also use the context to convert
250 * the resource into a format compatible for sharing. The use case is
251 * OpenGL-OpenCL interop. The context parameter is allowed to be NULL.
253 * NOTE: in the case of WINSYS_HANDLE_TYPE_FD handles, the caller
254 * takes ownership of the FD. (This is consistent with
255 * EGL_MESA_image_dma_buf_export)
257 * \param usage A combination of PIPE_HANDLE_USAGE_* flags.
259 bool (*resource_get_handle
)(struct pipe_screen
*,
260 struct pipe_context
*context
,
261 struct pipe_resource
*tex
,
262 struct winsys_handle
*handle
,
266 * Get info for the given pipe resource without the need to get a
269 bool (*resource_get_param
)(struct pipe_screen
*screen
,
270 struct pipe_resource
*resource
,
272 enum pipe_resource_param param
,
276 * Get stride and offset for the given pipe resource without the need to get
279 void (*resource_get_info
)(struct pipe_screen
*screen
,
280 struct pipe_resource
*resource
,
285 * Mark the resource as changed so derived internal resources will be
286 * recreated on next use.
288 * This is necessary when reimporting external images that can't be directly
289 * used as texture sampler source, to avoid sampling from old copies.
291 void (*resource_changed
)(struct pipe_screen
*, struct pipe_resource
*pt
);
293 void (*resource_destroy
)(struct pipe_screen
*,
294 struct pipe_resource
*pt
);
298 * Do any special operations to ensure frontbuffer contents are
299 * displayed, eg copy fake frontbuffer.
300 * \param winsys_drawable_handle an opaque handle that the calling context
302 * \param subbox an optional sub region to flush
304 void (*flush_frontbuffer
)( struct pipe_screen
*screen
,
305 struct pipe_resource
*resource
,
306 unsigned level
, unsigned layer
,
307 void *winsys_drawable_handle
,
308 struct pipe_box
*subbox
);
310 /** Set ptr = fence, with reference counting */
311 void (*fence_reference
)( struct pipe_screen
*screen
,
312 struct pipe_fence_handle
**ptr
,
313 struct pipe_fence_handle
*fence
);
316 * Wait for the fence to finish.
318 * If the fence was created with PIPE_FLUSH_DEFERRED, and the context is
319 * still unflushed, and the ctx parameter of fence_finish is equal to
320 * the context where the fence was created, fence_finish will flush
321 * the context prior to waiting for the fence.
323 * In all other cases, the ctx parameter has no effect.
325 * \param timeout in nanoseconds (may be PIPE_TIMEOUT_INFINITE).
327 bool (*fence_finish
)(struct pipe_screen
*screen
,
328 struct pipe_context
*ctx
,
329 struct pipe_fence_handle
*fence
,
333 * For fences created with PIPE_FLUSH_FENCE_FD (exported fd) or
334 * by create_fence_fd() (imported fd), return the native fence fd
335 * associated with the fence. This may return -1 for fences
336 * created with PIPE_FLUSH_DEFERRED if the fence command has not
339 int (*fence_get_fd
)(struct pipe_screen
*screen
,
340 struct pipe_fence_handle
*fence
);
343 * Returns a driver-specific query.
345 * If \p info is NULL, the number of available queries is returned.
346 * Otherwise, the driver query at the specified \p index is returned
347 * in \p info. The function returns non-zero on success.
349 int (*get_driver_query_info
)(struct pipe_screen
*screen
,
351 struct pipe_driver_query_info
*info
);
354 * Returns a driver-specific query group.
356 * If \p info is NULL, the number of available groups is returned.
357 * Otherwise, the driver query group at the specified \p index is returned
358 * in \p info. The function returns non-zero on success.
360 int (*get_driver_query_group_info
)(struct pipe_screen
*screen
,
362 struct pipe_driver_query_group_info
*info
);
365 * Query information about memory usage.
367 void (*query_memory_info
)(struct pipe_screen
*screen
,
368 struct pipe_memory_info
*info
);
371 * Get IR specific compiler options struct. For PIPE_SHADER_IR_NIR this
372 * returns a 'struct nir_shader_compiler_options'. Drivers reporting
373 * NIR as the preferred IR must implement this.
375 const void *(*get_compiler_options
)(struct pipe_screen
*screen
,
376 enum pipe_shader_ir ir
,
377 enum pipe_shader_type shader
);
380 * Returns a pointer to a driver-specific on-disk shader cache. If the
381 * driver failed to create the cache or does not support an on-disk shader
382 * cache NULL is returned. The callback itself may also be NULL if the
383 * driver doesn't support an on-disk shader cache.
385 struct disk_cache
*(*get_disk_shader_cache
)(struct pipe_screen
*screen
);
388 * Create a new texture object from the given template info, taking
389 * format modifiers into account. \p modifiers specifies a list of format
390 * modifier tokens, as defined in drm_fourcc.h. The driver then picks the
391 * best modifier among these and creates the resource. \p count must
392 * contain the size of \p modifiers array.
394 * Returns NULL if an entry in \p modifiers is unsupported by the driver,
395 * or if only DRM_FORMAT_MOD_INVALID is provided.
397 struct pipe_resource
* (*resource_create_with_modifiers
)(
398 struct pipe_screen
*,
399 const struct pipe_resource
*templat
,
400 const uint64_t *modifiers
, int count
);
403 * Get supported modifiers for a format.
404 * If \p max is 0, the total number of supported modifiers for the supplied
405 * format is returned in \p count, with no modification to \p modifiers.
406 * Otherwise, \p modifiers is filled with upto \p max supported modifier
407 * codes, and \p count with the number of modifiers copied.
408 * The \p external_only array is used to return whether the format and
409 * modifier combination can only be used with an external texture target.
411 void (*query_dmabuf_modifiers
)(struct pipe_screen
*screen
,
412 enum pipe_format format
, int max
,
414 unsigned int *external_only
, int *count
);
417 * Create a memory object from a winsys handle
419 * The underlying memory is most often allocated in by a foregin API.
420 * Then the underlying memory object is then exported through interfaces
421 * compatible with EXT_external_resources.
423 * Note: For WINSYS_HANDLE_TYPE_FD handles, the caller retains ownership
426 * \param handle A handle representing the memory object to import
428 struct pipe_memory_object
*(*memobj_create_from_handle
)(struct pipe_screen
*screen
,
429 struct winsys_handle
*handle
,
433 * Destroy a memory object
435 * \param memobj The memory object to destroy
437 void (*memobj_destroy
)(struct pipe_screen
*screen
,
438 struct pipe_memory_object
*memobj
);
441 * Create a texture from a memory object
443 * \param t texture template
444 * \param memobj The memory object used to back the texture
446 struct pipe_resource
* (*resource_from_memobj
)(struct pipe_screen
*screen
,
447 const struct pipe_resource
*t
,
448 struct pipe_memory_object
*memobj
,
452 * Fill @uuid with a unique driver identifier
454 * \param uuid pointer to a memory region of PIPE_UUID_SIZE bytes
456 void (*get_driver_uuid
)(struct pipe_screen
*screen
, char *uuid
);
459 * Fill @uuid with a unique device identifier
461 * \param uuid pointer to a memory region of PIPE_UUID_SIZE bytes
463 void (*get_device_uuid
)(struct pipe_screen
*screen
, char *uuid
);
466 * Set the maximum number of parallel shader compiler threads.
468 void (*set_max_shader_compiler_threads
)(struct pipe_screen
*screen
,
469 unsigned max_threads
);
472 * Return whether parallel shader compilation has finished.
474 bool (*is_parallel_shader_compilation_finished
)(struct pipe_screen
*screen
,
476 unsigned shader_type
);
479 * Set the damage region (called when KHR_partial_update() is invoked).
480 * This function is passed an array of rectangles encoding the damage area.
481 * rects are using the bottom-left origin convention.
482 * nrects = 0 means 'reset the damage region'. What 'reset' implies is HW
483 * specific. For tile-based renderers, the damage extent is typically set
484 * to cover the whole resource with no damage rect (or a 0-size damage
485 * rect). This way, the existing resource content is reloaded into the
486 * local tile buffer for every tile thus making partial tile update
487 * possible. For HW operating in immediate mode, this reset operation is
488 * likely to be a NOOP.
490 void (*set_damage_region
)(struct pipe_screen
*screen
,
491 struct pipe_resource
*resource
,
493 const struct pipe_box
*rects
);
498 * Global configuration options for screen creation.
500 struct pipe_screen_config
{
501 const struct driOptionCache
*options
;
509 #endif /* P_SCREEN_H */