Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/shader-translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ writelane, permlane, DPP, ds_swizzle, ds_bpermute, lane masks, mbcnt. A PC GPU r
the driver. Compute shaders can ask for a size; pixel, vertex and mesh shaders cannot in shader model 6.7.

Translated code therefore uses console (program) lane numbers through the prelude's `vw_lane`, `vw_read`,
`vw_ballot`, `vw_any` and `vw_count`; `readfirstlane` and `lane_bit` build on them. With
`vw_ballot`, `vw_any` and `vw_count`; `readfirstlane` and `lane_bit` build on them. `readfirstlane` takes the first lane
with EXEC set with WaveReadLaneFirst under `if (active)` and a WaveActiveMax when the hardware wave holds no more
than the program wave (outside the group forms): WaveReadLaneAt at the ballot's lowest bit crashed AMD's compiler
(RX 7800 XT, driver 32.0.32029.2010) in CreatePipelineState on the decoration-baking mesh pipeline's pixel program,
which does it seven times in a loop, and took the process with it. With
`TranslationOptions.EmulateWaveSize` (the default; `--native-waves` turns it off) a pixel, vertex or mesh program
starts with `#define VW_WAVE <32|64>` and `VW_EMULATE 1`, and each hardware wave of H lanes holds a window of the
program wave of W lanes:
Expand Down
12 changes: 12 additions & 0 deletions src/FiveStar.Shaders/Translation/Runtime/rdna_prelude.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,20 @@ uint vw_count(bool c) {
}

// ---- cross-lane
// When the hardware wave holds no more than the program wave, the first lane with EXEC set is the first hardware lane
// with `active`: it is read under `if (active)` and spread to the wave with a max (the other lanes give 0). Reading it
// with WaveReadLaneAt at the ballot's lowest bit crashed AMD's compiler in CreatePipelineState (RX 7800 XT, driver
// 32.0.32029.2010) on a pixel program that does it seven times in a loop, through dxc and the DXIL backend alike.
uint readfirstlane(uint x, bool active) { // first lane with EXEC set (not just the first HLSL-active lane); lane 0 if none
uint2 m = vw_ballot(active);
#if !VW_GROUP_WAVE && !VW_GROUP_LANES
if (!VW_EMULATE || WaveGetLaneCount() <= VW_WAVE) {
if ((m.x | m.y) == 0u) return vw_read(x, 0u);
uint v = 0u;
if (active) v = WaveReadLaneFirst(x);
return WaveActiveMax(v);
}
#endif
uint l = m.x != 0 ? firstbitlow(m.x) : m.y != 0 ? 32 + firstbitlow(m.y) : 0u;
return vw_read(x, l);
}
Expand Down