# ir3, turnip, freedreno: Shader preambles

This depends on and includes !13147 (closed), !13142 (merged), and !13143 (merged).

One thing that still needs to be resolved is whether we should use `ldc.k`

in gallium. For turnip we definitely want it, because we can pre-bake most of the uniform setup whereas we have to read the descriptors from write-combined memory (which nothing else does) to figure out which ranges to push, and we also need to do some complicated calculations for robustness2 support, and that all happens at draw time.

This needs to be tested with real apps, however the shader-db numbers are already very promising (with the baseline being !13143 (merged)):

```
total instructions in shared programs: 1565085 -> 1498405 (-4.26%)
instructions in affected programs: 1107442 -> 1040762 (-6.02%)
helped: 3509
HURT: 693
helped stats (abs) min: 1 max: 150 x̄: 20.09 x̃: 11
helped stats (rel) min: 0.15% max: 94.23% x̄: 10.03% x̃: 6.55%
HURT stats (abs) min: 1 max: 87 x̄: 5.50 x̃: 2
HURT stats (rel) min: 0.06% max: 31.43% x̄: 3.48% x̃: 1.82%
95% mean confidence interval for instructions value: -16.59 -15.15
95% mean confidence interval for instructions %-change: -8.17% -7.43%
Instructions are helped.
total nops in shared programs: 362253 -> 354974 (-2.01%)
nops in affected programs: 264147 -> 256868 (-2.76%)
helped: 2112
HURT: 2023
helped stats (abs) min: 1 max: 85 x̄: 11.12 x̃: 5
helped stats (rel) min: 0.26% max: 100.00% x̄: 29.67% x̃: 18.75%
HURT stats (abs) min: 1 max: 89 x̄: 8.01 x̃: 5
HURT stats (rel) min: 0.00% max: 1700.00% x̄: 56.83% x̃: 14.29%
95% mean confidence interval for nops value: -2.23 -1.30
95% mean confidence interval for nops %-change: 9.25% 16.05%
Inconclusive result (value mean confidence interval and %-change mean confidence interval disagree).
total non-nops in shared programs: 1202832 -> 1143431 (-4.94%)
non-nops in affected programs: 797113 -> 737712 (-7.45%)
helped: 3735
HURT: 111
helped stats (abs) min: 1 max: 100 x̄: 15.98 x̃: 10
helped stats (rel) min: 0.08% max: 85.00% x̄: 10.07% x̃: 7.89%
HURT stats (abs) min: 1 max: 26 x̄: 2.47 x̃: 2
HURT stats (rel) min: 0.17% max: 7.76% x̄: 1.96% x̃: 1.94%
95% mean confidence interval for non-nops value: -15.94 -14.95
95% mean confidence interval for non-nops %-change: -10.06% -9.39%
Non-nops are helped.
total mov in shared programs: 76648 -> 65086 (-15.08%)
mov in affected programs: 41707 -> 30145 (-27.72%)
helped: 2493
HURT: 787
helped stats (abs) min: 1 max: 36 x̄: 5.28 x̃: 4
helped stats (rel) min: 0.16% max: 100.00% x̄: 57.42% x̃: 50.00%
HURT stats (abs) min: 1 max: 31 x̄: 2.05 x̃: 1
HURT stats (rel) min: 0.00% max: 750.00% x̄: 39.50% x̃: 25.00%
95% mean confidence interval for mov value: -3.72 -3.33
95% mean confidence interval for mov %-change: -36.18% -32.16%
Mov are helped.
total cov in shared programs: 29200 -> 23791 (-18.52%)
cov in affected programs: 18545 -> 13136 (-29.17%)
helped: 964
HURT: 14
helped stats (abs) min: 1 max: 15 x̄: 5.63 x̃: 6
helped stats (rel) min: 3.03% max: 100.00% x̄: 41.28% x̃: 25.00%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 9.09% max: 100.00% x̄: 57.03% x̃: 60.00%
95% mean confidence interval for cov value: -5.72 -5.34
95% mean confidence interval for cov %-change: -41.74% -38.02%
Cov are helped.
total dwords in shared programs: 2766186 -> 3185922 (15.17%)
dwords in affected programs: 2291134 -> 2710870 (18.32%)
helped: 13
HURT: 9440
helped stats (abs) min: 2 max: 32 x̄: 18.31 x̃: 24
helped stats (rel) min: 0.08% max: 10.16% x̄: 4.41% x̃: 4.08%
HURT stats (abs) min: 2 max: 448 x̄: 44.49 x̃: 30
HURT stats (rel) min: 0.03% max: 500.00% x̄: 31.96% x̃: 18.75%
95% mean confidence interval for dwords value: 43.26 45.54
95% mean confidence interval for dwords %-change: 31.29% 32.53%
Dwords are HURT.
total last-baryf in shared programs: 81271 -> 71303 (-12.27%)
last-baryf in affected programs: 66064 -> 56096 (-15.09%)
helped: 393
HURT: 273
helped stats (abs) min: 1 max: 259 x̄: 33.14 x̃: 23
helped stats (rel) min: 0.46% max: 100.00% x̄: 31.83% x̃: 20.95%
HURT stats (abs) min: 1 max: 187 x̄: 11.20 x̃: 7
HURT stats (rel) min: 0.43% max: 2671.43% x̄: 94.32% x̃: 37.50%
95% mean confidence interval for last-baryf value: -17.66 -12.28
95% mean confidence interval for last-baryf %-change: 7.91% 31.85%
Inconclusive result (value mean confidence interval and %-change mean confidence interval disagree).
total cat0 in shared programs: 394761 -> 387156 (-1.93%)
cat0 in affected programs: 281223 -> 273618 (-2.70%)
helped: 2112
HURT: 2022
helped stats (abs) min: 1 max: 85 x̄: 11.30 x̃: 5
helped stats (rel) min: 0.25% max: 98.41% x̄: 25.74% x̃: 17.65%
HURT stats (abs) min: 1 max: 89 x̄: 8.04 x̃: 5
HURT stats (rel) min: 0.18% max: 3600.00% x̄: 71.04% x̃: 15.79%
95% mean confidence interval for cat0 value: -2.31 -1.37
95% mean confidence interval for cat0 %-change: 15.64% 27.55%
Inconclusive result (value mean confidence interval and %-change mean confidence interval disagree).
total cat1 in shared programs: 106330 -> 89555 (-15.78%)
cat1 in affected programs: 64296 -> 47521 (-26.09%)
helped: 2846
HURT: 640
helped stats (abs) min: 1 max: 45 x̄: 6.29 x̃: 4
helped stats (rel) min: 0.16% max: 100.00% x̄: 49.17% x̃: 42.86%
HURT stats (abs) min: 1 max: 31 x̄: 1.77 x̃: 1
HURT stats (rel) min: 0.00% max: 400.00% x̄: 31.42% x̃: 25.00%
95% mean confidence interval for cat1 value: -5.01 -4.61
95% mean confidence interval for cat1 %-change: -35.89% -32.86%
Cat1 are helped.
total cat2 in shared programs: 705061 -> 673318 (-4.50%)
cat2 in affected programs: 481276 -> 449533 (-6.60%)
helped: 3473
HURT: 129
helped stats (abs) min: 1 max: 55 x̄: 9.36 x̃: 6
helped stats (rel) min: 0.11% max: 100.00% x̄: 10.35% x̃: 7.69%
HURT stats (abs) min: 1 max: 100 x̄: 6.02 x̃: 3
HURT stats (rel) min: 0.29% max: 128.57% x̄: 12.66% x̃: 2.97%
95% mean confidence interval for cat2 value: -9.13 -8.50
95% mean confidence interval for cat2 %-change: -9.98% -9.07%
Cat2 are helped.
total cat3 in shared programs: 293762 -> 289169 (-1.56%)
cat3 in affected programs: 76629 -> 72036 (-5.99%)
helped: 1470
HURT: 115
helped stats (abs) min: 1 max: 100 x̄: 3.31 x̃: 2
helped stats (rel) min: 0.07% max: 100.00% x̄: 27.67% x̃: 8.26%
HURT stats (abs) min: 1 max: 6 x̄: 2.43 x̃: 2
HURT stats (rel) min: 1.47% max: 40.00% x̄: 28.57% x̃: 40.00%
95% mean confidence interval for cat3 value: -3.16 -2.64
95% mean confidence interval for cat3 %-change: -25.49% -21.70%
Cat3 are helped.
total cat4 in shared programs: 35022 -> 29314 (-16.30%)
cat4 in affected programs: 21137 -> 15429 (-27.00%)
helped: 1870
HURT: 0
helped stats (abs) min: 1 max: 11 x̄: 3.05 x̃: 2
helped stats (rel) min: 1.45% max: 100.00% x̄: 38.76% x̃: 28.57%
95% mean confidence interval for cat4 value: -3.17 -2.94
95% mean confidence interval for cat4 %-change: -40.13% -37.39%
Cat4 are helped.
total cat5 in shared programs: 24463 -> 24332 (-0.54%)
cat5 in affected programs: 731 -> 600 (-17.92%)
helped: 59
HURT: 0
helped stats (abs) min: 1 max: 16 x̄: 2.22 x̃: 1
helped stats (rel) min: 1.85% max: 100.00% x̄: 44.99% x̃: 44.44%
95% mean confidence interval for cat5 value: -2.81 -1.63
95% mean confidence interval for cat5 %-change: -54.62% -35.36%
Cat5 are helped.
total cat6 in shared programs: 5463 -> 5338 (-2.29%)
cat6 in affected programs: 682 -> 557 (-18.33%)
helped: 51
HURT: 53
helped stats (abs) min: 1 max: 7 x̄: 3.57 x̃: 4
helped stats (rel) min: 0.29% max: 100.00% x̄: 59.98% x̃: 66.67%
HURT stats (abs) min: 1 max: 2 x̄: 1.08 x̃: 1
HURT stats (rel) min: 100.00% max: 200.00% x̄: 107.55% x̃: 100.00%
95% mean confidence interval for cat6 value: -1.76 -0.64
95% mean confidence interval for cat6 %-change: 8.10% 42.69%
Inconclusive result (value mean confidence interval and %-change mean confidence interval disagree).
total ldp in shared programs: 328 -> 327 (-0.30%)
ldp in affected programs: 328 -> 327 (-0.30%)
helped: 1
HURT: 0
total sstall in shared programs: 138008 -> 125834 (-8.82%)
sstall in affected programs: 99932 -> 87758 (-12.18%)
helped: 1782
HURT: 833
helped stats (abs) min: 1 max: 49 x̄: 10.35 x̃: 8
helped stats (rel) min: 0.79% max: 100.00% x̄: 35.63% x̃: 22.22%
HURT stats (abs) min: 1 max: 53 x̄: 7.52 x̃: 6
HURT stats (rel) min: 0.00% max: 900.00% x̄: 51.46% x̃: 25.00%
95% mean confidence interval for sstall value: -5.09 -4.22
95% mean confidence interval for sstall %-change: -10.49% -5.29%
Sstall are helped.
total (ss) in shared programs: 34693 -> 32365 (-6.71%)
(ss) in affected programs: 20856 -> 18528 (-11.16%)
helped: 1653
HURT: 599
helped stats (abs) min: 1 max: 18 x̄: 2.06 x̃: 1
helped stats (rel) min: 1.75% max: 100.00% x̄: 31.73% x̃: 25.00%
HURT stats (abs) min: 1 max: 61 x̄: 1.81 x̃: 1
HURT stats (rel) min: 0.00% max: 700.00% x̄: 36.38% x̃: 25.00%
95% mean confidence interval for (ss) value: -1.14 -0.93
95% mean confidence interval for (ss) %-change: -15.46% -11.77%
(ss) are helped.
total (sy) in shared programs: 13245 -> 13238 (-0.05%)
(sy) in affected programs: 4201 -> 4194 (-0.17%)
helped: 339
HURT: 396
helped stats (abs) min: 1 max: 7 x̄: 1.59 x̃: 1
helped stats (rel) min: 0.31% max: 100.00% x̄: 33.86% x̃: 25.00%
HURT stats (abs) min: 1 max: 10 x̄: 1.34 x̃: 1
HURT stats (rel) min: 3.45% max: 500.00% x̄: 54.49% x̃: 33.33%
95% mean confidence interval for (sy) value: -0.14 0.12
95% mean confidence interval for (sy) %-change: 9.30% 18.18%
Inconclusive result (value mean confidence interval includes 0).
total waves in shared programs: 236494 -> 237562 (0.45%)
waves in affected programs: 10824 -> 11892 (9.87%)
helped: 311
HURT: 571
helped stats (abs) min: 2 max: 8 x̄: 2.64 x̃: 2
helped stats (rel) min: 12.50% max: 50.00% x̄: 18.87% x̃: 12.50%
HURT stats (abs) min: 2 max: 6 x̄: 3.31 x̃: 4
HURT stats (rel) min: 14.29% max: 100.00% x̄: 32.02% x̃: 33.33%
95% mean confidence interval for waves value: 1.01 1.41
95% mean confidence interval for waves %-change: 12.27% 15.89%
Waves are HURT.
Total CPU time (seconds): 203.36 -> 224.80 (10.54%)
```

The remaining shader-db regressions seem to be losing the scheduler lottery resulting in more nop's, and things like bumping up the occupancy resulting in more moves.