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 struct r600_context_state
*r600_new_context_state(unsigned type
)
38 struct r600_context_state
*rstate
= CALLOC_STRUCT(r600_context_state
);
46 static void *r600_create_blend_state(struct pipe_context
*ctx
,
47 const struct pipe_blend_state
*state
)
49 struct r600_context
*rctx
= r600_context(ctx
);
50 struct r600_context_state
*rstate
;
52 rstate
= r600_new_context_state(pipe_blend_type
);
53 rstate
->state
.blend
= *state
;
54 rctx
->vtbl
->blend(rctx
, &rstate
->rstate
[0], &rstate
->state
.blend
);
59 static void *r600_create_dsa_state(struct pipe_context
*ctx
,
60 const struct pipe_depth_stencil_alpha_state
*state
)
62 struct r600_context_state
*rstate
;
64 rstate
= r600_new_context_state(pipe_dsa_type
);
65 rstate
->state
.dsa
= *state
;
69 static void *r600_create_rs_state(struct pipe_context
*ctx
,
70 const struct pipe_rasterizer_state
*state
)
72 struct r600_context_state
*rstate
;
74 rstate
= r600_new_context_state(pipe_rasterizer_type
);
75 rstate
->state
.rasterizer
= *state
;
79 static void *r600_create_sampler_state(struct pipe_context
*ctx
,
80 const struct pipe_sampler_state
*state
)
82 struct r600_context
*rctx
= r600_context(ctx
);
83 struct r600_context_state
*rstate
;
85 rstate
= r600_new_context_state(pipe_sampler_type
);
86 rstate
->state
.sampler
= *state
;
87 rctx
->vtbl
->sampler(rctx
, &rstate
->rstate
[0], &rstate
->state
.sampler
, 0);
88 rctx
->vtbl
->sampler_border(rctx
, &rstate
->rstate
[1], &rstate
->state
.sampler
, 0);
92 static void r600_remove_sampler_view(struct r600_shader_sampler_states
*sampler
,
93 struct r600_context_state
*rstate
)
97 for (i
= 0; i
< sampler
->nview
; i
++) {
98 for (j
= 0; j
< rstate
->nrstate
; j
++) {
99 if (sampler
->view
[i
] == &rstate
->rstate
[j
])
100 sampler
->view
[i
] = NULL
;
104 static void r600_sampler_view_destroy(struct pipe_context
*ctx
,
105 struct pipe_sampler_view
*state
)
107 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
108 struct r600_context
*rctx
= r600_context(ctx
);
110 /* need to search list of vs/ps sampler views and remove it from any - uggh */
111 r600_remove_sampler_view(&rctx
->ps_sampler
, rstate
);
112 r600_remove_sampler_view(&rctx
->vs_sampler
, rstate
);
113 r600_context_state_decref(rstate
);
116 static struct pipe_sampler_view
*r600_create_sampler_view(struct pipe_context
*ctx
,
117 struct pipe_resource
*texture
,
118 const struct pipe_sampler_view
*state
)
120 struct r600_context_state
*rstate
;
121 struct r600_context
*rctx
= r600_context(ctx
);
123 rstate
= r600_new_context_state(pipe_sampler_view_type
);
124 rstate
->state
.sampler_view
= *state
;
125 rstate
->state
.sampler_view
.texture
= NULL
;
126 pipe_reference(NULL
, &texture
->reference
);
127 rstate
->state
.sampler_view
.texture
= texture
;
128 rstate
->state
.sampler_view
.reference
.count
= 1;
129 rstate
->state
.sampler_view
.context
= ctx
;
130 rctx
->vtbl
->resource(ctx
, &rstate
->rstate
[0], &rstate
->state
.sampler_view
, 0);
131 return &rstate
->state
.sampler_view
;
134 static void r600_set_sampler_view(struct pipe_context
*ctx
,
136 struct pipe_sampler_view
**views
,
137 struct r600_shader_sampler_states
*sampler
,
140 struct r600_context
*rctx
= r600_context(ctx
);
141 struct r600_context_state
*rstate
;
144 for (i
= 0; i
< sampler
->nview
; i
++) {
145 radeon_draw_unbind(&rctx
->draw
, sampler
->view
[i
]);
148 for (i
= 0; i
< count
; i
++) {
149 rstate
= (struct r600_context_state
*)views
[i
];
154 for (i
= 0; i
< count
; i
++) {
155 rstate
= (struct r600_context_state
*)views
[i
];
157 if (rstate
->nrstate
>= R600_MAX_RSTATE
)
159 if (rstate
->nrstate
) {
160 memcpy(&rstate
->rstate
[rstate
->nrstate
], &rstate
->rstate
[0], sizeof(struct radeon_state
));
162 radeon_state_convert(&rstate
->rstate
[rstate
->nrstate
], R600_STATE_RESOURCE
, i
, shader_id
);
163 sampler
->view
[i
] = &rstate
->rstate
[rstate
->nrstate
];
167 sampler
->nview
= count
;
170 static void r600_set_ps_sampler_view(struct pipe_context
*ctx
,
172 struct pipe_sampler_view
**views
)
174 struct r600_context
*rctx
= r600_context(ctx
);
175 r600_set_sampler_view(ctx
, count
, views
, &rctx
->ps_sampler
, R600_SHADER_PS
);
178 static void r600_set_vs_sampler_view(struct pipe_context
*ctx
,
180 struct pipe_sampler_view
**views
)
182 struct r600_context
*rctx
= r600_context(ctx
);
183 r600_set_sampler_view(ctx
, count
, views
, &rctx
->vs_sampler
, R600_SHADER_VS
);
186 static void *r600_create_shader_state(struct pipe_context
*ctx
,
187 const struct pipe_shader_state
*state
)
189 struct r600_context
*rctx
= r600_context(ctx
);
190 struct r600_context_state
*rstate
;
193 rstate
= r600_new_context_state(pipe_shader_type
);
194 rstate
->state
.shader
= *state
;
195 r
= r600_pipe_shader_create(&rctx
->context
, rstate
, rstate
->state
.shader
.tokens
);
197 r600_context_state_decref(rstate
);
203 static void *r600_create_vertex_elements(struct pipe_context
*ctx
,
205 const struct pipe_vertex_element
*elements
)
207 struct r600_vertex_element
*v
= CALLOC_STRUCT(r600_vertex_element
);
211 memcpy(v
->elements
, elements
, count
* sizeof(struct pipe_vertex_element
));
216 static void r600_delete_vertex_element(struct pipe_context
*ctx
, void *state
)
218 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
227 static void r600_bind_vertex_elements(struct pipe_context
*ctx
, void *state
)
229 struct r600_context
*rctx
= r600_context(ctx
);
230 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
232 r600_delete_vertex_element(ctx
, rctx
->vertex_elements
);
233 rctx
->vertex_elements
= v
;
239 static void r600_bind_rasterizer_state(struct pipe_context
*ctx
, void *state
)
241 struct r600_context
*rctx
= r600_context(ctx
);
242 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
246 rctx
->rasterizer
= r600_context_state_decref(rctx
->rasterizer
);
247 rctx
->rasterizer
= r600_context_state_incref(rstate
);
250 static void r600_bind_blend_state(struct pipe_context
*ctx
, void *state
)
252 struct r600_context
*rctx
= r600_context(ctx
);
253 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
257 rctx
->blend
= r600_context_state_decref(rctx
->blend
);
258 rctx
->blend
= r600_context_state_incref(rstate
);
262 static void r600_bind_dsa_state(struct pipe_context
*ctx
, void *state
)
264 struct r600_context
*rctx
= r600_context(ctx
);
265 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
269 rctx
->dsa
= r600_context_state_decref(rctx
->dsa
);
270 rctx
->dsa
= r600_context_state_incref(rstate
);
273 static void r600_bind_ps_shader(struct pipe_context
*ctx
, void *state
)
275 struct r600_context
*rctx
= r600_context(ctx
);
276 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
278 rctx
->ps_shader
= r600_context_state_decref(rctx
->ps_shader
);
279 rctx
->ps_shader
= r600_context_state_incref(rstate
);
282 static void r600_bind_vs_shader(struct pipe_context
*ctx
, void *state
)
284 struct r600_context
*rctx
= r600_context(ctx
);
285 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
287 rctx
->vs_shader
= r600_context_state_decref(rctx
->vs_shader
);
288 rctx
->vs_shader
= r600_context_state_incref(rstate
);
291 static void r600_bind_sampler_shader(struct pipe_context
*ctx
,
292 unsigned count
, void **states
,
293 struct r600_shader_sampler_states
*sampler
, unsigned shader_id
)
295 struct r600_context
*rctx
= r600_context(ctx
);
296 struct r600_context_state
*rstate
;
299 for (i
= 0; i
< sampler
->nsampler
; i
++) {
300 radeon_draw_unbind(&rctx
->draw
, sampler
->sampler
[i
]);
302 for (i
= 0; i
< sampler
->nborder
; i
++) {
303 radeon_draw_unbind(&rctx
->draw
, sampler
->border
[i
]);
305 for (i
= 0; i
< count
; i
++) {
306 rstate
= (struct r600_context_state
*)states
[i
];
311 for (i
= 0; i
< count
; i
++) {
312 rstate
= (struct r600_context_state
*)states
[i
];
314 if (rstate
->nrstate
>= R600_MAX_RSTATE
)
316 if (rstate
->nrstate
) {
317 memcpy(&rstate
->rstate
[rstate
->nrstate
], &rstate
->rstate
[0], sizeof(struct radeon_state
));
318 memcpy(&rstate
->rstate
[rstate
->nrstate
+1], &rstate
->rstate
[1], sizeof(struct radeon_state
));
320 radeon_state_convert(&rstate
->rstate
[rstate
->nrstate
], R600_STATE_SAMPLER
, i
, shader_id
);
321 radeon_state_convert(&rstate
->rstate
[rstate
->nrstate
+ 1], R600_STATE_SAMPLER_BORDER
, i
, shader_id
);
322 sampler
->sampler
[i
] = &rstate
->rstate
[rstate
->nrstate
];
323 sampler
->border
[i
] = &rstate
->rstate
[rstate
->nrstate
+ 1];
324 rstate
->nrstate
+= 2;
327 sampler
->nsampler
= count
;
328 sampler
->nborder
= count
;
331 static void r600_bind_ps_sampler(struct pipe_context
*ctx
,
332 unsigned count
, void **states
)
334 struct r600_context
*rctx
= r600_context(ctx
);
335 r600_bind_sampler_shader(ctx
, count
, states
, &rctx
->ps_sampler
, R600_SHADER_PS
);
338 static void r600_bind_vs_sampler(struct pipe_context
*ctx
,
339 unsigned count
, void **states
)
341 struct r600_context
*rctx
= r600_context(ctx
);
342 r600_bind_sampler_shader(ctx
, count
, states
, &rctx
->vs_sampler
, R600_SHADER_VS
);
345 static void r600_delete_state(struct pipe_context
*ctx
, void *state
)
347 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
349 r600_context_state_decref(rstate
);
352 static void r600_set_blend_color(struct pipe_context
*ctx
,
353 const struct pipe_blend_color
*color
)
355 struct r600_context
*rctx
= r600_context(ctx
);
357 rctx
->blend_color
= *color
;
360 static void r600_set_clip_state(struct pipe_context
*ctx
,
361 const struct pipe_clip_state
*state
)
363 struct r600_context
*rctx
= r600_context(ctx
);
364 struct r600_context_state
*rstate
;
366 r600_context_state_decref(rctx
->clip
);
368 rstate
= r600_new_context_state(pipe_clip_type
);
369 rstate
->state
.clip
= *state
;
370 rctx
->vtbl
->ucp(rctx
, &rstate
->rstate
[0], &rstate
->state
.clip
);
374 static void r600_set_framebuffer_state(struct pipe_context
*ctx
,
375 const struct pipe_framebuffer_state
*state
)
377 struct r600_context
*rctx
= r600_context(ctx
);
378 struct r600_context_state
*rstate
;
381 r600_context_state_decref(rctx
->framebuffer
);
383 rstate
= r600_new_context_state(pipe_framebuffer_type
);
384 rstate
->state
.framebuffer
= *state
;
385 for (i
= 0; i
< rstate
->state
.framebuffer
.nr_cbufs
; i
++) {
386 pipe_reference(NULL
, &state
->cbufs
[i
]->reference
);
388 pipe_reference(NULL
, &state
->zsbuf
->reference
);
389 rctx
->framebuffer
= rstate
;
390 for (i
= 0; i
< state
->nr_cbufs
; i
++) {
391 rctx
->vtbl
->cb(rctx
, &rstate
->rstate
[i
+1], state
, i
);
394 rctx
->vtbl
->db(rctx
, &rstate
->rstate
[0], state
);
399 static void r600_set_polygon_stipple(struct pipe_context
*ctx
,
400 const struct pipe_poly_stipple
*state
)
404 static void r600_set_sample_mask(struct pipe_context
*pipe
, unsigned sample_mask
)
408 static void r600_set_scissor_state(struct pipe_context
*ctx
,
409 const struct pipe_scissor_state
*state
)
411 struct r600_context
*rctx
= r600_context(ctx
);
412 struct r600_context_state
*rstate
;
414 r600_context_state_decref(rctx
->scissor
);
416 rstate
= r600_new_context_state(pipe_scissor_type
);
417 rstate
->state
.scissor
= *state
;
418 rctx
->scissor
= rstate
;
421 static void r600_set_stencil_ref(struct pipe_context
*ctx
,
422 const struct pipe_stencil_ref
*state
)
424 struct r600_context
*rctx
= r600_context(ctx
);
425 struct r600_context_state
*rstate
;
427 r600_context_state_decref(rctx
->stencil_ref
);
429 rstate
= r600_new_context_state(pipe_stencil_ref_type
);
430 rstate
->state
.stencil_ref
= *state
;
431 rctx
->stencil_ref
= rstate
;
434 static void r600_set_vertex_buffers(struct pipe_context
*ctx
,
436 const struct pipe_vertex_buffer
*buffers
)
438 struct r600_context
*rctx
= r600_context(ctx
);
441 for (i
= 0; i
< rctx
->nvertex_buffer
; i
++) {
442 pipe_resource_reference(&rctx
->vertex_buffer
[i
].buffer
, NULL
);
444 memcpy(rctx
->vertex_buffer
, buffers
, sizeof(struct pipe_vertex_buffer
) * count
);
445 for (i
= 0; i
< count
; i
++) {
446 rctx
->vertex_buffer
[i
].buffer
= NULL
;
447 pipe_resource_reference(&rctx
->vertex_buffer
[i
].buffer
, buffers
[i
].buffer
);
449 rctx
->nvertex_buffer
= count
;
452 static void r600_set_index_buffer(struct pipe_context
*ctx
,
453 const struct pipe_index_buffer
*ib
)
455 struct r600_context
*rctx
= r600_context(ctx
);
458 pipe_resource_reference(&rctx
->index_buffer
.buffer
, ib
->buffer
);
459 memcpy(&rctx
->index_buffer
, ib
, sizeof(rctx
->index_buffer
));
461 pipe_resource_reference(&rctx
->index_buffer
.buffer
, NULL
);
462 memset(&rctx
->index_buffer
, 0, sizeof(rctx
->index_buffer
));
465 /* TODO make this more like a state */
468 static void r600_set_viewport_state(struct pipe_context
*ctx
,
469 const struct pipe_viewport_state
*state
)
471 struct r600_context
*rctx
= r600_context(ctx
);
472 struct r600_context_state
*rstate
;
474 r600_context_state_decref(rctx
->viewport
);
476 rstate
= r600_new_context_state(pipe_viewport_type
);
477 rstate
->state
.viewport
= *state
;
478 rctx
->vtbl
->viewport(rctx
, &rstate
->rstate
[0], &rstate
->state
.viewport
);
479 rctx
->viewport
= rstate
;
482 void r600_init_state_functions(struct r600_context
*rctx
)
484 rctx
->context
.create_blend_state
= r600_create_blend_state
;
485 rctx
->context
.create_depth_stencil_alpha_state
= r600_create_dsa_state
;
486 rctx
->context
.create_fs_state
= r600_create_shader_state
;
487 rctx
->context
.create_rasterizer_state
= r600_create_rs_state
;
488 rctx
->context
.create_sampler_state
= r600_create_sampler_state
;
489 rctx
->context
.create_sampler_view
= r600_create_sampler_view
;
490 rctx
->context
.create_vertex_elements_state
= r600_create_vertex_elements
;
491 rctx
->context
.create_vs_state
= r600_create_shader_state
;
492 rctx
->context
.bind_blend_state
= r600_bind_blend_state
;
493 rctx
->context
.bind_depth_stencil_alpha_state
= r600_bind_dsa_state
;
494 rctx
->context
.bind_fragment_sampler_states
= r600_bind_ps_sampler
;
495 rctx
->context
.bind_fs_state
= r600_bind_ps_shader
;
496 rctx
->context
.bind_rasterizer_state
= r600_bind_rasterizer_state
;
497 rctx
->context
.bind_vertex_elements_state
= r600_bind_vertex_elements
;
498 rctx
->context
.bind_vertex_sampler_states
= r600_bind_vs_sampler
;
499 rctx
->context
.bind_vs_state
= r600_bind_vs_shader
;
500 rctx
->context
.delete_blend_state
= r600_delete_state
;
501 rctx
->context
.delete_depth_stencil_alpha_state
= r600_delete_state
;
502 rctx
->context
.delete_fs_state
= r600_delete_state
;
503 rctx
->context
.delete_rasterizer_state
= r600_delete_state
;
504 rctx
->context
.delete_sampler_state
= r600_delete_state
;
505 rctx
->context
.delete_vertex_elements_state
= r600_delete_vertex_element
;
506 rctx
->context
.delete_vs_state
= r600_delete_state
;
507 rctx
->context
.set_blend_color
= r600_set_blend_color
;
508 rctx
->context
.set_clip_state
= r600_set_clip_state
;
510 if (rctx
->screen
->chip_class
== EVERGREEN
)
511 rctx
->context
.set_constant_buffer
= eg_set_constant_buffer
;
512 else if (rctx
->screen
->use_mem_constant
)
513 rctx
->context
.set_constant_buffer
= r600_set_constant_buffer_mem
;
515 rctx
->context
.set_constant_buffer
= r600_set_constant_buffer_file
;
517 rctx
->context
.set_fragment_sampler_views
= r600_set_ps_sampler_view
;
518 rctx
->context
.set_framebuffer_state
= r600_set_framebuffer_state
;
519 rctx
->context
.set_polygon_stipple
= r600_set_polygon_stipple
;
520 rctx
->context
.set_sample_mask
= r600_set_sample_mask
;
521 rctx
->context
.set_scissor_state
= r600_set_scissor_state
;
522 rctx
->context
.set_stencil_ref
= r600_set_stencil_ref
;
523 rctx
->context
.set_vertex_buffers
= r600_set_vertex_buffers
;
524 rctx
->context
.set_index_buffer
= r600_set_index_buffer
;
525 rctx
->context
.set_vertex_sampler_views
= r600_set_vs_sampler_view
;
526 rctx
->context
.set_viewport_state
= r600_set_viewport_state
;
527 rctx
->context
.sampler_view_destroy
= r600_sampler_view_destroy
;
530 struct r600_context_state
*r600_context_state_incref(struct r600_context_state
*rstate
)
538 struct r600_context_state
*r600_context_state_decref(struct r600_context_state
*rstate
)
544 if (--rstate
->refcount
)
546 switch (rstate
->type
) {
547 case pipe_sampler_view_type
:
548 pipe_resource_reference(&rstate
->state
.sampler_view
.texture
, NULL
);
550 case pipe_framebuffer_type
:
551 for (i
= 0; i
< rstate
->state
.framebuffer
.nr_cbufs
; i
++) {
552 pipe_surface_reference(&rstate
->state
.framebuffer
.cbufs
[i
], NULL
);
554 pipe_surface_reference(&rstate
->state
.framebuffer
.zsbuf
, NULL
);
556 case pipe_viewport_type
:
557 case pipe_depth_type
:
558 case pipe_rasterizer_type
:
559 case pipe_poly_stipple_type
:
560 case pipe_scissor_type
:
562 case pipe_stencil_type
:
563 case pipe_alpha_type
:
565 case pipe_blend_type
:
566 case pipe_stencil_ref_type
:
567 case pipe_shader_type
:
568 case pipe_sampler_type
:
571 R600_ERR("invalid type %d\n", rstate
->type
);
574 radeon_state_fini(&rstate
->rstate
[0]);
579 static void r600_bind_shader_sampler(struct r600_context
*rctx
, struct r600_shader_sampler_states
*sampler
)
583 for (i
= 0; i
< sampler
->nsampler
; i
++) {
584 if (sampler
->sampler
[i
])
585 radeon_draw_bind(&rctx
->draw
, sampler
->sampler
[i
]);
588 for (i
= 0; i
< sampler
->nborder
; i
++) {
589 if (sampler
->border
[i
])
590 radeon_draw_bind(&rctx
->draw
, sampler
->border
[i
]);
593 for (i
= 0; i
< sampler
->nview
; i
++) {
594 if (sampler
->view
[i
])
595 radeon_draw_bind(&rctx
->draw
, sampler
->view
[i
]);
600 static int setup_cb_flush(struct r600_context
*rctx
, struct radeon_state
*flush
)
602 struct r600_screen
*rscreen
= rctx
->screen
;
603 struct r600_resource_texture
*rtex
;
604 struct r600_resource
*rbuffer
;
605 struct pipe_surface
*surf
;
608 radeon_state_init(flush
, rscreen
->rw
, R600_STATE_CB_FLUSH
, 0, 0);
610 for (i
= 0; i
< rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
; i
++) {
611 surf
= rctx
->framebuffer
->state
.framebuffer
.cbufs
[i
];
613 rtex
= (struct r600_resource_texture
*)surf
->texture
;
614 rbuffer
= &rtex
->resource
;
615 /* just need to the bo to the flush list */
616 flush
->bo
[i
] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
617 flush
->placement
[i
] = RADEON_GEM_DOMAIN_VRAM
;
619 flush
->nbo
= rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
;
620 return radeon_state_pm4(flush
);
623 static int setup_db_flush(struct r600_context
*rctx
, struct radeon_state
*flush
)
625 struct r600_screen
*rscreen
= rctx
->screen
;
626 struct r600_resource_texture
*rtex
;
627 struct r600_resource
*rbuffer
;
628 struct pipe_surface
*surf
;
630 surf
= rctx
->framebuffer
->state
.framebuffer
.zsbuf
;
635 radeon_state_init(flush
, rscreen
->rw
, R600_STATE_DB_FLUSH
, 0, 0);
636 rtex
= (struct r600_resource_texture
*)surf
->texture
;
637 rbuffer
= &rtex
->resource
;
638 /* just need to the bo to the flush list */
639 flush
->bo
[0] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
640 flush
->placement
[0] = RADEON_GEM_DOMAIN_VRAM
;
643 return radeon_state_pm4(flush
);
646 int r600_context_hw_states(struct pipe_context
*ctx
)
648 struct r600_context
*rctx
= r600_context(ctx
);
651 /* build new states */
652 rctx
->vtbl
->rasterizer(rctx
, &rctx
->hw_states
.rasterizer
);
653 rctx
->vtbl
->scissor(rctx
, &rctx
->hw_states
.scissor
);
654 rctx
->vtbl
->dsa(rctx
, &rctx
->hw_states
.dsa
);
655 rctx
->vtbl
->cb_cntl(rctx
, &rctx
->hw_states
.cb_cntl
);
658 setup_db_flush(rctx
, &rctx
->hw_states
.db_flush
);
659 setup_cb_flush(rctx
, &rctx
->hw_states
.cb_flush
);
662 radeon_draw_bind(&rctx
->draw
, &rctx
->config
);
664 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.rasterizer
);
665 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.scissor
);
666 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.dsa
);
667 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.cb_cntl
);
669 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.db_flush
);
670 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.cb_flush
);
672 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.db_flush
);
673 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.cb_flush
);
675 if (rctx
->viewport
) {
676 radeon_draw_bind(&rctx
->draw
, &rctx
->viewport
->rstate
[0]);
679 radeon_draw_bind(&rctx
->draw
, &rctx
->blend
->rstate
[0]);
682 radeon_draw_bind(&rctx
->draw
, &rctx
->clip
->rstate
[0]);
684 for (i
= 0; i
< rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
; i
++) {
685 radeon_draw_bind(&rctx
->draw
, &rctx
->framebuffer
->rstate
[i
+1]);
687 if (rctx
->framebuffer
->state
.framebuffer
.zsbuf
) {
688 radeon_draw_bind(&rctx
->draw
, &rctx
->framebuffer
->rstate
[0]);
691 r600_bind_shader_sampler(rctx
, &rctx
->vs_sampler
);
692 r600_bind_shader_sampler(rctx
, &rctx
->ps_sampler
);