gallium: remove PIPE_TEX_FILTER_ANISO
[mesa.git] / src / gallium / drivers / nv50 / nv50_state.c
1 /*
2 * Copyright 2008 Ben Skeggs
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #include "pipe/p_state.h"
24 #include "pipe/p_defines.h"
25 #include "pipe/p_inlines.h"
26
27 #include "tgsi/tgsi_parse.h"
28
29 #include "nv50_context.h"
30 #include "nv50_texture.h"
31
32 #include "nouveau/nouveau_stateobj.h"
33
34 static void *
35 nv50_blend_state_create(struct pipe_context *pipe,
36 const struct pipe_blend_state *cso)
37 {
38 struct nouveau_stateobj *so = so_new(5, 24, 0);
39 struct nouveau_grobj *tesla = nv50_context(pipe)->screen->tesla;
40 struct nv50_blend_stateobj *bso = CALLOC_STRUCT(nv50_blend_stateobj);
41 unsigned cmask = 0, i;
42
43 /*XXX ignored:
44 * - dither
45 */
46
47 if (cso->blend_enable == 0) {
48 so_method(so, tesla, NV50TCL_BLEND_ENABLE(0), 8);
49 for (i = 0; i < 8; i++)
50 so_data(so, 0);
51 } else {
52 so_method(so, tesla, NV50TCL_BLEND_ENABLE(0), 8);
53 for (i = 0; i < 8; i++)
54 so_data(so, 1);
55 so_method(so, tesla, NV50TCL_BLEND_EQUATION_RGB, 5);
56 so_data (so, nvgl_blend_eqn(cso->rgb_func));
57 so_data (so, 0x4000 | nvgl_blend_func(cso->rgb_src_factor));
58 so_data (so, 0x4000 | nvgl_blend_func(cso->rgb_dst_factor));
59 so_data (so, nvgl_blend_eqn(cso->alpha_func));
60 so_data (so, 0x4000 | nvgl_blend_func(cso->alpha_src_factor));
61 so_method(so, tesla, NV50TCL_BLEND_FUNC_DST_ALPHA, 1);
62 so_data (so, 0x4000 | nvgl_blend_func(cso->alpha_dst_factor));
63 }
64
65 if (cso->logicop_enable == 0 ) {
66 so_method(so, tesla, NV50TCL_LOGIC_OP_ENABLE, 1);
67 so_data (so, 0);
68 } else {
69 so_method(so, tesla, NV50TCL_LOGIC_OP_ENABLE, 2);
70 so_data (so, 1);
71 so_data (so, nvgl_logicop_func(cso->logicop_func));
72 }
73
74 if (cso->colormask & PIPE_MASK_R)
75 cmask |= (1 << 0);
76 if (cso->colormask & PIPE_MASK_G)
77 cmask |= (1 << 4);
78 if (cso->colormask & PIPE_MASK_B)
79 cmask |= (1 << 8);
80 if (cso->colormask & PIPE_MASK_A)
81 cmask |= (1 << 12);
82 so_method(so, tesla, NV50TCL_COLOR_MASK(0), 8);
83 for (i = 0; i < 8; i++)
84 so_data(so, cmask);
85
86 bso->pipe = *cso;
87 so_ref(so, &bso->so);
88 so_ref(NULL, &so);
89 return (void *)bso;
90 }
91
92 static void
93 nv50_blend_state_bind(struct pipe_context *pipe, void *hwcso)
94 {
95 struct nv50_context *nv50 = nv50_context(pipe);
96
97 nv50->blend = hwcso;
98 nv50->dirty |= NV50_NEW_BLEND;
99 }
100
101 static void
102 nv50_blend_state_delete(struct pipe_context *pipe, void *hwcso)
103 {
104 struct nv50_blend_stateobj *bso = hwcso;
105
106 so_ref(NULL, &bso->so);
107 FREE(bso);
108 }
109
110 static INLINE unsigned
111 wrap_mode(unsigned wrap)
112 {
113 switch (wrap) {
114 case PIPE_TEX_WRAP_REPEAT:
115 return NV50TSC_1_0_WRAPS_REPEAT;
116 case PIPE_TEX_WRAP_MIRROR_REPEAT:
117 return NV50TSC_1_0_WRAPS_MIRROR_REPEAT;
118 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
119 return NV50TSC_1_0_WRAPS_CLAMP_TO_EDGE;
120 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
121 return NV50TSC_1_0_WRAPS_CLAMP_TO_BORDER;
122 case PIPE_TEX_WRAP_CLAMP:
123 return NV50TSC_1_0_WRAPS_CLAMP;
124 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
125 return NV50TSC_1_0_WRAPS_MIRROR_CLAMP_TO_EDGE;
126 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
127 return NV50TSC_1_0_WRAPS_MIRROR_CLAMP_TO_BORDER;
128 case PIPE_TEX_WRAP_MIRROR_CLAMP:
129 return NV50TSC_1_0_WRAPS_MIRROR_CLAMP;
130 default:
131 NOUVEAU_ERR("unknown wrap mode: %d\n", wrap);
132 return NV50TSC_1_0_WRAPS_REPEAT;
133 }
134 }
135 static void *
136 nv50_sampler_state_create(struct pipe_context *pipe,
137 const struct pipe_sampler_state *cso)
138 {
139 struct nv50_sampler_stateobj *sso = CALLOC(1, sizeof(*sso));
140 unsigned *tsc = sso->tsc;
141 float limit;
142
143 tsc[0] = (0x00026000 |
144 (wrap_mode(cso->wrap_s) << 0) |
145 (wrap_mode(cso->wrap_t) << 3) |
146 (wrap_mode(cso->wrap_r) << 6));
147
148 switch (cso->mag_img_filter) {
149 case PIPE_TEX_FILTER_LINEAR:
150 tsc[1] |= NV50TSC_1_1_MAGF_LINEAR;
151 break;
152 case PIPE_TEX_FILTER_NEAREST:
153 default:
154 tsc[1] |= NV50TSC_1_1_MAGF_NEAREST;
155 break;
156 }
157
158 switch (cso->min_img_filter) {
159 case PIPE_TEX_FILTER_LINEAR:
160 tsc[1] |= NV50TSC_1_1_MINF_LINEAR;
161 break;
162 case PIPE_TEX_FILTER_NEAREST:
163 default:
164 tsc[1] |= NV50TSC_1_1_MINF_NEAREST;
165 break;
166 }
167
168 switch (cso->min_mip_filter) {
169 case PIPE_TEX_MIPFILTER_LINEAR:
170 tsc[1] |= NV50TSC_1_1_MIPF_LINEAR;
171 break;
172 case PIPE_TEX_MIPFILTER_NEAREST:
173 tsc[1] |= NV50TSC_1_1_MIPF_NEAREST;
174 break;
175 case PIPE_TEX_MIPFILTER_NONE:
176 default:
177 tsc[1] |= NV50TSC_1_1_MIPF_NONE;
178 break;
179 }
180
181 if (cso->max_anisotropy >= 16.0)
182 tsc[0] |= (7 << 20);
183 else
184 if (cso->max_anisotropy >= 12.0)
185 tsc[0] |= (6 << 20);
186 else {
187 tsc[0] |= (int)(cso->max_anisotropy * 0.5f) << 20;
188
189 if (cso->max_anisotropy >= 4.0)
190 tsc[1] |= NV50TSC_1_1_UNKN_ANISO_35;
191 else
192 if (cso->max_anisotropy >= 2.0)
193 tsc[1] |= NV50TSC_1_1_UNKN_ANISO_15;
194 }
195
196 if (cso->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
197 /* XXX: must be deactivated for non-shadow textures */
198 tsc[0] |= (1 << 9);
199 tsc[0] |= (nvgl_comparison_op(cso->compare_func) & 0x7) << 10;
200 }
201
202 limit = CLAMP(cso->lod_bias, -16.0, 15.0);
203 tsc[1] |= ((int)(limit * 256.0) & 0x1fff) << 12;
204
205 tsc[2] |= ((int)CLAMP(cso->max_lod, 0.0, 15.0) << 20) |
206 ((int)CLAMP(cso->min_lod, 0.0, 15.0) << 8);
207
208 tsc[4] = fui(cso->border_color[0]);
209 tsc[5] = fui(cso->border_color[1]);
210 tsc[6] = fui(cso->border_color[2]);
211 tsc[7] = fui(cso->border_color[3]);
212
213 sso->normalized = cso->normalized_coords;
214 return (void *)sso;
215 }
216
217 static INLINE void
218 nv50_sampler_state_bind(struct pipe_context *pipe, unsigned type,
219 unsigned nr, void **sampler)
220 {
221 struct nv50_context *nv50 = nv50_context(pipe);
222
223 memcpy(nv50->sampler[type], sampler, nr * sizeof(void *));
224
225 nv50->sampler_nr[type] = nr;
226 nv50->dirty |= NV50_NEW_SAMPLER;
227 }
228
229 static void
230 nv50_vp_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **s)
231 {
232 nv50_sampler_state_bind(pipe, PIPE_SHADER_VERTEX, nr, s);
233 }
234
235 static void
236 nv50_fp_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **s)
237 {
238 nv50_sampler_state_bind(pipe, PIPE_SHADER_FRAGMENT, nr, s);
239 }
240
241 static void
242 nv50_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
243 {
244 FREE(hwcso);
245 }
246
247 static INLINE void
248 nv50_set_sampler_texture(struct pipe_context *pipe, unsigned type,
249 unsigned nr, struct pipe_texture **pt)
250 {
251 struct nv50_context *nv50 = nv50_context(pipe);
252 unsigned i;
253
254 for (i = 0; i < nr; i++)
255 pipe_texture_reference((void *)&nv50->miptree[type][i], pt[i]);
256 for (i = nr; i < nv50->miptree_nr[type]; i++)
257 pipe_texture_reference((void *)&nv50->miptree[type][i], NULL);
258
259 nv50->miptree_nr[type] = nr;
260 nv50->dirty |= NV50_NEW_TEXTURE;
261 }
262
263 static void
264 nv50_set_vp_sampler_textures(struct pipe_context *pipe,
265 unsigned nr, struct pipe_texture **pt)
266 {
267 nv50_set_sampler_texture(pipe, PIPE_SHADER_VERTEX, nr, pt);
268 }
269
270 static void
271 nv50_set_fp_sampler_textures(struct pipe_context *pipe,
272 unsigned nr, struct pipe_texture **pt)
273 {
274 nv50_set_sampler_texture(pipe, PIPE_SHADER_FRAGMENT, nr, pt);
275 }
276
277 static void *
278 nv50_rasterizer_state_create(struct pipe_context *pipe,
279 const struct pipe_rasterizer_state *cso)
280 {
281 struct nouveau_stateobj *so = so_new(15, 21, 0);
282 struct nouveau_grobj *tesla = nv50_context(pipe)->screen->tesla;
283 struct nv50_rasterizer_stateobj *rso =
284 CALLOC_STRUCT(nv50_rasterizer_stateobj);
285
286 /*XXX: ignored
287 * - light_twosize
288 * - point_smooth
289 * - multisample
290 * - point_sprite / sprite_coord_mode
291 */
292
293 so_method(so, tesla, NV50TCL_SHADE_MODEL, 1);
294 so_data (so, cso->flatshade ? NV50TCL_SHADE_MODEL_FLAT :
295 NV50TCL_SHADE_MODEL_SMOOTH);
296 so_method(so, tesla, NV50TCL_PROVOKING_VERTEX_LAST, 1);
297 so_data (so, cso->flatshade_first ? 0 : 1);
298
299 so_method(so, tesla, NV50TCL_VERTEX_TWO_SIDE_ENABLE, 1);
300 so_data (so, cso->light_twoside);
301
302 so_method(so, tesla, NV50TCL_LINE_WIDTH, 1);
303 so_data (so, fui(cso->line_width));
304 so_method(so, tesla, NV50TCL_LINE_SMOOTH_ENABLE, 1);
305 so_data (so, cso->line_smooth ? 1 : 0);
306 if (cso->line_stipple_enable) {
307 so_method(so, tesla, NV50TCL_LINE_STIPPLE_ENABLE, 1);
308 so_data (so, 1);
309 so_method(so, tesla, NV50TCL_LINE_STIPPLE_PATTERN, 1);
310 so_data (so, (cso->line_stipple_pattern << 8) |
311 cso->line_stipple_factor);
312 } else {
313 so_method(so, tesla, NV50TCL_LINE_STIPPLE_ENABLE, 1);
314 so_data (so, 0);
315 }
316
317 so_method(so, tesla, NV50TCL_POINT_SIZE, 1);
318 so_data (so, fui(cso->point_size));
319
320 so_method(so, tesla, NV50TCL_POINT_SPRITE_ENABLE, 1);
321 so_data (so, cso->point_sprite);
322
323 so_method(so, tesla, NV50TCL_POLYGON_MODE_FRONT, 3);
324 if (cso->front_winding == PIPE_WINDING_CCW) {
325 so_data(so, nvgl_polygon_mode(cso->fill_ccw));
326 so_data(so, nvgl_polygon_mode(cso->fill_cw));
327 } else {
328 so_data(so, nvgl_polygon_mode(cso->fill_cw));
329 so_data(so, nvgl_polygon_mode(cso->fill_ccw));
330 }
331 so_data(so, cso->poly_smooth ? 1 : 0);
332
333 so_method(so, tesla, NV50TCL_CULL_FACE_ENABLE, 3);
334 so_data (so, cso->cull_mode != PIPE_WINDING_NONE);
335 if (cso->front_winding == PIPE_WINDING_CCW) {
336 so_data(so, NV50TCL_FRONT_FACE_CCW);
337 switch (cso->cull_mode) {
338 case PIPE_WINDING_CCW:
339 so_data(so, NV50TCL_CULL_FACE_FRONT);
340 break;
341 case PIPE_WINDING_CW:
342 so_data(so, NV50TCL_CULL_FACE_BACK);
343 break;
344 case PIPE_WINDING_BOTH:
345 so_data(so, NV50TCL_CULL_FACE_FRONT_AND_BACK);
346 break;
347 default:
348 so_data(so, NV50TCL_CULL_FACE_BACK);
349 break;
350 }
351 } else {
352 so_data(so, NV50TCL_FRONT_FACE_CW);
353 switch (cso->cull_mode) {
354 case PIPE_WINDING_CCW:
355 so_data(so, NV50TCL_CULL_FACE_BACK);
356 break;
357 case PIPE_WINDING_CW:
358 so_data(so, NV50TCL_CULL_FACE_FRONT);
359 break;
360 case PIPE_WINDING_BOTH:
361 so_data(so, NV50TCL_CULL_FACE_FRONT_AND_BACK);
362 break;
363 default:
364 so_data(so, NV50TCL_CULL_FACE_BACK);
365 break;
366 }
367 }
368
369 so_method(so, tesla, NV50TCL_POLYGON_STIPPLE_ENABLE, 1);
370 so_data (so, cso->poly_stipple_enable ? 1 : 0);
371
372 so_method(so, tesla, NV50TCL_POLYGON_OFFSET_POINT_ENABLE, 3);
373 if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_POINT) ||
374 (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_POINT))
375 so_data(so, 1);
376 else
377 so_data(so, 0);
378 if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_LINE) ||
379 (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_LINE))
380 so_data(so, 1);
381 else
382 so_data(so, 0);
383 if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_FILL) ||
384 (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_FILL))
385 so_data(so, 1);
386 else
387 so_data(so, 0);
388
389 if (cso->offset_cw || cso->offset_ccw) {
390 so_method(so, tesla, NV50TCL_POLYGON_OFFSET_FACTOR, 1);
391 so_data (so, fui(cso->offset_scale));
392 so_method(so, tesla, NV50TCL_POLYGON_OFFSET_UNITS, 1);
393 so_data (so, fui(cso->offset_units * 2.0f));
394 }
395
396 rso->pipe = *cso;
397 so_ref(so, &rso->so);
398 so_ref(NULL, &so);
399 return (void *)rso;
400 }
401
402 static void
403 nv50_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso)
404 {
405 struct nv50_context *nv50 = nv50_context(pipe);
406
407 nv50->rasterizer = hwcso;
408 nv50->dirty |= NV50_NEW_RASTERIZER;
409 }
410
411 static void
412 nv50_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
413 {
414 struct nv50_rasterizer_stateobj *rso = hwcso;
415
416 so_ref(NULL, &rso->so);
417 FREE(rso);
418 }
419
420 static void *
421 nv50_depth_stencil_alpha_state_create(struct pipe_context *pipe,
422 const struct pipe_depth_stencil_alpha_state *cso)
423 {
424 struct nouveau_grobj *tesla = nv50_context(pipe)->screen->tesla;
425 struct nv50_zsa_stateobj *zsa = CALLOC_STRUCT(nv50_zsa_stateobj);
426 struct nouveau_stateobj *so = so_new(8, 22, 0);
427
428 so_method(so, tesla, NV50TCL_DEPTH_WRITE_ENABLE, 1);
429 so_data (so, cso->depth.writemask ? 1 : 0);
430 if (cso->depth.enabled) {
431 so_method(so, tesla, NV50TCL_DEPTH_TEST_ENABLE, 1);
432 so_data (so, 1);
433 so_method(so, tesla, NV50TCL_DEPTH_TEST_FUNC, 1);
434 so_data (so, nvgl_comparison_op(cso->depth.func));
435 } else {
436 so_method(so, tesla, NV50TCL_DEPTH_TEST_ENABLE, 1);
437 so_data (so, 0);
438 }
439
440 if (cso->stencil[0].enabled) {
441 so_method(so, tesla, NV50TCL_STENCIL_FRONT_ENABLE, 8);
442 so_data (so, 1);
443 so_data (so, nvgl_stencil_op(cso->stencil[0].fail_op));
444 so_data (so, nvgl_stencil_op(cso->stencil[0].zfail_op));
445 so_data (so, nvgl_stencil_op(cso->stencil[0].zpass_op));
446 so_data (so, nvgl_comparison_op(cso->stencil[0].func));
447 so_data (so, cso->stencil[0].ref_value);
448 so_data (so, cso->stencil[0].writemask);
449 so_data (so, cso->stencil[0].valuemask);
450 } else {
451 so_method(so, tesla, NV50TCL_STENCIL_FRONT_ENABLE, 1);
452 so_data (so, 0);
453 }
454
455 if (cso->stencil[1].enabled) {
456 so_method(so, tesla, NV50TCL_STENCIL_BACK_ENABLE, 5);
457 so_data (so, 1);
458 so_data (so, nvgl_stencil_op(cso->stencil[1].fail_op));
459 so_data (so, nvgl_stencil_op(cso->stencil[1].zfail_op));
460 so_data (so, nvgl_stencil_op(cso->stencil[1].zpass_op));
461 so_data (so, nvgl_comparison_op(cso->stencil[1].func));
462 so_method(so, tesla, NV50TCL_STENCIL_BACK_FUNC_REF, 3);
463 so_data (so, cso->stencil[1].ref_value);
464 so_data (so, cso->stencil[1].writemask);
465 so_data (so, cso->stencil[1].valuemask);
466 } else {
467 so_method(so, tesla, NV50TCL_STENCIL_BACK_ENABLE, 1);
468 so_data (so, 0);
469 }
470
471 if (cso->alpha.enabled) {
472 so_method(so, tesla, NV50TCL_ALPHA_TEST_ENABLE, 1);
473 so_data (so, 1);
474 so_method(so, tesla, NV50TCL_ALPHA_TEST_REF, 2);
475 so_data (so, fui(cso->alpha.ref_value));
476 so_data (so, nvgl_comparison_op(cso->alpha.func));
477 } else {
478 so_method(so, tesla, NV50TCL_ALPHA_TEST_ENABLE, 1);
479 so_data (so, 0);
480 }
481
482 zsa->pipe = *cso;
483 so_ref(so, &zsa->so);
484 so_ref(NULL, &so);
485 return (void *)zsa;
486 }
487
488 static void
489 nv50_depth_stencil_alpha_state_bind(struct pipe_context *pipe, void *hwcso)
490 {
491 struct nv50_context *nv50 = nv50_context(pipe);
492
493 nv50->zsa = hwcso;
494 nv50->dirty |= NV50_NEW_ZSA;
495 }
496
497 static void
498 nv50_depth_stencil_alpha_state_delete(struct pipe_context *pipe, void *hwcso)
499 {
500 struct nv50_zsa_stateobj *zsa = hwcso;
501
502 so_ref(NULL, &zsa->so);
503 FREE(zsa);
504 }
505
506 static void *
507 nv50_vp_state_create(struct pipe_context *pipe,
508 const struct pipe_shader_state *cso)
509 {
510 struct nv50_program *p = CALLOC_STRUCT(nv50_program);
511
512 p->pipe.tokens = tgsi_dup_tokens(cso->tokens);
513 p->type = PIPE_SHADER_VERTEX;
514 tgsi_scan_shader(p->pipe.tokens, &p->info);
515 return (void *)p;
516 }
517
518 static void
519 nv50_vp_state_bind(struct pipe_context *pipe, void *hwcso)
520 {
521 struct nv50_context *nv50 = nv50_context(pipe);
522
523 nv50->vertprog = hwcso;
524 nv50->dirty |= NV50_NEW_VERTPROG;
525 }
526
527 static void
528 nv50_vp_state_delete(struct pipe_context *pipe, void *hwcso)
529 {
530 struct nv50_context *nv50 = nv50_context(pipe);
531 struct nv50_program *p = hwcso;
532
533 nv50_program_destroy(nv50, p);
534 FREE((void*)p->pipe.tokens);
535 FREE(p);
536 }
537
538 static void *
539 nv50_fp_state_create(struct pipe_context *pipe,
540 const struct pipe_shader_state *cso)
541 {
542 struct nv50_program *p = CALLOC_STRUCT(nv50_program);
543
544 p->pipe.tokens = tgsi_dup_tokens(cso->tokens);
545 p->type = PIPE_SHADER_FRAGMENT;
546 tgsi_scan_shader(p->pipe.tokens, &p->info);
547 return (void *)p;
548 }
549
550 static void
551 nv50_fp_state_bind(struct pipe_context *pipe, void *hwcso)
552 {
553 struct nv50_context *nv50 = nv50_context(pipe);
554
555 nv50->fragprog = hwcso;
556 nv50->dirty |= NV50_NEW_FRAGPROG;
557 }
558
559 static void
560 nv50_fp_state_delete(struct pipe_context *pipe, void *hwcso)
561 {
562 struct nv50_context *nv50 = nv50_context(pipe);
563 struct nv50_program *p = hwcso;
564
565 nv50_program_destroy(nv50, p);
566 FREE((void*)p->pipe.tokens);
567 FREE(p);
568 }
569
570 static void
571 nv50_set_blend_color(struct pipe_context *pipe,
572 const struct pipe_blend_color *bcol)
573 {
574 struct nv50_context *nv50 = nv50_context(pipe);
575
576 nv50->blend_colour = *bcol;
577 nv50->dirty |= NV50_NEW_BLEND_COLOUR;
578 }
579
580 static void
581 nv50_set_clip_state(struct pipe_context *pipe,
582 const struct pipe_clip_state *clip)
583 {
584 }
585
586 static void
587 nv50_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
588 const struct pipe_constant_buffer *buf )
589 {
590 struct nv50_context *nv50 = nv50_context(pipe);
591
592 if (shader == PIPE_SHADER_VERTEX) {
593 nv50->constbuf[PIPE_SHADER_VERTEX] = buf->buffer;
594 nv50->dirty |= NV50_NEW_VERTPROG_CB;
595 } else
596 if (shader == PIPE_SHADER_FRAGMENT) {
597 nv50->constbuf[PIPE_SHADER_FRAGMENT] = buf->buffer;
598 nv50->dirty |= NV50_NEW_FRAGPROG_CB;
599 }
600 }
601
602 static void
603 nv50_set_framebuffer_state(struct pipe_context *pipe,
604 const struct pipe_framebuffer_state *fb)
605 {
606 struct nv50_context *nv50 = nv50_context(pipe);
607
608 nv50->framebuffer = *fb;
609 nv50->dirty |= NV50_NEW_FRAMEBUFFER;
610 }
611
612 static void
613 nv50_set_polygon_stipple(struct pipe_context *pipe,
614 const struct pipe_poly_stipple *stipple)
615 {
616 struct nv50_context *nv50 = nv50_context(pipe);
617
618 nv50->stipple = *stipple;
619 nv50->dirty |= NV50_NEW_STIPPLE;
620 }
621
622 static void
623 nv50_set_scissor_state(struct pipe_context *pipe,
624 const struct pipe_scissor_state *s)
625 {
626 struct nv50_context *nv50 = nv50_context(pipe);
627
628 nv50->scissor = *s;
629 nv50->dirty |= NV50_NEW_SCISSOR;
630 }
631
632 static void
633 nv50_set_viewport_state(struct pipe_context *pipe,
634 const struct pipe_viewport_state *vpt)
635 {
636 struct nv50_context *nv50 = nv50_context(pipe);
637
638 nv50->viewport = *vpt;
639 nv50->dirty |= NV50_NEW_VIEWPORT;
640 }
641
642 static void
643 nv50_set_vertex_buffers(struct pipe_context *pipe, unsigned count,
644 const struct pipe_vertex_buffer *vb)
645 {
646 struct nv50_context *nv50 = nv50_context(pipe);
647
648 memcpy(nv50->vtxbuf, vb, sizeof(*vb) * count);
649 nv50->vtxbuf_nr = count;
650
651 nv50->dirty |= NV50_NEW_ARRAYS;
652 }
653
654 static void
655 nv50_set_vertex_elements(struct pipe_context *pipe, unsigned count,
656 const struct pipe_vertex_element *ve)
657 {
658 struct nv50_context *nv50 = nv50_context(pipe);
659
660 memcpy(nv50->vtxelt, ve, sizeof(*ve) * count);
661 nv50->vtxelt_nr = count;
662
663 nv50->dirty |= NV50_NEW_ARRAYS;
664 }
665
666 void
667 nv50_init_state_functions(struct nv50_context *nv50)
668 {
669 nv50->pipe.create_blend_state = nv50_blend_state_create;
670 nv50->pipe.bind_blend_state = nv50_blend_state_bind;
671 nv50->pipe.delete_blend_state = nv50_blend_state_delete;
672
673 nv50->pipe.create_sampler_state = nv50_sampler_state_create;
674 nv50->pipe.delete_sampler_state = nv50_sampler_state_delete;
675 nv50->pipe.bind_fragment_sampler_states = nv50_fp_sampler_state_bind;
676 nv50->pipe.bind_vertex_sampler_states = nv50_vp_sampler_state_bind;
677 nv50->pipe.set_fragment_sampler_textures = nv50_set_fp_sampler_textures;
678 nv50->pipe.set_vertex_sampler_textures = nv50_set_vp_sampler_textures;
679
680 nv50->pipe.create_rasterizer_state = nv50_rasterizer_state_create;
681 nv50->pipe.bind_rasterizer_state = nv50_rasterizer_state_bind;
682 nv50->pipe.delete_rasterizer_state = nv50_rasterizer_state_delete;
683
684 nv50->pipe.create_depth_stencil_alpha_state =
685 nv50_depth_stencil_alpha_state_create;
686 nv50->pipe.bind_depth_stencil_alpha_state =
687 nv50_depth_stencil_alpha_state_bind;
688 nv50->pipe.delete_depth_stencil_alpha_state =
689 nv50_depth_stencil_alpha_state_delete;
690
691 nv50->pipe.create_vs_state = nv50_vp_state_create;
692 nv50->pipe.bind_vs_state = nv50_vp_state_bind;
693 nv50->pipe.delete_vs_state = nv50_vp_state_delete;
694
695 nv50->pipe.create_fs_state = nv50_fp_state_create;
696 nv50->pipe.bind_fs_state = nv50_fp_state_bind;
697 nv50->pipe.delete_fs_state = nv50_fp_state_delete;
698
699 nv50->pipe.set_blend_color = nv50_set_blend_color;
700 nv50->pipe.set_clip_state = nv50_set_clip_state;
701 nv50->pipe.set_constant_buffer = nv50_set_constant_buffer;
702 nv50->pipe.set_framebuffer_state = nv50_set_framebuffer_state;
703 nv50->pipe.set_polygon_stipple = nv50_set_polygon_stipple;
704 nv50->pipe.set_scissor_state = nv50_set_scissor_state;
705 nv50->pipe.set_viewport_state = nv50_set_viewport_state;
706
707 nv50->pipe.set_vertex_buffers = nv50_set_vertex_buffers;
708 nv50->pipe.set_vertex_elements = nv50_set_vertex_elements;
709 }
710