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 r600_context_state_decref(rctx
->framebuffer
);
386 clean_flush(rctx
, &rctx
->hw_states
.cb_flush
);
387 clean_flush(rctx
, &rctx
->hw_states
.db_flush
);
389 rstate
= r600_new_context_state(pipe_framebuffer_type
);
390 rstate
->state
.framebuffer
= *state
;
391 for (i
= 0; i
< rstate
->state
.framebuffer
.nr_cbufs
; i
++) {
392 pipe_reference(NULL
, &state
->cbufs
[i
]->reference
);
394 pipe_reference(NULL
, &state
->zsbuf
->reference
);
395 rctx
->framebuffer
= rstate
;
396 for (i
= 0; i
< state
->nr_cbufs
; i
++) {
397 rctx
->vtbl
->cb(rctx
, &rstate
->rstate
[i
+1], state
, i
);
400 rctx
->vtbl
->db(rctx
, &rstate
->rstate
[0], state
);
402 /* setup flush states */
403 setup_cb_flush(rctx
, &rctx
->hw_states
.cb_flush
);
404 setup_db_flush(rctx
, &rctx
->hw_states
.db_flush
);
409 static void r600_set_polygon_stipple(struct pipe_context
*ctx
,
410 const struct pipe_poly_stipple
*state
)
414 static void r600_set_sample_mask(struct pipe_context
*pipe
, unsigned sample_mask
)
418 static void r600_set_scissor_state(struct pipe_context
*ctx
,
419 const struct pipe_scissor_state
*state
)
421 struct r600_context
*rctx
= r600_context(ctx
);
422 struct r600_context_state
*rstate
;
424 r600_context_state_decref(rctx
->scissor
);
426 rstate
= r600_new_context_state(pipe_scissor_type
);
427 rstate
->state
.scissor
= *state
;
428 rctx
->scissor
= rstate
;
431 static void r600_set_stencil_ref(struct pipe_context
*ctx
,
432 const struct pipe_stencil_ref
*state
)
434 struct r600_context
*rctx
= r600_context(ctx
);
435 struct r600_context_state
*rstate
;
437 r600_context_state_decref(rctx
->stencil_ref
);
439 rstate
= r600_new_context_state(pipe_stencil_ref_type
);
440 rstate
->state
.stencil_ref
= *state
;
441 rctx
->stencil_ref
= rstate
;
444 static void r600_set_vertex_buffers(struct pipe_context
*ctx
,
446 const struct pipe_vertex_buffer
*buffers
)
448 struct r600_context
*rctx
= r600_context(ctx
);
450 boolean any_user_buffers
= FALSE
;
452 for (i
= 0; i
< rctx
->nvertex_buffer
; i
++) {
453 pipe_resource_reference(&rctx
->vertex_buffer
[i
].buffer
, NULL
);
455 memcpy(rctx
->vertex_buffer
, buffers
, sizeof(struct pipe_vertex_buffer
) * count
);
456 for (i
= 0; i
< count
; i
++) {
457 rctx
->vertex_buffer
[i
].buffer
= NULL
;
458 if (r600_buffer_is_user_buffer(buffers
[i
].buffer
))
459 any_user_buffers
= TRUE
;
460 pipe_resource_reference(&rctx
->vertex_buffer
[i
].buffer
, buffers
[i
].buffer
);
462 rctx
->any_user_vbs
= any_user_buffers
;
463 rctx
->nvertex_buffer
= count
;
466 static void r600_set_index_buffer(struct pipe_context
*ctx
,
467 const struct pipe_index_buffer
*ib
)
469 struct r600_context
*rctx
= r600_context(ctx
);
472 pipe_resource_reference(&rctx
->index_buffer
.buffer
, ib
->buffer
);
473 memcpy(&rctx
->index_buffer
, ib
, sizeof(rctx
->index_buffer
));
475 pipe_resource_reference(&rctx
->index_buffer
.buffer
, NULL
);
476 memset(&rctx
->index_buffer
, 0, sizeof(rctx
->index_buffer
));
479 /* TODO make this more like a state */
482 static void r600_set_viewport_state(struct pipe_context
*ctx
,
483 const struct pipe_viewport_state
*state
)
485 struct r600_context
*rctx
= r600_context(ctx
);
486 struct r600_context_state
*rstate
;
488 r600_context_state_decref(rctx
->viewport
);
490 rstate
= r600_new_context_state(pipe_viewport_type
);
491 rstate
->state
.viewport
= *state
;
492 rctx
->vtbl
->viewport(rctx
, &rstate
->rstate
[0], &rstate
->state
.viewport
);
493 rctx
->viewport
= rstate
;
496 void r600_init_state_functions(struct r600_context
*rctx
)
498 rctx
->context
.create_blend_state
= r600_create_blend_state
;
499 rctx
->context
.create_depth_stencil_alpha_state
= r600_create_dsa_state
;
500 rctx
->context
.create_fs_state
= r600_create_shader_state
;
501 rctx
->context
.create_rasterizer_state
= r600_create_rs_state
;
502 rctx
->context
.create_sampler_state
= r600_create_sampler_state
;
503 rctx
->context
.create_sampler_view
= r600_create_sampler_view
;
504 rctx
->context
.create_vertex_elements_state
= r600_create_vertex_elements
;
505 rctx
->context
.create_vs_state
= r600_create_shader_state
;
506 rctx
->context
.bind_blend_state
= r600_bind_blend_state
;
507 rctx
->context
.bind_depth_stencil_alpha_state
= r600_bind_dsa_state
;
508 rctx
->context
.bind_fragment_sampler_states
= r600_bind_ps_sampler
;
509 rctx
->context
.bind_fs_state
= r600_bind_ps_shader
;
510 rctx
->context
.bind_rasterizer_state
= r600_bind_rasterizer_state
;
511 rctx
->context
.bind_vertex_elements_state
= r600_bind_vertex_elements
;
512 rctx
->context
.bind_vertex_sampler_states
= r600_bind_vs_sampler
;
513 rctx
->context
.bind_vs_state
= r600_bind_vs_shader
;
514 rctx
->context
.delete_blend_state
= r600_delete_state
;
515 rctx
->context
.delete_depth_stencil_alpha_state
= r600_delete_state
;
516 rctx
->context
.delete_fs_state
= r600_delete_state
;
517 rctx
->context
.delete_rasterizer_state
= r600_delete_state
;
518 rctx
->context
.delete_sampler_state
= r600_delete_state
;
519 rctx
->context
.delete_vertex_elements_state
= r600_delete_vertex_element
;
520 rctx
->context
.delete_vs_state
= r600_delete_state
;
521 rctx
->context
.set_blend_color
= r600_set_blend_color
;
522 rctx
->context
.set_clip_state
= r600_set_clip_state
;
524 if (rctx
->screen
->chip_class
== EVERGREEN
)
525 rctx
->context
.set_constant_buffer
= eg_set_constant_buffer
;
526 else if (rctx
->screen
->use_mem_constant
)
527 rctx
->context
.set_constant_buffer
= r600_set_constant_buffer_mem
;
529 rctx
->context
.set_constant_buffer
= r600_set_constant_buffer_file
;
531 rctx
->context
.set_fragment_sampler_views
= r600_set_ps_sampler_view
;
532 rctx
->context
.set_framebuffer_state
= r600_set_framebuffer_state
;
533 rctx
->context
.set_polygon_stipple
= r600_set_polygon_stipple
;
534 rctx
->context
.set_sample_mask
= r600_set_sample_mask
;
535 rctx
->context
.set_scissor_state
= r600_set_scissor_state
;
536 rctx
->context
.set_stencil_ref
= r600_set_stencil_ref
;
537 rctx
->context
.set_vertex_buffers
= r600_set_vertex_buffers
;
538 rctx
->context
.set_index_buffer
= r600_set_index_buffer
;
539 rctx
->context
.set_vertex_sampler_views
= r600_set_vs_sampler_view
;
540 rctx
->context
.set_viewport_state
= r600_set_viewport_state
;
541 rctx
->context
.sampler_view_destroy
= r600_sampler_view_destroy
;
544 struct r600_context_state
*r600_context_state_incref(struct r600_context_state
*rstate
)
552 struct r600_context_state
*r600_context_state_decref(struct r600_context_state
*rstate
)
558 if (--rstate
->refcount
)
560 switch (rstate
->type
) {
561 case pipe_sampler_view_type
:
562 pipe_resource_reference(&rstate
->state
.sampler_view
.texture
, NULL
);
564 case pipe_framebuffer_type
:
565 for (i
= 0; i
< rstate
->state
.framebuffer
.nr_cbufs
; i
++) {
566 pipe_surface_reference(&rstate
->state
.framebuffer
.cbufs
[i
], NULL
);
567 radeon_state_fini(&rstate
->rstate
[i
+1]);
569 pipe_surface_reference(&rstate
->state
.framebuffer
.zsbuf
, NULL
);
571 case pipe_viewport_type
:
572 case pipe_depth_type
:
573 case pipe_rasterizer_type
:
574 case pipe_poly_stipple_type
:
575 case pipe_scissor_type
:
577 case pipe_stencil_type
:
578 case pipe_alpha_type
:
580 case pipe_blend_type
:
581 case pipe_stencil_ref_type
:
582 case pipe_shader_type
:
583 case pipe_sampler_type
:
586 R600_ERR("invalid type %d\n", rstate
->type
);
589 radeon_state_fini(&rstate
->rstate
[0]);
594 static void r600_bind_shader_sampler(struct r600_context
*rctx
, struct r600_shader_sampler_states
*sampler
)
598 for (i
= 0; i
< sampler
->nsampler
; i
++) {
599 if (sampler
->sampler
[i
])
600 radeon_draw_bind(&rctx
->draw
, sampler
->sampler
[i
]);
603 for (i
= 0; i
< sampler
->nborder
; i
++) {
604 if (sampler
->border
[i
])
605 radeon_draw_bind(&rctx
->draw
, sampler
->border
[i
]);
608 for (i
= 0; i
< sampler
->nview
; i
++) {
609 if (sampler
->view
[i
])
610 radeon_draw_bind(&rctx
->draw
, sampler
->view
[i
]);
614 static void clean_flush(struct r600_context
*rctx
, struct radeon_state
*flush
)
616 struct r600_screen
*rscreen
= rctx
->screen
;
619 for (i
= 0 ; i
< flush
->nbo
; i
++) {
620 radeon_ws_bo_reference(rscreen
->rw
, &flush
->bo
[i
], NULL
);
623 radeon_state_fini(flush
);
626 static int setup_cb_flush(struct r600_context
*rctx
, struct radeon_state
*flush
)
628 struct r600_screen
*rscreen
= rctx
->screen
;
629 struct r600_resource_texture
*rtex
;
630 struct r600_resource
*rbuffer
;
631 struct pipe_surface
*surf
;
634 radeon_state_init(flush
, rscreen
->rw
, R600_STATE_CB_FLUSH
, 0, 0);
636 for (i
= 0; i
< rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
; i
++) {
637 surf
= rctx
->framebuffer
->state
.framebuffer
.cbufs
[i
];
639 rtex
= (struct r600_resource_texture
*)surf
->texture
;
640 rbuffer
= &rtex
->resource
;
641 /* just need to the bo to the flush list */
642 radeon_ws_bo_reference(rscreen
->rw
, &flush
->bo
[i
], rbuffer
->bo
);
643 flush
->placement
[i
] = RADEON_GEM_DOMAIN_VRAM
;
645 flush
->nbo
= rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
;
646 return radeon_state_pm4(flush
);
649 static int setup_db_flush(struct r600_context
*rctx
, struct radeon_state
*flush
)
651 struct r600_screen
*rscreen
= rctx
->screen
;
652 struct r600_resource_texture
*rtex
;
653 struct r600_resource
*rbuffer
;
654 struct pipe_surface
*surf
;
656 surf
= rctx
->framebuffer
->state
.framebuffer
.zsbuf
;
661 radeon_state_init(flush
, rscreen
->rw
, R600_STATE_DB_FLUSH
, 0, 0);
662 rtex
= (struct r600_resource_texture
*)surf
->texture
;
663 rbuffer
= &rtex
->resource
;
664 /* just need to the bo to the flush list */
665 radeon_ws_bo_reference(rscreen
->rw
, &flush
->bo
[0], rbuffer
->bo
);
666 flush
->placement
[0] = RADEON_GEM_DOMAIN_VRAM
;
669 return radeon_state_pm4(flush
);
672 int r600_context_hw_states(struct pipe_context
*ctx
)
674 struct r600_context
*rctx
= r600_context(ctx
);
677 /* build new states */
678 rctx
->vtbl
->rasterizer(rctx
, &rctx
->hw_states
.rasterizer
);
679 rctx
->vtbl
->scissor(rctx
, &rctx
->hw_states
.scissor
);
680 rctx
->vtbl
->dsa(rctx
, &rctx
->hw_states
.dsa
);
681 rctx
->vtbl
->cb_cntl(rctx
, &rctx
->hw_states
.cb_cntl
);
684 radeon_draw_bind(&rctx
->draw
, &rctx
->config
);
686 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.rasterizer
);
687 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.scissor
);
688 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.dsa
);
689 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.cb_cntl
);
691 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.db_flush
);
692 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.cb_flush
);
694 if (rctx
->viewport
) {
695 radeon_draw_bind(&rctx
->draw
, &rctx
->viewport
->rstate
[0]);
698 radeon_draw_bind(&rctx
->draw
, &rctx
->blend
->rstate
[0]);
701 radeon_draw_bind(&rctx
->draw
, &rctx
->clip
->rstate
[0]);
703 for (i
= 0; i
< rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
; i
++) {
704 radeon_draw_bind(&rctx
->draw
, &rctx
->framebuffer
->rstate
[i
+1]);
706 if (rctx
->framebuffer
->state
.framebuffer
.zsbuf
) {
707 radeon_draw_bind(&rctx
->draw
, &rctx
->framebuffer
->rstate
[0]);
710 r600_bind_shader_sampler(rctx
, &rctx
->vs_sampler
);
711 r600_bind_shader_sampler(rctx
, &rctx
->ps_sampler
);