2 * Copyright (C) 2019 Collabora, Ltd.
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:
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
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
23 * Authors (Collabora):
24 * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
28 #include "pan_context.h"
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).
34 * Alongside this triplet is the gl_WorkGroupSize X/Y/Z triplet.
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 */
41 panfrost_pack_work_groups_compute(
42 struct mali_vertex_tiler_prefix
*out
,
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 */
62 num_x
= MALI_POSITIVE(num_x
);
63 num_y
= MALI_POSITIVE(num_y
);
64 num_z
= MALI_POSITIVE(num_z
);
66 size_x
= MALI_POSITIVE(size_x
);
67 size_y
= MALI_POSITIVE(size_y
);
68 size_z
= MALI_POSITIVE(size_z
);
70 /* Next up is to pack in order */
74 /* The values needing packing, in order, and the corresponding shifts.
75 * Indicies into shift are off-by-one to make the logic easier */
77 unsigned shifts
[7] = { 0 };
78 unsigned values
[6] = { size_x
, size_y
, size_z
, num_x
, num_y
, num_z
};
80 for (unsigned i
= 0; i
< 6; ++i
) {
81 /* OR it in, shifting as required */
82 packed
|= (values
[i
] << shifts
[i
]);
84 /* How many bits did we use? */
85 unsigned bit_count
= util_logbase2_ceil(values
[i
] + 1);
87 /* Set the next shift accordingly */
88 shifts
[i
+ 1] = shifts
[i
] + bit_count
;
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];
100 out
->workgroups_x_shift_2
= MAX2(out
->workgroups_x_shift
, 2);
101 out
->workgroups_x_shift_3
= out
->workgroups_x_shift_2
;
104 /* Packs vertex/tiler descriptors simultaneously */
106 panfrost_pack_work_groups_fused(
107 struct mali_vertex_tiler_prefix
*vertex
,
108 struct mali_vertex_tiler_prefix
*tiler
,
116 panfrost_pack_work_groups_compute(vertex
, num_x
, num_y
, num_z
, size_x
, size_y
, size_z
);
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
;
123 tiler
->workgroups_x_shift_2
= vertex
->workgroups_x_shift_2
;
124 tiler
->workgroups_y_shift
= vertex
->workgroups_y_shift
;
125 tiler
->workgroups_z_shift
= vertex
->workgroups_z_shift
;
127 /* Set special fields for each */
128 vertex
->workgroups_x_shift_3
= 5;
129 tiler
->workgroups_x_shift_3
= 6;