r600g: indentation fix
[mesa.git] / src / gallium / drivers / r600 / r600_blit.c
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 *
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:
10 *
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
13 * Software.
14 *
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.
22 */
23 #include <util/u_surface.h>
24 #include <util/u_blitter.h>
25 #include <util/u_format.h>
26 #include "r600_pipe.h"
27
28 enum r600_blitter_op /* bitmask */
29 {
30 R600_CLEAR = 1,
31 R600_CLEAR_SURFACE = 2,
32 R600_COPY = 4
33 };
34
35 static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op)
36 {
37 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
38
39 r600_context_queries_suspend(&rctx->ctx);
40
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);
45 }
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);
52 }
53 if (rctx->states[R600_PIPE_STATE_CLIP]) {
54 util_blitter_save_clip(rctx->blitter, &rctx->clip);
55 }
56 util_blitter_save_vertex_buffers(rctx->blitter, rctx->nvertex_buffer, rctx->vertex_buffer);
57
58 rctx->vertex_elements = NULL;
59
60 if (op & (R600_CLEAR_SURFACE | R600_COPY))
61 util_blitter_save_framebuffer(rctx->blitter, &rctx->framebuffer);
62
63 if (op & R600_COPY) {
64 util_blitter_save_fragment_sampler_states(
65 rctx->blitter, rctx->ps_samplers.n_samplers,
66 (void**)rctx->ps_samplers.samplers);
67
68 util_blitter_save_fragment_sampler_views(
69 rctx->blitter, rctx->ps_samplers.n_views,
70 (struct pipe_sampler_view**)rctx->ps_samplers.views);
71 }
72
73 }
74
75 static void r600_blitter_end(struct pipe_context *ctx)
76 {
77 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
78 r600_context_queries_resume(&rctx->ctx);
79 }
80
81 int r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture)
82 {
83 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
84 struct pipe_surface *zsurf, *cbsurf, surf_tmpl;
85 int level = 0;
86 float depth = 1.0f;
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;
92
93 zsurf = ctx->create_surface(ctx, &texture->resource.base.b, &surf_tmpl);
94
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);
99
100 if (rctx->family == CHIP_RV610 || rctx->family == CHIP_RV630 ||
101 rctx->family == CHIP_RV620 || rctx->family == CHIP_RV635)
102 depth = 0.0f;
103
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);
107
108 pipe_surface_reference(&zsurf, NULL);
109 pipe_surface_reference(&cbsurf, NULL);
110
111
112 return 0;
113 }
114
115 static void r600_clear(struct pipe_context *ctx, unsigned buffers,
116 const float *rgba, double depth, unsigned stencil)
117 {
118 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
119 struct pipe_framebuffer_state *fb = &rctx->framebuffer;
120
121 r600_blitter_begin(ctx, R600_CLEAR);
122 util_blitter_clear(rctx->blitter, fb->width, fb->height,
123 fb->nr_cbufs, buffers, rgba, depth,
124 stencil);
125 r600_blitter_end(ctx);
126 }
127
128 static void r600_clear_render_target(struct pipe_context *ctx,
129 struct pipe_surface *dst,
130 const float *rgba,
131 unsigned dstx, unsigned dsty,
132 unsigned width, unsigned height)
133 {
134 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
135
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);
140 }
141
142 static void r600_clear_depth_stencil(struct pipe_context *ctx,
143 struct pipe_surface *dst,
144 unsigned clear_flags,
145 double depth,
146 unsigned stencil,
147 unsigned dstx, unsigned dsty,
148 unsigned width, unsigned height)
149 {
150 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
151
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);
156 }
157
158
159
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,
163 unsigned dst_level,
164 unsigned dstx, unsigned dsty, unsigned dstz,
165 struct pipe_resource *src,
166 unsigned src_level,
167 const struct pipe_box *src_box)
168 {
169 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
170
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);
175 }
176
177 static void r600_resource_copy_region(struct pipe_context *ctx,
178 struct pipe_resource *dst,
179 unsigned dst_level,
180 unsigned dstx, unsigned dsty, unsigned dstz,
181 struct pipe_resource *src,
182 unsigned src_level,
183 const struct pipe_box *src_box)
184 {
185 boolean is_depth;
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;
188 if (is_depth)
189 util_resource_copy_region(ctx, dst, dst_level, dstx, dsty, dstz,
190 src, src_level, src_box);
191 else
192 r600_hw_copy_region(ctx, dst, dst_level, dstx, dsty, dstz,
193 src, src_level, src_box);
194 }
195
196 void r600_init_blit_functions(struct r600_pipe_context *rctx)
197 {
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;
202 }