211d4e0a6d3ab72631d94cd8fa230c8de2334667
[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_screen.h"
40 #include "nouveau_state_cache.h"
41 #include "nouveau_buffers.h"
42 #include "nouveau_shader.h"
43
44 #include "xmlconfig.h"
45
46 typedef struct nouveau_fifo_t{
47 u_int32_t* buffer;
48 u_int32_t* mmio;
49 u_int32_t put_base;
50 u_int32_t current;
51 u_int32_t put;
52 u_int32_t free;
53 u_int32_t max;
54 }
55 nouveau_fifo;
56
57 #define TAG(x) nouveau##x
58 #include "tnl_dd/t_dd_vertex.h"
59 #undef TAG
60
61 /* Subpixel offsets for window coordinates (triangles): */
62 #define SUBPIXEL_X (0.0F)
63 #define SUBPIXEL_Y (0.125F)
64
65 struct nouveau_context;
66
67 typedef void (*nouveau_tri_func)( struct nouveau_context*,
68 nouveauVertex *,
69 nouveauVertex *,
70 nouveauVertex * );
71
72 typedef void (*nouveau_line_func)( struct nouveau_context*,
73 nouveauVertex *,
74 nouveauVertex * );
75
76 typedef void (*nouveau_point_func)( struct nouveau_context*,
77 nouveauVertex * );
78
79 typedef struct nouveau_hw_func_t {
80 /* Initialise any card-specific non-GL related state */
81 GLboolean (*InitCard)(struct nouveau_context *);
82 /* Update buffer offset/pitch/format */
83 GLboolean (*BindBuffers)(struct nouveau_context *, int num_color,
84 nouveau_renderbuffer **color,
85 nouveau_renderbuffer *depth);
86 /* Update anything that depends on the window position/size */
87 void (*WindowMoved)(struct nouveau_context *);
88 } nouveau_hw_func;
89
90 typedef struct nouveau_context {
91 /* Mesa context */
92 GLcontext *glCtx;
93
94 /* The per-context fifo */
95 nouveau_fifo fifo;
96
97 /* The read-only regs */
98 volatile unsigned char* mmio;
99
100 /* Physical addresses of AGP/VRAM apertures */
101 uint64_t vram_phys;
102 uint64_t agp_phys;
103
104 /* Additional hw-specific functions */
105 nouveau_hw_func hw_func;
106
107 /* FIXME : do we want to put all state into a separate struct ? */
108 /* State for tris */
109 GLuint color_offset;
110 GLuint specular_offset;
111
112 /* Vertex state */
113 GLuint vertex_size;
114 GLubyte *verts;
115 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
116 GLuint vertex_attr_count;
117
118 /* Depth/stencil clear state */
119 uint32_t clear_value;
120
121 /* Light state */
122 GLboolean lighting_enabled;
123 uint32_t enabled_lights;
124
125 /* Cached state */
126 nouveau_state_cache state_cache;
127
128 /* The drawing fallbacks */
129 GLuint Fallback;
130 nouveau_tri_func draw_tri;
131 nouveau_line_func draw_line;
132 nouveau_point_func draw_point;
133
134 /* Cliprects information */
135 GLuint numClipRects;
136 drm_clip_rect_t *pClipRects;
137
138 /* The rendering context information */
139 GLenum current_primitive; /* the current primitive enum */
140 DECLARE_RENDERINPUTS(render_inputs_bitset); /* the current render inputs */
141
142 /* Shader state */
143 nvsFunc VPfunc;
144 nvsFunc FPfunc;
145 nouveauShader *current_fragprog;
146 nouveauShader *current_vertprog;
147
148 nouveauScreenRec *screen;
149 drm_nouveau_sarea_t *sarea;
150
151 __DRIcontextPrivate *driContext; /* DRI context */
152 __DRIscreenPrivate *driScreen; /* DRI screen */
153 __DRIdrawablePrivate *driDrawable; /* DRI drawable bound to this ctx */
154 GLint lastStamp;
155
156 drm_context_t hHWContext;
157 drm_hw_lock_t *driHwLock;
158 int driFd;
159
160 /* Configuration cache */
161 driOptionCache optionCache;
162
163 /* vblank stuff */
164 uint32_t vblank_flags;
165 uint32_t vblank_seq;
166
167 GLuint new_state;
168 GLuint new_render_state;
169 GLuint render_index;
170 GLmatrix viewport;
171 GLfloat depth_scale;
172
173 }nouveauContextRec, *nouveauContextPtr;
174
175
176 #define NOUVEAU_CONTEXT(ctx) ((nouveauContextPtr)(ctx->DriverCtx))
177
178 /* Flags for software fallback cases: */
179 #define NOUVEAU_FALLBACK_TEXTURE 0x0001
180 #define NOUVEAU_FALLBACK_DRAW_BUFFER 0x0002
181 #define NOUVEAU_FALLBACK_READ_BUFFER 0x0004
182 #define NOUVEAU_FALLBACK_STENCIL 0x0008
183 #define NOUVEAU_FALLBACK_RENDER_MODE 0x0010
184 #define NOUVEAU_FALLBACK_LOGICOP 0x0020
185 #define NOUVEAU_FALLBACK_SEP_SPECULAR 0x0040
186 #define NOUVEAU_FALLBACK_BLEND_EQ 0x0080
187 #define NOUVEAU_FALLBACK_BLEND_FUNC 0x0100
188 #define NOUVEAU_FALLBACK_PROJTEX 0x0200
189 #define NOUVEAU_FALLBACK_DISABLE 0x0400
190
191
192 extern GLboolean nouveauCreateContext( const __GLcontextModes *glVisual,
193 __DRIcontextPrivate *driContextPriv,
194 void *sharedContextPrivate );
195
196 extern void nouveauDestroyContext( __DRIcontextPrivate * );
197
198 extern GLboolean nouveauMakeCurrent( __DRIcontextPrivate *driContextPriv,
199 __DRIdrawablePrivate *driDrawPriv,
200 __DRIdrawablePrivate *driReadPriv );
201
202 extern GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv );
203
204 extern void nouveauSwapBuffers(__DRIdrawablePrivate *dPriv);
205
206 extern void nouveauCopySubBuffer(__DRIdrawablePrivate *dPriv,
207 int x, int y, int w, int h);
208
209 #endif /* __NOUVEAU_CONTEXT_H__ */
210