summaryrefslogtreecommitdiff
path: root/src/gallium/include/frontend/api.h
blob: 91b2b73a3a53b009420f04482ce5d6c16709fba5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
/**********************************************************
 * Copyright 2010 VMware, Inc.  All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 **********************************************************/


#ifndef _API_H_
#define _API_H_

#include "util/format/u_formats.h"

struct st_context;

/**
 * \file API for communication between gallium frontends and supporting
 * frontends such as DRI.
 *
 * This file defines an API to be implemented by both gallium frontends and
 * their managers.
 */

/**
 * The profile of a context.
 */
enum st_profile_type
{
   ST_PROFILE_DEFAULT,			/**< OpenGL compatibility profile */
   ST_PROFILE_OPENGL_CORE,		/**< OpenGL 3.2+ core profile */
   ST_PROFILE_OPENGL_ES1,		/**< OpenGL ES 1.x */
   ST_PROFILE_OPENGL_ES2		/**< OpenGL ES 2.0 */
};

/* for profile_mask in st_api */
#define ST_PROFILE_DEFAULT_MASK      (1 << ST_PROFILE_DEFAULT)
#define ST_PROFILE_OPENGL_CORE_MASK  (1 << ST_PROFILE_OPENGL_CORE)
#define ST_PROFILE_OPENGL_ES1_MASK   (1 << ST_PROFILE_OPENGL_ES1)
#define ST_PROFILE_OPENGL_ES2_MASK   (1 << ST_PROFILE_OPENGL_ES2)
#define ST_PROFILE_ALL_MASK          (ST_PROFILE_DEFAULT_MASK | \
                                      ST_PROFILE_OPENGL_CORE_MASK | \
                                      ST_PROFILE_OPENGL_ES1_MASK | \
                                      ST_PROFILE_OPENGL_ES2_MASK)

/**
 * New context flags for GL 3.0 and beyond.
 *
 * Profile information (core vs. compatibilty for OpenGL 3.2+) is communicated
 * through the \c st_profile_type, not through flags.
 */
#define ST_CONTEXT_FLAG_DEBUG               (1 << 0)
#define ST_CONTEXT_FLAG_FORWARD_COMPATIBLE  (1 << 1)
#define ST_CONTEXT_FLAG_ROBUST_ACCESS       (1 << 2)
#define ST_CONTEXT_FLAG_RESET_NOTIFICATION_ENABLED (1 << 3)
#define ST_CONTEXT_FLAG_NO_ERROR            (1 << 4)
#define ST_CONTEXT_FLAG_RELEASE_NONE	    (1 << 5)
#define ST_CONTEXT_FLAG_HIGH_PRIORITY       (1 << 6)
#define ST_CONTEXT_FLAG_LOW_PRIORITY        (1 << 7)
#define ST_CONTEXT_FLAG_PROTECTED           (1 << 8)

/**
 * Reasons that context creation might fail.
 */
enum st_context_error {
   ST_CONTEXT_SUCCESS = 0,
   ST_CONTEXT_ERROR_NO_MEMORY,
   ST_CONTEXT_ERROR_BAD_API,
   ST_CONTEXT_ERROR_BAD_VERSION,
   ST_CONTEXT_ERROR_BAD_FLAG,
   ST_CONTEXT_ERROR_UNKNOWN_ATTRIBUTE,
   ST_CONTEXT_ERROR_UNKNOWN_FLAG
};

/**
 * Used in st_context_teximage.
 */
enum st_texture_type {
   ST_TEXTURE_1D,
   ST_TEXTURE_2D,
   ST_TEXTURE_3D,
   ST_TEXTURE_RECT
};

/**
 * Available attachments of framebuffer.
 */
enum st_attachment_type {
   ST_ATTACHMENT_FRONT_LEFT,
   ST_ATTACHMENT_BACK_LEFT,
   ST_ATTACHMENT_FRONT_RIGHT,
   ST_ATTACHMENT_BACK_RIGHT,
   ST_ATTACHMENT_DEPTH_STENCIL,
   ST_ATTACHMENT_ACCUM,

   ST_ATTACHMENT_COUNT,
   ST_ATTACHMENT_INVALID = -1
};

/* for buffer_mask in st_visual */
#define ST_ATTACHMENT_FRONT_LEFT_MASK     (1 << ST_ATTACHMENT_FRONT_LEFT)
#define ST_ATTACHMENT_BACK_LEFT_MASK      (1 << ST_ATTACHMENT_BACK_LEFT)
#define ST_ATTACHMENT_FRONT_RIGHT_MASK    (1 << ST_ATTACHMENT_FRONT_RIGHT)
#define ST_ATTACHMENT_BACK_RIGHT_MASK     (1 << ST_ATTACHMENT_BACK_RIGHT)
#define ST_ATTACHMENT_DEPTH_STENCIL_MASK  (1 << ST_ATTACHMENT_DEPTH_STENCIL)
#define ST_ATTACHMENT_ACCUM_MASK          (1 << ST_ATTACHMENT_ACCUM)

/**
 * Flush flags.
 */
#define ST_FLUSH_FRONT                    (1 << 0)
#define ST_FLUSH_END_OF_FRAME             (1 << 1)
#define ST_FLUSH_WAIT                     (1 << 2)
#define ST_FLUSH_FENCE_FD                 (1 << 3)

/**
 * State invalidation flags to notify frontends that states have been changed
 * behind their back.
 */
#define ST_INVALIDATE_FS_SAMPLER_VIEWS    (1 << 0)
#define ST_INVALIDATE_FS_CONSTBUF0        (1 << 1)
#define ST_INVALIDATE_VS_CONSTBUF0        (1 << 2)
#define ST_INVALIDATE_VERTEX_BUFFERS      (1 << 3)
#define ST_INVALIDATE_FB_STATE            (1 << 4)

/**
 * Value to st_manager->get_param function.
 */
enum st_manager_param {
   /**
    * The DRI frontend on old libGL's doesn't do the right thing
    * with regards to invalidating the framebuffers.
    *
    * For the GL gallium frontend that means that it needs to invalidate
    * the framebuffer in glViewport itself.
    */
   ST_MANAGER_BROKEN_INVALIDATE
};

struct pipe_context;
struct pipe_resource;
struct pipe_fence_handle;
struct util_queue_monitoring;

/**
 * Used in st_manager_iface->get_egl_image.
 */
struct st_egl_image
{
   /* this is owned by the caller */
   struct pipe_resource *texture;

   /* format only differs from texture->format for multi-planar (YUV): */
   enum pipe_format format;

   unsigned level;
   unsigned layer;
   /* GL internal format. */
   unsigned internalformat;

   /* one of __DRI_YUV_COLOR_SPACE_* */
   unsigned yuv_color_space;

   /* one of __DRI_YUV_RANGE_* */
   unsigned yuv_range;

   bool imported_dmabuf;
};

/**
 * Represent the visual of a framebuffer.
 */
struct st_visual
{
   /**
    * Available buffers.  Bitfield of ST_ATTACHMENT_*_MASK bits.
    */
   unsigned buffer_mask;

   /**
    * Buffer formats.  The formats are always set even when the buffer is
    * not available.
    */
   enum pipe_format color_format;
   enum pipe_format depth_stencil_format;
   enum pipe_format accum_format;
   unsigned samples;
};


/**
 * Configuration options from driconf
 */
struct st_config_options
{
   bool disable_blend_func_extended;
   bool disable_glsl_line_continuations;
   bool disable_arb_gpu_shader5;
   bool force_compat_shaders;
   bool force_glsl_extensions_warn;
   unsigned force_glsl_version;
   bool allow_extra_pp_tokens;
   bool allow_glsl_extension_directive_midshader;
   bool allow_glsl_120_subset_in_110;
   bool allow_glsl_builtin_const_expression;
   bool allow_glsl_relaxed_es;
   bool allow_glsl_builtin_variable_redeclaration;
   bool allow_higher_compat_version;
   bool allow_glsl_compat_shaders;
   bool glsl_ignore_write_to_readonly_var;
   bool glsl_zero_init;
   bool vs_position_always_invariant;
   bool vs_position_always_precise;
   bool force_glsl_abs_sqrt;
   bool allow_glsl_cross_stage_interpolation_mismatch;
   bool do_dce_before_clip_cull_analysis;
   bool allow_draw_out_of_order;
   bool glthread_nop_check_framebuffer_status;
   bool ignore_map_unsynchronized;
   bool force_integer_tex_nearest;
   bool force_gl_names_reuse;
   bool force_gl_map_buffer_synchronized;
   bool transcode_etc;
   bool transcode_astc;
   char *force_gl_vendor;
   char *force_gl_renderer;
   char *mesa_extension_override;
   unsigned char config_options_sha1[20];
};

/**
 * Represent the attributes of a context.
 */
struct st_context_attribs
{
   /**
    * The profile and minimal version to support.
    *
    * The valid profiles and versions are rendering API dependent.  The latest
    * version satisfying the request should be returned.
    */
   enum st_profile_type profile;
   int major, minor;

   /** Mask of ST_CONTEXT_FLAG_x bits */
   unsigned flags;

   /**
    * The visual of the framebuffers the context will be bound to.
    */
   struct st_visual visual;

   /**
    * Configuration options.
    */
   struct st_config_options options;
};

struct pipe_frontend_screen;

/**
 * Represent a windowing system drawable.
 *
 * The framebuffer is implemented by the frontend manager and
 * used by gallium frontends.
 *
 * Instead of the winsys poking into the frontend context to figure
 * out what buffers that might be needed in the future by the frontend
 * context, it calls into the framebuffer to get the textures.
 *
 * This structure along with the notify_invalid_framebuffer
 * allows framebuffers to be shared between different threads
 * but at the same make the API context free from thread
 * synchronization primitves, with the exception of a small
 * atomic flag used for notification of framebuffer dirty status.
 *
 * The thread synchronization is put inside the framebuffer
 * and only called once the framebuffer has become dirty.
 */
struct st_framebuffer_iface
{
   /**
    * Atomic stamp which changes when framebuffers need to be updated.
    */
   int32_t stamp;

   /**
    * Identifier that uniquely identifies the framebuffer interface object.
    */
   uint32_t ID;

   /**
    * The frontend manager that manages this object.
    */
   struct pipe_frontend_screen *fscreen;

   /**
    * Available for the frontend manager to use.
    */
   void *st_manager_private;

   /**
    * The visual of a framebuffer.
    */
   const struct st_visual *visual;

   /**
    * Flush the front buffer.
    *
    * On some window systems, changes to the front buffers are not immediately
    * visible.  They need to be flushed.
    *
    * @att is one of the front buffer attachments.
    */
   bool (*flush_front)(struct st_context *st,
                       struct st_framebuffer_iface *stfbi,
                       enum st_attachment_type statt);

   /**
    * the gallium frontend asks for the textures it needs.
    *
    * It should try to only ask for attachments that it currently renders
    * to, thus allowing the winsys to delay the allocation of textures not
    * needed. For example front buffer attachments are not needed if you
    * only do back buffer rendering.
    *
    * The implementor of this function needs to also ensure
    * thread safty as this call might be done from multiple threads.
    *
    * The returned textures are owned by the caller.  They should be
    * unreferenced when no longer used.  If this function is called multiple
    * times with different sets of attachments, those buffers not included in
    * the last call might be destroyed.  This behavior might change in the
    * future.
    */
   bool (*validate)(struct st_context *st,
                    struct st_framebuffer_iface *stfbi,
                    const enum st_attachment_type *statts,
                    unsigned count,
                    struct pipe_resource **out);
   bool (*flush_swapbuffers)(struct st_context *st,
                             struct st_framebuffer_iface *stfbi);
};


/**
 * This is inherited by a screen in the DRI/GLX/WGL frontends, e.g. dri_screen.
 */
struct pipe_frontend_screen
{
   struct pipe_screen *screen;

   /**
    * Look up and return the info of an EGLImage.
    *
    * This is used to implement for example EGLImageTargetTexture2DOES.
    * The GLeglImageOES agrument of that call is passed directly to this
    * function call and the information needed to access this is returned
    * in the given struct out.
    *
    * @fscreen: manager owning the caller context
    * @stctx: caller context
    * @egl_image: EGLImage that caller recived
    * @out: return struct filled out with access information.
    *
    * This function is optional.
    */
   bool (*get_egl_image)(struct pipe_frontend_screen *fscreen,
                         void *egl_image,
                         struct st_egl_image *out);

   /**
    * Validate EGLImage passed to get_egl_image.
    */
   bool (*validate_egl_image)(struct pipe_frontend_screen *fscreen,
                              void *egl_image);

   /**
    * Query an manager param.
    */
   int (*get_param)(struct pipe_frontend_screen *fscreen,
                    enum st_manager_param param);

   /**
    * Call the loader function setBackgroundContext. Called from the worker
    * thread.
    */
   void (*set_background_context)(struct st_context *st,
                                  struct util_queue_monitoring *queue_info);

   /**
    * Destroy any private data used by the frontend manager.
    */
   void (*destroy)(struct pipe_frontend_screen *fscreen);

   /**
    * Available for the frontend manager to use.
    */
   void *st_manager_private;
};

/**
 * The following st_api_* functions represent the OpenGL rendering API.
 *
 * Implemented by the gallium frontend and used by the frontend manager.
 */

/**
 * Query supported OpenGL versions. (if applicable)
 * The format is (major*10+minor).
 */
void
st_api_query_versions(struct pipe_frontend_screen *fscreen,
                      struct st_config_options *options,
                      int *gl_core_version,
                      int *gl_compat_version,
                      int *gl_es1_version,
                      int *gl_es2_version);

/**
 * Create a rendering context.
 */
struct st_context *
st_api_create_context(struct pipe_frontend_screen *fscreen,
                      const struct st_context_attribs *attribs,
                      enum st_context_error *error,
                      struct st_context *shared_ctx);

/**
 * Bind the context to the calling thread with draw and read as drawables.
 *
 * The framebuffers might be NULL, or might have different visuals than the
 * context does.
 */
bool
st_api_make_current(struct st_context *st,
                    struct st_framebuffer_iface *stdrawi,
                    struct st_framebuffer_iface *streadi);

/**
 * Get the currently bound context in the calling thread.
 */
struct st_context *
st_api_get_current(void);

/**
 * Notify the st manager the framebuffer interface object
 * is no longer valid.
 */
void
st_api_destroy_drawable(struct st_framebuffer_iface *stfbi);

#endif /* _API_H_ */