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.
23 #include <util/u_surface.h>
24 #include <util/u_blitter.h>
25 #include <util/u_format.h>
26 #include "r600_pipe.h"
28 enum r600_blitter_op
/* bitmask */
31 R600_CLEAR_SURFACE
= 2,
35 static void r600_blitter_begin(struct pipe_context
*ctx
, enum r600_blitter_op op
)
37 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
40 r600_context_queries_suspend(&rctx
->ctx
);
42 util_blitter_save_blend(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_BLEND
]);
43 util_blitter_save_depth_stencil_alpha(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_DSA
]);
44 if (rctx
->states
[R600_PIPE_STATE_STENCIL_REF
]) {
45 util_blitter_save_stencil_ref(rctx
->blitter
, &rctx
->stencil_ref
);
47 util_blitter_save_rasterizer(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_RASTERIZER
]);
48 util_blitter_save_fragment_shader(rctx
->blitter
, rctx
->ps_shader
);
49 util_blitter_save_vertex_shader(rctx
->blitter
, rctx
->vs_shader
);
50 util_blitter_save_vertex_elements(rctx
->blitter
, rctx
->vertex_elements
);
51 if (rctx
->states
[R600_PIPE_STATE_VIEWPORT
]) {
52 util_blitter_save_viewport(rctx
->blitter
, &rctx
->viewport
);
54 if (rctx
->states
[R600_PIPE_STATE_CLIP
]) {
55 util_blitter_save_clip(rctx
->blitter
, &rctx
->clip
);
57 util_blitter_save_vertex_buffers(rctx
->blitter
, rctx
->nvertex_buffers
, rctx
->vertex_buffer
);
59 if (op
& (R600_CLEAR_SURFACE
| R600_COPY
))
60 util_blitter_save_framebuffer(rctx
->blitter
, &rctx
->framebuffer
);
63 util_blitter_save_fragment_sampler_states(
64 rctx
->blitter
, rctx
->ps_samplers
.n_samplers
,
65 (void**)rctx
->ps_samplers
.samplers
);
67 util_blitter_save_fragment_sampler_views(
68 rctx
->blitter
, rctx
->ps_samplers
.n_views
,
69 (struct pipe_sampler_view
**)rctx
->ps_samplers
.views
);
74 static void r600_blitter_end(struct pipe_context
*ctx
)
76 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
77 r600_context_queries_resume(&rctx
->ctx
);
81 void r600_blit_uncompress_depth(struct pipe_context
*ctx
, struct r600_resource_texture
*texture
)
83 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
84 struct pipe_surface
*zsurf
, *cbsurf
, surf_tmpl
;
88 if (!texture
->dirty_db
)
91 surf_tmpl
.format
= texture
->resource
.base
.b
.format
;
92 surf_tmpl
.u
.tex
.level
= level
;
93 surf_tmpl
.u
.tex
.first_layer
= 0;
94 surf_tmpl
.u
.tex
.last_layer
= 0;
95 surf_tmpl
.usage
= PIPE_BIND_DEPTH_STENCIL
;
97 zsurf
= ctx
->create_surface(ctx
, &texture
->resource
.base
.b
, &surf_tmpl
);
99 surf_tmpl
.format
= ((struct pipe_resource
*)texture
->flushed_depth_texture
)->format
;
100 surf_tmpl
.usage
= PIPE_BIND_RENDER_TARGET
;
101 cbsurf
= ctx
->create_surface(ctx
,
102 (struct pipe_resource
*)texture
->flushed_depth_texture
, &surf_tmpl
);
104 if (rctx
->family
== CHIP_RV610
|| rctx
->family
== CHIP_RV630
||
105 rctx
->family
== CHIP_RV620
|| rctx
->family
== CHIP_RV635
)
108 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
109 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, cbsurf
, rctx
->custom_dsa_flush
, depth
);
110 r600_blitter_end(ctx
);
112 pipe_surface_reference(&zsurf
, NULL
);
113 pipe_surface_reference(&cbsurf
, NULL
);
115 texture
->dirty_db
= FALSE
;
118 void r600_flush_depth_textures(struct r600_pipe_context
*rctx
)
122 if (rctx
->blit
) return;
124 /* FIXME: This handles fragment shader textures only. */
126 for (i
= 0; i
< rctx
->ps_samplers
.n_views
; ++i
) {
127 struct r600_pipe_sampler_view
*view
;
128 struct r600_resource_texture
*tex
;
130 view
= rctx
->ps_samplers
.views
[i
];
133 tex
= (struct r600_resource_texture
*)view
->base
.texture
;
137 if (tex
->is_flushing_texture
)
140 r600_blit_uncompress_depth(&rctx
->context
, tex
);
143 /* also check CB here */
144 for (i
= 0; i
< rctx
->framebuffer
.nr_cbufs
; i
++) {
145 struct r600_resource_texture
*tex
;
146 tex
= (struct r600_resource_texture
*)rctx
->framebuffer
.cbufs
[i
]->texture
;
151 if (tex
->is_flushing_texture
)
154 r600_blit_uncompress_depth(&rctx
->context
, tex
);
158 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
159 const float *rgba
, double depth
, unsigned stencil
)
161 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
162 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
;
164 r600_blitter_begin(ctx
, R600_CLEAR
);
165 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
166 fb
->nr_cbufs
, buffers
, rgba
, depth
,
168 r600_blitter_end(ctx
);
171 static void r600_clear_render_target(struct pipe_context
*ctx
,
172 struct pipe_surface
*dst
,
174 unsigned dstx
, unsigned dsty
,
175 unsigned width
, unsigned height
)
177 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
179 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
180 util_blitter_clear_render_target(rctx
->blitter
, dst
, rgba
,
181 dstx
, dsty
, width
, height
);
182 r600_blitter_end(ctx
);
185 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
186 struct pipe_surface
*dst
,
187 unsigned clear_flags
,
190 unsigned dstx
, unsigned dsty
,
191 unsigned width
, unsigned height
)
193 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
195 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
196 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
197 dstx
, dsty
, width
, height
);
198 r600_blitter_end(ctx
);
203 /* Copy a block of pixels from one surface to another using HW. */
204 static void r600_hw_copy_region(struct pipe_context
*ctx
,
205 struct pipe_resource
*dst
,
207 unsigned dstx
, unsigned dsty
, unsigned dstz
,
208 struct pipe_resource
*src
,
210 const struct pipe_box
*src_box
)
212 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
214 r600_blitter_begin(ctx
, R600_COPY
);
215 util_blitter_copy_region(rctx
->blitter
, dst
, dst_level
, dstx
, dsty
, dstz
,
216 src
, src_level
, src_box
, TRUE
);
217 r600_blitter_end(ctx
);
220 static void r600_resource_copy_region(struct pipe_context
*ctx
,
221 struct pipe_resource
*dst
,
223 unsigned dstx
, unsigned dsty
, unsigned dstz
,
224 struct pipe_resource
*src
,
226 const struct pipe_box
*src_box
)
228 struct r600_resource_texture
*rsrc
= (struct r600_resource_texture
*)src
;
230 if (rsrc
->depth
&& !rsrc
->is_flushing_texture
)
231 r600_texture_depth_flush(ctx
, src
, FALSE
);
233 r600_hw_copy_region(ctx
, dst
, dst_level
, dstx
, dsty
, dstz
,
234 src
, src_level
, src_box
);
238 void r600_init_blit_functions(struct r600_pipe_context
*rctx
)
240 rctx
->context
.clear
= r600_clear
;
241 rctx
->context
.clear_render_target
= r600_clear_render_target
;
242 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
243 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;
246 void r600_blit_push_depth(struct pipe_context
*ctx
, struct r600_resource_texture
*texture
)
248 struct pipe_box sbox
;
250 sbox
.x
= sbox
.y
= sbox
.z
= 0;
251 sbox
.width
= texture
->resource
.base
.b
.width0
;
252 sbox
.height
= texture
->resource
.base
.b
.height0
;
253 /* XXX that might be wrong */
256 r600_hw_copy_region(ctx
, (struct pipe_resource
*)texture
, 0,
258 (struct pipe_resource
*)texture
->flushed_depth_texture
, 0,