blob: 0ec7c634a24f4765578c8fd4ecdd339b94d8a177 [file] [log] [blame]
Alyssa Rosenzweigc9b164f2019-06-27 08:29:06 -07001/*
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 Rosenzweig39b226c2019-08-16 13:57:38 -070028#include <assert.h>
29#include "util/u_math.h"
30#include "pan_encoder.h"
Alyssa Rosenzweigc9b164f2019-06-27 08:29:06 -070031
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
42void
43panfrost_pack_work_groups_compute(
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -070044 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 Rosenzweigfb56a162019-08-16 16:21:45 -070050 unsigned size_z,
51 bool quirk_graphics)
Alyssa Rosenzweigc9b164f2019-06-27 08:29:06 -070052{
Alyssa Rosenzweig5386b7e2019-12-12 11:30:20 -050053 /* First of all, all 6 values are off-by-one (strictly positive). */
Alyssa Rosenzweigc9b164f2019-06-27 08:29:06 -070054
55 num_x = MALI_POSITIVE(num_x);
56 num_y = MALI_POSITIVE(num_y);
57 num_z = MALI_POSITIVE(num_z);
58
59 size_x = MALI_POSITIVE(size_x);
60 size_y = MALI_POSITIVE(size_y);
61 size_z = MALI_POSITIVE(size_z);
62
63 /* Next up is to pack in order */
64
65 uint32_t packed = 0;
66
67 /* The values needing packing, in order, and the corresponding shifts.
68 * Indicies into shift are off-by-one to make the logic easier */
69
70 unsigned shifts[7] = { 0 };
71 unsigned values[6] = { size_x, size_y, size_z, num_x, num_y, num_z };
72
73 for (unsigned i = 0; i < 6; ++i) {
74 /* OR it in, shifting as required */
75 packed |= (values[i] << shifts[i]);
76
77 /* How many bits did we use? */
78 unsigned bit_count = util_logbase2_ceil(values[i] + 1);
79
80 /* Set the next shift accordingly */
81 shifts[i + 1] = shifts[i] + bit_count;
82 }
83
Alyssa Rosenzweigfb56a162019-08-16 16:21:45 -070084 /* Quirk: for non-instanced graphics, the blob sets workgroups_z_shift
85 * = 32. This doesn't appear to matter to the hardware, but it's good
86 * to be bit-identical. */
87
88 if (quirk_graphics && (num_z <= 1))
Alyssa Rosenzweig63787972019-12-12 11:28:08 -050089 shifts[5] = 32;
Alyssa Rosenzweigfb56a162019-08-16 16:21:45 -070090
Alyssa Rosenzweig37525662019-08-16 16:31:00 -070091 /* Quirk: for graphics, workgroups_x_shift_2 must be at least 2,
92 * whereas for OpenCL it is simply equal to workgroups_x_shift. For GL
93 * compute, it seems it might *always* be 2, but this is suspicious and
94 * needs further investigation. (I'm probably just using GL wrong). */
95
Alyssa Rosenzweig63787972019-12-12 11:28:08 -050096 unsigned shift_2 = shifts[3];
97
Alyssa Rosenzweig37525662019-08-16 16:31:00 -070098 if (quirk_graphics)
Alyssa Rosenzweig63787972019-12-12 11:28:08 -050099 shift_2 = MAX2(shift_2, 2);
100
101 /* Pack them in */
102 uint32_t packed_shifts =
103 (shifts[1] << 0) |
104 (shifts[2] << 5) |
105 (shifts[3] << 10) |
106 (shifts[4] << 16) |
107 (shifts[5] << 22) |
108 (shift_2 << 28);
109
110 /* Upload the packed bitfields */
111 out->invocation_count = packed;
112 out->invocation_shifts = packed_shifts;
Alyssa Rosenzweig37525662019-08-16 16:31:00 -0700113
114 /* TODO: Compute workgroups_x_shift_3 */
Alyssa Rosenzweig63787972019-12-12 11:28:08 -0500115 out->workgroups_x_shift_3 = shift_2;
Alyssa Rosenzweigc9b164f2019-06-27 08:29:06 -0700116}
117
118/* Packs vertex/tiler descriptors simultaneously */
119void
120panfrost_pack_work_groups_fused(
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700121 struct mali_vertex_tiler_prefix *vertex,
122 struct mali_vertex_tiler_prefix *tiler,
123 unsigned num_x,
124 unsigned num_y,
125 unsigned num_z,
126 unsigned size_x,
127 unsigned size_y,
128 unsigned size_z)
Alyssa Rosenzweigc9b164f2019-06-27 08:29:06 -0700129{
Alyssa Rosenzweigfb56a162019-08-16 16:21:45 -0700130 panfrost_pack_work_groups_compute(vertex, num_x, num_y, num_z, size_x, size_y, size_z, true);
Alyssa Rosenzweigc9b164f2019-06-27 08:29:06 -0700131
132 /* Copy results over */
133 tiler->invocation_count = vertex->invocation_count;
Alyssa Rosenzweig63787972019-12-12 11:28:08 -0500134 tiler->invocation_shifts = vertex->invocation_shifts;
Alyssa Rosenzweigc9b164f2019-06-27 08:29:06 -0700135
136 /* Set special fields for each */
137 vertex->workgroups_x_shift_3 = 5;
138 tiler->workgroups_x_shift_3 = 6;
139}
140