Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 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 |
Alyssa Rosenzweig | d47f090 | 2019-03-12 22:01:23 +0000 | [diff] [blame] | 39 | panfrost_sfbd_clear( |
Alyssa Rosenzweig | a2d0ea9 | 2019-07-10 10:10:31 -0700 | [diff] [blame^] | 40 | struct panfrost_job *job, |
| 41 | struct mali_single_framebuffer *sfbd) |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 42 | { |
| 43 | struct panfrost_context *ctx = job->ctx; |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 44 | |
| 45 | if (job->clear & PIPE_CLEAR_COLOR) { |
Alyssa Rosenzweig | 8e4e467 | 2019-07-01 11:49:06 -0700 | [diff] [blame] | 46 | sfbd->clear_color_1 = job->clear_color[0][0]; |
| 47 | sfbd->clear_color_2 = job->clear_color[0][1]; |
| 48 | sfbd->clear_color_3 = job->clear_color[0][2]; |
| 49 | sfbd->clear_color_4 = job->clear_color[0][3]; |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | if (job->clear & PIPE_CLEAR_DEPTH) { |
| 53 | sfbd->clear_depth_1 = job->clear_depth; |
| 54 | sfbd->clear_depth_2 = job->clear_depth; |
| 55 | sfbd->clear_depth_3 = job->clear_depth; |
| 56 | sfbd->clear_depth_4 = job->clear_depth; |
| 57 | |
Boris Brezillon | 3557746 | 2019-07-02 13:50:44 +0200 | [diff] [blame] | 58 | sfbd->depth_buffer = ctx->depth_stencil_buffer.bo->gpu; |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 59 | sfbd->depth_buffer_enable = MALI_DEPTH_STENCIL_ENABLE; |
| 60 | } |
| 61 | |
| 62 | if (job->clear & PIPE_CLEAR_STENCIL) { |
| 63 | sfbd->clear_stencil = job->clear_stencil; |
| 64 | |
Boris Brezillon | 3557746 | 2019-07-02 13:50:44 +0200 | [diff] [blame] | 65 | sfbd->stencil_buffer = ctx->depth_stencil_buffer.bo->gpu; |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 66 | sfbd->stencil_buffer_enable = MALI_DEPTH_STENCIL_ENABLE; |
| 67 | } |
| 68 | |
| 69 | /* Set flags based on what has been cleared, for the SFBD case */ |
| 70 | /* XXX: What do these flags mean? */ |
| 71 | int clear_flags = 0x101100; |
| 72 | |
| 73 | if (!(job->clear & ~(PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL))) { |
| 74 | /* On a tiler like this, it's fastest to clear all three buffers at once */ |
| 75 | |
| 76 | clear_flags |= MALI_CLEAR_FAST; |
| 77 | } else { |
| 78 | clear_flags |= MALI_CLEAR_SLOW; |
| 79 | |
| 80 | if (job->clear & PIPE_CLEAR_STENCIL) |
| 81 | clear_flags |= MALI_CLEAR_SLOW_STENCIL; |
| 82 | } |
| 83 | |
| 84 | sfbd->clear_flags = clear_flags; |
| 85 | } |
| 86 | |
| 87 | static void |
| 88 | panfrost_sfbd_set_cbuf( |
Alyssa Rosenzweig | a2d0ea9 | 2019-07-10 10:10:31 -0700 | [diff] [blame^] | 89 | struct mali_single_framebuffer *fb, |
| 90 | struct pipe_surface *surf) |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 91 | { |
| 92 | struct panfrost_resource *rsrc = pan_resource(surf->texture); |
| 93 | |
Boris Brezillon | aa5bc35 | 2019-07-02 11:37:40 +0200 | [diff] [blame] | 94 | signed stride = rsrc->slices[0].stride; |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 95 | |
Alyssa Rosenzweig | d47f090 | 2019-03-12 22:01:23 +0000 | [diff] [blame] | 96 | fb->format = panfrost_sfbd_format(surf); |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 97 | |
Boris Brezillon | aa5bc35 | 2019-07-02 11:37:40 +0200 | [diff] [blame] | 98 | if (rsrc->layout == PAN_LINEAR) { |
Alyssa Rosenzweig | 2adf35e | 2019-05-23 03:01:32 +0000 | [diff] [blame] | 99 | fb->framebuffer = rsrc->bo->gpu; |
Alyssa Rosenzweig | d47f090 | 2019-03-12 22:01:23 +0000 | [diff] [blame] | 100 | fb->stride = stride; |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 101 | } else { |
| 102 | fprintf(stderr, "Invalid render layout\n"); |
| 103 | assert(0); |
| 104 | } |
| 105 | } |
| 106 | |
Alyssa Rosenzweig | d47f090 | 2019-03-12 22:01:23 +0000 | [diff] [blame] | 107 | /* Creates an SFBD for the FRAGMENT section of the bound framebuffer */ |
| 108 | |
| 109 | mali_ptr |
Alyssa Rosenzweig | f9ecca2 | 2019-06-14 11:23:24 -0700 | [diff] [blame] | 110 | panfrost_sfbd_fragment(struct panfrost_context *ctx, bool has_draws) |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 111 | { |
Alyssa Rosenzweig | d47f090 | 2019-03-12 22:01:23 +0000 | [diff] [blame] | 112 | struct panfrost_job *job = panfrost_get_job_for_fbo(ctx); |
Alyssa Rosenzweig | f9ecca2 | 2019-06-14 11:23:24 -0700 | [diff] [blame] | 113 | struct mali_single_framebuffer fb = panfrost_emit_sfbd(ctx, has_draws); |
Alyssa Rosenzweig | d47f090 | 2019-03-12 22:01:23 +0000 | [diff] [blame] | 114 | |
| 115 | panfrost_sfbd_clear(job, &fb); |
| 116 | |
| 117 | /* SFBD does not support MRT natively; sanity check */ |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 118 | assert(ctx->pipe_framebuffer.nr_cbufs == 1); |
Alyssa Rosenzweig | 2adf35e | 2019-05-23 03:01:32 +0000 | [diff] [blame] | 119 | panfrost_sfbd_set_cbuf(&fb, ctx->pipe_framebuffer.cbufs[0]); |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 120 | |
| 121 | if (ctx->pipe_framebuffer.zsbuf) { |
| 122 | /* TODO */ |
| 123 | } |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 124 | |
Alyssa Rosenzweig | 8c26890 | 2019-03-12 23:16:37 +0000 | [diff] [blame] | 125 | if (job->requirements & PAN_REQ_MSAA) |
Alyssa Rosenzweig | d47f090 | 2019-03-12 22:01:23 +0000 | [diff] [blame] | 126 | fb.format |= MALI_FRAMEBUFFER_MSAA_A | MALI_FRAMEBUFFER_MSAA_B; |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 127 | |
Alyssa Rosenzweig | d47f090 | 2019-03-12 22:01:23 +0000 | [diff] [blame] | 128 | return panfrost_upload_transient(ctx, &fb, sizeof(fb)) | MALI_SFBD; |
Alyssa Rosenzweig | 9dd84db | 2019-03-12 03:32:17 +0000 | [diff] [blame] | 129 | } |