r600g: Remove unnecessary header.
[mesa.git] / src / gallium / drivers / r600 / r600_blit.c
1 /*
2 * Copyright 2009 Marek Olšák <maraeo@gmail.com>
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 * Authors:
24 * Jerome Glisse
25 * Marek Olšák
26 */
27 #include <errno.h>
28 #include <pipe/p_screen.h>
29 #include <util/u_blitter.h>
30 #include <util/u_inlines.h>
31 #include <util/u_memory.h>
32 #include "util/u_surface.h"
33 #include "r600_screen.h"
34 #include "r600_context.h"
35
36 static void r600_blitter_save_states(struct pipe_context *ctx)
37 {
38 struct r600_context *rctx = r600_context(ctx);
39
40 util_blitter_save_blend(rctx->blitter, rctx->blend);
41 util_blitter_save_depth_stencil_alpha(rctx->blitter, rctx->dsa);
42 if (rctx->stencil_ref) {
43 util_blitter_save_stencil_ref(rctx->blitter,
44 &rctx->stencil_ref->state.stencil_ref);
45 }
46 util_blitter_save_rasterizer(rctx->blitter, rctx->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->viewport) {
51 util_blitter_save_viewport(rctx->blitter, &rctx->viewport->state.viewport);
52 }
53 if (rctx->clip) {
54 util_blitter_save_clip(rctx->blitter, &rctx->clip->state.clip);
55 }
56 util_blitter_save_vertex_buffers(rctx->blitter, rctx->nvertex_buffer,
57 rctx->vertex_buffer);
58
59 /* remove ptr so they don't get deleted */
60 rctx->blend = NULL;
61 rctx->clip = NULL;
62 rctx->vs_shader = NULL;
63 rctx->ps_shader = NULL;
64 rctx->rasterizer = NULL;
65 rctx->dsa = NULL;
66 rctx->vertex_elements = NULL;
67
68 /* suspend queries */
69 r600_queries_suspend(ctx);
70 }
71
72 static void r600_clear(struct pipe_context *ctx, unsigned buffers,
73 const float *rgba, double depth, unsigned stencil)
74 {
75 struct r600_context *rctx = r600_context(ctx);
76 struct pipe_framebuffer_state *fb = &rctx->framebuffer->state.framebuffer;
77
78 r600_blitter_save_states(ctx);
79 util_blitter_clear(rctx->blitter, fb->width, fb->height,
80 fb->nr_cbufs, buffers, rgba, depth,
81 stencil);
82 /* resume queries */
83 r600_queries_resume(ctx);
84 }
85
86 static void r600_clear_render_target(struct pipe_context *ctx,
87 struct pipe_surface *dst,
88 const float *rgba,
89 unsigned dstx, unsigned dsty,
90 unsigned width, unsigned height)
91 {
92 struct r600_context *rctx = r600_context(ctx);
93 struct pipe_framebuffer_state *fb = &rctx->framebuffer->state.framebuffer;
94
95 r600_blitter_save_states(ctx);
96 util_blitter_save_framebuffer(rctx->blitter, fb);
97
98 util_blitter_clear_render_target(rctx->blitter, dst, rgba,
99 dstx, dsty, width, height);
100 /* resume queries */
101 r600_queries_resume(ctx);
102 }
103
104 static void r600_clear_depth_stencil(struct pipe_context *ctx,
105 struct pipe_surface *dst,
106 unsigned clear_flags,
107 double depth,
108 unsigned stencil,
109 unsigned dstx, unsigned dsty,
110 unsigned width, unsigned height)
111 {
112 struct r600_context *rctx = r600_context(ctx);
113 struct pipe_framebuffer_state *fb = &rctx->framebuffer->state.framebuffer;
114
115 r600_blitter_save_states(ctx);
116 util_blitter_save_framebuffer(rctx->blitter, fb);
117
118 util_blitter_clear_depth_stencil(rctx->blitter, dst, clear_flags, depth, stencil,
119 dstx, dsty, width, height);
120 /* resume queries */
121 r600_queries_resume(ctx);
122 }
123
124
125 static void r600_resource_copy_region(struct pipe_context *ctx,
126 struct pipe_resource *dst,
127 struct pipe_subresource subdst,
128 unsigned dstx, unsigned dsty, unsigned dstz,
129 struct pipe_resource *src,
130 struct pipe_subresource subsrc,
131 unsigned srcx, unsigned srcy, unsigned srcz,
132 unsigned width, unsigned height)
133 {
134 util_resource_copy_region(ctx, dst, subdst, dstx, dsty, dstz,
135 src, subsrc, srcx, srcy, srcz, width, height);
136 }
137
138 static void *r600_create_db_flush_dsa(struct r600_context *rctx)
139 {
140 struct r600_screen *rscreen = rctx->screen;
141 struct pipe_depth_stencil_alpha_state dsa;
142 struct r600_context_state *state;
143 boolean quirk = false;
144 enum radeon_family family;
145
146 family = radeon_get_family(rscreen->rw);
147 if (family == CHIP_RV610 || family == CHIP_RV630 || family == CHIP_RV620 ||
148 family == CHIP_RV635)
149 quirk = true;
150
151 memset(&dsa, 0, sizeof(dsa));
152
153 if (quirk) {
154 dsa.depth.enabled = 1;
155 dsa.depth.func = PIPE_FUNC_LEQUAL;
156 dsa.stencil[0].enabled = 1;
157 dsa.stencil[0].func = PIPE_FUNC_ALWAYS;
158 dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_KEEP;
159 dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_INCR;
160 dsa.stencil[0].writemask = 0xff;
161 }
162
163 state = rctx->context.create_depth_stencil_alpha_state(&rctx->context, &dsa);
164 state->flags |= R600_STATE_FLAG_DSA_FLUSH;
165 return state;
166
167 }
168
169 void r600_init_blit_functions(struct r600_context *rctx)
170 {
171 rctx->context.clear = r600_clear;
172 rctx->context.clear_render_target = r600_clear_render_target;
173 rctx->context.clear_depth_stencil = r600_clear_depth_stencil;
174 rctx->context.resource_copy_region = r600_resource_copy_region;
175
176 /* create a custom depth stencil for DB flush */
177 rctx->custom_dsa_flush = r600_create_db_flush_dsa(rctx);
178 }
179
180 int r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture)
181 {
182 struct r600_context *rctx = r600_context(ctx);
183 struct r600_screen *rscreen = rctx->screen;
184 struct pipe_framebuffer_state *fb = &rctx->framebuffer->state.framebuffer;
185 struct pipe_surface *zsurf, *cbsurf;
186 enum radeon_family family;
187 int level = 0;
188 float depth = 1.0f;
189
190 zsurf = ctx->screen->get_tex_surface(ctx->screen, &texture->resource.base.b, 0, level, 0,
191 PIPE_BIND_DEPTH_STENCIL);
192
193 cbsurf = ctx->screen->get_tex_surface(ctx->screen, texture->flushed_depth_texture, 0, level, 0,
194 PIPE_BIND_RENDER_TARGET);
195
196 r600_blitter_save_states(ctx);
197 util_blitter_save_framebuffer(rctx->blitter, fb);
198
199 family = radeon_get_family(rscreen->rw);
200 if (family == CHIP_RV610 || family == CHIP_RV630 || family == CHIP_RV620 ||
201 family == CHIP_RV635)
202 depth = 0.0f;
203
204 util_blitter_custom_depth_stencil(rctx->blitter, zsurf, cbsurf, rctx->custom_dsa_flush, depth);
205
206 /* resume queries */
207 r600_queries_resume(ctx);
208 return 0;
209 }