a19f494ea0cfe5685acb21dc673b31db25cf59a8
[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 "r600_pipe.h"
26
27 static void r600_blitter_save_states(struct pipe_context *ctx)
28 {
29 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
30
31 util_blitter_save_blend(rctx->blitter, rctx->states[R600_PIPE_STATE_BLEND]);
32 util_blitter_save_depth_stencil_alpha(rctx->blitter, rctx->states[R600_PIPE_STATE_DSA]);
33 if (rctx->states[R600_PIPE_STATE_STENCIL_REF]) {
34 util_blitter_save_stencil_ref(rctx->blitter, &rctx->stencil_ref);
35 }
36 util_blitter_save_rasterizer(rctx->blitter, rctx->states[R600_PIPE_STATE_RASTERIZER]);
37 util_blitter_save_fragment_shader(rctx->blitter, rctx->ps_shader);
38 util_blitter_save_vertex_shader(rctx->blitter, rctx->vs_shader);
39 util_blitter_save_vertex_elements(rctx->blitter, rctx->vertex_elements);
40 if (rctx->states[R600_PIPE_STATE_VIEWPORT]) {
41 util_blitter_save_viewport(rctx->blitter, &rctx->viewport);
42 }
43 if (rctx->states[R600_PIPE_STATE_CLIP]) {
44 util_blitter_save_clip(rctx->blitter, &rctx->clip);
45 }
46 util_blitter_save_vertex_buffers(rctx->blitter, rctx->nvertex_buffer, rctx->vertex_buffer);
47
48 rctx->vertex_elements = NULL;
49
50 /* TODO queries */
51 }
52
53 int r600_blit_uncompress_depth2(struct pipe_context *ctx, struct r600_resource_texture *texture)
54 {
55 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
56 struct pipe_framebuffer_state fb = *rctx->pframebuffer;
57 struct pipe_surface *zsurf, *cbsurf;
58 int level = 0;
59 float depth = 1.0f;
60
61 r600_context_queries_suspend(&rctx->ctx);
62 for (int i = 0; i < fb.nr_cbufs; i++) {
63 fb.cbufs[i] = NULL;
64 pipe_surface_reference(&fb.cbufs[i], rctx->pframebuffer->cbufs[i]);
65 }
66 fb.zsbuf = NULL;
67 pipe_surface_reference(&fb.zsbuf, rctx->pframebuffer->zsbuf);
68
69 zsurf = ctx->screen->get_tex_surface(ctx->screen, &texture->resource.base.b, 0, level, 0,
70 PIPE_BIND_DEPTH_STENCIL);
71
72 cbsurf = ctx->screen->get_tex_surface(ctx->screen,
73 (struct pipe_resource*)texture->flushed_depth_texture,
74 0, level, 0, PIPE_BIND_RENDER_TARGET);
75
76 r600_blitter_save_states(ctx);
77 util_blitter_save_framebuffer(rctx->blitter, &fb);
78
79 if (rctx->family == CHIP_RV610 || rctx->family == CHIP_RV630 ||
80 rctx->family == CHIP_RV620 || rctx->family == CHIP_RV635)
81 depth = 0.0f;
82
83 util_blitter_custom_depth_stencil(rctx->blitter, zsurf, cbsurf, rctx->custom_dsa_flush, depth);
84
85 pipe_surface_reference(&zsurf, NULL);
86 pipe_surface_reference(&cbsurf, NULL);
87 for (int i = 0; i < fb.nr_cbufs; i++) {
88 pipe_surface_reference(&fb.cbufs[i], NULL);
89 }
90 pipe_surface_reference(&fb.zsbuf, NULL);
91 r600_context_queries_resume(&rctx->ctx);
92
93 return 0;
94 }
95
96 static void r600_clear(struct pipe_context *ctx, unsigned buffers,
97 const float *rgba, double depth, unsigned stencil)
98 {
99 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
100 struct pipe_framebuffer_state *fb = &rctx->framebuffer;
101
102 r600_context_queries_suspend(&rctx->ctx);
103 r600_blitter_save_states(ctx);
104 util_blitter_clear(rctx->blitter, fb->width, fb->height,
105 fb->nr_cbufs, buffers, rgba, depth,
106 stencil);
107 r600_context_queries_resume(&rctx->ctx);
108 }
109
110 static void r600_clear_render_target(struct pipe_context *ctx,
111 struct pipe_surface *dst,
112 const float *rgba,
113 unsigned dstx, unsigned dsty,
114 unsigned width, unsigned height)
115 {
116 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
117 struct pipe_framebuffer_state *fb = &rctx->framebuffer;
118
119 r600_context_queries_suspend(&rctx->ctx);
120 util_blitter_save_framebuffer(rctx->blitter, fb);
121 util_blitter_clear_render_target(rctx->blitter, dst, rgba,
122 dstx, dsty, width, height);
123 r600_context_queries_resume(&rctx->ctx);
124 }
125
126 static void r600_clear_depth_stencil(struct pipe_context *ctx,
127 struct pipe_surface *dst,
128 unsigned clear_flags,
129 double depth,
130 unsigned stencil,
131 unsigned dstx, unsigned dsty,
132 unsigned width, unsigned height)
133 {
134 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
135 struct pipe_framebuffer_state *fb = &rctx->framebuffer;
136
137 r600_context_queries_suspend(&rctx->ctx);
138 util_blitter_save_framebuffer(rctx->blitter, fb);
139 util_blitter_clear_depth_stencil(rctx->blitter, dst, clear_flags, depth, stencil,
140 dstx, dsty, width, height);
141 r600_context_queries_resume(&rctx->ctx);
142 }
143
144
145 static void r600_resource_copy_region(struct pipe_context *ctx,
146 struct pipe_resource *dst,
147 struct pipe_subresource subdst,
148 unsigned dstx, unsigned dsty, unsigned dstz,
149 struct pipe_resource *src,
150 struct pipe_subresource subsrc,
151 unsigned srcx, unsigned srcy, unsigned srcz,
152 unsigned width, unsigned height)
153 {
154 util_resource_copy_region(ctx, dst, subdst, dstx, dsty, dstz,
155 src, subsrc, srcx, srcy, srcz, width, height);
156 }
157
158 void r600_init_blit_functions2(struct r600_pipe_context *rctx)
159 {
160 rctx->context.clear = r600_clear;
161 rctx->context.clear_render_target = r600_clear_render_target;
162 rctx->context.clear_depth_stencil = r600_clear_depth_stencil;
163 rctx->context.resource_copy_region = r600_resource_copy_region;
164 }