Merge hands/cultmath-shader-conforming-run (verdicts s1, s2)

This commit is contained in:
Meta Vens 2026-10-16 23:33:53 +02:00
commit 4bf6e6750c
10 changed files with 1276 additions and 13 deletions

View file

@ -194,6 +194,12 @@ class. SPIRV-Cross emits Metal Shading Language from SPIR-V on Windows; building
an iPad-ready `.metallib` still belongs to Apple's Metal compiler on an Apple
toolchain.
The lavapipe conforming run executes every fixture family through the HLSL (dxc) and the committed GLSL
(glslang) on Mesa lavapipe and judges the results in `GlslMirrorTests.DeviceResultsHoldFixture`. It needs a Linux
container with apt: from the repo root, `tools/stopgap/ygg-verify.sh <repo> <rev> mcr.microsoft.com/dotnet/sdk:10.0
'bash packages/cultmath/tools/device/run-lavapipe.sh'`. `WRITE_BOUNDS=1` in front of the script re-records the
device's bounds file and prints it between `BOUNDS-BEGIN` and `BOUNDS-END`.
## Doctrine
The goal is mechanical sympathy between CPU-side authoring, native kernels, and

View file

@ -214,6 +214,12 @@ test, bit for bit; GLSL against C# by the golden fixture, which records 256
seeded cases per function family as float32 bit patterns, evaluated by the
consumer on WebGL2 and read back. The families `pcg3d` and `pcg4d` are marked
exact; the float families are ulp-bounded, the bound measured on the device.
A conforming leg runs every fixture family through both routes on a device: `tools/device/run-lavapipe.sh`
compiles the HLSL with dxc and the committed GLSL with glslang, dispatches each family on Mesa lavapipe, and
`GlslMirrorTests.DeviceResultsHoldFixture` judges the results. Exact and integer families must match bit for bit,
families with a check pass their `Verify`, the sampled-form families are checked on the device's own noise values,
and every other family is held to the worst error recorded for that device in
`tests/CultMath.Tests/fixtures/device-bounds-lavapipe.txt`.
`iv_frustum_ball` is ulp-bounded, not exact: it calls `sqrt`, which GLSL ES
3.00 does not require to be correctly rounded, and WebGL2 compilers may
@ -260,17 +266,19 @@ name the platform that generated them and the test compares them case by case
against the running platform, printing the largest distance. `iv_exp`
("ulp-bounded, platform exp") must agree within one ulp. `phacelle`
("ulp-bounded, platform exp, sin, cos; across platforms |diff| <= 2^-20
max(|v|, 1)") must agree within `2^-20 max(|v|, 1)` per component, `v` being
max(|v|, 1); on a device |diff| <= 2^-18 max(|v|, 1)") must agree across
platforms within `2^-20 max(|v|, 1)` per component, `v` being
the fixture's value: its sums of `exp`, `sin` and `cos` cancel near zero, where
ulps mean nothing, and Windows differs from the Linux fixture by up to
`3.6e-7 max(|v|, 1)`. Every other family is compared as text. `phacelle` is in
`3.6e-7 max(|v|, 1)`. The device clause is `2^-18` because the devices measured
are farther: lavapipe is `2.2e-6 max(|v|, 1)` and the GTX 1070 `3.1e-6`; the conforming
run judges it. Every other family is compared as text. `phacelle` is in
`CultMath.Phacelle.glsl`, so the evaluator concatenates
`CultMath.Phacelle.glsl` after `CultMath.glsl` for that family, with
normalization 0.5. The site does not vendor the MPL file and skips the family.
Its evaluator is the cultmath-tapes follow-up `glsl-browser-parity-run`, owned
by the next CultMath parity cut: a repeatable CultLib WebGL2 run of every
fixture family, `phacelle` included. Until it lands, the one GLSL evaluation of
`phacelle` is a single probe (GTX 1070, ANGLE D3D11: within `3.1e-6 max(|v|, 1)`
Its evaluator is the lavapipe GLSL route of the conforming run above, which covers
every fixture family, `phacelle` included. The real-device leg (ANGLE D3D11 on the GTX 1070)
is the later cut `angle-capture`; the one GLSL evaluation of `phacelle` on that device is a single probe (GTX 1070, ANGLE D3D11: within `3.1e-6 max(|v|, 1)`
of C#). Asura's `gpu-snoise-parity` is a different check, an FXC and Unity
readback of `snoise`, and evaluates no GLSL.

View file

@ -0,0 +1,701 @@
using System.Globalization;
using System.Text.Json.Nodes;
using CultMath;
using Xunit;
using Xunit.Sdk;
namespace CultMath.Tests;
/// <summary>
/// The conforming run's C# half. <see cref="WriteWork"/> says what a device must compute: every fixture
/// family on the fixture's own arguments, plus one reference family for each sampled-form family, whose
/// points are the ones the form check evaluates. <see cref="JudgeDevice"/> says whether a device's results
/// hold: exact and integer families bit for bit, check families by their Verify, sampled-form families by
/// the form check on the device's own reference values, every other family within its recorded bound.
/// The generator, the Vulkan host and the job script only spell, dispatch and run; they compare nothing.
/// </summary>
public sealed partial class GlslMirrorTests
{
private static readonly string[] DeviceRoutes = { "lavapipe-hlsl", "lavapipe-glsl" };
private static string BoundsPath => Path.Combine(Root, "tests", "CultMath.Tests", "fixtures", "device-bounds-lavapipe.txt");
private static string? Env(string name) => Environment.GetEnvironmentVariable(name) is { Length: > 0 } value ? value : null;
private static JsonArray FixtureFamilies() => JsonNode.Parse(File.ReadAllText(FixturePath))!["functions"]!.AsArray();
private static string[] Sides(JsonNode? entry) => ((string)entry!).Split(" -> ");
private static uint[] DevWords(string hex) => hex.Split(' ').Select(h => Convert.ToUInt32(h, 16)).ToArray();
private static string DevHex(IEnumerable<uint> words) => string.Join(' ', words.Select(w => w.ToString("x8")));
private static uint[] ReadWords(string path)
{
var bytes = File.ReadAllBytes(path);
var words = new uint[bytes.Length / 4];
for (var i = 0; i < words.Length; i++)
words[i] = BitConverter.ToUInt32(bytes, i * 4);
return words;
}
private static void WriteWords(string path, IEnumerable<uint> words)
{
using var writer = new BinaryWriter(File.Create(path));
foreach (var word in words)
writer.Write(word);
}
private static bool IsSampledForm(Family family) =>
family.Check is not null && (family.Glsl.Contains("cultmath_af_snoise(") || family.Glsl.Contains("cultmath_af_fbm("));
private static string Tag(int family) => $"f{family:D3}";
private static string RefTag(int family) => $"r{family:D3}";
private sealed record WorkItem(string Tag, string Index, string Glsl, int N, int WordsIn, int WordsOut);
// ---- What a device must compute ----
private static List<WorkItem> WriteWork(string dir)
{
Directory.CreateDirectory(dir);
var fixture = FixtureFamilies();
Assert.Equal(Families.Length, fixture.Count);
var items = new List<WorkItem>();
for (var f = 0; f < Families.Length; f++)
{
Assert.Equal(Families[f].Glsl, (string?)fixture[f]!["glsl"]);
var cases = fixture[f]!["cases"]!.AsArray();
WriteWords(Path.Combine(dir, Tag(f) + ".in"), cases.SelectMany(c => DevWords(Sides(c)[0])));
items.Add(new WorkItem(Tag(f), f.ToString(CultureInfo.InvariantCulture), Families[f].Glsl, cases.Count, DevWords(Sides(cases[0])[0]).Length, DevWords(Sides(cases[0])[1]).Length));
if (IsSampledForm(Families[f]))
items.Add(WriteReference(dir, f, cases));
}
File.WriteAllLines(Path.Combine(dir, "manifest.txt"), items.Select(i => string.Join('\t', i.Tag, i.Index, i.Glsl, i.N, i.WordsIn, i.WordsOut)));
return items;
}
// The points the form check evaluates the reference at, in the order it evaluates them: the reference
// func records p, and for fBm the case's octaves, lacunarity and gain, then answers as C# does.
private static WorkItem WriteReference(string dir, int family, JsonArray cases)
{
var fbm = Families[family].Glsl.Contains("cultmath_af_fbm(");
var recorded = new List<uint>();
Func<string[], float3, float> recorder = (t, p) =>
{
recorded.AddRange(new[] { BitConverter.SingleToUInt32Bits(p.x), BitConverter.SingleToUInt32Bits(p.y), BitConverter.SingleToUInt32Bits(p.z) });
if (fbm)
recorded.AddRange(t[7..10].Select(h => Convert.ToUInt32(h, 16)));
return fbm ? FbmReference(t, p) : SnoiseReference(t, p);
};
if (fbm)
AssertFbmForm(cases, false, recorder);
else
AssertSnoiseForm(cases, false, recorder);
var wordsIn = fbm ? 6 : 3;
WriteWords(Path.Combine(dir, RefTag(family) + ".in"), recorded);
return new WorkItem(RefTag(family), "ref:" + family.ToString(CultureInfo.InvariantCulture),
fbm ? "vec4 cultmath_fbm_grad(vec3, int, float, float)" : "float cultmath_snoise(vec3)", recorded.Count / wordsIn, wordsIn, fbm ? 4 : 1);
}
[Fact]
public void WriteDeviceWork()
{
var dir = Env("CULTMATH_DEVICE_WORK");
Assert.SkipUnless(dir is not null, "CULTMATH_DEVICE_WORK=<dir> writes the work list a device runs");
var items = WriteWork(dir!);
output.WriteLine($"{items.Count} work items ({items.Count(i => i.Index.StartsWith("ref:"))} reference families) in {dir}");
}
// ---- Whether a device's results hold ----
private sealed record BoundRow(string Route, int Index, string Glsl, string Tolerance, int Exact, double Worst, int NanClass, string Bits);
private sealed record Measured(BoundRow Row, string Class);
private sealed record Judgement(List<string> Failures, List<Measured> Rows);
// Which words of a family's result are floats; the rest are integers and must match bit for bit.
private static IEnumerable<bool> FloatWords(Type type) =>
type == typeof(float) ? new[] { true }
: type == typeof(int) || type == typeof(uint) ? new[] { false }
: type == typeof(float3x3) ? Enumerable.Repeat(true, 9)
: type.GetFields().Where(f => !f.IsStatic).SelectMany(f => FloatWords(f.FieldType));
// u1 = |device - fixture| / max(|fixture|, 1) / 2^-23 per float component, worst over the family; NaN and
// Inf are compared as classes (NaN against not-NaN, an Inf against anything else), never by value.
private static (int Exact, double Worst, int NanClass) Measure(JsonArray cases, bool[] floatWord, uint[] got)
{
int exact = 0, nanClass = 0;
var worst = 0.0;
var wordsOut = floatWord.Length;
for (var c = 0; c < cases.Count; c++)
{
var want = DevWords(Sides(cases[c])[1]);
var same = true;
for (var w = 0; w < wordsOut; w++)
{
var have = got[c * wordsOut + w];
if (have == want[w])
continue;
same = false;
if (!floatWord[w])
{
nanClass++;
continue;
}
var e = BitConverter.UInt32BitsToSingle(want[w]);
var h = BitConverter.UInt32BitsToSingle(have);
if (float.IsNaN(e) || float.IsNaN(h))
nanClass += float.IsNaN(e) == float.IsNaN(h) ? 0 : 1;
else if (float.IsInfinity(e) || float.IsInfinity(h))
nanClass += e == h ? 0 : 1;
else
worst = Math.Max(worst, Math.Abs((double)e - h) / Math.Max(Math.Abs((double)e), 1.0) / Math.ScaleB(1.0, -23));
}
if (same)
exact++;
}
return (exact, worst, nanClass);
}
// The device's own reference values, in the order WriteReference recorded their points. The check asks
// for the reference at a point; the point it asks for must be the one the device was given at that place.
private static Func<string[], float3, float> DeviceReference(string work, string routeResults, WorkItem reference)
{
var points = ReadWords(Path.Combine(work, reference.Tag + ".in"));
var values = ReadWords(Path.Combine(routeResults, reference.Tag + ".out"));
Assert.Equal(reference.N * reference.WordsOut, values.Length);
var next = 0;
return (_, p) =>
{
Assert.True(next < reference.N, "reference point asked for past the recorded work");
var at = next * reference.WordsIn;
Assert.True(points[at] == BitConverter.SingleToUInt32Bits(p.x) && points[at + 1] == BitConverter.SingleToUInt32Bits(p.y) && points[at + 2] == BitConverter.SingleToUInt32Bits(p.z),
$"reference point {next} is not the point the device was given");
return BitConverter.UInt32BitsToSingle(values[next++ * reference.WordsOut + reference.WordsOut - 1]);
};
}
// sha256 of the family's result bytes, and of its reference result when it is judged on one.
private static string ResultBits(string path, string? reference)
{
var bytes = File.ReadAllBytes(path);
if (reference is not null)
bytes = bytes.Concat(File.ReadAllBytes(reference)).ToArray();
return Convert.ToHexString(System.Security.Cryptography.SHA256.HashData(bytes)).ToLowerInvariant();
}
// A tolerance text may state what a device is allowed: "on a device |diff| <= 2^-N max(|v|, 1)", which in
// u1 units (2^-23) is 2^(23-N). The judge reads it here and nowhere else.
private static double? StatedDeviceLimit(string tolerance)
{
var m = System.Text.RegularExpressions.Regex.Match(tolerance, @"on a device \|diff\| <= 2\^-(\d+) max\(\|v\|, 1\)");
return m.Success ? Math.ScaleB(1.0, 23 - int.Parse(m.Groups[1].Value)) : null;
}
private static string FirstLine(Exception e)
{
var line = e.Message.Split('\n')[0];
return line.Length > 300 ? line[..300] : line;
}
private static Judgement JudgeDevice(string work, string results, string renderer, string identity, string boundsPath, bool write)
{
var failures = new List<string>();
var measured = new List<Measured>();
Dictionary<(string, int), BoundRow>? recorded = null;
if (!write)
{
if (!File.Exists(boundsPath))
return new Judgement(new List<string> { "no recorded device bounds; record them with CULTMATH_WRITE_DEVICE_BOUNDS=1" }, measured);
var (header, rows) = ReadBounds(boundsPath);
if (header.GetValueOrDefault("renderer") != renderer || header.GetValueOrDefault("identity") != identity)
return new Judgement(new List<string> { "the device or its toolchain is not the one the bounds were recorded on; re-record them with CULTMATH_WRITE_DEVICE_BOUNDS=1" }, measured);
recorded = rows;
}
var fixture = FixtureFamilies();
var items = File.ReadAllLines(Path.Combine(work, "manifest.txt")).Select(l => l.Split('\t'))
.ToDictionary(c => c[1], c => new WorkItem(c[0], c[1], c[2], int.Parse(c[3]), int.Parse(c[4]), int.Parse(c[5])));
foreach (var route in DeviceRoutes)
for (var f = 0; f < Families.Length; f++)
{
var family = Families[f];
var cases = fixture[f]!["cases"]!.AsArray();
var name = $"{route} #{f} {family.Glsl}";
var path = Path.Combine(results, route, Tag(f) + ".out");
if (!File.Exists(path))
{
failures.Add($"{name}: missing {Tag(f)}.out");
continue;
}
var floatWord = FloatWords(Resolve(family.Glsl).ReturnType).ToArray();
var got = ReadWords(path);
if (got.Length != cases.Count * floatWord.Length)
{
failures.Add($"{name}: {Tag(f)}.out holds {got.Length} words, not {cases.Count * floatWord.Length}");
continue;
}
var (exact, worst, nanClass) = Measure(cases, floatWord, got);
var bits = ResultBits(path, IsSampledForm(family) ? Path.Combine(results, route, RefTag(f) + ".out") : null);
var exactClass = family.Tolerance == "exact" || !floatWord.Any(w => w);
var kind = exactClass ? "exact" : IsSampledForm(family) ? "sampled" : family.Verify is not null ? "check" : "bound";
measured.Add(new Measured(new BoundRow(route, f, family.Glsl, family.Tolerance, exact, worst, nanClass, bits), kind));
try
{
if (exactClass)
Assert.True(exact == cases.Count, $"{exact} of {cases.Count} cases are bit-identical to the fixture");
else if (kind == "sampled")
{
var reference = DeviceReference(work, Path.Combine(results, route), items["ref:" + f]);
if (family.Glsl.Contains("cultmath_af_fbm("))
AssertFbmForm(cases, false, reference);
else
AssertSnoiseForm(cases, false, reference);
}
else if (kind == "check")
family.Verify!(new JsonArray(cases.Select((c, i) => (JsonNode)JsonValue.Create(Sides(c)[0] + " -> " + DevHex(got.Skip(i * floatWord.Length).Take(floatWord.Length)))!).ToArray()));
}
catch (XunitException e)
{
failures.Add($"{name}: {FirstLine(e)}");
}
}
if (write)
{
WriteBounds(boundsPath, renderer, identity, measured.Select(m => m.Row));
recorded = measured.ToDictionary(m => (m.Row.Route, m.Row.Index), m => m.Row);
}
foreach (var m in measured)
{
var name = $"{m.Row.Route} #{m.Row.Index} {m.Row.Glsl}";
if (!recorded!.TryGetValue((m.Row.Route, m.Row.Index), out var bound))
failures.Add($"{name}: no recorded row; re-record with CULTMATH_WRITE_DEVICE_BOUNDS=1");
else if (bound.Glsl != m.Row.Glsl || bound.Tolerance != m.Row.Tolerance)
failures.Add($"{name}: the recorded row is for another family; re-record with CULTMATH_WRITE_DEVICE_BOUNDS=1");
else if (m.Class == "bound" && (m.Row.Worst > bound.Worst || m.Row.NanClass > bound.NanClass))
failures.Add($"{name}: worst u1 {m.Row.Worst:R} and {m.Row.NanClass} NaN-class mismatches, past the recorded {bound.Worst:R} and {bound.NanClass}");
else if (m.Class == "bound" && StatedDeviceLimit(m.Row.Tolerance) is { } limit && m.Row.Worst > limit)
failures.Add($"{name}: worst u1 {m.Row.Worst:R}, past the {limit:R} its stated tolerance allows a device");
else if (m.Row.Bits != bound.Bits && !failures.Any(x => x.StartsWith(name + ":")))
failures.Add($"{name}: the result bits differ from the recorded run's; if the change is meant, re-record with CULTMATH_WRITE_DEVICE_BOUNDS=1");
}
return new Judgement(failures, measured);
}
// ---- The recorded bounds: plain text, tab-separated, one row per route and family ----
private static void WriteBounds(string path, string renderer, string identity, IEnumerable<BoundRow> rows)
{
var lines = new List<string>
{
"# renderer\t" + renderer,
"# identity\t" + identity,
"# route\tindex\tglsl\ttolerance\texact cases\tworst u1\tNaN-class mismatches result sha256; written only by CULTMATH_WRITE_DEVICE_BOUNDS=1",
};
lines.AddRange(rows.OrderBy(r => r.Route, StringComparer.Ordinal).ThenBy(r => r.Index)
.Select(r => string.Join('\t', r.Route, r.Index, r.Glsl, r.Tolerance, r.Exact, r.Worst.ToString("R", CultureInfo.InvariantCulture), r.NanClass, r.Bits)));
File.WriteAllText(path, string.Join('\n', lines) + "\n");
}
private static (Dictionary<string, string> Header, Dictionary<(string, int), BoundRow> Rows) ReadBounds(string path)
{
var header = new Dictionary<string, string>();
var rows = new Dictionary<(string, int), BoundRow>();
foreach (var line in File.ReadAllLines(path))
{
var c = line.Split('\t');
if (line.StartsWith("# renderer\t") || line.StartsWith("# identity\t"))
header[c[0][2..]] = c[1];
else if (!line.StartsWith('#') && line.Length > 0)
rows[(c[0], int.Parse(c[1]))] = new BoundRow(c[0], int.Parse(c[1]), c[2], c[3], int.Parse(c[4]), double.Parse(c[5], CultureInfo.InvariantCulture), int.Parse(c[6]), c[7]);
}
return (header, rows);
}
[Fact]
public void DeviceResultsHoldFixture()
{
var results = Env("CULTMATH_DEVICE_RESULTS");
Assert.SkipUnless(results is not null, "CULTMATH_DEVICE_RESULTS=<dir> (holding <route>/<tag>.out) judges a device's results");
var work = Env("CULTMATH_DEVICE_WORK");
var renderer = Env("CULTMATH_DEVICE_NAME");
var identity = Env("CULTMATH_DEVICE_IDENTITY");
Assert.True(work is not null && renderer is not null && identity is not null, "CULTMATH_DEVICE_WORK, CULTMATH_DEVICE_NAME and CULTMATH_DEVICE_IDENTITY are required beside CULTMATH_DEVICE_RESULTS");
var judgement = JudgeDevice(work!, results!, renderer!, identity!, BoundsPath, Env("CULTMATH_WRITE_DEVICE_BOUNDS") == "1");
foreach (var route in DeviceRoutes)
{
var rows = judgement.Rows.Where(m => m.Row.Route == route).ToList();
output.WriteLine($"{route}: {rows.Count} families judged: " + string.Join(", ", rows.GroupBy(m => m.Class).OrderBy(g => g.Key).Select(g => $"{g.Count()} {g.Key}")));
foreach (var m in rows.OrderByDescending(m => m.Row.Worst).Take(5))
output.WriteLine($" worst u1 {m.Row.Worst:R}, {m.Row.NanClass} NaN-class: #{m.Row.Index} {m.Row.Glsl} ({m.Class})");
}
foreach (var failure in judgement.Failures.Take(60))
output.WriteLine("FAIL " + failure);
Assert.True(judgement.Failures.Count == 0, $"{judgement.Failures.Count} device results do not hold the fixture; first: {judgement.Failures.FirstOrDefault()}");
}
// ---- The judge against simulated devices ----
// A faithful device answers the fixture's own result bits and, for a reference family, C#'s snoise or
// fBm at the recorded points. A test alters what one family or one route answers.
private sealed record Simulated(string Root, string Work, string Results, string Bounds) : IDisposable
{
public void Dispose() => Directory.Delete(Root, true);
}
private static Simulated Simulate(Func<string, WorkItem, uint[], uint[]>? alter = null)
{
var root = Path.Combine(Path.GetTempPath(), "cultmath-device-" + Guid.NewGuid().ToString("N"));
var work = Path.Combine(root, "work");
var items = WriteWork(work);
var fixture = FixtureFamilies();
foreach (var route in DeviceRoutes)
{
Directory.CreateDirectory(Path.Combine(root, "results", route));
foreach (var item in items)
{
uint[] words;
if (item.Index.StartsWith("ref:"))
{
var points = ReadWords(Path.Combine(work, item.Tag + ".in"));
words = new uint[item.N * item.WordsOut];
for (var k = 0; k < item.N; k++)
{
var at = k * item.WordsIn;
var p = new float3(BitConverter.UInt32BitsToSingle(points[at]), BitConverter.UInt32BitsToSingle(points[at + 1]), BitConverter.UInt32BitsToSingle(points[at + 2]));
var tokens = new string[10];
if (item.WordsIn == 6)
for (var t = 0; t < 3; t++)
tokens[7 + t] = points[at + 3 + t].ToString("x8");
words[k * item.WordsOut + item.WordsOut - 1] = BitConverter.SingleToUInt32Bits(item.WordsIn == 6 ? FbmReference(tokens, p) : SnoiseReference(tokens, p));
}
}
else
words = fixture[int.Parse(item.Index)]!["cases"]!.AsArray().SelectMany(c => DevWords(Sides(c)[1])).ToArray();
WriteWords(Path.Combine(root, "results", route, item.Tag + ".out"), alter?.Invoke(route, item, words) ?? words);
}
}
return new Simulated(root, work, Path.Combine(root, "results"), Path.Combine(root, "bounds.txt"));
}
private static Judgement Record(Simulated device) => JudgeDevice(device.Work, device.Results, "test renderer", "test identity", device.Bounds, true);
private static Judgement Judge(Simulated device, Simulated recordedOn, string renderer = "test renderer", string identity = "test identity") =>
JudgeDevice(device.Work, device.Results, renderer, identity, recordedOn.Bounds, false);
// Every case's first result word, altered.
private static uint[] Alter(WorkItem item, uint[] words, Func<uint, uint> change, int cases = int.MaxValue)
{
var altered = (uint[])words.Clone();
for (var c = 0; c < Math.Min(item.N, cases); c++)
altered[c * item.WordsOut] = change(altered[c * item.WordsOut]);
return altered;
}
// A family judged by its recorded bound alone: not exact, not checked, not a sampled form, a float first word.
private static int BoundFamily() =>
Array.FindIndex(Families, f => f.Tolerance == "ulp-bounded" && f.Verify is null && FloatWords(Resolve(f.Glsl).ReturnType).First());
[Fact]
public void AFaithfulDeviceHoldsEveryFamilyOnBothRoutes()
{
using var device = Simulate();
var recorded = Record(device);
Assert.Empty(recorded.Failures);
Assert.Equal(DeviceRoutes.Length * Families.Length, recorded.Rows.Count);
Assert.All(recorded.Rows, m => Assert.Equal(0.0, m.Row.Worst));
Assert.Equal(DeviceRoutes.Length * Families.Count(IsSampledForm), recorded.Rows.Count(m => m.Class == "sampled"));
Assert.Equal(DeviceRoutes.Length * Families.Count(f => f.Tolerance == "exact"), recorded.Rows.Count(m => m.Class == "exact"));
Assert.Empty(Judge(device, device).Failures);
}
[Fact]
public void AnExactFamilyAllowsNoDifferenceAtAll()
{
// Bounds recorded on the very device that is off by one ulp: a bound would pass it, the exact rule must not.
var exact = Array.FindIndex(Families, f => f.Tolerance == "exact");
using var off = Simulate((route, item, words) => route == "lavapipe-glsl" && item.Index == exact.ToString() ? Alter(item, words, w => w ^ 1u) : words);
Record(off);
var failures = Judge(off, off).Failures;
Assert.Single(failures);
Assert.Contains($"lavapipe-glsl #{exact} ", failures[0]);
// One case in 256 is enough.
using var oneCase = Simulate((_, item, words) => item.Index == exact.ToString() ? Alter(item, words, w => w ^ 1u, 1) : words);
Record(oneCase);
Assert.Equal(DeviceRoutes.Length, Judge(oneCase, oneCase).Failures.Count);
}
[Fact]
public void AFamilyIsHeldToItsRecordedWorstAndNotBeyond()
{
var f = BoundFamily();
using var near = Simulate((_, item, words) => item.Index == f.ToString() ? Alter(item, words, w => w ^ 4u) : words);
Record(near);
Assert.Empty(Judge(near, near).Failures);
using var farther = Simulate((_, item, words) => item.Index == f.ToString() ? Alter(item, words, w => w ^ 7u) : words);
var failures = Judge(farther, near).Failures;
Assert.Equal(DeviceRoutes.Length, failures.Count);
Assert.All(failures, line => Assert.Contains($"#{f} ", line));
var lines = File.ReadAllLines(near.Bounds).ToList();
var at = lines.FindIndex(l => l.StartsWith($"lavapipe-hlsl\t{f}\t"));
var row = lines[at].Split('\t');
Assert.NotEqual(0.0, double.Parse(row[5], CultureInfo.InvariantCulture));
row[5] = "0";
lines[at] = string.Join('\t', row);
File.WriteAllLines(near.Bounds, lines);
Assert.Single(Judge(near, near).Failures);
lines.RemoveAt(at);
File.WriteAllLines(near.Bounds, lines);
var missing = Judge(near, near).Failures;
Assert.Single(missing);
Assert.Contains("no recorded row", missing[0]);
}
[Fact]
public void ABoundMeasuresTheErrorAgainstTheFixturesMagnitude()
{
// The metric divides by max(|fixture|, 1): a result of twice a fixture value of at least 2 is 2^23 away,
// and of twice a fixture value under 1 is |fixture| 2^23 away.
var fixture = FixtureFamilies();
float Fixture(int family, int c) => BitConverter.UInt32BitsToSingle(DevWords(Sides(fixture[family]!["cases"]![c])[1])[0]);
int Find(int family, Func<float, bool> wanted) => Enumerable.Range(0, Points).FirstOrDefault(c => wanted(Math.Abs(Fixture(family, c))), -1);
bool Large(float v) => v is >= 2.0f and < 1e30f;
bool Small(float v) => v is > 1e-3f and < 1.0f;
var f = Enumerable.Range(0, Families.Length).First(g => Families[g].Tolerance == "ulp-bounded" && Families[g].Verify is null
&& FloatWords(Resolve(Families[g].Glsl).ReturnType).First() && Find(g, Large) >= 0 && Find(g, Small) >= 0);
var large = Find(f, Large);
var small = Find(f, Small);
foreach (var (c, expected) in new[] { (large, Math.ScaleB(1.0, 23)), (small, Math.Abs((double)Fixture(f, small)) * Math.ScaleB(1.0, 23)) })
{
using var device = Simulate((_, item, words) =>
{
if (item.Index != f.ToString())
return words;
var doubled = (uint[])words.Clone();
doubled[c * item.WordsOut] = BitConverter.SingleToUInt32Bits(2.0f * BitConverter.UInt32BitsToSingle(words[c * item.WordsOut]));
return doubled;
});
Assert.Equal(expected, Record(device).Rows.First(m => m.Row.Route == "lavapipe-hlsl" && m.Row.Index == f).Row.Worst);
}
}
[Fact]
public void ANaNWhereTheFixtureHasANumberFailsAFamilyRecordedWithout()
{
var f = BoundFamily();
using var faithful = Simulate();
Record(faithful);
using var nan = Simulate((_, item, words) => item.Index == f.ToString() ? Alter(item, words, _ => 0x7fc00000u) : words);
var failures = Judge(nan, faithful).Failures;
Assert.Equal(DeviceRoutes.Length, failures.Count);
Assert.All(failures, line => Assert.Contains("NaN-class", line));
}
[Fact]
public void AMissingOutputFailsOnlyItsFamily()
{
using var device = Simulate();
Record(device);
File.Delete(Path.Combine(device.Results, "lavapipe-hlsl", Tag(3) + ".out"));
var failures = Judge(device, device).Failures;
Assert.Single(failures);
Assert.Contains("missing", failures[0]);
Assert.Contains("lavapipe-hlsl #3 ", failures[0]);
}
[Fact]
public void ADeviceOrToolchainOtherThanTheRecordedOneIsRefusedBeforeJudging()
{
using var device = Simulate();
Record(device);
foreach (var (renderer, identity) in new[] { ("another renderer", "test identity"), ("test renderer", "another toolchain") })
{
var judgement = Judge(device, device, renderer, identity);
Assert.Single(judgement.Failures);
Assert.Empty(judgement.Rows);
}
}
[Theory]
[InlineData("cultmath_af_snoise(")]
[InlineData("cultmath_af_fbm(")]
public void ASampledFormIsJudgedOnTheDevicesOwnReferenceAtTheRecordedPoints(string function)
{
var sampled = Array.FindIndex(Families, f => IsSampledForm(f) && f.Glsl.Contains(function));
using var faithful = Simulate();
Record(faithful);
// A reference that answers wrongly puts the form's enclosure out of reach.
using var wrong = Simulate((_, item, words) => item.Index == "ref:" + sampled
? words.Select(w => BitConverter.SingleToUInt32Bits(BitConverter.UInt32BitsToSingle(w) + 100.0f)).ToArray() : words);
var failures = Judge(wrong, faithful).Failures;
Assert.Equal(DeviceRoutes.Length, failures.Count);
Assert.All(failures, line => Assert.Contains($"#{sampled} ", line));
// Two points in the other order: the device's i-th answer is not for the point the check asks about.
using var swapped = Simulate();
var path = Path.Combine(swapped.Work, RefTag(sampled) + ".in");
var stride = function.Contains("fbm") ? 6 : 3;
var points = ReadWords(path);
(points[0], points[stride]) = (points[stride], points[0]);
WriteWords(path, points);
var order = Judge(swapped, faithful).Failures;
Assert.Equal(DeviceRoutes.Length, order.Count);
Assert.All(order, line => Assert.Contains("not the point the device was given", line));
}
[Fact]
public void AnInfinityWhereTheFixtureHasAnotherValueIsAMismatchOfClass()
{
var fixture = FixtureFamilies();
int f = -1, c = 0, w = 0;
for (var g = 0; g < Families.Length && f < 0; g++)
{
if (Families[g].Tolerance == "exact" || Families[g].Verify is not null)
continue;
var floatWord = FloatWords(Resolve(Families[g].Glsl).ReturnType).ToArray();
for (var k = 0; k < Points && f < 0; k++)
{
var want = DevWords(Sides(fixture[g]!["cases"]![k])[1]);
for (var at = 0; at < want.Length && f < 0; at++)
if (floatWord[at] && float.IsInfinity(BitConverter.UInt32BitsToSingle(want[at])))
(f, c, w) = (g, k, at);
}
}
Assert.True(f >= 0, "no fixture family holds an infinite result");
using var faithful = Simulate();
Record(faithful);
using var finite = Simulate((_, item, words) =>
{
if (item.Index != f.ToString())
return words;
var altered = (uint[])words.Clone();
altered[c * item.WordsOut + w] = BitConverter.SingleToUInt32Bits(1.0f);
return altered;
});
var failures = Judge(finite, faithful).Failures;
Assert.Equal(DeviceRoutes.Length, failures.Count);
Assert.All(failures, line => Assert.Contains("NaN-class", line));
}
[Fact]
public void ARecordedRowForAnotherFamilyIsRefused()
{
using var device = Simulate();
Record(device);
var lines = File.ReadAllLines(device.Bounds).ToList();
var at = lines.FindIndex(l => l.StartsWith("lavapipe-glsl 5 "));
var row = lines[at].Split(' ');
row[2] = "float cultmath_other(float)";
lines[at] = string.Join(' ', row);
File.WriteAllLines(device.Bounds, lines);
var failures = Judge(device, device).Failures;
Assert.Single(failures);
Assert.Contains("another family", failures[0]);
}
[Fact]
public void ACheckFamilyIsJudgedByItsVerify()
{
var f = Array.FindIndex(Families, fam => fam.Verify is not null && !IsSampledForm(fam));
using var faithful = Simulate();
Record(faithful);
using var broken = Simulate((_, item, words) => item.Index == f.ToString() ? words.Select(_ => 0x7fc00000u).ToArray() : words);
var failures = Judge(broken, faithful).Failures;
Assert.Equal(DeviceRoutes.Length, failures.Count);
Assert.All(failures, line => Assert.Contains($"#{f} ", line));
}
[Fact]
public void AChangeInResultBitsFailsEvenWithinTheRecordedBound()
{
// Recorded on a device off in every case; judged on one off in a single case. The bound holds, the bits do not.
var f = BoundFamily();
using var recorded = Simulate((_, item, words) => item.Index == f.ToString() ? Alter(item, words, w => w ^ 4u) : words);
Record(recorded);
using var fewer = Simulate((_, item, words) => item.Index == f.ToString() ? Alter(item, words, w => w ^ 4u, 1) : words);
var failures = Judge(fewer, recorded).Failures;
Assert.Equal(DeviceRoutes.Length, failures.Count);
Assert.All(failures, line => { Assert.Contains($"#{f} ", line); Assert.Contains("result bits differ", line); });
}
[Fact]
public void AFamilyIsHeldToTheDeviceToleranceItsOwnTextStates()
{
// Recorded on the very device that violates it: only the stated tolerance can fail the family.
var f = Array.FindIndex(Families, fam => StatedDeviceLimit(fam.Tolerance) is not null);
Assert.True(f >= 0, "no family states a device tolerance");
using var far = Simulate((_, item, words) => item.Index == f.ToString() ? Alter(item, words, w => w ^ 0x00100000u) : words);
Record(far);
var failures = Judge(far, far).Failures;
Assert.Equal(DeviceRoutes.Length, failures.Count);
Assert.All(failures, line => Assert.Contains("stated tolerance", line));
}
[Theory]
[InlineData(24, true)]
[InlineData(40, false)]
public void TheStatedDeviceToleranceIsTheLimitInUlpsOfTheFixturesMagnitude(int ulps, bool holds)
{
// 2^-18 max(|v|, 1) is 32 u1. A fixture value in [1, 1.1) moved by k ulps is k/|v| u1 away, 0.91 k to k.
var f = Array.FindIndex(Families, fam => StatedDeviceLimit(fam.Tolerance) is not null);
Assert.Equal(32.0, StatedDeviceLimit(Families[f].Tolerance));
var fixture = FixtureFamilies()[f]!["cases"]!.AsArray();
var floatWord = FloatWords(Resolve(Families[f].Glsl).ReturnType).ToArray();
var at = -1;
for (var c = 0; c < fixture.Count && at < 0; c++)
{
var want = DevWords(Sides(fixture[c])[1]);
for (var w = 0; w < want.Length && at < 0; w++)
if (floatWord[w] && Math.Abs(BitConverter.UInt32BitsToSingle(want[w])) is >= 1.0f and < 1.1f)
at = c * want.Length + w;
}
Assert.True(at >= 0, "no fixture value of the family lies in [1, 1.1)");
using var device = Simulate((_, item, words) =>
{
if (item.Index != f.ToString())
return words;
var moved = (uint[])words.Clone();
moved[at] += (uint)ulps; // magnitude grows by k ulps whatever the sign
return moved;
});
Record(device);
var failures = Judge(device, device).Failures;
Assert.Equal(holds ? 0 : DeviceRoutes.Length, failures.Count);
}
[Fact]
public void AChangeInTheReferenceBitsOfASampledFormFailsItsFamily()
{
// One ulp in one reference value stays inside the form's enclosure, so only the recorded bits can see it.
var sampled = Array.FindIndex(Families, IsSampledForm);
using var faithful = Simulate();
Record(faithful);
using var moved = Simulate((_, item, words) => item.Index == "ref:" + sampled ? Alter(item, words, w => w + 1u, 1) : words);
var failures = Judge(moved, faithful).Failures;
Assert.Equal(DeviceRoutes.Length, failures.Count);
Assert.All(failures, line => { Assert.Contains($"#{sampled} ", line); Assert.Contains("result bits differ", line); });
}
}

View file

@ -0,0 +1,56 @@
using System.Text.RegularExpressions;
using Xunit;
namespace CultMath.Tests;
public sealed partial class GlslMirrorTests
{
// Tripwire: lavapipe and desktop ANGLE ignore mediump and min16float, so a reduced-precision qualifier in the
// committed shaders would change the computation on a phone GPU and nowhere the conforming run can see it.
// Stated limits: a syntax guardrail only. It reads whole words in the committed .glsl and .hlsl under shaders/
// with comments removed; it does not see a qualifier spelled through a macro, an include or a generated
// shader, and it says nothing about a driver that relaxes highp itself. It names file and line, never text.
private static readonly Regex ReducedPrecision = new(
@"\b(mediump|lowp|min(10|12|16)(float|int|uint)[1-4]?(x[1-4])?|half[1-4]?(x[1-4])?)\b|\bprecision\s+(?!highp\b)\w+", RegexOptions.Compiled);
private static IEnumerable<int> ReducedPrecisionLines(string source)
{
var text = Regex.Replace(source, @"/\*.*?\*/", m => new string('\n', m.Value.Count(c => c == '\n')), RegexOptions.Singleline);
var lines = text.Split('\n');
for (var i = 0; i < lines.Length; i++)
{
var code = lines[i].Split("//")[0];
if (ReducedPrecision.IsMatch(code))
yield return i + 1;
}
}
[Fact]
public void CommittedShadersCarryNoReducedPrecisionQualifier()
{
var found = new List<string>();
foreach (var file in Directory.EnumerateFiles(Path.Combine(Root, "shaders")).Where(f => f.EndsWith(".glsl") || f.EndsWith(".hlsl")).OrderBy(f => f, StringComparer.Ordinal))
found.AddRange(ReducedPrecisionLines(File.ReadAllText(file)).Select(line => $"{Path.GetFileName(file)}:{line}"));
Assert.True(found.Count == 0, "reduced-precision qualifier at " + string.Join(", ", found));
}
[Theory]
[InlineData("mediump float x;", true)]
[InlineData("lowp vec3 c;", true)]
[InlineData("precision mediump float;", true)]
[InlineData("precision highp float;", false)]
[InlineData("min16float x;", true)]
[InlineData("min10float2 x;", true)]
[InlineData("min16int i;", true)]
[InlineData("half3x3 m;", true)]
[InlineData("float half_width;", false)]
[InlineData("float x; // mediump is not used", false)]
[InlineData("/* half\n min16float */ float x;", false)]
public void TheTripwireReadsQualifiersAndNotComments(string source, bool trips) => Assert.Equal(trips, ReducedPrecisionLines(source).Any());
[Fact]
public void TheTripwireNamesTheLine()
{
Assert.Equal(new[] { 3 }, ReducedPrecisionLines("float a;\n/* c */\nmediump float b;\n").ToArray());
}
}

View file

@ -16,7 +16,7 @@ namespace CultMath.Tests;
/// CULTMATH_WRITE_GLSL=1 set, the first and last tests write the committed files before comparing, which
/// is the one regeneration path.
/// </summary>
public sealed class GlslMirrorTests
public sealed partial class GlslMirrorTests
{
private readonly ITestOutputHelper output;
@ -361,13 +361,17 @@ static int4 clamp(int4 x, int4 a, int4 b) { if (a.x > b.x || a.y > b.y || a.z >
return sum;
}
private static string AssertSnoiseForm(JsonArray cases, bool allowanceDecides = false) =>
AssertSampledForm(cases, "af_snoise", (_, p) => math.snoise(p),
private static float SnoiseReference(string[] tokens, float3 p) => math.snoise(p);
private static float FbmReference(string[] t, float3 p) => math.fbm_grad(p, (int)Convert.ToUInt32(t[7], 16), (float)Floats(t[8])[0], (float)Floats(t[9])[0]).w;
private static string AssertSnoiseForm(JsonArray cases, bool allowanceDecides = false, Func<string[], float3, float>? reference = null) =>
AssertSampledForm(cases, "af_snoise", reference ?? SnoiseReference,
(_, a) => SnoiseOctave(SnoiseWidthBound, a, 1.0), (_, a) => SnoiseOctave(SnoiseAllowance, a, 1.0), allowanceDecides);
private static string AssertFbmForm(JsonArray cases, bool allowanceDecides = false) =>
private static string AssertFbmForm(JsonArray cases, bool allowanceDecides = false, Func<string[], float3, float>? reference = null) =>
AssertSampledForm(cases, "af_fbm",
(t, p) => math.fbm_grad(p, (int)Convert.ToUInt32(t[7], 16), (float)Floats(t[8])[0], (float)Floats(t[9])[0]).w,
reference ?? FbmReference,
(t, a) => FbmOctaves(t, a, SnoiseWidthBound), (t, a) => FbmOctaves(t, a, SnoiseAllowance), allowanceDecides);
// AffineFrustumBall applied to C#'s own results.
@ -682,7 +686,7 @@ static int4 clamp(int4 x, int4 a, int4 b) { if (a.x > b.x || a.y > b.y || a.z >
return new object[] { slope, z0, z0 + Uniform(r, 0.01f, 50.0f), Uniform(r, 0.0001f, 0.05f), Uniform(r, 0.0f, 2.0f) };
}, FrustumBall, Verify: AssertFrustumBall),
new("vec2 cultmath_iv_exp(vec2)", "ulp-bounded, platform exp", r => new object[] { Interval(r) }, Platform: Platform.Ulp),
new("CultPhasor cultmath_phacelle(vec3, vec3, float, float)", "ulp-bounded, platform exp, sin, cos; across platforms |diff| <= 2^-20 max(|v|, 1)",
new("CultPhasor cultmath_phacelle(vec3, vec3, float, float)", "ulp-bounded, platform exp, sin, cos; across platforms |diff| <= 2^-20 max(|v|, 1); on a device |diff| <= 2^-18 max(|v|, 1)",
r => new object[] { Point3(r), Side(r), Uniform(r, 0.0f, 1.0f), 0.5f }, Platform: Platform.Scaled),
new("float cultmath_snoise(vec3)", "ulp-bounded, on the simplex tie set", r => new object[] { TiePoint3(r) }),
new("vec4 cultmath_snoise_grad(vec3)", "ulp-bounded, on the simplex tie set", r => new object[] { TiePoint3(r) }),

View file

@ -0,0 +1,221 @@
# renderer llvmpipe (LLVM 20.1.2, 256 bits)
# identity glslang-tools 15.1.0-2~ubuntu0.24.04.2; mesa-vulkan-drivers 25.2.8-0ubuntu0.24.04.4; dxc libdxcompiler.so: 1.9(1-0d3ee6b5)(1.9.0.1); apt snapshot 20261016T000000Z
# route index glsl tolerance exact cases worst u1 NaN-class mismatches result sha256; written only by CULTMATH_WRITE_DEVICE_BOUNDS=1
lavapipe-glsl 0 float cultmath_snoise(vec3) ulp-bounded 86 88.5 0 546a5fd0ec6ff9e958b281791d2ea75409e8085d07eca0578ca31c373251cbd3
lavapipe-glsl 1 float cultmath_snoise(vec2) ulp-bounded 141 111.71875 0 2ceef683245300198343565b581de6978efdc92970ee8ae1b8f4b2fcfb732cbb
lavapipe-glsl 2 vec4 cultmath_snoise_grad(vec3) ulp-bounded 68 617.5 0 cb8b652fde6b9b11fa9f5a6e120a3fed7ead5b69db2ccf981240c9b098343984
lavapipe-glsl 3 vec4 cultmath_fbm_grad(vec3, int, float, float) ulp-bounded 11 2812 0 7cfbaadc05c186be8122ee5cbd8f4932b256d2cb0239acbd7ba6290f8976ca06
lavapipe-glsl 4 vec4 cultmath_ridged_grad(vec3, int, float, float) ulp-bounded 9 3510 0 937908e0e35a863a1dc80c624c0f384461db28500aa5de2010a292d61a13368b
lavapipe-glsl 5 CultCellular cultmath_cellular(vec3) ulp-bounded 199 1 0 ec144b78ccb06b565bdcb514f941f1823bb2cb8ec519b45f8a034ef50ef1b871
lavapipe-glsl 6 ivec3 cultmath_pcg3d(ivec3) exact 256 0 0 a410be8431cbc976fd6b7af9c83a71858d0f9ccb9e7f2c8fda94d5ca2db62176
lavapipe-glsl 7 ivec4 cultmath_pcg4d(ivec4) exact 256 0 0 d22bad50369da1bb343cfa0457565fa795a9374dd354c7cedeaa84b1f4fcb5e1
lavapipe-glsl 8 vec2 cultmath_iv_point(float) ulp-bounded 256 0 0 4345669b712d86cc70869adee43d1b371bb5acbf767fd0ad4c96e6bdd2167eae
lavapipe-glsl 9 vec2 cultmath_iv_add(vec2, vec2) ulp-bounded 256 0 0 71fb79c72089090255803a20bdda0ab592b71edf7e4ff2e35a1e4407bb203f91
lavapipe-glsl 10 vec2 cultmath_iv_sub(vec2, vec2) ulp-bounded 256 0 0 a94e8e5a7315fe885499a0984755d2fc8dfaaa0a2cd776ae70d06fa061e5526e
lavapipe-glsl 11 vec2 cultmath_iv_neg(vec2) ulp-bounded 256 0 0 c659fe8af49f9d27717efae94578fcd76a0d8db173755b008c10314e71509018
lavapipe-glsl 12 vec2 cultmath_iv_mul(vec2, vec2) ulp-bounded 256 0 0 1bef7438c091e05e39918e961e2154161ffb86192f35917ea344250560803ce0
lavapipe-glsl 13 vec2 cultmath_iv_scale(vec2, float) ulp-bounded 256 0 0 f7cabee9534c5867efaa66ded529feab679065fed8e277d48804f8a127cfb1da
lavapipe-glsl 14 vec2 cultmath_iv_abs(vec2) ulp-bounded 256 0 0 06b1b8506452333155949472f815ce84542614e434633f4824ff708377b6b622
lavapipe-glsl 15 vec2 cultmath_iv_min(vec2, vec2) ulp-bounded 256 0 0 a324b35cb4a7c5fa0c95050814175df5d8279efe4359f3898e14208cc87ecaaa
lavapipe-glsl 16 vec2 cultmath_iv_max(vec2, vec2) ulp-bounded 256 0 0 d68412262ca234c1da130fc5217ba6856da3e92e435c28c1fbdbf3692a89e1fa
lavapipe-glsl 17 vec2 cultmath_iv_sqr(vec2) ulp-bounded 256 0 0 dbbb0e0df015456393452377d689732428a9a8e24d8e2b407ee9620593b4c46b
lavapipe-glsl 18 vec2 cultmath_iv_sqrt(vec2) ulp-bounded 256 0 0 95bd15d1b283713fc632ced350f5da1b89f8f73e6618329773db1b52acd29991
lavapipe-glsl 19 vec2 cultmath_iv_clamp(vec2, float, float) ulp-bounded 256 0 0 abe9daf24930a5e3a49ec994c4cae3a0c27b9d019d6d93ec1963ec3daad664a0
lavapipe-glsl 20 vec2 cultmath_iv_saturate(vec2) ulp-bounded 256 0 0 0f844ef8c4d9a9f748c80677bbbfc36b5f6e682eb87c2d46e7e20635d5f55c26
lavapipe-glsl 21 vec2 cultmath_iv_smoothstep(float, float, vec2) ulp-bounded 256 0 0 3d5944a4c43feb91d6786924e0f5439c05285d28ff1f500b5582893758dd4ce5
lavapipe-glsl 22 vec2 cultmath_iv_lerp(vec2, vec2, float) ulp-bounded 256 0 0 96b09e90a3fbbfe81379a29a23b676e490bc7dc6bb731450197707e6cf4c573f
lavapipe-glsl 23 vec2 cultmath_iv_snoise_ball(vec3, float) ulp-bounded 242 54 0 570eb031260c8f4aab42edc57a5fa1d0da70e8a4e6f0b4bf68208c15506f7cb5
lavapipe-glsl 24 vec2 cultmath_iv_fbm_ball(vec3, float, int, float, float) ulp-bounded 250 56 0 9e7017426314537f84c58dcdd1f85188cbe8f4dd9ababed887f60776cf861ebf
lavapipe-glsl 25 vec4 cultmath_iv_frustum_ball(vec2, float, float, float, float) ulp-bounded 198 1.6457063576593662 0 327c306aa4d06aecbb2681d8808c6dbf0567e87b54a6067c68001e36b3e52169
lavapipe-glsl 26 vec2 cultmath_iv_exp(vec2) ulp-bounded, platform exp 7 7.526057804152758 0 b4af8232dc3dd782cc6d790e928ede0f6ba6dfdffd6c71dd9494fb58973e485c
lavapipe-glsl 27 CultPhasor cultmath_phacelle(vec3, vec3, float, float) ulp-bounded, platform exp, sin, cos; across platforms |diff| <= 2^-20 max(|v|, 1); on a device |diff| <= 2^-18 max(|v|, 1) 0 18.5 0 705b4c18027a0838218645e9368c3749ae4b5bf75e0485985725e8e72b73ab88
lavapipe-glsl 28 float cultmath_snoise(vec3) ulp-bounded, on the simplex tie set 127 112 0 6929326e4f27726d7bbdbac3a7823209e2ecfcd301018ef164527c4c1a9f7ae8
lavapipe-glsl 29 vec4 cultmath_snoise_grad(vec3) ulp-bounded, on the simplex tie set 102 546.5 0 6173a812fd4059fa19bce84d34858c6035cdda98aa21a2b210e611cbd58c29d6
lavapipe-glsl 30 vec3 cultmath_af_point(float) ulp-bounded 256 0 0 7aa8ec07c8804cc92400c8a5c0f0d301db2ca4b7c4593a40c4223df306dab4c8
lavapipe-glsl 31 vec3 cultmath_af_symbol(float, float) ulp-bounded 256 0 0 041476b7fda30584d1b555d8ee5ffbf29f111d8fa97f0a47acba8c16641e222f
lavapipe-glsl 32 vec3 cultmath_af_from_iv(vec2) ulp-bounded 256 0 0 306fe58a3268199fc8fd845a32d956f349a790422fa5c87d5a0824636cb55424
lavapipe-glsl 33 vec2 cultmath_af_range(vec3) ulp-bounded 256 0 0 6245eeba19473d69d0d8155e20e2e6089a6843140723d23ed5d501064023a44a
lavapipe-glsl 34 vec3 cultmath_af_add(vec3, vec3) ulp-bounded 256 0 0 cb1cb3fc69224837342de767525d332687b9d3e17b3de255c28e2f0f65f32640
lavapipe-glsl 35 vec3 cultmath_af_sub(vec3, vec3) ulp-bounded 256 0 0 a8fad8ea86cf61841430293fdd9840a54008160250114040380c9634c63bb17e
lavapipe-glsl 36 vec3 cultmath_af_neg(vec3) ulp-bounded 256 0 0 e485acf8ee21c6d880621cc6216b3b2a78318f56f5864b33c5509be27e22a694
lavapipe-glsl 37 vec3 cultmath_af_scale(vec3, float) ulp-bounded 256 0 0 8b0c8a540fea82fe058efc42ffa38dbd69850e579cefe5fdbc4c164b715ec15d
lavapipe-glsl 38 vec3 cultmath_af_add_iv(vec3, vec2) ulp-bounded 256 0 0 620f747e6ba53014c9714a8dbfaa3ff93f281c80938bd035ef64657e3bdc1a16
lavapipe-glsl 39 vec3 cultmath_af_mul(vec3, vec3) ulp-bounded 256 0 0 9dd029d56132560877ea155cf09e1b9519c2721acac462b10ac64afe7d01e134
lavapipe-glsl 40 vec3 cultmath_af_snoise(vec3, vec3, float) ulp-bounded 53 90.75 0 bdfd575faf2016af642b9280ecf77e34673babf2420362537ae5d1dba7cebe64
lavapipe-glsl 41 vec3 cultmath_af_fbm(vec3, vec3, float, int, float, float) ulp-bounded 28 97.5 0 188d2e6eb49daa0eda38ed0c9b947b8b9f2c0a4c426665bdd25c72efa477933e
lavapipe-glsl 42 vec3 cultmath_af_frustum_axis(vec2, float, float) ulp-bounded 256 0 0 9a6daac34242d264db9dedc40c8c074ea0fd188af9c04bb1658d0693111eabee
lavapipe-glsl 43 vec4 cultmath_af_frustum_ball(vec2, float, float, float, float) ulp-bounded 256 0 0 45522a4b8e0e31f90e9e9e3af245182305ca8bb27abf1ab61b04f6c35b606112
lavapipe-glsl 44 vec2 cultmath_iv_snoise_ball(vec2, float) ulp-bounded 244 46 0 edcfa49ec6c1e01fdb920c3265a79ca781e2edefdfe8a11f9cae3bf985b3687d
lavapipe-glsl 45 vec3 cultmath_af_snoise(vec3, vec3, float) ulp-bounded, reach 1e-6 to 1e-3 75 46.9375 0 1a66868821ee19096da857fe52df70207f0d9daa20d5939440edf1ad8f4c0455
lavapipe-glsl 46 vec3 cultmath_af_fbm(vec3, vec3, float, int, float, float) ulp-bounded, reach 1e-6 to 1e-3 27 102.5 0 42246db4e19a1da20433517cdc7016dda375ea70dc90d1a777679bfd76fb59e8
lavapipe-glsl 47 float cultmath_cycles_divide(float, float) ulp-bounded 256 0 0 87f143c57806ad52c3295cde67e97f31e39c8572b8c0a4b8c577e6fcd8ecbebf
lavapipe-glsl 48 float cultmath_cycles_power(float, float) ulp-bounded, platform pow 136 4.918926113980705 0 0e62db5ea32fdb9fdd3a9b135a914ddadd3231bdee0ff15c709102b26bb89186
lavapipe-glsl 49 float cultmath_cycles_logarithm(float, float) ulp-bounded, platform log 146 4.94622778071426 0 5b2bf1411512c7e5a3f4b335a16fc3ba00ba0784bb87acb14b7d1b9dd551b2f3
lavapipe-glsl 50 float cultmath_cycles_sqrt(float) ulp-bounded 256 0 0 6d4beb34e93ae304b3d9d30f203fb6c2ba222affc0efc35bb5441528e9062a9a
lavapipe-glsl 51 float cultmath_cycles_inverse_sqrt(float) ulp-bounded 256 0 0 71aadd5bd384b9ca2eb89827de53af810a1350b02177de1987e9405e4a6e9ad8
lavapipe-glsl 52 float cultmath_cycles_modulo(float, float) ulp-bounded 256 0 0 cf055cafcb5b2d4789a0a2d5cfbc8bc79f52df646b60f5e47db3f994680949e9
lavapipe-glsl 53 float cultmath_cycles_floored_modulo(float, float) ulp-bounded 256 0 0 b781fd31c3671b332d7c726f1ef38c28119d0cda26f45a8a8f788127e73b60cd
lavapipe-glsl 54 float cultmath_cycles_wrap(float, float, float) ulp-bounded 256 0 0 76c0b9fc35952c0557b4c1bd51d970851de7faa427dc6772a5cbad8851c9b4f8
lavapipe-glsl 55 float cultmath_cycles_snap(float, float) ulp-bounded 256 0 0 1211752ef48e46517f14eee689ada2e425688e0e7b1f3e10491d0099b19c7a96
lavapipe-glsl 56 float cultmath_cycles_pingpong(float, float) ulp-bounded 256 0 0 968ec85b73586bc37d1a0ce850c48b9ba55f9de42b0f05dee908fa307300887c
lavapipe-glsl 57 float cultmath_cycles_smooth_min(float, float, float) ulp-bounded 256 0 0 9e5ef2547c138970e8edcaf669a1f43e54982b7f113ace2e1ca0ba7712bfc052
lavapipe-glsl 58 float cultmath_cycles_smooth_max(float, float, float) ulp-bounded 256 0 0 25e92186c7fcfd8692595b6be6fbb16add05cc97b9347129e46dccefe518f6ea
lavapipe-glsl 59 float cultmath_cycles_compare(float, float, float) ulp-bounded 256 0 0 525e89cb65b42d49ebecdc542a82e5833aa5abc12de0baf85dcb5d628966f1f6
lavapipe-glsl 60 float cultmath_cycles_round(float) ulp-bounded 256 0 0 ace31f9ef6b3990cfd2deafd3bb831393b17a5c605de645d351096dd37469ecf
lavapipe-glsl 61 float cultmath_cycles_trunc(float) ulp-bounded 256 0 0 ff8954688fa6017fdb94e9f2d76f1bebd4403dc961185b5e911a13341107f3b6
lavapipe-glsl 62 float cultmath_cycles_fract(float) ulp-bounded 256 0 0 8f9ca486ba15de9d17103ab201c42a2e71d8b813752690c503971786abdf20ee
lavapipe-glsl 63 float cultmath_cycles_sign(float) ulp-bounded 256 0 0 6d4d58598959072125f811e50a6b4cb399946ffb53bcc12d66e985e3ae1f7237
lavapipe-glsl 64 float cultmath_cycles_map_range_linear(float, float, float, float, float) ulp-bounded 256 0 0 153c7636170f2c2df751da7d4108b264048a0c2441eea4175a07d52283bc34f8
lavapipe-glsl 65 float cultmath_cycles_map_range_stepped(float, float, float, float, float, float) ulp-bounded 256 0 0 75391d2c4ae437bbb7de824fff0ee2a4cface26160589a2546051fd7fe6302ea
lavapipe-glsl 66 float cultmath_cycles_map_range_smoothstep(float, float, float, float, float) ulp-bounded 256 0 0 202bd26423a4ffe30698d093ab79a6d3aa0d388402f8a0059733695bcbc7bef8
lavapipe-glsl 67 float cultmath_cycles_map_range_smootherstep(float, float, float, float, float) ulp-bounded 256 0 0 fb98cb86965fda6c1e8b4f348009a997bfa8b38ba78c85a6c7c5aa3daff2c9b5
lavapipe-glsl 68 float cultmath_cycles_clamp_minmax(float, float, float) ulp-bounded 256 0 0 13093e4a629a5f7eaeafa6dca36af46692d323ebc7565bfc052195c13d820d9c
lavapipe-glsl 69 float cultmath_cycles_clamp_range(float, float, float) ulp-bounded 256 0 0 801145eabd38a9b92f5fb81aa5d9d4c6a9a977c8514f753e92a039f66099dbbb
lavapipe-glsl 70 float cultmath_cycles_mix_float(float, float, float) ulp-bounded 256 0 0 555151462568cdf0c4557c44b299fc5085149dbe7f9b8e77995b0ae84094701b
lavapipe-glsl 71 vec3 cultmath_cycles_mix_vector(float, vec3, vec3) ulp-bounded 256 0 0 024dfa0de6980161524c7d26c0ccbac06769764b7b1f05e1ddaa2de3d26f5e9e
lavapipe-glsl 72 vec3 cultmath_cycles_rgb_to_hsv(vec3) ulp-bounded 256 0 0 eec7cf189745ddc1c001297a42ab404b4186607f32a38a3b053122104f7c7b38
lavapipe-glsl 73 vec3 cultmath_cycles_hsv_to_rgb(vec3) ulp-bounded 256 0 0 1391d6304ba96b5f271c1fc66935785bf496d40c6a66d07669dbd9b36b7fd0f2
lavapipe-glsl 74 float cultmath_cycles_rgb_to_bw(vec3) ulp-bounded 256 0 0 d3c13195d2fd31e8fe5d0a8127d2650fe7b54ab0681d259735b891ef6c48a3d0
lavapipe-glsl 75 vec2 cultmath_cycles_ramp_index(float, int) ulp-bounded 256 0 0 62dbe8cdbd7a7cc64367dbe49f6554ee6660ba686bff145ec043f6932bea1f4e
lavapipe-glsl 76 vec3 cultmath_cycles_mix_blend(float, vec3, vec3) ulp-bounded 256 0 0 98d559290d1eea28711099f58334c3013ded3d8055ffe2c460463fd8e6920e8a
lavapipe-glsl 77 vec3 cultmath_cycles_mix_add(float, vec3, vec3) ulp-bounded 203 1.280824945387952 0 a6eb4ea72d93fadd76258113bcec9e2aa6a3557f7ffbbd018591b411826372e5
lavapipe-glsl 78 vec3 cultmath_cycles_mix_mul(float, vec3, vec3) ulp-bounded 256 0 0 d8c88a3734b9a6298dbfddafb2f4261639d9292f2c3282bd2de93ac87dc64aff
lavapipe-glsl 79 vec3 cultmath_cycles_mix_screen(float, vec3, vec3) ulp-bounded 256 0 0 18a96f09e992efa4ffeccb6882a25d0a95eddd5c552f38081f9e9cbaeb302ba2
lavapipe-glsl 80 vec3 cultmath_cycles_mix_overlay(float, vec3, vec3) ulp-bounded 256 0 0 0d432008ddc87cf7c9728417be9dc5fbfbbff109b70696606c069bedb6f34455
lavapipe-glsl 81 vec3 cultmath_cycles_mix_sub(float, vec3, vec3) ulp-bounded 224 0.9887614915449221 0 43f38c46c85ec8e9bd50c40d273090301b56e45072d396e6840aba4b85d36ea0
lavapipe-glsl 82 vec3 cultmath_cycles_mix_div(float, vec3, vec3) ulp-bounded 256 0 0 595b729b984c7eafac49d571e213b70cab0cc3961c0875fd44f14f0eef712f6b
lavapipe-glsl 83 vec3 cultmath_cycles_mix_diff(float, vec3, vec3) ulp-bounded 256 0 0 0f1494d72ef1aa26250df833c36c0059bfabc957ad46939f48095714f44724ab
lavapipe-glsl 84 vec3 cultmath_cycles_mix_exclusion(float, vec3, vec3) ulp-bounded 256 0 0 49ac2faf217ebce63ea6f21aef3d865936106f1f461258d8f1dc0ebbc87ddb6e
lavapipe-glsl 85 vec3 cultmath_cycles_mix_dark(float, vec3, vec3) ulp-bounded 256 0 0 446ec94675d81f6d228b70c79d9d857898f26522dd274305ae3c9dcf01e79d2e
lavapipe-glsl 86 vec3 cultmath_cycles_mix_light(float, vec3, vec3) ulp-bounded 256 0 0 a2d1efef2a24fc3d55a9fc05aec5396e9e8360ff3e2f5f2c3987b828d21600b1
lavapipe-glsl 87 vec3 cultmath_cycles_mix_dodge(float, vec3, vec3) ulp-bounded 256 0 0 f75638b3350d6d10342c679b22051f854fe21cf886c7e1ec337ec66ec5b4e208
lavapipe-glsl 88 vec3 cultmath_cycles_mix_burn(float, vec3, vec3) ulp-bounded 256 0 0 96405c0838ddd0d2201909253f0a120ec1f73bed7d196d1c74f63ec36a28646b
lavapipe-glsl 89 vec3 cultmath_cycles_mix_hue(float, vec3, vec3) ulp-bounded 256 0 0 3a010be30109d2782af0eb52c0d71b668caa30ed9817fbcfa2763a424f0d5235
lavapipe-glsl 90 vec3 cultmath_cycles_mix_sat(float, vec3, vec3) ulp-bounded 256 0 0 0d5fded68d4f56dcfe97fd5e2aee9644ac0d176572c069bc9aa8afa29a83ddaf
lavapipe-glsl 91 vec3 cultmath_cycles_mix_val(float, vec3, vec3) ulp-bounded 256 0 0 8b4f5e0be561175c0417791b42ed18dc2c8a0330d6f98421f6dcc89bfe152a81
lavapipe-glsl 92 vec3 cultmath_cycles_mix_color(float, vec3, vec3) ulp-bounded 256 0 0 00067b1567bcd6c07a81fa5002f145dfca22437a3f3df5389b2665334d14909b
lavapipe-glsl 93 vec3 cultmath_cycles_mix_soft(float, vec3, vec3) ulp-bounded 157 1.9750388068880254 0 ed7c5508ca0543cc20a5f0c5624e75e3ca2a2d6044d481816eeda2edc50c0592
lavapipe-glsl 94 vec3 cultmath_cycles_mix_linear(float, vec3, vec3) ulp-bounded 256 0 0 672435cc30bcbbb253cce7316ee0712b1a18f06924bc89cea2d3388dd164a15d
lavapipe-glsl 95 float cultmath_cycles_arcsine(float) ulp-bounded, platform asin 154 2734.286809678319 0 f28f3ed0a53ffeebdfa84865d2d3d41590e6b46fc1578d40e1215e2a9e1af585
lavapipe-glsl 96 float cultmath_cycles_arccosine(float) ulp-bounded, platform acos 79 1046.8674409774287 0 22a2c38ab5a232cdbb33cf0c133362581a398f64a4d0d5d6dd89dc5af06bd890
lavapipe-glsl 97 float cultmath_cycles_arctan2(float, float) ulp-bounded, platform atan 6 25.5 0 2c60447d80186f6dc9726f19c09fa96ec3f66d8f5688968da533d9195ea463c4
lavapipe-glsl 98 mat3 cultmath_snoise_hessian(vec3) ulp-bounded 30 1358.4375 0 62bbafb8420ed5aaa0ce11d1470ca98945e690b186c33a1e7cf4d71478396465
lavapipe-glsl 99 mat3 cultmath_snoise_hessian(vec3) ulp-bounded, on the simplex tie set 110 1317.4754224467295 0 0efd9b3a637b46033ed0351f64de274db4d9ce05bb83dd1ce57afb3ceaea26bc
lavapipe-glsl 100 float cultmath_integral_clamp_linear(float, float, float, float, float, float) ulp-bounded 256 0 0 84bf9c9a2126b3114a692507cc54f58d313afc33de8a1cac83969cc508433cbe
lavapipe-glsl 101 float cultmath_integral_clamp_linear(float, float, float, float, float, float) ulp-bounded, lo above hi and infinite bounds 256 0 0 ff999094d7794aa525e0f9f9a067aa21408a59559aa546cace3b1bb4a8c7f96d
lavapipe-glsl 102 float cultmath_integral_clamp_linear(float, float, float, float, float, float) ulp-bounded, zero-length spans and flat infinite clamps 256 0 0 c3cc48f4edcac6801b9223f12d289934916431bdfaea8f68af33a1b833ab9860
lavapipe-glsl 103 SpanNoise cultmath_span_fbm(SpanPath, SpanStage, int, float, float) ulp-bounded 7 1012477.3459086476 0 97c531c3a690e056d95e949e243ae74111d4a93a39fd22c0358a103b3bb14bc1
lavapipe-glsl 104 SpanNoise cultmath_span_ridged(SpanPath, SpanStage, int, float, float) ulp-bounded 8 948534.9108393334 0 54fd229d69439ff3318690b7802143f8410dc7ece30ad0d56ccc4b68bf39bec2
lavapipe-glsl 105 vec4 cultmath_snoise_grad(vec3) ulp-bounded, coordinate bands 1e-4 to 1e2 116 249.5 0 fff9658a8ec055766c9327ee9b680cf7fb83736c472ae90a11e50d6d2a053fdc
lavapipe-glsl 106 vec4 cultmath_snoise_grad(vec3) ulp-bounded, coordinate bands 1e2 to 4e6 70 11866336.625 0 833484714ebcea59d86e0fbc2eaa4ae247c29541703763989e6758547dbf6db8
lavapipe-glsl 107 mat3 cultmath_snoise_hessian(vec3) ulp-bounded, coordinate bands 1e-4 to 1e2 120 980.7417469278579 0 3ea43dabe0091ea8e994c1dfc65c7274ed38b9343d4d1d06f7caa09c806c91df
lavapipe-glsl 108 mat3 cultmath_snoise_hessian(vec3) ulp-bounded, coordinate bands 1e2 to 4e6 46 164827710.09171063 0 0984abe5fff2e2df93b053a5b5dbdd4eacd816d26144d8352497614e45159c07
lavapipe-hlsl 0 float cultmath_snoise(vec3) ulp-bounded 94 122.6875 0 5d41c14241a13124f2e1b49f230f5df0c48d0d69fb1be9ef2f33dc1702bf0b0a
lavapipe-hlsl 1 float cultmath_snoise(vec2) ulp-bounded 204 1 0 81d9c62726afdccbbe4ffef173b5c92731eb6bf5927b3979d653e50dbd5d4064
lavapipe-hlsl 2 vec4 cultmath_snoise_grad(vec3) ulp-bounded 71 617.5 0 f7e9ed1707cdb015efaba0e0150193309da0d4c125349518f8b7c60a17b25790
lavapipe-hlsl 3 vec4 cultmath_fbm_grad(vec3, int, float, float) ulp-bounded 8 5043.031516667752 0 d60ec63e283433334da31e8f7ab396f6bfac473ed3a59e50f1db0db320ba37b9
lavapipe-hlsl 4 vec4 cultmath_ridged_grad(vec3, int, float, float) ulp-bounded 12 3510 0 3a545af386da2e9c04f665e1fc42120e687b0f832c9afdad3a87ecdddf813a20
lavapipe-hlsl 5 CultCellular cultmath_cellular(vec3) ulp-bounded 199 1 0 ec144b78ccb06b565bdcb514f941f1823bb2cb8ec519b45f8a034ef50ef1b871
lavapipe-hlsl 6 ivec3 cultmath_pcg3d(ivec3) exact 256 0 0 a410be8431cbc976fd6b7af9c83a71858d0f9ccb9e7f2c8fda94d5ca2db62176
lavapipe-hlsl 7 ivec4 cultmath_pcg4d(ivec4) exact 256 0 0 d22bad50369da1bb343cfa0457565fa795a9374dd354c7cedeaa84b1f4fcb5e1
lavapipe-hlsl 8 vec2 cultmath_iv_point(float) ulp-bounded 256 0 0 4345669b712d86cc70869adee43d1b371bb5acbf767fd0ad4c96e6bdd2167eae
lavapipe-hlsl 9 vec2 cultmath_iv_add(vec2, vec2) ulp-bounded 256 0 0 71fb79c72089090255803a20bdda0ab592b71edf7e4ff2e35a1e4407bb203f91
lavapipe-hlsl 10 vec2 cultmath_iv_sub(vec2, vec2) ulp-bounded 256 0 0 a94e8e5a7315fe885499a0984755d2fc8dfaaa0a2cd776ae70d06fa061e5526e
lavapipe-hlsl 11 vec2 cultmath_iv_neg(vec2) ulp-bounded 256 0 0 c659fe8af49f9d27717efae94578fcd76a0d8db173755b008c10314e71509018
lavapipe-hlsl 12 vec2 cultmath_iv_mul(vec2, vec2) ulp-bounded 256 0 0 1bef7438c091e05e39918e961e2154161ffb86192f35917ea344250560803ce0
lavapipe-hlsl 13 vec2 cultmath_iv_scale(vec2, float) ulp-bounded 256 0 0 f7cabee9534c5867efaa66ded529feab679065fed8e277d48804f8a127cfb1da
lavapipe-hlsl 14 vec2 cultmath_iv_abs(vec2) ulp-bounded 256 0 0 06b1b8506452333155949472f815ce84542614e434633f4824ff708377b6b622
lavapipe-hlsl 15 vec2 cultmath_iv_min(vec2, vec2) ulp-bounded 256 0 0 a324b35cb4a7c5fa0c95050814175df5d8279efe4359f3898e14208cc87ecaaa
lavapipe-hlsl 16 vec2 cultmath_iv_max(vec2, vec2) ulp-bounded 256 0 0 d68412262ca234c1da130fc5217ba6856da3e92e435c28c1fbdbf3692a89e1fa
lavapipe-hlsl 17 vec2 cultmath_iv_sqr(vec2) ulp-bounded 256 0 0 dbbb0e0df015456393452377d689732428a9a8e24d8e2b407ee9620593b4c46b
lavapipe-hlsl 18 vec2 cultmath_iv_sqrt(vec2) ulp-bounded 256 0 0 95bd15d1b283713fc632ced350f5da1b89f8f73e6618329773db1b52acd29991
lavapipe-hlsl 19 vec2 cultmath_iv_clamp(vec2, float, float) ulp-bounded 256 0 0 abe9daf24930a5e3a49ec994c4cae3a0c27b9d019d6d93ec1963ec3daad664a0
lavapipe-hlsl 20 vec2 cultmath_iv_saturate(vec2) ulp-bounded 256 0 0 0f844ef8c4d9a9f748c80677bbbfc36b5f6e682eb87c2d46e7e20635d5f55c26
lavapipe-hlsl 21 vec2 cultmath_iv_smoothstep(float, float, vec2) ulp-bounded 256 0 0 3d5944a4c43feb91d6786924e0f5439c05285d28ff1f500b5582893758dd4ce5
lavapipe-hlsl 22 vec2 cultmath_iv_lerp(vec2, vec2, float) ulp-bounded 256 0 0 96b09e90a3fbbfe81379a29a23b676e490bc7dc6bb731450197707e6cf4c573f
lavapipe-hlsl 23 vec2 cultmath_iv_snoise_ball(vec3, float) ulp-bounded 244 54 0 f36530a4cd8c9fdc1c73e7ddb6782cd11cbf8493e2ee7b0656e818812504267e
lavapipe-hlsl 24 vec2 cultmath_iv_fbm_ball(vec3, float, int, float, float) ulp-bounded 252 75 0 a1677ea42ce91a5d2b6f83fa7c44879b7a184ed4631108d7a1c6e710bf26ff02
lavapipe-hlsl 25 vec4 cultmath_iv_frustum_ball(vec2, float, float, float, float) ulp-bounded 198 1.6457063576593662 0 327c306aa4d06aecbb2681d8808c6dbf0567e87b54a6067c68001e36b3e52169
lavapipe-hlsl 26 vec2 cultmath_iv_exp(vec2) ulp-bounded, platform exp 7 7.526057804152758 0 b4af8232dc3dd782cc6d790e928ede0f6ba6dfdffd6c71dd9494fb58973e485c
lavapipe-hlsl 27 CultPhasor cultmath_phacelle(vec3, vec3, float, float) ulp-bounded, platform exp, sin, cos; across platforms |diff| <= 2^-20 max(|v|, 1); on a device |diff| <= 2^-18 max(|v|, 1) 0 18.5 0 705b4c18027a0838218645e9368c3749ae4b5bf75e0485985725e8e72b73ab88
lavapipe-hlsl 28 float cultmath_snoise(vec3) ulp-bounded, on the simplex tie set 144 99 0 be76512b18eb678194dad0c4726c0aef9ba34012b60b79d24c2df27989707145
lavapipe-hlsl 29 vec4 cultmath_snoise_grad(vec3) ulp-bounded, on the simplex tie set 111 546.5 0 124d4be07cbb66edab644e649c081cb7c8be5d99b6c1d84fec5d7ef65c76ed0f
lavapipe-hlsl 30 vec3 cultmath_af_point(float) ulp-bounded 256 0 0 7aa8ec07c8804cc92400c8a5c0f0d301db2ca4b7c4593a40c4223df306dab4c8
lavapipe-hlsl 31 vec3 cultmath_af_symbol(float, float) ulp-bounded 256 0 0 041476b7fda30584d1b555d8ee5ffbf29f111d8fa97f0a47acba8c16641e222f
lavapipe-hlsl 32 vec3 cultmath_af_from_iv(vec2) ulp-bounded 256 0 0 306fe58a3268199fc8fd845a32d956f349a790422fa5c87d5a0824636cb55424
lavapipe-hlsl 33 vec2 cultmath_af_range(vec3) ulp-bounded 256 0 0 6245eeba19473d69d0d8155e20e2e6089a6843140723d23ed5d501064023a44a
lavapipe-hlsl 34 vec3 cultmath_af_add(vec3, vec3) ulp-bounded 256 0 0 cb1cb3fc69224837342de767525d332687b9d3e17b3de255c28e2f0f65f32640
lavapipe-hlsl 35 vec3 cultmath_af_sub(vec3, vec3) ulp-bounded 256 0 0 a8fad8ea86cf61841430293fdd9840a54008160250114040380c9634c63bb17e
lavapipe-hlsl 36 vec3 cultmath_af_neg(vec3) ulp-bounded 256 0 0 e485acf8ee21c6d880621cc6216b3b2a78318f56f5864b33c5509be27e22a694
lavapipe-hlsl 37 vec3 cultmath_af_scale(vec3, float) ulp-bounded 256 0 0 8b0c8a540fea82fe058efc42ffa38dbd69850e579cefe5fdbc4c164b715ec15d
lavapipe-hlsl 38 vec3 cultmath_af_add_iv(vec3, vec2) ulp-bounded 256 0 0 620f747e6ba53014c9714a8dbfaa3ff93f281c80938bd035ef64657e3bdc1a16
lavapipe-hlsl 39 vec3 cultmath_af_mul(vec3, vec3) ulp-bounded 256 0 0 9dd029d56132560877ea155cf09e1b9519c2721acac462b10ac64afe7d01e134
lavapipe-hlsl 40 vec3 cultmath_af_snoise(vec3, vec3, float) ulp-bounded 54 61 0 052ba44c08e92f1a9176d99c99c3939686c8e05f1398c3a184e0edf246cd565c
lavapipe-hlsl 41 vec3 cultmath_af_fbm(vec3, vec3, float, int, float, float) ulp-bounded 32 99.125 0 21f78108b9704a4b6dca1f74445c4a07f0fe235b222100c083346eae69833a3e
lavapipe-hlsl 42 vec3 cultmath_af_frustum_axis(vec2, float, float) ulp-bounded 256 0 0 9a6daac34242d264db9dedc40c8c074ea0fd188af9c04bb1658d0693111eabee
lavapipe-hlsl 43 vec4 cultmath_af_frustum_ball(vec2, float, float, float, float) ulp-bounded 256 0 0 45522a4b8e0e31f90e9e9e3af245182305ca8bb27abf1ab61b04f6c35b606112
lavapipe-hlsl 44 vec2 cultmath_iv_snoise_ball(vec2, float) ulp-bounded 253 0.5 0 401da9e2e59377ac82a602dc86614e9c0418ee2ee8d38eecea45b5406ebca611
lavapipe-hlsl 45 vec3 cultmath_af_snoise(vec3, vec3, float) ulp-bounded, reach 1e-6 to 1e-3 79 35.59375 0 9e9d24960b0514ee1fa795aead7629b8a61b65eec94aa1f25a94c0c754a1d992
lavapipe-hlsl 46 vec3 cultmath_af_fbm(vec3, vec3, float, int, float, float) ulp-bounded, reach 1e-6 to 1e-3 24 122.75 0 7f941b1f0c76d9f2121027a555ae7f2a741cc164402f0df75237198ac97f850b
lavapipe-hlsl 47 float cultmath_cycles_divide(float, float) ulp-bounded 256 0 0 87f143c57806ad52c3295cde67e97f31e39c8572b8c0a4b8c577e6fcd8ecbebf
lavapipe-hlsl 48 float cultmath_cycles_power(float, float) ulp-bounded, platform pow 136 4.918926113980705 0 0e62db5ea32fdb9fdd3a9b135a914ddadd3231bdee0ff15c709102b26bb89186
lavapipe-hlsl 49 float cultmath_cycles_logarithm(float, float) ulp-bounded, platform log 146 4.94622778071426 0 5b2bf1411512c7e5a3f4b335a16fc3ba00ba0784bb87acb14b7d1b9dd551b2f3
lavapipe-hlsl 50 float cultmath_cycles_sqrt(float) ulp-bounded 256 0 0 6d4beb34e93ae304b3d9d30f203fb6c2ba222affc0efc35bb5441528e9062a9a
lavapipe-hlsl 51 float cultmath_cycles_inverse_sqrt(float) ulp-bounded 256 0 0 71aadd5bd384b9ca2eb89827de53af810a1350b02177de1987e9405e4a6e9ad8
lavapipe-hlsl 52 float cultmath_cycles_modulo(float, float) ulp-bounded 256 0 0 cf055cafcb5b2d4789a0a2d5cfbc8bc79f52df646b60f5e47db3f994680949e9
lavapipe-hlsl 53 float cultmath_cycles_floored_modulo(float, float) ulp-bounded 256 0 0 b781fd31c3671b332d7c726f1ef38c28119d0cda26f45a8a8f788127e73b60cd
lavapipe-hlsl 54 float cultmath_cycles_wrap(float, float, float) ulp-bounded 256 0 0 76c0b9fc35952c0557b4c1bd51d970851de7faa427dc6772a5cbad8851c9b4f8
lavapipe-hlsl 55 float cultmath_cycles_snap(float, float) ulp-bounded 256 0 0 1211752ef48e46517f14eee689ada2e425688e0e7b1f3e10491d0099b19c7a96
lavapipe-hlsl 56 float cultmath_cycles_pingpong(float, float) ulp-bounded 256 0 0 968ec85b73586bc37d1a0ce850c48b9ba55f9de42b0f05dee908fa307300887c
lavapipe-hlsl 57 float cultmath_cycles_smooth_min(float, float, float) ulp-bounded 256 0 0 9e5ef2547c138970e8edcaf669a1f43e54982b7f113ace2e1ca0ba7712bfc052
lavapipe-hlsl 58 float cultmath_cycles_smooth_max(float, float, float) ulp-bounded 256 0 0 25e92186c7fcfd8692595b6be6fbb16add05cc97b9347129e46dccefe518f6ea
lavapipe-hlsl 59 float cultmath_cycles_compare(float, float, float) ulp-bounded 256 0 0 525e89cb65b42d49ebecdc542a82e5833aa5abc12de0baf85dcb5d628966f1f6
lavapipe-hlsl 60 float cultmath_cycles_round(float) ulp-bounded 256 0 0 ace31f9ef6b3990cfd2deafd3bb831393b17a5c605de645d351096dd37469ecf
lavapipe-hlsl 61 float cultmath_cycles_trunc(float) ulp-bounded 256 0 0 ff8954688fa6017fdb94e9f2d76f1bebd4403dc961185b5e911a13341107f3b6
lavapipe-hlsl 62 float cultmath_cycles_fract(float) ulp-bounded 256 0 0 8f9ca486ba15de9d17103ab201c42a2e71d8b813752690c503971786abdf20ee
lavapipe-hlsl 63 float cultmath_cycles_sign(float) ulp-bounded 256 0 0 6d4d58598959072125f811e50a6b4cb399946ffb53bcc12d66e985e3ae1f7237
lavapipe-hlsl 64 float cultmath_cycles_map_range_linear(float, float, float, float, float) ulp-bounded 256 0 0 153c7636170f2c2df751da7d4108b264048a0c2441eea4175a07d52283bc34f8
lavapipe-hlsl 65 float cultmath_cycles_map_range_stepped(float, float, float, float, float, float) ulp-bounded 256 0 0 75391d2c4ae437bbb7de824fff0ee2a4cface26160589a2546051fd7fe6302ea
lavapipe-hlsl 66 float cultmath_cycles_map_range_smoothstep(float, float, float, float, float) ulp-bounded 256 0 0 202bd26423a4ffe30698d093ab79a6d3aa0d388402f8a0059733695bcbc7bef8
lavapipe-hlsl 67 float cultmath_cycles_map_range_smootherstep(float, float, float, float, float) ulp-bounded 256 0 0 fb98cb86965fda6c1e8b4f348009a997bfa8b38ba78c85a6c7c5aa3daff2c9b5
lavapipe-hlsl 68 float cultmath_cycles_clamp_minmax(float, float, float) ulp-bounded 256 0 0 13093e4a629a5f7eaeafa6dca36af46692d323ebc7565bfc052195c13d820d9c
lavapipe-hlsl 69 float cultmath_cycles_clamp_range(float, float, float) ulp-bounded 256 0 0 801145eabd38a9b92f5fb81aa5d9d4c6a9a977c8514f753e92a039f66099dbbb
lavapipe-hlsl 70 float cultmath_cycles_mix_float(float, float, float) ulp-bounded 256 0 0 555151462568cdf0c4557c44b299fc5085149dbe7f9b8e77995b0ae84094701b
lavapipe-hlsl 71 vec3 cultmath_cycles_mix_vector(float, vec3, vec3) ulp-bounded 256 0 0 024dfa0de6980161524c7d26c0ccbac06769764b7b1f05e1ddaa2de3d26f5e9e
lavapipe-hlsl 72 vec3 cultmath_cycles_rgb_to_hsv(vec3) ulp-bounded 256 0 0 eec7cf189745ddc1c001297a42ab404b4186607f32a38a3b053122104f7c7b38
lavapipe-hlsl 73 vec3 cultmath_cycles_hsv_to_rgb(vec3) ulp-bounded 256 0 0 1391d6304ba96b5f271c1fc66935785bf496d40c6a66d07669dbd9b36b7fd0f2
lavapipe-hlsl 74 float cultmath_cycles_rgb_to_bw(vec3) ulp-bounded 256 0 0 d3c13195d2fd31e8fe5d0a8127d2650fe7b54ab0681d259735b891ef6c48a3d0
lavapipe-hlsl 75 vec2 cultmath_cycles_ramp_index(float, int) ulp-bounded 256 0 0 62dbe8cdbd7a7cc64367dbe49f6554ee6660ba686bff145ec043f6932bea1f4e
lavapipe-hlsl 76 vec3 cultmath_cycles_mix_blend(float, vec3, vec3) ulp-bounded 256 0 0 98d559290d1eea28711099f58334c3013ded3d8055ffe2c460463fd8e6920e8a
lavapipe-hlsl 77 vec3 cultmath_cycles_mix_add(float, vec3, vec3) ulp-bounded 203 1.280824945387952 0 a6eb4ea72d93fadd76258113bcec9e2aa6a3557f7ffbbd018591b411826372e5
lavapipe-hlsl 78 vec3 cultmath_cycles_mix_mul(float, vec3, vec3) ulp-bounded 256 0 0 d8c88a3734b9a6298dbfddafb2f4261639d9292f2c3282bd2de93ac87dc64aff
lavapipe-hlsl 79 vec3 cultmath_cycles_mix_screen(float, vec3, vec3) ulp-bounded 256 0 0 18a96f09e992efa4ffeccb6882a25d0a95eddd5c552f38081f9e9cbaeb302ba2
lavapipe-hlsl 80 vec3 cultmath_cycles_mix_overlay(float, vec3, vec3) ulp-bounded 256 0 0 0d432008ddc87cf7c9728417be9dc5fbfbbff109b70696606c069bedb6f34455
lavapipe-hlsl 81 vec3 cultmath_cycles_mix_sub(float, vec3, vec3) ulp-bounded 224 0.9887614915449221 0 43f38c46c85ec8e9bd50c40d273090301b56e45072d396e6840aba4b85d36ea0
lavapipe-hlsl 82 vec3 cultmath_cycles_mix_div(float, vec3, vec3) ulp-bounded 256 0 0 595b729b984c7eafac49d571e213b70cab0cc3961c0875fd44f14f0eef712f6b
lavapipe-hlsl 83 vec3 cultmath_cycles_mix_diff(float, vec3, vec3) ulp-bounded 256 0 0 0f1494d72ef1aa26250df833c36c0059bfabc957ad46939f48095714f44724ab
lavapipe-hlsl 84 vec3 cultmath_cycles_mix_exclusion(float, vec3, vec3) ulp-bounded 256 0 0 49ac2faf217ebce63ea6f21aef3d865936106f1f461258d8f1dc0ebbc87ddb6e
lavapipe-hlsl 85 vec3 cultmath_cycles_mix_dark(float, vec3, vec3) ulp-bounded 256 0 0 446ec94675d81f6d228b70c79d9d857898f26522dd274305ae3c9dcf01e79d2e
lavapipe-hlsl 86 vec3 cultmath_cycles_mix_light(float, vec3, vec3) ulp-bounded 256 0 0 a2d1efef2a24fc3d55a9fc05aec5396e9e8360ff3e2f5f2c3987b828d21600b1
lavapipe-hlsl 87 vec3 cultmath_cycles_mix_dodge(float, vec3, vec3) ulp-bounded 256 0 0 f75638b3350d6d10342c679b22051f854fe21cf886c7e1ec337ec66ec5b4e208
lavapipe-hlsl 88 vec3 cultmath_cycles_mix_burn(float, vec3, vec3) ulp-bounded 256 0 0 96405c0838ddd0d2201909253f0a120ec1f73bed7d196d1c74f63ec36a28646b
lavapipe-hlsl 89 vec3 cultmath_cycles_mix_hue(float, vec3, vec3) ulp-bounded 256 0 0 3a010be30109d2782af0eb52c0d71b668caa30ed9817fbcfa2763a424f0d5235
lavapipe-hlsl 90 vec3 cultmath_cycles_mix_sat(float, vec3, vec3) ulp-bounded 256 0 0 0d5fded68d4f56dcfe97fd5e2aee9644ac0d176572c069bc9aa8afa29a83ddaf
lavapipe-hlsl 91 vec3 cultmath_cycles_mix_val(float, vec3, vec3) ulp-bounded 256 0 0 8b4f5e0be561175c0417791b42ed18dc2c8a0330d6f98421f6dcc89bfe152a81
lavapipe-hlsl 92 vec3 cultmath_cycles_mix_color(float, vec3, vec3) ulp-bounded 256 0 0 00067b1567bcd6c07a81fa5002f145dfca22437a3f3df5389b2665334d14909b
lavapipe-hlsl 93 vec3 cultmath_cycles_mix_soft(float, vec3, vec3) ulp-bounded 157 1.9750388068880254 0 ed7c5508ca0543cc20a5f0c5624e75e3ca2a2d6044d481816eeda2edc50c0592
lavapipe-hlsl 94 vec3 cultmath_cycles_mix_linear(float, vec3, vec3) ulp-bounded 256 0 0 672435cc30bcbbb253cce7316ee0712b1a18f06924bc89cea2d3388dd164a15d
lavapipe-hlsl 95 float cultmath_cycles_arcsine(float) ulp-bounded, platform asin 154 2734.286809678319 0 f28f3ed0a53ffeebdfa84865d2d3d41590e6b46fc1578d40e1215e2a9e1af585
lavapipe-hlsl 96 float cultmath_cycles_arccosine(float) ulp-bounded, platform acos 79 1046.8674409774287 0 22a2c38ab5a232cdbb33cf0c133362581a398f64a4d0d5d6dd89dc5af06bd890
lavapipe-hlsl 97 float cultmath_cycles_arctan2(float, float) ulp-bounded, platform atan 6 25.5 0 2c60447d80186f6dc9726f19c09fa96ec3f66d8f5688968da533d9195ea463c4
lavapipe-hlsl 98 mat3 cultmath_snoise_hessian(vec3) ulp-bounded 33 2377.8799856935966 0 a64853839f394cc7c367ba5e107caa8bb396f07cf202263aa917095dd1c939f7
lavapipe-hlsl 99 mat3 cultmath_snoise_hessian(vec3) ulp-bounded, on the simplex tie set 132 1317.4754224467295 0 9066a49e50731881583ffca16c949171bb61578a1dfd497c54dafe773ab49488
lavapipe-hlsl 100 float cultmath_integral_clamp_linear(float, float, float, float, float, float) ulp-bounded 256 0 0 84bf9c9a2126b3114a692507cc54f58d313afc33de8a1cac83969cc508433cbe
lavapipe-hlsl 101 float cultmath_integral_clamp_linear(float, float, float, float, float, float) ulp-bounded, lo above hi and infinite bounds 256 0 0 ff999094d7794aa525e0f9f9a067aa21408a59559aa546cace3b1bb4a8c7f96d
lavapipe-hlsl 102 float cultmath_integral_clamp_linear(float, float, float, float, float, float) ulp-bounded, zero-length spans and flat infinite clamps 256 0 0 c3cc48f4edcac6801b9223f12d289934916431bdfaea8f68af33a1b833ab9860
lavapipe-hlsl 103 SpanNoise cultmath_span_fbm(SpanPath, SpanStage, int, float, float) ulp-bounded 3 1024946.5723514018 0 f6395b9f2609d914894c35b442719be3cc3e11d07c5f0bae5a8719651e60cd4e
lavapipe-hlsl 104 SpanNoise cultmath_span_ridged(SpanPath, SpanStage, int, float, float) ulp-bounded 7 948534.9108393334 0 2adfdc4e6c81ee0bc7bb7869c55207f5033b4176104bc36dce1528ae0a5fe39b
lavapipe-hlsl 105 vec4 cultmath_snoise_grad(vec3) ulp-bounded, coordinate bands 1e-4 to 1e2 119 423.1430718408491 0 a94c38d1baa651a6faa510920cbe9d1f9528c0adb863ba6e35d835588ad00a58
lavapipe-hlsl 106 vec4 cultmath_snoise_grad(vec3) ulp-bounded, coordinate bands 1e2 to 4e6 73 13116827.1875 0 9ad0fd577b26aa717534c0693df97ee41bcded0768f442739b98f505e4a2a430
lavapipe-hlsl 107 mat3 cultmath_snoise_hessian(vec3) ulp-bounded, coordinate bands 1e-4 to 1e2 122 980.7417469278579 0 0977fa6f446e4f916a9b938ce24ea32df6aa912dc991c182014d309dc0efb1cb
lavapipe-hlsl 108 mat3 cultmath_snoise_hessian(vec3) ulp-bounded, coordinate bands 1e2 to 4e6 51 164827710.09171063 0 c87f8a091b11770f7ffd8f01cf421f3fa139b58b7bcfbb6afa171ad5bca10c7b

View file

@ -7082,7 +7082,7 @@
},
{
"glsl": "CultPhasor cultmath_phacelle(vec3, vec3, float, float)",
"tolerance": "ulp-bounded, platform exp, sin, cos; across platforms |diff| <= 2^-20 max(|v|, 1)",
"tolerance": "ulp-bounded, platform exp, sin, cos; across platforms |diff| <= 2^-20 max(|v|, 1); on a device |diff| <= 2^-18 max(|v|, 1)",
"platform": "Ubuntu 24.04.5 LTS; .NET 10.0.12",
"cases": [
"c01d8630 41b2cd8c 41ea274c bfa19894 40aeb6ce 40918978 3e9be843 3f000000 -> bf74d9fb 3fb71956 bf35fe4e 3f21280a c01277e2 403b5fe4 40464bbd bd5b4455",

View file

@ -0,0 +1,124 @@
#!/usr/bin/env python3
"""Spell one compute shader per work item, in HLSL and in GLSL ES 3.10. It compares and judges nothing.
usage: gen.py <workdir> <cultmath-root>
<workdir>/manifest.txt (written by GlslMirrorTests.WriteDeviceWork) has one tab-separated line per item:
tag, fixture index, glsl signature, n, words in, words out. For each item this writes <tag>.hlsl (cs_6_0,
includes CultMath.hlsl) and <tag>.comp (#version 310 es, the committed GLSL files, then the body). An item
reads n argument tuples of 32-bit words from binding 0 and writes n result tuples to binding 1. Struct
arguments and results are built and flattened in field order, from the struct definitions in the HLSL."""
import glob
import os
import re
import sys
HLSL_VEC = re.compile(r'(float|int|uint)([234])$')
GLSL_VEC = re.compile(r'(i|u|)vec([234])$')
KIND = {'float': 'f', 'int': 'i', 'uint': 'u'}
def structs(root):
"""struct name -> [(field, type, hlsl)] from every shader's struct definitions, GLSL type names."""
found = {}
for path in sorted(glob.glob(os.path.join(root, 'shaders', '*.hlsl'))):
for name, body in re.findall(r'(?m)^struct (\w+)\s*\{(.*?)\};', open(path).read(), re.S):
found[name] = [(f, t) for t, f in re.findall(r'(\w+)\s+(\w+);', body)]
return found
def leaves(t, defs, path=''):
"""Flatten a type (GLSL spelling for scalars and vectors, HLSL for struct fields) to scalar leaves:
(accessor path, kind) in field order. A vector's components are path[i]; a mat3 is read row by row."""
if t in KIND:
return [(path, KIND[t], None)]
m = HLSL_VEC.match(t) or GLSL_VEC.match(t)
if m:
k = {'float': 'f', 'int': 'i', 'uint': 'u', '': 'f', 'i': 'i', 'u': 'u'}[m.group(1)]
return [(path, k, i) for i in range(int(m.group(2)))]
if t in ('mat3', 'float3x3'):
return [(path, 'f', (i, j)) for i in range(3) for j in range(3)]
if t in defs:
out = []
for field, ft in defs[t]:
out += leaves(ft, defs, path + '.' + field)
return out
raise SystemExit('unsupported type ' + t)
def access(leaf, glsl):
path, _, index = leaf
if index is None:
return path
if isinstance(index, tuple): # row i, column j; GLSL matrices index the column first
return '%s[%d][%d]' % ((path,) + ((index[1], index[0]) if glsl else index))
return '%s[%d]' % (path, index)
def read(kind, glsl, word):
if glsl:
return {'f': 'uintBitsToFloat(%s)', 'i': 'int(%s)', 'u': '%s'}[kind] % word
return {'f': 'asfloat(%s)', 'i': 'asint(%s)', 'u': '%s'}[kind] % word
def write(kind, glsl, value):
if glsl:
return {'f': 'floatBitsToUint(%s)', 'i': 'uint(%s)', 'u': '%s'}[kind] % value
return {'f': 'asuint(%s)', 'i': 'asuint(%s)', 'u': '%s'}[kind] % value
def hlsl_type(t):
m = GLSL_VEC.match(t)
if m:
return {'': 'float', 'i': 'int', 'u': 'uint'}[m.group(1)] + m.group(2)
return 'float3x3' if t == 'mat3' else t
def body(sig, n, win, wout, defs, glsl):
m = re.fullmatch(r'(\w+)\s+(\w+)\((.*)\)', sig)
ret, name, params = m.group(1), m.group(2), [p.strip() for p in m.group(3).split(',') if p.strip()]
lines, offset, args = [], 0, []
for j, p in enumerate(params):
ptype = p if glsl else hlsl_type(p)
lines.append(' %s a%d;' % (ptype, j))
for leaf in leaves(p, defs):
word = ('In.a[b + %du]' if glsl else 'In[b + %d]') % offset
lines.append(' a%d%s = %s;' % (j, access(leaf, glsl), read(leaf[1], glsl, word)))
offset += 1
args.append('a%d' % j)
rtype = ret if glsl else hlsl_type(ret)
lines.append(' %s r = %s(%s);' % (rtype, name, ', '.join(args)))
produced = leaves(ret, defs)
for k, leaf in enumerate(produced):
target = ('Out.a[o + %du]' if glsl else 'Out[o + %d]') % k
lines.append(' %s = %s;' % (target, write(leaf[1], glsl, 'r' + access(leaf, glsl))))
if offset != win or len(produced) != wout:
raise SystemExit('%s: %d words in and %d out, the manifest says %d and %d' % (sig, offset, len(produced), win, wout))
head = 'uint i = id.x; if (i >= %du) return; uint b = i * %du; uint o = i * %du;' % (n, win, wout)
return head, '\n'.join(lines)
def main(work, root):
defs = structs(root)
shaders = os.path.join(root, 'shaders')
library = ''.join(open(os.path.join(shaders, f)).read() for f in ('CultMath.glsl', 'CultMath.Cycles.glsl', 'CultMath.Phacelle.glsl'))
count = 0
for line in open(os.path.join(work, 'manifest.txt')):
tag, _, sig, n, win, wout = line.rstrip('\n').split('\t')
n, win, wout = int(n), int(win), int(wout)
head, code = body(sig, n, win, wout, defs, False)
open(os.path.join(work, tag + '.hlsl'), 'w').write(
'#include "CultMath.hlsl"\n[[vk::binding(0)]] StructuredBuffer<uint> In;\n[[vk::binding(1)]] RWStructuredBuffer<uint> Out;\n'
'[numthreads(64, 1, 1)] void main(uint3 id : SV_DispatchThreadID) {\n %s\n%s\n}\n' % (head, code))
head, code = body(sig, n, win, wout, defs, True)
open(os.path.join(work, tag + '.comp'), 'w').write(
'#version 310 es\nprecision highp float;\nprecision highp int;\n' + library +
'layout(local_size_x = 64) in;\nlayout(std430, binding = 0) readonly buffer IB { uint a[]; } In;\n'
'layout(std430, binding = 1) buffer OB { uint a[]; } Out;\n'
'void main() {\n uint i = gl_GlobalInvocationID.x; %s\n%s\n}\n' % (head.replace('uint i = id.x; ', ''), code))
count += 1
print('generated', count, 'work items')
if __name__ == '__main__':
main(sys.argv[1], sys.argv[2])

View file

@ -0,0 +1,60 @@
#!/usr/bin/env bash
# The lavapipe conforming run: every fixture family, through HLSL (dxc) and GLSL (glslang), on Mesa lavapipe,
# judged by GlslMirrorTests.DeviceResultsHoldFixture. This script spells, compiles and dispatches; the C# judge
# is the only thing that compares.
#
# Run from the CultLib root inside mcr.microsoft.com/dotnet/sdk:10.0 (Ubuntu 24.04), for example
# SUMMARY=<log> tools/stopgap/ygg-verify.sh <repo> <rev> mcr.microsoft.com/dotnet/sdk:10.0 'bash packages/cultmath/tools/device/run-lavapipe.sh'
# WRITE_BOUNDS=1 re-records packages/cultmath/tests/CultMath.Tests/fixtures/device-bounds-lavapipe.txt and prints it
# between BOUNDS-BEGIN and BOUNDS-END, because the job's clone is discarded.
set -euo pipefail
ROOT=$(pwd)
CM=$ROOT/packages/cultmath
TESTS=$CM/tests/CultMath.Tests
DEV=$CM/tools/device
W=/tmp/device
SNAPSHOT=20261016T000000Z
DXC_URL=https://github.com/microsoft/DirectXShaderCompiler/releases/download/v1.9.2607/linux_dxc_2026_07_29.x86_x64.tar.gz
DXC_SHA=55665c87824051ed4774ff3280a79ccbbb7d39243b9736ca5e98222134112d54
mkdir -p "$W/dxc" "$W/results/lavapipe-hlsl" "$W/results/lavapipe-glsl"
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq --snapshot "$SNAPSHOT" >/dev/null
apt-get install -y -qq --no-install-recommends mesa-vulkan-drivers libvulkan-dev glslang-tools spirv-tools gcc libc6-dev curl ca-certificates python3 >/dev/null
curl -sL --fail -o "$W/dxc.tgz" "$DXC_URL"
echo "$DXC_SHA $W/dxc.tgz" | sha256sum -c - >/dev/null || { echo "dxc tarball sha256 differs from the pinned one"; exit 1; }
tar xzf "$W/dxc.tgz" -C "$W/dxc"
DXC=$(find "$W/dxc" -name dxc -type f | head -1)
export LD_LIBRARY_PATH=$(dirname "$DXC")/../lib:$(dirname "$DXC")${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
gcc -O2 -o "$W/vkrun" "$DEV/vkrun.c" -lvulkan
dotnet build "$TESTS" -nologo -v q >/dev/null
export CULTMATH_DEVICE_WORK=$W/work
dotnet test "$TESTS" --no-build --filter "FullyQualifiedName~GlslMirrorTests.WriteDeviceWork"
python3 "$DEV/gen.py" "$W/work" "$CM"
while IFS=$'\t' read -r tag _ _ n _ wout; do
in=$W/work/$tag.in
"$DXC" -T cs_6_0 -E main -HV 2021 -spirv -fspv-target-env=vulkan1.2 -I "$CM/shaders" "$W/work/$tag.hlsl" -Fo "$W/work/$tag.h.spv" >"$W/work/$tag.h.log" 2>&1 \
|| { echo "dxc failed for $tag"; head -5 "$W/work/$tag.h.log"; exit 1; }
glslangValidator -V --target-env vulkan1.2 -o "$W/work/$tag.g.spv" "$W/work/$tag.comp" >"$W/work/$tag.g.log" 2>&1 \
|| { echo "glslang failed for $tag"; head -5 "$W/work/$tag.g.log"; exit 1; }
"$W/vkrun" "$W/work/$tag.h.spv" "$in" "$W/results/lavapipe-hlsl/$tag.out" "$n" "$wout" >>"$W/device.txt"
"$W/vkrun" "$W/work/$tag.g.spv" "$in" "$W/results/lavapipe-glsl/$tag.out" "$n" "$wout" >>"$W/device.txt"
done <"$W/work/manifest.txt"
RENDERER=$(sort -u "$W/device.txt")
[ "$(echo "$RENDERER" | wc -l)" = 1 ] || { echo "the runs saw more than one device: $RENDERER"; exit 1; }
export CULTMATH_DEVICE_NAME=${RENDERER#device=}
export CULTMATH_DEVICE_IDENTITY="$(dpkg-query -W -f='${Package} ${Version}; ' mesa-vulkan-drivers glslang-tools)dxc $("$DXC" --version | head -1); apt snapshot $SNAPSHOT"
export CULTMATH_DEVICE_RESULTS=$W/results
echo "outputs sha256: $(cd "$W/results" && find . -type f | sort | xargs sha256sum | sha256sum | cut -c1-64)"
echo "device: $CULTMATH_DEVICE_NAME"
echo "identity: $CULTMATH_DEVICE_IDENTITY"
if [ "${WRITE_BOUNDS:-0}" = 1 ]; then
export CULTMATH_WRITE_DEVICE_BOUNDS=1
trap 'echo BOUNDS-BEGIN; cat "$TESTS/fixtures/device-bounds-lavapipe.txt"; echo BOUNDS-END' EXIT
fi
dotnet test "$TESTS" --no-build --filter "FullyQualifiedName~GlslMirrorTests.DeviceResultsHoldFixture|FullyQualifiedName~GlslMirrorTests.CommittedShadersCarryNoReducedPrecisionQualifier" --logger "console;verbosity=detailed"

View file

@ -0,0 +1,83 @@
// Vulkan compute host for the conforming run: one dispatch of a generated shader on the first Vulkan device,
// binding 0 = input words, binding 1 = output words. It prints the device's name on stdout and judges nothing.
// usage: vkrun <spv> <in.bin> <out.bin> <ncases> <out_words_per_case>
#include <vulkan/vulkan.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CK(x) do { VkResult r_ = (x); if (r_ != VK_SUCCESS) { fprintf(stderr, "FAIL %s = %d\n", #x, r_); exit(2); } } while (0)
static void *slurp(const char *p, size_t *n) {
FILE *f = fopen(p, "rb"); if (!f) { perror(p); exit(2); }
fseek(f, 0, SEEK_END); *n = ftell(f); fseek(f, 0, SEEK_SET);
void *b = malloc(*n ? *n : 4); if (fread(b, 1, *n, f) != *n) exit(2); fclose(f); return b;
}
int main(int argc, char **argv) {
if (argc != 6) { fprintf(stderr, "usage\n"); return 2; }
size_t spvn, inn; void *spv = slurp(argv[1], &spvn); void *in = slurp(argv[2], &inn);
unsigned ncases = atoi(argv[4]), ow = atoi(argv[5]); const char *entry = "main";
size_t outn = (size_t)ncases * ow * 4;
VkApplicationInfo ai = { VK_STRUCTURE_TYPE_APPLICATION_INFO, 0, "vkrun", 1, "vkrun", 1, VK_API_VERSION_1_2 };
VkInstanceCreateInfo ici = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, 0, 0, &ai };
VkInstance inst; CK(vkCreateInstance(&ici, 0, &inst));
uint32_t np = 1; VkPhysicalDevice pd; vkEnumeratePhysicalDevices(inst, &np, &pd); if (!np) { fprintf(stderr, "no device\n"); return 2; }
VkPhysicalDeviceProperties props;
vkGetPhysicalDeviceProperties(pd, &props);
printf("device=%s\n", props.deviceName);
float prio = 1; VkDeviceQueueCreateInfo qci = { VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, 0, 0, 0, 1, &prio };
VkDeviceCreateInfo dci = { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, 0, 0, 1, &qci };
VkDevice dev; CK(vkCreateDevice(pd, &dci, 0, &dev)); VkQueue q; vkGetDeviceQueue(dev, 0, 0, &q);
VkPhysicalDeviceMemoryProperties mp; vkGetPhysicalDeviceMemoryProperties(pd, &mp);
VkBuffer buf[2]; VkDeviceMemory mem[2]; size_t sz[2] = { inn, outn }; void *map[2];
for (int i = 0; i < 2; i++) {
VkBufferCreateInfo bci = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, 0, 0, sz[i], VK_BUFFER_USAGE_STORAGE_BUFFER_BIT };
CK(vkCreateBuffer(dev, &bci, 0, &buf[i])); VkMemoryRequirements mr; vkGetBufferMemoryRequirements(dev, buf[i], &mr);
uint32_t t = 0; VkMemoryPropertyFlags want = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
for (; t < mp.memoryTypeCount; t++) if ((mr.memoryTypeBits & (1u << t)) && (mp.memoryTypes[t].propertyFlags & want) == want) break;
VkMemoryAllocateInfo mai = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, 0, mr.size, t };
CK(vkAllocateMemory(dev, &mai, 0, &mem[i])); CK(vkBindBufferMemory(dev, buf[i], mem[i], 0));
CK(vkMapMemory(dev, mem[i], 0, sz[i], 0, &map[i]));
}
memcpy(map[0], in, inn); memset(map[1], 0xEE, outn);
VkDescriptorSetLayoutBinding b[2] = { { 0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT },
{ 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT } };
VkDescriptorSetLayoutCreateInfo lci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, 0, 0, 2, b };
VkDescriptorSetLayout dsl; CK(vkCreateDescriptorSetLayout(dev, &lci, 0, &dsl));
VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, 0, 0, 1, &dsl };
VkPipelineLayout pl; CK(vkCreatePipelineLayout(dev, &plci, 0, &pl));
VkShaderModuleCreateInfo smci = { VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, 0, 0, spvn, spv };
VkShaderModule sm; CK(vkCreateShaderModule(dev, &smci, 0, &sm));
VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, 0, 0,
{ VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, 0, 0, VK_SHADER_STAGE_COMPUTE_BIT, sm, entry }, pl };
VkPipeline pipe; CK(vkCreateComputePipelines(dev, 0, 1, &cpci, 0, &pipe));
VkDescriptorPoolSize ps = { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2 };
VkDescriptorPoolCreateInfo dpci = { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, 0, 0, 1, 1, &ps };
VkDescriptorPool dp; CK(vkCreateDescriptorPool(dev, &dpci, 0, &dp));
VkDescriptorSetAllocateInfo dsai = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, 0, dp, 1, &dsl };
VkDescriptorSet ds; CK(vkAllocateDescriptorSets(dev, &dsai, &ds));
VkDescriptorBufferInfo dbi[2] = { { buf[0], 0, VK_WHOLE_SIZE }, { buf[1], 0, VK_WHOLE_SIZE } };
VkWriteDescriptorSet w[2];
for (int i = 0; i < 2; i++) { VkWriteDescriptorSet x = { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 0, ds, i, 0, 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 0, &dbi[i] }; w[i] = x; }
vkUpdateDescriptorSets(dev, 2, w, 0, 0);
VkCommandPoolCreateInfo cpi = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, 0, 0, 0 };
VkCommandPool cp; CK(vkCreateCommandPool(dev, &cpi, 0, &cp));
VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, 0, cp, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
VkCommandBuffer cb; CK(vkAllocateCommandBuffers(dev, &cbai, &cb));
VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
CK(vkBeginCommandBuffer(cb, &cbbi));
vkCmdBindPipeline(cb, VK_PIPELINE_BIND_POINT_COMPUTE, pipe);
vkCmdBindDescriptorSets(cb, VK_PIPELINE_BIND_POINT_COMPUTE, pl, 0, 1, &ds, 0, 0);
vkCmdDispatch(cb, (ncases + 63) / 64, 1, 1);
CK(vkEndCommandBuffer(cb));
VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, 0, 0, 0, 0, 1, &cb };
CK(vkQueueSubmit(q, 1, &si, 0)); CK(vkQueueWaitIdle(q));
FILE *f = fopen(argv[3], "wb"); fwrite(map[1], 1, outn, f); fclose(f);
return 0;
}