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