Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/freedreno/ir3/ir3_a4xx.c
4565 views
1
/*
2
* Copyright (C) 2017-2018 Rob Clark <[email protected]>
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:
24
* Rob Clark <[email protected]>
25
*/
26
27
#define GPU 400
28
29
#include "ir3_context.h"
30
#include "ir3_image.h"
31
32
/*
33
* Handlers for instructions changed/added in a4xx:
34
*/
35
36
/* src[] = { buffer_index, offset }. No const_index */
37
static void
38
emit_intrinsic_load_ssbo(struct ir3_context *ctx, nir_intrinsic_instr *intr,
39
struct ir3_instruction **dst)
40
{
41
struct ir3_block *b = ctx->block;
42
struct ir3_instruction *ldgb, *src0, *src1, *byte_offset, *offset;
43
44
struct ir3_instruction *ssbo = ir3_ssbo_to_ibo(ctx, intr->src[0]);
45
46
byte_offset = ir3_get_src(ctx, &intr->src[1])[0];
47
offset = ir3_get_src(ctx, &intr->src[2])[0];
48
49
/* src0 is uvec2(offset*4, 0), src1 is offset.. nir already *= 4: */
50
src0 = ir3_collect(ctx, byte_offset, create_immed(b, 0));
51
src1 = offset;
52
53
ldgb = ir3_LDGB(b, ssbo, 0, src0, 0, src1, 0);
54
ldgb->dsts[0]->wrmask = MASK(intr->num_components);
55
ldgb->cat6.iim_val = intr->num_components;
56
ldgb->cat6.d = 4;
57
ldgb->cat6.type = TYPE_U32;
58
ldgb->barrier_class = IR3_BARRIER_BUFFER_R;
59
ldgb->barrier_conflict = IR3_BARRIER_BUFFER_W;
60
61
ir3_split_dest(b, dst, ldgb, 0, intr->num_components);
62
}
63
64
/* src[] = { value, block_index, offset }. const_index[] = { write_mask } */
65
static void
66
emit_intrinsic_store_ssbo(struct ir3_context *ctx, nir_intrinsic_instr *intr)
67
{
68
struct ir3_block *b = ctx->block;
69
struct ir3_instruction *stgb, *src0, *src1, *src2, *byte_offset, *offset;
70
unsigned wrmask = nir_intrinsic_write_mask(intr);
71
unsigned ncomp = ffs(~wrmask) - 1;
72
73
assert(wrmask == BITFIELD_MASK(intr->num_components));
74
75
struct ir3_instruction *ssbo = ir3_ssbo_to_ibo(ctx, intr->src[1]);
76
77
byte_offset = ir3_get_src(ctx, &intr->src[2])[0];
78
offset = ir3_get_src(ctx, &intr->src[3])[0];
79
80
/* src0 is value, src1 is offset, src2 is uvec2(offset*4, 0)..
81
* nir already *= 4:
82
*/
83
src0 = ir3_create_collect(ctx, ir3_get_src(ctx, &intr->src[0]), ncomp);
84
src1 = offset;
85
src2 = ir3_collect(ctx, byte_offset, create_immed(b, 0));
86
87
stgb = ir3_STGB(b, ssbo, 0, src0, 0, src1, 0, src2, 0);
88
stgb->cat6.iim_val = ncomp;
89
stgb->cat6.d = 4;
90
stgb->cat6.type = TYPE_U32;
91
stgb->barrier_class = IR3_BARRIER_BUFFER_W;
92
stgb->barrier_conflict = IR3_BARRIER_BUFFER_R | IR3_BARRIER_BUFFER_W;
93
94
array_insert(b, b->keeps, stgb);
95
}
96
97
/*
98
* SSBO atomic intrinsics
99
*
100
* All of the SSBO atomic memory operations read a value from memory,
101
* compute a new value using one of the operations below, write the new
102
* value to memory, and return the original value read.
103
*
104
* All operations take 3 sources except CompSwap that takes 4. These
105
* sources represent:
106
*
107
* 0: The SSBO buffer index.
108
* 1: The offset into the SSBO buffer of the variable that the atomic
109
* operation will operate on.
110
* 2: The data parameter to the atomic function (i.e. the value to add
111
* in ssbo_atomic_add, etc).
112
* 3: For CompSwap only: the second data parameter.
113
*/
114
static struct ir3_instruction *
115
emit_intrinsic_atomic_ssbo(struct ir3_context *ctx, nir_intrinsic_instr *intr)
116
{
117
struct ir3_block *b = ctx->block;
118
struct ir3_instruction *atomic, *ssbo, *src0, *src1, *src2, *byte_offset,
119
*offset;
120
type_t type = TYPE_U32;
121
122
ssbo = ir3_ssbo_to_ibo(ctx, intr->src[0]);
123
124
byte_offset = ir3_get_src(ctx, &intr->src[1])[0];
125
offset = ir3_get_src(ctx, &intr->src[3])[0];
126
127
/* src0 is data (or uvec2(data, compare))
128
* src1 is offset
129
* src2 is uvec2(offset*4, 0) (appears to be 64b byte offset)
130
*
131
* Note that nir already multiplies the offset by four
132
*/
133
src0 = ir3_get_src(ctx, &intr->src[2])[0];
134
src1 = offset;
135
src2 = ir3_collect(ctx, byte_offset, create_immed(b, 0));
136
137
switch (intr->intrinsic) {
138
case nir_intrinsic_ssbo_atomic_add_ir3:
139
atomic = ir3_ATOMIC_ADD_G(b, ssbo, 0, src0, 0, src1, 0, src2, 0);
140
break;
141
case nir_intrinsic_ssbo_atomic_imin_ir3:
142
atomic = ir3_ATOMIC_MIN_G(b, ssbo, 0, src0, 0, src1, 0, src2, 0);
143
type = TYPE_S32;
144
break;
145
case nir_intrinsic_ssbo_atomic_umin_ir3:
146
atomic = ir3_ATOMIC_MIN_G(b, ssbo, 0, src0, 0, src1, 0, src2, 0);
147
break;
148
case nir_intrinsic_ssbo_atomic_imax_ir3:
149
atomic = ir3_ATOMIC_MAX_G(b, ssbo, 0, src0, 0, src1, 0, src2, 0);
150
type = TYPE_S32;
151
break;
152
case nir_intrinsic_ssbo_atomic_umax_ir3:
153
atomic = ir3_ATOMIC_MAX_G(b, ssbo, 0, src0, 0, src1, 0, src2, 0);
154
break;
155
case nir_intrinsic_ssbo_atomic_and_ir3:
156
atomic = ir3_ATOMIC_AND_G(b, ssbo, 0, src0, 0, src1, 0, src2, 0);
157
break;
158
case nir_intrinsic_ssbo_atomic_or_ir3:
159
atomic = ir3_ATOMIC_OR_G(b, ssbo, 0, src0, 0, src1, 0, src2, 0);
160
break;
161
case nir_intrinsic_ssbo_atomic_xor_ir3:
162
atomic = ir3_ATOMIC_XOR_G(b, ssbo, 0, src0, 0, src1, 0, src2, 0);
163
break;
164
case nir_intrinsic_ssbo_atomic_exchange_ir3:
165
atomic = ir3_ATOMIC_XCHG_G(b, ssbo, 0, src0, 0, src1, 0, src2, 0);
166
break;
167
case nir_intrinsic_ssbo_atomic_comp_swap_ir3:
168
/* for cmpxchg, src0 is [ui]vec2(data, compare): */
169
src0 = ir3_collect(ctx, ir3_get_src(ctx, &intr->src[3])[0], src0);
170
src1 = ir3_get_src(ctx, &intr->src[4])[0];
171
atomic = ir3_ATOMIC_CMPXCHG_G(b, ssbo, 0, src0, 0, src1, 0, src2, 0);
172
break;
173
default:
174
unreachable("boo");
175
}
176
177
atomic->cat6.iim_val = 1;
178
atomic->cat6.d = 4;
179
atomic->cat6.type = type;
180
atomic->barrier_class = IR3_BARRIER_BUFFER_W;
181
atomic->barrier_conflict = IR3_BARRIER_BUFFER_R | IR3_BARRIER_BUFFER_W;
182
183
/* even if nothing consume the result, we can't DCE the instruction: */
184
array_insert(b, b->keeps, atomic);
185
186
return atomic;
187
}
188
189
static struct ir3_instruction *
190
get_image_offset(struct ir3_context *ctx, const nir_intrinsic_instr *instr,
191
struct ir3_instruction *const *coords, bool byteoff)
192
{
193
struct ir3_block *b = ctx->block;
194
struct ir3_instruction *offset;
195
unsigned index = nir_src_as_uint(instr->src[0]);
196
unsigned ncoords = ir3_get_image_coords(instr, NULL);
197
198
/* to calculate the byte offset (yes, uggg) we need (up to) three
199
* const values to know the bytes per pixel, and y and z stride:
200
*/
201
const struct ir3_const_state *const_state = ir3_const_state(ctx->so);
202
unsigned cb = regid(const_state->offsets.image_dims, 0) +
203
const_state->image_dims.off[index];
204
205
debug_assert(const_state->image_dims.mask & (1 << index));
206
207
/* offset = coords.x * bytes_per_pixel: */
208
offset = ir3_MUL_S24(b, coords[0], 0, create_uniform(b, cb + 0), 0);
209
if (ncoords > 1) {
210
/* offset += coords.y * y_pitch: */
211
offset =
212
ir3_MAD_S24(b, create_uniform(b, cb + 1), 0, coords[1], 0, offset, 0);
213
}
214
if (ncoords > 2) {
215
/* offset += coords.z * z_pitch: */
216
offset =
217
ir3_MAD_S24(b, create_uniform(b, cb + 2), 0, coords[2], 0, offset, 0);
218
}
219
220
if (!byteoff) {
221
/* Some cases, like atomics, seem to use dword offset instead
222
* of byte offsets.. blob just puts an extra shr.b in there
223
* in those cases:
224
*/
225
offset = ir3_SHR_B(b, offset, 0, create_immed(b, 2), 0);
226
}
227
228
return ir3_collect(ctx, offset, create_immed(b, 0));
229
}
230
231
/* src[] = { index, coord, sample_index, value }. const_index[] = {} */
232
static void
233
emit_intrinsic_store_image(struct ir3_context *ctx, nir_intrinsic_instr *intr)
234
{
235
struct ir3_block *b = ctx->block;
236
struct ir3_instruction *stib, *offset;
237
struct ir3_instruction *const *value = ir3_get_src(ctx, &intr->src[3]);
238
struct ir3_instruction *const *coords = ir3_get_src(ctx, &intr->src[1]);
239
struct ir3_instruction *ibo = ir3_image_to_ibo(ctx, intr->src[0]);
240
unsigned ncoords = ir3_get_image_coords(intr, NULL);
241
unsigned ncomp =
242
ir3_get_num_components_for_image_format(nir_intrinsic_format(intr));
243
244
/* src0 is value
245
* src1 is coords
246
* src2 is 64b byte offset
247
*/
248
249
offset = get_image_offset(ctx, intr, coords, true);
250
251
/* NOTE: stib seems to take byte offset, but stgb.typed can be used
252
* too and takes a dword offset.. not quite sure yet why blob uses
253
* one over the other in various cases.
254
*/
255
256
stib = ir3_STIB(b, ibo, 0, ir3_create_collect(ctx, value, ncomp), 0,
257
ir3_create_collect(ctx, coords, ncoords), 0, offset, 0);
258
stib->cat6.iim_val = ncomp;
259
stib->cat6.d = ncoords;
260
stib->cat6.type = ir3_get_type_for_image_intrinsic(intr);
261
stib->cat6.typed = true;
262
stib->barrier_class = IR3_BARRIER_IMAGE_W;
263
stib->barrier_conflict = IR3_BARRIER_IMAGE_R | IR3_BARRIER_IMAGE_W;
264
265
array_insert(b, b->keeps, stib);
266
}
267
268
/* src[] = { deref, coord, sample_index, value, compare }. const_index[] = {} */
269
static struct ir3_instruction *
270
emit_intrinsic_atomic_image(struct ir3_context *ctx, nir_intrinsic_instr *intr)
271
{
272
struct ir3_block *b = ctx->block;
273
struct ir3_instruction *atomic, *src0, *src1, *src2;
274
struct ir3_instruction *const *coords = ir3_get_src(ctx, &intr->src[1]);
275
struct ir3_instruction *image = ir3_image_to_ibo(ctx, intr->src[0]);
276
unsigned ncoords = ir3_get_image_coords(intr, NULL);
277
278
/* src0 is value (or uvec2(value, compare))
279
* src1 is coords
280
* src2 is 64b byte offset
281
*/
282
src0 = ir3_get_src(ctx, &intr->src[3])[0];
283
src1 = ir3_create_collect(ctx, coords, ncoords);
284
src2 = get_image_offset(ctx, intr, coords, false);
285
286
switch (intr->intrinsic) {
287
case nir_intrinsic_image_atomic_add:
288
atomic = ir3_ATOMIC_ADD_G(b, image, 0, src0, 0, src1, 0, src2, 0);
289
break;
290
case nir_intrinsic_image_atomic_imin:
291
case nir_intrinsic_image_atomic_umin:
292
atomic = ir3_ATOMIC_MIN_G(b, image, 0, src0, 0, src1, 0, src2, 0);
293
break;
294
case nir_intrinsic_image_atomic_imax:
295
case nir_intrinsic_image_atomic_umax:
296
atomic = ir3_ATOMIC_MAX_G(b, image, 0, src0, 0, src1, 0, src2, 0);
297
break;
298
case nir_intrinsic_image_atomic_and:
299
atomic = ir3_ATOMIC_AND_G(b, image, 0, src0, 0, src1, 0, src2, 0);
300
break;
301
case nir_intrinsic_image_atomic_or:
302
atomic = ir3_ATOMIC_OR_G(b, image, 0, src0, 0, src1, 0, src2, 0);
303
break;
304
case nir_intrinsic_image_atomic_xor:
305
atomic = ir3_ATOMIC_XOR_G(b, image, 0, src0, 0, src1, 0, src2, 0);
306
break;
307
case nir_intrinsic_image_atomic_exchange:
308
atomic = ir3_ATOMIC_XCHG_G(b, image, 0, src0, 0, src1, 0, src2, 0);
309
break;
310
case nir_intrinsic_image_atomic_comp_swap:
311
/* for cmpxchg, src0 is [ui]vec2(data, compare): */
312
src0 = ir3_collect(ctx, ir3_get_src(ctx, &intr->src[4])[0], src0);
313
atomic = ir3_ATOMIC_CMPXCHG_G(b, image, 0, src0, 0, src1, 0, src2, 0);
314
break;
315
default:
316
unreachable("boo");
317
}
318
319
atomic->cat6.iim_val = 1;
320
atomic->cat6.d = ncoords;
321
atomic->cat6.type = ir3_get_type_for_image_intrinsic(intr);
322
atomic->cat6.typed = true;
323
atomic->barrier_class = IR3_BARRIER_IMAGE_W;
324
atomic->barrier_conflict = IR3_BARRIER_IMAGE_R | IR3_BARRIER_IMAGE_W;
325
326
/* even if nothing consume the result, we can't DCE the instruction: */
327
array_insert(b, b->keeps, atomic);
328
329
return atomic;
330
}
331
332
const struct ir3_context_funcs ir3_a4xx_funcs = {
333
.emit_intrinsic_load_ssbo = emit_intrinsic_load_ssbo,
334
.emit_intrinsic_store_ssbo = emit_intrinsic_store_ssbo,
335
.emit_intrinsic_atomic_ssbo = emit_intrinsic_atomic_ssbo,
336
.emit_intrinsic_store_image = emit_intrinsic_store_image,
337
.emit_intrinsic_atomic_image = emit_intrinsic_atomic_image,
338
.emit_intrinsic_image_size = emit_intrinsic_image_size_tex,
339
.emit_intrinsic_load_global_ir3 = NULL,
340
.emit_intrinsic_store_global_ir3 = NULL,
341
};
342
343