• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    /**
73     * For drivers using u_transfer_helper:
74     */
75    struct u_transfer_helper *transfer_helper;
76 
77    void (*destroy)( struct pipe_screen * );
78 
79    const char *(*get_name)( struct pipe_screen * );
80 
81    const char *(*get_vendor)( struct pipe_screen * );
82 
83    /**
84     * Returns the device vendor.
85     *
86     * The returned value should return the actual device vendor/manufacturer,
87     * rather than a potentially generic driver string.
88     */
89    const char *(*get_device_vendor)( struct pipe_screen * );
90 
91    /**
92     * Query an integer-valued capability/parameter/limit
93     * \param param  one of PIPE_CAP_x
94     */
95    int (*get_param)( struct pipe_screen *, enum pipe_cap param );
96 
97    /**
98     * Query a float-valued capability/parameter/limit
99     * \param param  one of PIPE_CAP_x
100     */
101    float (*get_paramf)( struct pipe_screen *, enum pipe_capf param );
102 
103    /**
104     * Query a per-shader-stage integer-valued capability/parameter/limit
105     * \param param  one of PIPE_CAP_x
106     */
107    int (*get_shader_param)( struct pipe_screen *, enum pipe_shader_type shader,
108                             enum pipe_shader_cap param );
109 
110    /**
111     * Query an integer-valued capability/parameter/limit for a codec/profile
112     * \param param  one of PIPE_VIDEO_CAP_x
113     */
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 );
118 
119    /**
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
127     *                returned.
128     */
129    int (*get_compute_param)(struct pipe_screen *,
130 			    enum pipe_shader_ir ir_type,
131 			    enum pipe_compute_cap param,
132 			    void *ret);
133 
134    /**
135     * Query a timestamp in nanoseconds. The returned value should match
136     * PIPE_QUERY_TIMESTAMP. This function returns immediately and doesn't
137     * wait for rendering to complete (which cannot be achieved with queries).
138     */
139    uint64_t (*get_timestamp)(struct pipe_screen *);
140 
141    /**
142     * Create a context.
143     *
144     * \param screen      pipe screen
145     * \param priv        a pointer to set in pipe_context::priv
146     * \param flags       a mask of PIPE_CONTEXT_* flags
147     */
148    struct pipe_context * (*context_create)(struct pipe_screen *screen,
149 					   void *priv, unsigned flags);
150 
151    /**
152     * Check if the given pipe_format is supported as a texture or
153     * drawing surface.
154     * \param bindings  bitmask of PIPE_BIND_*
155     */
156    boolean (*is_format_supported)( struct pipe_screen *,
157                                    enum pipe_format format,
158                                    enum pipe_texture_target target,
159                                    unsigned sample_count,
160                                    unsigned bindings );
161 
162    /**
163     * Check if the given pipe_format is supported as output for this codec/profile.
164     * \param profile  profile to check, may also be PIPE_VIDEO_PROFILE_UNKNOWN
165     */
166    boolean (*is_video_format_supported)( struct pipe_screen *,
167                                          enum pipe_format format,
168                                          enum pipe_video_profile profile,
169                                          enum pipe_video_entrypoint entrypoint );
170 
171    /**
172     * Check if we can actually create the given resource (test the dimension,
173     * overall size, etc).  Used to implement proxy textures.
174     * \return TRUE if size is OK, FALSE if too large.
175     */
176    boolean (*can_create_resource)(struct pipe_screen *screen,
177                                   const struct pipe_resource *templat);
178 
179    /**
180     * Create a new texture object, using the given template info.
181     */
182    struct pipe_resource * (*resource_create)(struct pipe_screen *,
183 					     const struct pipe_resource *templat);
184 
185    struct pipe_resource * (*resource_create_front)(struct pipe_screen *,
186                                                    const struct pipe_resource *templat,
187                                                    const void *map_front_private);
188 
189    /**
190     * Create a texture from a winsys_handle. The handle is often created in
191     * another process by first creating a pipe texture and then calling
192     * resource_get_handle.
193     *
194     * NOTE: in the case of DRM_API_HANDLE_TYPE_FD handles, the caller
195     * retains ownership of the FD.  (This is consistent with
196     * EGL_EXT_image_dma_buf_import)
197     *
198     * \param usage  A combination of PIPE_HANDLE_USAGE_* flags.
199     */
200    struct pipe_resource * (*resource_from_handle)(struct pipe_screen *,
201 						  const struct pipe_resource *templat,
202 						  struct winsys_handle *handle,
203 						  unsigned usage);
204 
205    /**
206     * Create a resource from user memory. This maps the user memory into
207     * the device address space.
208     */
209    struct pipe_resource * (*resource_from_user_memory)(struct pipe_screen *,
210                                                        const struct pipe_resource *t,
211                                                        void *user_memory);
212 
213    /**
214     * Unlike pipe_resource::bind, which describes what state trackers want,
215     * resources can have much greater capabilities in practice, often implied
216     * by the tiling layout or memory placement. This function allows querying
217     * whether a capability is supported beyond what was requested by state
218     * trackers. It's also useful for querying capabilities of imported
219     * resources where the capabilities are unknown at first.
220     *
221     * Only these flags are allowed:
222     * - PIPE_BIND_SCANOUT
223     * - PIPE_BIND_CURSOR
224     * - PIPE_BIND_LINEAR
225     */
226    bool (*check_resource_capability)(struct pipe_screen *screen,
227                                      struct pipe_resource *resource,
228                                      unsigned bind);
229 
230    /**
231     * Get a winsys_handle from a texture. Some platforms/winsys requires
232     * that the texture is created with a special usage flag like
233     * DISPLAYTARGET or PRIMARY.
234     *
235     * The context parameter can optionally be used to flush the resource and
236     * the context to make sure the resource is coherent with whatever user
237     * will use it. Some drivers may also use the context to convert
238     * the resource into a format compatible for sharing. The use case is
239     * OpenGL-OpenCL interop. The context parameter is allowed to be NULL.
240     *
241     * NOTE: in the case of DRM_API_HANDLE_TYPE_FD handles, the caller
242     * takes ownership of the FD.  (This is consistent with
243     * EGL_MESA_image_dma_buf_export)
244     *
245     * \param usage  A combination of PIPE_HANDLE_USAGE_* flags.
246     */
247    boolean (*resource_get_handle)(struct pipe_screen *,
248                                   struct pipe_context *context,
249 				  struct pipe_resource *tex,
250 				  struct winsys_handle *handle,
251 				  unsigned usage);
252 
253    /**
254     * Mark the resource as changed so derived internal resources will be
255     * recreated on next use.
256     *
257     * This is necessary when reimporting external images that can't be directly
258     * used as texture sampler source, to avoid sampling from old copies.
259     */
260    void (*resource_changed)(struct pipe_screen *, struct pipe_resource *pt);
261 
262    void (*resource_destroy)(struct pipe_screen *,
263 			    struct pipe_resource *pt);
264 
265 
266    /**
267     * Do any special operations to ensure frontbuffer contents are
268     * displayed, eg copy fake frontbuffer.
269     * \param winsys_drawable_handle  an opaque handle that the calling context
270     *                                gets out-of-band
271     * \param subbox an optional sub region to flush
272     */
273    void (*flush_frontbuffer)( struct pipe_screen *screen,
274                               struct pipe_resource *resource,
275                               unsigned level, unsigned layer,
276                               void *winsys_drawable_handle,
277                               struct pipe_box *subbox );
278 
279    /** Set ptr = fence, with reference counting */
280    void (*fence_reference)( struct pipe_screen *screen,
281                             struct pipe_fence_handle **ptr,
282                             struct pipe_fence_handle *fence );
283 
284    /**
285     * Wait for the fence to finish.
286     *
287     * If the fence was created with PIPE_FLUSH_DEFERRED, and the context is
288     * still unflushed, and the ctx parameter of fence_finish is equal to
289     * the context where the fence was created, fence_finish will flush
290     * the context prior to waiting for the fence.
291     *
292     * In all other cases, the ctx parameter has no effect.
293     *
294     * \param timeout  in nanoseconds (may be PIPE_TIMEOUT_INFINITE).
295     */
296    boolean (*fence_finish)(struct pipe_screen *screen,
297                            struct pipe_context *ctx,
298                            struct pipe_fence_handle *fence,
299                            uint64_t timeout);
300 
301    /**
302     * For fences created with PIPE_FLUSH_FENCE_FD (exported fd) or
303     * by create_fence_fd() (imported fd), return the native fence fd
304     * associated with the fence.  This may return -1 for fences
305     * created with PIPE_FLUSH_DEFERRED if the fence command has not
306     * been flushed yet.
307     */
308    int (*fence_get_fd)(struct pipe_screen *screen,
309                        struct pipe_fence_handle *fence);
310 
311    /**
312     * Returns a driver-specific query.
313     *
314     * If \p info is NULL, the number of available queries is returned.
315     * Otherwise, the driver query at the specified \p index is returned
316     * in \p info. The function returns non-zero on success.
317     */
318    int (*get_driver_query_info)(struct pipe_screen *screen,
319                                 unsigned index,
320                                 struct pipe_driver_query_info *info);
321 
322    /**
323     * Returns a driver-specific query group.
324     *
325     * If \p info is NULL, the number of available groups is returned.
326     * Otherwise, the driver query group at the specified \p index is returned
327     * in \p info. The function returns non-zero on success.
328     */
329    int (*get_driver_query_group_info)(struct pipe_screen *screen,
330                                       unsigned index,
331                                       struct pipe_driver_query_group_info *info);
332 
333    /**
334     * Query information about memory usage.
335     */
336    void (*query_memory_info)(struct pipe_screen *screen,
337                              struct pipe_memory_info *info);
338 
339    /**
340     * Get IR specific compiler options struct.  For PIPE_SHADER_IR_NIR this
341     * returns a 'struct nir_shader_compiler_options'.  Drivers reporting
342     * NIR as the preferred IR must implement this.
343     */
344    const void *(*get_compiler_options)(struct pipe_screen *screen,
345                                       enum pipe_shader_ir ir,
346                                       enum pipe_shader_type shader);
347 
348    /**
349     * Returns a pointer to a driver-specific on-disk shader cache. If the
350     * driver failed to create the cache or does not support an on-disk shader
351     * cache NULL is returned. The callback itself may also be NULL if the
352     * driver doesn't support an on-disk shader cache.
353     */
354    struct disk_cache *(*get_disk_shader_cache)(struct pipe_screen *screen);
355 
356    /**
357     * Create a new texture object from the given template info, taking
358     * format modifiers into account. \p modifiers specifies a list of format
359     * modifier tokens, as defined in drm_fourcc.h. The driver then picks the
360     * best modifier among these and creates the resource. \p count must
361     * contain the size of \p modifiers array.
362     *
363     * Returns NULL if an entry in \p modifiers is unsupported by the driver,
364     * or if only DRM_FORMAT_MOD_INVALID is provided.
365     */
366    struct pipe_resource * (*resource_create_with_modifiers)(
367                            struct pipe_screen *,
368                            const struct pipe_resource *templat,
369                            const uint64_t *modifiers, int count);
370 
371    /**
372     * Get supported modifiers for a format.
373     * If \p max is 0, the total number of supported modifiers for the supplied
374     * format is returned in \p count, with no modification to \p modifiers.
375     * Otherwise, \p modifiers is filled with upto \p max supported modifier
376     * codes, and \p count with the number of modifiers copied.
377     * The \p external_only array is used to return whether the format and
378     * modifier combination can only be used with an external texture target.
379     */
380    void (*query_dmabuf_modifiers)(struct pipe_screen *screen,
381                                   enum pipe_format format, int max,
382                                   uint64_t *modifiers,
383                                   unsigned int *external_only, int *count);
384 
385    /**
386     * Create a memory object from a winsys handle
387     *
388     * The underlying memory is most often allocated in by a foregin API.
389     * Then the underlying memory object is then exported through interfaces
390     * compatible with EXT_external_resources.
391     *
392     * Note: For DRM_API_HANDLE_TYPE_FD handles, the caller retains ownership
393     * of the fd.
394     *
395     * \param handle  A handle representing the memory object to import
396     */
397    struct pipe_memory_object *(*memobj_create_from_handle)(struct pipe_screen *screen,
398                                                            struct winsys_handle *handle,
399                                                            bool dedicated);
400 
401    /**
402     * Destroy a memory object
403     *
404     * \param memobj  The memory object to destroy
405     */
406    void (*memobj_destroy)(struct pipe_screen *screen,
407                           struct pipe_memory_object *memobj);
408 
409    /**
410     * Create a texture from a memory object
411     *
412     * \param t       texture template
413     * \param memobj  The memory object used to back the texture
414     */
415    struct pipe_resource * (*resource_from_memobj)(struct pipe_screen *screen,
416                                                   const struct pipe_resource *t,
417                                                   struct pipe_memory_object *memobj,
418                                                   uint64_t offset);
419 
420    /**
421     * Fill @uuid with a unique driver identifier
422     *
423     * \param uuid    pointer to a memory region of PIPE_UUID_SIZE bytes
424     */
425    void (*get_driver_uuid)(struct pipe_screen *screen, char *uuid);
426 
427    /**
428     * Fill @uuid with a unique device identifier
429     *
430     * \param uuid    pointer to a memory region of PIPE_UUID_SIZE bytes
431     */
432    void (*get_device_uuid)(struct pipe_screen *screen, char *uuid);
433 };
434 
435 
436 /**
437  * Global configuration options for screen creation.
438  */
439 struct pipe_screen_config {
440    const struct driOptionCache *options;
441 };
442 
443 
444 #ifdef __cplusplus
445 }
446 #endif
447 
448 #endif /* P_SCREEN_H */
449