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
->flushed
) return;
90 surf_tmpl
.format
= texture
->resource
.base
.b
.format
;
91 surf_tmpl
.u
.tex
.level
= level
;
92 surf_tmpl
.u
.tex
.first_layer
= 0;
93 surf_tmpl
.u
.tex
.last_layer
= 0;
94 surf_tmpl
.usage
= PIPE_BIND_DEPTH_STENCIL
;
96 zsurf
= ctx
->create_surface(ctx
, &texture
->resource
.base
.b
, &surf_tmpl
);
98 surf_tmpl
.format
= ((struct pipe_resource
*)texture
->flushed_depth_texture
)->format
;
99 surf_tmpl
.usage
= PIPE_BIND_RENDER_TARGET
;
100 cbsurf
= ctx
->create_surface(ctx
,
101 (struct pipe_resource
*)texture
->flushed_depth_texture
, &surf_tmpl
);
103 if (rctx
->family
== CHIP_RV610
|| rctx
->family
== CHIP_RV630
||
104 rctx
->family
== CHIP_RV620
|| rctx
->family
== CHIP_RV635
)
107 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
108 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, cbsurf
, rctx
->custom_dsa_flush
, depth
);
109 r600_blitter_end(ctx
);
110 texture
->flushed
= true;
112 pipe_surface_reference(&zsurf
, NULL
);
113 pipe_surface_reference(&cbsurf
, NULL
);
116 void r600_flush_depth_textures(struct r600_pipe_context
*rctx
)
120 if (rctx
->blit
) return;
122 /* FIXME: This handles fragment shader textures only. */
124 for (i
= 0; i
< rctx
->ps_samplers
.n_views
; ++i
) {
125 struct r600_pipe_sampler_view
*view
;
126 struct r600_resource_texture
*tex
;
128 view
= rctx
->ps_samplers
.views
[i
];
131 tex
= (struct r600_resource_texture
*)view
->base
.texture
;
132 if (!tex
->depth
) continue;
134 r600_blit_uncompress_depth(&rctx
->context
, tex
);
138 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
139 const float *rgba
, double depth
, unsigned stencil
)
141 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
142 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
;
144 r600_blitter_begin(ctx
, R600_CLEAR
);
145 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
146 fb
->nr_cbufs
, buffers
, rgba
, depth
,
148 r600_blitter_end(ctx
);
151 static void r600_clear_render_target(struct pipe_context
*ctx
,
152 struct pipe_surface
*dst
,
154 unsigned dstx
, unsigned dsty
,
155 unsigned width
, unsigned height
)
157 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
159 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
160 util_blitter_clear_render_target(rctx
->blitter
, dst
, rgba
,
161 dstx
, dsty
, width
, height
);
162 r600_blitter_end(ctx
);
165 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
166 struct pipe_surface
*dst
,
167 unsigned clear_flags
,
170 unsigned dstx
, unsigned dsty
,
171 unsigned width
, unsigned height
)
173 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
175 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
176 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
177 dstx
, dsty
, width
, height
);
178 r600_blitter_end(ctx
);
183 /* Copy a block of pixels from one surface to another using HW. */
184 static void r600_hw_copy_region(struct pipe_context
*ctx
,
185 struct pipe_resource
*dst
,
187 unsigned dstx
, unsigned dsty
, unsigned dstz
,
188 struct pipe_resource
*src
,
190 const struct pipe_box
*src_box
)
192 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
194 r600_blitter_begin(ctx
, R600_COPY
);
195 util_blitter_copy_region(rctx
->blitter
, dst
, dst_level
, dstx
, dsty
, dstz
,
196 src
, src_level
, src_box
, TRUE
);
197 r600_blitter_end(ctx
);
200 static void r600_resource_copy_region(struct pipe_context
*ctx
,
201 struct pipe_resource
*dst
,
203 unsigned dstx
, unsigned dsty
, unsigned dstz
,
204 struct pipe_resource
*src
,
206 const struct pipe_box
*src_box
)
209 /* there is something wrong with depth resource copies at the moment so avoid them for now */
210 is_depth
= util_format_get_component_bits(src
->format
, UTIL_FORMAT_COLORSPACE_ZS
, 0) != 0;
212 util_resource_copy_region(ctx
, dst
, dst_level
, dstx
, dsty
, dstz
,
213 src
, src_level
, src_box
);
215 r600_hw_copy_region(ctx
, dst
, dst_level
, dstx
, dsty
, dstz
,
216 src
, src_level
, src_box
);
219 void r600_init_blit_functions(struct r600_pipe_context
*rctx
)
221 rctx
->context
.clear
= r600_clear
;
222 rctx
->context
.clear_render_target
= r600_clear_render_target
;
223 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
224 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;