OSDN Git Service

st/mesa: remove ST_NEW_MESA flag (v2)
[android-x86/external-mesa.git] / src / mesa / state_tracker / st_context.h
1 /**************************************************************************
2  * 
3  * Copyright 2003 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 #ifndef ST_CONTEXT_H
29 #define ST_CONTEXT_H
30
31 #include "main/mtypes.h"
32 #include "pipe/p_state.h"
33 #include "state_tracker/st_api.h"
34 #include "main/fbobject.h"
35
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41
42 struct bitmap_cache;
43 struct dd_function_table;
44 struct draw_context;
45 struct draw_stage;
46 struct gen_mipmap_state;
47 struct st_context;
48 struct st_fragment_program;
49 struct st_perf_monitor_group;
50 struct u_upload_mgr;
51
52
53 /* gap  */
54 #define ST_NEW_FRAGMENT_PROGRAM        (1 << 1)
55 #define ST_NEW_VERTEX_PROGRAM          (1 << 2)
56 #define ST_NEW_FRAMEBUFFER             (1 << 3)
57 #define ST_NEW_TESS_STATE              (1 << 4)
58 #define ST_NEW_GEOMETRY_PROGRAM        (1 << 5)
59 #define ST_NEW_VERTEX_ARRAYS           (1 << 6)
60 #define ST_NEW_RASTERIZER              (1 << 7)
61 #define ST_NEW_UNIFORM_BUFFER          (1 << 8)
62 #define ST_NEW_TESSCTRL_PROGRAM        (1 << 9)
63 #define ST_NEW_TESSEVAL_PROGRAM        (1 << 10)
64 #define ST_NEW_SAMPLER_VIEWS           (1 << 11)
65 #define ST_NEW_ATOMIC_BUFFER           (1 << 12)
66 #define ST_NEW_STORAGE_BUFFER          (1 << 13)
67 #define ST_NEW_COMPUTE_PROGRAM         (1 << 14)
68 #define ST_NEW_IMAGE_UNITS             (1 << 15)
69
70
71 struct st_state_flags {
72    GLbitfield mesa;  /**< Mask of _NEW_x flags */
73    uint64_t st;      /**< Mask of ST_NEW_x flags */
74 };
75
76 struct st_tracked_state {
77    const char *name;
78    struct st_state_flags dirty;
79    void (*update)( struct st_context *st );
80 };
81
82
83 /**
84  * Enumeration of state tracker pipelines.
85  */
86 enum st_pipeline {
87    ST_PIPELINE_RENDER,
88    ST_PIPELINE_COMPUTE,
89 };
90
91
92 /** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
93 struct st_util_vertex
94 {
95    float x, y, z;
96    float r, g, b, a;
97    float s, t;
98 };
99
100
101 struct st_context
102 {
103    struct st_context_iface iface;
104
105    struct gl_context *ctx;
106
107    struct pipe_context *pipe;
108
109    struct u_upload_mgr *uploader, *indexbuf_uploader, *constbuf_uploader;
110
111    struct draw_context *draw;  /**< For selection/feedback/rastpos only */
112    struct draw_stage *feedback_stage;  /**< For GL_FEEDBACK rendermode */
113    struct draw_stage *selection_stage;  /**< For GL_SELECT rendermode */
114    struct draw_stage *rastpos_stage;  /**< For glRasterPos */
115    GLboolean clamp_frag_color_in_shader;
116    GLboolean clamp_vert_color_in_shader;
117    boolean has_stencil_export; /**< can do shader stencil export? */
118    boolean has_time_elapsed;
119    boolean has_shader_model3;
120    boolean has_etc1;
121    boolean has_etc2;
122    boolean prefer_blit_based_texture_transfer;
123    boolean force_persample_in_shader;
124    boolean has_shareable_shaders;
125    boolean has_half_float_packing;
126    boolean has_multi_draw_indirect;
127
128    /**
129     * If a shader can be created when we get its source.
130     * This means it has only 1 variant, not counting glBitmap and
131     * glDrawPixels.
132     */
133    boolean shader_has_one_variant[MESA_SHADER_STAGES];
134
135    boolean needs_texcoord_semantic;
136    boolean apply_texture_swizzle_to_border_color;
137
138    /* On old libGL's for linux we need to invalidate the drawables
139     * on glViewpport calls, this is set via a option.
140     */
141    boolean invalidate_on_gl_viewport;
142
143    boolean vertex_array_out_of_memory;
144
145    /* Some state is contained in constant objects.
146     * Other state is just parameter values.
147     */
148    struct {
149       struct pipe_blend_state               blend;
150       struct pipe_depth_stencil_alpha_state depth_stencil;
151       struct pipe_rasterizer_state          rasterizer;
152       struct pipe_sampler_state samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
153       GLuint num_samplers[PIPE_SHADER_TYPES];
154       struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
155       GLuint num_sampler_views[PIPE_SHADER_TYPES];
156       struct pipe_clip_state clip;
157       struct {
158          void *ptr;
159          unsigned size;
160       } constants[PIPE_SHADER_TYPES];
161       struct pipe_framebuffer_state framebuffer;
162       struct pipe_scissor_state scissor[PIPE_MAX_VIEWPORTS];
163       struct pipe_viewport_state viewport[PIPE_MAX_VIEWPORTS];
164       unsigned sample_mask;
165
166       GLuint poly_stipple[32];  /**< In OpenGL's bottom-to-top order */
167
168       GLuint fb_orientation;
169    } state;
170
171    char vendor[100];
172    char renderer[100];
173
174    struct st_state_flags dirty;
175    struct st_state_flags dirty_cp;
176
177    GLboolean vertdata_edgeflags;
178    GLboolean edgeflag_culls_prims;
179
180    /** Mapping from VARYING_SLOT_x to post-transformed vertex slot */
181    const GLuint *vertex_result_to_slot;
182
183    struct st_vertex_program *vp;    /**< Currently bound vertex program */
184    struct st_fragment_program *fp;  /**< Currently bound fragment program */
185    struct st_geometry_program *gp;  /**< Currently bound geometry program */
186    struct st_tessctrl_program *tcp; /**< Currently bound tess control program */
187    struct st_tesseval_program *tep; /**< Currently bound tess eval program */
188    struct st_compute_program *cp;   /**< Currently bound compute program */
189
190    struct st_vp_variant *vp_variant;
191    struct st_fp_variant *fp_variant;
192    struct st_basic_variant *gp_variant;
193    struct st_basic_variant *tcp_variant;
194    struct st_basic_variant *tep_variant;
195    struct st_basic_variant *cp_variant;
196
197    struct gl_texture_object *default_texture;
198
199    struct {
200       struct pipe_resource *pixelmap_texture;
201       struct pipe_sampler_view *pixelmap_sampler_view;
202    } pixel_xfer;
203
204    /** for glBitmap */
205    struct {
206       struct pipe_rasterizer_state rasterizer;
207       struct pipe_sampler_state sampler;
208       struct pipe_sampler_state atlas_sampler;
209       enum pipe_format tex_format;
210       void *vs;
211       struct bitmap_cache *cache;
212    } bitmap;
213
214    /** for glDraw/CopyPixels */
215    struct {
216       void *zs_shaders[4];
217       void *vert_shaders[2];   /**< ureg shaders */
218    } drawpix;
219
220    struct {
221       GLsizei width, height;
222       GLenum format, type;
223       const void *user_pointer;  /**< Last user 'pixels' pointer */
224       void *image;               /**< Copy of the glDrawPixels image data */
225       struct pipe_resource *texture;
226    } drawpix_cache;
227
228    /** for glClear */
229    struct {
230       struct pipe_rasterizer_state raster;
231       struct pipe_viewport_state viewport;
232       void *vs;
233       void *fs;
234       void *vs_layered;
235       void *gs_layered;
236    } clear;
237
238    /* For gl(Compressed)Tex(Sub)Image */
239    struct {
240       struct pipe_rasterizer_state raster;
241       struct pipe_blend_state blend;
242       void *vs;
243       void *gs;
244       void *fs;
245       bool enabled;
246       bool rgba_only;
247       bool upload_layers;
248       bool use_gs;
249    } pbo_upload;
250
251    /** for drawing with st_util_vertex */
252    struct pipe_vertex_element util_velems[3];
253
254    void *passthrough_fs;  /**< simple pass-through frag shader */
255
256    enum pipe_texture_target internal_target;
257
258    struct cso_context *cso_context;
259
260    void *winsys_drawable_handle;
261
262    /* The number of vertex buffers from the last call of validate_arrays. */
263    unsigned last_num_vbuffers;
264
265    int32_t draw_stamp;
266    int32_t read_stamp;
267
268    struct st_config_options options;
269
270    struct st_perf_monitor_group *perfmon;
271 };
272
273
274 /* Need this so that we can implement Mesa callbacks in this module.
275  */
276 static inline struct st_context *st_context(struct gl_context *ctx)
277 {
278    return ctx->st;
279 }
280
281
282 /**
283  * Wrapper for struct gl_framebuffer.
284  * This is an opaque type to the outside world.
285  */
286 struct st_framebuffer
287 {
288    struct gl_framebuffer Base;
289    void *Private;
290
291    struct st_framebuffer_iface *iface;
292    enum st_attachment_type statts[ST_ATTACHMENT_COUNT];
293    unsigned num_statts;
294    int32_t stamp;
295    int32_t iface_stamp;
296 };
297
298
299 extern void st_init_driver_functions(struct pipe_screen *screen,
300                                      struct dd_function_table *functions);
301
302 void st_invalidate_state(struct gl_context * ctx, GLbitfield new_state);
303
304
305
306 #define Y_0_TOP 1
307 #define Y_0_BOTTOM 2
308
309 static inline GLuint
310 st_fb_orientation(const struct gl_framebuffer *fb)
311 {
312    if (fb && _mesa_is_winsys_fbo(fb)) {
313       /* Drawing into a window (on-screen buffer).
314        *
315        * Negate Y scale to flip image vertically.
316        * The NDC Y coords prior to viewport transformation are in the range
317        * [y=-1=bottom, y=1=top]
318        * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
319        * H is the window height.
320        * Use the viewport transformation to invert Y.
321        */
322       return Y_0_TOP;
323    }
324    else {
325       /* Drawing into user-created FBO (very likely a texture).
326        *
327        * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
328        */
329       return Y_0_BOTTOM;
330    }
331 }
332
333
334 static inline unsigned
335 st_shader_stage_to_ptarget(gl_shader_stage stage)
336 {
337    switch (stage) {
338    case MESA_SHADER_VERTEX:
339       return PIPE_SHADER_VERTEX;
340    case MESA_SHADER_FRAGMENT:
341       return PIPE_SHADER_FRAGMENT;
342    case MESA_SHADER_GEOMETRY:
343       return PIPE_SHADER_GEOMETRY;
344    case MESA_SHADER_TESS_CTRL:
345       return PIPE_SHADER_TESS_CTRL;
346    case MESA_SHADER_TESS_EVAL:
347       return PIPE_SHADER_TESS_EVAL;
348    case MESA_SHADER_COMPUTE:
349       return PIPE_SHADER_COMPUTE;
350    }
351
352    assert(!"should not be reached");
353    return PIPE_SHADER_VERTEX;
354 }
355
356
357 /** clear-alloc a struct-sized object, with casting */
358 #define ST_CALLOC_STRUCT(T)   (struct T *) calloc(1, sizeof(struct T))
359
360
361 extern struct st_context *
362 st_create_context(gl_api api, struct pipe_context *pipe,
363                   const struct gl_config *visual,
364                   struct st_context *share,
365                   const struct st_config_options *options);
366
367 extern void
368 st_destroy_context(struct st_context *st);
369
370
371 #ifdef __cplusplus
372 }
373 #endif
374
375 #endif