1 #ifndef __NV30_CONTEXT_H__
2 #define __NV30_CONTEXT_H__
4 #include "pipe/p_context.h"
5 #include "pipe/p_defines.h"
6 #include "pipe/p_state.h"
7 #include "pipe/p_compiler.h"
9 #include "util/u_memory.h"
10 #include "util/u_math.h"
12 #include "draw/draw_vertex.h"
14 #include "nouveau/nouveau_winsys.h"
15 #include "nouveau/nouveau_gldefs.h"
16 #include "nouveau/nouveau_context.h"
17 #include "nouveau/nouveau_stateobj.h"
19 #include "nv30_state.h"
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);
26 enum nv30_state_index
{
28 NV30_STATE_VIEWPORT
= 1,
34 NV30_STATE_SCISSOR
= 7,
35 NV30_STATE_STIPPLE
= 8,
36 NV30_STATE_FRAGPROG
= 9,
37 NV30_STATE_VERTPROG
= 10,
38 NV30_STATE_FRAGTEX0
= 11,
39 NV30_STATE_FRAGTEX1
= 12,
40 NV30_STATE_FRAGTEX2
= 13,
41 NV30_STATE_FRAGTEX3
= 14,
42 NV30_STATE_FRAGTEX4
= 15,
43 NV30_STATE_FRAGTEX5
= 16,
44 NV30_STATE_FRAGTEX6
= 17,
45 NV30_STATE_FRAGTEX7
= 18,
46 NV30_STATE_FRAGTEX8
= 19,
47 NV30_STATE_FRAGTEX9
= 20,
48 NV30_STATE_FRAGTEX10
= 21,
49 NV30_STATE_FRAGTEX11
= 22,
50 NV30_STATE_FRAGTEX12
= 23,
51 NV30_STATE_FRAGTEX13
= 24,
52 NV30_STATE_FRAGTEX14
= 25,
53 NV30_STATE_FRAGTEX15
= 26,
54 NV30_STATE_VERTTEX0
= 27,
55 NV30_STATE_VERTTEX1
= 28,
56 NV30_STATE_VERTTEX2
= 29,
57 NV30_STATE_VERTTEX3
= 30,
58 NV30_STATE_VTXBUF
= 31,
59 NV30_STATE_VTXFMT
= 32,
60 NV30_STATE_VTXATTR
= 33,
64 #include "nv30_screen.h"
66 #define NV30_NEW_BLEND (1 << 0)
67 #define NV30_NEW_RAST (1 << 1)
68 #define NV30_NEW_ZSA (1 << 2)
69 #define NV30_NEW_SAMPLER (1 << 3)
70 #define NV30_NEW_FB (1 << 4)
71 #define NV30_NEW_STIPPLE (1 << 5)
72 #define NV30_NEW_SCISSOR (1 << 6)
73 #define NV30_NEW_VIEWPORT (1 << 7)
74 #define NV30_NEW_BCOL (1 << 8)
75 #define NV30_NEW_VERTPROG (1 << 9)
76 #define NV30_NEW_FRAGPROG (1 << 10)
77 #define NV30_NEW_ARRAYS (1 << 11)
78 #define NV30_NEW_UCP (1 << 12)
80 struct nv30_rasterizer_state
{
81 struct pipe_rasterizer_state pipe
;
82 struct nouveau_stateobj
*so
;
85 struct nv30_zsa_state
{
86 struct pipe_depth_stencil_alpha_state pipe
;
87 struct nouveau_stateobj
*so
;
90 struct nv30_blend_state
{
91 struct pipe_blend_state pipe
;
92 struct nouveau_stateobj
*so
;
97 unsigned scissor_enabled
;
98 unsigned stipple_enabled
;
99 unsigned viewport_bypass
;
100 unsigned fp_samplers
;
103 struct nouveau_stateobj
*hw
[NV30_STATE_MAX
];
106 struct nv30_context
{
107 struct pipe_context pipe
;
109 struct nouveau_winsys
*nvws
;
110 struct nv30_screen
*screen
;
113 struct draw_context
*draw
;
115 /* HW state derived from pipe states */
116 struct nv30_state state
;
120 struct pipe_scissor_state scissor
;
121 unsigned stipple
[32];
122 struct nv30_vertex_program
*vertprog
;
123 struct nv30_fragment_program
*fragprog
;
124 struct pipe_buffer
*constbuf
[PIPE_SHADER_TYPES
];
125 unsigned constbuf_nr
[PIPE_SHADER_TYPES
];
126 struct nv30_rasterizer_state
*rasterizer
;
127 struct nv30_zsa_state
*zsa
;
128 struct nv30_blend_state
*blend
;
129 struct pipe_blend_color blend_colour
;
130 struct pipe_viewport_state viewport
;
131 struct pipe_framebuffer_state framebuffer
;
132 struct pipe_buffer
*idxbuf
;
133 unsigned idxbuf_format
;
134 struct nv30_sampler_state
*tex_sampler
[PIPE_MAX_SAMPLERS
];
135 struct nv30_miptree
*tex_miptree
[PIPE_MAX_SAMPLERS
];
136 unsigned nr_samplers
;
137 unsigned nr_textures
;
138 unsigned dirty_samplers
;
139 struct pipe_vertex_buffer vtxbuf
[PIPE_MAX_ATTRIBS
];
141 struct pipe_vertex_element vtxelt
[PIPE_MAX_ATTRIBS
];
145 static INLINE
struct nv30_context
*
146 nv30_context(struct pipe_context
*pipe
)
148 return (struct nv30_context
*)pipe
;
151 struct nv30_state_entry
{
152 boolean (*validate
)(struct nv30_context
*nv30
);
159 extern void nv30_init_state_functions(struct nv30_context
*nv30
);
160 extern void nv30_init_surface_functions(struct nv30_context
*nv30
);
161 extern void nv30_init_query_functions(struct nv30_context
*nv30
);
163 extern void nv30_screen_init_miptree_functions(struct pipe_screen
*pscreen
);
166 extern struct draw_stage
*nv30_draw_render_stage(struct nv30_context
*nv30
);
168 /* nv30_vertprog.c */
169 extern void nv30_vertprog_destroy(struct nv30_context
*,
170 struct nv30_vertex_program
*);
172 /* nv30_fragprog.c */
173 extern void nv30_fragprog_destroy(struct nv30_context
*,
174 struct nv30_fragment_program
*);
177 extern void nv30_fragtex_bind(struct nv30_context
*);
179 /* nv30_state.c and friends */
180 extern boolean
nv30_state_validate(struct nv30_context
*nv30
);
181 extern void nv30_state_emit(struct nv30_context
*nv30
);
182 extern void nv30_state_flush_notify(struct nouveau_channel
*chan
);
183 extern struct nv30_state_entry nv30_state_rasterizer
;
184 extern struct nv30_state_entry nv30_state_scissor
;
185 extern struct nv30_state_entry nv30_state_stipple
;
186 extern struct nv30_state_entry nv30_state_fragprog
;
187 extern struct nv30_state_entry nv30_state_vertprog
;
188 extern struct nv30_state_entry nv30_state_blend
;
189 extern struct nv30_state_entry nv30_state_blend_colour
;
190 extern struct nv30_state_entry nv30_state_zsa
;
191 extern struct nv30_state_entry nv30_state_viewport
;
192 extern struct nv30_state_entry nv30_state_framebuffer
;
193 extern struct nv30_state_entry nv30_state_fragtex
;
194 extern struct nv30_state_entry nv30_state_vbo
;
197 extern void nv30_draw_arrays(struct pipe_context
*, unsigned mode
,
198 unsigned start
, unsigned count
);
199 extern void nv30_draw_elements(struct pipe_context
*pipe
,
200 struct pipe_buffer
*indexBuffer
,
202 unsigned mode
, unsigned start
,
206 extern void nv30_clear(struct pipe_context
*pipe
, unsigned buffers
,
207 const float *rgba
, double depth
, unsigned stencil
);