2 * Copyright 2009 Marek Olšák <maraeo@gmail.com>
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 <pipe/p_screen.h>
29 #include <util/u_blitter.h>
30 #include <util/u_inlines.h>
31 #include <util/u_memory.h>
32 #include "util/u_surface.h"
33 #include "r600_screen.h"
34 #include "r600_context.h"
36 static void r600_blitter_save_states(struct pipe_context
*ctx
)
38 struct r600_context
*rctx
= r600_context(ctx
);
40 util_blitter_save_blend(rctx
->blitter
, rctx
->blend
);
41 util_blitter_save_depth_stencil_alpha(rctx
->blitter
, rctx
->dsa
);
42 if (rctx
->stencil_ref
) {
43 util_blitter_save_stencil_ref(rctx
->blitter
,
44 &rctx
->stencil_ref
->state
.stencil_ref
);
46 util_blitter_save_rasterizer(rctx
->blitter
, rctx
->rasterizer
);
47 util_blitter_save_fragment_shader(rctx
->blitter
, rctx
->ps_shader
);
48 util_blitter_save_vertex_shader(rctx
->blitter
, rctx
->vs_shader
);
49 util_blitter_save_vertex_elements(rctx
->blitter
, rctx
->vertex_elements
);
51 util_blitter_save_viewport(rctx
->blitter
, &rctx
->viewport
->state
.viewport
);
54 util_blitter_save_clip(rctx
->blitter
, &rctx
->clip
->state
.clip
);
56 util_blitter_save_vertex_buffers(rctx
->blitter
, rctx
->nvertex_buffer
,
59 /* remove ptr so they don't get deleted */
62 rctx
->vs_shader
= NULL
;
63 rctx
->ps_shader
= NULL
;
64 rctx
->rasterizer
= NULL
;
66 rctx
->vertex_elements
= NULL
;
69 r600_queries_suspend(ctx
);
72 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
73 const float *rgba
, double depth
, unsigned stencil
)
75 struct r600_context
*rctx
= r600_context(ctx
);
76 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
->state
.framebuffer
;
78 r600_blitter_save_states(ctx
);
79 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
80 fb
->nr_cbufs
, buffers
, rgba
, depth
,
83 r600_queries_resume(ctx
);
86 static void r600_clear_render_target(struct pipe_context
*ctx
,
87 struct pipe_surface
*dst
,
89 unsigned dstx
, unsigned dsty
,
90 unsigned width
, unsigned height
)
92 struct r600_context
*rctx
= r600_context(ctx
);
93 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
->state
.framebuffer
;
95 r600_blitter_save_states(ctx
);
96 util_blitter_save_framebuffer(rctx
->blitter
, fb
);
98 util_blitter_clear_render_target(rctx
->blitter
, dst
, rgba
,
99 dstx
, dsty
, width
, height
);
101 r600_queries_resume(ctx
);
104 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
105 struct pipe_surface
*dst
,
106 unsigned clear_flags
,
109 unsigned dstx
, unsigned dsty
,
110 unsigned width
, unsigned height
)
112 struct r600_context
*rctx
= r600_context(ctx
);
113 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
->state
.framebuffer
;
115 r600_blitter_save_states(ctx
);
116 util_blitter_save_framebuffer(rctx
->blitter
, fb
);
118 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
119 dstx
, dsty
, width
, height
);
121 r600_queries_resume(ctx
);
125 static void r600_resource_copy_region(struct pipe_context
*ctx
,
126 struct pipe_resource
*dst
,
127 struct pipe_subresource subdst
,
128 unsigned dstx
, unsigned dsty
, unsigned dstz
,
129 struct pipe_resource
*src
,
130 struct pipe_subresource subsrc
,
131 unsigned srcx
, unsigned srcy
, unsigned srcz
,
132 unsigned width
, unsigned height
)
134 util_resource_copy_region(ctx
, dst
, subdst
, dstx
, dsty
, dstz
,
135 src
, subsrc
, srcx
, srcy
, srcz
, width
, height
);
138 static void *r600_create_db_flush_dsa(struct r600_context
*rctx
)
140 struct r600_screen
*rscreen
= rctx
->screen
;
141 struct pipe_depth_stencil_alpha_state dsa
;
142 struct r600_context_state
*state
;
143 boolean quirk
= false;
144 enum radeon_family family
;
146 family
= radeon_get_family(rscreen
->rw
);
147 if (family
== CHIP_RV610
|| family
== CHIP_RV630
|| family
== CHIP_RV620
||
148 family
== CHIP_RV635
)
151 memset(&dsa
, 0, sizeof(dsa
));
154 dsa
.depth
.enabled
= 1;
155 dsa
.depth
.func
= PIPE_FUNC_LEQUAL
;
156 dsa
.stencil
[0].enabled
= 1;
157 dsa
.stencil
[0].func
= PIPE_FUNC_ALWAYS
;
158 dsa
.stencil
[0].zpass_op
= PIPE_STENCIL_OP_KEEP
;
159 dsa
.stencil
[0].zfail_op
= PIPE_STENCIL_OP_INCR
;
160 dsa
.stencil
[0].writemask
= 0xff;
163 state
= rctx
->context
.create_depth_stencil_alpha_state(&rctx
->context
, &dsa
);
164 state
->flags
|= R600_STATE_FLAG_DSA_FLUSH
;
169 void r600_init_blit_functions(struct r600_context
*rctx
)
171 rctx
->context
.clear
= r600_clear
;
172 rctx
->context
.clear_render_target
= r600_clear_render_target
;
173 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
174 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;
176 /* create a custom depth stencil for DB flush */
177 rctx
->custom_dsa_flush
= r600_create_db_flush_dsa(rctx
);
180 int r600_blit_uncompress_depth(struct pipe_context
*ctx
, struct r600_resource_texture
*texture
)
182 struct r600_context
*rctx
= r600_context(ctx
);
183 struct r600_screen
*rscreen
= rctx
->screen
;
184 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
->state
.framebuffer
;
185 struct pipe_surface
*zsurf
, *cbsurf
;
186 enum radeon_family family
;
190 zsurf
= ctx
->screen
->get_tex_surface(ctx
->screen
, &texture
->resource
.base
.b
, 0, level
, 0,
191 PIPE_BIND_DEPTH_STENCIL
);
193 cbsurf
= ctx
->screen
->get_tex_surface(ctx
->screen
, texture
->flushed_depth_texture
, 0, level
, 0,
194 PIPE_BIND_RENDER_TARGET
);
196 r600_blitter_save_states(ctx
);
197 util_blitter_save_framebuffer(rctx
->blitter
, fb
);
199 family
= radeon_get_family(rscreen
->rw
);
200 if (family
== CHIP_RV610
|| family
== CHIP_RV630
|| family
== CHIP_RV620
||
201 family
== CHIP_RV635
)
204 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, cbsurf
, rctx
->custom_dsa_flush
, depth
);
207 r600_queries_resume(ctx
);