r600g: add support for constants in memory buffers.
[mesa.git] / src / gallium / drivers / r600 / r600_state.c
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Jerome Glisse
25 */
26 #include <stdio.h>
27 #include <errno.h>
28 #include "util/u_inlines.h"
29 #include "util/u_format.h"
30 #include "util/u_memory.h"
31 #include "util/u_pack_color.h"
32 #include "r600_screen.h"
33 #include "r600_context.h"
34 #include "r600_resource.h"
35 #include "r600d.h"
36 #include "r600_state_inlines.h"
37
38 static struct r600_context_state *r600_new_context_state(unsigned type)
39 {
40 struct r600_context_state *rstate = CALLOC_STRUCT(r600_context_state);
41 if (rstate == NULL)
42 return NULL;
43 rstate->type = type;
44 rstate->refcount = 1;
45 return rstate;
46 }
47
48 static void *r600_create_blend_state(struct pipe_context *ctx,
49 const struct pipe_blend_state *state)
50 {
51 struct r600_context *rctx = r600_context(ctx);
52 struct r600_context_state *rstate;
53
54 rstate = r600_new_context_state(pipe_blend_type);
55 rstate->state.blend = *state;
56 rctx->vtbl->blend(rctx, &rstate->rstate[0], &rstate->state.blend);
57
58 return rstate;
59 }
60
61 static void *r600_create_dsa_state(struct pipe_context *ctx,
62 const struct pipe_depth_stencil_alpha_state *state)
63 {
64 struct r600_context_state *rstate;
65
66 rstate = r600_new_context_state(pipe_dsa_type);
67 rstate->state.dsa = *state;
68 return rstate;
69 }
70
71 static void *r600_create_rs_state(struct pipe_context *ctx,
72 const struct pipe_rasterizer_state *state)
73 {
74 struct r600_context_state *rstate;
75
76 rstate = r600_new_context_state(pipe_rasterizer_type);
77 rstate->state.rasterizer = *state;
78 return rstate;
79 }
80
81 static void *r600_create_sampler_state(struct pipe_context *ctx,
82 const struct pipe_sampler_state *state)
83 {
84 struct r600_context *rctx = r600_context(ctx);
85 struct r600_context_state *rstate;
86
87 rstate = r600_new_context_state(pipe_sampler_type);
88 rstate->state.sampler = *state;
89 rctx->vtbl->sampler(rctx, &rstate->rstate[0], &rstate->state.sampler, 0);
90 rctx->vtbl->sampler_border(rctx, &rstate->rstate[1], &rstate->state.sampler, 0);
91 return rstate;
92 }
93
94 static void r600_remove_sampler_view(struct r600_shader_sampler_states *sampler,
95 struct r600_context_state *rstate)
96 {
97 int i, j;
98
99 for (i = 0; i < sampler->nview; i++) {
100 for (j = 0; j < rstate->nrstate; j++) {
101 if (sampler->view[i] == &rstate->rstate[j])
102 sampler->view[i] = NULL;
103 }
104 }
105 }
106 static void r600_sampler_view_destroy(struct pipe_context *ctx,
107 struct pipe_sampler_view *state)
108 {
109 struct r600_context_state *rstate = (struct r600_context_state *)state;
110 struct r600_context *rctx = r600_context(ctx);
111 int i;
112
113 /* need to search list of vs/ps sampler views and remove it from any - uggh */
114 r600_remove_sampler_view(&rctx->ps_sampler, rstate);
115 r600_remove_sampler_view(&rctx->vs_sampler, rstate);
116 r600_context_state_decref(rstate);
117 }
118
119 static struct pipe_sampler_view *r600_create_sampler_view(struct pipe_context *ctx,
120 struct pipe_resource *texture,
121 const struct pipe_sampler_view *state)
122 {
123 struct r600_context_state *rstate;
124 struct r600_context *rctx = r600_context(ctx);
125
126 rstate = r600_new_context_state(pipe_sampler_view_type);
127 rstate->state.sampler_view = *state;
128 rstate->state.sampler_view.texture = NULL;
129 pipe_reference(NULL, &texture->reference);
130 rstate->state.sampler_view.texture = texture;
131 rstate->state.sampler_view.reference.count = 1;
132 rstate->state.sampler_view.context = ctx;
133 rctx->vtbl->resource(ctx, &rstate->rstate[0], &rstate->state.sampler_view, 0);
134 return &rstate->state.sampler_view;
135 }
136
137 static void r600_set_sampler_view(struct pipe_context *ctx,
138 unsigned count,
139 struct pipe_sampler_view **views,
140 struct r600_shader_sampler_states *sampler,
141 unsigned shader_id)
142 {
143 struct r600_context *rctx = r600_context(ctx);
144 struct r600_context_state *rstate;
145 unsigned i;
146
147 for (i = 0; i < sampler->nview; i++) {
148 radeon_draw_unbind(&rctx->draw, sampler->view[i]);
149 }
150
151 for (i = 0; i < count; i++) {
152 rstate = (struct r600_context_state *)views[i];
153 if (rstate) {
154 rstate->nrstate = 0;
155 }
156 }
157 for (i = 0; i < count; i++) {
158 rstate = (struct r600_context_state *)views[i];
159 if (rstate) {
160 if (rstate->nrstate >= R600_MAX_RSTATE)
161 continue;
162 if (rstate->nrstate) {
163 memcpy(&rstate->rstate[rstate->nrstate], &rstate->rstate[0], sizeof(struct radeon_state));
164 }
165 radeon_state_convert(&rstate->rstate[rstate->nrstate], R600_STATE_RESOURCE, i, shader_id);
166 sampler->view[i] = &rstate->rstate[rstate->nrstate];
167 rstate->nrstate++;
168 }
169 }
170 sampler->nview = count;
171 }
172
173 static void r600_set_ps_sampler_view(struct pipe_context *ctx,
174 unsigned count,
175 struct pipe_sampler_view **views)
176 {
177 struct r600_context *rctx = r600_context(ctx);
178 r600_set_sampler_view(ctx, count, views, &rctx->ps_sampler, R600_SHADER_PS);
179 }
180
181 static void r600_set_vs_sampler_view(struct pipe_context *ctx,
182 unsigned count,
183 struct pipe_sampler_view **views)
184 {
185 struct r600_context *rctx = r600_context(ctx);
186 r600_set_sampler_view(ctx, count, views, &rctx->vs_sampler, R600_SHADER_VS);
187 }
188
189 static void *r600_create_shader_state(struct pipe_context *ctx,
190 const struct pipe_shader_state *state)
191 {
192 struct r600_context *rctx = r600_context(ctx);
193 struct r600_context_state *rstate;
194 int r;
195
196 rstate = r600_new_context_state(pipe_shader_type);
197 rstate->state.shader = *state;
198 r = r600_pipe_shader_create(&rctx->context, rstate, rstate->state.shader.tokens);
199 if (r) {
200 r600_context_state_decref(rstate);
201 return NULL;
202 }
203 return rstate;
204 }
205
206 static void *r600_create_vertex_elements(struct pipe_context *ctx,
207 unsigned count,
208 const struct pipe_vertex_element *elements)
209 {
210 struct r600_vertex_element *v = CALLOC_STRUCT(r600_vertex_element);
211
212 assert(count < 32);
213 v->count = count;
214 memcpy(v->elements, elements, count * sizeof(struct pipe_vertex_element));
215 v->refcount = 1;
216 return v;
217 }
218
219 static void r600_delete_vertex_element(struct pipe_context *ctx, void *state)
220 {
221 struct r600_vertex_element *v = (struct r600_vertex_element*)state;
222
223 if (v == NULL)
224 return;
225 if (--v->refcount)
226 return;
227 free(v);
228 }
229
230 static void r600_bind_vertex_elements(struct pipe_context *ctx, void *state)
231 {
232 struct r600_context *rctx = r600_context(ctx);
233 struct r600_vertex_element *v = (struct r600_vertex_element*)state;
234
235 r600_delete_vertex_element(ctx, rctx->vertex_elements);
236 rctx->vertex_elements = v;
237 if (v) {
238 v->refcount++;
239 }
240 }
241
242 static void r600_bind_rasterizer_state(struct pipe_context *ctx, void *state)
243 {
244 struct r600_context *rctx = r600_context(ctx);
245 struct r600_context_state *rstate = (struct r600_context_state *)state;
246
247 if (state == NULL)
248 return;
249 rctx->rasterizer = r600_context_state_decref(rctx->rasterizer);
250 rctx->rasterizer = r600_context_state_incref(rstate);
251 }
252
253 static void r600_bind_blend_state(struct pipe_context *ctx, void *state)
254 {
255 struct r600_context *rctx = r600_context(ctx);
256 struct r600_context_state *rstate = (struct r600_context_state *)state;
257
258 if (state == NULL)
259 return;
260 rctx->blend = r600_context_state_decref(rctx->blend);
261 rctx->blend = r600_context_state_incref(rstate);
262
263 }
264
265 static void r600_bind_dsa_state(struct pipe_context *ctx, void *state)
266 {
267 struct r600_context *rctx = r600_context(ctx);
268 struct r600_context_state *rstate = (struct r600_context_state *)state;
269
270 if (state == NULL)
271 return;
272 rctx->dsa = r600_context_state_decref(rctx->dsa);
273 rctx->dsa = r600_context_state_incref(rstate);
274 }
275
276 static void r600_bind_ps_shader(struct pipe_context *ctx, void *state)
277 {
278 struct r600_context *rctx = r600_context(ctx);
279 struct r600_context_state *rstate = (struct r600_context_state *)state;
280
281 rctx->ps_shader = r600_context_state_decref(rctx->ps_shader);
282 rctx->ps_shader = r600_context_state_incref(rstate);
283 }
284
285 static void r600_bind_vs_shader(struct pipe_context *ctx, void *state)
286 {
287 struct r600_context *rctx = r600_context(ctx);
288 struct r600_context_state *rstate = (struct r600_context_state *)state;
289
290 rctx->vs_shader = r600_context_state_decref(rctx->vs_shader);
291 rctx->vs_shader = r600_context_state_incref(rstate);
292 }
293
294 static void r600_bind_sampler_shader(struct pipe_context *ctx,
295 unsigned count, void **states,
296 struct r600_shader_sampler_states *sampler, unsigned shader_id)
297 {
298 struct r600_context *rctx = r600_context(ctx);
299 struct r600_context_state *rstate;
300 unsigned i;
301
302 for (i = 0; i < sampler->nsampler; i++) {
303 radeon_draw_unbind(&rctx->draw, sampler->sampler[i]);
304 }
305 for (i = 0; i < sampler->nborder; i++) {
306 radeon_draw_unbind(&rctx->draw, sampler->border[i]);
307 }
308 for (i = 0; i < count; i++) {
309 rstate = (struct r600_context_state *)states[i];
310 if (rstate) {
311 rstate->nrstate = 0;
312 }
313 }
314 for (i = 0; i < count; i++) {
315 rstate = (struct r600_context_state *)states[i];
316 if (rstate) {
317 if (rstate->nrstate >= R600_MAX_RSTATE)
318 continue;
319 if (rstate->nrstate) {
320 memcpy(&rstate->rstate[rstate->nrstate], &rstate->rstate[0], sizeof(struct radeon_state));
321 memcpy(&rstate->rstate[rstate->nrstate+1], &rstate->rstate[1], sizeof(struct radeon_state));
322 }
323 radeon_state_convert(&rstate->rstate[rstate->nrstate], R600_STATE_SAMPLER, i, shader_id);
324 radeon_state_convert(&rstate->rstate[rstate->nrstate + 1], R600_STATE_SAMPLER_BORDER, i, shader_id);
325 sampler->sampler[i] = &rstate->rstate[rstate->nrstate];
326 sampler->border[i] = &rstate->rstate[rstate->nrstate + 1];
327 rstate->nrstate += 2;
328 }
329 }
330 sampler->nsampler = count;
331 sampler->nborder = count;
332 }
333
334 static void r600_bind_ps_sampler(struct pipe_context *ctx,
335 unsigned count, void **states)
336 {
337 struct r600_context *rctx = r600_context(ctx);
338 r600_bind_sampler_shader(ctx, count, states, &rctx->ps_sampler, R600_SHADER_PS);
339 }
340
341 static void r600_bind_vs_sampler(struct pipe_context *ctx,
342 unsigned count, void **states)
343 {
344 struct r600_context *rctx = r600_context(ctx);
345 r600_bind_sampler_shader(ctx, count, states, &rctx->vs_sampler, R600_SHADER_VS);
346 }
347
348 static void r600_delete_state(struct pipe_context *ctx, void *state)
349 {
350 struct r600_context_state *rstate = (struct r600_context_state *)state;
351
352 r600_context_state_decref(rstate);
353 }
354
355 static void r600_set_blend_color(struct pipe_context *ctx,
356 const struct pipe_blend_color *color)
357 {
358 struct r600_context *rctx = r600_context(ctx);
359
360 rctx->blend_color = *color;
361 }
362
363 static void r600_set_clip_state(struct pipe_context *ctx,
364 const struct pipe_clip_state *state)
365 {
366 struct r600_context *rctx = r600_context(ctx);
367 struct r600_context_state *rstate;
368
369 r600_context_state_decref(rctx->clip);
370
371 rstate = r600_new_context_state(pipe_clip_type);
372 rstate->state.clip = *state;
373 rctx->vtbl->ucp(rctx, &rstate->rstate[0], &rstate->state.clip);
374 rctx->clip = rstate;
375 }
376
377 static void r600_set_framebuffer_state(struct pipe_context *ctx,
378 const struct pipe_framebuffer_state *state)
379 {
380 struct r600_context *rctx = r600_context(ctx);
381 struct r600_context_state *rstate;
382 int i;
383
384 r600_context_state_decref(rctx->framebuffer);
385
386 rstate = r600_new_context_state(pipe_framebuffer_type);
387 rstate->state.framebuffer = *state;
388 for (i = 0; i < rstate->state.framebuffer.nr_cbufs; i++) {
389 pipe_reference(NULL, &state->cbufs[i]->reference);
390 }
391 pipe_reference(NULL, &state->zsbuf->reference);
392 rctx->framebuffer = rstate;
393 for (i = 0; i < state->nr_cbufs; i++) {
394 rctx->vtbl->cb(rctx, &rstate->rstate[i+1], state, i);
395 }
396 if (state->zsbuf) {
397 rctx->vtbl->db(rctx, &rstate->rstate[0], state);
398 }
399 return;
400 }
401
402 static void r600_set_polygon_stipple(struct pipe_context *ctx,
403 const struct pipe_poly_stipple *state)
404 {
405 }
406
407 static void r600_set_sample_mask(struct pipe_context *pipe, unsigned sample_mask)
408 {
409 }
410
411 static void r600_set_scissor_state(struct pipe_context *ctx,
412 const struct pipe_scissor_state *state)
413 {
414 struct r600_context *rctx = r600_context(ctx);
415 struct r600_context_state *rstate;
416
417 r600_context_state_decref(rctx->scissor);
418
419 rstate = r600_new_context_state(pipe_scissor_type);
420 rstate->state.scissor = *state;
421 rctx->scissor = rstate;
422 }
423
424 static void r600_set_stencil_ref(struct pipe_context *ctx,
425 const struct pipe_stencil_ref *state)
426 {
427 struct r600_context *rctx = r600_context(ctx);
428 struct r600_context_state *rstate;
429
430 r600_context_state_decref(rctx->stencil_ref);
431
432 rstate = r600_new_context_state(pipe_stencil_ref_type);
433 rstate->state.stencil_ref = *state;
434 rctx->stencil_ref = rstate;
435 }
436
437 static void r600_set_vertex_buffers(struct pipe_context *ctx,
438 unsigned count,
439 const struct pipe_vertex_buffer *buffers)
440 {
441 struct r600_context *rctx = r600_context(ctx);
442 unsigned i;
443
444 for (i = 0; i < rctx->nvertex_buffer; i++) {
445 pipe_resource_reference(&rctx->vertex_buffer[i].buffer, NULL);
446 }
447 memcpy(rctx->vertex_buffer, buffers, sizeof(struct pipe_vertex_buffer) * count);
448 for (i = 0; i < count; i++) {
449 rctx->vertex_buffer[i].buffer = NULL;
450 pipe_resource_reference(&rctx->vertex_buffer[i].buffer, buffers[i].buffer);
451 }
452 rctx->nvertex_buffer = count;
453 }
454
455 static void r600_set_index_buffer(struct pipe_context *ctx,
456 const struct pipe_index_buffer *ib)
457 {
458 struct r600_context *rctx = r600_context(ctx);
459
460 if (ib) {
461 pipe_resource_reference(&rctx->index_buffer.buffer, ib->buffer);
462 memcpy(&rctx->index_buffer, ib, sizeof(rctx->index_buffer));
463 } else {
464 pipe_resource_reference(&rctx->index_buffer.buffer, NULL);
465 memset(&rctx->index_buffer, 0, sizeof(rctx->index_buffer));
466 }
467
468 /* TODO make this more like a state */
469 }
470
471 static void r600_set_viewport_state(struct pipe_context *ctx,
472 const struct pipe_viewport_state *state)
473 {
474 struct r600_context *rctx = r600_context(ctx);
475 struct r600_context_state *rstate;
476
477 r600_context_state_decref(rctx->viewport);
478
479 rstate = r600_new_context_state(pipe_viewport_type);
480 rstate->state.viewport = *state;
481 rctx->vtbl->viewport(rctx, &rstate->rstate[0], &rstate->state.viewport);
482 rctx->viewport = rstate;
483 }
484
485 void r600_init_state_functions(struct r600_context *rctx)
486 {
487 rctx->context.create_blend_state = r600_create_blend_state;
488 rctx->context.create_depth_stencil_alpha_state = r600_create_dsa_state;
489 rctx->context.create_fs_state = r600_create_shader_state;
490 rctx->context.create_rasterizer_state = r600_create_rs_state;
491 rctx->context.create_sampler_state = r600_create_sampler_state;
492 rctx->context.create_sampler_view = r600_create_sampler_view;
493 rctx->context.create_vertex_elements_state = r600_create_vertex_elements;
494 rctx->context.create_vs_state = r600_create_shader_state;
495 rctx->context.bind_blend_state = r600_bind_blend_state;
496 rctx->context.bind_depth_stencil_alpha_state = r600_bind_dsa_state;
497 rctx->context.bind_fragment_sampler_states = r600_bind_ps_sampler;
498 rctx->context.bind_fs_state = r600_bind_ps_shader;
499 rctx->context.bind_rasterizer_state = r600_bind_rasterizer_state;
500 rctx->context.bind_vertex_elements_state = r600_bind_vertex_elements;
501 rctx->context.bind_vertex_sampler_states = r600_bind_vs_sampler;
502 rctx->context.bind_vs_state = r600_bind_vs_shader;
503 rctx->context.delete_blend_state = r600_delete_state;
504 rctx->context.delete_depth_stencil_alpha_state = r600_delete_state;
505 rctx->context.delete_fs_state = r600_delete_state;
506 rctx->context.delete_rasterizer_state = r600_delete_state;
507 rctx->context.delete_sampler_state = r600_delete_state;
508 rctx->context.delete_vertex_elements_state = r600_delete_vertex_element;
509 rctx->context.delete_vs_state = r600_delete_state;
510 rctx->context.set_blend_color = r600_set_blend_color;
511 rctx->context.set_clip_state = r600_set_clip_state;
512 if (rctx->screen->use_mem_constant)
513 rctx->context.set_constant_buffer = r600_set_constant_buffer_mem;
514 else
515 rctx->context.set_constant_buffer = r600_set_constant_buffer_file;
516 rctx->context.set_fragment_sampler_views = r600_set_ps_sampler_view;
517 rctx->context.set_framebuffer_state = r600_set_framebuffer_state;
518 rctx->context.set_polygon_stipple = r600_set_polygon_stipple;
519 rctx->context.set_sample_mask = r600_set_sample_mask;
520 rctx->context.set_scissor_state = r600_set_scissor_state;
521 rctx->context.set_stencil_ref = r600_set_stencil_ref;
522 rctx->context.set_vertex_buffers = r600_set_vertex_buffers;
523 rctx->context.set_index_buffer = r600_set_index_buffer;
524 rctx->context.set_vertex_sampler_views = r600_set_vs_sampler_view;
525 rctx->context.set_viewport_state = r600_set_viewport_state;
526 rctx->context.sampler_view_destroy = r600_sampler_view_destroy;
527 }
528
529 struct r600_context_state *r600_context_state_incref(struct r600_context_state *rstate)
530 {
531 if (rstate == NULL)
532 return NULL;
533 rstate->refcount++;
534 return rstate;
535 }
536
537 struct r600_context_state *r600_context_state_decref(struct r600_context_state *rstate)
538 {
539 unsigned i;
540
541 if (rstate == NULL)
542 return NULL;
543 if (--rstate->refcount)
544 return NULL;
545 switch (rstate->type) {
546 case pipe_sampler_view_type:
547 pipe_resource_reference(&rstate->state.sampler_view.texture, NULL);
548 break;
549 case pipe_framebuffer_type:
550 for (i = 0; i < rstate->state.framebuffer.nr_cbufs; i++) {
551 pipe_surface_reference(&rstate->state.framebuffer.cbufs[i], NULL);
552 }
553 pipe_surface_reference(&rstate->state.framebuffer.zsbuf, NULL);
554 break;
555 case pipe_viewport_type:
556 case pipe_depth_type:
557 case pipe_rasterizer_type:
558 case pipe_poly_stipple_type:
559 case pipe_scissor_type:
560 case pipe_clip_type:
561 case pipe_stencil_type:
562 case pipe_alpha_type:
563 case pipe_dsa_type:
564 case pipe_blend_type:
565 case pipe_stencil_ref_type:
566 case pipe_shader_type:
567 case pipe_sampler_type:
568 break;
569 default:
570 R600_ERR("invalid type %d\n", rstate->type);
571 return NULL;
572 }
573 radeon_state_fini(&rstate->rstate[0]);
574 FREE(rstate);
575 return NULL;
576 }
577
578 static void r600_bind_shader_sampler(struct r600_context *rctx, struct r600_shader_sampler_states *sampler)
579 {
580 int i;
581
582 for (i = 0; i < sampler->nsampler; i++) {
583 if (sampler->sampler[i])
584 radeon_draw_bind(&rctx->draw, sampler->sampler[i]);
585 }
586
587 for (i = 0; i < sampler->nborder; i++) {
588 if (sampler->border[i])
589 radeon_draw_bind(&rctx->draw, sampler->border[i]);
590 }
591
592 for (i = 0; i < sampler->nview; i++) {
593 if (sampler->view[i])
594 radeon_draw_bind(&rctx->draw, sampler->view[i]);
595 }
596 }
597
598 int r600_context_hw_states(struct pipe_context *ctx)
599 {
600 struct r600_context *rctx = r600_context(ctx);
601 unsigned i;
602
603 /* build new states */
604 rctx->vtbl->rasterizer(rctx, &rctx->hw_states.rasterizer);
605 rctx->vtbl->scissor(rctx, &rctx->hw_states.scissor);
606 rctx->vtbl->dsa(rctx, &rctx->hw_states.dsa);
607 rctx->vtbl->cb_cntl(rctx, &rctx->hw_states.cb_cntl);
608
609 /* bind states */
610 radeon_draw_bind(&rctx->draw, &rctx->hw_states.rasterizer);
611 radeon_draw_bind(&rctx->draw, &rctx->hw_states.scissor);
612 radeon_draw_bind(&rctx->draw, &rctx->hw_states.dsa);
613 radeon_draw_bind(&rctx->draw, &rctx->hw_states.cb_cntl);
614
615 radeon_draw_bind(&rctx->draw, &rctx->config);
616
617 if (rctx->viewport) {
618 radeon_draw_bind(&rctx->draw, &rctx->viewport->rstate[0]);
619 }
620 if (rctx->blend) {
621 radeon_draw_bind(&rctx->draw, &rctx->blend->rstate[0]);
622 }
623 if (rctx->clip) {
624 radeon_draw_bind(&rctx->draw, &rctx->clip->rstate[0]);
625 }
626 for (i = 0; i < rctx->framebuffer->state.framebuffer.nr_cbufs; i++) {
627 radeon_draw_bind(&rctx->draw, &rctx->framebuffer->rstate[i+1]);
628 }
629 if (rctx->framebuffer->state.framebuffer.zsbuf) {
630 radeon_draw_bind(&rctx->draw, &rctx->framebuffer->rstate[0]);
631 }
632
633 r600_bind_shader_sampler(rctx, &rctx->vs_sampler);
634 r600_bind_shader_sampler(rctx, &rctx->ps_sampler);
635
636 return 0;
637 }