2 * Copyright 2018-2019 Alyssa Rosenzweig
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:
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
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
26 #include "pan_context.h"
28 #include "pan_format.h"
30 #include "util/u_format.h"
33 panfrost_sfbd_format(struct pipe_surface
*surf
)
36 return 0xb84e0281; /* RGB32, no MSAA */
41 struct panfrost_batch
*batch
,
42 struct mali_single_framebuffer
*sfbd
)
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];
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
;
58 if (batch
->clear
& PIPE_CLEAR_STENCIL
) {
59 sfbd
->clear_stencil
= batch
->clear_stencil
;
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;
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 */
69 clear_flags
|= MALI_CLEAR_FAST
;
71 clear_flags
|= MALI_CLEAR_SLOW
;
73 if (batch
->clear
& PIPE_CLEAR_STENCIL
)
74 clear_flags
|= MALI_CLEAR_SLOW_STENCIL
;
77 sfbd
->clear_flags
= clear_flags
;
81 panfrost_sfbd_set_cbuf(
82 struct mali_single_framebuffer
*fb
,
83 struct pipe_surface
*surf
)
85 struct panfrost_resource
*rsrc
= pan_resource(surf
->texture
);
87 unsigned level
= surf
->u
.tex
.level
;
88 assert(surf
->u
.tex
.first_layer
== 0);
90 fb
->format
= panfrost_sfbd_format(surf
);
92 unsigned offset
= rsrc
->slices
[level
].offset
;
93 signed stride
= rsrc
->slices
[level
].stride
;
95 if (rsrc
->layout
== PAN_LINEAR
) {
96 fb
->framebuffer
= rsrc
->bo
->gpu
+ offset
;
99 fprintf(stderr
, "Invalid render layout\n");
105 panfrost_sfbd_set_zsbuf(
106 struct mali_single_framebuffer
*fb
,
107 struct pipe_surface
*surf
)
109 struct panfrost_resource
*rsrc
= pan_resource(surf
->texture
);
111 unsigned level
= surf
->u
.tex
.level
;
112 assert(surf
->u
.tex
.first_layer
== 0);
114 unsigned offset
= rsrc
->slices
[level
].offset
;
116 if (rsrc
->layout
== PAN_LINEAR
) {
117 /* TODO: What about format selection? */
118 /* TODO: Z/S stride selection? */
120 fb
->depth_buffer
= rsrc
->bo
->gpu
+ offset
;
121 fb
->depth_buffer_enable
= MALI_DEPTH_STENCIL_ENABLE
;
123 fb
->stencil_buffer
= rsrc
->bo
->gpu
+ offset
;
124 fb
->stencil_buffer_enable
= MALI_DEPTH_STENCIL_ENABLE
;
126 fprintf(stderr
, "Invalid render layout\n");
131 /* Creates an SFBD for the FRAGMENT section of the bound framebuffer */
134 panfrost_sfbd_fragment(struct panfrost_batch
*batch
, bool has_draws
)
136 struct mali_single_framebuffer fb
= panfrost_emit_sfbd(batch
, has_draws
);
138 panfrost_sfbd_clear(batch
, &fb
);
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]);
144 if (batch
->key
.zsbuf
)
145 panfrost_sfbd_set_zsbuf(&fb
, batch
->key
.zsbuf
);
147 if (batch
->requirements
& PAN_REQ_MSAA
)
148 fb
.format
|= MALI_FRAMEBUFFER_MSAA_A
| MALI_FRAMEBUFFER_MSAA_B
;
150 return panfrost_upload_transient(batch
, &fb
, sizeof(fb
)) | MALI_SFBD
;