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 #include "r600_state_inlines.h"
38 static struct r600_context_state
*r600_new_context_state(unsigned type
)
40 struct r600_context_state
*rstate
= CALLOC_STRUCT(r600_context_state
);
48 static void *r600_create_blend_state(struct pipe_context
*ctx
,
49 const struct pipe_blend_state
*state
)
51 struct r600_context
*rctx
= r600_context(ctx
);
52 struct r600_context_state
*rstate
;
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
);
61 static void *r600_create_dsa_state(struct pipe_context
*ctx
,
62 const struct pipe_depth_stencil_alpha_state
*state
)
64 struct r600_context_state
*rstate
;
66 rstate
= r600_new_context_state(pipe_dsa_type
);
67 rstate
->state
.dsa
= *state
;
71 static void *r600_create_rs_state(struct pipe_context
*ctx
,
72 const struct pipe_rasterizer_state
*state
)
74 struct r600_context_state
*rstate
;
76 rstate
= r600_new_context_state(pipe_rasterizer_type
);
77 rstate
->state
.rasterizer
= *state
;
81 static void *r600_create_sampler_state(struct pipe_context
*ctx
,
82 const struct pipe_sampler_state
*state
)
84 struct r600_context
*rctx
= r600_context(ctx
);
85 struct r600_context_state
*rstate
;
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);
94 static void r600_remove_sampler_view(struct r600_shader_sampler_states
*sampler
,
95 struct r600_context_state
*rstate
)
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
;
106 static void r600_sampler_view_destroy(struct pipe_context
*ctx
,
107 struct pipe_sampler_view
*state
)
109 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
110 struct r600_context
*rctx
= r600_context(ctx
);
112 /* need to search list of vs/ps sampler views and remove it from any - uggh */
113 r600_remove_sampler_view(&rctx
->ps_sampler
, rstate
);
114 r600_remove_sampler_view(&rctx
->vs_sampler
, rstate
);
115 r600_context_state_decref(rstate
);
118 static struct pipe_sampler_view
*r600_create_sampler_view(struct pipe_context
*ctx
,
119 struct pipe_resource
*texture
,
120 const struct pipe_sampler_view
*state
)
122 struct r600_context_state
*rstate
;
123 struct r600_context
*rctx
= r600_context(ctx
);
125 rstate
= r600_new_context_state(pipe_sampler_view_type
);
126 rstate
->state
.sampler_view
= *state
;
127 rstate
->state
.sampler_view
.texture
= NULL
;
128 pipe_reference(NULL
, &texture
->reference
);
129 rstate
->state
.sampler_view
.texture
= texture
;
130 rstate
->state
.sampler_view
.reference
.count
= 1;
131 rstate
->state
.sampler_view
.context
= ctx
;
132 rctx
->vtbl
->resource(ctx
, &rstate
->rstate
[0], &rstate
->state
.sampler_view
, 0);
133 return &rstate
->state
.sampler_view
;
136 static void r600_set_sampler_view(struct pipe_context
*ctx
,
138 struct pipe_sampler_view
**views
,
139 struct r600_shader_sampler_states
*sampler
,
142 struct r600_context
*rctx
= r600_context(ctx
);
143 struct r600_context_state
*rstate
;
146 for (i
= 0; i
< sampler
->nview
; i
++) {
147 radeon_draw_unbind(&rctx
->draw
, sampler
->view
[i
]);
150 for (i
= 0; i
< count
; i
++) {
151 rstate
= (struct r600_context_state
*)views
[i
];
156 for (i
= 0; i
< count
; i
++) {
157 rstate
= (struct r600_context_state
*)views
[i
];
159 if (rstate
->nrstate
>= R600_MAX_RSTATE
)
161 if (rstate
->nrstate
) {
162 memcpy(&rstate
->rstate
[rstate
->nrstate
], &rstate
->rstate
[0], sizeof(struct radeon_state
));
164 radeon_state_convert(&rstate
->rstate
[rstate
->nrstate
], R600_STATE_RESOURCE
, i
, shader_id
);
165 sampler
->view
[i
] = &rstate
->rstate
[rstate
->nrstate
];
169 sampler
->nview
= count
;
172 static void r600_set_ps_sampler_view(struct pipe_context
*ctx
,
174 struct pipe_sampler_view
**views
)
176 struct r600_context
*rctx
= r600_context(ctx
);
177 r600_set_sampler_view(ctx
, count
, views
, &rctx
->ps_sampler
, R600_SHADER_PS
);
180 static void r600_set_vs_sampler_view(struct pipe_context
*ctx
,
182 struct pipe_sampler_view
**views
)
184 struct r600_context
*rctx
= r600_context(ctx
);
185 r600_set_sampler_view(ctx
, count
, views
, &rctx
->vs_sampler
, R600_SHADER_VS
);
188 static void *r600_create_shader_state(struct pipe_context
*ctx
,
189 const struct pipe_shader_state
*state
)
191 struct r600_context
*rctx
= r600_context(ctx
);
192 struct r600_context_state
*rstate
;
195 rstate
= r600_new_context_state(pipe_shader_type
);
196 rstate
->state
.shader
= *state
;
197 r
= r600_pipe_shader_create(&rctx
->context
, rstate
, rstate
->state
.shader
.tokens
);
199 r600_context_state_decref(rstate
);
205 static void *r600_create_vertex_elements(struct pipe_context
*ctx
,
207 const struct pipe_vertex_element
*elements
)
209 struct r600_vertex_element
*v
= CALLOC_STRUCT(r600_vertex_element
);
213 memcpy(v
->elements
, elements
, count
* sizeof(struct pipe_vertex_element
));
218 static void r600_delete_vertex_element(struct pipe_context
*ctx
, void *state
)
220 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
229 static void r600_bind_vertex_elements(struct pipe_context
*ctx
, void *state
)
231 struct r600_context
*rctx
= r600_context(ctx
);
232 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
234 r600_delete_vertex_element(ctx
, rctx
->vertex_elements
);
235 rctx
->vertex_elements
= v
;
241 static void r600_bind_rasterizer_state(struct pipe_context
*ctx
, void *state
)
243 struct r600_context
*rctx
= r600_context(ctx
);
244 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
248 rctx
->rasterizer
= r600_context_state_decref(rctx
->rasterizer
);
249 rctx
->rasterizer
= r600_context_state_incref(rstate
);
252 static void r600_bind_blend_state(struct pipe_context
*ctx
, void *state
)
254 struct r600_context
*rctx
= r600_context(ctx
);
255 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
259 rctx
->blend
= r600_context_state_decref(rctx
->blend
);
260 rctx
->blend
= r600_context_state_incref(rstate
);
264 static void r600_bind_dsa_state(struct pipe_context
*ctx
, void *state
)
266 struct r600_context
*rctx
= r600_context(ctx
);
267 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
271 rctx
->dsa
= r600_context_state_decref(rctx
->dsa
);
272 rctx
->dsa
= r600_context_state_incref(rstate
);
275 static void r600_bind_ps_shader(struct pipe_context
*ctx
, void *state
)
277 struct r600_context
*rctx
= r600_context(ctx
);
278 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
280 rctx
->ps_shader
= r600_context_state_decref(rctx
->ps_shader
);
281 rctx
->ps_shader
= r600_context_state_incref(rstate
);
284 static void r600_bind_vs_shader(struct pipe_context
*ctx
, void *state
)
286 struct r600_context
*rctx
= r600_context(ctx
);
287 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
289 rctx
->vs_shader
= r600_context_state_decref(rctx
->vs_shader
);
290 rctx
->vs_shader
= r600_context_state_incref(rstate
);
293 static void r600_bind_sampler_shader(struct pipe_context
*ctx
,
294 unsigned count
, void **states
,
295 struct r600_shader_sampler_states
*sampler
, unsigned shader_id
)
297 struct r600_context
*rctx
= r600_context(ctx
);
298 struct r600_context_state
*rstate
;
301 for (i
= 0; i
< sampler
->nsampler
; i
++) {
302 radeon_draw_unbind(&rctx
->draw
, sampler
->sampler
[i
]);
304 for (i
= 0; i
< sampler
->nborder
; i
++) {
305 radeon_draw_unbind(&rctx
->draw
, sampler
->border
[i
]);
307 for (i
= 0; i
< count
; i
++) {
308 rstate
= (struct r600_context_state
*)states
[i
];
313 for (i
= 0; i
< count
; i
++) {
314 rstate
= (struct r600_context_state
*)states
[i
];
316 if (rstate
->nrstate
>= R600_MAX_RSTATE
)
318 if (rstate
->nrstate
) {
319 memcpy(&rstate
->rstate
[rstate
->nrstate
], &rstate
->rstate
[0], sizeof(struct radeon_state
));
320 memcpy(&rstate
->rstate
[rstate
->nrstate
+1], &rstate
->rstate
[1], sizeof(struct radeon_state
));
322 radeon_state_convert(&rstate
->rstate
[rstate
->nrstate
], R600_STATE_SAMPLER
, i
, shader_id
);
323 radeon_state_convert(&rstate
->rstate
[rstate
->nrstate
+ 1], R600_STATE_SAMPLER_BORDER
, i
, shader_id
);
324 sampler
->sampler
[i
] = &rstate
->rstate
[rstate
->nrstate
];
325 sampler
->border
[i
] = &rstate
->rstate
[rstate
->nrstate
+ 1];
326 rstate
->nrstate
+= 2;
329 sampler
->nsampler
= count
;
330 sampler
->nborder
= count
;
333 static void r600_bind_ps_sampler(struct pipe_context
*ctx
,
334 unsigned count
, void **states
)
336 struct r600_context
*rctx
= r600_context(ctx
);
337 r600_bind_sampler_shader(ctx
, count
, states
, &rctx
->ps_sampler
, R600_SHADER_PS
);
340 static void r600_bind_vs_sampler(struct pipe_context
*ctx
,
341 unsigned count
, void **states
)
343 struct r600_context
*rctx
= r600_context(ctx
);
344 r600_bind_sampler_shader(ctx
, count
, states
, &rctx
->vs_sampler
, R600_SHADER_VS
);
347 static void r600_delete_state(struct pipe_context
*ctx
, void *state
)
349 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
351 r600_context_state_decref(rstate
);
354 static void r600_set_blend_color(struct pipe_context
*ctx
,
355 const struct pipe_blend_color
*color
)
357 struct r600_context
*rctx
= r600_context(ctx
);
359 rctx
->blend_color
= *color
;
362 static void r600_set_clip_state(struct pipe_context
*ctx
,
363 const struct pipe_clip_state
*state
)
365 struct r600_context
*rctx
= r600_context(ctx
);
366 struct r600_context_state
*rstate
;
368 r600_context_state_decref(rctx
->clip
);
370 rstate
= r600_new_context_state(pipe_clip_type
);
371 rstate
->state
.clip
= *state
;
372 rctx
->vtbl
->ucp(rctx
, &rstate
->rstate
[0], &rstate
->state
.clip
);
376 static void r600_set_framebuffer_state(struct pipe_context
*ctx
,
377 const struct pipe_framebuffer_state
*state
)
379 struct r600_context
*rctx
= r600_context(ctx
);
380 struct r600_context_state
*rstate
;
383 r600_context_state_decref(rctx
->framebuffer
);
385 rstate
= r600_new_context_state(pipe_framebuffer_type
);
386 rstate
->state
.framebuffer
= *state
;
387 for (i
= 0; i
< rstate
->state
.framebuffer
.nr_cbufs
; i
++) {
388 pipe_reference(NULL
, &state
->cbufs
[i
]->reference
);
390 pipe_reference(NULL
, &state
->zsbuf
->reference
);
391 rctx
->framebuffer
= rstate
;
392 for (i
= 0; i
< state
->nr_cbufs
; i
++) {
393 rctx
->vtbl
->cb(rctx
, &rstate
->rstate
[i
+1], state
, i
);
396 rctx
->vtbl
->db(rctx
, &rstate
->rstate
[0], state
);
401 static void r600_set_polygon_stipple(struct pipe_context
*ctx
,
402 const struct pipe_poly_stipple
*state
)
406 static void r600_set_sample_mask(struct pipe_context
*pipe
, unsigned sample_mask
)
410 static void r600_set_scissor_state(struct pipe_context
*ctx
,
411 const struct pipe_scissor_state
*state
)
413 struct r600_context
*rctx
= r600_context(ctx
);
414 struct r600_context_state
*rstate
;
416 r600_context_state_decref(rctx
->scissor
);
418 rstate
= r600_new_context_state(pipe_scissor_type
);
419 rstate
->state
.scissor
= *state
;
420 rctx
->scissor
= rstate
;
423 static void r600_set_stencil_ref(struct pipe_context
*ctx
,
424 const struct pipe_stencil_ref
*state
)
426 struct r600_context
*rctx
= r600_context(ctx
);
427 struct r600_context_state
*rstate
;
429 r600_context_state_decref(rctx
->stencil_ref
);
431 rstate
= r600_new_context_state(pipe_stencil_ref_type
);
432 rstate
->state
.stencil_ref
= *state
;
433 rctx
->stencil_ref
= rstate
;
436 static void r600_set_vertex_buffers(struct pipe_context
*ctx
,
438 const struct pipe_vertex_buffer
*buffers
)
440 struct r600_context
*rctx
= r600_context(ctx
);
443 for (i
= 0; i
< rctx
->nvertex_buffer
; i
++) {
444 pipe_resource_reference(&rctx
->vertex_buffer
[i
].buffer
, NULL
);
446 memcpy(rctx
->vertex_buffer
, buffers
, sizeof(struct pipe_vertex_buffer
) * count
);
447 for (i
= 0; i
< count
; i
++) {
448 rctx
->vertex_buffer
[i
].buffer
= NULL
;
449 pipe_resource_reference(&rctx
->vertex_buffer
[i
].buffer
, buffers
[i
].buffer
);
451 rctx
->nvertex_buffer
= count
;
454 static void r600_set_index_buffer(struct pipe_context
*ctx
,
455 const struct pipe_index_buffer
*ib
)
457 struct r600_context
*rctx
= r600_context(ctx
);
460 pipe_resource_reference(&rctx
->index_buffer
.buffer
, ib
->buffer
);
461 memcpy(&rctx
->index_buffer
, ib
, sizeof(rctx
->index_buffer
));
463 pipe_resource_reference(&rctx
->index_buffer
.buffer
, NULL
);
464 memset(&rctx
->index_buffer
, 0, sizeof(rctx
->index_buffer
));
467 /* TODO make this more like a state */
470 static void r600_set_viewport_state(struct pipe_context
*ctx
,
471 const struct pipe_viewport_state
*state
)
473 struct r600_context
*rctx
= r600_context(ctx
);
474 struct r600_context_state
*rstate
;
476 r600_context_state_decref(rctx
->viewport
);
478 rstate
= r600_new_context_state(pipe_viewport_type
);
479 rstate
->state
.viewport
= *state
;
480 rctx
->vtbl
->viewport(rctx
, &rstate
->rstate
[0], &rstate
->state
.viewport
);
481 rctx
->viewport
= rstate
;
484 void r600_init_state_functions(struct r600_context
*rctx
)
486 rctx
->context
.create_blend_state
= r600_create_blend_state
;
487 rctx
->context
.create_depth_stencil_alpha_state
= r600_create_dsa_state
;
488 rctx
->context
.create_fs_state
= r600_create_shader_state
;
489 rctx
->context
.create_rasterizer_state
= r600_create_rs_state
;
490 rctx
->context
.create_sampler_state
= r600_create_sampler_state
;
491 rctx
->context
.create_sampler_view
= r600_create_sampler_view
;
492 rctx
->context
.create_vertex_elements_state
= r600_create_vertex_elements
;
493 rctx
->context
.create_vs_state
= r600_create_shader_state
;
494 rctx
->context
.bind_blend_state
= r600_bind_blend_state
;
495 rctx
->context
.bind_depth_stencil_alpha_state
= r600_bind_dsa_state
;
496 rctx
->context
.bind_fragment_sampler_states
= r600_bind_ps_sampler
;
497 rctx
->context
.bind_fs_state
= r600_bind_ps_shader
;
498 rctx
->context
.bind_rasterizer_state
= r600_bind_rasterizer_state
;
499 rctx
->context
.bind_vertex_elements_state
= r600_bind_vertex_elements
;
500 rctx
->context
.bind_vertex_sampler_states
= r600_bind_vs_sampler
;
501 rctx
->context
.bind_vs_state
= r600_bind_vs_shader
;
502 rctx
->context
.delete_blend_state
= r600_delete_state
;
503 rctx
->context
.delete_depth_stencil_alpha_state
= r600_delete_state
;
504 rctx
->context
.delete_fs_state
= r600_delete_state
;
505 rctx
->context
.delete_rasterizer_state
= r600_delete_state
;
506 rctx
->context
.delete_sampler_state
= r600_delete_state
;
507 rctx
->context
.delete_vertex_elements_state
= r600_delete_vertex_element
;
508 rctx
->context
.delete_vs_state
= r600_delete_state
;
509 rctx
->context
.set_blend_color
= r600_set_blend_color
;
510 rctx
->context
.set_clip_state
= r600_set_clip_state
;
512 if (rctx
->screen
->chip_class
== EVERGREEN
)
513 rctx
->context
.set_constant_buffer
= eg_set_constant_buffer
;
514 else if (rctx
->screen
->use_mem_constant
)
515 rctx
->context
.set_constant_buffer
= r600_set_constant_buffer_mem
;
517 rctx
->context
.set_constant_buffer
= r600_set_constant_buffer_file
;
519 rctx
->context
.set_fragment_sampler_views
= r600_set_ps_sampler_view
;
520 rctx
->context
.set_framebuffer_state
= r600_set_framebuffer_state
;
521 rctx
->context
.set_polygon_stipple
= r600_set_polygon_stipple
;
522 rctx
->context
.set_sample_mask
= r600_set_sample_mask
;
523 rctx
->context
.set_scissor_state
= r600_set_scissor_state
;
524 rctx
->context
.set_stencil_ref
= r600_set_stencil_ref
;
525 rctx
->context
.set_vertex_buffers
= r600_set_vertex_buffers
;
526 rctx
->context
.set_index_buffer
= r600_set_index_buffer
;
527 rctx
->context
.set_vertex_sampler_views
= r600_set_vs_sampler_view
;
528 rctx
->context
.set_viewport_state
= r600_set_viewport_state
;
529 rctx
->context
.sampler_view_destroy
= r600_sampler_view_destroy
;
532 struct r600_context_state
*r600_context_state_incref(struct r600_context_state
*rstate
)
540 struct r600_context_state
*r600_context_state_decref(struct r600_context_state
*rstate
)
546 if (--rstate
->refcount
)
548 switch (rstate
->type
) {
549 case pipe_sampler_view_type
:
550 pipe_resource_reference(&rstate
->state
.sampler_view
.texture
, NULL
);
552 case pipe_framebuffer_type
:
553 for (i
= 0; i
< rstate
->state
.framebuffer
.nr_cbufs
; i
++) {
554 pipe_surface_reference(&rstate
->state
.framebuffer
.cbufs
[i
], NULL
);
556 pipe_surface_reference(&rstate
->state
.framebuffer
.zsbuf
, NULL
);
558 case pipe_viewport_type
:
559 case pipe_depth_type
:
560 case pipe_rasterizer_type
:
561 case pipe_poly_stipple_type
:
562 case pipe_scissor_type
:
564 case pipe_stencil_type
:
565 case pipe_alpha_type
:
567 case pipe_blend_type
:
568 case pipe_stencil_ref_type
:
569 case pipe_shader_type
:
570 case pipe_sampler_type
:
573 R600_ERR("invalid type %d\n", rstate
->type
);
576 radeon_state_fini(&rstate
->rstate
[0]);
581 static void r600_bind_shader_sampler(struct r600_context
*rctx
, struct r600_shader_sampler_states
*sampler
)
585 for (i
= 0; i
< sampler
->nsampler
; i
++) {
586 if (sampler
->sampler
[i
])
587 radeon_draw_bind(&rctx
->draw
, sampler
->sampler
[i
]);
590 for (i
= 0; i
< sampler
->nborder
; i
++) {
591 if (sampler
->border
[i
])
592 radeon_draw_bind(&rctx
->draw
, sampler
->border
[i
]);
595 for (i
= 0; i
< sampler
->nview
; i
++) {
596 if (sampler
->view
[i
])
597 radeon_draw_bind(&rctx
->draw
, sampler
->view
[i
]);
602 static int setup_cb_flush(struct r600_context
*rctx
, struct radeon_state
*flush
)
604 struct r600_screen
*rscreen
= rctx
->screen
;
605 struct r600_resource_texture
*rtex
;
606 struct r600_resource
*rbuffer
;
607 struct pipe_surface
*surf
;
610 radeon_state_init(flush
, rscreen
->rw
, R600_STATE_CB_FLUSH
, 0, 0);
612 for (i
= 0; i
< rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
; i
++) {
613 surf
= rctx
->framebuffer
->state
.framebuffer
.cbufs
[i
];
615 rtex
= (struct r600_resource_texture
*)surf
->texture
;
616 rbuffer
= &rtex
->resource
;
617 /* just need to the bo to the flush list */
618 flush
->bo
[i
] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
619 flush
->placement
[i
] = RADEON_GEM_DOMAIN_VRAM
;
621 flush
->nbo
= rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
;
622 return radeon_state_pm4(flush
);
625 static int setup_db_flush(struct r600_context
*rctx
, struct radeon_state
*flush
)
627 struct r600_screen
*rscreen
= rctx
->screen
;
628 struct r600_resource_texture
*rtex
;
629 struct r600_resource
*rbuffer
;
630 struct pipe_surface
*surf
;
632 surf
= rctx
->framebuffer
->state
.framebuffer
.zsbuf
;
637 radeon_state_init(flush
, rscreen
->rw
, R600_STATE_DB_FLUSH
, 0, 0);
638 rtex
= (struct r600_resource_texture
*)surf
->texture
;
639 rbuffer
= &rtex
->resource
;
640 /* just need to the bo to the flush list */
641 flush
->bo
[0] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
642 flush
->placement
[0] = RADEON_GEM_DOMAIN_VRAM
;
645 return radeon_state_pm4(flush
);
648 int r600_context_hw_states(struct pipe_context
*ctx
)
650 struct r600_context
*rctx
= r600_context(ctx
);
653 /* build new states */
654 rctx
->vtbl
->rasterizer(rctx
, &rctx
->hw_states
.rasterizer
);
655 rctx
->vtbl
->scissor(rctx
, &rctx
->hw_states
.scissor
);
656 rctx
->vtbl
->dsa(rctx
, &rctx
->hw_states
.dsa
);
657 rctx
->vtbl
->cb_cntl(rctx
, &rctx
->hw_states
.cb_cntl
);
660 setup_db_flush(rctx
, &rctx
->hw_states
.db_flush
);
661 setup_cb_flush(rctx
, &rctx
->hw_states
.cb_flush
);
664 radeon_draw_bind(&rctx
->draw
, &rctx
->config
);
666 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.rasterizer
);
667 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.scissor
);
668 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.dsa
);
669 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.cb_cntl
);
671 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.db_flush
);
672 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.cb_flush
);
674 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.db_flush
);
675 radeon_draw_bind(&rctx
->draw
, &rctx
->hw_states
.cb_flush
);
677 if (rctx
->viewport
) {
678 radeon_draw_bind(&rctx
->draw
, &rctx
->viewport
->rstate
[0]);
681 radeon_draw_bind(&rctx
->draw
, &rctx
->blend
->rstate
[0]);
684 radeon_draw_bind(&rctx
->draw
, &rctx
->clip
->rstate
[0]);
686 for (i
= 0; i
< rctx
->framebuffer
->state
.framebuffer
.nr_cbufs
; i
++) {
687 radeon_draw_bind(&rctx
->draw
, &rctx
->framebuffer
->rstate
[i
+1]);
689 if (rctx
->framebuffer
->state
.framebuffer
.zsbuf
) {
690 radeon_draw_bind(&rctx
->draw
, &rctx
->framebuffer
->rstate
[0]);
693 r600_bind_shader_sampler(rctx
, &rctx
->vs_sampler
);
694 r600_bind_shader_sampler(rctx
, &rctx
->ps_sampler
);