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
;
39 r600_context_queries_suspend(&rctx
->ctx
);
41 util_blitter_save_blend(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_BLEND
]);
42 util_blitter_save_depth_stencil_alpha(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_DSA
]);
43 if (rctx
->states
[R600_PIPE_STATE_STENCIL_REF
]) {
44 util_blitter_save_stencil_ref(rctx
->blitter
, &rctx
->stencil_ref
);
46 util_blitter_save_rasterizer(rctx
->blitter
, rctx
->states
[R600_PIPE_STATE_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
);
50 if (rctx
->states
[R600_PIPE_STATE_VIEWPORT
]) {
51 util_blitter_save_viewport(rctx
->blitter
, &rctx
->viewport
);
53 if (rctx
->states
[R600_PIPE_STATE_CLIP
]) {
54 util_blitter_save_clip(rctx
->blitter
, &rctx
->clip
);
56 util_blitter_save_vertex_buffers(rctx
->blitter
, rctx
->nvertex_buffer
, rctx
->vertex_buffer
);
58 rctx
->vertex_elements
= NULL
;
60 if (op
& (R600_CLEAR_SURFACE
| R600_COPY
))
61 util_blitter_save_framebuffer(rctx
->blitter
, &rctx
->framebuffer
);
64 util_blitter_save_fragment_sampler_states(
65 rctx
->blitter
, rctx
->ps_samplers
.n_samplers
,
66 (void**)rctx
->ps_samplers
.samplers
);
68 util_blitter_save_fragment_sampler_views(
69 rctx
->blitter
, rctx
->ps_samplers
.n_views
,
70 (struct pipe_sampler_view
**)rctx
->ps_samplers
.views
);
75 static void r600_blitter_end(struct pipe_context
*ctx
)
77 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
78 r600_context_queries_resume(&rctx
->ctx
);
81 int 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
;
87 surf_tmpl
.format
= texture
->resource
.base
.b
.format
;
88 surf_tmpl
.u
.tex
.level
= level
;
89 surf_tmpl
.u
.tex
.first_layer
= 0;
90 surf_tmpl
.u
.tex
.last_layer
= 0;
91 surf_tmpl
.usage
= PIPE_BIND_DEPTH_STENCIL
;
93 zsurf
= ctx
->create_surface(ctx
, &texture
->resource
.base
.b
, &surf_tmpl
);
95 surf_tmpl
.format
= ((struct pipe_resource
*)texture
->flushed_depth_texture
)->format
;
96 surf_tmpl
.usage
= PIPE_BIND_RENDER_TARGET
;
97 cbsurf
= ctx
->create_surface(ctx
,
98 (struct pipe_resource
*)texture
->flushed_depth_texture
, &surf_tmpl
);
100 if (rctx
->family
== CHIP_RV610
|| rctx
->family
== CHIP_RV630
||
101 rctx
->family
== CHIP_RV620
|| rctx
->family
== CHIP_RV635
)
104 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
105 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, cbsurf
, rctx
->custom_dsa_flush
, depth
);
106 r600_blitter_end(ctx
);
108 pipe_surface_reference(&zsurf
, NULL
);
109 pipe_surface_reference(&cbsurf
, NULL
);
115 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
116 const float *rgba
, double depth
, unsigned stencil
)
118 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
119 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
;
121 r600_blitter_begin(ctx
, R600_CLEAR
);
122 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
123 fb
->nr_cbufs
, buffers
, rgba
, depth
,
125 r600_blitter_end(ctx
);
128 static void r600_clear_render_target(struct pipe_context
*ctx
,
129 struct pipe_surface
*dst
,
131 unsigned dstx
, unsigned dsty
,
132 unsigned width
, unsigned height
)
134 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
136 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
137 util_blitter_clear_render_target(rctx
->blitter
, dst
, rgba
,
138 dstx
, dsty
, width
, height
);
139 r600_blitter_end(ctx
);
142 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
143 struct pipe_surface
*dst
,
144 unsigned clear_flags
,
147 unsigned dstx
, unsigned dsty
,
148 unsigned width
, unsigned height
)
150 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
152 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
153 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
154 dstx
, dsty
, width
, height
);
155 r600_blitter_end(ctx
);
160 /* Copy a block of pixels from one surface to another using HW. */
161 static void r600_hw_copy_region(struct pipe_context
*ctx
,
162 struct pipe_resource
*dst
,
164 unsigned dstx
, unsigned dsty
, unsigned dstz
,
165 struct pipe_resource
*src
,
167 const struct pipe_box
*src_box
)
169 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
171 r600_blitter_begin(ctx
, R600_COPY
);
172 util_blitter_copy_region(rctx
->blitter
, dst
, dst_level
, dstx
, dsty
, dstz
,
173 src
, src_level
, src_box
, TRUE
);
174 r600_blitter_end(ctx
);
177 static void r600_resource_copy_region(struct pipe_context
*ctx
,
178 struct pipe_resource
*dst
,
180 unsigned dstx
, unsigned dsty
, unsigned dstz
,
181 struct pipe_resource
*src
,
183 const struct pipe_box
*src_box
)
186 /* there is something wrong with depth resource copies at the moment so avoid them for now */
187 is_depth
= util_format_get_component_bits(src
->format
, UTIL_FORMAT_COLORSPACE_ZS
, 0) != 0;
189 util_resource_copy_region(ctx
, dst
, dst_level
, dstx
, dsty
, dstz
,
190 src
, src_level
, src_box
);
192 r600_hw_copy_region(ctx
, dst
, dst_level
, dstx
, dsty
, dstz
,
193 src
, src_level
, src_box
);
196 void r600_init_blit_functions(struct r600_pipe_context
*rctx
)
198 rctx
->context
.clear
= r600_clear
;
199 rctx
->context
.clear_render_target
= r600_clear_render_target
;
200 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
201 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;