• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

tests/22-Nov-2023-15170

.gitignoreD22-Nov-202397 65

READMED23-Nov-20235.7 KiB11998

meson.buildD23-Nov-20236.6 KiB235217

nir.cD23-Nov-202355.3 KiB2,0491,597

nir.hD23-Nov-202382.4 KiB2,7801,607

nir_algebraic.pyD23-Nov-202321.3 KiB633483

nir_builder.hD23-Nov-202320.3 KiB684526

nir_builder_opcodes_h.pyD23-Nov-20231.8 KiB5041

nir_clone.cD23-Nov-202324 KiB782538

nir_constant_expressions.hD23-Nov-20231.5 KiB376

nir_constant_expressions.pyD23-Nov-202312.4 KiB439398

nir_control_flow.cD23-Nov-202321.7 KiB737495

nir_control_flow.hD23-Nov-20236.4 KiB16953

nir_control_flow_private.hD23-Nov-20231.5 KiB426

nir_dominance.cD22-Nov-20237.9 KiB313207

nir_from_ssa.cD23-Nov-202332.2 KiB984601

nir_gather_info.cD23-Nov-202311.7 KiB370271

nir_gs_count_vertices.cD22-Nov-20233 KiB9443

nir_inline_functions.cD22-Nov-20239.3 KiB286183

nir_instr_set.cD22-Nov-202316.5 KiB544400

nir_instr_set.hD23-Nov-20232.4 KiB658

nir_intrinsics.cD22-Nov-20232 KiB5725

nir_intrinsics.hD23-Nov-202321 KiB481189

nir_linking_helpers.cD23-Nov-202318.2 KiB507335

nir_liveness.cD22-Nov-20239.5 KiB294160

nir_loop_analyze.cD23-Nov-202326.6 KiB845557

nir_loop_analyze.hD23-Nov-20233.2 KiB9649

nir_lower_64bit_packing.cD23-Nov-20233.3 KiB10860

nir_lower_alpha_test.cD23-Nov-20234.1 KiB11264

nir_lower_alu_to_scalar.cD23-Nov-20239.5 KiB280194

nir_lower_atomics.cD23-Nov-20236.8 KiB198128

nir_lower_atomics_to_ssbo.cD23-Nov-20238.4 KiB237163

nir_lower_bitmap.cD23-Nov-20234.5 KiB14068

nir_lower_clamp_color_outputs.cD23-Nov-20233.8 KiB144102

nir_lower_clip.cD23-Nov-202310.1 KiB340206

nir_lower_clip_cull_distance_arrays.cD23-Nov-20236.2 KiB205115

nir_lower_constant_initializers.cD22-Nov-20233.6 KiB11368

nir_lower_double_ops.cD23-Nov-202319.6 KiB600296

nir_lower_drawpixels.cD23-Nov-20238.5 KiB262184

nir_lower_global_vars_to_local.cD22-Nov-20233.5 KiB10857

nir_lower_gs_intrinsics.cD23-Nov-20237 KiB213100

nir_lower_idiv.cD23-Nov-20234.1 KiB15388

nir_lower_indirect_derefs.cD23-Nov-20237.6 KiB221149

nir_lower_int64.cD23-Nov-20239.7 KiB297207

nir_lower_io.cD23-Nov-202318 KiB566420

nir_lower_io_arrays_to_elements.cD23-Nov-202314.9 KiB429297

nir_lower_io_to_scalar.cD23-Nov-202313.3 KiB384260

nir_lower_io_to_temporaries.cD23-Nov-20237 KiB202119

nir_lower_io_types.cD23-Nov-20235.6 KiB177105

nir_lower_load_const_to_scalar.cD23-Nov-20233.5 KiB10354

nir_lower_locals_to_regs.cD23-Nov-20239.7 KiB302205

nir_lower_passthrough_edgeflags.cD22-Nov-20232 KiB5726

nir_lower_patch_vertices.cD22-Nov-20232.2 KiB5427

nir_lower_phis_to_scalar.cD22-Nov-202310.7 KiB309162

nir_lower_regs_to_ssa.cD23-Nov-20239.2 KiB298192

nir_lower_returns.cD23-Nov-20239.1 KiB283170

nir_lower_samplers.cD23-Nov-20235.4 KiB166107

nir_lower_samplers_as_deref.cD23-Nov-20237.8 KiB246149

nir_lower_subgroups.cD23-Nov-20238.2 KiB245172

nir_lower_system_values.cD23-Nov-20236 KiB185113

nir_lower_tex.cD23-Nov-202329.4 KiB875587

nir_lower_to_source_mods.cD23-Nov-20236.4 KiB216135

nir_lower_two_sided_color.cD23-Nov-20235.9 KiB208129

nir_lower_uniforms_to_ubo.cD23-Nov-20233.5 KiB9855

nir_lower_var_copies.cD23-Nov-20237.1 KiB202103

nir_lower_vars_to_ssa.cD23-Nov-202324.7 KiB756465

nir_lower_vec_to_movs.cD23-Nov-202310.1 KiB315179

nir_lower_wpos_center.cD23-Nov-20234.3 KiB12566

nir_lower_wpos_ytransform.cD23-Nov-202313.2 KiB364226

nir_metadata.cD23-Nov-20233 KiB9746

nir_move_vec_src_uses_to_dest.cD23-Nov-20236.6 KiB213110

nir_normalize_cubemap_coords.cD22-Nov-20233.8 KiB11762

nir_opcodes.pyD23-Nov-202325.6 KiB744530

nir_opcodes_c.pyD23-Nov-20234.9 KiB134102

nir_opcodes_h.pyD23-Nov-20231.6 KiB4739

nir_opt_algebraic.pyD23-Nov-202327.8 KiB595394

nir_opt_conditional_discard.cD22-Nov-20234.2 KiB12572

nir_opt_constant_folding.cD22-Nov-20237 KiB238147

nir_opt_copy_prop_vars.cD23-Nov-202327.8 KiB814531

nir_opt_copy_propagate.cD23-Nov-20239.1 KiB342249

nir_opt_cse.cD23-Nov-20232.7 KiB9441

nir_opt_dce.cD22-Nov-20234.7 KiB177117

nir_opt_dead_cf.cD22-Nov-202310.4 KiB357198

nir_opt_gcm.cD22-Nov-202317.2 KiB519277

nir_opt_global_to_local.cD22-Nov-20232.9 KiB10358

nir_opt_if.cD22-Nov-20238.2 KiB257123

nir_opt_intrinsics.cD23-Nov-20232.8 KiB9253

nir_opt_loop_unroll.cD23-Nov-202320.8 KiB595323

nir_opt_move_comparisons.cD22-Nov-20236 KiB18692

nir_opt_peephole_select.cD23-Nov-20237.7 KiB265152

nir_opt_remove_phis.cD23-Nov-20235.4 KiB17383

nir_opt_trivial_continues.cD22-Nov-20234.8 KiB13881

nir_opt_undef.cD22-Nov-20235 KiB16295

nir_phi_builder.cD23-Nov-202310.7 KiB298148

nir_phi_builder.hD23-Nov-20234.7 KiB12017

nir_print.cD23-Nov-202332.1 KiB1,2601,009

nir_propagate_invariant.cD22-Nov-20235.4 KiB197140

nir_remove_dead_variables.cD23-Nov-20236.5 KiB218151

nir_repair_ssa.cD22-Nov-20234.5 KiB15390

nir_search.cD22-Nov-202319.5 KiB623444

nir_search.hD22-Nov-20234.2 KiB13150

nir_search_helpers.hD23-Nov-20235 KiB189129

nir_serialize.cD23-Nov-202335.3 KiB1,222958

nir_serialize.hD23-Nov-20231.5 KiB4415

nir_split_var_copies.cD23-Nov-202311.4 KiB297151

nir_sweep.cD23-Nov-20235 KiB177108

nir_to_lcssa.cD22-Nov-20236.4 KiB204124

nir_validate.cD23-Nov-202339.5 KiB1,248929

nir_vla.hD23-Nov-20232.1 KiB5710

nir_worklist.cD22-Nov-20233.4 KiB13982

nir_worklist.hD23-Nov-20232.9 KiB9132

README

1New IR, or NIR, is an IR for Mesa intended to sit below GLSL IR and Mesa IR.
2Its design inherits from the various IRs that Mesa has used in the past, as
3well as Direct3D assembly, and it includes a few new ideas as well. It is a
4flat (in terms of using instructions instead of expressions), typeless IR,
5similar to TGSI and Mesa IR.  It also supports SSA (although it doesn't require
6it).
7
8Variables
9=========
10
11NIR includes support for source-level GLSL variables through a structure mostly
12copied from GLSL IR. These will be used for linking and conversion from GLSL IR
13(and later, from an AST), but for the most part, they will be lowered to
14registers (see below) and loads/stores.
15
16Registers
17=========
18
19Registers are light-weight; they consist of a structure that only contains its
20size, its index for liveness analysis, and an optional name for debugging. In
21addition, registers can be local to a function or global to the entire shader;
22the latter will be used in ARB_shader_subroutine for passing parameters and
23getting return values from subroutines. Registers can also be an array, in which
24case they can be accessed indirectly. Each ALU instruction (add, subtract, etc.)
25works directly with registers or SSA values (see below).
26
27SSA
28========
29
30Everywhere a register can be loaded/stored, an SSA value can be used instead.
31The only exception is that arrays/indirect addressing are not supported with
32SSA; although research has been done on extensions of SSA to arrays before, it's
33usually for the purpose of parallelization (which we're not interested in), and
34adds some overhead in the form of adding copies or extra arrays (which is much
35more expensive than introducing copies between non-array registers). SSA uses
36point directly to their corresponding definition, which in turn points to the
37instruction it is part of. This creates an implicit use-def chain and avoids the
38need for an external structure for each SSA register.
39
40Functions
41=========
42
43Support for function calls is mostly similar to GLSL IR. Each shader contains a
44list of functions, and each function has a list of overloads. Each overload
45contains a list of parameters, and may contain an implementation which specifies
46the variables that correspond to the parameters and return value. Inlining a
47function, assuming it has a single return point, is as simple as copying its
48instructions, registers, and local variables into the target function and then
49inserting copies to and from the new parameters as appropriate. After functions
50are inlined and any non-subroutine functions are deleted, parameters and return
51variables will be converted to global variables and then global registers. We
52don't do this lowering earlier (i.e. the fortranizer idea) for a few reasons:
53
54- If we want to do optimizations before link time, we need to have the function
55signature available during link-time.
56
57- If we do any inlining before link time, then we might wind up with the
58inlined function and the non-inlined function using the same global
59variables/registers which would preclude optimization.
60
61Intrinsics
62=========
63
64Any operation (other than function calls and textures) which touches a variable
65or is not referentially transparent is represented by an intrinsic. Intrinsics
66are similar to the idea of a "builtin function," i.e. a function declaration
67whose implementation is provided by the backend, except they are more powerful
68in the following ways:
69
70- They can also load and store registers when appropriate, which limits the
71number of variables needed in later stages of the IR while obviating the need
72for a separate load/store variable instruction.
73
74- Intrinsics can be marked as side-effect free, which permits them to be
75treated like any other instruction when it comes to optimizations. This allows
76load intrinsics to be represented as intrinsics while still being optimized
77away by dead code elimination, common subexpression elimination, etc.
78
79Intrinsics are used for:
80
81- Atomic operations
82- Memory barriers
83- Subroutine calls
84- Geometry shader emitVertex and endPrimitive
85- Loading and storing variables (before lowering)
86- Loading and storing uniforms, shader inputs and outputs, etc (after lowering)
87- Copying variables (cases where in GLSL the destination is a structure or
88array)
89- The kitchen sink
90- ...
91
92Textures
93=========
94
95Unfortunately, there are far too many texture operations to represent each one
96of them with an intrinsic, so there's a special texture instruction similar to
97the GLSL IR one. The biggest difference is that, while the texture instruction
98has a sampler dereference field used just like in GLSL IR, this gets lowered to
99a texture unit index (with a possible indirect offset) while the type
100information of the original sampler is kept around for backends. Also, all the
101non-constant sources are stored in a single array to make it easier for
102optimization passes to iterate over all the sources.
103
104Control Flow
105=========
106
107Like in GLSL IR, control flow consists of a tree of "control flow nodes", which
108include if statements and loops, and jump instructions (break, continue, and
109return). Unlike GLSL IR, though, the leaves of the tree aren't statements but
110basic blocks. Each basic block also keeps track of its successors and
111predecessors, and function implementations keep track of the beginning basic
112block (the first basic block of the function) and the ending basic block (a fake
113basic block that every return statement points to). Together, these elements
114make up the control flow graph, in this case a redundant piece of information on
115top of the control flow tree that will be used by almost all the optimizations.
116There are helper functions to add and remove control flow nodes that also update
117the control flow graph, and so usually it doesn't need to be touched by passes
118that modify control flow nodes.
119