Skip to content
Merged
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
3 changes: 2 additions & 1 deletion docs/shader-translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ strip. The record size `GS_VTX_DW` is derived from the LDS write offsets between
| FMA | `mad` (the prelude's exact `fma32` exists but is slow): fused on AMD and NVIDIA, unfused on WARP. `v_mad_f32`, `v_mac_f32`, `v_madak_f32` and `v_madmk_f32`, unfused on AMD, are `mad_unfused`: a `precise` product and sum, which dxc does not mark fast, so no driver contracts them (NVIDIA did) |
| `v_fract_f32` | `fract_f32`: `frac`, clamped to 0x3F7FFFFF as AMD does (`frac` of a small negative value rounds to 1.0 on NVIDIA) |

**Mesh fallback contract** (register space 9, bound through a descriptor table):
**Mesh fallback contract** (register space 9, bound through a descriptor table; not as root descriptors, since the
compute shader reads the capacities of `u0` and `u1` with GetDimensions, which root descriptors leave undefined):

| Binding | Content |
|---|---|
Expand Down
11 changes: 3 additions & 8 deletions tests/FiveStar.Shaders.Tests/Cases/MeshStageRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public sealed partial class MeshStageRunner
{
public const string Native = "ms_ngg_strips";
public const string FallbackTable = "msfb_ngg_strips";
public const string FallbackRoot = "msfb_ngg_strips_rootdesc";
public const string FallbackOverflow = "msfb_overflow_dropped";

/// <summary>The program with the mesh launch payload (TranslationOptions.MeshPayload): drawn without the stage, and through the fallback.</summary>
Expand Down Expand Up @@ -207,7 +206,7 @@ public MeshStageRunner(WarpFixture fixture)
_fixture = fixture;
}

public static IReadOnlyList<string> Variants => [Native, FallbackTable, FallbackRoot, FallbackOverflow, Supersteps, SuperstepFallback, SuperstepCarry, Payload, PayloadFallback];
public static IReadOnlyList<string> Variants => [Native, FallbackTable, FallbackOverflow, Supersteps, SuperstepFallback, SuperstepCarry, Payload, PayloadFallback];

/// <summary>Draws a variant; <paramref name="direct"/> compiles a native mesh shader with the DXIL backend.</summary>
public IReadOnlyList<string> Run(string variant, bool direct = false)
Expand Down Expand Up @@ -236,19 +235,15 @@ private List<string> RunFallback(string variant, string mesh, byte[] pixel, Fram
var (compute, vertex) = MeshComputeFallback.Rewrite(mesh);
var stride = int.Parse(StridePattern().Match(compute).Groups[1].Value, CultureInfo.InvariantCulture);
var groups = variant == FallbackOverflow ? 3 : 1;
var rootConstants = variant == FallbackRoot ? 16 : 60;
var job = new MeshFallbackJob(
_fixture.Workbench.Compile(variant + "_cs", compute, "cs"),
_fixture.Workbench.Compile(variant + "_vs", vertex, "vs"),
pixel,
framebuffer,
bindings with { RootConstantCount = rootConstants },
bindings with { RootConstantCount = 60 },
groups,
MaxOutputs * stride,
MaxOutputs * 12)
{
RootDescriptors = variant == FallbackRoot,
};
MaxOutputs * 12);

if (variant == FallbackOverflow)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/FiveStar.Shaders.Tests/MeshShaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace FiveStar.Shaders.Tests;

/// <summary>
/// An NGG program through the two-phase mesh path, drawn natively and through the mesh-to-compute fallback (descriptor
/// table, root descriptors, and an overflowing dispatch whose extra group must be dropped). A variant whose regions
/// table, and an overflowing dispatch whose extra group must be dropped). A variant whose regions
/// WARP's 4-lane waves skip while the 64-lane console wave runs them is classified as right on 4 lanes and draws so.
/// </summary>
public sealed class MeshShaderTests : IClassFixture<WarpFixture>
Expand Down
3 changes: 1 addition & 2 deletions tests/FiveStar.Shaders.Tests/UserDataBindingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace FiveStar.Shaders.Tests;
/// <summary>
/// The loader's two ways of passing user SGPRs, a root CBV over 128 dwords and 32 root constants
/// (--user-data-constants), give each stage the reference result: compute, pixel, vertex, geometry, and mesh drawn
/// natively and through the fallback (whose root descriptors share the root signature with the constants). All but the
/// natively and through the fallback (whose table shares the root signature with the constants). All but the
/// geometry program read user SGPRs: the compute output descriptor, the pixel and vertex values, the mesh counts.
/// FIVESTAR_WARP_USER_DATA runs the whole suite either way.
/// </summary>
Expand All @@ -35,7 +35,6 @@ public void Every_stage_reads_its_user_sgprs(UserDataBinding binding)
["geometry"] = new GeometryStageRunner(fixture).Run(),
["mesh"] = mesh.Run(MeshStageRunner.Native),
["mesh fallback, table"] = mesh.Run(MeshStageRunner.FallbackTable),
["mesh fallback, root descriptors"] = mesh.Run(MeshStageRunner.FallbackRoot),
};
var failed = runs.Where(run => run.Value.Count != 0).Select(run => $"{run.Key}: {run.Value.Count} mismatches, {string.Join("; ", run.Value.Take(4))}");

Expand Down
3 changes: 0 additions & 3 deletions tests/FiveStar.Shaders.Tests/Warp/MeshFallbackJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@ public sealed record MeshFallbackJob(
int IndexBytes)
{
public IReadOnlyList<uint> StaleIndices { get; init; } = [];

/// <summary>Bind u0..u2 / t0 as root descriptors instead of a descriptor table.</summary>
public bool RootDescriptors { get; init; }
}
11 changes: 1 addition & 10 deletions tests/FiveStar.Shaders.Tests/Warp/PipelineFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,7 @@ public static ID3D12RootSignature RootSignature(ID3D12Device device, int rootCon
| RootSignatureFlags.SamplerHeapDirectlyIndexed | RootSignatureFlags.AllowInputAssemblerInputLayout;
var parameters = new List<RootParameter1> { UserData(rootConstants, binding) };

if (layout == RootLayout.FallbackRoot)
{
for (uint register = 0; register < FallbackUavs; register++)
{
parameters.Add(new RootParameter1(RootParameterType.UnorderedAccessView, new RootDescriptor1(register, FallbackSpace), ShaderVisibility.All));
}

parameters.Add(new RootParameter1(RootParameterType.ShaderResourceView, new RootDescriptor1(0, FallbackSpace), ShaderVisibility.All));
}
else if (layout == RootLayout.FallbackTable)
if (layout == RootLayout.FallbackTable)
{
var volatileFlags = DescriptorRangeFlags.DataVolatile | DescriptorRangeFlags.DescriptorsVolatile;
DescriptorRange1[] ranges =
Expand Down
3 changes: 0 additions & 3 deletions tests/FiveStar.Shaders.Tests/Warp/RootLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@ public enum RootLayout

/// <summary>Mesh fallback: u0..u2 and t0 (space 9) through a descriptor table.</summary>
FallbackTable,

/// <summary>Mesh fallback: u0..u2 and t0 (space 9) as root descriptors.</summary>
FallbackRoot,
}
43 changes: 7 additions & 36 deletions tests/FiveStar.Shaders.Tests/Warp/WarpRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public WarpResult MeshFallback(MeshFallbackJob job)
{
return Run(recording =>
{
var layout = job.RootDescriptors ? RootLayout.FallbackRoot : RootLayout.FallbackTable;
var root = recording.Own(PipelineFactory.RootSignature(_device.Device, job.Bindings.RootConstantCount, layout, _userData));
var root = recording.Own(PipelineFactory.RootSignature(_device.Device, job.Bindings.RootConstantCount, RootLayout.FallbackTable, _userData));
recording.CreateHeaps(job.Bindings);
var formats = recording.CreateTargets(job.Framebuffer);

Expand All @@ -116,15 +115,15 @@ public WarpResult MeshFallback(MeshFallbackJob job)

recording.BeginStatistics();
recording.SetComputeRoot(root, job.Bindings);
BindFallback(recording, job, buffers, compute: true);
recording.List.SetComputeRootDescriptorTable(1, recording.ResourceTable(FallbackSlot));
recording.List.SetPipelineState(compute);
recording.List.Dispatch((uint)job.Groups, 1, 1);

Transition(recording, buffers.Vertices, ResourceStates.UnorderedAccess, ResourceStates.NonPixelShaderResource);
Transition(recording, buffers.Indices, ResourceStates.UnorderedAccess, ResourceStates.IndexBuffer);
Transition(recording, buffers.Counter, ResourceStates.UnorderedAccess, ResourceStates.IndirectArgument);
recording.SetGraphicsRoot(root, job.Bindings);
BindFallback(recording, job, buffers, compute: false);
recording.List.SetGraphicsRootDescriptorTable(1, recording.ResourceTable(FallbackSlot));
recording.List.SetPipelineState(draw);

DrawIndirect(recording, job, buffers);
Expand All @@ -141,42 +140,14 @@ private static (ID3D12Resource Vertices, ID3D12Resource Indices, ID3D12Resource
var indices = recording.FilledBuffer([.. job.StaleIndices], job.IndexBytes, ResourceStates.UnorderedAccess, flags);
var counter = recording.FilledBuffer([0, 1, 0, 0, 0, 0, 0, 0], CounterBytes, ResourceStates.UnorderedAccess, flags);

if (!job.RootDescriptors)
{
recording.CreateRawUav(vertices, job.VertexBytes / 4, FallbackSlot);
recording.CreateRawUav(indices, job.IndexBytes / 4, FallbackSlot + 1);
recording.CreateRawUav(counter, CounterBytes / 4, FallbackSlot + 2);
recording.CreateRawSrv(vertices, job.VertexBytes / 4, FallbackSlot + 3);
}
recording.CreateRawUav(vertices, job.VertexBytes / 4, FallbackSlot);
recording.CreateRawUav(indices, job.IndexBytes / 4, FallbackSlot + 1);
recording.CreateRawUav(counter, CounterBytes / 4, FallbackSlot + 2);
recording.CreateRawSrv(vertices, job.VertexBytes / 4, FallbackSlot + 3);

return (vertices, indices, counter);
}

private static void BindFallback(
Recording recording, MeshFallbackJob job, (ID3D12Resource Vertices, ID3D12Resource Indices, ID3D12Resource Counter) buffers, bool compute)
{
var list = recording.List;

if (!job.RootDescriptors && compute)
{
list.SetComputeRootDescriptorTable(1, recording.ResourceTable(FallbackSlot));
}
else if (!job.RootDescriptors)
{
list.SetGraphicsRootDescriptorTable(1, recording.ResourceTable(FallbackSlot));
}
else if (compute)
{
list.SetComputeRootUnorderedAccessView(1, buffers.Vertices.GPUVirtualAddress);
list.SetComputeRootUnorderedAccessView(2, buffers.Indices.GPUVirtualAddress);
list.SetComputeRootUnorderedAccessView(3, buffers.Counter.GPUVirtualAddress);
}
else
{
list.SetGraphicsRootShaderResourceView(4, buffers.Vertices.GPUVirtualAddress);
}
}

private void DrawIndirect(
Recording recording, MeshFallbackJob job, (ID3D12Resource Vertices, ID3D12Resource Indices, ID3D12Resource Counter) buffers)
{
Expand Down