panfrost: Call util_blitter_save_fragment_constant_buffer_slot
[mesa.git] / src / gallium / drivers / panfrost / pan_blit.c
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
34 static void
35 panfrost_blitter_save(
36 struct panfrost_context *ctx,
37 struct blitter_context *blitter)
38 {
39
40 util_blitter_save_vertex_buffer_slot(blitter, ctx->vertex_buffers);
41 util_blitter_save_vertex_elements(blitter, ctx->vertex);
42 util_blitter_save_vertex_shader(blitter, ctx->shader[PIPE_SHADER_VERTEX]);
43 util_blitter_save_rasterizer(blitter, ctx->rasterizer);
44 util_blitter_save_viewport(blitter, &ctx->pipe_viewport);
45 util_blitter_save_scissor(blitter, &ctx->scissor);
46 util_blitter_save_fragment_shader(blitter, ctx->shader[PIPE_SHADER_FRAGMENT]);
47 util_blitter_save_blend(blitter, ctx->blend);
48 util_blitter_save_depth_stencil_alpha(blitter, ctx->depth_stencil);
49 util_blitter_save_stencil_ref(blitter, &ctx->stencil_ref);
50 util_blitter_save_so_targets(blitter, 0, NULL);
51 util_blitter_save_sample_mask(blitter, ctx->sample_mask);
52
53 util_blitter_save_framebuffer(blitter, &ctx->pipe_framebuffer);
54 util_blitter_save_fragment_sampler_states(blitter,
55 ctx->sampler_count[PIPE_SHADER_FRAGMENT],
56 (void **)(&ctx->samplers[PIPE_SHADER_FRAGMENT]));
57 util_blitter_save_fragment_sampler_views(blitter,
58 ctx->sampler_view_count[PIPE_SHADER_FRAGMENT],
59 (struct pipe_sampler_view **)&ctx->sampler_views[PIPE_SHADER_FRAGMENT]);
60 util_blitter_save_fragment_constant_buffer_slot(blitter,
61 ctx->constant_buffer[PIPE_SHADER_FRAGMENT].cb);
62 }
63
64 static bool
65 panfrost_u_blitter_blit(struct pipe_context *pipe,
66 const struct pipe_blit_info *info)
67 {
68 struct panfrost_context *ctx = pan_context(pipe);
69 struct panfrost_device *dev = pan_device(pipe->screen);
70
71 if (!util_blitter_is_blit_supported(ctx->blitter, info)) {
72 if (dev->debug & PAN_DBG_MSGS) {
73 fprintf(stderr, "blit unsupported %s -> %s\n",
74 util_format_short_name(info->src.resource->format),
75 util_format_short_name(info->dst.resource->format));
76 }
77
78 return false;
79 }
80
81 /* TODO: Scissor */
82
83 panfrost_blitter_save(ctx, ctx->blitter);
84 util_blitter_blit(ctx->blitter, info);
85
86 return true;
87 }
88
89 void
90 panfrost_blit(struct pipe_context *pipe,
91 const struct pipe_blit_info *info)
92 {
93 /* We don't have a hardware blit, so we just fake it with
94 * u_blitter. We could do a little better by culling
95 * vertex jobs, though. */
96
97 if (panfrost_u_blitter_blit(pipe, info))
98 return;
99
100 return;
101 }
102
103 /* Blits a framebuffer to "itself". Mali is a tiler, so the
104 * framebuffer is implicitly cleared every frame, so if there is
105 * no actual glClear(), we have to blit it back ourselves.
106 */
107
108 void
109 panfrost_blit_wallpaper(struct panfrost_context *ctx, struct pipe_box *box)
110 {
111 struct panfrost_batch *batch = ctx->wallpaper_batch;
112 struct pipe_blit_info binfo = {0};
113
114 panfrost_blitter_save(ctx, ctx->blitter_wallpaper);
115
116 struct pipe_surface *surf = batch->key.cbufs[0];
117 unsigned level = surf->u.tex.level;
118 unsigned layer = surf->u.tex.first_layer;
119 assert(surf->u.tex.last_layer == layer);
120
121 binfo.src.resource = binfo.dst.resource = batch->key.cbufs[0]->texture;
122 binfo.src.level = binfo.dst.level = level;
123 binfo.src.box.x = binfo.dst.box.x = box->x;
124 binfo.src.box.y = binfo.dst.box.y = box->y;
125 binfo.src.box.z = binfo.dst.box.z = layer;
126 binfo.src.box.width = binfo.dst.box.width = box->width;
127 binfo.src.box.height = binfo.dst.box.height = box->height;
128 binfo.src.box.depth = binfo.dst.box.depth = 1;
129
130 binfo.src.format = binfo.dst.format = batch->key.cbufs[0]->format;
131
132 assert(batch->key.nr_cbufs == 1);
133 binfo.mask = PIPE_MASK_RGBA;
134 binfo.filter = PIPE_TEX_FILTER_LINEAR;
135 binfo.scissor_enable = FALSE;
136
137 util_blitter_blit(ctx->blitter_wallpaper, &binfo);
138 }
139