Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/broadcom/compiler/v3d_compiler.h
4564 views
1
/*
2
* Copyright © 2016 Broadcom
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
#ifndef V3D_COMPILER_H
25
#define V3D_COMPILER_H
26
27
#include <assert.h>
28
#include <stdio.h>
29
#include <stdlib.h>
30
#include <stdbool.h>
31
#include <stdint.h>
32
#include <string.h>
33
34
#include "util/macros.h"
35
#include "common/v3d_debug.h"
36
#include "common/v3d_device_info.h"
37
#include "common/v3d_limits.h"
38
#include "compiler/nir/nir.h"
39
#include "util/list.h"
40
#include "util/u_math.h"
41
42
#include "qpu/qpu_instr.h"
43
#include "pipe/p_state.h"
44
45
/**
46
* Maximum number of outstanding TMU operations we can queue for execution.
47
*
48
* This is mostly limited by the size of the TMU fifos. The Input and Config
49
* fifos can stall, but we prefer that than injecting TMU flushes manually
50
* in the driver, so we can ignore these, but we can't overflow the Output fifo,
51
* which has 16 / threads per-thread entries, meaning that the maximum number
52
* of outstanding LDTMUs we can ever have is 8, for a 2-way threaded shader.
53
* This means that at most we can have 8 outstanding TMU loads, if each load
54
* is just one component.
55
*
56
* NOTE: we could actually have a larger value here because TMU stores don't
57
* consume any entries in the Output fifo (so we could have any number of
58
* outstanding stores) and the driver keeps track of used Output fifo entries
59
* and will flush if we ever needs more than 8, but since loads are much more
60
* common than stores, it is probably not worth it.
61
*/
62
#define MAX_TMU_QUEUE_SIZE 8
63
64
/**
65
* Maximum offset distance in bytes between two consecutive constant UBO loads
66
* for the same UBO where we would favor updating the unifa address by emitting
67
* dummy ldunifa instructions to avoid writing the unifa register.
68
*/
69
#define MAX_UNIFA_SKIP_DISTANCE 16
70
71
struct nir_builder;
72
73
struct v3d_fs_inputs {
74
/**
75
* Array of the meanings of the VPM inputs this shader needs.
76
*
77
* It doesn't include those that aren't part of the VPM, like
78
* point/line coordinates.
79
*/
80
struct v3d_varying_slot *input_slots;
81
uint32_t num_inputs;
82
};
83
84
enum qfile {
85
/** An unused source or destination register. */
86
QFILE_NULL,
87
88
/** A physical register, such as the W coordinate payload. */
89
QFILE_REG,
90
/** One of the regsiters for fixed function interactions. */
91
QFILE_MAGIC,
92
93
/**
94
* A virtual register, that will be allocated to actual accumulator
95
* or physical registers later.
96
*/
97
QFILE_TEMP,
98
99
/**
100
* VPM reads use this with an index value to say what part of the VPM
101
* is being read.
102
*/
103
QFILE_VPM,
104
105
/**
106
* Stores an immediate value in the index field that will be used
107
* directly by qpu_load_imm().
108
*/
109
QFILE_LOAD_IMM,
110
111
/**
112
* Stores an immediate value in the index field that can be turned
113
* into a small immediate field by qpu_encode_small_immediate().
114
*/
115
QFILE_SMALL_IMM,
116
};
117
118
/**
119
* A reference to a QPU register or a virtual temp register.
120
*/
121
struct qreg {
122
enum qfile file;
123
uint32_t index;
124
};
125
126
static inline struct qreg vir_reg(enum qfile file, uint32_t index)
127
{
128
return (struct qreg){file, index};
129
}
130
131
static inline struct qreg vir_magic_reg(uint32_t index)
132
{
133
return (struct qreg){QFILE_MAGIC, index};
134
}
135
136
static inline struct qreg vir_nop_reg(void)
137
{
138
return (struct qreg){QFILE_NULL, 0};
139
}
140
141
/**
142
* A reference to an actual register at the QPU level, for register
143
* allocation.
144
*/
145
struct qpu_reg {
146
bool magic;
147
bool smimm;
148
int index;
149
};
150
151
struct qinst {
152
/** Entry in qblock->instructions */
153
struct list_head link;
154
155
/**
156
* The instruction being wrapped. Its condition codes, pack flags,
157
* signals, etc. will all be used, with just the register references
158
* being replaced by the contents of qinst->dst and qinst->src[].
159
*/
160
struct v3d_qpu_instr qpu;
161
162
/* Pre-register-allocation references to src/dst registers */
163
struct qreg dst;
164
struct qreg src[3];
165
bool is_last_thrsw;
166
167
/* If the instruction reads a uniform (other than through src[i].file
168
* == QFILE_UNIF), that uniform's index in c->uniform_contents. ~0
169
* otherwise.
170
*/
171
int uniform;
172
};
173
174
enum quniform_contents {
175
/**
176
* Indicates that a constant 32-bit value is copied from the program's
177
* uniform contents.
178
*/
179
QUNIFORM_CONSTANT,
180
/**
181
* Indicates that the program's uniform contents are used as an index
182
* into the GL uniform storage.
183
*/
184
QUNIFORM_UNIFORM,
185
186
/** @{
187
* Scaling factors from clip coordinates to relative to the viewport
188
* center.
189
*
190
* This is used by the coordinate and vertex shaders to produce the
191
* 32-bit entry consisting of 2 16-bit fields with 12.4 signed fixed
192
* point offsets from the viewport ccenter.
193
*/
194
QUNIFORM_VIEWPORT_X_SCALE,
195
QUNIFORM_VIEWPORT_Y_SCALE,
196
/** @} */
197
198
QUNIFORM_VIEWPORT_Z_OFFSET,
199
QUNIFORM_VIEWPORT_Z_SCALE,
200
201
QUNIFORM_USER_CLIP_PLANE,
202
203
/**
204
* A reference to a V3D 3.x texture config parameter 0 uniform.
205
*
206
* This is a uniform implicitly loaded with a QPU_W_TMU* write, which
207
* defines texture type, miplevels, and such. It will be found as a
208
* parameter to the first QOP_TEX_[STRB] instruction in a sequence.
209
*/
210
QUNIFORM_TEXTURE_CONFIG_P0_0,
211
QUNIFORM_TEXTURE_CONFIG_P0_1,
212
QUNIFORM_TEXTURE_CONFIG_P0_2,
213
QUNIFORM_TEXTURE_CONFIG_P0_3,
214
QUNIFORM_TEXTURE_CONFIG_P0_4,
215
QUNIFORM_TEXTURE_CONFIG_P0_5,
216
QUNIFORM_TEXTURE_CONFIG_P0_6,
217
QUNIFORM_TEXTURE_CONFIG_P0_7,
218
QUNIFORM_TEXTURE_CONFIG_P0_8,
219
QUNIFORM_TEXTURE_CONFIG_P0_9,
220
QUNIFORM_TEXTURE_CONFIG_P0_10,
221
QUNIFORM_TEXTURE_CONFIG_P0_11,
222
QUNIFORM_TEXTURE_CONFIG_P0_12,
223
QUNIFORM_TEXTURE_CONFIG_P0_13,
224
QUNIFORM_TEXTURE_CONFIG_P0_14,
225
QUNIFORM_TEXTURE_CONFIG_P0_15,
226
QUNIFORM_TEXTURE_CONFIG_P0_16,
227
QUNIFORM_TEXTURE_CONFIG_P0_17,
228
QUNIFORM_TEXTURE_CONFIG_P0_18,
229
QUNIFORM_TEXTURE_CONFIG_P0_19,
230
QUNIFORM_TEXTURE_CONFIG_P0_20,
231
QUNIFORM_TEXTURE_CONFIG_P0_21,
232
QUNIFORM_TEXTURE_CONFIG_P0_22,
233
QUNIFORM_TEXTURE_CONFIG_P0_23,
234
QUNIFORM_TEXTURE_CONFIG_P0_24,
235
QUNIFORM_TEXTURE_CONFIG_P0_25,
236
QUNIFORM_TEXTURE_CONFIG_P0_26,
237
QUNIFORM_TEXTURE_CONFIG_P0_27,
238
QUNIFORM_TEXTURE_CONFIG_P0_28,
239
QUNIFORM_TEXTURE_CONFIG_P0_29,
240
QUNIFORM_TEXTURE_CONFIG_P0_30,
241
QUNIFORM_TEXTURE_CONFIG_P0_31,
242
QUNIFORM_TEXTURE_CONFIG_P0_32,
243
244
/**
245
* A reference to a V3D 3.x texture config parameter 1 uniform.
246
*
247
* This is a uniform implicitly loaded with a QPU_W_TMU* write, which
248
* has the pointer to the indirect texture state. Our data[] field
249
* will have a packed p1 value, but the address field will be just
250
* which texture unit's texture should be referenced.
251
*/
252
QUNIFORM_TEXTURE_CONFIG_P1,
253
254
/* A V3D 4.x texture config parameter. The high 8 bits will be
255
* which texture or sampler is being sampled, and the driver must
256
* replace the address field with the appropriate address.
257
*/
258
QUNIFORM_TMU_CONFIG_P0,
259
QUNIFORM_TMU_CONFIG_P1,
260
261
QUNIFORM_IMAGE_TMU_CONFIG_P0,
262
263
QUNIFORM_TEXTURE_FIRST_LEVEL,
264
265
QUNIFORM_TEXTURE_WIDTH,
266
QUNIFORM_TEXTURE_HEIGHT,
267
QUNIFORM_TEXTURE_DEPTH,
268
QUNIFORM_TEXTURE_ARRAY_SIZE,
269
QUNIFORM_TEXTURE_LEVELS,
270
QUNIFORM_TEXTURE_SAMPLES,
271
272
QUNIFORM_UBO_ADDR,
273
274
QUNIFORM_TEXRECT_SCALE_X,
275
QUNIFORM_TEXRECT_SCALE_Y,
276
277
/* Returns the base offset of the SSBO given by the data value. */
278
QUNIFORM_SSBO_OFFSET,
279
280
/* Returns the size of the SSBO or UBO given by the data value. */
281
QUNIFORM_GET_SSBO_SIZE,
282
QUNIFORM_GET_UBO_SIZE,
283
284
/* Sizes (in pixels) of a shader image given by the data value. */
285
QUNIFORM_IMAGE_WIDTH,
286
QUNIFORM_IMAGE_HEIGHT,
287
QUNIFORM_IMAGE_DEPTH,
288
QUNIFORM_IMAGE_ARRAY_SIZE,
289
290
QUNIFORM_LINE_WIDTH,
291
292
/* The line width sent to hardware. This includes the expanded width
293
* when anti-aliasing is enabled.
294
*/
295
QUNIFORM_AA_LINE_WIDTH,
296
297
/* Number of workgroups passed to glDispatchCompute in the dimension
298
* selected by the data value.
299
*/
300
QUNIFORM_NUM_WORK_GROUPS,
301
302
/* Base workgroup offset passed to vkCmdDispatchBase in the dimension
303
* selected by the data value.
304
*/
305
QUNIFORM_WORK_GROUP_BASE,
306
307
/**
308
* Returns the the offset of the scratch buffer for register spilling.
309
*/
310
QUNIFORM_SPILL_OFFSET,
311
QUNIFORM_SPILL_SIZE_PER_THREAD,
312
313
/**
314
* Returns the offset of the shared memory for compute shaders.
315
*
316
* This will be accessed using TMU general memory operations, so the
317
* L2T cache will effectively be the shared memory area.
318
*/
319
QUNIFORM_SHARED_OFFSET,
320
321
/**
322
* Returns the number of layers in the framebuffer.
323
*
324
* This is used to cap gl_Layer in geometry shaders to avoid
325
* out-of-bounds accesses into the tile state during binning.
326
*/
327
QUNIFORM_FB_LAYERS,
328
};
329
330
static inline uint32_t v3d_unit_data_create(uint32_t unit, uint32_t value)
331
{
332
assert(value < (1 << 24));
333
return unit << 24 | value;
334
}
335
336
static inline uint32_t v3d_unit_data_get_unit(uint32_t data)
337
{
338
return data >> 24;
339
}
340
341
static inline uint32_t v3d_unit_data_get_offset(uint32_t data)
342
{
343
return data & 0xffffff;
344
}
345
346
struct v3d_varying_slot {
347
uint8_t slot_and_component;
348
};
349
350
static inline struct v3d_varying_slot
351
v3d_slot_from_slot_and_component(uint8_t slot, uint8_t component)
352
{
353
assert(slot < 255 / 4);
354
return (struct v3d_varying_slot){ (slot << 2) + component };
355
}
356
357
static inline uint8_t v3d_slot_get_slot(struct v3d_varying_slot slot)
358
{
359
return slot.slot_and_component >> 2;
360
}
361
362
static inline uint8_t v3d_slot_get_component(struct v3d_varying_slot slot)
363
{
364
return slot.slot_and_component & 3;
365
}
366
367
enum v3d_execution_environment {
368
V3D_ENVIRONMENT_OPENGL = 0,
369
V3D_ENVIRONMENT_VULKAN,
370
};
371
372
struct v3d_key {
373
void *shader_state;
374
struct {
375
uint8_t swizzle[4];
376
} tex[V3D_MAX_TEXTURE_SAMPLERS];
377
struct {
378
uint8_t return_size;
379
uint8_t return_channels;
380
} sampler[V3D_MAX_TEXTURE_SAMPLERS];
381
382
uint8_t num_tex_used;
383
uint8_t num_samplers_used;
384
uint8_t ucp_enables;
385
bool is_last_geometry_stage;
386
bool robust_buffer_access;
387
388
enum v3d_execution_environment environment;
389
};
390
391
struct v3d_fs_key {
392
struct v3d_key base;
393
bool is_points;
394
bool is_lines;
395
bool line_smoothing;
396
bool point_coord_upper_left;
397
bool msaa;
398
bool sample_coverage;
399
bool sample_alpha_to_coverage;
400
bool sample_alpha_to_one;
401
/* Mask of which color render targets are present. */
402
uint8_t cbufs;
403
uint8_t swap_color_rb;
404
/* Mask of which render targets need to be written as 32-bit floats */
405
uint8_t f32_color_rb;
406
/* Masks of which render targets need to be written as ints/uints.
407
* Used by gallium to work around lost information in TGSI.
408
*/
409
uint8_t int_color_rb;
410
uint8_t uint_color_rb;
411
412
/* Color format information per render target. Only set when logic
413
* operations are enabled.
414
*/
415
struct {
416
enum pipe_format format;
417
const uint8_t *swizzle;
418
} color_fmt[V3D_MAX_DRAW_BUFFERS];
419
420
uint8_t logicop_func;
421
uint32_t point_sprite_mask;
422
423
struct pipe_rt_blend_state blend;
424
425
/* If the fragment shader reads gl_PrimitiveID then we have 2 scenarios:
426
*
427
* - If there is a geometry shader, then gl_PrimitiveID must be written
428
* by it and the fragment shader loads it as a regular explicit input
429
* varying. This is the only valid use case in GLES 3.1.
430
*
431
* - If there is not a geometry shader (allowed since GLES 3.2 and
432
* Vulkan 1.0), then gl_PrimitiveID must be implicitly written by
433
* hardware and is considered an implicit input varying in the
434
* fragment shader.
435
*/
436
bool has_gs;
437
};
438
439
struct v3d_gs_key {
440
struct v3d_key base;
441
442
struct v3d_varying_slot used_outputs[V3D_MAX_FS_INPUTS];
443
uint8_t num_used_outputs;
444
445
bool is_coord;
446
bool per_vertex_point_size;
447
};
448
449
struct v3d_vs_key {
450
struct v3d_key base;
451
452
struct v3d_varying_slot used_outputs[V3D_MAX_ANY_STAGE_INPUTS];
453
uint8_t num_used_outputs;
454
455
/* A bit-mask indicating if we need to swap the R/B channels for
456
* vertex attributes. Since the hardware doesn't provide any
457
* means to swizzle vertex attributes we need to do it in the shader.
458
*/
459
uint32_t va_swap_rb_mask;
460
461
bool is_coord;
462
bool per_vertex_point_size;
463
bool clamp_color;
464
};
465
466
/** A basic block of VIR intructions. */
467
struct qblock {
468
struct list_head link;
469
470
struct list_head instructions;
471
472
struct set *predecessors;
473
struct qblock *successors[2];
474
475
int index;
476
477
/* Instruction IPs for the first and last instruction of the block.
478
* Set by qpu_schedule.c.
479
*/
480
uint32_t start_qpu_ip;
481
uint32_t end_qpu_ip;
482
483
/* Instruction IP for the branch instruction of the block. Set by
484
* qpu_schedule.c.
485
*/
486
uint32_t branch_qpu_ip;
487
488
/** Offset within the uniform stream at the start of the block. */
489
uint32_t start_uniform;
490
/** Offset within the uniform stream of the branch instruction */
491
uint32_t branch_uniform;
492
493
/**
494
* Has the terminating branch of this block already been emitted
495
* by a break or continue?
496
*/
497
bool branch_emitted;
498
499
/** @{ used by v3d_vir_live_variables.c */
500
BITSET_WORD *def;
501
BITSET_WORD *defin;
502
BITSET_WORD *defout;
503
BITSET_WORD *use;
504
BITSET_WORD *live_in;
505
BITSET_WORD *live_out;
506
int start_ip, end_ip;
507
/** @} */
508
};
509
510
/** Which util/list.h add mode we should use when inserting an instruction. */
511
enum vir_cursor_mode {
512
vir_cursor_add,
513
vir_cursor_addtail,
514
};
515
516
/**
517
* Tracking structure for where new instructions should be inserted. Create
518
* with one of the vir_after_inst()-style helper functions.
519
*
520
* This does not protect against removal of the block or instruction, so we
521
* have an assert in instruction removal to try to catch it.
522
*/
523
struct vir_cursor {
524
enum vir_cursor_mode mode;
525
struct list_head *link;
526
};
527
528
static inline struct vir_cursor
529
vir_before_inst(struct qinst *inst)
530
{
531
return (struct vir_cursor){ vir_cursor_addtail, &inst->link };
532
}
533
534
static inline struct vir_cursor
535
vir_after_inst(struct qinst *inst)
536
{
537
return (struct vir_cursor){ vir_cursor_add, &inst->link };
538
}
539
540
static inline struct vir_cursor
541
vir_before_block(struct qblock *block)
542
{
543
return (struct vir_cursor){ vir_cursor_add, &block->instructions };
544
}
545
546
static inline struct vir_cursor
547
vir_after_block(struct qblock *block)
548
{
549
return (struct vir_cursor){ vir_cursor_addtail, &block->instructions };
550
}
551
552
enum v3d_compilation_result {
553
V3D_COMPILATION_SUCCEEDED,
554
V3D_COMPILATION_FAILED_REGISTER_ALLOCATION,
555
V3D_COMPILATION_FAILED,
556
};
557
558
/**
559
* Compiler state saved across compiler invocations, for any expensive global
560
* setup.
561
*/
562
struct v3d_compiler {
563
const struct v3d_device_info *devinfo;
564
struct ra_regs *regs;
565
struct ra_class *reg_class_any[3];
566
struct ra_class *reg_class_r5[3];
567
struct ra_class *reg_class_phys[3];
568
struct ra_class *reg_class_phys_or_acc[3];
569
};
570
571
/**
572
* This holds partially interpolated inputs as provided by hardware
573
* (The Vp = A*(x - x0) + B*(y - y0) term), as well as the C coefficient
574
* required to compute the final interpolated value.
575
*/
576
struct v3d_interp_input {
577
struct qreg vp;
578
struct qreg C;
579
unsigned mode; /* interpolation mode */
580
};
581
582
struct v3d_compile {
583
const struct v3d_device_info *devinfo;
584
nir_shader *s;
585
nir_function_impl *impl;
586
struct exec_list *cf_node_list;
587
const struct v3d_compiler *compiler;
588
589
void (*debug_output)(const char *msg,
590
void *debug_output_data);
591
void *debug_output_data;
592
593
/**
594
* Mapping from nir_register * or nir_ssa_def * to array of struct
595
* qreg for the values.
596
*/
597
struct hash_table *def_ht;
598
599
/* For each temp, the instruction generating its value. */
600
struct qinst **defs;
601
uint32_t defs_array_size;
602
603
/* TMU pipelining tracking */
604
struct {
605
/* NIR registers that have been updated with a TMU operation
606
* that has not been flushed yet.
607
*/
608
struct set *outstanding_regs;
609
610
uint32_t output_fifo_size;
611
612
struct {
613
nir_dest *dest;
614
uint8_t num_components;
615
uint8_t component_mask;
616
} flush[MAX_TMU_QUEUE_SIZE];
617
uint32_t flush_count;
618
} tmu;
619
620
/**
621
* Inputs to the shader, arranged by TGSI declaration order.
622
*
623
* Not all fragment shader QFILE_VARY reads are present in this array.
624
*/
625
struct qreg *inputs;
626
/**
627
* Partially interpolated inputs to the shader.
628
*/
629
struct v3d_interp_input *interp;
630
struct qreg *outputs;
631
bool msaa_per_sample_output;
632
struct qreg color_reads[V3D_MAX_DRAW_BUFFERS * V3D_MAX_SAMPLES * 4];
633
struct qreg sample_colors[V3D_MAX_DRAW_BUFFERS * V3D_MAX_SAMPLES * 4];
634
uint32_t inputs_array_size;
635
uint32_t outputs_array_size;
636
uint32_t uniforms_array_size;
637
638
/* Booleans for whether the corresponding QFILE_VARY[i] is
639
* flat-shaded. This includes gl_FragColor flat-shading, which is
640
* customized based on the shademodel_flat shader key.
641
*/
642
uint32_t flat_shade_flags[BITSET_WORDS(V3D_MAX_FS_INPUTS)];
643
644
uint32_t noperspective_flags[BITSET_WORDS(V3D_MAX_FS_INPUTS)];
645
646
uint32_t centroid_flags[BITSET_WORDS(V3D_MAX_FS_INPUTS)];
647
648
bool uses_center_w;
649
bool writes_z;
650
bool uses_implicit_point_line_varyings;
651
652
/* True if a fragment shader reads gl_PrimitiveID */
653
bool fs_uses_primitive_id;
654
655
/* If the fragment shader does anything that requires to force
656
* per-sample MSAA, such as reading gl_SampleID.
657
*/
658
bool force_per_sample_msaa;
659
660
/* Whether we are using the fallback scheduler. This will be set after
661
* register allocation has failed once.
662
*/
663
bool fallback_scheduler;
664
665
/* Disable TMU pipelining. This may increase the chances of being able
666
* to compile shaders with high register pressure that require to emit
667
* TMU spills.
668
*/
669
bool disable_tmu_pipelining;
670
bool pipelined_any_tmu;
671
672
/* Disable sorting of UBO loads with constant offset. This may
673
* increase the chances of being able to compile shaders with high
674
* register pressure.
675
*/
676
bool disable_constant_ubo_load_sorting;
677
bool sorted_any_ubo_loads;
678
679
/* Emits ldunif for each new uniform, even if the uniform was already
680
* emitted in the same block. Useful to compile shaders with high
681
* register pressure or to disable the optimization during uniform
682
* spills.
683
*/
684
bool disable_ldunif_opt;
685
686
/* Disables loop unrolling to reduce register pressure. */
687
bool disable_loop_unrolling;
688
bool unrolled_any_loops;
689
690
/* Minimum number of threads we are willing to use to register allocate
691
* a shader with the current compilation strategy. This only prevents
692
* us from lowering the thread count to register allocate successfully,
693
* which can be useful when we prefer doing other changes to the
694
* compilation strategy before dropping thread count.
695
*/
696
uint32_t min_threads_for_reg_alloc;
697
698
/* Whether TMU spills are allowed. If this is disabled it may cause
699
* register allocation to fail. We set this to favor other compilation
700
* strategies that can reduce register pressure and hopefully reduce or
701
* eliminate TMU spills in the shader.
702
*/
703
bool tmu_spilling_allowed;
704
705
/* The UBO index and block used with the last unifa load, as well as the
706
* current unifa offset *after* emitting that load. This is used to skip
707
* unifa writes (and their 3 delay slot) when the next UBO load reads
708
* right after the previous one in the same block.
709
*/
710
struct qblock *current_unifa_block;
711
int32_t current_unifa_index;
712
uint32_t current_unifa_offset;
713
714
/* State for whether we're executing on each channel currently. 0 if
715
* yes, otherwise a block number + 1 that the channel jumped to.
716
*/
717
struct qreg execute;
718
bool in_control_flow;
719
720
struct qreg line_x, point_x, point_y, primitive_id;
721
722
/**
723
* Instance ID, which comes in before the vertex attribute payload if
724
* the shader record requests it.
725
*/
726
struct qreg iid;
727
728
/**
729
* Base Instance ID, which comes in before the vertex attribute payload
730
* (after Instance ID) if the shader record requests it.
731
*/
732
struct qreg biid;
733
734
/**
735
* Vertex ID, which comes in before the vertex attribute payload
736
* (after Base Instance) if the shader record requests it.
737
*/
738
struct qreg vid;
739
740
/* Fragment shader payload regs. */
741
struct qreg payload_w, payload_w_centroid, payload_z;
742
743
struct qreg cs_payload[2];
744
struct qreg cs_shared_offset;
745
int local_invocation_index_bits;
746
747
/* If the shader uses subgroup functionality */
748
bool has_subgroups;
749
750
uint8_t vattr_sizes[V3D_MAX_VS_INPUTS / 4];
751
uint32_t vpm_output_size;
752
753
/* Size in bytes of registers that have been spilled. This is how much
754
* space needs to be available in the spill BO per thread per QPU.
755
*/
756
uint32_t spill_size;
757
/* Shader-db stats */
758
uint32_t spills, fills, loops;
759
/**
760
* Register spilling's per-thread base address, shared between each
761
* spill/fill's addressing calculations.
762
*/
763
struct qreg spill_base;
764
/* Bit vector of which temps may be spilled */
765
BITSET_WORD *spillable;
766
767
/**
768
* Array of the VARYING_SLOT_* of all FS QFILE_VARY reads.
769
*
770
* This includes those that aren't part of the VPM varyings, like
771
* point/line coordinates.
772
*/
773
struct v3d_varying_slot input_slots[V3D_MAX_FS_INPUTS];
774
775
/**
776
* An entry per outputs[] in the VS indicating what the VARYING_SLOT_*
777
* of the output is. Used to emit from the VS in the order that the
778
* FS needs.
779
*/
780
struct v3d_varying_slot *output_slots;
781
782
struct pipe_shader_state *shader_state;
783
struct v3d_key *key;
784
struct v3d_fs_key *fs_key;
785
struct v3d_gs_key *gs_key;
786
struct v3d_vs_key *vs_key;
787
788
/* Live ranges of temps. */
789
int *temp_start, *temp_end;
790
bool live_intervals_valid;
791
792
uint32_t *uniform_data;
793
enum quniform_contents *uniform_contents;
794
uint32_t uniform_array_size;
795
uint32_t num_uniforms;
796
uint32_t output_position_index;
797
nir_variable *output_color_var[4];
798
uint32_t output_sample_mask_index;
799
800
struct qreg undef;
801
uint32_t num_temps;
802
803
struct vir_cursor cursor;
804
struct list_head blocks;
805
int next_block_index;
806
struct qblock *cur_block;
807
struct qblock *loop_cont_block;
808
struct qblock *loop_break_block;
809
/**
810
* Which temp, if any, do we currently have in the flags?
811
* This is set when processing a comparison instruction, and
812
* reset to -1 by anything else that touches the flags.
813
*/
814
int32_t flags_temp;
815
enum v3d_qpu_cond flags_cond;
816
817
uint64_t *qpu_insts;
818
uint32_t qpu_inst_count;
819
uint32_t qpu_inst_size;
820
uint32_t qpu_inst_stalled_count;
821
uint32_t nop_count;
822
823
/* For the FS, the number of varying inputs not counting the
824
* point/line varyings payload
825
*/
826
uint32_t num_inputs;
827
828
uint32_t program_id;
829
uint32_t variant_id;
830
831
/* Set to compile program in in 1x, 2x, or 4x threaded mode, where
832
* SIG_THREAD_SWITCH is used to hide texturing latency at the cost of
833
* limiting ourselves to the part of the physical reg space.
834
*
835
* On V3D 3.x, 2x or 4x divide the physical reg space by 2x or 4x. On
836
* V3D 4.x, all shaders are 2x threaded, and 4x only divides the
837
* physical reg space in half.
838
*/
839
uint8_t threads;
840
struct qinst *last_thrsw;
841
bool last_thrsw_at_top_level;
842
843
bool emitted_tlb_load;
844
bool lock_scoreboard_on_first_thrsw;
845
846
/* Total number of spilled registers in the program */
847
uint32_t spill_count;
848
849
enum v3d_compilation_result compilation_result;
850
851
bool tmu_dirty_rcl;
852
};
853
854
struct v3d_uniform_list {
855
enum quniform_contents *contents;
856
uint32_t *data;
857
uint32_t count;
858
};
859
860
struct v3d_prog_data {
861
struct v3d_uniform_list uniforms;
862
863
uint32_t spill_size;
864
865
uint8_t threads;
866
867
/* For threads > 1, whether the program should be dispatched in the
868
* after-final-THRSW state.
869
*/
870
bool single_seg;
871
872
bool tmu_dirty_rcl;
873
874
bool has_control_barrier;
875
};
876
877
struct v3d_vs_prog_data {
878
struct v3d_prog_data base;
879
880
bool uses_iid, uses_biid, uses_vid;
881
882
/* Number of components read from each vertex attribute. */
883
uint8_t vattr_sizes[V3D_MAX_VS_INPUTS / 4];
884
885
/* Total number of components read, for the shader state record. */
886
uint32_t vpm_input_size;
887
888
/* Total number of components written, for the shader state record. */
889
uint32_t vpm_output_size;
890
891
/* Set if there should be separate VPM segments for input and output.
892
* If unset, vpm_input_size will be 0.
893
*/
894
bool separate_segments;
895
896
/* Value to be programmed in VCM_CACHE_SIZE. */
897
uint8_t vcm_cache_size;
898
899
/* Maps the nir->data.location to its
900
* nir->data.driver_location. In general we are using the
901
* driver location as index (like vattr_sizes above), so this
902
* map is useful when what we have is the location
903
*
904
* Returns -1 if the location is not used
905
*/
906
int32_t driver_location_map[V3D_MAX_VS_INPUTS];
907
};
908
909
struct v3d_gs_prog_data {
910
struct v3d_prog_data base;
911
912
/* Whether the program reads gl_PrimitiveIDIn */
913
bool uses_pid;
914
915
/* Number of components read from each input varying. */
916
uint8_t input_sizes[V3D_MAX_GS_INPUTS / 4];
917
918
/* Number of inputs */
919
uint8_t num_inputs;
920
struct v3d_varying_slot input_slots[V3D_MAX_GS_INPUTS];
921
922
/* Total number of components written, for the shader state record. */
923
uint32_t vpm_output_size;
924
925
/* Maximum SIMD dispatch width to not exceed VPM output size limits
926
* in the geometry shader. Notice that the final dispatch width has to
927
* be decided at draw time and could be lower based on the VPM pressure
928
* added by other shader stages.
929
*/
930
uint8_t simd_width;
931
932
/* Output primitive type */
933
uint8_t out_prim_type;
934
935
/* Number of GS invocations */
936
uint8_t num_invocations;
937
938
bool writes_psiz;
939
};
940
941
struct v3d_fs_prog_data {
942
struct v3d_prog_data base;
943
944
/* Whether the program reads gl_PrimitiveID */
945
bool uses_pid;
946
947
struct v3d_varying_slot input_slots[V3D_MAX_FS_INPUTS];
948
949
/* Array of flat shade flags.
950
*
951
* Each entry is only 24 bits (high 8 bits 0), to match the hardware
952
* packet layout.
953
*/
954
uint32_t flat_shade_flags[((V3D_MAX_FS_INPUTS - 1) / 24) + 1];
955
956
uint32_t noperspective_flags[((V3D_MAX_FS_INPUTS - 1) / 24) + 1];
957
958
uint32_t centroid_flags[((V3D_MAX_FS_INPUTS - 1) / 24) + 1];
959
960
uint8_t num_inputs;
961
bool writes_z;
962
bool disable_ez;
963
bool uses_center_w;
964
bool uses_implicit_point_line_varyings;
965
bool lock_scoreboard_on_first_thrsw;
966
bool force_per_sample_msaa;
967
};
968
969
struct v3d_compute_prog_data {
970
struct v3d_prog_data base;
971
/* Size in bytes of the workgroup's shared space. */
972
uint32_t shared_size;
973
uint16_t local_size[3];
974
/* If the shader uses subgroup functionality */
975
bool has_subgroups;
976
};
977
978
struct vpm_config {
979
uint32_t As;
980
uint32_t Vc;
981
uint32_t Gs;
982
uint32_t Gd;
983
uint32_t Gv;
984
uint32_t Ve;
985
uint32_t gs_width;
986
};
987
988
bool
989
v3d_compute_vpm_config(struct v3d_device_info *devinfo,
990
struct v3d_vs_prog_data *vs_bin,
991
struct v3d_vs_prog_data *vs,
992
struct v3d_gs_prog_data *gs_bin,
993
struct v3d_gs_prog_data *gs,
994
struct vpm_config *vpm_cfg_bin,
995
struct vpm_config *vpm_cfg);
996
997
static inline bool
998
vir_has_uniform(struct qinst *inst)
999
{
1000
return inst->uniform != ~0;
1001
}
1002
1003
const struct v3d_compiler *v3d_compiler_init(const struct v3d_device_info *devinfo);
1004
void v3d_compiler_free(const struct v3d_compiler *compiler);
1005
void v3d_optimize_nir(struct v3d_compile *c, struct nir_shader *s);
1006
1007
uint64_t *v3d_compile(const struct v3d_compiler *compiler,
1008
struct v3d_key *key,
1009
struct v3d_prog_data **prog_data,
1010
nir_shader *s,
1011
void (*debug_output)(const char *msg,
1012
void *debug_output_data),
1013
void *debug_output_data,
1014
int program_id, int variant_id,
1015
uint32_t *final_assembly_size);
1016
1017
uint32_t v3d_prog_data_size(gl_shader_stage stage);
1018
void v3d_nir_to_vir(struct v3d_compile *c);
1019
1020
void vir_compile_destroy(struct v3d_compile *c);
1021
const char *vir_get_stage_name(struct v3d_compile *c);
1022
struct qblock *vir_new_block(struct v3d_compile *c);
1023
void vir_set_emit_block(struct v3d_compile *c, struct qblock *block);
1024
void vir_link_blocks(struct qblock *predecessor, struct qblock *successor);
1025
struct qblock *vir_entry_block(struct v3d_compile *c);
1026
struct qblock *vir_exit_block(struct v3d_compile *c);
1027
struct qinst *vir_add_inst(enum v3d_qpu_add_op op, struct qreg dst,
1028
struct qreg src0, struct qreg src1);
1029
struct qinst *vir_mul_inst(enum v3d_qpu_mul_op op, struct qreg dst,
1030
struct qreg src0, struct qreg src1);
1031
struct qinst *vir_branch_inst(struct v3d_compile *c,
1032
enum v3d_qpu_branch_cond cond);
1033
void vir_remove_instruction(struct v3d_compile *c, struct qinst *qinst);
1034
uint32_t vir_get_uniform_index(struct v3d_compile *c,
1035
enum quniform_contents contents,
1036
uint32_t data);
1037
struct qreg vir_uniform(struct v3d_compile *c,
1038
enum quniform_contents contents,
1039
uint32_t data);
1040
void vir_schedule_instructions(struct v3d_compile *c);
1041
void v3d_setup_spill_base(struct v3d_compile *c);
1042
struct v3d_qpu_instr v3d_qpu_nop(void);
1043
1044
struct qreg vir_emit_def(struct v3d_compile *c, struct qinst *inst);
1045
struct qinst *vir_emit_nondef(struct v3d_compile *c, struct qinst *inst);
1046
void vir_set_cond(struct qinst *inst, enum v3d_qpu_cond cond);
1047
void vir_set_pf(struct v3d_compile *c, struct qinst *inst, enum v3d_qpu_pf pf);
1048
void vir_set_uf(struct v3d_compile *c, struct qinst *inst, enum v3d_qpu_uf uf);
1049
void vir_set_unpack(struct qinst *inst, int src,
1050
enum v3d_qpu_input_unpack unpack);
1051
void vir_set_pack(struct qinst *inst, enum v3d_qpu_output_pack pack);
1052
1053
struct qreg vir_get_temp(struct v3d_compile *c);
1054
void vir_emit_last_thrsw(struct v3d_compile *c);
1055
void vir_calculate_live_intervals(struct v3d_compile *c);
1056
int vir_get_nsrc(struct qinst *inst);
1057
bool vir_has_side_effects(struct v3d_compile *c, struct qinst *inst);
1058
bool vir_get_add_op(struct qinst *inst, enum v3d_qpu_add_op *op);
1059
bool vir_get_mul_op(struct qinst *inst, enum v3d_qpu_mul_op *op);
1060
bool vir_is_raw_mov(struct qinst *inst);
1061
bool vir_is_tex(const struct v3d_device_info *devinfo, struct qinst *inst);
1062
bool vir_is_add(struct qinst *inst);
1063
bool vir_is_mul(struct qinst *inst);
1064
bool vir_writes_r3(const struct v3d_device_info *devinfo, struct qinst *inst);
1065
bool vir_writes_r4(const struct v3d_device_info *devinfo, struct qinst *inst);
1066
struct qreg vir_follow_movs(struct v3d_compile *c, struct qreg reg);
1067
uint8_t vir_channels_written(struct qinst *inst);
1068
struct qreg ntq_get_src(struct v3d_compile *c, nir_src src, int i);
1069
void ntq_store_dest(struct v3d_compile *c, nir_dest *dest, int chan,
1070
struct qreg result);
1071
bool ntq_tmu_fifo_overflow(struct v3d_compile *c, uint32_t components);
1072
void ntq_add_pending_tmu_flush(struct v3d_compile *c, nir_dest *dest,
1073
uint32_t component_mask);
1074
void ntq_flush_tmu(struct v3d_compile *c);
1075
void vir_emit_thrsw(struct v3d_compile *c);
1076
1077
void vir_dump(struct v3d_compile *c);
1078
void vir_dump_inst(struct v3d_compile *c, struct qinst *inst);
1079
void vir_dump_uniform(enum quniform_contents contents, uint32_t data);
1080
1081
void vir_validate(struct v3d_compile *c);
1082
1083
void vir_optimize(struct v3d_compile *c);
1084
bool vir_opt_algebraic(struct v3d_compile *c);
1085
bool vir_opt_constant_folding(struct v3d_compile *c);
1086
bool vir_opt_copy_propagate(struct v3d_compile *c);
1087
bool vir_opt_dead_code(struct v3d_compile *c);
1088
bool vir_opt_peephole_sf(struct v3d_compile *c);
1089
bool vir_opt_redundant_flags(struct v3d_compile *c);
1090
bool vir_opt_small_immediates(struct v3d_compile *c);
1091
bool vir_opt_vpm(struct v3d_compile *c);
1092
bool vir_opt_constant_alu(struct v3d_compile *c);
1093
void v3d_nir_lower_blend(nir_shader *s, struct v3d_compile *c);
1094
void v3d_nir_lower_io(nir_shader *s, struct v3d_compile *c);
1095
void v3d_nir_lower_line_smooth(nir_shader *shader);
1096
void v3d_nir_lower_logic_ops(nir_shader *s, struct v3d_compile *c);
1097
void v3d_nir_lower_robust_buffer_access(nir_shader *shader, struct v3d_compile *c);
1098
void v3d_nir_lower_scratch(nir_shader *s);
1099
void v3d_nir_lower_txf_ms(nir_shader *s, struct v3d_compile *c);
1100
void v3d_nir_lower_image_load_store(nir_shader *s);
1101
void vir_lower_uniforms(struct v3d_compile *c);
1102
1103
void v3d33_vir_vpm_read_setup(struct v3d_compile *c, int num_components);
1104
void v3d33_vir_vpm_write_setup(struct v3d_compile *c);
1105
void v3d33_vir_emit_tex(struct v3d_compile *c, nir_tex_instr *instr);
1106
void v3d40_vir_emit_tex(struct v3d_compile *c, nir_tex_instr *instr);
1107
void v3d40_vir_emit_image_load_store(struct v3d_compile *c,
1108
nir_intrinsic_instr *instr);
1109
1110
void v3d_vir_to_qpu(struct v3d_compile *c, struct qpu_reg *temp_registers);
1111
uint32_t v3d_qpu_schedule_instructions(struct v3d_compile *c);
1112
void qpu_validate(struct v3d_compile *c);
1113
struct qpu_reg *v3d_register_allocate(struct v3d_compile *c, bool *spilled);
1114
bool vir_init_reg_sets(struct v3d_compiler *compiler);
1115
1116
int v3d_shaderdb_dump(struct v3d_compile *c, char **shaderdb_str);
1117
1118
bool v3d_gl_format_is_return_32(GLenum format);
1119
1120
uint32_t
1121
v3d_get_op_for_atomic_add(nir_intrinsic_instr *instr, unsigned src);
1122
1123
static inline bool
1124
quniform_contents_is_texture_p0(enum quniform_contents contents)
1125
{
1126
return (contents >= QUNIFORM_TEXTURE_CONFIG_P0_0 &&
1127
contents < (QUNIFORM_TEXTURE_CONFIG_P0_0 +
1128
V3D_MAX_TEXTURE_SAMPLERS));
1129
}
1130
1131
static inline bool
1132
vir_in_nonuniform_control_flow(struct v3d_compile *c)
1133
{
1134
return c->execute.file != QFILE_NULL;
1135
}
1136
1137
static inline struct qreg
1138
vir_uniform_ui(struct v3d_compile *c, uint32_t ui)
1139
{
1140
return vir_uniform(c, QUNIFORM_CONSTANT, ui);
1141
}
1142
1143
static inline struct qreg
1144
vir_uniform_f(struct v3d_compile *c, float f)
1145
{
1146
return vir_uniform(c, QUNIFORM_CONSTANT, fui(f));
1147
}
1148
1149
#define VIR_ALU0(name, vir_inst, op) \
1150
static inline struct qreg \
1151
vir_##name(struct v3d_compile *c) \
1152
{ \
1153
return vir_emit_def(c, vir_inst(op, c->undef, \
1154
c->undef, c->undef)); \
1155
} \
1156
static inline struct qinst * \
1157
vir_##name##_dest(struct v3d_compile *c, struct qreg dest) \
1158
{ \
1159
return vir_emit_nondef(c, vir_inst(op, dest, \
1160
c->undef, c->undef)); \
1161
}
1162
1163
#define VIR_ALU1(name, vir_inst, op) \
1164
static inline struct qreg \
1165
vir_##name(struct v3d_compile *c, struct qreg a) \
1166
{ \
1167
return vir_emit_def(c, vir_inst(op, c->undef, \
1168
a, c->undef)); \
1169
} \
1170
static inline struct qinst * \
1171
vir_##name##_dest(struct v3d_compile *c, struct qreg dest, \
1172
struct qreg a) \
1173
{ \
1174
return vir_emit_nondef(c, vir_inst(op, dest, a, \
1175
c->undef)); \
1176
}
1177
1178
#define VIR_ALU2(name, vir_inst, op) \
1179
static inline struct qreg \
1180
vir_##name(struct v3d_compile *c, struct qreg a, struct qreg b) \
1181
{ \
1182
return vir_emit_def(c, vir_inst(op, c->undef, a, b)); \
1183
} \
1184
static inline struct qinst * \
1185
vir_##name##_dest(struct v3d_compile *c, struct qreg dest, \
1186
struct qreg a, struct qreg b) \
1187
{ \
1188
return vir_emit_nondef(c, vir_inst(op, dest, a, b)); \
1189
}
1190
1191
#define VIR_NODST_0(name, vir_inst, op) \
1192
static inline struct qinst * \
1193
vir_##name(struct v3d_compile *c) \
1194
{ \
1195
return vir_emit_nondef(c, vir_inst(op, c->undef, \
1196
c->undef, c->undef)); \
1197
}
1198
1199
#define VIR_NODST_1(name, vir_inst, op) \
1200
static inline struct qinst * \
1201
vir_##name(struct v3d_compile *c, struct qreg a) \
1202
{ \
1203
return vir_emit_nondef(c, vir_inst(op, c->undef, \
1204
a, c->undef)); \
1205
}
1206
1207
#define VIR_NODST_2(name, vir_inst, op) \
1208
static inline struct qinst * \
1209
vir_##name(struct v3d_compile *c, struct qreg a, struct qreg b) \
1210
{ \
1211
return vir_emit_nondef(c, vir_inst(op, c->undef, \
1212
a, b)); \
1213
}
1214
1215
#define VIR_SFU(name) \
1216
static inline struct qreg \
1217
vir_##name(struct v3d_compile *c, struct qreg a) \
1218
{ \
1219
if (c->devinfo->ver >= 41) { \
1220
return vir_emit_def(c, vir_add_inst(V3D_QPU_A_##name, \
1221
c->undef, \
1222
a, c->undef)); \
1223
} else { \
1224
vir_FMOV_dest(c, vir_reg(QFILE_MAGIC, V3D_QPU_WADDR_##name), a); \
1225
return vir_FMOV(c, vir_reg(QFILE_MAGIC, V3D_QPU_WADDR_R4)); \
1226
} \
1227
} \
1228
static inline struct qinst * \
1229
vir_##name##_dest(struct v3d_compile *c, struct qreg dest, \
1230
struct qreg a) \
1231
{ \
1232
if (c->devinfo->ver >= 41) { \
1233
return vir_emit_nondef(c, vir_add_inst(V3D_QPU_A_##name, \
1234
dest, \
1235
a, c->undef)); \
1236
} else { \
1237
vir_FMOV_dest(c, vir_reg(QFILE_MAGIC, V3D_QPU_WADDR_##name), a); \
1238
return vir_FMOV_dest(c, dest, vir_reg(QFILE_MAGIC, V3D_QPU_WADDR_R4)); \
1239
} \
1240
}
1241
1242
#define VIR_A_ALU2(name) VIR_ALU2(name, vir_add_inst, V3D_QPU_A_##name)
1243
#define VIR_M_ALU2(name) VIR_ALU2(name, vir_mul_inst, V3D_QPU_M_##name)
1244
#define VIR_A_ALU1(name) VIR_ALU1(name, vir_add_inst, V3D_QPU_A_##name)
1245
#define VIR_M_ALU1(name) VIR_ALU1(name, vir_mul_inst, V3D_QPU_M_##name)
1246
#define VIR_A_ALU0(name) VIR_ALU0(name, vir_add_inst, V3D_QPU_A_##name)
1247
#define VIR_M_ALU0(name) VIR_ALU0(name, vir_mul_inst, V3D_QPU_M_##name)
1248
#define VIR_A_NODST_2(name) VIR_NODST_2(name, vir_add_inst, V3D_QPU_A_##name)
1249
#define VIR_M_NODST_2(name) VIR_NODST_2(name, vir_mul_inst, V3D_QPU_M_##name)
1250
#define VIR_A_NODST_1(name) VIR_NODST_1(name, vir_add_inst, V3D_QPU_A_##name)
1251
#define VIR_M_NODST_1(name) VIR_NODST_1(name, vir_mul_inst, V3D_QPU_M_##name)
1252
#define VIR_A_NODST_0(name) VIR_NODST_0(name, vir_add_inst, V3D_QPU_A_##name)
1253
1254
VIR_A_ALU2(FADD)
1255
VIR_A_ALU2(VFPACK)
1256
VIR_A_ALU2(FSUB)
1257
VIR_A_ALU2(FMIN)
1258
VIR_A_ALU2(FMAX)
1259
1260
VIR_A_ALU2(ADD)
1261
VIR_A_ALU2(SUB)
1262
VIR_A_ALU2(SHL)
1263
VIR_A_ALU2(SHR)
1264
VIR_A_ALU2(ASR)
1265
VIR_A_ALU2(ROR)
1266
VIR_A_ALU2(MIN)
1267
VIR_A_ALU2(MAX)
1268
VIR_A_ALU2(UMIN)
1269
VIR_A_ALU2(UMAX)
1270
VIR_A_ALU2(AND)
1271
VIR_A_ALU2(OR)
1272
VIR_A_ALU2(XOR)
1273
VIR_A_ALU2(VADD)
1274
VIR_A_ALU2(VSUB)
1275
VIR_A_NODST_2(STVPMV)
1276
VIR_A_NODST_2(STVPMD)
1277
VIR_A_ALU1(NOT)
1278
VIR_A_ALU1(NEG)
1279
VIR_A_ALU1(FLAPUSH)
1280
VIR_A_ALU1(FLBPUSH)
1281
VIR_A_ALU1(FLPOP)
1282
VIR_A_ALU0(FLAFIRST)
1283
VIR_A_ALU0(FLNAFIRST)
1284
VIR_A_ALU1(SETMSF)
1285
VIR_A_ALU1(SETREVF)
1286
VIR_A_ALU0(TIDX)
1287
VIR_A_ALU0(EIDX)
1288
VIR_A_ALU1(LDVPMV_IN)
1289
VIR_A_ALU1(LDVPMV_OUT)
1290
VIR_A_ALU1(LDVPMD_IN)
1291
VIR_A_ALU1(LDVPMD_OUT)
1292
VIR_A_ALU2(LDVPMG_IN)
1293
VIR_A_ALU2(LDVPMG_OUT)
1294
VIR_A_ALU0(TMUWT)
1295
1296
VIR_A_ALU0(IID)
1297
VIR_A_ALU0(FXCD)
1298
VIR_A_ALU0(XCD)
1299
VIR_A_ALU0(FYCD)
1300
VIR_A_ALU0(YCD)
1301
VIR_A_ALU0(MSF)
1302
VIR_A_ALU0(REVF)
1303
VIR_A_ALU0(BARRIERID)
1304
VIR_A_ALU0(SAMPID)
1305
VIR_A_NODST_1(VPMSETUP)
1306
VIR_A_NODST_0(VPMWT)
1307
VIR_A_ALU2(FCMP)
1308
VIR_A_ALU2(VFMAX)
1309
1310
VIR_A_ALU1(FROUND)
1311
VIR_A_ALU1(FTOIN)
1312
VIR_A_ALU1(FTRUNC)
1313
VIR_A_ALU1(FTOIZ)
1314
VIR_A_ALU1(FFLOOR)
1315
VIR_A_ALU1(FTOUZ)
1316
VIR_A_ALU1(FCEIL)
1317
VIR_A_ALU1(FTOC)
1318
1319
VIR_A_ALU1(FDX)
1320
VIR_A_ALU1(FDY)
1321
1322
VIR_A_ALU1(ITOF)
1323
VIR_A_ALU1(CLZ)
1324
VIR_A_ALU1(UTOF)
1325
1326
VIR_M_ALU2(UMUL24)
1327
VIR_M_ALU2(FMUL)
1328
VIR_M_ALU2(SMUL24)
1329
VIR_M_NODST_2(MULTOP)
1330
1331
VIR_M_ALU1(MOV)
1332
VIR_M_ALU1(FMOV)
1333
1334
VIR_SFU(RECIP)
1335
VIR_SFU(RSQRT)
1336
VIR_SFU(EXP)
1337
VIR_SFU(LOG)
1338
VIR_SFU(SIN)
1339
VIR_SFU(RSQRT2)
1340
1341
static inline struct qinst *
1342
vir_MOV_cond(struct v3d_compile *c, enum v3d_qpu_cond cond,
1343
struct qreg dest, struct qreg src)
1344
{
1345
struct qinst *mov = vir_MOV_dest(c, dest, src);
1346
vir_set_cond(mov, cond);
1347
return mov;
1348
}
1349
1350
static inline struct qreg
1351
vir_SEL(struct v3d_compile *c, enum v3d_qpu_cond cond,
1352
struct qreg src0, struct qreg src1)
1353
{
1354
struct qreg t = vir_get_temp(c);
1355
vir_MOV_dest(c, t, src1);
1356
vir_MOV_cond(c, cond, t, src0);
1357
return t;
1358
}
1359
1360
static inline struct qinst *
1361
vir_NOP(struct v3d_compile *c)
1362
{
1363
return vir_emit_nondef(c, vir_add_inst(V3D_QPU_A_NOP,
1364
c->undef, c->undef, c->undef));
1365
}
1366
1367
static inline struct qreg
1368
vir_LDTMU(struct v3d_compile *c)
1369
{
1370
if (c->devinfo->ver >= 41) {
1371
struct qinst *ldtmu = vir_add_inst(V3D_QPU_A_NOP, c->undef,
1372
c->undef, c->undef);
1373
ldtmu->qpu.sig.ldtmu = true;
1374
1375
return vir_emit_def(c, ldtmu);
1376
} else {
1377
vir_NOP(c)->qpu.sig.ldtmu = true;
1378
return vir_MOV(c, vir_reg(QFILE_MAGIC, V3D_QPU_WADDR_R4));
1379
}
1380
}
1381
1382
static inline struct qreg
1383
vir_UMUL(struct v3d_compile *c, struct qreg src0, struct qreg src1)
1384
{
1385
vir_MULTOP(c, src0, src1);
1386
return vir_UMUL24(c, src0, src1);
1387
}
1388
1389
static inline struct qreg
1390
vir_TLBU_COLOR_READ(struct v3d_compile *c, uint32_t config)
1391
{
1392
assert(c->devinfo->ver >= 41); /* XXX */
1393
assert((config & 0xffffff00) == 0xffffff00);
1394
1395
struct qinst *ldtlb = vir_add_inst(V3D_QPU_A_NOP, c->undef,
1396
c->undef, c->undef);
1397
ldtlb->qpu.sig.ldtlbu = true;
1398
ldtlb->uniform = vir_get_uniform_index(c, QUNIFORM_CONSTANT, config);
1399
return vir_emit_def(c, ldtlb);
1400
}
1401
1402
static inline struct qreg
1403
vir_TLB_COLOR_READ(struct v3d_compile *c)
1404
{
1405
assert(c->devinfo->ver >= 41); /* XXX */
1406
1407
struct qinst *ldtlb = vir_add_inst(V3D_QPU_A_NOP, c->undef,
1408
c->undef, c->undef);
1409
ldtlb->qpu.sig.ldtlb = true;
1410
return vir_emit_def(c, ldtlb);
1411
}
1412
1413
/*
1414
static inline struct qreg
1415
vir_LOAD_IMM(struct v3d_compile *c, uint32_t val)
1416
{
1417
return vir_emit_def(c, vir_inst(QOP_LOAD_IMM, c->undef,
1418
vir_reg(QFILE_LOAD_IMM, val), c->undef));
1419
}
1420
1421
static inline struct qreg
1422
vir_LOAD_IMM_U2(struct v3d_compile *c, uint32_t val)
1423
{
1424
return vir_emit_def(c, vir_inst(QOP_LOAD_IMM_U2, c->undef,
1425
vir_reg(QFILE_LOAD_IMM, val),
1426
c->undef));
1427
}
1428
static inline struct qreg
1429
vir_LOAD_IMM_I2(struct v3d_compile *c, uint32_t val)
1430
{
1431
return vir_emit_def(c, vir_inst(QOP_LOAD_IMM_I2, c->undef,
1432
vir_reg(QFILE_LOAD_IMM, val),
1433
c->undef));
1434
}
1435
*/
1436
1437
static inline struct qinst *
1438
vir_BRANCH(struct v3d_compile *c, enum v3d_qpu_branch_cond cond)
1439
{
1440
/* The actual uniform_data value will be set at scheduling time */
1441
return vir_emit_nondef(c, vir_branch_inst(c, cond));
1442
}
1443
1444
#define vir_for_each_block(block, c) \
1445
list_for_each_entry(struct qblock, block, &c->blocks, link)
1446
1447
#define vir_for_each_block_rev(block, c) \
1448
list_for_each_entry_rev(struct qblock, block, &c->blocks, link)
1449
1450
/* Loop over the non-NULL members of the successors array. */
1451
#define vir_for_each_successor(succ, block) \
1452
for (struct qblock *succ = block->successors[0]; \
1453
succ != NULL; \
1454
succ = (succ == block->successors[1] ? NULL : \
1455
block->successors[1]))
1456
1457
#define vir_for_each_inst(inst, block) \
1458
list_for_each_entry(struct qinst, inst, &block->instructions, link)
1459
1460
#define vir_for_each_inst_rev(inst, block) \
1461
list_for_each_entry_rev(struct qinst, inst, &block->instructions, link)
1462
1463
#define vir_for_each_inst_safe(inst, block) \
1464
list_for_each_entry_safe(struct qinst, inst, &block->instructions, link)
1465
1466
#define vir_for_each_inst_inorder(inst, c) \
1467
vir_for_each_block(_block, c) \
1468
vir_for_each_inst(inst, _block)
1469
1470
#define vir_for_each_inst_inorder_safe(inst, c) \
1471
vir_for_each_block(_block, c) \
1472
vir_for_each_inst_safe(inst, _block)
1473
1474
#endif /* V3D_COMPILER_H */
1475
1476