1c069f1625f7908ca5fd83098a58fe93893bc846
[mesa.git] / src / gallium / drivers / nv50 / nv50_context.h
1 #ifndef __NV50_CONTEXT_H__
2 #define __NV50_CONTEXT_H__
3
4 #include "pipe/p_context.h"
5 #include "pipe/p_defines.h"
6 #include "pipe/p_state.h"
7
8 #include "draw/draw_vertex.h"
9
10 #include "nouveau/nouveau_winsys.h"
11 #include "nouveau/nouveau_gldefs.h"
12 #include "nouveau/nouveau_stateobj.h"
13
14 #define NOUVEAU_PUSH_CONTEXT(ctx) \
15 struct nv50_screen *ctx = nv50->screen
16 #include "nouveau/nouveau_push.h"
17
18 #include "nv50_screen.h"
19 #include "nv50_program.h"
20
21 #define NOUVEAU_ERR(fmt, args...) \
22 fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args);
23 #define NOUVEAU_MSG(fmt, args...) \
24 fprintf(stderr, "nouveau: "fmt, ##args);
25
26 /* Constant buffer assignment */
27 #define NV50_CB_PMISC 0
28 #define NV50_CB_PVP 1
29 #define NV50_CB_PFP 2
30 #define NV50_CB_PGP 3
31 #define NV50_CB_TIC 4
32 #define NV50_CB_TSC 5
33 #define NV50_CB_PUPLOAD 6
34
35 #define NV50_NEW_BLEND (1 << 0)
36 #define NV50_NEW_ZSA (1 << 1)
37 #define NV50_NEW_BLEND_COLOUR (1 << 2)
38 #define NV50_NEW_STIPPLE (1 << 3)
39 #define NV50_NEW_SCISSOR (1 << 4)
40 #define NV50_NEW_VIEWPORT (1 << 5)
41 #define NV50_NEW_RASTERIZER (1 << 6)
42 #define NV50_NEW_FRAMEBUFFER (1 << 7)
43 #define NV50_NEW_VERTPROG (1 << 8)
44 #define NV50_NEW_VERTPROG_CB (1 << 9)
45 #define NV50_NEW_FRAGPROG (1 << 10)
46 #define NV50_NEW_FRAGPROG_CB (1 << 11)
47 #define NV50_NEW_ARRAYS (1 << 12)
48 #define NV50_NEW_SAMPLER (1 << 13)
49 #define NV50_NEW_TEXTURE (1 << 14)
50
51 struct nv50_blend_stateobj {
52 struct pipe_blend_state pipe;
53 struct nouveau_stateobj *so;
54 };
55
56 struct nv50_zsa_stateobj {
57 struct pipe_depth_stencil_alpha_state pipe;
58 struct nouveau_stateobj *so;
59 };
60
61 struct nv50_rasterizer_stateobj {
62 struct pipe_rasterizer_state pipe;
63 struct nouveau_stateobj *so;
64 };
65
66 struct nv50_miptree {
67 struct pipe_texture base;
68 struct pipe_buffer *buffer;
69 };
70
71 static INLINE struct nv50_miptree *
72 nv50_miptree(struct pipe_texture *pt)
73 {
74 return (struct nv50_miptree *)pt;
75 }
76
77 struct nv50_surface {
78 struct pipe_surface base;
79 struct pipe_buffer *untiled;
80 };
81
82 static INLINE struct nv50_surface *
83 nv50_surface(struct pipe_surface *pt)
84 {
85 return (struct nv50_surface *)pt;
86 }
87
88 struct nv50_state {
89 unsigned dirty;
90
91 struct nouveau_stateobj *fb;
92 struct nouveau_stateobj *blend;
93 struct nouveau_stateobj *blend_colour;
94 struct nouveau_stateobj *zsa;
95 struct nouveau_stateobj *rast;
96 struct nouveau_stateobj *stipple;
97 struct nouveau_stateobj *scissor;
98 unsigned scissor_enabled;
99 struct nouveau_stateobj *viewport;
100 unsigned viewport_bypass;
101 struct nouveau_stateobj *tsc_upload;
102 struct nouveau_stateobj *tic_upload;
103 struct nouveau_stateobj *vertprog;
104 struct nouveau_stateobj *fragprog;
105 struct nouveau_stateobj *vtxfmt;
106 struct nouveau_stateobj *vtxbuf;
107 };
108
109 struct nv50_context {
110 struct pipe_context pipe;
111
112 struct nv50_screen *screen;
113 unsigned pctx_id;
114
115 struct draw_context *draw;
116
117 struct nv50_state state;
118
119 unsigned dirty;
120 struct nv50_blend_stateobj *blend;
121 struct nv50_zsa_stateobj *zsa;
122 struct nv50_rasterizer_stateobj *rasterizer;
123 struct pipe_blend_color blend_colour;
124 struct pipe_poly_stipple stipple;
125 struct pipe_scissor_state scissor;
126 struct pipe_viewport_state viewport;
127 struct pipe_framebuffer_state framebuffer;
128 struct nv50_program *vertprog;
129 struct nv50_program *fragprog;
130 struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
131 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
132 unsigned vtxbuf_nr;
133 struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS];
134 unsigned vtxelt_nr;
135 unsigned *sampler[PIPE_MAX_SAMPLERS];
136 unsigned sampler_nr;
137 struct nv50_miptree *miptree[PIPE_MAX_SAMPLERS];
138 unsigned miptree_nr;
139 };
140
141 static INLINE struct nv50_context *
142 nv50_context(struct pipe_context *pipe)
143 {
144 return (struct nv50_context *)pipe;
145 }
146
147 extern void nv50_init_surface_functions(struct nv50_context *nv50);
148 extern void nv50_init_state_functions(struct nv50_context *nv50);
149 extern void nv50_init_query_functions(struct nv50_context *nv50);
150
151 extern void nv50_screen_init_miptree_functions(struct pipe_screen *pscreen);
152
153 /* nv50_draw.c */
154 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *nv50);
155
156 /* nv50_vbo.c */
157 extern boolean nv50_draw_arrays(struct pipe_context *, unsigned mode,
158 unsigned start, unsigned count);
159 extern boolean nv50_draw_elements(struct pipe_context *pipe,
160 struct pipe_buffer *indexBuffer,
161 unsigned indexSize,
162 unsigned mode, unsigned start,
163 unsigned count);
164 extern void nv50_vbo_validate(struct nv50_context *nv50);
165
166 /* nv50_clear.c */
167 extern void nv50_clear(struct pipe_context *pipe, struct pipe_surface *ps,
168 unsigned clearValue);
169
170 /* nv50_program.c */
171 extern void nv50_vertprog_validate(struct nv50_context *nv50);
172 extern void nv50_fragprog_validate(struct nv50_context *nv50);
173 extern void nv50_program_destroy(struct nv50_context *nv50, struct nv50_program *p);
174
175 /* nv50_state_validate.c */
176 extern boolean nv50_state_validate(struct nv50_context *nv50);
177
178 /* nv50_tex.c */
179 extern void nv50_tex_validate(struct nv50_context *);
180
181 #endif