iris: Make an iris_genx_protos.h header for prototypes.
[mesa.git] / src / gallium / drivers / panfrost / pan_sfbd.c
1 /*
2 * Copyright 2018-2019 Alyssa Rosenzweig
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, sublicense,
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 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 NONINFRINGEMENT. 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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 */
24
25 #include "pan_context.h"
26 #include "pan_util.h"
27 #include "pan_format.h"
28
29 #include "util/u_format.h"
30
31 static unsigned
32 panfrost_sfbd_format(struct pipe_surface *surf)
33 {
34 /* TODO */
35 return 0xb84e0281; /* RGB32, no MSAA */
36 }
37
38 static void
39 panfrost_sfbd_clear(
40 struct panfrost_job *job,
41 struct mali_single_framebuffer *sfbd)
42 {
43 if (job->clear & PIPE_CLEAR_COLOR) {
44 sfbd->clear_color_1 = job->clear_color[0][0];
45 sfbd->clear_color_2 = job->clear_color[0][1];
46 sfbd->clear_color_3 = job->clear_color[0][2];
47 sfbd->clear_color_4 = job->clear_color[0][3];
48 }
49
50 if (job->clear & PIPE_CLEAR_DEPTH) {
51 sfbd->clear_depth_1 = job->clear_depth;
52 sfbd->clear_depth_2 = job->clear_depth;
53 sfbd->clear_depth_3 = job->clear_depth;
54 sfbd->clear_depth_4 = job->clear_depth;
55 }
56
57 if (job->clear & PIPE_CLEAR_STENCIL) {
58 sfbd->clear_stencil = job->clear_stencil;
59 }
60
61 /* Set flags based on what has been cleared, for the SFBD case */
62 /* XXX: What do these flags mean? */
63 int clear_flags = 0x101100;
64
65 if (!(job->clear & ~(PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL))) {
66 /* On a tiler like this, it's fastest to clear all three buffers at once */
67
68 clear_flags |= MALI_CLEAR_FAST;
69 } else {
70 clear_flags |= MALI_CLEAR_SLOW;
71
72 if (job->clear & PIPE_CLEAR_STENCIL)
73 clear_flags |= MALI_CLEAR_SLOW_STENCIL;
74 }
75
76 sfbd->clear_flags = clear_flags;
77 }
78
79 static void
80 panfrost_sfbd_set_cbuf(
81 struct mali_single_framebuffer *fb,
82 struct pipe_surface *surf)
83 {
84 struct panfrost_resource *rsrc = pan_resource(surf->texture);
85
86 unsigned level = surf->u.tex.level;
87 assert(surf->u.tex.first_layer == 0);
88
89 fb->format = panfrost_sfbd_format(surf);
90
91 unsigned offset = rsrc->slices[level].offset;
92 signed stride = rsrc->slices[level].stride;
93
94 if (rsrc->layout == PAN_LINEAR) {
95 fb->framebuffer = rsrc->bo->gpu + offset;
96 fb->stride = stride;
97 } else {
98 fprintf(stderr, "Invalid render layout\n");
99 assert(0);
100 }
101 }
102
103 static void
104 panfrost_sfbd_set_zsbuf(
105 struct mali_single_framebuffer *fb,
106 struct pipe_surface *surf)
107 {
108 struct panfrost_resource *rsrc = pan_resource(surf->texture);
109
110 unsigned level = surf->u.tex.level;
111 assert(surf->u.tex.first_layer == 0);
112
113 unsigned offset = rsrc->slices[level].offset;
114
115 if (rsrc->layout == PAN_LINEAR) {
116 /* TODO: What about format selection? */
117 /* TODO: Z/S stride selection? */
118
119 fb->depth_buffer = rsrc->bo->gpu + offset;
120 fb->depth_buffer_enable = MALI_DEPTH_STENCIL_ENABLE;
121
122 fb->stencil_buffer = rsrc->bo->gpu + offset;
123 fb->stencil_buffer_enable = MALI_DEPTH_STENCIL_ENABLE;
124 } else {
125 fprintf(stderr, "Invalid render layout\n");
126 assert(0);
127 }
128 }
129
130 /* Creates an SFBD for the FRAGMENT section of the bound framebuffer */
131
132 mali_ptr
133 panfrost_sfbd_fragment(struct panfrost_context *ctx, bool has_draws)
134 {
135 struct panfrost_job *job = panfrost_get_job_for_fbo(ctx);
136 struct mali_single_framebuffer fb = panfrost_emit_sfbd(ctx, has_draws);
137
138 panfrost_sfbd_clear(job, &fb);
139
140 /* SFBD does not support MRT natively; sanity check */
141 assert(ctx->pipe_framebuffer.nr_cbufs == 1);
142 panfrost_sfbd_set_cbuf(&fb, ctx->pipe_framebuffer.cbufs[0]);
143
144 if (ctx->pipe_framebuffer.zsbuf)
145 panfrost_sfbd_set_zsbuf(&fb, ctx->pipe_framebuffer.zsbuf);
146
147 if (job->requirements & PAN_REQ_MSAA)
148 fb.format |= MALI_FRAMEBUFFER_MSAA_A | MALI_FRAMEBUFFER_MSAA_B;
149
150 return panfrost_upload_transient(ctx, &fb, sizeof(fb)) | MALI_SFBD;
151 }