etnaviv: remove dead code
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_clear_blit.c
1 /*
2 * Copyright (c) 2012-2015 Etnaviv Project
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 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the 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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Wladimir J. van der Laan <laanwj@gmail.com>
25 */
26
27 #include "etnaviv_clear_blit.h"
28
29 #include "hw/common.xml.h"
30
31 #include "etnaviv_blt.h"
32 #include "etnaviv_context.h"
33 #include "etnaviv_emit.h"
34 #include "etnaviv_format.h"
35 #include "etnaviv_resource.h"
36 #include "etnaviv_rs.h"
37 #include "etnaviv_surface.h"
38 #include "etnaviv_translate.h"
39
40 #include "pipe/p_defines.h"
41 #include "pipe/p_state.h"
42 #include "util/u_blitter.h"
43 #include "util/u_inlines.h"
44 #include "util/u_memory.h"
45 #include "util/u_surface.h"
46
47 /* Save current state for blitter operation */
48 void
49 etna_blit_save_state(struct etna_context *ctx)
50 {
51 util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vertex_buffer.vb);
52 util_blitter_save_vertex_elements(ctx->blitter, ctx->vertex_elements);
53 util_blitter_save_vertex_shader(ctx->blitter, ctx->shader.bind_vs);
54 util_blitter_save_rasterizer(ctx->blitter, ctx->rasterizer);
55 util_blitter_save_viewport(ctx->blitter, &ctx->viewport_s);
56 util_blitter_save_scissor(ctx->blitter, &ctx->scissor_s);
57 util_blitter_save_fragment_shader(ctx->blitter, ctx->shader.bind_fs);
58 util_blitter_save_blend(ctx->blitter, ctx->blend);
59 util_blitter_save_depth_stencil_alpha(ctx->blitter, ctx->zsa);
60 util_blitter_save_stencil_ref(ctx->blitter, &ctx->stencil_ref_s);
61 util_blitter_save_sample_mask(ctx->blitter, ctx->sample_mask);
62 util_blitter_save_framebuffer(ctx->blitter, &ctx->framebuffer_s);
63 util_blitter_save_fragment_sampler_states(ctx->blitter,
64 ctx->num_fragment_samplers, (void **)ctx->sampler);
65 util_blitter_save_fragment_sampler_views(ctx->blitter,
66 ctx->num_fragment_sampler_views, ctx->sampler_view);
67 }
68
69 uint64_t
70 etna_clear_blit_pack_rgba(enum pipe_format format, const union pipe_color_union *color)
71 {
72 union util_color uc;
73
74 if (util_format_is_pure_uint(format)) {
75 util_format_write_4ui(format, color->ui, 0, &uc, 0, 0, 0, 1, 1);
76 } else if (util_format_is_pure_sint(format)) {
77 util_format_write_4i(format, color->i, 0, &uc, 0, 0, 0, 1, 1);
78 } else {
79 util_pack_color(color->f, format, &uc);
80 }
81
82 switch (util_format_get_blocksize(format)) {
83 case 1:
84 uc.ui[0] = uc.ui[0] << 8 | (uc.ui[0] & 0xff);
85 case 2:
86 uc.ui[0] = uc.ui[0] << 16 | (uc.ui[0] & 0xffff);
87 case 4:
88 uc.ui[1] = uc.ui[0];
89 default:
90 return (uint64_t) uc.ui[1] << 32 | uc.ui[0];
91 }
92 }
93
94 static void
95 etna_clear_render_target(struct pipe_context *pctx, struct pipe_surface *dst,
96 const union pipe_color_union *color, unsigned dstx,
97 unsigned dsty, unsigned width, unsigned height,
98 bool render_condition_enabled)
99 {
100 struct etna_context *ctx = etna_context(pctx);
101
102 /* XXX could fall back to RS when target area is full screen / resolveable
103 * and no TS. */
104 etna_blit_save_state(ctx);
105 util_blitter_clear_render_target(ctx->blitter, dst, color, dstx, dsty, width, height);
106 }
107
108 static void
109 etna_clear_depth_stencil(struct pipe_context *pctx, struct pipe_surface *dst,
110 unsigned clear_flags, double depth, unsigned stencil,
111 unsigned dstx, unsigned dsty, unsigned width,
112 unsigned height, bool render_condition_enabled)
113 {
114 struct etna_context *ctx = etna_context(pctx);
115
116 /* XXX could fall back to RS when target area is full screen / resolveable
117 * and no TS. */
118 etna_blit_save_state(ctx);
119 util_blitter_clear_depth_stencil(ctx->blitter, dst, clear_flags, depth,
120 stencil, dstx, dsty, width, height);
121 }
122
123 static void
124 etna_resource_copy_region(struct pipe_context *pctx, struct pipe_resource *dst,
125 unsigned dst_level, unsigned dstx, unsigned dsty,
126 unsigned dstz, struct pipe_resource *src,
127 unsigned src_level, const struct pipe_box *src_box)
128 {
129 struct etna_context *ctx = etna_context(pctx);
130
131 /* XXX we can use the RS as a literal copy engine here
132 * the only complexity is tiling; the size of the boxes needs to be aligned
133 * to the tile size
134 * how to handle the case where a resource is copied from/to a non-aligned
135 * position?
136 * from non-aligned: can fall back to rendering-based copy?
137 * to non-aligned: can fall back to rendering-based copy?
138 * XXX this goes wrong when source surface is supertiled.
139 */
140 if (util_blitter_is_copy_supported(ctx->blitter, dst, src)) {
141 etna_blit_save_state(ctx);
142 util_blitter_copy_texture(ctx->blitter, dst, dst_level, dstx, dsty, dstz,
143 src, src_level, src_box);
144 } else {
145 util_resource_copy_region(pctx, dst, dst_level, dstx, dsty, dstz, src,
146 src_level, src_box);
147 }
148 }
149
150 static void
151 etna_flush_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
152 {
153 struct etna_resource *rsc = etna_resource(prsc);
154
155 if (rsc->render) {
156 if (etna_resource_older(rsc, etna_resource(rsc->render))) {
157 etna_copy_resource(pctx, prsc, rsc->render, 0, 0);
158 rsc->seqno = etna_resource(rsc->render)->seqno;
159 }
160 } else if (etna_resource_needs_flush(rsc)) {
161 etna_copy_resource(pctx, prsc, prsc, 0, 0);
162 rsc->flush_seqno = rsc->seqno;
163 }
164 }
165
166 void
167 etna_copy_resource(struct pipe_context *pctx, struct pipe_resource *dst,
168 struct pipe_resource *src, int first_level, int last_level)
169 {
170 struct etna_resource *src_priv = etna_resource(src);
171 struct etna_resource *dst_priv = etna_resource(dst);
172
173 assert(src->format == dst->format);
174 assert(src->array_size == dst->array_size);
175 assert(last_level <= dst->last_level && last_level <= src->last_level);
176
177 struct pipe_blit_info blit = {};
178 blit.mask = util_format_get_mask(dst->format);
179 blit.filter = PIPE_TEX_FILTER_NEAREST;
180 blit.src.resource = src;
181 blit.src.format = src->format;
182 blit.dst.resource = dst;
183 blit.dst.format = dst->format;
184 blit.dst.box.depth = blit.src.box.depth = 1;
185
186 /* Copy each level and each layer */
187 for (int level = first_level; level <= last_level; level++) {
188 blit.src.level = blit.dst.level = level;
189 blit.src.box.width = blit.dst.box.width =
190 MIN2(src_priv->levels[level].padded_width, dst_priv->levels[level].padded_width);
191 blit.src.box.height = blit.dst.box.height =
192 MIN2(src_priv->levels[level].padded_height, dst_priv->levels[level].padded_height);
193 unsigned depth = MIN2(src_priv->levels[level].depth, dst_priv->levels[level].depth);
194 if (dst->array_size > 1) {
195 assert(depth == 1); /* no array of 3d texture */
196 depth = dst->array_size;
197 }
198
199 for (int z = 0; z < depth; z++) {
200 blit.src.box.z = blit.dst.box.z = z;
201 pctx->blit(pctx, &blit);
202 }
203 }
204 }
205
206 void
207 etna_copy_resource_box(struct pipe_context *pctx, struct pipe_resource *dst,
208 struct pipe_resource *src, int level,
209 struct pipe_box *box)
210 {
211 assert(src->format == dst->format);
212 assert(src->array_size == dst->array_size);
213
214 struct pipe_blit_info blit = {};
215 blit.mask = util_format_get_mask(dst->format);
216 blit.filter = PIPE_TEX_FILTER_NEAREST;
217 blit.src.resource = src;
218 blit.src.format = src->format;
219 blit.src.box = *box;
220 blit.dst.resource = dst;
221 blit.dst.format = dst->format;
222 blit.dst.box = *box;
223
224 blit.dst.box.depth = blit.src.box.depth = 1;
225 blit.src.level = blit.dst.level = level;
226
227 for (int z = 0; z < box->depth; z++) {
228 blit.src.box.z = blit.dst.box.z = box->z + z;
229 pctx->blit(pctx, &blit);
230 }
231 }
232
233 void
234 etna_clear_blit_init(struct pipe_context *pctx)
235 {
236 struct etna_context *ctx = etna_context(pctx);
237
238 pctx->clear_render_target = etna_clear_render_target;
239 pctx->clear_depth_stencil = etna_clear_depth_stencil;
240 pctx->resource_copy_region = etna_resource_copy_region;
241 pctx->flush_resource = etna_flush_resource;
242
243 if (ctx->specs.use_blt)
244 etna_clear_blit_blt_init(pctx);
245 else
246 etna_clear_blit_rs_init(pctx);
247 }