i915: Use the new draw vbuf interface
[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 return (void *)bso;
89 }
90
91 static void
92 nv50_blend_state_bind(struct pipe_context *pipe, void *hwcso)
93 {
94 struct nv50_context *nv50 = nv50_context(pipe);
95
96 nv50->blend = hwcso;
97 nv50->dirty |= NV50_NEW_BLEND;
98 }
99
100 static void
101 nv50_blend_state_delete(struct pipe_context *pipe, void *hwcso)
102 {
103 struct nv50_blend_stateobj *bso = hwcso;
104
105 so_ref(NULL, &bso->so);
106 FREE(bso);
107 }
108
109 static INLINE unsigned
110 wrap_mode(unsigned wrap)
111 {
112 switch (wrap) {
113 case PIPE_TEX_WRAP_REPEAT:
114 return NV50TSC_1_0_WRAPS_REPEAT;
115 case PIPE_TEX_WRAP_MIRROR_REPEAT:
116 return NV50TSC_1_0_WRAPS_MIRROR_REPEAT;
117 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
118 return NV50TSC_1_0_WRAPS_CLAMP_TO_EDGE;
119 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
120 return NV50TSC_1_0_WRAPS_CLAMP_TO_BORDER;
121 case PIPE_TEX_WRAP_CLAMP:
122 return NV50TSC_1_0_WRAPS_CLAMP;
123 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
124 return NV50TSC_1_0_WRAPS_MIRROR_CLAMP_TO_EDGE;
125 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
126 return NV50TSC_1_0_WRAPS_MIRROR_CLAMP_TO_BORDER;
127 case PIPE_TEX_WRAP_MIRROR_CLAMP:
128 return NV50TSC_1_0_WRAPS_MIRROR_CLAMP;
129 default:
130 NOUVEAU_ERR("unknown wrap mode: %d\n", wrap);
131 return NV50TSC_1_0_WRAPS_REPEAT;
132 }
133 }
134 static void *
135 nv50_sampler_state_create(struct pipe_context *pipe,
136 const struct pipe_sampler_state *cso)
137 {
138 unsigned *tsc = CALLOC(8, sizeof(unsigned));
139
140 tsc[0] = (0x00024000 |
141 (wrap_mode(cso->wrap_s) << 0) |
142 (wrap_mode(cso->wrap_t) << 3) |
143 (wrap_mode(cso->wrap_r) << 6));
144
145 switch (cso->mag_img_filter) {
146 case PIPE_TEX_FILTER_LINEAR:
147 tsc[1] |= NV50TSC_1_1_MAGF_LINEAR;
148 break;
149 case PIPE_TEX_FILTER_NEAREST:
150 default:
151 tsc[1] |= NV50TSC_1_1_MAGF_NEAREST;
152 break;
153 }
154
155 switch (cso->min_img_filter) {
156 case PIPE_TEX_FILTER_LINEAR:
157 tsc[1] |= NV50TSC_1_1_MINF_LINEAR;
158 break;
159 case PIPE_TEX_FILTER_NEAREST:
160 default:
161 tsc[1] |= NV50TSC_1_1_MINF_NEAREST;
162 break;
163 }
164
165 switch (cso->min_mip_filter) {
166 case PIPE_TEX_MIPFILTER_LINEAR:
167 tsc[1] |= NV50TSC_1_1_MIPF_LINEAR;
168 break;
169 case PIPE_TEX_MIPFILTER_NEAREST:
170 tsc[1] |= NV50TSC_1_1_MIPF_NEAREST;
171 break;
172 case PIPE_TEX_MIPFILTER_NONE:
173 default:
174 tsc[1] |= NV50TSC_1_1_MIPF_NONE;
175 break;
176 }
177
178 if (cso->max_anisotropy >= 16.0)
179 tsc[0] |= (7 << 20);
180 else
181 if (cso->max_anisotropy >= 12.0)
182 tsc[0] |= (6 << 20);
183 else
184 if (cso->max_anisotropy >= 10.0)
185 tsc[0] |= (5 << 20);
186 else
187 if (cso->max_anisotropy >= 8.0)
188 tsc[0] |= (4 << 20);
189 else
190 if (cso->max_anisotropy >= 6.0)
191 tsc[0] |= (3 << 20);
192 else
193 if (cso->max_anisotropy >= 4.0)
194 tsc[0] |= (2 << 20);
195 else
196 if (cso->max_anisotropy >= 2.0)
197 tsc[0] |= (1 << 20);
198
199 if (cso->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
200 tsc[0] |= (1 << 8);
201 tsc[0] |= (nvgl_comparison_op(cso->compare_func) & 0x7);
202 }
203
204 return (void *)tsc;
205 }
206
207 static void
208 nv50_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **sampler)
209 {
210 struct nv50_context *nv50 = nv50_context(pipe);
211 int i;
212
213 nv50->sampler_nr = nr;
214 for (i = 0; i < nv50->sampler_nr; i++)
215 nv50->sampler[i] = sampler[i];
216
217 nv50->dirty |= NV50_NEW_SAMPLER;
218 }
219
220 static void
221 nv50_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
222 {
223 FREE(hwcso);
224 }
225
226 static void
227 nv50_set_sampler_texture(struct pipe_context *pipe, unsigned nr,
228 struct pipe_texture **pt)
229 {
230 struct nv50_context *nv50 = nv50_context(pipe);
231 int i;
232
233 for (i = 0; i < nr; i++)
234 pipe_texture_reference((void *)&nv50->miptree[i], pt[i]);
235 for (i = nr; i < nv50->miptree_nr; i++)
236 pipe_texture_reference((void *)&nv50->miptree[i], NULL);
237
238 nv50->miptree_nr = nr;
239 nv50->dirty |= NV50_NEW_TEXTURE;
240 }
241
242 static void *
243 nv50_rasterizer_state_create(struct pipe_context *pipe,
244 const struct pipe_rasterizer_state *cso)
245 {
246 struct nouveau_stateobj *so = so_new(64, 0);
247 struct nouveau_grobj *tesla = nv50_context(pipe)->screen->tesla;
248 struct nv50_rasterizer_stateobj *rso =
249 CALLOC_STRUCT(nv50_rasterizer_stateobj);
250
251 /*XXX: ignored
252 * - light_twosize
253 * - point_smooth
254 * - multisample
255 * - point_sprite / sprite_coord_mode
256 */
257
258 so_method(so, tesla, NV50TCL_SHADE_MODEL, 1);
259 so_data (so, cso->flatshade ? NV50TCL_SHADE_MODEL_FLAT :
260 NV50TCL_SHADE_MODEL_SMOOTH);
261
262 so_method(so, tesla, NV50TCL_LINE_WIDTH, 1);
263 so_data (so, fui(cso->line_width));
264 so_method(so, tesla, NV50TCL_LINE_SMOOTH_ENABLE, 1);
265 so_data (so, cso->line_smooth ? 1 : 0);
266 if (cso->line_stipple_enable) {
267 so_method(so, tesla, NV50TCL_LINE_STIPPLE_ENABLE, 1);
268 so_data (so, 1);
269 so_method(so, tesla, NV50TCL_LINE_STIPPLE_PATTERN, 1);
270 so_data (so, (cso->line_stipple_pattern << 8) |
271 cso->line_stipple_factor);
272 } else {
273 so_method(so, tesla, NV50TCL_LINE_STIPPLE_ENABLE, 1);
274 so_data (so, 0);
275 }
276
277 so_method(so, tesla, NV50TCL_POINT_SIZE, 1);
278 so_data (so, fui(cso->point_size));
279
280 so_method(so, tesla, NV50TCL_POLYGON_MODE_FRONT, 3);
281 if (cso->front_winding == PIPE_WINDING_CCW) {
282 so_data(so, nvgl_polygon_mode(cso->fill_ccw));
283 so_data(so, nvgl_polygon_mode(cso->fill_cw));
284 } else {
285 so_data(so, nvgl_polygon_mode(cso->fill_cw));
286 so_data(so, nvgl_polygon_mode(cso->fill_ccw));
287 }
288 so_data(so, cso->poly_smooth ? 1 : 0);
289
290 so_method(so, tesla, NV50TCL_CULL_FACE_ENABLE, 3);
291 so_data (so, cso->cull_mode != PIPE_WINDING_NONE);
292 if (cso->front_winding == PIPE_WINDING_CCW) {
293 so_data(so, NV50TCL_FRONT_FACE_CCW);
294 switch (cso->cull_mode) {
295 case PIPE_WINDING_CCW:
296 so_data(so, NV50TCL_CULL_FACE_FRONT);
297 break;
298 case PIPE_WINDING_CW:
299 so_data(so, NV50TCL_CULL_FACE_BACK);
300 break;
301 case PIPE_WINDING_BOTH:
302 so_data(so, NV50TCL_CULL_FACE_FRONT_AND_BACK);
303 break;
304 default:
305 so_data(so, NV50TCL_CULL_FACE_BACK);
306 break;
307 }
308 } else {
309 so_data(so, NV50TCL_FRONT_FACE_CW);
310 switch (cso->cull_mode) {
311 case PIPE_WINDING_CCW:
312 so_data(so, NV50TCL_CULL_FACE_BACK);
313 break;
314 case PIPE_WINDING_CW:
315 so_data(so, NV50TCL_CULL_FACE_FRONT);
316 break;
317 case PIPE_WINDING_BOTH:
318 so_data(so, NV50TCL_CULL_FACE_FRONT_AND_BACK);
319 break;
320 default:
321 so_data(so, NV50TCL_CULL_FACE_BACK);
322 break;
323 }
324 }
325
326 so_method(so, tesla, NV50TCL_POLYGON_STIPPLE_ENABLE, 1);
327 so_data (so, cso->poly_stipple_enable ? 1 : 0);
328
329 so_method(so, tesla, NV50TCL_POLYGON_OFFSET_POINT_ENABLE, 3);
330 if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_POINT) ||
331 (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_POINT))
332 so_data(so, 1);
333 else
334 so_data(so, 0);
335 if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_LINE) ||
336 (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_LINE))
337 so_data(so, 1);
338 else
339 so_data(so, 0);
340 if ((cso->offset_cw && cso->fill_cw == PIPE_POLYGON_MODE_FILL) ||
341 (cso->offset_ccw && cso->fill_ccw == PIPE_POLYGON_MODE_FILL))
342 so_data(so, 1);
343 else
344 so_data(so, 0);
345
346 if (cso->offset_cw || cso->offset_ccw) {
347 so_method(so, tesla, NV50TCL_POLYGON_OFFSET_FACTOR, 1);
348 so_data (so, fui(cso->offset_scale));
349 so_method(so, tesla, NV50TCL_POLYGON_OFFSET_UNITS, 1);
350 so_data (so, fui(cso->offset_units));
351 }
352
353 rso->pipe = *cso;
354 so_ref(so, &rso->so);
355 return (void *)rso;
356 }
357
358 static void
359 nv50_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso)
360 {
361 struct nv50_context *nv50 = nv50_context(pipe);
362
363 nv50->rasterizer = hwcso;
364 nv50->dirty |= NV50_NEW_RASTERIZER;
365 }
366
367 static void
368 nv50_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
369 {
370 struct nv50_rasterizer_stateobj *rso = hwcso;
371
372 so_ref(NULL, &rso->so);
373 FREE(rso);
374 }
375
376 static void *
377 nv50_depth_stencil_alpha_state_create(struct pipe_context *pipe,
378 const struct pipe_depth_stencil_alpha_state *cso)
379 {
380 struct nouveau_grobj *tesla = nv50_context(pipe)->screen->tesla;
381 struct nv50_zsa_stateobj *zsa = CALLOC_STRUCT(nv50_zsa_stateobj);
382 struct nouveau_stateobj *so = so_new(64, 0);
383
384 so_method(so, tesla, NV50TCL_DEPTH_WRITE_ENABLE, 1);
385 so_data (so, cso->depth.writemask ? 1 : 0);
386 if (cso->depth.enabled) {
387 so_method(so, tesla, NV50TCL_DEPTH_TEST_ENABLE, 1);
388 so_data (so, 1);
389 so_method(so, tesla, NV50TCL_DEPTH_TEST_FUNC, 1);
390 so_data (so, nvgl_comparison_op(cso->depth.func));
391 } else {
392 so_method(so, tesla, NV50TCL_DEPTH_TEST_ENABLE, 1);
393 so_data (so, 0);
394 }
395
396 /*XXX: yes, I know they're backwards.. header needs fixing */
397 if (cso->stencil[0].enabled) {
398 so_method(so, tesla, NV50TCL_STENCIL_BACK_ENABLE, 5);
399 so_data (so, 1);
400 so_data (so, nvgl_stencil_op(cso->stencil[0].fail_op));
401 so_data (so, nvgl_stencil_op(cso->stencil[0].zfail_op));
402 so_data (so, nvgl_stencil_op(cso->stencil[0].zpass_op));
403 so_data (so, nvgl_comparison_op(cso->stencil[0].func));
404 so_method(so, tesla, NV50TCL_STENCIL_BACK_FUNC_REF, 3);
405 so_data (so, cso->stencil[0].ref_value);
406 so_data (so, cso->stencil[0].writemask);
407 so_data (so, cso->stencil[0].valuemask);
408 } else {
409 so_method(so, tesla, NV50TCL_STENCIL_BACK_ENABLE, 1);
410 so_data (so, 0);
411 }
412
413 if (cso->stencil[1].enabled) {
414 so_method(so, tesla, NV50TCL_STENCIL_FRONT_ENABLE, 8);
415 so_data (so, 1);
416 so_data (so, nvgl_stencil_op(cso->stencil[1].fail_op));
417 so_data (so, nvgl_stencil_op(cso->stencil[1].zfail_op));
418 so_data (so, nvgl_stencil_op(cso->stencil[1].zpass_op));
419 so_data (so, nvgl_comparison_op(cso->stencil[1].func));
420 so_data (so, cso->stencil[1].ref_value);
421 so_data (so, cso->stencil[1].writemask);
422 so_data (so, cso->stencil[1].valuemask);
423 } else {
424 so_method(so, tesla, NV50TCL_STENCIL_FRONT_ENABLE, 1);
425 so_data (so, 0);
426 }
427
428 if (cso->alpha.enabled) {
429 so_method(so, tesla, NV50TCL_ALPHA_TEST_ENABLE, 1);
430 so_data (so, 1);
431 so_method(so, tesla, NV50TCL_ALPHA_TEST_REF, 2);
432 so_data (so, fui(cso->alpha.ref_value));
433 so_data (so, nvgl_comparison_op(cso->alpha.func));
434 } else {
435 so_method(so, tesla, NV50TCL_ALPHA_TEST_ENABLE, 1);
436 so_data (so, 0);
437 }
438
439 zsa->pipe = *cso;
440 so_ref(so, &zsa->so);
441 return (void *)zsa;
442 }
443
444 static void
445 nv50_depth_stencil_alpha_state_bind(struct pipe_context *pipe, void *hwcso)
446 {
447 struct nv50_context *nv50 = nv50_context(pipe);
448
449 nv50->zsa = hwcso;
450 nv50->dirty |= NV50_NEW_ZSA;
451 }
452
453 static void
454 nv50_depth_stencil_alpha_state_delete(struct pipe_context *pipe, void *hwcso)
455 {
456 struct nv50_zsa_stateobj *zsa = hwcso;
457
458 so_ref(NULL, &zsa->so);
459 FREE(zsa);
460 }
461
462 static void *
463 nv50_vp_state_create(struct pipe_context *pipe,
464 const struct pipe_shader_state *cso)
465 {
466 struct nv50_program *p = CALLOC_STRUCT(nv50_program);
467
468 p->pipe.tokens = tgsi_dup_tokens(cso->tokens);
469 p->type = PIPE_SHADER_VERTEX;
470 tgsi_scan_shader(p->pipe.tokens, &p->info);
471 return (void *)p;
472 }
473
474 static void
475 nv50_vp_state_bind(struct pipe_context *pipe, void *hwcso)
476 {
477 struct nv50_context *nv50 = nv50_context(pipe);
478
479 nv50->vertprog = hwcso;
480 nv50->dirty |= NV50_NEW_VERTPROG;
481 }
482
483 static void
484 nv50_vp_state_delete(struct pipe_context *pipe, void *hwcso)
485 {
486 struct nv50_context *nv50 = nv50_context(pipe);
487 struct nv50_program *p = hwcso;
488
489 nv50_program_destroy(nv50, p);
490 FREE((void*)p->pipe.tokens);
491 FREE(p);
492 }
493
494 static void *
495 nv50_fp_state_create(struct pipe_context *pipe,
496 const struct pipe_shader_state *cso)
497 {
498 struct nv50_program *p = CALLOC_STRUCT(nv50_program);
499
500 p->pipe.tokens = tgsi_dup_tokens(cso->tokens);
501 p->type = PIPE_SHADER_FRAGMENT;
502 tgsi_scan_shader(p->pipe.tokens, &p->info);
503 return (void *)p;
504 }
505
506 static void
507 nv50_fp_state_bind(struct pipe_context *pipe, void *hwcso)
508 {
509 struct nv50_context *nv50 = nv50_context(pipe);
510
511 nv50->fragprog = hwcso;
512 nv50->dirty |= NV50_NEW_FRAGPROG;
513 }
514
515 static void
516 nv50_fp_state_delete(struct pipe_context *pipe, void *hwcso)
517 {
518 struct nv50_context *nv50 = nv50_context(pipe);
519 struct nv50_program *p = hwcso;
520
521 nv50_program_destroy(nv50, p);
522 FREE((void*)p->pipe.tokens);
523 FREE(p);
524 }
525
526 static void
527 nv50_set_blend_color(struct pipe_context *pipe,
528 const struct pipe_blend_color *bcol)
529 {
530 struct nv50_context *nv50 = nv50_context(pipe);
531
532 nv50->blend_colour = *bcol;
533 nv50->dirty |= NV50_NEW_BLEND_COLOUR;
534 }
535
536 static void
537 nv50_set_clip_state(struct pipe_context *pipe,
538 const struct pipe_clip_state *clip)
539 {
540 }
541
542 static void
543 nv50_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
544 const struct pipe_constant_buffer *buf )
545 {
546 struct nv50_context *nv50 = nv50_context(pipe);
547
548 if (shader == PIPE_SHADER_VERTEX) {
549 nv50->constbuf[PIPE_SHADER_VERTEX] = buf->buffer;
550 nv50->dirty |= NV50_NEW_VERTPROG_CB;
551 } else
552 if (shader == PIPE_SHADER_FRAGMENT) {
553 nv50->constbuf[PIPE_SHADER_FRAGMENT] = buf->buffer;
554 nv50->dirty |= NV50_NEW_FRAGPROG_CB;
555 }
556 }
557
558 static void
559 nv50_set_framebuffer_state(struct pipe_context *pipe,
560 const struct pipe_framebuffer_state *fb)
561 {
562 struct nv50_context *nv50 = nv50_context(pipe);
563
564 nv50->framebuffer = *fb;
565 nv50->dirty |= NV50_NEW_FRAMEBUFFER;
566 }
567
568 static void
569 nv50_set_polygon_stipple(struct pipe_context *pipe,
570 const struct pipe_poly_stipple *stipple)
571 {
572 struct nv50_context *nv50 = nv50_context(pipe);
573
574 nv50->stipple = *stipple;
575 nv50->dirty |= NV50_NEW_STIPPLE;
576 }
577
578 static void
579 nv50_set_scissor_state(struct pipe_context *pipe,
580 const struct pipe_scissor_state *s)
581 {
582 struct nv50_context *nv50 = nv50_context(pipe);
583
584 nv50->scissor = *s;
585 nv50->dirty |= NV50_NEW_SCISSOR;
586 }
587
588 static void
589 nv50_set_viewport_state(struct pipe_context *pipe,
590 const struct pipe_viewport_state *vpt)
591 {
592 struct nv50_context *nv50 = nv50_context(pipe);
593
594 nv50->viewport = *vpt;
595 nv50->dirty |= NV50_NEW_VIEWPORT;
596 }
597
598 static void
599 nv50_set_vertex_buffers(struct pipe_context *pipe, unsigned count,
600 const struct pipe_vertex_buffer *vb)
601 {
602 struct nv50_context *nv50 = nv50_context(pipe);
603
604 memcpy(nv50->vtxbuf, vb, sizeof(*vb) * count);
605 nv50->vtxbuf_nr = count;
606
607 nv50->dirty |= NV50_NEW_ARRAYS;
608 }
609
610 static void
611 nv50_set_vertex_elements(struct pipe_context *pipe, unsigned count,
612 const struct pipe_vertex_element *ve)
613 {
614 struct nv50_context *nv50 = nv50_context(pipe);
615
616 memcpy(nv50->vtxelt, ve, sizeof(*ve) * count);
617 nv50->vtxelt_nr = count;
618
619 nv50->dirty |= NV50_NEW_ARRAYS;
620 }
621
622 void
623 nv50_init_state_functions(struct nv50_context *nv50)
624 {
625 nv50->pipe.create_blend_state = nv50_blend_state_create;
626 nv50->pipe.bind_blend_state = nv50_blend_state_bind;
627 nv50->pipe.delete_blend_state = nv50_blend_state_delete;
628
629 nv50->pipe.create_sampler_state = nv50_sampler_state_create;
630 nv50->pipe.bind_sampler_states = nv50_sampler_state_bind;
631 nv50->pipe.delete_sampler_state = nv50_sampler_state_delete;
632 nv50->pipe.set_sampler_textures = nv50_set_sampler_texture;
633
634 nv50->pipe.create_rasterizer_state = nv50_rasterizer_state_create;
635 nv50->pipe.bind_rasterizer_state = nv50_rasterizer_state_bind;
636 nv50->pipe.delete_rasterizer_state = nv50_rasterizer_state_delete;
637
638 nv50->pipe.create_depth_stencil_alpha_state =
639 nv50_depth_stencil_alpha_state_create;
640 nv50->pipe.bind_depth_stencil_alpha_state =
641 nv50_depth_stencil_alpha_state_bind;
642 nv50->pipe.delete_depth_stencil_alpha_state =
643 nv50_depth_stencil_alpha_state_delete;
644
645 nv50->pipe.create_vs_state = nv50_vp_state_create;
646 nv50->pipe.bind_vs_state = nv50_vp_state_bind;
647 nv50->pipe.delete_vs_state = nv50_vp_state_delete;
648
649 nv50->pipe.create_fs_state = nv50_fp_state_create;
650 nv50->pipe.bind_fs_state = nv50_fp_state_bind;
651 nv50->pipe.delete_fs_state = nv50_fp_state_delete;
652
653 nv50->pipe.set_blend_color = nv50_set_blend_color;
654 nv50->pipe.set_clip_state = nv50_set_clip_state;
655 nv50->pipe.set_constant_buffer = nv50_set_constant_buffer;
656 nv50->pipe.set_framebuffer_state = nv50_set_framebuffer_state;
657 nv50->pipe.set_polygon_stipple = nv50_set_polygon_stipple;
658 nv50->pipe.set_scissor_state = nv50_set_scissor_state;
659 nv50->pipe.set_viewport_state = nv50_set_viewport_state;
660
661 nv50->pipe.set_vertex_buffers = nv50_set_vertex_buffers;
662 nv50->pipe.set_vertex_elements = nv50_set_vertex_elements;
663 }
664