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