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 | |
| 28 | #include "pan_context.h" |
| 29 | |
| 30 | /* Compute shaders are invoked with a gl_NumWorkGroups X/Y/Z triplet. Vertex |
| 31 | * shaders, it turns out, are invoked with the same mechanism, with the triplet |
| 32 | * (1, vertex_count, instance_count). |
| 33 | * |
| 34 | * Alongside this triplet is the gl_WorkGroupSize X/Y/Z triplet. |
| 35 | * |
| 36 | * Unfortunately, the packing for these triplet into the |
| 37 | * mali_vertex_tiler_prefix is a little funky, using a dynamic bitfield. The |
| 38 | * routines here exist to pack this */ |
| 39 | |
| 40 | void |
| 41 | panfrost_pack_work_groups_compute( |
| 42 | struct mali_vertex_tiler_prefix *out, |
| 43 | unsigned num_x, |
| 44 | unsigned num_y, |
| 45 | unsigned num_z, |
| 46 | unsigned size_x, |
| 47 | unsigned size_y, |
| 48 | unsigned size_z) |
| 49 | { |
| 50 | /* First of all, all 6 values are off-by-one (strictly positive). |
| 51 | * Account for that, first by ensuring all values are strictly positive |
| 52 | * and then by offsetting */ |
| 53 | |
| 54 | assert(num_x > 0); |
| 55 | assert(num_y > 0); |
| 56 | assert(num_z > 0); |
| 57 | |
| 58 | assert(size_x > 0); |
| 59 | assert(size_y > 0); |
| 60 | assert(size_z > 0); |
| 61 | |
| 62 | num_x = MALI_POSITIVE(num_x); |
| 63 | num_y = MALI_POSITIVE(num_y); |
| 64 | num_z = MALI_POSITIVE(num_z); |
| 65 | |
| 66 | size_x = MALI_POSITIVE(size_x); |
| 67 | size_y = MALI_POSITIVE(size_y); |
| 68 | size_z = MALI_POSITIVE(size_z); |
| 69 | |
| 70 | /* Next up is to pack in order */ |
| 71 | |
| 72 | uint32_t packed = 0; |
| 73 | |
| 74 | /* The values needing packing, in order, and the corresponding shifts. |
| 75 | * Indicies into shift are off-by-one to make the logic easier */ |
| 76 | |
| 77 | unsigned shifts[7] = { 0 }; |
| 78 | unsigned values[6] = { size_x, size_y, size_z, num_x, num_y, num_z }; |
| 79 | |
| 80 | for (unsigned i = 0; i < 6; ++i) { |
| 81 | /* OR it in, shifting as required */ |
| 82 | packed |= (values[i] << shifts[i]); |
| 83 | |
| 84 | /* How many bits did we use? */ |
| 85 | unsigned bit_count = util_logbase2_ceil(values[i] + 1); |
| 86 | |
| 87 | /* Set the next shift accordingly */ |
| 88 | shifts[i + 1] = shifts[i] + bit_count; |
| 89 | } |
| 90 | |
| 91 | /* We're packed, so upload everything */ |
| 92 | out->invocation_count = packed; |
| 93 | out->size_y_shift = shifts[1]; |
| 94 | out->size_z_shift = shifts[2]; |
| 95 | out->workgroups_x_shift = shifts[3]; |
| 96 | out->workgroups_y_shift = shifts[4]; |
| 97 | out->workgroups_z_shift = shifts[5]; |
| 98 | |
| 99 | /* Special fields */ |
| 100 | out->workgroups_x_shift_2 = MAX2(out->workgroups_x_shift, 2); |
| 101 | out->workgroups_x_shift_3 = out->workgroups_x_shift_2; |
| 102 | } |
| 103 | |
| 104 | /* Packs vertex/tiler descriptors simultaneously */ |
| 105 | void |
| 106 | panfrost_pack_work_groups_fused( |
| 107 | struct mali_vertex_tiler_prefix *vertex, |
| 108 | struct mali_vertex_tiler_prefix *tiler, |
| 109 | unsigned num_x, |
| 110 | unsigned num_y, |
| 111 | unsigned num_z, |
| 112 | unsigned size_x, |
| 113 | unsigned size_y, |
| 114 | unsigned size_z) |
| 115 | { |
| 116 | panfrost_pack_work_groups_compute(vertex, num_x, num_y, num_z, size_x, size_y, size_z); |
| 117 | |
| 118 | /* Copy results over */ |
| 119 | tiler->invocation_count = vertex->invocation_count; |
| 120 | tiler->size_y_shift = vertex->size_y_shift; |
| 121 | tiler->size_z_shift = vertex->size_z_shift; |
| 122 | tiler->workgroups_x_shift = vertex->workgroups_x_shift; |
Alyssa Rosenzweig | 8d74749 | 2019-06-27 14:13:10 -0700 | [diff] [blame] | 123 | tiler->workgroups_x_shift_2 = vertex->workgroups_x_shift_2; |
Alyssa Rosenzweig | c9b164f | 2019-06-27 08:29:06 -0700 | [diff] [blame] | 124 | tiler->workgroups_y_shift = vertex->workgroups_y_shift; |
| 125 | tiler->workgroups_z_shift = vertex->workgroups_z_shift; |
| 126 | |
| 127 | /* Set special fields for each */ |
| 128 | vertex->workgroups_x_shift_3 = 5; |
| 129 | tiler->workgroups_x_shift_3 = 6; |
| 130 | } |
| 131 | |