dc57b333a03860477b44952a2a1df8d04f3a0f48
[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 <pipe/p_screen.h>
28 #include <util/u_blitter.h>
29 #include <util/u_inlines.h>
30 #include <util/u_memory.h>
31 #include "util/u_surface.h"
32 #include "r600_screen.h"
33 #include "r600_context.h"
34
35 static void r600_blitter_save_states(struct pipe_context *ctx)
36 {
37 struct r600_context *rctx = r600_context(ctx);
38
39 util_blitter_save_blend(rctx->blitter, rctx->blend);
40 util_blitter_save_depth_stencil_alpha(rctx->blitter, rctx->dsa);
41 if (rctx->stencil_ref) {
42 util_blitter_save_stencil_ref(rctx->blitter,
43 &rctx->stencil_ref->state.stencil_ref);
44 }
45 util_blitter_save_rasterizer(rctx->blitter, rctx->rasterizer);
46 util_blitter_save_fragment_shader(rctx->blitter, rctx->ps_shader);
47 util_blitter_save_vertex_shader(rctx->blitter, rctx->vs_shader);
48 util_blitter_save_vertex_elements(rctx->blitter, rctx->vertex_elements);
49 if (rctx->viewport) {
50 util_blitter_save_viewport(rctx->blitter, &rctx->viewport->state.viewport);
51 }
52 if (rctx->clip) {
53 util_blitter_save_clip(rctx->blitter, &rctx->clip->state.clip);
54 }
55 util_blitter_save_vertex_buffers(rctx->blitter, rctx->nvertex_buffer,
56 rctx->vertex_buffer);
57
58 /* remove ptr so they don't get deleted */
59 rctx->blend = NULL;
60 rctx->clip = NULL;
61 rctx->vs_shader = NULL;
62 rctx->ps_shader = NULL;
63 rctx->rasterizer = NULL;
64 rctx->dsa = NULL;
65 rctx->vertex_elements = NULL;
66
67 /* suspend queries */
68 r600_queries_suspend(ctx);
69 }
70
71 static void r600_clear(struct pipe_context *ctx, unsigned buffers,
72 const float *rgba, double depth, unsigned stencil)
73 {
74 struct r600_context *rctx = r600_context(ctx);
75 struct pipe_framebuffer_state *fb = &rctx->framebuffer->state.framebuffer;
76
77 r600_blitter_save_states(ctx);
78 util_blitter_clear(rctx->blitter, fb->width, fb->height,
79 fb->nr_cbufs, buffers, rgba, depth,
80 stencil);
81 /* resume queries */
82 r600_queries_resume(ctx);
83 }
84
85 static void r600_clear_render_target(struct pipe_context *ctx,
86 struct pipe_surface *dst,
87 const float *rgba,
88 unsigned dstx, unsigned dsty,
89 unsigned width, unsigned height)
90 {
91 struct r600_context *rctx = r600_context(ctx);
92 struct pipe_framebuffer_state *fb = &rctx->framebuffer->state.framebuffer;
93
94 r600_blitter_save_states(ctx);
95 util_blitter_save_framebuffer(rctx->blitter, fb);
96
97 util_blitter_clear_render_target(rctx->blitter, dst, rgba,
98 dstx, dsty, width, height);
99 /* resume queries */
100 r600_queries_resume(ctx);
101 }
102
103 static void r600_clear_depth_stencil(struct pipe_context *ctx,
104 struct pipe_surface *dst,
105 unsigned clear_flags,
106 double depth,
107 unsigned stencil,
108 unsigned dstx, unsigned dsty,
109 unsigned width, unsigned height)
110 {
111 struct r600_context *rctx = r600_context(ctx);
112 struct pipe_framebuffer_state *fb = &rctx->framebuffer->state.framebuffer;
113
114 r600_blitter_save_states(ctx);
115 util_blitter_save_framebuffer(rctx->blitter, fb);
116
117 util_blitter_clear_depth_stencil(rctx->blitter, dst, clear_flags, depth, stencil,
118 dstx, dsty, width, height);
119 /* resume queries */
120 r600_queries_resume(ctx);
121 }
122
123
124 static void r600_resource_copy_region(struct pipe_context *ctx,
125 struct pipe_resource *dst,
126 struct pipe_subresource subdst,
127 unsigned dstx, unsigned dsty, unsigned dstz,
128 struct pipe_resource *src,
129 struct pipe_subresource subsrc,
130 unsigned srcx, unsigned srcy, unsigned srcz,
131 unsigned width, unsigned height)
132 {
133 struct r600_context *rctx = r600_context(ctx);
134 struct pipe_framebuffer_state *fb = &rctx->framebuffer->state.framebuffer;
135 struct pipe_sampler_state *samplers[PIPE_MAX_ATTRIBS];
136 struct pipe_sampler_view_state *sampler_views[PIPE_MAX_ATTRIBS];
137 unsigned i;
138
139 for (i = 0; i < rctx->ps_nsampler_view; i++) {
140 sampler_views[i] = &rctx->ps_sampler_view[i]->state.sampler_view;
141 }
142 for (i = 0; i < rctx->ps_nsampler; i++) {
143 samplers[i] = &rctx->ps_sampler[i]->state.sampler;
144 }
145 r600_blitter_save_states(ctx);
146 util_blitter_save_framebuffer(rctx->blitter, fb);
147 util_blitter_save_fragment_sampler_states(rctx->blitter, rctx->ps_nsampler, samplers);
148 util_blitter_save_fragment_sampler_views(rctx->blitter, rctx->ps_nsampler_view, sampler_views);
149
150 util_blitter_copy_region(rctx->blitter, dst, subdst, dstx, dsty, dstz,
151 src, subsrc, srcx, srcy, srcz, width, height,
152 TRUE);
153 /* resume queries */
154 r600_queries_resume(ctx);
155 }
156
157 void r600_init_blit_functions(struct r600_context *rctx)
158 {
159 rctx->context.clear = r600_clear;
160 rctx->context.clear_render_target = r600_clear_render_target;
161 rctx->context.clear_depth_stencil = r600_clear_depth_stencil;
162 rctx->context.resource_copy_region = r600_resource_copy_region;
163 }