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