Alyssa Rosenzweig | c9b164f | 2019-06-27 08:29:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 Collabora, Ltd. |
| 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 | * Authors (Collabora): |
| 24 | * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> |
| 25 | * |
| 26 | */ |
| 27 | |
Alyssa Rosenzweig | 39b226c | 2019-08-16 13:57:38 -0700 | [diff] [blame] | 28 | #include <assert.h> |
| 29 | #include "util/u_math.h" |
| 30 | #include "pan_encoder.h" |
Alyssa Rosenzweig | c9b164f | 2019-06-27 08:29:06 -0700 | [diff] [blame] | 31 | |
| 32 | /* Compute shaders are invoked with a gl_NumWorkGroups X/Y/Z triplet. Vertex |
| 33 | * shaders, it turns out, are invoked with the same mechanism, with the triplet |
| 34 | * (1, vertex_count, instance_count). |
| 35 | * |
| 36 | * Alongside this triplet is the gl_WorkGroupSize X/Y/Z triplet. |
| 37 | * |
| 38 | * Unfortunately, the packing for these triplet into the |
| 39 | * mali_vertex_tiler_prefix is a little funky, using a dynamic bitfield. The |
| 40 | * routines here exist to pack this */ |
| 41 | |
| 42 | void |
| 43 | panfrost_pack_work_groups_compute( |
Alyssa Rosenzweig | a2d0ea9 | 2019-07-10 10:10:31 -0700 | [diff] [blame] | 44 | struct mali_vertex_tiler_prefix *out, |
| 45 | unsigned num_x, |
| 46 | unsigned num_y, |
| 47 | unsigned num_z, |
| 48 | unsigned size_x, |
| 49 | unsigned size_y, |
Alyssa Rosenzweig | fb56a16 | 2019-08-16 16:21:45 -0700 | [diff] [blame] | 50 | unsigned size_z, |
| 51 | bool quirk_graphics) |
Alyssa Rosenzweig | c9b164f | 2019-06-27 08:29:06 -0700 | [diff] [blame] | 52 | { |
Alyssa Rosenzweig | c9b164f | 2019-06-27 08:29:06 -0700 | [diff] [blame] | 53 | uint32_t packed = 0; |
| 54 | |
| 55 | /* The values needing packing, in order, and the corresponding shifts. |
| 56 | * Indicies into shift are off-by-one to make the logic easier */ |
| 57 | |
| 58 | unsigned shifts[7] = { 0 }; |
Alyssa Rosenzweig | 9c249d3 | 2019-12-24 22:33:13 -0500 | [diff] [blame^] | 59 | |
| 60 | unsigned values[6] = { |
| 61 | MALI_POSITIVE(size_x), |
| 62 | MALI_POSITIVE(size_y), |
| 63 | MALI_POSITIVE(size_z), |
| 64 | MALI_POSITIVE(num_x), |
| 65 | MALI_POSITIVE(num_y), |
| 66 | MALI_POSITIVE(num_z), |
| 67 | }; |
Alyssa Rosenzweig | c9b164f | 2019-06-27 08:29:06 -0700 | [diff] [blame] | 68 | |
| 69 | for (unsigned i = 0; i < 6; ++i) { |
| 70 | /* OR it in, shifting as required */ |
| 71 | packed |= (values[i] << shifts[i]); |
| 72 | |
| 73 | /* How many bits did we use? */ |
| 74 | unsigned bit_count = util_logbase2_ceil(values[i] + 1); |
| 75 | |
| 76 | /* Set the next shift accordingly */ |
| 77 | shifts[i + 1] = shifts[i] + bit_count; |
| 78 | } |
| 79 | |
Alyssa Rosenzweig | fb56a16 | 2019-08-16 16:21:45 -0700 | [diff] [blame] | 80 | /* Quirk: for non-instanced graphics, the blob sets workgroups_z_shift |
| 81 | * = 32. This doesn't appear to matter to the hardware, but it's good |
| 82 | * to be bit-identical. */ |
| 83 | |
| 84 | if (quirk_graphics && (num_z <= 1)) |
Alyssa Rosenzweig | 6378797 | 2019-12-12 11:28:08 -0500 | [diff] [blame] | 85 | shifts[5] = 32; |
Alyssa Rosenzweig | fb56a16 | 2019-08-16 16:21:45 -0700 | [diff] [blame] | 86 | |
Alyssa Rosenzweig | 3752566 | 2019-08-16 16:31:00 -0700 | [diff] [blame] | 87 | /* Quirk: for graphics, workgroups_x_shift_2 must be at least 2, |
| 88 | * whereas for OpenCL it is simply equal to workgroups_x_shift. For GL |
| 89 | * compute, it seems it might *always* be 2, but this is suspicious and |
| 90 | * needs further investigation. (I'm probably just using GL wrong). */ |
| 91 | |
Alyssa Rosenzweig | 6378797 | 2019-12-12 11:28:08 -0500 | [diff] [blame] | 92 | unsigned shift_2 = shifts[3]; |
| 93 | |
Alyssa Rosenzweig | 3752566 | 2019-08-16 16:31:00 -0700 | [diff] [blame] | 94 | if (quirk_graphics) |
Alyssa Rosenzweig | 6378797 | 2019-12-12 11:28:08 -0500 | [diff] [blame] | 95 | shift_2 = MAX2(shift_2, 2); |
| 96 | |
| 97 | /* Pack them in */ |
| 98 | uint32_t packed_shifts = |
| 99 | (shifts[1] << 0) | |
| 100 | (shifts[2] << 5) | |
| 101 | (shifts[3] << 10) | |
| 102 | (shifts[4] << 16) | |
| 103 | (shifts[5] << 22) | |
| 104 | (shift_2 << 28); |
| 105 | |
| 106 | /* Upload the packed bitfields */ |
| 107 | out->invocation_count = packed; |
| 108 | out->invocation_shifts = packed_shifts; |
Alyssa Rosenzweig | 3752566 | 2019-08-16 16:31:00 -0700 | [diff] [blame] | 109 | |
| 110 | /* TODO: Compute workgroups_x_shift_3 */ |
Alyssa Rosenzweig | 6378797 | 2019-12-12 11:28:08 -0500 | [diff] [blame] | 111 | out->workgroups_x_shift_3 = shift_2; |
Alyssa Rosenzweig | c9b164f | 2019-06-27 08:29:06 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /* Packs vertex/tiler descriptors simultaneously */ |
| 115 | void |
| 116 | panfrost_pack_work_groups_fused( |
Alyssa Rosenzweig | a2d0ea9 | 2019-07-10 10:10:31 -0700 | [diff] [blame] | 117 | struct mali_vertex_tiler_prefix *vertex, |
| 118 | struct mali_vertex_tiler_prefix *tiler, |
| 119 | unsigned num_x, |
| 120 | unsigned num_y, |
| 121 | unsigned num_z, |
| 122 | unsigned size_x, |
| 123 | unsigned size_y, |
| 124 | unsigned size_z) |
Alyssa Rosenzweig | c9b164f | 2019-06-27 08:29:06 -0700 | [diff] [blame] | 125 | { |
Alyssa Rosenzweig | fb56a16 | 2019-08-16 16:21:45 -0700 | [diff] [blame] | 126 | panfrost_pack_work_groups_compute(vertex, num_x, num_y, num_z, size_x, size_y, size_z, true); |
Alyssa Rosenzweig | c9b164f | 2019-06-27 08:29:06 -0700 | [diff] [blame] | 127 | |
| 128 | /* Copy results over */ |
| 129 | tiler->invocation_count = vertex->invocation_count; |
Alyssa Rosenzweig | 6378797 | 2019-12-12 11:28:08 -0500 | [diff] [blame] | 130 | tiler->invocation_shifts = vertex->invocation_shifts; |
Alyssa Rosenzweig | c9b164f | 2019-06-27 08:29:06 -0700 | [diff] [blame] | 131 | |
| 132 | /* Set special fields for each */ |
| 133 | vertex->workgroups_x_shift_3 = 5; |
| 134 | tiler->workgroups_x_shift_3 = 6; |
| 135 | } |
| 136 | |