nv50: multiply polygon offset units by 2
[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(64, 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_ANISO:
150 case PIPE_TEX_FILTER_LINEAR:
151 tsc[1] |= NV50TSC_1_1_MAGF_LINEAR;
152 break;
153 case PIPE_TEX_FILTER_NEAREST:
154 default:
155 tsc[1] |= NV50TSC_1_1_MAGF_NEAREST;
156 break;
157 }
158
159 switch (cso->min_img_filter) {
160 case PIPE_TEX_FILTER_ANISO:
161 case PIPE_TEX_FILTER_LINEAR:
162 tsc[1] |= NV50TSC_1_1_MINF_LINEAR;
163 break;
164 case PIPE_TEX_FILTER_NEAREST:
165 default:
166 tsc[1] |= NV50TSC_1_1_MINF_NEAREST;
167 break;
168 }
169
170 switch (cso->min_mip_filter) {
171 case PIPE_TEX_MIPFILTER_LINEAR:
172 tsc[1] |= NV50TSC_1_1_MIPF_LINEAR;
173 break;
174 case PIPE_TEX_MIPFILTER_NEAREST:
175 tsc[1] |= NV50TSC_1_1_MIPF_NEAREST;
176 break;
177 case PIPE_TEX_MIPFILTER_NONE:
178 default:
179 tsc[1] |= NV50TSC_1_1_MIPF_NONE;
180 break;
181 }
182
183 if (cso->max_anisotropy >= 16.0)
184 tsc[0] |= (7 << 20);
185 else
186 if (cso->max_anisotropy >= 12.0)
187 tsc[0] |= (6 << 20);
188 else {
189 tsc[0] |= (int)(cso->max_anisotropy * 0.5f) << 20;
190
191 if (cso->max_anisotropy >= 4.0)
192 tsc[1] |= NV50TSC_1_1_UNKN_ANISO_35;
193 else
194 if (cso->max_anisotropy >= 2.0)
195 tsc[1] |= NV50TSC_1_1_UNKN_ANISO_15;
196 }
197
198 if (cso->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
199 /* XXX: must be deactivated for non-shadow textures */
200 tsc[0] |= (1 << 9);
201 tsc[0] |= (nvgl_comparison_op(cso->compare_func) & 0x7) << 10;
202 }
203
204 limit = CLAMP(cso->lod_bias, -16.0, 15.0);
205 tsc[1] |= ((int)(limit * 256.0) & 0x1fff) << 12;
206
207 tsc[2] |= ((int)CLAMP(cso->max_lod, 0.0, 15.0) << 20) |
208 ((int)CLAMP(cso->min_lod, 0.0, 15.0) << 8);
209
210 tsc[4] = fui(cso->border_color[0]);
211 tsc[5] = fui(cso->border_color[1]);
212 tsc[6] = fui(cso->border_color[2]);
213 tsc[7] = fui(cso->border_color[3]);
214
215 sso->normalized = cso->normalized_coords;
216 return (void *)sso;
217 }
218
219 static INLINE void
220 nv50_sampler_state_bind(struct pipe_context *pipe, unsigned type,
221 unsigned nr, void **sampler)
222 {
223 struct nv50_context *nv50 = nv50_context(pipe);
224
225 memcpy(nv50->sampler[type], sampler, nr * sizeof(void *));
226
227 nv50->sampler_nr[type] = nr;
228 nv50->dirty |= NV50_NEW_SAMPLER;
229 }
230
231 static void
232 nv50_vp_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **s)
233 {
234 nv50_sampler_state_bind(pipe, PIPE_SHADER_VERTEX, nr, s);
235 }
236
237 static void
238 nv50_fp_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **s)
239 {
240 nv50_sampler_state_bind(pipe, PIPE_SHADER_FRAGMENT, nr, s);
241 }
242
243 static void
244 nv50_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
245 {
246 FREE(hwcso);
247 }
248
249 static INLINE void
250 nv50_set_sampler_texture(struct pipe_context *pipe, unsigned type,
251 unsigned nr, struct pipe_texture **pt)
252 {
253 struct nv50_context *nv50 = nv50_context(pipe);
254 unsigned i;
255
256 for (i = 0; i < nr; i++)
257 pipe_texture_reference((void *)&nv50->miptree[type][i], pt[i]);
258 for (i = nr; i < nv50->miptree_nr[type]; i++)
259 pipe_texture_reference((void *)&nv50->miptree[type][i], NULL);
260
261 nv50->miptree_nr[type] = nr;
262 nv50->dirty |= NV50_NEW_TEXTURE;
263 }
264
265 static void
266 nv50_set_vp_sampler_textures(struct pipe_context *pipe,
267 unsigned nr, struct pipe_texture **pt)
268 {
269 nv50_set_sampler_texture(pipe, PIPE_SHADER_VERTEX, nr, pt);
270 }
271
272 static void
273 nv50_set_fp_sampler_textures(struct pipe_context *pipe,
274 unsigned nr, struct pipe_texture **pt)
275 {
276 nv50_set_sampler_texture(pipe, PIPE_SHADER_FRAGMENT, nr, pt);
277 }
278
279 static void *
280 nv50_rasterizer_state_create(struct pipe_context *pipe,
281 const struct pipe_rasterizer_state *cso)
282 {
283 struct nouveau_stateobj *so = so_new(64, 0);
284 struct nouveau_grobj *tesla = nv50_context(pipe)->screen->tesla;
285 struct nv50_rasterizer_stateobj *rso =
286 CALLOC_STRUCT(nv50_rasterizer_stateobj);
287
288 /*XXX: ignored
289 * - light_twosize
290 * - point_smooth
291 * - multisample
292 * - point_sprite / sprite_coord_mode
293 */
294
295 so_method(so, tesla, NV50TCL_SHADE_MODEL, 1);
296 so_data (so, cso->flatshade ? NV50TCL_SHADE_MODEL_FLAT :
297 NV50TCL_SHADE_MODEL_SMOOTH);
298 so_method(so, tesla, NV50TCL_PROVOKING_VERTEX_LAST, 1);
299 so_data (so, cso->flatshade_first ? 0 : 1);
300
301 so_method(so, tesla, NV50TCL_VERTEX_TWO_SIDE_ENABLE, 1);
302 so_data (so, cso->light_twoside);
303
304 so_method(so, tesla, NV50TCL_LINE_WIDTH, 1);
305 so_data (so, fui(cso->line_width));
306 so_method(so, tesla, NV50TCL_LINE_SMOOTH_ENABLE, 1);
307 so_data (so, cso->line_smooth ? 1 : 0);
308 if (cso->line_stipple_enable) {
309 so_method(so, tesla, NV50TCL_LINE_STIPPLE_ENABLE, 1);
310 so_data (so, 1);
311 so_method(so, tesla, NV50TCL_LINE_STIPPLE_PATTERN, 1);
312 so_data (so, (cso->line_stipple_pattern << 8) |
313 cso->line_stipple_factor);
314 } else {
315 so_method(so, tesla, NV50TCL_LINE_STIPPLE_ENABLE, 1);
316 so_data (so, 0);
317 }
318
319 so_method(so, tesla, NV50TCL_POINT_SIZE, 1);
320 so_data (so, fui(cso->point_size));
321
322 so_method(so, tesla, NV50TCL_POINT_SPRITE_ENABLE, 1);
323 so_data (so, cso->point_sprite);
324
325 so_method(so, tesla, NV50TCL_POLYGON_MODE_FRONT, 3);
326 if (cso->front_winding == PIPE_WINDING_CCW) {
327 so_data(so, nvgl_polygon_mode(cso->fill_ccw));
328 so_data(so, nvgl_polygon_mode(cso->fill_cw));
329 } else {
330 so_data(so, nvgl_polygon_mode(cso->fill_cw));
331 so_data(so, nvgl_polygon_mode(cso->fill_ccw));
332 }
333 so_data(so, cso->poly_smooth ? 1 : 0);
334
335 so_method(so, tesla, NV50TCL_CULL_FACE_ENABLE, 3);
336 so_data (so, cso->cull_mode != PIPE_WINDING_NONE);
337 if (cso->front_winding == PIPE_WINDING_CCW) {
338 so_data(so, NV50TCL_FRONT_FACE_CCW);
339 switch (cso->cull_mode) {
340 case PIPE_WINDING_CCW:
341 so_data(so, NV50TCL_CULL_FACE_FRONT);
342 break;
343 case PIPE_WINDING_CW:
344 so_data(so, NV50TCL_CULL_FACE_BACK);
345 break;
346 case PIPE_WINDING_BOTH:
347 so_data(so, NV50TCL_CULL_FACE_FRONT_AND_BACK);
348 break;
349 default:
350 so_data(so, NV50TCL_CULL_FACE_BACK);
351 break;
352 }
353 } else {
354 so_data(so, NV50TCL_FRONT_FACE_CW);
355 switch (cso->cull_mode) {
356 case PIPE_WINDING_CCW:
357 so_data(so, NV50TCL_CULL_FACE_BACK);
358 break;
359 case PIPE_WINDING_CW:
360 so_data(so, NV50TCL_CULL_FACE_FRONT);
361 break;
362 case PIPE_WINDING_BOTH:
363 so_data(so, NV50TCL_CULL_FACE_FRONT_AND_BACK);
364 break;
365 default:
366 so_data(so, NV50TCL_CULL_FACE_BACK);
367 break;
368 }
369 }
370
371 so_method(so, tesla, NV50TCL_POLYGON_STIPPLE_ENABLE, 1);
372 so_data (so, cso->poly_stipple_enable ? 1 : 0);
373
374 so_method(so, tesla, NV50TCL_POLYGON_OFFSET_POINT_ENABLE, 3);
375 if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_POINT) ||
376 (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_POINT))
377 so_data(so, 1);
378 else
379 so_data(so, 0);
380 if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_LINE) ||
381 (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_LINE))
382 so_data(so, 1);
383 else
384 so_data(so, 0);
385 if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_FILL) ||
386 (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_FILL))
387 so_data(so, 1);
388 else
389 so_data(so, 0);
390
391 if (cso->offset_cw || cso->offset_ccw) {
392 so_method(so, tesla, NV50TCL_POLYGON_OFFSET_FACTOR, 1);
393 so_data (so, fui(cso->offset_scale));
394 so_method(so, tesla, NV50TCL_POLYGON_OFFSET_UNITS, 1);
395 so_data (so, fui(cso->offset_units * 2.0f));
396 }
397
398 rso->pipe = *cso;
399 so_ref(so, &rso->so);
400 so_ref(NULL, &so);
401 return (void *)rso;
402 }
403
404 static void
405 nv50_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso)
406 {
407 struct nv50_context *nv50 = nv50_context(pipe);
408
409 nv50->rasterizer = hwcso;
410 nv50->dirty |= NV50_NEW_RASTERIZER;
411 }
412
413 static void
414 nv50_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
415 {
416 struct nv50_rasterizer_stateobj *rso = hwcso;
417
418 so_ref(NULL, &rso->so);
419 FREE(rso);
420 }
421
422 static void *
423 nv50_depth_stencil_alpha_state_create(struct pipe_context *pipe,
424 const struct pipe_depth_stencil_alpha_state *cso)
425 {
426 struct nouveau_grobj *tesla = nv50_context(pipe)->screen->tesla;
427 struct nv50_zsa_stateobj *zsa = CALLOC_STRUCT(nv50_zsa_stateobj);
428 struct nouveau_stateobj *so = so_new(64, 0);
429
430 so_method(so, tesla, NV50TCL_DEPTH_WRITE_ENABLE, 1);
431 so_data (so, cso->depth.writemask ? 1 : 0);
432 if (cso->depth.enabled) {
433 so_method(so, tesla, NV50TCL_DEPTH_TEST_ENABLE, 1);
434 so_data (so, 1);
435 so_method(so, tesla, NV50TCL_DEPTH_TEST_FUNC, 1);
436 so_data (so, nvgl_comparison_op(cso->depth.func));
437 } else {
438 so_method(so, tesla, NV50TCL_DEPTH_TEST_ENABLE, 1);
439 so_data (so, 0);
440 }
441
442 if (cso->stencil[0].enabled) {
443 so_method(so, tesla, NV50TCL_STENCIL_FRONT_ENABLE, 8);
444 so_data (so, 1);
445 so_data (so, nvgl_stencil_op(cso->stencil[0].fail_op));
446 so_data (so, nvgl_stencil_op(cso->stencil[0].zfail_op));
447 so_data (so, nvgl_stencil_op(cso->stencil[0].zpass_op));
448 so_data (so, nvgl_comparison_op(cso->stencil[0].func));
449 so_data (so, cso->stencil[0].ref_value);
450 so_data (so, cso->stencil[0].writemask);
451 so_data (so, cso->stencil[0].valuemask);
452 } else {
453 so_method(so, tesla, NV50TCL_STENCIL_FRONT_ENABLE, 1);
454 so_data (so, 0);
455 }
456
457 if (cso->stencil[1].enabled) {
458 so_method(so, tesla, NV50TCL_STENCIL_BACK_ENABLE, 5);
459 so_data (so, 1);
460 so_data (so, nvgl_stencil_op(cso->stencil[1].fail_op));
461 so_data (so, nvgl_stencil_op(cso->stencil[1].zfail_op));
462 so_data (so, nvgl_stencil_op(cso->stencil[1].zpass_op));
463 so_data (so, nvgl_comparison_op(cso->stencil[1].func));
464 so_method(so, tesla, NV50TCL_STENCIL_BACK_FUNC_REF, 3);
465 so_data (so, cso->stencil[1].ref_value);
466 so_data (so, cso->stencil[1].writemask);
467 so_data (so, cso->stencil[1].valuemask);
468 } else {
469 so_method(so, tesla, NV50TCL_STENCIL_BACK_ENABLE, 1);
470 so_data (so, 0);
471 }
472
473 if (cso->alpha.enabled) {
474 so_method(so, tesla, NV50TCL_ALPHA_TEST_ENABLE, 1);
475 so_data (so, 1);
476 so_method(so, tesla, NV50TCL_ALPHA_TEST_REF, 2);
477 so_data (so, fui(cso->alpha.ref_value));
478 so_data (so, nvgl_comparison_op(cso->alpha.func));
479 } else {
480 so_method(so, tesla, NV50TCL_ALPHA_TEST_ENABLE, 1);
481 so_data (so, 0);
482 }
483
484 zsa->pipe = *cso;
485 so_ref(so, &zsa->so);
486 so_ref(NULL, &so);
487 return (void *)zsa;
488 }
489
490 static void
491 nv50_depth_stencil_alpha_state_bind(struct pipe_context *pipe, void *hwcso)
492 {
493 struct nv50_context *nv50 = nv50_context(pipe);
494
495 nv50->zsa = hwcso;
496 nv50->dirty |= NV50_NEW_ZSA;
497 }
498
499 static void
500 nv50_depth_stencil_alpha_state_delete(struct pipe_context *pipe, void *hwcso)
501 {
502 struct nv50_zsa_stateobj *zsa = hwcso;
503
504 so_ref(NULL, &zsa->so);
505 FREE(zsa);
506 }
507
508 static void *
509 nv50_vp_state_create(struct pipe_context *pipe,
510 const struct pipe_shader_state *cso)
511 {
512 struct nv50_program *p = CALLOC_STRUCT(nv50_program);
513
514 p->pipe.tokens = tgsi_dup_tokens(cso->tokens);
515 p->type = PIPE_SHADER_VERTEX;
516 tgsi_scan_shader(p->pipe.tokens, &p->info);
517 return (void *)p;
518 }
519
520 static void
521 nv50_vp_state_bind(struct pipe_context *pipe, void *hwcso)
522 {
523 struct nv50_context *nv50 = nv50_context(pipe);
524
525 nv50->vertprog = hwcso;
526 nv50->dirty |= NV50_NEW_VERTPROG;
527 }
528
529 static void
530 nv50_vp_state_delete(struct pipe_context *pipe, void *hwcso)
531 {
532 struct nv50_context *nv50 = nv50_context(pipe);
533 struct nv50_program *p = hwcso;
534
535 nv50_program_destroy(nv50, p);
536 FREE((void*)p->pipe.tokens);
537 FREE(p);
538 }
539
540 static void *
541 nv50_fp_state_create(struct pipe_context *pipe,
542 const struct pipe_shader_state *cso)
543 {
544 struct nv50_program *p = CALLOC_STRUCT(nv50_program);
545
546 p->pipe.tokens = tgsi_dup_tokens(cso->tokens);
547 p->type = PIPE_SHADER_FRAGMENT;
548 tgsi_scan_shader(p->pipe.tokens, &p->info);
549 return (void *)p;
550 }
551
552 static void
553 nv50_fp_state_bind(struct pipe_context *pipe, void *hwcso)
554 {
555 struct nv50_context *nv50 = nv50_context(pipe);
556
557 nv50->fragprog = hwcso;
558 nv50->dirty |= NV50_NEW_FRAGPROG;
559 }
560
561 static void
562 nv50_fp_state_delete(struct pipe_context *pipe, void *hwcso)
563 {
564 struct nv50_context *nv50 = nv50_context(pipe);
565 struct nv50_program *p = hwcso;
566
567 nv50_program_destroy(nv50, p);
568 FREE((void*)p->pipe.tokens);
569 FREE(p);
570 }
571
572 static void
573 nv50_set_blend_color(struct pipe_context *pipe,
574 const struct pipe_blend_color *bcol)
575 {
576 struct nv50_context *nv50 = nv50_context(pipe);
577
578 nv50->blend_colour = *bcol;
579 nv50->dirty |= NV50_NEW_BLEND_COLOUR;
580 }
581
582 static void
583 nv50_set_clip_state(struct pipe_context *pipe,
584 const struct pipe_clip_state *clip)
585 {
586 }
587
588 static void
589 nv50_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
590 const struct pipe_constant_buffer *buf )
591 {
592 struct nv50_context *nv50 = nv50_context(pipe);
593
594 if (shader == PIPE_SHADER_VERTEX) {
595 nv50->constbuf[PIPE_SHADER_VERTEX] = buf->buffer;
596 nv50->dirty |= NV50_NEW_VERTPROG_CB;
597 } else
598 if (shader == PIPE_SHADER_FRAGMENT) {
599 nv50->constbuf[PIPE_SHADER_FRAGMENT] = buf->buffer;
600 nv50->dirty |= NV50_NEW_FRAGPROG_CB;
601 }
602 }
603
604 static void
605 nv50_set_framebuffer_state(struct pipe_context *pipe,
606 const struct pipe_framebuffer_state *fb)
607 {
608 struct nv50_context *nv50 = nv50_context(pipe);
609
610 nv50->framebuffer = *fb;
611 nv50->dirty |= NV50_NEW_FRAMEBUFFER;
612 }
613
614 static void
615 nv50_set_polygon_stipple(struct pipe_context *pipe,
616 const struct pipe_poly_stipple *stipple)
617 {
618 struct nv50_context *nv50 = nv50_context(pipe);
619
620 nv50->stipple = *stipple;
621 nv50->dirty |= NV50_NEW_STIPPLE;
622 }
623
624 static void
625 nv50_set_scissor_state(struct pipe_context *pipe,
626 const struct pipe_scissor_state *s)
627 {
628 struct nv50_context *nv50 = nv50_context(pipe);
629
630 nv50->scissor = *s;
631 nv50->dirty |= NV50_NEW_SCISSOR;
632 }
633
634 static void
635 nv50_set_viewport_state(struct pipe_context *pipe,
636 const struct pipe_viewport_state *vpt)
637 {
638 struct nv50_context *nv50 = nv50_context(pipe);
639
640 nv50->viewport = *vpt;
641 nv50->dirty |= NV50_NEW_VIEWPORT;
642 }
643
644 static void
645 nv50_set_vertex_buffers(struct pipe_context *pipe, unsigned count,
646 const struct pipe_vertex_buffer *vb)
647 {
648 struct nv50_context *nv50 = nv50_context(pipe);
649
650 memcpy(nv50->vtxbuf, vb, sizeof(*vb) * count);
651 nv50->vtxbuf_nr = count;
652
653 nv50->dirty |= NV50_NEW_ARRAYS;
654 }
655
656 static void
657 nv50_set_vertex_elements(struct pipe_context *pipe, unsigned count,
658 const struct pipe_vertex_element *ve)
659 {
660 struct nv50_context *nv50 = nv50_context(pipe);
661
662 memcpy(nv50->vtxelt, ve, sizeof(*ve) * count);
663 nv50->vtxelt_nr = count;
664
665 nv50->dirty |= NV50_NEW_ARRAYS;
666 }
667
668 void
669 nv50_init_state_functions(struct nv50_context *nv50)
670 {
671 nv50->pipe.create_blend_state = nv50_blend_state_create;
672 nv50->pipe.bind_blend_state = nv50_blend_state_bind;
673 nv50->pipe.delete_blend_state = nv50_blend_state_delete;
674
675 nv50->pipe.create_sampler_state = nv50_sampler_state_create;
676 nv50->pipe.delete_sampler_state = nv50_sampler_state_delete;
677 nv50->pipe.bind_fragment_sampler_states = nv50_fp_sampler_state_bind;
678 nv50->pipe.bind_vertex_sampler_states = nv50_vp_sampler_state_bind;
679 nv50->pipe.set_fragment_sampler_textures = nv50_set_fp_sampler_textures;
680 nv50->pipe.set_vertex_sampler_textures = nv50_set_vp_sampler_textures;
681
682 nv50->pipe.create_rasterizer_state = nv50_rasterizer_state_create;
683 nv50->pipe.bind_rasterizer_state = nv50_rasterizer_state_bind;
684 nv50->pipe.delete_rasterizer_state = nv50_rasterizer_state_delete;
685
686 nv50->pipe.create_depth_stencil_alpha_state =
687 nv50_depth_stencil_alpha_state_create;
688 nv50->pipe.bind_depth_stencil_alpha_state =
689 nv50_depth_stencil_alpha_state_bind;
690 nv50->pipe.delete_depth_stencil_alpha_state =
691 nv50_depth_stencil_alpha_state_delete;
692
693 nv50->pipe.create_vs_state = nv50_vp_state_create;
694 nv50->pipe.bind_vs_state = nv50_vp_state_bind;
695 nv50->pipe.delete_vs_state = nv50_vp_state_delete;
696
697 nv50->pipe.create_fs_state = nv50_fp_state_create;
698 nv50->pipe.bind_fs_state = nv50_fp_state_bind;
699 nv50->pipe.delete_fs_state = nv50_fp_state_delete;
700
701 nv50->pipe.set_blend_color = nv50_set_blend_color;
702 nv50->pipe.set_clip_state = nv50_set_clip_state;
703 nv50->pipe.set_constant_buffer = nv50_set_constant_buffer;
704 nv50->pipe.set_framebuffer_state = nv50_set_framebuffer_state;
705 nv50->pipe.set_polygon_stipple = nv50_set_polygon_stipple;
706 nv50->pipe.set_scissor_state = nv50_set_scissor_state;
707 nv50->pipe.set_viewport_state = nv50_set_viewport_state;
708
709 nv50->pipe.set_vertex_buffers = nv50_set_vertex_buffers;
710 nv50->pipe.set_vertex_elements = nv50_set_vertex_elements;
711 }
712