2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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:
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
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.
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"
36 static void clean_flush(struct r600_context
*rctx
, struct radeon_state
*flush
);
37 static int setup_cb_flush(struct r600_context
*rctx
, struct radeon_state
*flush
);
38 static int setup_db_flush(struct r600_context
*rctx
, struct radeon_state
*flush
);
40 static struct r600_context_state
*r600_new_context_state(unsigned type
)
42 struct r600_context_state
*rstate
= CALLOC_STRUCT(r600_context_state
);
50 static void *r600_create_blend_state(struct pipe_context
*ctx
,
51 const struct pipe_blend_state
*state
)
53 struct r600_context
*rctx
= r600_context(ctx
);
54 struct r600_context_state
*rstate
;
56 rstate
= r600_new_context_state(pipe_blend_type
);
57 rstate
->state
.blend
= *state
;
58 rctx
->vtbl
->blend(rctx
, &rstate
->rstate
[0], &rstate
->state
.blend
);
63 static void *r600_create_dsa_state(struct pipe_context
*ctx
,
64 const struct pipe_depth_stencil_alpha_state
*state
)
66 struct r600_context_state
*rstate
;
68 rstate
= r600_new_context_state(pipe_dsa_type
);
69 rstate
->state
.dsa
= *state
;
73 static void *r600_create_rs_state(struct pipe_context
*ctx
,
74 const struct pipe_rasterizer_state
*state
)
76 struct r600_context_state
*rstate
;
78 rstate
= r600_new_context_state(pipe_rasterizer_type
);
79 rstate
->state
.rasterizer
= *state
;
83 static void *r600_create_sampler_state(struct pipe_context
*ctx
,
84 const struct pipe_sampler_state
*state
)
86 struct r600_context
*rctx
= r600_context(ctx
);
87 struct r600_context_state
*rstate
;
89 rstate
= r600_new_context_state(pipe_sampler_type
);
90 rstate
->state
.sampler
= *state
;
91 rctx
->vtbl
->sampler(rctx
, &rstate
->rstate
[0], &rstate
->state
.sampler
, 0);
92 rctx
->vtbl
->sampler_border(rctx
, &rstate
->rstate
[1], &rstate
->state
.sampler
, 0);
96 static void r600_remove_sampler_view(struct r600_shader_sampler_states
*sampler
,
97 struct r600_context_state
*rstate
)
101 for (i
= 0; i
< sampler
->nview
; i
++) {
102 for (j
= 0; j
< rstate
->nrstate
; j
++) {
103 if (sampler
->view
[i
] == &rstate
->rstate
[j
])
104 sampler
->view
[i
] = NULL
;
108 static void r600_sampler_view_destroy(struct pipe_context
*ctx
,
109 struct pipe_sampler_view
*state
)
111 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
112 struct r600_context
*rctx
= r600_context(ctx
);
114 /* need to search list of vs/ps sampler views and remove it from any - uggh */
115 r600_remove_sampler_view(&rctx
->ps_sampler
, rstate
);
116 r600_remove_sampler_view(&rctx
->vs_sampler
, rstate
);
117 r600_context_state_decref(rstate
);
120 static struct pipe_sampler_view
*r600_create_sampler_view(struct pipe_context
*ctx
,
121 struct pipe_resource
*texture
,
122 const struct pipe_sampler_view
*state
)
124 struct r600_context_state
*rstate
;
125 struct r600_context
*rctx
= r600_context(ctx
);
127 rstate
= r600_new_context_state(pipe_sampler_view_type
);
128 rstate
->state
.sampler_view
= *state
;
129 rstate
->state
.sampler_view
.texture
= NULL
;
130 pipe_reference(NULL
, &texture
->reference
);
131 rstate
->state
.sampler_view
.texture
= texture
;
132 rstate
->state
.sampler_view
.reference
.count
= 1;
133 rstate
->state
.sampler_view
.context
= ctx
;
134 rctx
->vtbl
->resource(ctx
, &rstate
->rstate
[0], &rstate
->state
.sampler_view
, 0);
135 return &rstate
->state
.sampler_view
;
138 static void r600_set_sampler_view(struct pipe_context
*ctx
,
140 struct pipe_sampler_view
**views
,
141 struct r600_shader_sampler_states
*sampler
,
144 struct r600_context
*rctx
= r600_context(ctx
);
145 struct r600_context_state
*rstate
;
148 for (i
= 0; i
< sampler
->nview
; i
++) {
149 radeon_draw_unbind(&rctx
->draw
, sampler
->view
[i
]);
152 for (i
= 0; i
< count
; i
++) {
153 rstate
= (struct r600_context_state
*)views
[i
];
158 for (i
= 0; i
< count
; i
++) {
159 rstate
= (struct r600_context_state
*)views
[i
];
161 if (rstate
->nrstate
>= R600_MAX_RSTATE
)
163 if (rstate
->nrstate
) {
164 memcpy(&rstate
->rstate
[rstate
->nrstate
], &rstate
->rstate
[0], sizeof(struct radeon_state
));
166 radeon_state_convert(&rstate
->rstate
[rstate
->nrstate
], R600_STATE_RESOURCE
, i
, shader_id
);
167 sampler
->view
[i
] = &rstate
->rstate
[rstate
->nrstate
];
171 sampler
->nview
= count
;
174 static void r600_set_ps_sampler_view(struct pipe_context
*ctx
,
176 struct pipe_sampler_view
**views
)
178 struct r600_context
*rctx
= r600_context(ctx
);
179 r600_set_sampler_view(ctx
, count
, views
, &rctx
->ps_sampler
, R600_SHADER_PS
);
182 static void r600_set_vs_sampler_view(struct pipe_context
*ctx
,
184 struct pipe_sampler_view
**views
)
186 struct r600_context
*rctx
= r600_context(ctx
);
187 r600_set_sampler_view(ctx
, count
, views
, &rctx
->vs_sampler
, R600_SHADER_VS
);
190 static void *r600_create_shader_state(struct pipe_context
*ctx
,
191 const struct pipe_shader_state
*state
)
193 struct r600_context
*rctx
= r600_context(ctx
);
194 struct r600_context_state
*rstate
;
197 rstate
= r600_new_context_state(pipe_shader_type
);
198 rstate
->state
.shader
= *state
;
199 r
= r600_pipe_shader_create(&rctx
->context
, rstate
, rstate
->state
.shader
.tokens
);
201 r600_context_state_decref(rstate
);
207 static void *r600_create_vertex_elements(struct pipe_context
*ctx
,
209 const struct pipe_vertex_element
*elements
)
211 struct r600_vertex_element
*v
= CALLOC_STRUCT(r600_vertex_element
);
215 memcpy(v
->elements
, elements
, count
* sizeof(struct pipe_vertex_element
));
220 static void r600_delete_vertex_element(struct pipe_context
*ctx
, void *state
)
222 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
231 static void r600_bind_vertex_elements(struct pipe_context
*ctx
, void *state
)
233 struct r600_context
*rctx
= r600_context(ctx
);
234 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
236 r600_delete_vertex_element(ctx
, rctx
->vertex_elements
);
237 rctx
->vertex_elements
= v
;
243 static void r600_bind_rasterizer_state(struct pipe_context
*ctx
, void *state
)
245 struct r600_context
*rctx
= r600_context(ctx
);
246 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
250 rctx
->rasterizer
= r600_context_state_decref(rctx
->rasterizer
);
251 rctx
->rasterizer
= r600_context_state_incref(rstate
);
254 static void r600_bind_blend_state(struct pipe_context
*ctx
, void *state
)
256 struct r600_context
*rctx
= r600_context(ctx
);
257 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
261 rctx
->blend
= r600_context_state_decref(rctx
->blend
);
262 rctx
->blend
= r600_context_state_incref(rstate
);
266 static void r600_bind_dsa_state(struct pipe_context
*ctx
, void *state
)
268 struct r600_context
*rctx
= r600_context(ctx
);
269 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
273 rctx
->dsa
= r600_context_state_decref(rctx
->dsa
);
274 rctx
->dsa
= r600_context_state_incref(rstate
);
277 static void r600_bind_ps_shader(struct pipe_context
*ctx
, void *state
)
279 struct r600_context
*rctx
= r600_context(ctx
);
280 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
282 rctx
->ps_shader
= r600_context_state_decref(rctx
->ps_shader
);
283 rctx
->ps_shader
= r600_context_state_incref(rstate
);
286 static void r600_bind_vs_shader(struct pipe_context
*ctx
, void *state
)
288 struct r600_context
*rctx
= r600_context(ctx
);
289 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
291 rctx
->vs_shader
= r600_context_state_decref(rctx
->vs_shader
);
292 rctx
->vs_shader
= r600_context_state_incref(rstate
);
295 static void r600_bind_sampler_shader(struct pipe_context
*ctx
,
296 unsigned count
, void **states
,
297 struct r600_shader_sampler_states
*sampler
, unsigned shader_id
)
299 struct r600_context
*rctx
= r600_context(ctx
);
300 struct r600_context_state
*rstate
;
303 for (i
= 0; i
< sampler
->nsampler
; i
++) {
304 radeon_draw_unbind(&rctx
->draw
, sampler
->sampler
[i
]);
306 for (i
= 0; i
< sampler
->nborder
; i
++) {
307 radeon_draw_unbind(&rctx
->draw
, sampler
->border
[i
]);
309 for (i
= 0; i
< count
; i
++) {
310 rstate
= (struct r600_context_state
*)states
[i
];
315 for (i
= 0; i
< count
; i
++) {
316 rstate
= (struct r600_context_state
*)states
[i
];
318 if (rstate
->nrstate
>= R600_MAX_RSTATE
)
320 if (rstate
->nrstate
) {
321 memcpy(&rstate
->rstate
[rstate
->nrstate
], &rstate
->rstate
[0], sizeof(struct radeon_state
));
322 memcpy(&rstate
->rstate
[rstate
->nrstate
+1], &rstate
->rstate
[1], sizeof(struct radeon_state
));
324 radeon_state_convert(&rstate
->rstate
[rstate
->nrstate
], R600_STATE_SAMPLER
, i
, shader_id
);
325 radeon_state_convert(&rstate
->rstate
[rstate
->nrstate
+ 1], R600_STATE_SAMPLER_BORDER
, i
, shader_id
);
326 sampler
->sampler
[i
] = &rstate
->rstate
[rstate
->nrstate
];
327 sampler
->border
[i
] = &rstate
->rstate
[rstate
->nrstate
+ 1];
328 rstate
->nrstate
+= 2;
331 sampler
->nsampler
= count
;
332 sampler
->nborder
= count
;
335 static void r600_bind_ps_sampler(struct pipe_context
*ctx
,
336 unsigned count
, void **states
)
338 struct r600_context
*rctx
= r600_context(ctx
);
339 r600_bind_sampler_shader(ctx
, count
, states
, &rctx
->ps_sampler
, R600_SHADER_PS
);
342 static void r600_bind_vs_sampler(struct pipe_context
*ctx
,
343 unsigned count
, void **states
)
345 struct r600_context
*rctx
= r600_context(ctx
);
346 r600_bind_sampler_shader(ctx
, count
, states
, &rctx
->vs_sampler
, R600_SHADER_VS
);
349 static void r600_delete_state(struct pipe_context
*ctx
, void *state
)
351 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
353 r600_context_state_decref(rstate
);
356 static void r600_set_blend_color(struct pipe_context
*ctx
,
357 const struct pipe_blend_color
*color
)
359 struct r600_context
*rctx
= r600_context(ctx
);
361 rctx
->blend_color
= *color
;
364 static void r600_set_clip_state(struct pipe_context
*ctx
,
365 const struct pipe_clip_state
*state
)
367 struct r600_context
*rctx
= r600_context(ctx
);
368 struct r600_context_state
*rstate
;
370 r600_context_state_decref(rctx
->clip
);
372 rstate
= r600_new_context_state(pipe_clip_type
);
373 rstate
->state
.clip
= *state
;
374 rctx
->vtbl
->ucp(rctx
, &rstate
->rstate
[0], &rstate
->state
.clip
);
378 static void r600_set_framebuffer_state(struct pipe_context
*ctx
,
379 const struct pipe_framebuffer_state
*state
)
381 struct r600_context
*rctx
= r600_context(ctx
);
382 struct r600_context_state
*rstate
;
385 if (rctx
->framebuffer
) {
386 for (i
= 0; i
< rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
; i
++)
387 radeon_draw_unbind(&rctx
->draw
, &rctx
->framebuffer
->rstate
[i
+1]);
388 radeon_draw_unbind(&rctx
->draw
, &rctx
->framebuffer
->rstate
[0]);
390 clean_flush(rctx
, &rctx
->hw_states
.cb_flush
);
391 clean_flush(rctx
, &rctx
->hw_states
.db_flush
);
393 r600_context_state_decref(rctx
->framebuffer
);
395 rstate
= r600_new_context_state(pipe_framebuffer_type
);
396 rstate
->state
.framebuffer
= *state
;
397 for (i
= 0; i
< rstate
->state
.framebuffer
.nr_cbufs
; i
++) {
398 pipe_reference(NULL
, &state
->cbufs
[i
]->reference
);
400 pipe_reference(NULL
, &state
->zsbuf
->reference
);
401 rctx
->framebuffer
= rstate
;
402 for (i
= 0; i
< state
->nr_cbufs
; i
++) {
403 rctx
->vtbl
->cb(rctx
, &rstate
->rstate
[i
+1], state
, i
);
406 rctx
->vtbl
->db(rctx
, &rstate
->rstate
[0], state
);
408 /* setup flush states */
409 setup_cb_flush(rctx
, &rctx
->hw_states
.cb_flush
);
410 setup_db_flush(rctx
, &rctx
->hw_states
.db_flush
);
415 static void r600_set_polygon_stipple(struct pipe_context
*ctx
,
416 const struct pipe_poly_stipple
*state
)
420 static void r600_set_sample_mask(struct pipe_context
*pipe
, unsigned sample_mask
)
424 static void r600_set_scissor_state(struct pipe_context
*ctx
,
425 const struct pipe_scissor_state
*state
)
427 struct r600_context
*rctx
= r600_context(ctx
);
428 struct r600_context_state
*rstate
;
430 r600_context_state_decref(rctx
->scissor
);
432 rstate
= r600_new_context_state(pipe_scissor_type
);
433 rstate
->state
.scissor
= *state
;
434 rctx
->scissor
= rstate
;
437 static void r600_set_stencil_ref(struct pipe_context
*ctx
,
438 const struct pipe_stencil_ref
*state
)
440 struct r600_context
*rctx
= r600_context(ctx
);
441 struct r600_context_state
*rstate
;
443 r600_context_state_decref(rctx
->stencil_ref
);
445 rstate
= r600_new_context_state(pipe_stencil_ref_type
);
446 rstate
->state
.stencil_ref
= *state
;
447 rctx
->stencil_ref
= rstate
;
450 static void r600_set_vertex_buffers(struct pipe_context
*ctx
,
452 const struct pipe_vertex_buffer
*buffers
)
454 struct r600_context
*rctx
= r600_context(ctx
);
456 boolean any_user_buffers
= FALSE
;
458 for (i
= 0; i
< rctx
->nvertex_buffer
; i
++) {
459 pipe_resource_reference(&rctx
->vertex_buffer
[i
].buffer
, NULL
);
461 memcpy(rctx
->vertex_buffer
, buffers
, sizeof(struct pipe_vertex_buffer
) * count
);
462 for (i
= 0; i
< count
; i
++) {
463 rctx
->vertex_buffer
[i
].buffer
= NULL
;
464 if (r600_buffer_is_user_buffer(buffers
[i
].buffer
))
465 any_user_buffers
= TRUE
;
466 pipe_resource_reference(&rctx
->vertex_buffer
[i
].buffer
, buffers
[i
].buffer
);
468 rctx
->any_user_vbs
= any_user_buffers
;
469 rctx
->nvertex_buffer
= count
;
472 static void r600_set_index_buffer(struct pipe_context
*ctx
,
473 const struct pipe_index_buffer
*ib
)
475 struct r600_context
*rctx
= r600_context(ctx
);
478 pipe_resource_reference(&rctx
->index_buffer
.buffer
, ib
->buffer
);
479 memcpy(&rctx
->index_buffer
, ib
, sizeof(rctx
->index_buffer
));
481 pipe_resource_reference(&rctx
->index_buffer
.buffer
, NULL
);
482 memset(&rctx
->index_buffer
, 0, sizeof(rctx
->index_buffer
));
485 /* TODO make this more like a state */
488 static void r600_set_viewport_state(struct pipe_context
*ctx
,
489 const struct pipe_viewport_state
*state
)
491 struct r600_context
*rctx
= r600_context(ctx
);
492 struct r600_context_state
*rstate
;
494 r600_context_state_decref(rctx
->viewport
);
496 rstate
= r600_new_context_state(pipe_viewport_type
);
497 rstate
->state
.viewport
= *state
;
498 rctx
->vtbl
->viewport(rctx
, &rstate
->rstate
[0], &rstate
->state
.viewport
);
499 rctx
->viewport
= rstate
;
502 void r600_init_state_functions(struct r600_context
*rctx
)
504 rctx
->context
.create_blend_state
= r600_create_blend_state
;
505 rctx
->context
.create_depth_stencil_alpha_state
= r600_create_dsa_state
;
506 rctx
->context
.create_fs_state
= r600_create_shader_state
;
507 rctx
->context
.create_rasterizer_state
= r600_create_rs_state
;
508 rctx
->context
.create_sampler_state
= r600_create_sampler_state
;
509 rctx
->context
.create_sampler_view
= r600_create_sampler_view
;
510 rctx
->context
.create_vertex_elements_state
= r600_create_vertex_elements
;
511 rctx
->context
.create_vs_state
= r600_create_shader_state
;
512 rctx
->context
.bind_blend_state
= r600_bind_blend_state
;
513 rctx
->context
.bind_depth_stencil_alpha_state
= r600_bind_dsa_state
;
514 rctx
->context
.bind_fragment_sampler_states
= r600_bind_ps_sampler
;
515 rctx
->context
.bind_fs_state
= r600_bind_ps_shader
;
516 rctx
->context
.bind_rasterizer_state
= r600_bind_rasterizer_state
;
517 rctx
->context
.bind_vertex_elements_state
= r600_bind_vertex_elements
;
518 rctx
->context
.bind_vertex_sampler_states
= r600_bind_vs_sampler
;
519 rctx
->context
.bind_vs_state
= r600_bind_vs_shader
;
520 rctx
->context
.delete_blend_state
= r600_delete_state
;
521 rctx
->context
.delete_depth_stencil_alpha_state
= r600_delete_state
;
522 rctx
->context
.delete_fs_state
= r600_delete_state
;
523 rctx
->context
.delete_rasterizer_state
= r600_delete_state
;
524 rctx
->context
.delete_sampler_state
= r600_delete_state
;
525 rctx
->context
.delete_vertex_elements_state
= r600_delete_vertex_element
;
526 rctx
->context
.delete_vs_state
= r600_delete_state
;
527 rctx
->context
.set_blend_color
= r600_set_blend_color
;
528 rctx
->context
.set_clip_state
= r600_set_clip_state
;
530 if (radeon_get_family_class(rctx
->rw
) == EVERGREEN
)
531 rctx
->context
.set_constant_buffer
= eg_set_constant_buffer
;
532 else if (rctx
->screen
->use_mem_constant
)
533 rctx
->context
.set_constant_buffer
= r600_set_constant_buffer_mem
;
535 rctx
->context
.set_constant_buffer
= r600_set_constant_buffer_file
;
537 rctx
->context
.set_fragment_sampler_views
= r600_set_ps_sampler_view
;
538 rctx
->context
.set_framebuffer_state
= r600_set_framebuffer_state
;
539 rctx
->context
.set_polygon_stipple
= r600_set_polygon_stipple
;
540 rctx
->context
.set_sample_mask
= r600_set_sample_mask
;
541 rctx
->context
.set_scissor_state
= r600_set_scissor_state
;
542 rctx
->context
.set_stencil_ref
= r600_set_stencil_ref
;
543 rctx
->context
.set_vertex_buffers
= r600_set_vertex_buffers
;
544 rctx
->context
.set_index_buffer
= r600_set_index_buffer
;
545 rctx
->context
.set_vertex_sampler_views
= r600_set_vs_sampler_view
;
546 rctx
->context
.set_viewport_state
= r600_set_viewport_state
;
547 rctx
->context
.sampler_view_destroy
= r600_sampler_view_destroy
;
550 struct r600_context_state
*r600_context_state_incref(struct r600_context_state
*rstate
)
558 struct r600_context_state
*r600_context_state_decref(struct r600_context_state
*rstate
)
564 if (--rstate
->refcount
)
566 switch (rstate
->type
) {
567 case pipe_sampler_view_type
:
568 pipe_resource_reference(&rstate
->state
.sampler_view
.texture
, NULL
);
570 case pipe_framebuffer_type
:
571 for (i
= 0; i
< rstate
->state
.framebuffer
.nr_cbufs
; i
++) {
572 pipe_surface_reference(&rstate
->state
.framebuffer
.cbufs
[i
], NULL
);
573 radeon_state_fini(&rstate
->rstate
[i
+1]);
575 pipe_surface_reference(&rstate
->state
.framebuffer
.zsbuf
, NULL
);
577 case pipe_viewport_type
:
578 case pipe_depth_type
:
579 case pipe_rasterizer_type
:
580 case pipe_poly_stipple_type
:
581 case pipe_scissor_type
:
583 case pipe_stencil_type
:
584 case pipe_alpha_type
:
586 case pipe_blend_type
:
587 case pipe_stencil_ref_type
:
588 case pipe_shader_type
:
589 case pipe_sampler_type
:
592 R600_ERR("invalid type %d\n", rstate
->type
);
595 radeon_state_fini(&rstate
->rstate
[0]);
600 static void r600_bind_shader_sampler(struct r600_context
*rctx
, struct r600_shader_sampler_states
*sampler
)
604 for (i
= 0; i
< sampler
->nsampler
; i
++) {
605 if (sampler
->sampler
[i
])
606 radeon_draw_bind(&rctx
->draw
, sampler
->sampler
[i
]);
609 for (i
= 0; i
< sampler
->nborder
; i
++) {
610 if (sampler
->border
[i
])
611 radeon_draw_bind(&rctx
->draw
, sampler
->border
[i
]);
614 for (i
= 0; i
< sampler
->nview
; i
++) {
615 if (sampler
->view
[i
])
616 radeon_draw_bind(&rctx
->draw
, sampler
->view
[i
]);
620 static void clean_flush(struct r600_context
*rctx
, struct radeon_state
*flush
)
622 struct r600_screen
*rscreen
= rctx
->screen
;
625 for (i
= 0 ; i
< flush
->nbo
; i
++) {
626 radeon_ws_bo_reference(rscreen
->rw
, &flush
->bo
[i
], NULL
);
629 radeon_state_fini(flush
);
632 static int setup_cb_flush(struct r600_context
*rctx
, struct radeon_state
*flush
)
634 struct r600_screen
*rscreen
= rctx
->screen
;
635 struct r600_resource_texture
*rtex
;
636 struct r600_resource
*rbuffer
;
637 struct pipe_surface
*surf
;
640 radeon_state_init(flush
, rscreen
->rw
, R600_STATE_CB_FLUSH
, 0, 0);
642 for (i
= 0; i
< rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
; i
++) {
643 surf
= rctx
->framebuffer
->state
.framebuffer
.cbufs
[i
];
645 rtex
= (struct r600_resource_texture
*)surf
->texture
;
646 rbuffer
= &rtex
->resource
;
647 /* just need to the bo to the flush list */
648 radeon_ws_bo_reference(rscreen
->rw
, &flush
->bo
[i
], rbuffer
->bo
);
649 flush
->placement
[i
] = RADEON_GEM_DOMAIN_VRAM
;
651 flush
->nbo
= rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
;
652 return radeon_state_pm4(flush
);
655 static int setup_db_flush(struct r600_context
*rctx
, struct radeon_state
*flush
)
657 struct r600_screen
*rscreen
= rctx
->screen
;
658 struct r600_resource_texture
*rtex
;
659 struct r600_resource
*rbuffer
;
660 struct pipe_surface
*surf
;
662 surf
= rctx
->framebuffer
->state
.framebuffer
.zsbuf
;
667 radeon_state_init(flush
, rscreen
->rw
, R600_STATE_DB_FLUSH
, 0, 0);
668 rtex
= (struct r600_resource_texture
*)surf
->texture
;
669 rbuffer
= &rtex
->resource
;
670 /* just need to the bo to the flush list */
671 radeon_ws_bo_reference(rscreen
->rw
, &flush
->bo
[0], rbuffer
->bo
);
672 flush
->placement
[0] = RADEON_GEM_DOMAIN_VRAM
;
675 return radeon_state_pm4(flush
);
678 int r600_context_hw_states(struct pipe_context
*ctx
)
680 struct r600_context
*rctx
= r600_context(ctx
);
683 /* build new states */
684 rctx
->vtbl
->rasterizer(rctx
, &rctx
->hw_states
.rasterizer
);
685 rctx
->vtbl
->scissor(rctx
, &rctx
->hw_states
.scissor
);
686 rctx
->vtbl
->dsa(rctx
, &rctx
->hw_states
.dsa
);
687 rctx
->vtbl
->cb_cntl(rctx
, &rctx
->hw_states
.cb_cntl
);
690 radeon_draw_bind(&rctx
->draw
, &rctx
->config
);
692 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.rasterizer
);
693 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.scissor
);
694 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.dsa
);
695 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.cb_cntl
);
697 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.db_flush
);
698 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.cb_flush
);
700 if (rctx
->viewport
) {
701 radeon_draw_bind(&rctx
->draw
, &rctx
->viewport
->rstate
[0]);
704 radeon_draw_bind(&rctx
->draw
, &rctx
->blend
->rstate
[0]);
707 radeon_draw_bind(&rctx
->draw
, &rctx
->clip
->rstate
[0]);
709 for (i
= 0; i
< rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
; i
++) {
710 radeon_draw_bind(&rctx
->draw
, &rctx
->framebuffer
->rstate
[i
+1]);
712 if (rctx
->framebuffer
->state
.framebuffer
.zsbuf
) {
713 radeon_draw_bind(&rctx
->draw
, &rctx
->framebuffer
->rstate
[0]);
716 r600_bind_shader_sampler(rctx
, &rctx
->vs_sampler
);
717 r600_bind_shader_sampler(rctx
, &rctx
->ps_sampler
);