Merge branch 'master' into i915-superioctl
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_context.h
1 /**************************************************************************
2
3 Copyright 2006 Stephane Marchesin
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 "Software"),
8 to deal in the Software without restriction, including without limitation
9 on the rights to use, copy, modify, merge, publish, distribute, sub
10 license, and/or sell copies of the Software, and to permit persons to whom
11 the Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice (including the next
14 paragraph) shall be included in all copies or substantial portions of the
15 Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
21 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 **************************************************************************/
26
27
28
29 #ifndef __NOUVEAU_CONTEXT_H__
30 #define __NOUVEAU_CONTEXT_H__
31
32 #include "dri_util.h"
33 #include "drm.h"
34 #include "nouveau_drm.h"
35
36 #include "mtypes.h"
37 #include "tnl/t_vertex.h"
38
39 #include "nouveau_fbo.h"
40 #include "nouveau_screen.h"
41 #include "nouveau_shader.h"
42 #include "nouveau_state_cache.h"
43 #include "nouveau_sync.h"
44
45 #include "xmlconfig.h"
46
47 typedef struct nouveau_fifo {
48 struct drm_nouveau_channel_alloc drm;
49 uint32_t *pushbuf;
50 uint32_t *mmio;
51 uint32_t *notifier_block;
52 uint32_t current;
53 uint32_t put;
54 uint32_t free;
55 uint32_t max;
56 } nouveau_fifo_t;
57
58 #define TAG(x) nouveau##x
59 #include "tnl_dd/t_dd_vertex.h"
60 #undef TAG
61
62 /* Subpixel offsets for window coordinates (triangles): */
63 #define SUBPIXEL_X (0.0F)
64 #define SUBPIXEL_Y (0.125F)
65
66 struct nouveau_context;
67
68 typedef void (*nouveau_tri_func)( struct nouveau_context*,
69 nouveauVertex *,
70 nouveauVertex *,
71 nouveauVertex * );
72
73 typedef void (*nouveau_line_func)( struct nouveau_context*,
74 nouveauVertex *,
75 nouveauVertex * );
76
77 typedef void (*nouveau_point_func)( struct nouveau_context*,
78 nouveauVertex * );
79
80 typedef struct nouveau_hw_func_t {
81 /* Initialise any card-specific non-GL related state */
82 GLboolean (*InitCard)(struct nouveau_context *);
83 /* Update buffer offset/pitch/format */
84 GLboolean (*BindBuffers)(struct nouveau_context *, int num_color,
85 nouveau_renderbuffer_t **color,
86 nouveau_renderbuffer_t *depth);
87 /* Update anything that depends on the window position/size */
88 void (*WindowMoved)(struct nouveau_context *);
89
90 /* Update projection matrix */
91 void (*UpdateProjectionMatrix)(GLcontext *);
92
93 /* Update modelview matrix (used for lighting and vertex weight) */
94 void (*UpdateModelviewMatrix)(GLcontext *);
95 } nouveau_hw_func;
96
97 typedef struct nouveau_context {
98 /* Mesa context */
99 GLcontext *glCtx;
100
101 /* The per-context fifo */
102 nouveau_fifo_t fifo;
103
104 /* Physical addresses of AGP/VRAM apertures */
105 uint64_t vram_phys;
106 uint64_t vram_size;
107 uint64_t gart_phys;
108 uint64_t gart_size;
109
110 /* Channel synchronisation */
111 struct drm_nouveau_notifierobj_alloc *syncNotifier;
112
113 /* ARB_occlusion_query / EXT_timer_query */
114 GLuint query_object_max;
115 GLboolean * query_alloc;
116 struct drm_nouveau_notifierobj_alloc *queryNotifier;
117
118 /* Additional hw-specific functions */
119 nouveau_hw_func hw_func;
120
121 /* FIXME : do we want to put all state into a separate struct ? */
122 /* State for tris */
123 GLuint color_offset;
124 GLuint specular_offset;
125
126 /* Vertex state */
127 GLuint vertex_size;
128 GLubyte *verts;
129 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
130 GLuint vertex_attr_count;
131
132 /* Color and depth renderbuffers */
133 nouveau_renderbuffer_t *color_buffer;
134 nouveau_renderbuffer_t *depth_buffer;
135
136 /* Depth/stencil clear value */
137 uint32_t clear_value;
138
139 /* Light state */
140 GLboolean lighting_enabled;
141 uint32_t enabled_lights;
142
143 /* Cached state */
144 nouveau_state_cache state_cache;
145
146 /* The drawing fallbacks */
147 GLuint Fallback;
148 nouveau_tri_func draw_tri;
149 nouveau_line_func draw_line;
150 nouveau_point_func draw_point;
151
152 /* Cliprects information */
153 GLuint numClipRects;
154 drm_clip_rect_t *pClipRects;
155 drm_clip_rect_t osClipRect;
156 GLuint drawX, drawY, drawW, drawH;
157
158 /* The rendering context information */
159 GLenum current_primitive; /* the current primitive enum */
160 DECLARE_RENDERINPUTS(render_inputs_bitset); /* the current render inputs */
161
162 /* Shader state */
163 nvsFunc VPfunc;
164 nvsFunc FPfunc;
165 nouveauShader *current_fragprog;
166 nouveauShader *current_vertprog;
167 nouveauShader *passthrough_vp;
168 nouveauShader *passthrough_fp;
169
170 nouveauScreenRec *screen;
171 struct drm_nouveau_sarea *sarea;
172
173 __DRIcontextPrivate *driContext; /* DRI context */
174 __DRIscreenPrivate *driScreen; /* DRI screen */
175 __DRIdrawablePrivate *driDrawable; /* DRI drawable bound to this ctx */
176 GLint lastStamp;
177
178 drm_context_t hHWContext;
179 drm_hw_lock_t *driHwLock;
180 int driFd;
181
182 /* Configuration cache */
183 driOptionCache optionCache;
184
185 /* vblank stuff */
186 uint32_t vblank_flags;
187 uint32_t vblank_seq;
188
189 GLuint new_state;
190 GLuint new_render_state;
191 GLuint render_index;
192 GLmatrix viewport;
193 GLfloat depth_scale;
194
195 }nouveauContextRec, *nouveauContextPtr;
196
197
198 #define NOUVEAU_CONTEXT(ctx) ((nouveauContextPtr)(ctx->DriverCtx))
199
200 /* Flags for software fallback cases: */
201 #define NOUVEAU_FALLBACK_TEXTURE 0x0001
202 #define NOUVEAU_FALLBACK_DRAW_BUFFER 0x0002
203 #define NOUVEAU_FALLBACK_READ_BUFFER 0x0004
204 #define NOUVEAU_FALLBACK_STENCIL 0x0008
205 #define NOUVEAU_FALLBACK_RENDER_MODE 0x0010
206 #define NOUVEAU_FALLBACK_LOGICOP 0x0020
207 #define NOUVEAU_FALLBACK_SEP_SPECULAR 0x0040
208 #define NOUVEAU_FALLBACK_BLEND_EQ 0x0080
209 #define NOUVEAU_FALLBACK_BLEND_FUNC 0x0100
210 #define NOUVEAU_FALLBACK_PROJTEX 0x0200
211 #define NOUVEAU_FALLBACK_DISABLE 0x0400
212
213
214 extern GLboolean nouveauCreateContext( const __GLcontextModes *glVisual,
215 __DRIcontextPrivate *driContextPriv,
216 void *sharedContextPrivate );
217
218 extern void nouveauDestroyContext( __DRIcontextPrivate * );
219
220 extern GLboolean nouveauMakeCurrent( __DRIcontextPrivate *driContextPriv,
221 __DRIdrawablePrivate *driDrawPriv,
222 __DRIdrawablePrivate *driReadPriv );
223
224 extern GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv );
225
226 extern void nouveauDoSwapBuffers(nouveauContextPtr nmesa,
227 __DRIdrawablePrivate *dPriv);
228
229 extern void nouveauSwapBuffers(__DRIdrawablePrivate *dPriv);
230
231 extern void nouveauCopySubBuffer(__DRIdrawablePrivate *dPriv,
232 int x, int y, int w, int h);
233
234 extern void nouveauClearBuffer(GLcontext *ctx, nouveau_renderbuffer_t *buffer,
235 int fill, int mask);
236
237 /* Debugging utils: */
238 extern int NOUVEAU_DEBUG;
239
240 #define DEBUG_SHADERS 0x00000001
241 #define DEBUG_MEM 0x00000002
242 #define DEBUG_BUFFEROBJ 0x00000004
243
244 #endif /* __NOUVEAU_CONTEXT_H__ */
245