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