blob: 810fed3a96960ba75bc82618dfa73667e914937e [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,
50 unsigned size_z)
Alyssa Rosenzweigc9b164f2019-06-27 08:29:06 -070051{
52 /* First of all, all 6 values are off-by-one (strictly positive).
53 * Account for that, first by ensuring all values are strictly positive
54 * and then by offsetting */
55
56 assert(num_x > 0);
57 assert(num_y > 0);
58 assert(num_z > 0);
59
60 assert(size_x > 0);
61 assert(size_y > 0);
62 assert(size_z > 0);
63
64 num_x = MALI_POSITIVE(num_x);
65 num_y = MALI_POSITIVE(num_y);
66 num_z = MALI_POSITIVE(num_z);
67
68 size_x = MALI_POSITIVE(size_x);
69 size_y = MALI_POSITIVE(size_y);
70 size_z = MALI_POSITIVE(size_z);
71
72 /* Next up is to pack in order */
73
74 uint32_t packed = 0;
75
76 /* The values needing packing, in order, and the corresponding shifts.
77 * Indicies into shift are off-by-one to make the logic easier */
78
79 unsigned shifts[7] = { 0 };
80 unsigned values[6] = { size_x, size_y, size_z, num_x, num_y, num_z };
81
82 for (unsigned i = 0; i < 6; ++i) {
83 /* OR it in, shifting as required */
84 packed |= (values[i] << shifts[i]);
85
86 /* How many bits did we use? */
87 unsigned bit_count = util_logbase2_ceil(values[i] + 1);
88
89 /* Set the next shift accordingly */
90 shifts[i + 1] = shifts[i] + bit_count;
91 }
92
93 /* We're packed, so upload everything */
94 out->invocation_count = packed;
95 out->size_y_shift = shifts[1];
96 out->size_z_shift = shifts[2];
97 out->workgroups_x_shift = shifts[3];
98 out->workgroups_y_shift = shifts[4];
99 out->workgroups_z_shift = shifts[5];
100
101 /* Special fields */
102 out->workgroups_x_shift_2 = MAX2(out->workgroups_x_shift, 2);
103 out->workgroups_x_shift_3 = out->workgroups_x_shift_2;
104}
105
106/* Packs vertex/tiler descriptors simultaneously */
107void
108panfrost_pack_work_groups_fused(
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700109 struct mali_vertex_tiler_prefix *vertex,
110 struct mali_vertex_tiler_prefix *tiler,
111 unsigned num_x,
112 unsigned num_y,
113 unsigned num_z,
114 unsigned size_x,
115 unsigned size_y,
116 unsigned size_z)
Alyssa Rosenzweigc9b164f2019-06-27 08:29:06 -0700117{
118 panfrost_pack_work_groups_compute(vertex, num_x, num_y, num_z, size_x, size_y, size_z);
119
120 /* Copy results over */
121 tiler->invocation_count = vertex->invocation_count;
122 tiler->size_y_shift = vertex->size_y_shift;
123 tiler->size_z_shift = vertex->size_z_shift;
124 tiler->workgroups_x_shift = vertex->workgroups_x_shift;
Alyssa Rosenzweig8d747492019-06-27 14:13:10 -0700125 tiler->workgroups_x_shift_2 = vertex->workgroups_x_shift_2;
Alyssa Rosenzweigc9b164f2019-06-27 08:29:06 -0700126 tiler->workgroups_y_shift = vertex->workgroups_y_shift;
127 tiler->workgroups_z_shift = vertex->workgroups_z_shift;
128
129 /* Set special fields for each */
130 vertex->workgroups_x_shift_3 = 5;
131 tiler->workgroups_x_shift_3 = 6;
132}
133