Debian Codegraph @

src/asahi/compiler/README.md

raw
1 # Special registers
2
3 `r0l` is the hardware nesting counter.
4
5 `r1` is the hardware link register.
6
7 `r5` and `r6` are preloaded in vertex shaders to the vertex ID and instance ID.
8
9 # ABI
10
11 The following section describes the ABI used by non-monolithic programs.
12
13 ## Vertex
14
15 Registers have the following layout at the beginning of the vertex shader
16 (written by the vertex prolog):
17
18 * `r0-r3` and `r7` undefined. This avoids preloading into the nesting counter or
19 having unaligned values. The prolog is free to use these registers as
20 temporaries.
21 * `r4` is the zero-based vertex ID if the vertex shader is running as a hardware
22 compute shader, useful to avoid a redundant special register read in the main
23 shader. Undefined in hardware vertex shaders.
24 * `r5-r6` retain their usual meanings, even if the vertex shader is running as a
25 hardware compute shader. This allows software index fetch code to run in the
26 prolog without contaminating the main shader key.
27 * `r8` onwards contains 128-bit uniform vectors for each attribute.
28 Accommodates 30 attributes without spilling, exceeding the 16 attribute API
29 minimum. For 32 attributes, we will need to use function calls or the stack.
30
31 One useful property is that the GPR usage of the combined program is equal to
32 the GPR usage of the main shader. The prolog cannot write higher registers than
33 read by the main shader.
34
35 Vertex prologs do not have any uniform registers allocated for preamble
36 optimization or constant promotion, as this adds complexity without any
37 legitimate use case.
38
39 For a vertex shader reading $n$ attributes, the following layout is used:
40
41 * The first $n$ 64-bit uniforms are the base addresses of each attribute.
42 * The next $n$ 32-bit uniforms are the associated clamps (sizes). Presently
43 robustness is always used.
44 * The next 2x32-bit uniform is the base vertex and base instance. This must
45 always be reserved because it is unknown at vertex shader compile-time whether
46 any attribute will use instancing. Reserving also the base vertex allows us to
47 push both conveniently with a single USC Uniform word.
48 * The next 16-bit is the draw ID.
49 * For a hardware compute shader, the next 48-bit is padding.
50 * For a hardware compute shader, the next 64-bit uniform is a pointer to the
51 input assembly buffer.
52
53 In total, the first $6n + 5$ 16-bit uniform slots are reserved for a hardware
54 vertex shader, or $6n + 12$ for a hardware compute shader.
55
56 ## Fragment
57
58 When sample shading is enabled in a non-monolithic fragment shader, the fragment
59 shader has the following register inputs:
60
61 * `r0l = 0`. This is the hardware nesting counter.
62 * `r1l` is the mask of samples currently being shaded. This usually equals to
63 `1 << sample ID`, for "true" per-sample shading.
64
65 When sample shading is disabled, no register inputs are defined. The fragment
66 prolog (if present) may clobber whatever registers it pleases.
67
68 Registers have the following layout at the end of the fragment shader (read by
69 the fragment epilog):
70
71 * `r0l = 0` if sample shading is enabled. This is implicitly true.
72 * `r1l` preserved if sample shading is enabled.
73 * `r2` and `r3l` contain the emitted depth/stencil respectively, if
74 depth and/or stencil are written by the fragment shader. Depth/stencil writes
75 must be deferred to the epilog for correctness when the epilog can discard
76 (i.e. when alpha-to-coverage is enabled).
77 * `r3h` contains the logically emitted sample mask, if the fragment shader uses
78 forced early tests. This predicates the epilog's stores.
79 * The vec4 of 32-bit registers beginning at `r(4 * (i + 1))` contains the colour
80 output for render target `i`. When dual source blending is enabled, there is
81 only a single render target and the dual source colour is treated as the
82 second render target (registers r8-r11).
83
84 Uniform registers have the following layout:
85
86 * u0_u1: 64-bit render target texture heap
87 * u2...u5: Blend constant
88 * u6_u7: Root descriptor, so we can fetch the 64-bit fragment invocation counter
89 address and (OpenGL only) the 64-bit polygon stipple address