st/dri: implement createImageWithModifiers in DRIimage
[mesa.git] / src / gallium / include / pipe / p_screen.h
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
63
64 /**
65 * Gallium screen/adapter context. Basically everything
66 * hardware-specific that doesn't actually require a rendering
67 * context.
68 */
69 struct pipe_screen {
70 void (*destroy)( struct pipe_screen * );
71
72 const char *(*get_name)( struct pipe_screen * );
73
74 const char *(*get_vendor)( struct pipe_screen * );
75
76 /**
77 * Returns the device vendor.
78 *
79 * The returned value should return the actual device vendor/manufacturer,
80 * rather than a potentially generic driver string.
81 */
82 const char *(*get_device_vendor)( struct pipe_screen * );
83
84 /**
85 * Query an integer-valued capability/parameter/limit
86 * \param param one of PIPE_CAP_x
87 */
88 int (*get_param)( struct pipe_screen *, enum pipe_cap param );
89
90 /**
91 * Query a float-valued capability/parameter/limit
92 * \param param one of PIPE_CAP_x
93 */
94 float (*get_paramf)( struct pipe_screen *, enum pipe_capf param );
95
96 /**
97 * Query a per-shader-stage integer-valued capability/parameter/limit
98 * \param param one of PIPE_CAP_x
99 */
100 int (*get_shader_param)( struct pipe_screen *, enum pipe_shader_type shader,
101 enum pipe_shader_cap param );
102
103 /**
104 * Query an integer-valued capability/parameter/limit for a codec/profile
105 * \param param one of PIPE_VIDEO_CAP_x
106 */
107 int (*get_video_param)( struct pipe_screen *,
108 enum pipe_video_profile profile,
109 enum pipe_video_entrypoint entrypoint,
110 enum pipe_video_cap param );
111
112 /**
113 * Query a compute-specific capability/parameter/limit.
114 * \param ir_type shader IR type for which the param applies, or don't care
115 * if the param is not shader related
116 * \param param one of PIPE_COMPUTE_CAP_x
117 * \param ret pointer to a preallocated buffer that will be
118 * initialized to the parameter value, or NULL.
119 * \return size in bytes of the parameter value that would be
120 * returned.
121 */
122 int (*get_compute_param)(struct pipe_screen *,
123 enum pipe_shader_ir ir_type,
124 enum pipe_compute_cap param,
125 void *ret);
126
127 /**
128 * Query a timestamp in nanoseconds. The returned value should match
129 * PIPE_QUERY_TIMESTAMP. This function returns immediately and doesn't
130 * wait for rendering to complete (which cannot be achieved with queries).
131 */
132 uint64_t (*get_timestamp)(struct pipe_screen *);
133
134 /**
135 * Create a context.
136 *
137 * \param screen pipe screen
138 * \param priv a pointer to set in pipe_context::priv
139 * \param flags a mask of PIPE_CONTEXT_* flags
140 */
141 struct pipe_context * (*context_create)(struct pipe_screen *screen,
142 void *priv, unsigned flags);
143
144 /**
145 * Check if the given pipe_format is supported as a texture or
146 * drawing surface.
147 * \param bindings bitmask of PIPE_BIND_*
148 */
149 boolean (*is_format_supported)( struct pipe_screen *,
150 enum pipe_format format,
151 enum pipe_texture_target target,
152 unsigned sample_count,
153 unsigned bindings );
154
155 /**
156 * Check if the given pipe_format is supported as output for this codec/profile.
157 * \param profile profile to check, may also be PIPE_VIDEO_PROFILE_UNKNOWN
158 */
159 boolean (*is_video_format_supported)( struct pipe_screen *,
160 enum pipe_format format,
161 enum pipe_video_profile profile,
162 enum pipe_video_entrypoint entrypoint );
163
164 /**
165 * Check if we can actually create the given resource (test the dimension,
166 * overall size, etc). Used to implement proxy textures.
167 * \return TRUE if size is OK, FALSE if too large.
168 */
169 boolean (*can_create_resource)(struct pipe_screen *screen,
170 const struct pipe_resource *templat);
171
172 /**
173 * Create a new texture object, using the given template info.
174 */
175 struct pipe_resource * (*resource_create)(struct pipe_screen *,
176 const struct pipe_resource *templat);
177
178 struct pipe_resource * (*resource_create_front)(struct pipe_screen *,
179 const struct pipe_resource *templat,
180 const void *map_front_private);
181
182 /**
183 * Create a texture from a winsys_handle. The handle is often created in
184 * another process by first creating a pipe texture and then calling
185 * resource_get_handle.
186 *
187 * NOTE: in the case of DRM_API_HANDLE_TYPE_FD handles, the caller
188 * retains ownership of the FD. (This is consistent with
189 * EGL_EXT_image_dma_buf_import)
190 *
191 * \param usage A combination of PIPE_HANDLE_USAGE_* flags.
192 */
193 struct pipe_resource * (*resource_from_handle)(struct pipe_screen *,
194 const struct pipe_resource *templat,
195 struct winsys_handle *handle,
196 unsigned usage);
197
198 /**
199 * Create a resource from user memory. This maps the user memory into
200 * the device address space.
201 */
202 struct pipe_resource * (*resource_from_user_memory)(struct pipe_screen *,
203 const struct pipe_resource *t,
204 void *user_memory);
205
206 /**
207 * Get a winsys_handle from a texture. Some platforms/winsys requires
208 * that the texture is created with a special usage flag like
209 * DISPLAYTARGET or PRIMARY.
210 *
211 * The context parameter can optionally be used to flush the resource and
212 * the context to make sure the resource is coherent with whatever user
213 * will use it. Some drivers may also use the context to convert
214 * the resource into a format compatible for sharing. The use case is
215 * OpenGL-OpenCL interop. The context parameter is allowed to be NULL.
216 *
217 * NOTE: in the case of DRM_API_HANDLE_TYPE_FD handles, the caller
218 * takes ownership of the FD. (This is consistent with
219 * EGL_MESA_image_dma_buf_export)
220 *
221 * \param usage A combination of PIPE_HANDLE_USAGE_* flags.
222 */
223 boolean (*resource_get_handle)(struct pipe_screen *,
224 struct pipe_context *context,
225 struct pipe_resource *tex,
226 struct winsys_handle *handle,
227 unsigned usage);
228
229 /**
230 * Mark the resource as changed so derived internal resources will be
231 * recreated on next use.
232 *
233 * This is necessary when reimporting external images that can't be directly
234 * used as texture sampler source, to avoid sampling from old copies.
235 */
236 void (*resource_changed)(struct pipe_screen *, struct pipe_resource *pt);
237
238 void (*resource_destroy)(struct pipe_screen *,
239 struct pipe_resource *pt);
240
241
242 /**
243 * Do any special operations to ensure frontbuffer contents are
244 * displayed, eg copy fake frontbuffer.
245 * \param winsys_drawable_handle an opaque handle that the calling context
246 * gets out-of-band
247 * \param subbox an optional sub region to flush
248 */
249 void (*flush_frontbuffer)( struct pipe_screen *screen,
250 struct pipe_resource *resource,
251 unsigned level, unsigned layer,
252 void *winsys_drawable_handle,
253 struct pipe_box *subbox );
254
255 /** Set ptr = fence, with reference counting */
256 void (*fence_reference)( struct pipe_screen *screen,
257 struct pipe_fence_handle **ptr,
258 struct pipe_fence_handle *fence );
259
260 /**
261 * Wait for the fence to finish.
262 *
263 * If the fence was created with PIPE_FLUSH_DEFERRED, and the context is
264 * still unflushed, and the ctx parameter of fence_finish is equal to
265 * the context where the fence was created, fence_finish will flush
266 * the context prior to waiting for the fence.
267 *
268 * In all other cases, the ctx parameter has no effect.
269 *
270 * \param timeout in nanoseconds (may be PIPE_TIMEOUT_INFINITE).
271 */
272 boolean (*fence_finish)(struct pipe_screen *screen,
273 struct pipe_context *ctx,
274 struct pipe_fence_handle *fence,
275 uint64_t timeout);
276
277 /**
278 * For fences created with PIPE_FLUSH_FENCE_FD (exported fd) or
279 * by create_fence_fd() (imported fd), return the native fence fd
280 * associated with the fence. This may return -1 for fences
281 * created with PIPE_FLUSH_DEFERRED if the fence command has not
282 * been flushed yet.
283 */
284 int (*fence_get_fd)(struct pipe_screen *screen,
285 struct pipe_fence_handle *fence);
286
287 /**
288 * Returns a driver-specific query.
289 *
290 * If \p info is NULL, the number of available queries is returned.
291 * Otherwise, the driver query at the specified \p index is returned
292 * in \p info. The function returns non-zero on success.
293 */
294 int (*get_driver_query_info)(struct pipe_screen *screen,
295 unsigned index,
296 struct pipe_driver_query_info *info);
297
298 /**
299 * Returns a driver-specific query group.
300 *
301 * If \p info is NULL, the number of available groups is returned.
302 * Otherwise, the driver query group at the specified \p index is returned
303 * in \p info. The function returns non-zero on success.
304 */
305 int (*get_driver_query_group_info)(struct pipe_screen *screen,
306 unsigned index,
307 struct pipe_driver_query_group_info *info);
308
309 /**
310 * Query information about memory usage.
311 */
312 void (*query_memory_info)(struct pipe_screen *screen,
313 struct pipe_memory_info *info);
314
315 /**
316 * Get IR specific compiler options struct. For PIPE_SHADER_IR_NIR this
317 * returns a 'struct nir_shader_compiler_options'. Drivers reporting
318 * NIR as the preferred IR must implement this.
319 */
320 const void *(*get_compiler_options)(struct pipe_screen *screen,
321 enum pipe_shader_ir ir,
322 enum pipe_shader_type shader);
323
324 /**
325 * Returns a pointer to a driver-specific on-disk shader cache. If the
326 * driver failed to create the cache or does not support an on-disk shader
327 * cache NULL is returned. The callback itself may also be NULL if the
328 * driver doesn't support an on-disk shader cache.
329 */
330 struct disk_cache *(*get_disk_shader_cache)(struct pipe_screen *screen);
331
332 /**
333 * Create a new texture object from the given template info, taking
334 * format modifiers into account. \p modifiers specifies a list of format
335 * modifier tokens, as defined in drm_fourcc.h. The driver then picks the
336 * best modifier among these and creates the resource. \p count must
337 * contain the size of \p modifiers array.
338 *
339 * Returns NULL if an entry in \p modifiers is unsupported by the driver,
340 * or if only DRM_FORMAT_MOD_INVALID is provided.
341 */
342 struct pipe_resource * (*resource_create_with_modifiers)(
343 struct pipe_screen *,
344 const struct pipe_resource *templat,
345 const uint64_t *modifiers, int count);
346 };
347
348
349 #ifdef __cplusplus
350 }
351 #endif
352
353 #endif /* P_SCREEN_H */