Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/intel/common/intel_urb_config.c
4547 views
1
/*
2
* Copyright (c) 2011 Intel Corporation
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
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
* IN THE SOFTWARE.
22
*/
23
24
#include <stdlib.h>
25
#include <math.h>
26
27
#include "util/macros.h"
28
#include "main/macros.h"
29
#include "compiler/shader_enums.h"
30
31
#include "intel_l3_config.h"
32
33
/**
34
* The following diagram shows how we partition the URB:
35
*
36
* 16kb or 32kb Rest of the URB space
37
* __________-__________ _________________-_________________
38
* / \ / \
39
* +-------------------------------------------------------------+
40
* | VS/HS/DS/GS/FS Push | VS/HS/DS/GS URB |
41
* | Constants | Entries |
42
* +-------------------------------------------------------------+
43
*
44
* Push constants must be stored at the beginning of the URB space,
45
* while URB entries can be stored anywhere. We choose to lay them
46
* out in pipeline order (VS -> HS -> DS -> GS).
47
*/
48
49
/**
50
* Decide how to partition the URB among the various stages.
51
*
52
* \param[in] push_constant_bytes - space allocate for push constants.
53
* \param[in] urb_size_bytes - total size of the URB (from L3 config).
54
* \param[in] tess_present - are tessellation shaders active?
55
* \param[in] gs_present - are geometry shaders active?
56
* \param[in] entry_size - the URB entry size (from the shader compiler)
57
* \param[out] entries - the number of URB entries for each stage
58
* \param[out] start - the starting offset for each stage
59
* \param[out] deref_block_size - deref block size for 3DSTATE_SF
60
* \param[out] constrained - true if we wanted more space than we had
61
*/
62
void
63
intel_get_urb_config(const struct intel_device_info *devinfo,
64
const struct intel_l3_config *l3_cfg,
65
bool tess_present, bool gs_present,
66
const unsigned entry_size[4],
67
unsigned entries[4], unsigned start[4],
68
enum intel_urb_deref_block_size *deref_block_size,
69
bool *constrained)
70
{
71
unsigned urb_size_kB = intel_get_l3_config_urb_size(devinfo, l3_cfg);
72
73
/* RCU_MODE register for Gfx12+ in BSpec says:
74
*
75
* "HW reserves 4KB of URB space per bank for Compute Engine out of the
76
* total storage available in L3. SW must consider that 4KB of storage
77
* per bank will be reduced from what is programmed for the URB space
78
* in L3 for Render Engine executed workloads.
79
*
80
* Example: When URB space programmed is 64KB (per bank) for Render
81
* Engine, the actual URB space available for operation is only 60KB
82
* (per bank). Similarly when URB space programmed is 128KB (per bank)
83
* for render engine, the actual URB space available for operation is
84
* only 124KB (per bank). More detailed descripton available in "L3
85
* Cache" section of the B-Spec."
86
*/
87
if (devinfo->ver >= 12)
88
urb_size_kB -= 4 * devinfo->l3_banks;
89
90
const unsigned push_constant_kB =
91
(devinfo->ver >= 8 || (devinfo->is_haswell && devinfo->gt == 3)) ? 32 : 16;
92
93
const bool active[4] = { true, tess_present, tess_present, gs_present };
94
95
/* URB allocations must be done in 8k chunks. */
96
const unsigned chunk_size_kB = 8;
97
const unsigned chunk_size_bytes = chunk_size_kB * 1024;
98
99
const unsigned push_constant_chunks = push_constant_kB / chunk_size_kB;
100
const unsigned urb_chunks = urb_size_kB / chunk_size_kB;
101
102
/* From p35 of the Ivy Bridge PRM (section 1.7.1: 3DSTATE_URB_GS):
103
*
104
* VS Number of URB Entries must be divisible by 8 if the VS URB Entry
105
* Allocation Size is less than 9 512-bit URB entries.
106
*
107
* Similar text exists for HS, DS and GS.
108
*/
109
unsigned granularity[4];
110
for (int i = MESA_SHADER_VERTEX; i <= MESA_SHADER_GEOMETRY; i++) {
111
granularity[i] = (entry_size[i] < 9) ? 8 : 1;
112
}
113
114
unsigned min_entries[4] = {
115
/* VS has a lower limit on the number of URB entries.
116
*
117
* From the Broadwell PRM, 3DSTATE_URB_VS instruction:
118
* "When tessellation is enabled, the VS Number of URB Entries must be
119
* greater than or equal to 192."
120
*/
121
[MESA_SHADER_VERTEX] = tess_present && devinfo->ver == 8 ?
122
192 : devinfo->urb.min_entries[MESA_SHADER_VERTEX],
123
124
/* There are two constraints on the minimum amount of URB space we can
125
* allocate:
126
*
127
* (1) We need room for at least 2 URB entries, since we always operate
128
* the GS in DUAL_OBJECT mode.
129
*
130
* (2) We can't allocate less than nr_gs_entries_granularity.
131
*/
132
[MESA_SHADER_GEOMETRY] = gs_present ? 2 : 0,
133
134
[MESA_SHADER_TESS_CTRL] = tess_present ? 1 : 0,
135
136
[MESA_SHADER_TESS_EVAL] = tess_present ?
137
devinfo->urb.min_entries[MESA_SHADER_TESS_EVAL] : 0,
138
};
139
140
/* Min VS Entries isn't a multiple of 8 on Cherryview/Broxton; round up.
141
* Round them all up.
142
*/
143
for (int i = MESA_SHADER_VERTEX; i <= MESA_SHADER_GEOMETRY; i++) {
144
min_entries[i] = ALIGN(min_entries[i], granularity[i]);
145
}
146
147
unsigned entry_size_bytes[4];
148
for (int i = MESA_SHADER_VERTEX; i <= MESA_SHADER_GEOMETRY; i++) {
149
entry_size_bytes[i] = 64 * entry_size[i];
150
}
151
152
/* Initially, assign each stage the minimum amount of URB space it needs,
153
* and make a note of how much additional space it "wants" (the amount of
154
* additional space it could actually make use of).
155
*/
156
unsigned chunks[4];
157
unsigned wants[4];
158
unsigned total_needs = push_constant_chunks;
159
unsigned total_wants = 0;
160
161
for (int i = MESA_SHADER_VERTEX; i <= MESA_SHADER_GEOMETRY; i++) {
162
if (active[i]) {
163
chunks[i] = DIV_ROUND_UP(min_entries[i] * entry_size_bytes[i],
164
chunk_size_bytes);
165
166
wants[i] =
167
DIV_ROUND_UP(devinfo->urb.max_entries[i] * entry_size_bytes[i],
168
chunk_size_bytes) - chunks[i];
169
} else {
170
chunks[i] = 0;
171
wants[i] = 0;
172
}
173
174
total_needs += chunks[i];
175
total_wants += wants[i];
176
}
177
178
assert(total_needs <= urb_chunks);
179
180
*constrained = total_needs + total_wants > urb_chunks;
181
182
/* Mete out remaining space (if any) in proportion to "wants". */
183
unsigned remaining_space = MIN2(urb_chunks - total_needs, total_wants);
184
185
if (remaining_space > 0) {
186
for (int i = MESA_SHADER_VERTEX;
187
total_wants > 0 && i <= MESA_SHADER_TESS_EVAL; i++) {
188
unsigned additional = (unsigned)
189
roundf(wants[i] * (((float) remaining_space) / total_wants));
190
chunks[i] += additional;
191
remaining_space -= additional;
192
total_wants -= wants[i];
193
}
194
195
chunks[MESA_SHADER_GEOMETRY] += remaining_space;
196
}
197
198
/* Sanity check that we haven't over-allocated. */
199
unsigned total_chunks = push_constant_chunks;
200
for (int i = MESA_SHADER_VERTEX; i <= MESA_SHADER_GEOMETRY; i++) {
201
total_chunks += chunks[i];
202
}
203
assert(total_chunks <= urb_chunks);
204
205
/* Finally, compute the number of entries that can fit in the space
206
* allocated to each stage.
207
*/
208
for (int i = MESA_SHADER_VERTEX; i <= MESA_SHADER_GEOMETRY; i++) {
209
entries[i] = chunks[i] * chunk_size_bytes / entry_size_bytes[i];
210
211
/* Since we rounded up when computing wants[], this may be slightly
212
* more than the maximum allowed amount, so correct for that.
213
*/
214
entries[i] = MIN2(entries[i], devinfo->urb.max_entries[i]);
215
216
/* Ensure that we program a multiple of the granularity. */
217
entries[i] = ROUND_DOWN_TO(entries[i], granularity[i]);
218
219
/* Finally, sanity check to make sure we have at least the minimum
220
* number of entries needed for each stage.
221
*/
222
assert(entries[i] >= min_entries[i]);
223
}
224
225
/* Lay out the URB in pipeline order: push constants, VS, HS, DS, GS. */
226
int next = push_constant_chunks;
227
for (int i = MESA_SHADER_VERTEX; i <= MESA_SHADER_GEOMETRY; i++) {
228
if (entries[i]) {
229
start[i] = next;
230
next += chunks[i];
231
} else {
232
/* Just put disabled stages at the beginning. */
233
start[i] = 0;
234
}
235
}
236
237
if (deref_block_size) {
238
if (devinfo->ver >= 12) {
239
/* From the Gfx12 BSpec:
240
*
241
* "Deref Block size depends on the last enabled shader and number
242
* of handles programmed for that shader
243
*
244
* 1) For GS last shader enabled cases, the deref block is
245
* always set to a per poly(within hardware)
246
*
247
* If the last enabled shader is VS or DS.
248
*
249
* 1) If DS is last enabled shader then if the number of DS
250
* handles is less than 324, need to set per poly deref.
251
*
252
* 2) If VS is last enabled shader then if the number of VS
253
* handles is less than 192, need to set per poly deref"
254
*
255
* The default is 32 so we assume that's the right choice if we're
256
* not in one of the explicit cases listed above.
257
*/
258
if (gs_present) {
259
*deref_block_size = INTEL_URB_DEREF_BLOCK_SIZE_PER_POLY;
260
} else if (tess_present) {
261
if (entries[MESA_SHADER_TESS_EVAL] < 324)
262
*deref_block_size = INTEL_URB_DEREF_BLOCK_SIZE_PER_POLY;
263
else
264
*deref_block_size = INTEL_URB_DEREF_BLOCK_SIZE_32;
265
} else {
266
if (entries[MESA_SHADER_VERTEX] < 192)
267
*deref_block_size = INTEL_URB_DEREF_BLOCK_SIZE_PER_POLY;
268
else
269
*deref_block_size = INTEL_URB_DEREF_BLOCK_SIZE_32;
270
}
271
} else {
272
*deref_block_size = 0;
273
}
274
}
275
}
276
277