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