nouveau: nv10: only one color buffer atm
[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 } nouveau_hw_func;
90
91 typedef struct nouveau_context {
92 /* Mesa context */
93 GLcontext *glCtx;
94
95 /* The per-context fifo */
96 nouveau_fifo_t fifo;
97
98 /* Physical addresses of AGP/VRAM apertures */
99 uint64_t vram_phys;
100 uint64_t vram_size;
101 uint64_t gart_phys;
102 uint64_t gart_size;
103
104 /* Channel synchronisation */
105 struct drm_nouveau_notifierobj_alloc *syncNotifier;
106
107 /* ARB_occlusion_query / EXT_timer_query */
108 GLuint query_object_max;
109 GLboolean * query_alloc;
110 struct drm_nouveau_notifierobj_alloc *queryNotifier;
111
112 /* Additional hw-specific functions */
113 nouveau_hw_func hw_func;
114
115 /* FIXME : do we want to put all state into a separate struct ? */
116 /* State for tris */
117 GLuint color_offset;
118 GLuint specular_offset;
119
120 /* Vertex state */
121 GLuint vertex_size;
122 GLubyte *verts;
123 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
124 GLuint vertex_attr_count;
125
126 /* Color and depth renderbuffers */
127 nouveau_renderbuffer_t *color_buffer;
128 nouveau_renderbuffer_t *depth_buffer;
129
130 /* Color buffer clear value */
131 uint32_t clear_color_value;
132
133 /* Depth/stencil clear value */
134 uint32_t clear_value;
135
136 /* Light state */
137 GLboolean lighting_enabled;
138 uint32_t enabled_lights;
139
140 /* Cached state */
141 nouveau_state_cache state_cache;
142
143 /* The drawing fallbacks */
144 GLuint Fallback;
145 nouveau_tri_func draw_tri;
146 nouveau_line_func draw_line;
147 nouveau_point_func draw_point;
148
149 /* Cliprects information */
150 GLuint numClipRects;
151 drm_clip_rect_t *pClipRects;
152 drm_clip_rect_t osClipRect;
153 GLuint drawX, drawY, drawW, drawH;
154
155 /* The rendering context information */
156 GLenum current_primitive; /* the current primitive enum */
157 DECLARE_RENDERINPUTS(render_inputs_bitset); /* the current render inputs */
158
159 /* Shader state */
160 nvsFunc VPfunc;
161 nvsFunc FPfunc;
162 nouveauShader *current_fragprog;
163 nouveauShader *current_vertprog;
164 nouveauShader *passthrough_vp;
165 nouveauShader *passthrough_fp;
166
167 nouveauScreenRec *screen;
168 struct drm_nouveau_sarea *sarea;
169
170 __DRIcontextPrivate *driContext; /* DRI context */
171 __DRIscreenPrivate *driScreen; /* DRI screen */
172 __DRIdrawablePrivate *driDrawable; /* DRI drawable bound to this ctx */
173 GLint lastStamp;
174
175 drm_context_t hHWContext;
176 drm_hw_lock_t *driHwLock;
177 int driFd;
178
179 /* Configuration cache */
180 driOptionCache optionCache;
181
182 /* vblank stuff */
183 uint32_t vblank_flags;
184 uint32_t vblank_seq;
185
186 GLuint new_state;
187 GLuint new_render_state;
188 GLuint render_index;
189 GLmatrix viewport;
190 GLfloat depth_scale;
191
192 }nouveauContextRec, *nouveauContextPtr;
193
194
195 #define NOUVEAU_CONTEXT(ctx) ((nouveauContextPtr)(ctx->DriverCtx))
196
197 /* Flags for software fallback cases: */
198 #define NOUVEAU_FALLBACK_TEXTURE 0x0001
199 #define NOUVEAU_FALLBACK_DRAW_BUFFER 0x0002
200 #define NOUVEAU_FALLBACK_READ_BUFFER 0x0004
201 #define NOUVEAU_FALLBACK_STENCIL 0x0008
202 #define NOUVEAU_FALLBACK_RENDER_MODE 0x0010
203 #define NOUVEAU_FALLBACK_LOGICOP 0x0020
204 #define NOUVEAU_FALLBACK_SEP_SPECULAR 0x0040
205 #define NOUVEAU_FALLBACK_BLEND_EQ 0x0080
206 #define NOUVEAU_FALLBACK_BLEND_FUNC 0x0100
207 #define NOUVEAU_FALLBACK_PROJTEX 0x0200
208 #define NOUVEAU_FALLBACK_DISABLE 0x0400
209
210
211 extern GLboolean nouveauCreateContext( const __GLcontextModes *glVisual,
212 __DRIcontextPrivate *driContextPriv,
213 void *sharedContextPrivate );
214
215 extern void nouveauDestroyContext( __DRIcontextPrivate * );
216
217 extern GLboolean nouveauMakeCurrent( __DRIcontextPrivate *driContextPriv,
218 __DRIdrawablePrivate *driDrawPriv,
219 __DRIdrawablePrivate *driReadPriv );
220
221 extern GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv );
222
223 extern void nouveauDoSwapBuffers(nouveauContextPtr nmesa,
224 __DRIdrawablePrivate *dPriv);
225
226 extern void nouveauSwapBuffers(__DRIdrawablePrivate *dPriv);
227
228 extern void nouveauCopySubBuffer(__DRIdrawablePrivate *dPriv,
229 int x, int y, int w, int h);
230
231 /* Debugging utils: */
232 extern int NOUVEAU_DEBUG;
233
234 #define DEBUG_SHADERS 0x00000001
235 #define DEBUG_MEM 0x00000002
236 #define DEBUG_BUFFEROBJ 0x00000004
237
238 #endif /* __NOUVEAU_CONTEXT_H__ */
239