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 <tomeu.vizoso@collabora.com>
26 *   Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
27 *
28 */
29
30#include "pan_context.h"
31#include "pan_util.h"
32#include "util/format/u_format.h"
33
34static void
35panfrost_blitter_save(
36        struct panfrost_context *ctx,
37        struct blitter_context *blitter,
38        bool render_cond)
39{
40
41        util_blitter_save_vertex_buffer_slot(blitter, ctx->vertex_buffers);
42        util_blitter_save_vertex_elements(blitter, ctx->vertex);
43        util_blitter_save_vertex_shader(blitter, ctx->shader[PIPE_SHADER_VERTEX]);
44        util_blitter_save_rasterizer(blitter, ctx->rasterizer);
45        util_blitter_save_viewport(blitter, &ctx->pipe_viewport);
46        util_blitter_save_scissor(blitter, &ctx->scissor);
47        util_blitter_save_fragment_shader(blitter, ctx->shader[PIPE_SHADER_FRAGMENT]);
48        util_blitter_save_blend(blitter, ctx->blend);
49        util_blitter_save_depth_stencil_alpha(blitter, ctx->depth_stencil);
50        util_blitter_save_stencil_ref(blitter, &ctx->stencil_ref);
51        util_blitter_save_so_targets(blitter, 0, NULL);
52        util_blitter_save_sample_mask(blitter, ctx->sample_mask);
53
54        util_blitter_save_framebuffer(blitter, &ctx->pipe_framebuffer);
55        util_blitter_save_fragment_sampler_states(blitter,
56                        ctx->sampler_count[PIPE_SHADER_FRAGMENT],
57                        (void **)(&ctx->samplers[PIPE_SHADER_FRAGMENT]));
58        util_blitter_save_fragment_sampler_views(blitter,
59                        ctx->sampler_view_count[PIPE_SHADER_FRAGMENT],
60                        (struct pipe_sampler_view **)&ctx->sampler_views[PIPE_SHADER_FRAGMENT]);
61        util_blitter_save_fragment_constant_buffer_slot(blitter,
62                        ctx->constant_buffer[PIPE_SHADER_FRAGMENT].cb);
63
64        if (!render_cond) {
65                util_blitter_save_render_condition(blitter,
66                                (struct pipe_query *) ctx->cond_query,
67                                ctx->cond_cond, ctx->cond_mode);
68        }
69
70}
71
72void
73panfrost_blit(struct pipe_context *pipe,
74              const struct pipe_blit_info *info)
75{
76        struct panfrost_context *ctx = pan_context(pipe);
77
78        if (info->render_condition_enable &&
79            !panfrost_render_condition_check(ctx))
80                return;
81
82        if (!util_blitter_is_blit_supported(ctx->blitter, info))
83                unreachable("Unsupported blit\n");
84
85        panfrost_blitter_save(ctx, ctx->blitter, info->render_condition_enable);
86        util_blitter_blit(ctx->blitter, info);
87}
88