1 /**************************************************************************
3 Copyright 2006 Stephane Marchesin
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:
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
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.
25 **************************************************************************/
29 #ifndef __NOUVEAU_CONTEXT_H__
30 #define __NOUVEAU_CONTEXT_H__
34 #include "nouveau_drm.h"
37 #include "tnl/t_vertex.h"
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"
45 #include "xmlconfig.h"
47 typedef struct nouveau_fifo
{
48 struct drm_nouveau_channel_alloc drm
;
51 uint32_t *notifier_block
;
58 #define TAG(x) nouveau##x
59 #include "tnl_dd/t_dd_vertex.h"
62 /* Subpixel offsets for window coordinates (triangles): */
63 #define SUBPIXEL_X (0.0F)
64 #define SUBPIXEL_Y (0.125F)
66 struct nouveau_context
;
68 typedef void (*nouveau_tri_func
)( struct nouveau_context
*,
73 typedef void (*nouveau_line_func
)( struct nouveau_context
*,
77 typedef void (*nouveau_point_func
)( struct nouveau_context
*,
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
*);
90 /* Update projection matrix */
91 void (*UpdateProjectionMatrix
)(GLcontext
*);
93 /* Update modelview matrix (used for lighting and vertex weight) */
94 void (*UpdateModelviewMatrix
)(GLcontext
*);
97 typedef struct nouveau_context
{
101 /* The per-context fifo */
104 /* Physical addresses of AGP/VRAM apertures */
110 /* Channel synchronisation */
111 struct drm_nouveau_notifierobj_alloc
*syncNotifier
;
113 /* ARB_occlusion_query / EXT_timer_query */
114 GLuint query_object_max
;
115 GLboolean
* query_alloc
;
116 struct drm_nouveau_notifierobj_alloc
*queryNotifier
;
118 /* Additional hw-specific functions */
119 nouveau_hw_func hw_func
;
121 /* FIXME : do we want to put all state into a separate struct ? */
124 GLuint specular_offset
;
129 struct tnl_attr_map vertex_attrs
[VERT_ATTRIB_MAX
];
130 GLuint vertex_attr_count
;
132 /* Color and depth renderbuffers */
133 nouveau_renderbuffer_t
*color_buffer
;
134 nouveau_renderbuffer_t
*depth_buffer
;
136 /* Depth/stencil clear value */
137 uint32_t clear_value
;
140 GLboolean lighting_enabled
;
141 uint32_t enabled_lights
;
144 nouveau_state_cache state_cache
;
146 /* The drawing fallbacks */
148 nouveau_tri_func draw_tri
;
149 nouveau_line_func draw_line
;
150 nouveau_point_func draw_point
;
152 /* Cliprects information */
154 drm_clip_rect_t
*pClipRects
;
155 drm_clip_rect_t osClipRect
;
156 GLuint drawX
, drawY
, drawW
, drawH
;
158 /* The rendering context information */
159 GLenum current_primitive
; /* the current primitive enum */
160 DECLARE_RENDERINPUTS(render_inputs_bitset
); /* the current render inputs */
165 nouveauShader
*current_fragprog
;
166 nouveauShader
*current_vertprog
;
167 nouveauShader
*passthrough_vp
;
168 nouveauShader
*passthrough_fp
;
170 nouveauScreenRec
*screen
;
171 struct drm_nouveau_sarea
*sarea
;
173 __DRIcontextPrivate
*driContext
; /* DRI context */
174 __DRIscreenPrivate
*driScreen
; /* DRI screen */
175 __DRIdrawablePrivate
*driDrawable
; /* DRI drawable bound to this ctx */
178 drm_context_t hHWContext
;
179 drm_hw_lock_t
*driHwLock
;
182 /* Configuration cache */
183 driOptionCache optionCache
;
186 GLuint new_render_state
;
191 }nouveauContextRec
, *nouveauContextPtr
;
194 #define NOUVEAU_CONTEXT(ctx) ((nouveauContextPtr)(ctx->DriverCtx))
196 /* Flags for software fallback cases: */
197 #define NOUVEAU_FALLBACK_TEXTURE 0x0001
198 #define NOUVEAU_FALLBACK_DRAW_BUFFER 0x0002
199 #define NOUVEAU_FALLBACK_READ_BUFFER 0x0004
200 #define NOUVEAU_FALLBACK_STENCIL 0x0008
201 #define NOUVEAU_FALLBACK_RENDER_MODE 0x0010
202 #define NOUVEAU_FALLBACK_LOGICOP 0x0020
203 #define NOUVEAU_FALLBACK_SEP_SPECULAR 0x0040
204 #define NOUVEAU_FALLBACK_BLEND_EQ 0x0080
205 #define NOUVEAU_FALLBACK_BLEND_FUNC 0x0100
206 #define NOUVEAU_FALLBACK_PROJTEX 0x0200
207 #define NOUVEAU_FALLBACK_DISABLE 0x0400
210 extern GLboolean
nouveauCreateContext( const __GLcontextModes
*glVisual
,
211 __DRIcontextPrivate
*driContextPriv
,
212 void *sharedContextPrivate
);
214 extern void nouveauDestroyContext( __DRIcontextPrivate
* );
216 extern GLboolean
nouveauMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
217 __DRIdrawablePrivate
*driDrawPriv
,
218 __DRIdrawablePrivate
*driReadPriv
);
220 extern GLboolean
nouveauUnbindContext( __DRIcontextPrivate
*driContextPriv
);
222 extern void nouveauDoSwapBuffers(nouveauContextPtr nmesa
,
223 __DRIdrawablePrivate
*dPriv
);
225 extern void nouveauSwapBuffers(__DRIdrawablePrivate
*dPriv
);
227 extern void nouveauCopySubBuffer(__DRIdrawablePrivate
*dPriv
,
228 int x
, int y
, int w
, int h
);
230 extern void nouveauClearBuffer(GLcontext
*ctx
, nouveau_renderbuffer_t
*buffer
,
233 /* Debugging utils: */
234 extern int NOUVEAU_DEBUG
;
236 #define DEBUG_SHADERS 0x00000001
237 #define DEBUG_MEM 0x00000002
238 #define DEBUG_BUFFEROBJ 0x00000004
240 #endif /* __NOUVEAU_CONTEXT_H__ */