1 /*
2 * Copyright (C) 2014 Broadcom
3 * Copyright (C) 2019 Collabora, Ltd.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 * Authors (Collabora):
25 * Tomeu Vizoso <[email protected]>
26 * Alyssa Rosenzweig <[email protected]>
27 *
28 */
29
30 #include "util/format/u_format.h"
31 #include "pan_context.h"
32 #include "pan_resource.h"
33 #include "pan_util.h"
34
35 void
panfrost_blitter_save(struct panfrost_context * ctx,const enum panfrost_blitter_op blitter_op)36 panfrost_blitter_save(struct panfrost_context *ctx,
37 const enum panfrost_blitter_op blitter_op)
38 {
39 struct blitter_context *blitter = ctx->blitter;
40
41 util_blitter_save_vertex_buffers(blitter, ctx->vertex_buffers,
42 util_last_bit(ctx->vb_mask));
43 util_blitter_save_vertex_elements(blitter, ctx->vertex);
44 util_blitter_save_vertex_shader(blitter,
45 ctx->uncompiled[PIPE_SHADER_VERTEX]);
46 util_blitter_save_rasterizer(blitter, ctx->rasterizer);
47 util_blitter_save_viewport(blitter, &ctx->pipe_viewport);
48 util_blitter_save_so_targets(blitter, 0, NULL);
49
50 if (blitter_op & PAN_SAVE_FRAGMENT_STATE) {
51 if (blitter_op & PAN_SAVE_FRAGMENT_CONSTANT)
52 util_blitter_save_fragment_constant_buffer_slot(
53 blitter, ctx->constant_buffer[PIPE_SHADER_FRAGMENT].cb);
54
55 util_blitter_save_blend(blitter, ctx->blend);
56 util_blitter_save_depth_stencil_alpha(blitter, ctx->depth_stencil);
57 util_blitter_save_stencil_ref(blitter, &ctx->stencil_ref);
58 util_blitter_save_fragment_shader(blitter,
59 ctx->uncompiled[PIPE_SHADER_FRAGMENT]);
60 util_blitter_save_sample_mask(blitter, ctx->sample_mask,
61 ctx->min_samples);
62 util_blitter_save_scissor(blitter, &ctx->scissor);
63 }
64
65 if (blitter_op & PAN_SAVE_FRAMEBUFFER)
66 util_blitter_save_framebuffer(blitter, &ctx->pipe_framebuffer);
67
68 if (blitter_op & PAN_SAVE_TEXTURES) {
69 util_blitter_save_fragment_sampler_states(
70 blitter, ctx->sampler_count[PIPE_SHADER_FRAGMENT],
71 (void **)(&ctx->samplers[PIPE_SHADER_FRAGMENT]));
72 util_blitter_save_fragment_sampler_views(
73 blitter, ctx->sampler_view_count[PIPE_SHADER_FRAGMENT],
74 (struct pipe_sampler_view **)&ctx->sampler_views[PIPE_SHADER_FRAGMENT]);
75 }
76
77 if (!(blitter_op & PAN_DISABLE_RENDER_COND)) {
78 util_blitter_save_render_condition(blitter,
79 (struct pipe_query *)ctx->cond_query,
80 ctx->cond_cond, ctx->cond_mode);
81 }
82 }
83
84 void
panfrost_blit_no_afbc_legalization(struct pipe_context * pipe,const struct pipe_blit_info * info)85 panfrost_blit_no_afbc_legalization(struct pipe_context *pipe,
86 const struct pipe_blit_info *info)
87 {
88 struct panfrost_context *ctx = pan_context(pipe);
89
90 panfrost_blitter_save(ctx, info->render_condition_enable
91 ? PAN_RENDER_BLIT_COND
92 : PAN_RENDER_BLIT);
93 util_blitter_blit(ctx->blitter, info, NULL);
94 }
95
96 void
panfrost_blit(struct pipe_context * pipe,const struct pipe_blit_info * info)97 panfrost_blit(struct pipe_context *pipe, const struct pipe_blit_info *info)
98 {
99 struct panfrost_context *ctx = pan_context(pipe);
100
101 if (info->render_condition_enable && !panfrost_render_condition_check(ctx))
102 return;
103
104 if (!util_blitter_is_blit_supported(ctx->blitter, info))
105 unreachable("Unsupported blit\n");
106
107 /* Legalize here because it could trigger a recursive blit otherwise */
108 struct panfrost_resource *src = pan_resource(info->src.resource);
109 enum pipe_format src_view_format = util_format_linear(info->src.format);
110 pan_legalize_format(ctx, src, src_view_format, false, false);
111
112 struct panfrost_resource *dst = pan_resource(info->dst.resource);
113 enum pipe_format dst_view_format = util_format_linear(info->dst.format);
114 pan_legalize_format(ctx, dst, dst_view_format, true, false);
115
116 panfrost_blit_no_afbc_legalization(pipe, info);
117 }
118