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
;
88 zsurf
= ctx
->screen
->get_tex_surface(ctx
->screen
, &texture
->resource
.base
.b
, 0, level
, 0,
89 PIPE_BIND_DEPTH_STENCIL
);
91 cbsurf
= ctx
->screen
->get_tex_surface(ctx
->screen
,
92 (struct pipe_resource
*)texture
->flushed_depth_texture
,
93 0, level
, 0, PIPE_BIND_RENDER_TARGET
);
95 if (rctx
->family
== CHIP_RV610
|| rctx
->family
== CHIP_RV630
||
96 rctx
->family
== CHIP_RV620
|| rctx
->family
== CHIP_RV635
)
99 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
100 util_blitter_custom_depth_stencil(rctx
->blitter
, zsurf
, cbsurf
, rctx
->custom_dsa_flush
, depth
);
101 r600_blitter_end(ctx
);
103 pipe_surface_reference(&zsurf
, NULL
);
104 pipe_surface_reference(&cbsurf
, NULL
);
110 static void r600_clear(struct pipe_context
*ctx
, unsigned buffers
,
111 const float *rgba
, double depth
, unsigned stencil
)
113 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
114 struct pipe_framebuffer_state
*fb
= &rctx
->framebuffer
;
116 r600_blitter_begin(ctx
, R600_CLEAR
);
117 util_blitter_clear(rctx
->blitter
, fb
->width
, fb
->height
,
118 fb
->nr_cbufs
, buffers
, rgba
, depth
,
120 r600_blitter_end(ctx
);
123 static void r600_clear_render_target(struct pipe_context
*ctx
,
124 struct pipe_surface
*dst
,
126 unsigned dstx
, unsigned dsty
,
127 unsigned width
, unsigned height
)
129 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
131 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
132 util_blitter_clear_render_target(rctx
->blitter
, dst
, rgba
,
133 dstx
, dsty
, width
, height
);
134 r600_blitter_end(ctx
);
137 static void r600_clear_depth_stencil(struct pipe_context
*ctx
,
138 struct pipe_surface
*dst
,
139 unsigned clear_flags
,
142 unsigned dstx
, unsigned dsty
,
143 unsigned width
, unsigned height
)
145 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
147 r600_blitter_begin(ctx
, R600_CLEAR_SURFACE
);
148 util_blitter_clear_depth_stencil(rctx
->blitter
, dst
, clear_flags
, depth
, stencil
,
149 dstx
, dsty
, width
, height
);
150 r600_blitter_end(ctx
);
155 /* Copy a block of pixels from one surface to another using HW. */
156 static void r600_hw_copy_region(struct pipe_context
*ctx
,
157 struct pipe_resource
*dst
,
158 struct pipe_subresource subdst
,
159 unsigned dstx
, unsigned dsty
, unsigned dstz
,
160 struct pipe_resource
*src
,
161 struct pipe_subresource subsrc
,
162 unsigned srcx
, unsigned srcy
, unsigned srcz
,
163 unsigned width
, unsigned height
)
165 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
167 r600_blitter_begin(ctx
, R600_COPY
);
168 util_blitter_copy_region(rctx
->blitter
, dst
, subdst
, dstx
, dsty
, dstz
,
169 src
, subsrc
, srcx
, srcy
, srcz
, width
, height
,
171 r600_blitter_end(ctx
);
174 static void r600_resource_copy_region(struct pipe_context
*ctx
,
175 struct pipe_resource
*dst
,
176 struct pipe_subresource subdst
,
177 unsigned dstx
, unsigned dsty
, unsigned dstz
,
178 struct pipe_resource
*src
,
179 struct pipe_subresource subsrc
,
180 unsigned srcx
, unsigned srcy
, unsigned srcz
,
181 unsigned width
, unsigned height
)
184 /* there is something wrong with depth resource copies at the moment so avoid them for now */
185 is_depth
= util_format_get_component_bits(src
->format
, UTIL_FORMAT_COLORSPACE_ZS
, 0) != 0;
187 util_resource_copy_region(ctx
, dst
, subdst
, dstx
, dsty
, dstz
,
188 src
, subsrc
, srcx
, srcy
, srcz
, width
, height
);
190 r600_hw_copy_region(ctx
, dst
, subdst
, dstx
, dsty
, dstz
,
191 src
, subsrc
, srcx
, srcy
, srcz
, width
, height
);
194 void r600_init_blit_functions(struct r600_pipe_context
*rctx
)
196 rctx
->context
.clear
= r600_clear
;
197 rctx
->context
.clear_render_target
= r600_clear_render_target
;
198 rctx
->context
.clear_depth_stencil
= r600_clear_depth_stencil
;
199 rctx
->context
.resource_copy_region
= r600_resource_copy_region
;