2ae66e70859f4481a12fa821f7b16a54c3df1054
[mesa.git] / src / gallium / drivers / nv30 / nv30_state.c
1 #include "pipe/p_state.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/p_inlines.h"
4
5 #include "tgsi/tgsi_parse.h"
6
7 #include "nv30_context.h"
8 #include "nv30_state.h"
9
10 static void *
11 nv30_blend_state_create(struct pipe_context *pipe,
12 const struct pipe_blend_state *cso)
13 {
14 struct nv30_context *nv30 = nv30_context(pipe);
15 struct nouveau_grobj *rankine = nv30->screen->rankine;
16 struct nv30_blend_state *bso = CALLOC(1, sizeof(*bso));
17 struct nouveau_stateobj *so = so_new(16, 0);
18
19 if (cso->blend_enable) {
20 so_method(so, rankine, NV34TCL_BLEND_FUNC_ENABLE, 3);
21 so_data (so, 1);
22 so_data (so, (nvgl_blend_func(cso->alpha_src_factor) << 16) |
23 nvgl_blend_func(cso->rgb_src_factor));
24 so_data (so, nvgl_blend_func(cso->alpha_dst_factor) << 16 |
25 nvgl_blend_func(cso->rgb_dst_factor));
26 /* FIXME: Gallium assumes GL_EXT_blend_func_separate.
27 It is not the case for NV30 */
28 so_method(so, rankine, NV34TCL_BLEND_EQUATION, 1);
29 so_data (so, nvgl_blend_eqn(cso->rgb_func));
30 } else {
31 so_method(so, rankine, NV34TCL_BLEND_FUNC_ENABLE, 1);
32 so_data (so, 0);
33 }
34
35 so_method(so, rankine, NV34TCL_COLOR_MASK, 1);
36 so_data (so, (((cso->colormask & PIPE_MASK_A) ? (0x01 << 24) : 0) |
37 ((cso->colormask & PIPE_MASK_R) ? (0x01 << 16) : 0) |
38 ((cso->colormask & PIPE_MASK_G) ? (0x01 << 8) : 0) |
39 ((cso->colormask & PIPE_MASK_B) ? (0x01 << 0) : 0)));
40
41 if (cso->logicop_enable) {
42 so_method(so, rankine, NV34TCL_COLOR_LOGIC_OP_ENABLE, 2);
43 so_data (so, 1);
44 so_data (so, nvgl_logicop_func(cso->logicop_func));
45 } else {
46 so_method(so, rankine, NV34TCL_COLOR_LOGIC_OP_ENABLE, 1);
47 so_data (so, 0);
48 }
49
50 so_method(so, rankine, NV34TCL_DITHER_ENABLE, 1);
51 so_data (so, cso->dither ? 1 : 0);
52
53 so_ref(so, &bso->so);
54 bso->pipe = *cso;
55 return (void *)bso;
56 }
57
58 static void
59 nv30_blend_state_bind(struct pipe_context *pipe, void *hwcso)
60 {
61 struct nv30_context *nv30 = nv30_context(pipe);
62
63 nv30->blend = hwcso;
64 nv30->dirty |= NV30_NEW_BLEND;
65 }
66
67 static void
68 nv30_blend_state_delete(struct pipe_context *pipe, void *hwcso)
69 {
70 struct nv30_blend_state *bso = hwcso;
71
72 so_ref(NULL, &bso->so);
73 FREE(bso);
74 }
75
76
77 static INLINE unsigned
78 wrap_mode(unsigned wrap) {
79 unsigned ret;
80
81 switch (wrap) {
82 case PIPE_TEX_WRAP_REPEAT:
83 ret = NV34TCL_TX_WRAP_S_REPEAT;
84 break;
85 case PIPE_TEX_WRAP_MIRROR_REPEAT:
86 ret = NV34TCL_TX_WRAP_S_MIRRORED_REPEAT;
87 break;
88 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
89 ret = NV34TCL_TX_WRAP_S_CLAMP_TO_EDGE;
90 break;
91 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
92 ret = NV34TCL_TX_WRAP_S_CLAMP_TO_BORDER;
93 break;
94 case PIPE_TEX_WRAP_CLAMP:
95 ret = NV34TCL_TX_WRAP_S_CLAMP;
96 break;
97 /* case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
98 ret = NV34TCL_TX_WRAP_S_MIRROR_CLAMP_TO_EDGE;
99 break;
100 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
101 ret = NV34TCL_TX_WRAP_S_MIRROR_CLAMP_TO_BORDER;
102 break;
103 case PIPE_TEX_WRAP_MIRROR_CLAMP:
104 ret = NV34TCL_TX_WRAP_S_MIRROR_CLAMP;
105 break;*/
106 default:
107 NOUVEAU_ERR("unknown wrap mode: %d\n", wrap);
108 ret = NV34TCL_TX_WRAP_S_REPEAT;
109 break;
110 }
111
112 return ret >> NV34TCL_TX_WRAP_S_SHIFT;
113 }
114
115 static void *
116 nv30_sampler_state_create(struct pipe_context *pipe,
117 const struct pipe_sampler_state *cso)
118 {
119 struct nv30_sampler_state *ps;
120 uint32_t filter = 0;
121
122 ps = MALLOC(sizeof(struct nv30_sampler_state));
123
124 ps->fmt = 0;
125 /* TODO: Not all RECTs formats have this bit set, bits 15-8 of format
126 are the tx format to use. We should store normalized coord flag
127 in sampler state structure, and set appropriate format in
128 nvxx_fragtex_build()
129 */
130 /*NV34TCL_TX_FORMAT_RECT*/
131 /*if (!cso->normalized_coords) {
132 ps->fmt |= (1<<14) ;
133 }*/
134
135 ps->wrap = ((wrap_mode(cso->wrap_s) << NV34TCL_TX_WRAP_S_SHIFT) |
136 (wrap_mode(cso->wrap_t) << NV34TCL_TX_WRAP_T_SHIFT) |
137 (wrap_mode(cso->wrap_r) << NV34TCL_TX_WRAP_R_SHIFT));
138
139 ps->en = 0;
140
141 if (cso->max_anisotropy >= 8.0) {
142 ps->en |= NV34TCL_TX_ENABLE_ANISO_8X;
143 } else
144 if (cso->max_anisotropy >= 4.0) {
145 ps->en |= NV34TCL_TX_ENABLE_ANISO_4X;
146 } else
147 if (cso->max_anisotropy >= 2.0) {
148 ps->en |= NV34TCL_TX_ENABLE_ANISO_2X;
149 }
150
151 switch (cso->mag_img_filter) {
152 case PIPE_TEX_FILTER_LINEAR:
153 filter |= NV34TCL_TX_FILTER_MAGNIFY_LINEAR;
154 break;
155 case PIPE_TEX_FILTER_NEAREST:
156 default:
157 filter |= NV34TCL_TX_FILTER_MAGNIFY_NEAREST;
158 break;
159 }
160
161 switch (cso->min_img_filter) {
162 case PIPE_TEX_FILTER_LINEAR:
163 switch (cso->min_mip_filter) {
164 case PIPE_TEX_MIPFILTER_NEAREST:
165 filter |= NV34TCL_TX_FILTER_MINIFY_LINEAR_MIPMAP_NEAREST;
166 break;
167 case PIPE_TEX_MIPFILTER_LINEAR:
168 filter |= NV34TCL_TX_FILTER_MINIFY_LINEAR_MIPMAP_LINEAR;
169 break;
170 case PIPE_TEX_MIPFILTER_NONE:
171 default:
172 filter |= NV34TCL_TX_FILTER_MINIFY_LINEAR;
173 break;
174 }
175 break;
176 case PIPE_TEX_FILTER_NEAREST:
177 default:
178 switch (cso->min_mip_filter) {
179 case PIPE_TEX_MIPFILTER_NEAREST:
180 filter |= NV34TCL_TX_FILTER_MINIFY_NEAREST_MIPMAP_NEAREST;
181 break;
182 case PIPE_TEX_MIPFILTER_LINEAR:
183 filter |= NV34TCL_TX_FILTER_MINIFY_NEAREST_MIPMAP_LINEAR;
184 break;
185 case PIPE_TEX_MIPFILTER_NONE:
186 default:
187 filter |= NV34TCL_TX_FILTER_MINIFY_NEAREST;
188 break;
189 }
190 break;
191 }
192
193 ps->filt = filter;
194
195 {
196 float limit;
197
198 limit = CLAMP(cso->lod_bias, -16.0, 15.0);
199 ps->filt |= (int)(cso->lod_bias * 256.0) & 0x1fff;
200
201 limit = CLAMP(cso->max_lod, 0.0, 15.0);
202 ps->en |= (int)(limit) << 14 /*NV34TCL_TX_ENABLE_MIPMAP_MAX_LOD_SHIFT*/;
203
204 limit = CLAMP(cso->min_lod, 0.0, 15.0);
205 ps->en |= (int)(limit) << 26 /*NV34TCL_TX_ENABLE_MIPMAP_MIN_LOD_SHIFT*/;
206 }
207
208 if (cso->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
209 switch (cso->compare_func) {
210 case PIPE_FUNC_NEVER:
211 ps->wrap |= NV34TCL_TX_WRAP_RCOMP_NEVER;
212 break;
213 case PIPE_FUNC_GREATER:
214 ps->wrap |= NV34TCL_TX_WRAP_RCOMP_GREATER;
215 break;
216 case PIPE_FUNC_EQUAL:
217 ps->wrap |= NV34TCL_TX_WRAP_RCOMP_EQUAL;
218 break;
219 case PIPE_FUNC_GEQUAL:
220 ps->wrap |= NV34TCL_TX_WRAP_RCOMP_GEQUAL;
221 break;
222 case PIPE_FUNC_LESS:
223 ps->wrap |= NV34TCL_TX_WRAP_RCOMP_LESS;
224 break;
225 case PIPE_FUNC_NOTEQUAL:
226 ps->wrap |= NV34TCL_TX_WRAP_RCOMP_NOTEQUAL;
227 break;
228 case PIPE_FUNC_LEQUAL:
229 ps->wrap |= NV34TCL_TX_WRAP_RCOMP_LEQUAL;
230 break;
231 case PIPE_FUNC_ALWAYS:
232 ps->wrap |= NV34TCL_TX_WRAP_RCOMP_ALWAYS;
233 break;
234 default:
235 break;
236 }
237 }
238
239 ps->bcol = ((float_to_ubyte(cso->border_color[3]) << 24) |
240 (float_to_ubyte(cso->border_color[0]) << 16) |
241 (float_to_ubyte(cso->border_color[1]) << 8) |
242 (float_to_ubyte(cso->border_color[2]) << 0));
243
244 return (void *)ps;
245 }
246
247 static void
248 nv30_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **sampler)
249 {
250 struct nv30_context *nv30 = nv30_context(pipe);
251 unsigned unit;
252
253 for (unit = 0; unit < nr; unit++) {
254 nv30->tex_sampler[unit] = sampler[unit];
255 nv30->dirty_samplers |= (1 << unit);
256 }
257
258 for (unit = nr; unit < nv30->nr_samplers; unit++) {
259 nv30->tex_sampler[unit] = NULL;
260 nv30->dirty_samplers |= (1 << unit);
261 }
262
263 nv30->nr_samplers = nr;
264 nv30->dirty |= NV30_NEW_SAMPLER;
265 }
266
267 static void
268 nv30_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
269 {
270 FREE(hwcso);
271 }
272
273 static void
274 nv30_set_sampler_texture(struct pipe_context *pipe, unsigned nr,
275 struct pipe_texture **miptree)
276 {
277 struct nv30_context *nv30 = nv30_context(pipe);
278 unsigned unit;
279
280 for (unit = 0; unit < nr; unit++) {
281 pipe_texture_reference((struct pipe_texture **)
282 &nv30->tex_miptree[unit], miptree[unit]);
283 nv30->dirty_samplers |= (1 << unit);
284 }
285
286 for (unit = nr; unit < nv30->nr_textures; unit++) {
287 pipe_texture_reference((struct pipe_texture **)
288 &nv30->tex_miptree[unit], NULL);
289 nv30->dirty_samplers |= (1 << unit);
290 }
291
292 nv30->nr_textures = nr;
293 nv30->dirty |= NV30_NEW_SAMPLER;
294 }
295
296 static void *
297 nv30_rasterizer_state_create(struct pipe_context *pipe,
298 const struct pipe_rasterizer_state *cso)
299 {
300 struct nv30_context *nv30 = nv30_context(pipe);
301 struct nv30_rasterizer_state *rsso = CALLOC(1, sizeof(*rsso));
302 struct nouveau_stateobj *so = so_new(32, 0);
303 struct nouveau_grobj *rankine = nv30->screen->rankine;
304
305 /*XXX: ignored:
306 * light_twoside
307 * point_smooth -nohw
308 * multisample
309 */
310
311 so_method(so, rankine, NV34TCL_SHADE_MODEL, 1);
312 so_data (so, cso->flatshade ? NV34TCL_SHADE_MODEL_FLAT :
313 NV34TCL_SHADE_MODEL_SMOOTH);
314
315 so_method(so, rankine, NV34TCL_LINE_WIDTH, 2);
316 so_data (so, (unsigned char)(cso->line_width * 8.0) & 0xff);
317 so_data (so, cso->line_smooth ? 1 : 0);
318 so_method(so, rankine, NV34TCL_LINE_STIPPLE_ENABLE, 2);
319 so_data (so, cso->line_stipple_enable ? 1 : 0);
320 so_data (so, (cso->line_stipple_pattern << 16) |
321 cso->line_stipple_factor);
322
323 so_method(so, rankine, NV34TCL_POINT_SIZE, 1);
324 so_data (so, fui(cso->point_size));
325
326 so_method(so, rankine, NV34TCL_POLYGON_MODE_FRONT, 6);
327 if (cso->front_winding == PIPE_WINDING_CCW) {
328 so_data(so, nvgl_polygon_mode(cso->fill_ccw));
329 so_data(so, nvgl_polygon_mode(cso->fill_cw));
330 switch (cso->cull_mode) {
331 case PIPE_WINDING_CCW:
332 so_data(so, NV34TCL_CULL_FACE_FRONT);
333 break;
334 case PIPE_WINDING_CW:
335 so_data(so, NV34TCL_CULL_FACE_BACK);
336 break;
337 case PIPE_WINDING_BOTH:
338 so_data(so, NV34TCL_CULL_FACE_FRONT_AND_BACK);
339 break;
340 default:
341 so_data(so, NV34TCL_CULL_FACE_BACK);
342 break;
343 }
344 so_data(so, NV34TCL_FRONT_FACE_CCW);
345 } else {
346 so_data(so, nvgl_polygon_mode(cso->fill_cw));
347 so_data(so, nvgl_polygon_mode(cso->fill_ccw));
348 switch (cso->cull_mode) {
349 case PIPE_WINDING_CCW:
350 so_data(so, NV34TCL_CULL_FACE_BACK);
351 break;
352 case PIPE_WINDING_CW:
353 so_data(so, NV34TCL_CULL_FACE_FRONT);
354 break;
355 case PIPE_WINDING_BOTH:
356 so_data(so, NV34TCL_CULL_FACE_FRONT_AND_BACK);
357 break;
358 default:
359 so_data(so, NV34TCL_CULL_FACE_BACK);
360 break;
361 }
362 so_data(so, NV34TCL_FRONT_FACE_CW);
363 }
364 so_data(so, cso->poly_smooth ? 1 : 0);
365 so_data(so, (cso->cull_mode != PIPE_WINDING_NONE) ? 1 : 0);
366
367 so_method(so, rankine, NV34TCL_POLYGON_STIPPLE_ENABLE, 1);
368 so_data (so, cso->poly_stipple_enable ? 1 : 0);
369
370 so_method(so, rankine, NV34TCL_POLYGON_OFFSET_POINT_ENABLE, 3);
371 if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_POINT) ||
372 (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_POINT))
373 so_data(so, 1);
374 else
375 so_data(so, 0);
376 if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_LINE) ||
377 (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_LINE))
378 so_data(so, 1);
379 else
380 so_data(so, 0);
381 if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_FILL) ||
382 (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_FILL))
383 so_data(so, 1);
384 else
385 so_data(so, 0);
386 if (cso->offset_cw || cso->offset_ccw) {
387 so_method(so, rankine, NV34TCL_POLYGON_OFFSET_FACTOR, 2);
388 so_data (so, fui(cso->offset_scale));
389 so_data (so, fui(cso->offset_units * 2));
390 }
391
392 so_method(so, rankine, NV34TCL_POINT_SPRITE, 1);
393 if (cso->point_sprite) {
394 unsigned psctl = (1 << 0), i;
395
396 for (i = 0; i < 8; i++) {
397 if (cso->sprite_coord_mode[i] != PIPE_SPRITE_COORD_NONE)
398 psctl |= (1 << (8 + i));
399 }
400
401 so_data(so, psctl);
402 } else {
403 so_data(so, 0);
404 }
405
406 so_ref(so, &rsso->so);
407 rsso->pipe = *cso;
408 return (void *)rsso;
409 }
410
411 static void
412 nv30_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso)
413 {
414 struct nv30_context *nv30 = nv30_context(pipe);
415
416 nv30->rasterizer = hwcso;
417 nv30->dirty |= NV30_NEW_RAST;
418 /*nv30->draw_dirty |= NV30_NEW_RAST;*/
419 }
420
421 static void
422 nv30_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
423 {
424 struct nv30_rasterizer_state *rsso = hwcso;
425
426 so_ref(NULL, &rsso->so);
427 FREE(rsso);
428 }
429
430 static void *
431 nv30_depth_stencil_alpha_state_create(struct pipe_context *pipe,
432 const struct pipe_depth_stencil_alpha_state *cso)
433 {
434 struct nv30_context *nv30 = nv30_context(pipe);
435 struct nv30_zsa_state *zsaso = CALLOC(1, sizeof(*zsaso));
436 struct nouveau_stateobj *so = so_new(32, 0);
437 struct nouveau_grobj *rankine = nv30->screen->rankine;
438
439 so_method(so, rankine, NV34TCL_DEPTH_FUNC, 3);
440 so_data (so, nvgl_comparison_op(cso->depth.func));
441 so_data (so, cso->depth.writemask ? 1 : 0);
442 so_data (so, cso->depth.enabled ? 1 : 0);
443
444 so_method(so, rankine, NV34TCL_ALPHA_FUNC_ENABLE, 3);
445 so_data (so, cso->alpha.enabled ? 1 : 0);
446 so_data (so, nvgl_comparison_op(cso->alpha.func));
447 so_data (so, float_to_ubyte(cso->alpha.ref));
448
449 if (cso->stencil[0].enabled) {
450 so_method(so, rankine, NV34TCL_STENCIL_FRONT_ENABLE, 8);
451 so_data (so, cso->stencil[0].enabled ? 1 : 0);
452 so_data (so, cso->stencil[0].writemask);
453 so_data (so, nvgl_comparison_op(cso->stencil[0].func));
454 so_data (so, cso->stencil[0].ref_value);
455 so_data (so, cso->stencil[0].valuemask);
456 so_data (so, nvgl_stencil_op(cso->stencil[0].fail_op));
457 so_data (so, nvgl_stencil_op(cso->stencil[0].zfail_op));
458 so_data (so, nvgl_stencil_op(cso->stencil[0].zpass_op));
459 } else {
460 so_method(so, rankine, NV34TCL_STENCIL_FRONT_ENABLE, 1);
461 so_data (so, 0);
462 }
463
464 if (cso->stencil[1].enabled) {
465 so_method(so, rankine, NV34TCL_STENCIL_BACK_ENABLE, 8);
466 so_data (so, cso->stencil[1].enabled ? 1 : 0);
467 so_data (so, cso->stencil[1].writemask);
468 so_data (so, nvgl_comparison_op(cso->stencil[1].func));
469 so_data (so, cso->stencil[1].ref_value);
470 so_data (so, cso->stencil[1].valuemask);
471 so_data (so, nvgl_stencil_op(cso->stencil[1].fail_op));
472 so_data (so, nvgl_stencil_op(cso->stencil[1].zfail_op));
473 so_data (so, nvgl_stencil_op(cso->stencil[1].zpass_op));
474 } else {
475 so_method(so, rankine, NV34TCL_STENCIL_BACK_ENABLE, 1);
476 so_data (so, 0);
477 }
478
479 so_ref(so, &zsaso->so);
480 zsaso->pipe = *cso;
481 return (void *)zsaso;
482 }
483
484 static void
485 nv30_depth_stencil_alpha_state_bind(struct pipe_context *pipe, void *hwcso)
486 {
487 struct nv30_context *nv30 = nv30_context(pipe);
488
489 nv30->zsa = hwcso;
490 nv30->dirty |= NV30_NEW_ZSA;
491 }
492
493 static void
494 nv30_depth_stencil_alpha_state_delete(struct pipe_context *pipe, void *hwcso)
495 {
496 struct nv30_zsa_state *zsaso = hwcso;
497
498 so_ref(NULL, &zsaso->so);
499 FREE(zsaso);
500 }
501
502 static void *
503 nv30_vp_state_create(struct pipe_context *pipe,
504 const struct pipe_shader_state *cso)
505 {
506 /*struct nv30_context *nv30 = nv30_context(pipe);*/
507 struct nv30_vertex_program *vp;
508
509 vp = CALLOC(1, sizeof(struct nv30_vertex_program));
510 vp->pipe.tokens = tgsi_dup_tokens(cso->tokens);
511 /*vp->draw = draw_create_vertex_shader(nv30->draw, &vp->pipe);*/
512
513 return (void *)vp;
514 }
515
516 static void
517 nv30_vp_state_bind(struct pipe_context *pipe, void *hwcso)
518 {
519 struct nv30_context *nv30 = nv30_context(pipe);
520
521 nv30->vertprog = hwcso;
522 nv30->dirty |= NV30_NEW_VERTPROG;
523 /*nv30->draw_dirty |= NV30_NEW_VERTPROG;*/
524 }
525
526 static void
527 nv30_vp_state_delete(struct pipe_context *pipe, void *hwcso)
528 {
529 struct nv30_context *nv30 = nv30_context(pipe);
530 struct nv30_vertex_program *vp = hwcso;
531
532 /*draw_delete_vertex_shader(nv30->draw, vp->draw);*/
533 nv30_vertprog_destroy(nv30, vp);
534 FREE((void*)vp->pipe.tokens);
535 FREE(vp);
536 }
537
538 static void *
539 nv30_fp_state_create(struct pipe_context *pipe,
540 const struct pipe_shader_state *cso)
541 {
542 struct nv30_fragment_program *fp;
543
544 fp = CALLOC(1, sizeof(struct nv30_fragment_program));
545 fp->pipe.tokens = tgsi_dup_tokens(cso->tokens);
546
547 tgsi_scan_shader(fp->pipe.tokens, &fp->info);
548
549 return (void *)fp;
550 }
551
552 static void
553 nv30_fp_state_bind(struct pipe_context *pipe, void *hwcso)
554 {
555 struct nv30_context *nv30 = nv30_context(pipe);
556
557 nv30->fragprog = hwcso;
558 nv30->dirty |= NV30_NEW_FRAGPROG;
559 }
560
561 static void
562 nv30_fp_state_delete(struct pipe_context *pipe, void *hwcso)
563 {
564 struct nv30_context *nv30 = nv30_context(pipe);
565 struct nv30_fragment_program *fp = hwcso;
566
567 nv30_fragprog_destroy(nv30, fp);
568 FREE((void*)fp->pipe.tokens);
569 FREE(fp);
570 }
571
572 static void
573 nv30_set_blend_color(struct pipe_context *pipe,
574 const struct pipe_blend_color *bcol)
575 {
576 struct nv30_context *nv30 = nv30_context(pipe);
577
578 nv30->blend_colour = *bcol;
579 nv30->dirty |= NV30_NEW_BCOL;
580 }
581
582 static void
583 nv30_set_clip_state(struct pipe_context *pipe,
584 const struct pipe_clip_state *clip)
585 {
586 }
587
588 static void
589 nv30_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
590 const struct pipe_constant_buffer *buf )
591 {
592 struct nv30_context *nv30 = nv30_context(pipe);
593
594 nv30->constbuf[shader] = buf->buffer;
595 nv30->constbuf_nr[shader] = buf->size / (4 * sizeof(float));
596
597 if (shader == PIPE_SHADER_VERTEX) {
598 nv30->dirty |= NV30_NEW_VERTPROG;
599 } else
600 if (shader == PIPE_SHADER_FRAGMENT) {
601 nv30->dirty |= NV30_NEW_FRAGPROG;
602 }
603 }
604
605 static void
606 nv30_set_framebuffer_state(struct pipe_context *pipe,
607 const struct pipe_framebuffer_state *fb)
608 {
609 struct nv30_context *nv30 = nv30_context(pipe);
610
611 nv30->framebuffer = *fb;
612 nv30->dirty |= NV30_NEW_FB;
613 }
614
615 static void
616 nv30_set_polygon_stipple(struct pipe_context *pipe,
617 const struct pipe_poly_stipple *stipple)
618 {
619 struct nv30_context *nv30 = nv30_context(pipe);
620
621 memcpy(nv30->stipple, stipple->stipple, 4 * 32);
622 nv30->dirty |= NV30_NEW_STIPPLE;
623 }
624
625 static void
626 nv30_set_scissor_state(struct pipe_context *pipe,
627 const struct pipe_scissor_state *s)
628 {
629 struct nv30_context *nv30 = nv30_context(pipe);
630
631 nv30->scissor = *s;
632 nv30->dirty |= NV30_NEW_SCISSOR;
633 }
634
635 static void
636 nv30_set_viewport_state(struct pipe_context *pipe,
637 const struct pipe_viewport_state *vpt)
638 {
639 struct nv30_context *nv30 = nv30_context(pipe);
640
641 nv30->viewport = *vpt;
642 nv30->dirty |= NV30_NEW_VIEWPORT;
643 /*nv30->draw_dirty |= NV30_NEW_VIEWPORT;*/
644 }
645
646 static void
647 nv30_set_vertex_buffers(struct pipe_context *pipe, unsigned count,
648 const struct pipe_vertex_buffer *vb)
649 {
650 struct nv30_context *nv30 = nv30_context(pipe);
651
652 memcpy(nv30->vtxbuf, vb, sizeof(*vb) * count);
653 nv30->vtxbuf_nr = count;
654
655 nv30->dirty |= NV30_NEW_ARRAYS;
656 /*nv30->draw_dirty |= NV30_NEW_ARRAYS;*/
657 }
658
659 static void
660 nv30_set_vertex_elements(struct pipe_context *pipe, unsigned count,
661 const struct pipe_vertex_element *ve)
662 {
663 struct nv30_context *nv30 = nv30_context(pipe);
664
665 memcpy(nv30->vtxelt, ve, sizeof(*ve) * count);
666 nv30->vtxelt_nr = count;
667
668 nv30->dirty |= NV30_NEW_ARRAYS;
669 /*nv30->draw_dirty |= NV30_NEW_ARRAYS;*/
670 }
671
672 static void
673 nv30_set_edgeflags(struct pipe_context *pipe, const unsigned *bitfield)
674 {
675 struct nv30_context *nv30 = nv30_context(pipe);
676
677 nv30->edgeflags = bitfield;
678 nv30->dirty |= NV30_NEW_ARRAYS;
679 /*nv30->draw_dirty |= NV30_NEW_ARRAYS;*/
680 }
681
682 void
683 nv30_init_state_functions(struct nv30_context *nv30)
684 {
685 nv30->pipe.create_blend_state = nv30_blend_state_create;
686 nv30->pipe.bind_blend_state = nv30_blend_state_bind;
687 nv30->pipe.delete_blend_state = nv30_blend_state_delete;
688
689 nv30->pipe.create_sampler_state = nv30_sampler_state_create;
690 nv30->pipe.bind_sampler_states = nv30_sampler_state_bind;
691 nv30->pipe.delete_sampler_state = nv30_sampler_state_delete;
692 nv30->pipe.set_sampler_textures = nv30_set_sampler_texture;
693
694 nv30->pipe.create_rasterizer_state = nv30_rasterizer_state_create;
695 nv30->pipe.bind_rasterizer_state = nv30_rasterizer_state_bind;
696 nv30->pipe.delete_rasterizer_state = nv30_rasterizer_state_delete;
697
698 nv30->pipe.create_depth_stencil_alpha_state =
699 nv30_depth_stencil_alpha_state_create;
700 nv30->pipe.bind_depth_stencil_alpha_state =
701 nv30_depth_stencil_alpha_state_bind;
702 nv30->pipe.delete_depth_stencil_alpha_state =
703 nv30_depth_stencil_alpha_state_delete;
704
705 nv30->pipe.create_vs_state = nv30_vp_state_create;
706 nv30->pipe.bind_vs_state = nv30_vp_state_bind;
707 nv30->pipe.delete_vs_state = nv30_vp_state_delete;
708
709 nv30->pipe.create_fs_state = nv30_fp_state_create;
710 nv30->pipe.bind_fs_state = nv30_fp_state_bind;
711 nv30->pipe.delete_fs_state = nv30_fp_state_delete;
712
713 nv30->pipe.set_blend_color = nv30_set_blend_color;
714 nv30->pipe.set_clip_state = nv30_set_clip_state;
715 nv30->pipe.set_constant_buffer = nv30_set_constant_buffer;
716 nv30->pipe.set_framebuffer_state = nv30_set_framebuffer_state;
717 nv30->pipe.set_polygon_stipple = nv30_set_polygon_stipple;
718 nv30->pipe.set_scissor_state = nv30_set_scissor_state;
719 nv30->pipe.set_viewport_state = nv30_set_viewport_state;
720
721 nv30->pipe.set_edgeflags = nv30_set_edgeflags;
722 nv30->pipe.set_vertex_buffers = nv30_set_vertex_buffers;
723 nv30->pipe.set_vertex_elements = nv30_set_vertex_elements;
724 }
725