zdxc: make the tree a clean public source drop
Move the oracle tests, the benchmark, the agent skill and the libzdxc investigation notes to the zdxc-internal development repo, which builds this tree as a path dependency. The public build keeps install, run and test. build.zig.zon now lists tools/ (the build needs its generators) and docs/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
33d390816f
commit
05076bb91a
|
|
@ -1,26 +0,0 @@
|
||||||
---
|
|
||||||
name: zig
|
|
||||||
description: Work on Zig 0.17 code and build files using the documentation and standard-library source shipped with the active compiler. Use for writing, reviewing, debugging, or migrating Zig in this repository.
|
|
||||||
---
|
|
||||||
|
|
||||||
# Zig 0.17
|
|
||||||
|
|
||||||
Use the installed Zig toolchain as the source of truth. Do not rely on remembered
|
|
||||||
APIs or hand-maintained summaries when the compiler distribution can answer the
|
|
||||||
question directly.
|
|
||||||
|
|
||||||
- Run `zig env` to locate `zig_exe`, `lib_dir`, and `std_dir`; do not assume a
|
|
||||||
particular installation path.
|
|
||||||
- Consult `<directory containing zig_exe>/doc/langref.html` for language syntax,
|
|
||||||
semantics, and builtins.
|
|
||||||
- Search `std_dir` for exact APIs, implementations, and tests. Use them as
|
|
||||||
examples of both correct usage and Zig coding style; follow standard-library
|
|
||||||
conventions.
|
|
||||||
- Use compiler and test failures to verify any inferred API usage.
|
|
||||||
|
|
||||||
For `if` conditions, put continuation `and`/`or` operators at the start of
|
|
||||||
the next line. Run `zig fmt` on changed Zig files.
|
|
||||||
|
|
||||||
If the installed documentation is unavailable, use the versioned official
|
|
||||||
reference at <https://ziglang.org/documentation/0.17.0/>; download a copy once and
|
|
||||||
avoid unnecessary traffic.
|
|
||||||
|
|
@ -1,121 +0,0 @@
|
||||||
//! Preprocessor benchmark: lexes / preprocesses a set of files in-process
|
|
||||||
//! and reports the best-of-N wall time and throughput.
|
|
||||||
//!
|
|
||||||
//! Usage: pp_bench [-mode lex|load|pp|print|parse] [-iters N] <file-list.txt>
|
|
||||||
//! The file list has one path per line. File contents are read once and
|
|
||||||
//! served from memory, so disk I/O is excluded from the timings.
|
|
||||||
|
|
||||||
const std = @import("std");
|
|
||||||
const Io = std.Io;
|
|
||||||
const zdxc = @import("zdxc");
|
|
||||||
const front = zdxc.front;
|
|
||||||
|
|
||||||
const Mode = enum { lex, load, pp, print, parse };
|
|
||||||
|
|
||||||
/// Serves each path from memory after the first read.
|
|
||||||
const CachedFs = struct {
|
|
||||||
io: Io,
|
|
||||||
gpa: std.mem.Allocator,
|
|
||||||
files: std.StringHashMapUnmanaged(?[]const u8) = .empty,
|
|
||||||
|
|
||||||
fn fileSystem(c: *CachedFs) front.source.FileSystem {
|
|
||||||
return .{ .ctx = c, .readFn = readImpl };
|
|
||||||
}
|
|
||||||
|
|
||||||
fn readImpl(ctx: *anyopaque, _: std.mem.Allocator, path: []const u8) ?[]const u8 {
|
|
||||||
const c: *CachedFs = @ptrCast(@alignCast(ctx));
|
|
||||||
const gop = c.files.getOrPut(c.gpa, path) catch return null;
|
|
||||||
if (!gop.found_existing) {
|
|
||||||
gop.key_ptr.* = c.gpa.dupe(u8, path) catch return null;
|
|
||||||
gop.value_ptr.* = Io.Dir.cwd().readFileAlloc(c.io, path, c.gpa, .limited(256 << 20)) catch null;
|
|
||||||
}
|
|
||||||
return gop.value_ptr.*;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn main(init: std.process.Init) !void {
|
|
||||||
const gpa = init.gpa;
|
|
||||||
const io = init.io;
|
|
||||||
const arena = init.arena.allocator();
|
|
||||||
const args = try init.minimal.args.toSlice(arena);
|
|
||||||
|
|
||||||
var mode: Mode = .pp;
|
|
||||||
var iters: usize = 5;
|
|
||||||
var list_path: ?[]const u8 = null;
|
|
||||||
var i: usize = 1;
|
|
||||||
while (i < args.len) : (i += 1) {
|
|
||||||
if (std.mem.eql(u8, args[i], "-mode")) {
|
|
||||||
i += 1;
|
|
||||||
mode = std.meta.stringToEnum(Mode, args[i]) orelse return error.BadMode;
|
|
||||||
} else if (std.mem.eql(u8, args[i], "-iters")) {
|
|
||||||
i += 1;
|
|
||||||
iters = try std.fmt.parseInt(usize, args[i], 10);
|
|
||||||
} else list_path = args[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
const list = try Io.Dir.cwd().readFileAlloc(io, list_path orelse return error.MissingFileList, arena, .limited(64 << 20));
|
|
||||||
var paths: std.ArrayList([]const u8) = .empty;
|
|
||||||
var it = std.mem.tokenizeScalar(u8, list, '\n');
|
|
||||||
while (it.next()) |p| try paths.append(arena, p);
|
|
||||||
|
|
||||||
var cfs: CachedFs = .{ .io = io, .gpa = gpa };
|
|
||||||
var total_bytes: usize = 0;
|
|
||||||
for (paths.items) |p| {
|
|
||||||
if (CachedFs.readImpl(&cfs, gpa, p)) |text| total_bytes += text.len;
|
|
||||||
}
|
|
||||||
|
|
||||||
var best: u64 = std.math.maxInt(u64);
|
|
||||||
var checksum: u64 = 0;
|
|
||||||
for (0..iters) |_| {
|
|
||||||
const start = Io.Timestamp.now(io, .awake);
|
|
||||||
checksum = 0;
|
|
||||||
for (paths.items) |p| checksum +%= try runOne(gpa, &cfs, p, mode);
|
|
||||||
const ns: u64 = @intCast(start.durationTo(Io.Timestamp.now(io, .awake)).nanoseconds);
|
|
||||||
best = @min(best, ns);
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf: [256]u8 = undefined;
|
|
||||||
var w = Io.File.Writer.init(.stdout(), io, &buf);
|
|
||||||
const mb = @as(f64, @floatFromInt(total_bytes)) / (1024.0 * 1024.0);
|
|
||||||
const secs = @as(f64, @floatFromInt(best)) / 1e9;
|
|
||||||
try w.interface.print("{s}: {d} files, {d:.1} MB, best {d:.2} ms, {d:.0} MB/s (checksum {d})\n", .{
|
|
||||||
@tagName(mode), paths.items.len, mb, secs * 1000.0, mb / secs, checksum,
|
|
||||||
});
|
|
||||||
try w.interface.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn runOne(gpa: std.mem.Allocator, cfs: *CachedFs, path: []const u8, mode: Mode) !u64 {
|
|
||||||
var arena_state: std.heap.ArenaAllocator = .init(gpa);
|
|
||||||
defer arena_state.deinit();
|
|
||||||
const arena = arena_state.allocator();
|
|
||||||
|
|
||||||
if (mode == .lex) {
|
|
||||||
const text = CachedFs.readImpl(cfs, gpa, path) orelse return 0;
|
|
||||||
var lx = front.lexer.Lexer.init(text, 0);
|
|
||||||
var n: u64 = 0;
|
|
||||||
while (lx.next().kind != .eof) n += 1;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sm = front.source.SourceManager.init(arena, cfs.fileSystem());
|
|
||||||
if (mode == .load) {
|
|
||||||
const id = try sm.load(path) orelse return 0;
|
|
||||||
return sm.file(id).line_starts.len;
|
|
||||||
}
|
|
||||||
var diags = zdxc.Diagnostics.init(arena);
|
|
||||||
var pp = front.preproc.Preprocessor.init(arena, &sm, &diags, .{});
|
|
||||||
if (!try pp.enterMainFile(path)) return 0;
|
|
||||||
if (mode == .parse) {
|
|
||||||
var parser = try front.parser.Parser.fromPreprocessor(arena, &diags, &pp);
|
|
||||||
const tu = try parser.parseTranslationUnit();
|
|
||||||
return tu.decls.len + diags.error_count;
|
|
||||||
}
|
|
||||||
if (mode == .print) {
|
|
||||||
var out: Io.Writer.Allocating = .init(arena);
|
|
||||||
try front.pp_print.print(&pp, &out.writer);
|
|
||||||
return out.written().len;
|
|
||||||
}
|
|
||||||
var n: u64 = 0;
|
|
||||||
while ((try pp.next()).kind != .eof) n += 1;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
83
build.zig
83
build.zig
|
|
@ -65,87 +65,4 @@ pub fn build(b: *std.Build) void {
|
||||||
test_step.dependOn(&b.addRunArtifact(mod_tests).step);
|
test_step.dependOn(&b.addRunArtifact(mod_tests).step);
|
||||||
const exe_tests = b.addTest(.{ .root_module = exe.root_module });
|
const exe_tests = b.addTest(.{ .root_module = exe.root_module });
|
||||||
test_step.dependOn(&b.addRunArtifact(exe_tests).step);
|
test_step.dependOn(&b.addRunArtifact(exe_tests).step);
|
||||||
|
|
||||||
// Oracle checks: compare zdxc output against the DXC build in ../build.
|
|
||||||
const oracle_step = b.step("oracle", "Validate zdxc output with dxv and spirv-val");
|
|
||||||
const oracle = b.addSystemCommand(&.{ "sh", "test/oracle/m0.sh" });
|
|
||||||
oracle.addArtifactArg(exe);
|
|
||||||
oracle.setCwd(b.path("."));
|
|
||||||
oracle.has_side_effects = true;
|
|
||||||
oracle_step.dependOn(&oracle.step);
|
|
||||||
const dxil_checks = b.addSystemCommand(&.{ "sh", "test/dxil/check.sh" });
|
|
||||||
dxil_checks.addArtifactArg(exe);
|
|
||||||
dxil_checks.setCwd(b.path("."));
|
|
||||||
dxil_checks.has_side_effects = true;
|
|
||||||
oracle_step.dependOn(&dxil_checks.step);
|
|
||||||
const spirv_checks = b.addSystemCommand(&.{ "sh", "test/spirv/check.sh" });
|
|
||||||
spirv_checks.addArtifactArg(exe);
|
|
||||||
spirv_checks.setCwd(b.path("."));
|
|
||||||
spirv_checks.has_side_effects = true;
|
|
||||||
oracle_step.dependOn(&spirv_checks.step);
|
|
||||||
const job_checks = b.addSystemCommand(&.{ "sh", "test/job/check.sh" });
|
|
||||||
job_checks.addArtifactArg(exe);
|
|
||||||
job_checks.setCwd(b.path("."));
|
|
||||||
job_checks.has_side_effects = true;
|
|
||||||
oracle_step.dependOn(&job_checks.step);
|
|
||||||
|
|
||||||
const oracle_parse_step = b.step("oracle-parse", "Parse every dxc-valid corpus file with zdxc");
|
|
||||||
const oracle_parse = b.addSystemCommand(&.{ "sh", "test/oracle/parse.sh" });
|
|
||||||
oracle_parse.addArtifactArg(exe);
|
|
||||||
oracle_parse.setCwd(b.path("."));
|
|
||||||
oracle_parse.has_side_effects = true;
|
|
||||||
oracle_parse_step.dependOn(&oracle_parse.step);
|
|
||||||
|
|
||||||
const oracle_sema_step = b.step("oracle-sema", "Check that Sema accepts every dxc-valid corpus file");
|
|
||||||
const oracle_sema = b.addSystemCommand(&.{ "sh", "test/oracle/sema.sh" });
|
|
||||||
oracle_sema.addArtifactArg(exe);
|
|
||||||
oracle_sema.setCwd(b.path("."));
|
|
||||||
oracle_sema.has_side_effects = true;
|
|
||||||
oracle_sema.step.dependOn(&oracle_parse.step); // builds the corpus list
|
|
||||||
oracle_sema_step.dependOn(&oracle_sema.step);
|
|
||||||
|
|
||||||
const oracle_codegen_step = b.step("oracle-codegen", "Compile the dxc-valid corpus to SPIR-V and DXIL and validate the output");
|
|
||||||
for ([_][]const u8{ "spirv", "dxil" }) |backend| {
|
|
||||||
const run = b.addSystemCommand(&.{ "sh", "test/oracle/codegen.sh" });
|
|
||||||
run.addArtifactArg(exe);
|
|
||||||
run.addArg(backend);
|
|
||||||
run.setCwd(b.path("."));
|
|
||||||
run.has_side_effects = true;
|
|
||||||
run.step.dependOn(&oracle_parse.step); // builds the corpus list
|
|
||||||
oracle_codegen_step.dependOn(&run.step);
|
|
||||||
}
|
|
||||||
|
|
||||||
const oracle_verify_step = b.step("oracle-verify", "Compare Sema errors with dxc's SemaHLSL -verify expectations");
|
|
||||||
const oracle_verify = b.addSystemCommand(&.{ "sh", "test/oracle/verify.sh" });
|
|
||||||
oracle_verify.addArtifactArg(exe);
|
|
||||||
oracle_verify.setCwd(b.path("."));
|
|
||||||
oracle_verify.has_side_effects = true;
|
|
||||||
oracle_verify_step.dependOn(&oracle_verify.step);
|
|
||||||
|
|
||||||
const oracle_cli_step = b.step("oracle-cli", "Parse every dxc command line in the DXC test corpus");
|
|
||||||
const oracle_cli = b.addSystemCommand(&.{ "sh", "test/oracle/cli.sh" });
|
|
||||||
oracle_cli.addArtifactArg(exe);
|
|
||||||
oracle_cli.setCwd(b.path("."));
|
|
||||||
oracle_cli.has_side_effects = true;
|
|
||||||
oracle_cli_step.dependOn(&oracle_cli.step);
|
|
||||||
|
|
||||||
// Benchmarks always build optimized so numbers are comparable.
|
|
||||||
const bench = b.addExecutable(.{
|
|
||||||
.name = "pp_bench",
|
|
||||||
.root_module = b.createModule(.{
|
|
||||||
.root_source_file = b.path("bench/pp_bench.zig"),
|
|
||||||
.target = target,
|
|
||||||
.optimize = .ReleaseFast,
|
|
||||||
.imports = &.{.{ .name = "zdxc", .module = mod }},
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
const bench_step = b.step("bench", "Build the preprocessor benchmark (zig-out/bin/pp_bench)");
|
|
||||||
bench_step.dependOn(&b.addInstallArtifact(bench, .{}).step);
|
|
||||||
|
|
||||||
const oracle_pp_step = b.step("oracle-pp", "Compare zdxc -P with dxc -P over the DXC test corpus");
|
|
||||||
const oracle_pp = b.addSystemCommand(&.{ "sh", "test/oracle/pp.sh" });
|
|
||||||
oracle_pp.addArtifactArg(exe);
|
|
||||||
oracle_pp.setCwd(b.path("."));
|
|
||||||
oracle_pp.has_side_effects = true;
|
|
||||||
oracle_pp_step.dependOn(&oracle_pp.step);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"build.zig",
|
"build.zig",
|
||||||
"build.zig.zon",
|
"build.zig.zon",
|
||||||
|
"docs",
|
||||||
"src",
|
"src",
|
||||||
|
"tools",
|
||||||
"vendor",
|
"vendor",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ Every job writes its own `-Fo` / `-Fh` / ... outputs. What a job prints —
|
||||||
diagnostics, and text output such as `-P` without a file — comes out
|
diagnostics, and text output such as `-P` without a file — comes out
|
||||||
exactly as one zdxc run of that command line would print it, kept together
|
exactly as one zdxc run of that command line would print it, kept together
|
||||||
and in job order, whatever order the jobs finish in. The outputs are
|
and in job order, whatever order the jobs finish in. The outputs are
|
||||||
byte-identical to separate runs (`test/job/check.sh` checks this).
|
byte-identical to separate runs.
|
||||||
|
|
||||||
When jobs fail, the other jobs still run, and a last line says how many
|
When jobs fail, the other jobs still run, and a last line says how many
|
||||||
failed:
|
failed:
|
||||||
|
|
|
||||||
|
|
@ -1,310 +0,0 @@
|
||||||
# libzdxc: matching DXC's library API
|
|
||||||
|
|
||||||
Status: investigation notes, not yet implemented. Source references are to the
|
|
||||||
DXC tree at `f9fc72ad3`.
|
|
||||||
|
|
||||||
## How DXC works as a library
|
|
||||||
|
|
||||||
`dxcompiler` (`libdxcompiler.so` / `.dylib`, `dxcompiler.dll`) exports
|
|
||||||
exactly two C symbols (`tools/clang/tools/dxcompiler/dxcompiler.def`):
|
|
||||||
|
|
||||||
```c
|
|
||||||
HRESULT DxcCreateInstance (REFCLSID rclsid, REFIID riid, void **ppv);
|
|
||||||
HRESULT DxcCreateInstance2(IMalloc *pMalloc, REFCLSID rclsid, REFIID riid, void **ppv);
|
|
||||||
```
|
|
||||||
|
|
||||||
Everything else is a COM-style interface reached from those two calls.
|
|
||||||
`DxcCreateInstance` is a CLSID switch (`dxcapi.cpp`,
|
|
||||||
`ThreadMallocDxcCreateInstance`) that returns `REGDB_E_CLASSNOTREG`
|
|
||||||
(0x80040154) for unknown classes. `DxcCreateInstance2` installs a
|
|
||||||
caller-supplied `IMalloc` as the allocator for that object's lifetime.
|
|
||||||
|
|
||||||
The `dxc` executable is itself a thin client. It `dlopen`s dxcompiler through
|
|
||||||
`include/dxc/Support/dxcapi.use.h` and drives it with `CLSID_DxcCompiler`,
|
|
||||||
`CLSID_DxcLibrary`, and so on (`tools/clang/tools/dxclib/dxc.cpp`). The command
|
|
||||||
line and the API share one option parser: the arguments passed to
|
|
||||||
`IDxcCompiler3::Compile` are dxc command-line flags as wide strings.
|
|
||||||
|
|
||||||
### Classes and interfaces
|
|
||||||
|
|
||||||
| CLSID | Interfaces it answers `QueryInterface` for | Typical use |
|
|
||||||
|---|---|---|
|
|
||||||
| `CLSID_DxcCompiler` | `IDxcCompiler3`, `IDxcVersionInfo`, `IDxcVersionInfo2/3`, `IDxcLangExtensions*`, `IDxcContainerEvent`; legacy `IDxcCompiler`, `IDxcCompiler2` via an adapter sub-object (`dxcompilerobj.cpp:499`) | compile, preprocess, disassemble |
|
|
||||||
| `CLSID_DxcUtils` == `CLSID_DxcLibrary` (same GUID) | `IDxcUtils`, legacy `IDxcLibrary` | blobs, default include handler, `BuildArguments`, `CreateReflection`, `GetDxilContainerPart` |
|
|
||||||
| `CLSID_DxcCompilerArgs` | `IDxcCompilerArgs` | building argument lists |
|
|
||||||
| `CLSID_DxcValidator` | `IDxcValidator`, `IDxcValidator2`, `IDxcVersionInfo` | validation and signing (also exported by the separate `dxil` library) |
|
|
||||||
| `CLSID_DxcContainerReflection` | `IDxcContainerReflection` | listing container parts, `ID3D12ShaderReflection` |
|
|
||||||
| `CLSID_DxcContainerBuilder` | `IDxcContainerBuilder` | adding and removing parts |
|
|
||||||
| `CLSID_DxcAssembler`, `CLSID_DxcOptimizer`, `CLSID_DxcLinker`, `CLSID_DxcPdbUtils`, `CLSID_DxcRewriter`, `CLSID_DxcIntelliSense` | — | LLVM-IR tooling, PDBs, IntelliSense |
|
|
||||||
|
|
||||||
### Compile contract (`IDxcCompiler3::Compile`, `dxcompilerobj.cpp:517`)
|
|
||||||
|
|
||||||
- Inputs: a `DxcBuffer` (pointer, size, code page; 0 means detect a BOM,
|
|
||||||
otherwise treat as UTF-8), `LPCWSTR` argv, an optional `IDxcIncludeHandler`,
|
|
||||||
and an `riid` that must be `IDxcResult` or `IDxcOperationResult`. Any other
|
|
||||||
`riid`, a null source, or a null argv with `argCount > 0` returns
|
|
||||||
`E_INVALIDARG`.
|
|
||||||
- **Compile errors do not fail the call.** `Compile` returns `S_OK` and the
|
|
||||||
result's `GetStatus` reports `E_FAIL`. The call itself fails only for API
|
|
||||||
misuse or out-of-memory. Clients depend on this.
|
|
||||||
- Outputs are keyed by `DXC_OUT_KIND`: `OBJECT` (DXIL container or SPIR-V
|
|
||||||
words), `ERRORS` (UTF-8 diagnostic text, also present on success when there
|
|
||||||
are warnings), `HLSL` (`-P`), `REFLECTION`, `SHADER_HASH`, `ROOT_SIGNATURE`,
|
|
||||||
`PDB`, and others. Each output can carry a name taken from the flags (`-Fo`,
|
|
||||||
`-Fre`, `-Fsh`, ...). The library never writes files; the client does.
|
|
||||||
- The source name is the first positional argument, or `hlsl.hlsl` if there is
|
|
||||||
none (`dxcompilerobj.cpp:588`). That name appears in diagnostics.
|
|
||||||
- Includes go through a virtual file system (`dxcfilesystem.cpp`). Clang's
|
|
||||||
header search builds each candidate path (including file's directory, then
|
|
||||||
`-I` directories) and passes it through `NormalizePathW` (`Support/Path.h`):
|
|
||||||
`\` becomes `/` on Unix, doubled slashes collapse, and relative paths get a
|
|
||||||
`./` prefix. Each candidate is then handed to `LoadSource`. **A failed
|
|
||||||
`LoadSource` means "try the next candidate", not "abort".** With a null
|
|
||||||
handler, nothing except the main buffer resolves, and DXC never touches the
|
|
||||||
disk itself. `IDxcUtils::CreateDefaultIncludeHandler` is the one that reads
|
|
||||||
from disk (`dxclibrary.cpp:41`).
|
|
||||||
|
|
||||||
## ABI facts libzdxc must match
|
|
||||||
|
|
||||||
These are exactly where a "looks right" reimplementation silently breaks.
|
|
||||||
|
|
||||||
1. **Vtable layout.** On Unix, `IUnknown` has three pure virtuals and *no
|
|
||||||
virtual destructor*. The destructor was removed specifically for ABI
|
|
||||||
(`47f31378a`, #3793). An interface pointer points at a vptr, and the vtable
|
|
||||||
is the base's slots followed by each derived interface's methods in
|
|
||||||
declaration order. This holds on both Itanium and MSVC, so one Zig
|
|
||||||
`extern struct { vtable: *const VTable }` layout serves both.
|
|
||||||
2. **Calling convention.** `STDMETHODCALLTYPE` and `__stdcall` are empty on Unix
|
|
||||||
(plain C convention). On Windows, use `callconv(.winapi)`. Two methods,
|
|
||||||
`IDxcResult::GetOutputByIndex` and `PrimaryOutput`, are declared without
|
|
||||||
`STDMETHODCALLTYPE`. They only differ on 32-bit Windows (`__thiscall`), which
|
|
||||||
can be ignored unless x86-32 is a target.
|
|
||||||
3. **`BOOL` is `bool` (1 byte) on Unix** (`WinAdapter.h:306`) and `int`
|
|
||||||
(4 bytes) on Windows. This affects `IDxcResult::HasOutput`,
|
|
||||||
`IDxcBlobEncoding::GetEncoding(BOOL *)`, and `IDxcPdbUtils::IsFullPDB`.
|
|
||||||
4. **`WCHAR` is `wchar_t`: UTF-32 on Unix, UTF-16 on Windows.** All `LPCWSTR`
|
|
||||||
arguments, file names passed to `LoadSource`, and `IDxcBlobWide` contents
|
|
||||||
follow this. `DXC_CP_WIDE` is `DXC_CP_UTF32` on Unix.
|
|
||||||
5. **`ULONG` is `unsigned long` on Unix** (64-bit on LP64). That is what
|
|
||||||
`AddRef`/`Release` return; in Zig that is `c_ulong`.
|
|
||||||
6. **GUIDs.** `__uuidof` is emulated on the client side through
|
|
||||||
`CROSS_PLATFORM_UUIDOF` templates, so the library only needs to compare
|
|
||||||
16-byte `GUID` values.
|
|
||||||
7. **HRESULTs** use the Windows values: `E_NOINTERFACE` 0x80004002, `E_NOTIMPL`
|
|
||||||
0x80004001, `E_POINTER` 0x80004003, `E_INVALIDARG`, `E_OUTOFMEMORY`,
|
|
||||||
`E_FAIL`, `REGDB_E_CLASSNOTREG`.
|
|
||||||
8. **Ownership.** Every returned interface carries one reference. Reference
|
|
||||||
counts must be atomic: DXC lets separate instances run on separate threads,
|
|
||||||
and clients release objects from any thread. Objects that clients pass in
|
|
||||||
(include handler, blobs) are borrowed; take an `AddRef` only when keeping
|
|
||||||
them.
|
|
||||||
9. **No unwinding across the boundary.** Every exported function and vtable
|
|
||||||
entry must catch every Zig error and turn it into an HRESULT.
|
|
||||||
|
|
||||||
## Proposed shape
|
|
||||||
|
|
||||||
### Layering
|
|
||||||
|
|
||||||
```
|
|
||||||
src/compile.zig Zig-native API: compile(gpa, Request) -> Result
|
|
||||||
Request { source, name, args: []const []const u8, fs: source.FileSystem }
|
|
||||||
Result { status, outputs: [kind]?Output } (bytes + name + code page)
|
|
||||||
src/options.zig dxc argv parser built on options_table (moved out of main.zig)
|
|
||||||
src/capi/ COM layer; the only code that knows about GUIDs and vtables
|
|
||||||
types.zig GUID, HRESULT, BOOL/WCHAR per target, CLSIDs/IIDs from dxcapi.h
|
|
||||||
object.zig Object(Impl, .{ interfaces... }) — atomic refcount, comptime QI table
|
|
||||||
blob.zig IDxcBlob / Encoding / Utf8 / Wide over owned, pinned, or IMalloc memory
|
|
||||||
result.zig IDxcResult + IDxcOperationResult over compile.Result
|
|
||||||
include.zig IDxcIncludeHandler -> source.FileSystem adapter (+ default disk handler)
|
|
||||||
compiler.zig IDxcCompiler3 (+ legacy IDxcCompiler/2 adapter), IDxcVersionInfo
|
|
||||||
utils.zig IDxcUtils, IDxcLibrary, IDxcCompilerArgs
|
|
||||||
exports.zig export fn DxcCreateInstance / DxcCreateInstance2
|
|
||||||
src/main.zig CLI built on compile.zig — the same relationship dxc has with dxcompiler
|
|
||||||
```
|
|
||||||
|
|
||||||
The important split is that `compile.zig` is the real library and `capi/` is a
|
|
||||||
translation shell. The CLI and the COM layer then exercise one code path. Zig
|
|
||||||
users can import the `zdxc` module and call `compile` directly with no COM.
|
|
||||||
|
|
||||||
Existing pieces already fit:
|
|
||||||
|
|
||||||
- `source.FileSystem` is a vtable, so an `IDxcIncludeHandler` adapter is a
|
|
||||||
single `read` implementation. It converts the candidate path to `WCHAR`,
|
|
||||||
calls `LoadSource`, decodes the blob to UTF-8, and maps failure to `null`.
|
|
||||||
The preprocessor must still produce dxc's candidate-path sequence and
|
|
||||||
`NormalizePathW` spelling, because handlers often match on exact strings.
|
|
||||||
Add an oracle test that logs `LoadSource` calls from both libraries.
|
|
||||||
- `Diagnostics.render` already writes to an `Io.Writer`. `DXC_OUT_ERRORS` is
|
|
||||||
that text rendered without color, in dxc's default format.
|
|
||||||
- `DxcCreateInstance2`'s `IMalloc` wraps directly into a `std.mem.Allocator`
|
|
||||||
(`Alloc` / `Realloc` / `Free`), which becomes the `gpa` for that object.
|
|
||||||
|
|
||||||
### Build artifacts
|
|
||||||
|
|
||||||
- `zig build` installs `libzdxc` both as a static library and as a shared
|
|
||||||
library. An option such as `-Ddxcompiler-name` would also name the shared
|
|
||||||
library `libdxcompiler.{so,dylib}` / `dxcompiler.dll`, so existing loaders
|
|
||||||
(`dxcapi.use.h`, hassle-rs, engines that `dlopen` by name) work unmodified.
|
|
||||||
- Optionally, add a `dxil` shim exporting `DxcCreateInstance` for
|
|
||||||
`CLSID_DxcValidator` only. Some clients, such as wgpu through hassle-rs,
|
|
||||||
require `dxil.dll` to load. Since zdxc signs its own output, that validator
|
|
||||||
can re-check the hash and return `S_OK`.
|
|
||||||
- Ship no headers of our own: clients keep using DXC's `dxcapi.h`. The ABI is
|
|
||||||
the contract.
|
|
||||||
|
|
||||||
### Staging
|
|
||||||
|
|
||||||
| Stage | Surface | Who needs it |
|
|
||||||
|---|---|---|
|
|
||||||
| L0 | exports, `IUnknown` machinery, blob family, `IDxcUtils` (`CreateBlob`, `CreateBlobFromPinned`, `LoadFile`, `CreateDefaultIncludeHandler`, `GetBlobAsUtf8`), `IDxcCompiler3::Compile` (no `Disassemble`), `IDxcResult`, `IDxcVersionInfo` | modern engines; enough to run the drop-in oracle |
|
|
||||||
| L1 | legacy `IDxcLibrary`, `IDxcCompiler`/`IDxcCompiler2` (`Compile`, `Preprocess`), `IDxcOperationResult`, `IDxcCompilerArgs`, `IDxcUtils::BuildArguments` | hassle-rs and wgpu, older engines, `-P` users |
|
|
||||||
| L2 | `IDxcContainerReflection` (part listing), `IDxcUtils::GetDxilContainerPart`, `IDxcContainerBuilder`, `IDxcValidator` (hash check) | tooling that inspects containers |
|
|
||||||
| L3 | `IDxcUtils::CreateReflection` / `GetPartReflection` → `ID3D12ShaderReflection` (`d3d12shader.h`) | engines building root signatures from reflection |
|
|
||||||
| — | `Disassemble`, assembler, optimizer, linker, PDB utils, IntelliSense, rewriter, DIA | return `E_NOTIMPL` or `REGDB_E_CLASSNOTREG`, matching the plan's dropped list |
|
|
||||||
|
|
||||||
L3 is the expensive stage. DXC's `ID3D12ShaderReflection` reads the DXIL
|
|
||||||
module from the container's STAT part and walks its metadata, plus RDAT for
|
|
||||||
libraries. zdxc can serve it from bytes it wrote itself, but the reflection
|
|
||||||
interface is large (types, variables, constant buffers, bindings). Because
|
|
||||||
`CreateReflection` takes only a blob, the data must come from the container,
|
|
||||||
not from the compiler's memory. Schedule this alongside M0.1's reflection-match
|
|
||||||
exit criterion. SPIR-V clients use SPIRV-Reflect, not DXC, so it is DXIL-only.
|
|
||||||
|
|
||||||
Versioning: `IDxcVersionInfo::GetVersion` should report the DXC version
|
|
||||||
whose behavior zdxc matches (clients gate features on it), and
|
|
||||||
`IDxcVersionInfo3::GetCustomVersionString` should report `zdxc <version>`.
|
|
||||||
|
|
||||||
## Being a backend for Slang and SDL_shadercross
|
|
||||||
|
|
||||||
Read from Slang `c959b56` (`source/compiler-core/slang-dxc-compiler.cpp`) and
|
|
||||||
SDL_shadercross `1ff05be` (`src/SDL_shadercross.c`,
|
|
||||||
`cmake/FindDirectXShaderCompiler.cmake`). Neither client needs code changes:
|
|
||||||
both reach DXC only through `DxcCreateInstance`, so a library that matches the
|
|
||||||
ABI and is installed under DXC's names is a drop-in replacement. Both feed
|
|
||||||
DXC *machine-generated* HLSL, which makes them good acceptance corpora.
|
|
||||||
|
|
||||||
### SDL_shadercross (smallest surface; best first target)
|
|
||||||
|
|
||||||
- **Linking:** the DXC library is linked at build time (`extern
|
|
||||||
DxcCreateInstance`), not loaded with `dlopen`. CMake finds it either as a
|
|
||||||
vendored DXC subproject or through `FindDirectXShaderCompiler.cmake` with
|
|
||||||
`DirectXShaderCompiler_ROOT`. On non-Windows, that module *requires*
|
|
||||||
`dxcapi.h` in an include directory plus `libdxcompiler` and `libdxil`
|
|
||||||
libraries, even though the C code declares its own vtables and never includes
|
|
||||||
the header. So a zdxc install tree would need `include/dxcapi.h` (a
|
|
||||||
placeholder file would satisfy the lookup), `lib/libdxcompiler.*`, and a
|
|
||||||
`lib/libdxil.*` stub.
|
|
||||||
- **API used:** `CLSID_DxcCompiler`→`IDxcCompiler3::Compile`,
|
|
||||||
`CLSID_DxcUtils`→`IDxcUtils::CreateDefaultIncludeHandler`, and on
|
|
||||||
`IDxcResult`: `GetStatus`, `GetOutput(DXC_OUT_OBJECT, IID_IDxcBlob)`,
|
|
||||||
`GetOutput(DXC_OUT_ERRORS, IID_IDxcBlobUtf8)` (read on success too, for
|
|
||||||
warnings). That is exactly L0.
|
|
||||||
- **Inputs:** `DxcBuffer.Size = strlen + 1`, so **the source buffer includes
|
|
||||||
its NUL terminator**, and the encoding is `DXC_CP_ACP` (0). Arguments are
|
|
||||||
`-D…`, `-E`, `-I <dir>`, `-T {vs,ps,cs}_6_0` only, an optional bare source
|
|
||||||
name, and `-Zi` for debug builds. For SPIR-V: `-spirv
|
|
||||||
-fspv-flatten-resource-arrays -fspv-preserve-interface`, plus
|
|
||||||
`-fspv-preserve-bindings` unless unused bindings are culled, and
|
|
||||||
`-fspv-debug=vulkan-with-source` for debug builds. There is no `-HV`, so
|
|
||||||
dxc's default of 2021 applies.
|
|
||||||
- **Pipeline:** by default, `CompileDXILFromHLSL` **round-trips**:
|
|
||||||
HLSL →(DXC `-spirv`)→ SPIR-V →(SPIRV-Cross, `HLSL_SHADER_MODEL`)→ HLSL
|
|
||||||
→(DXC)→ DXIL. MSL output and all resource reflection come from SPIRV-Cross
|
|
||||||
reading DXC's SPIR-V, and DXC's own reflection is never used. Consequences:
|
|
||||||
- Both backends are on the critical path, and the DXIL backend must accept
|
|
||||||
SPIRV-Cross-generated HLSL.
|
|
||||||
- zdxc's SPIR-V must satisfy SPIRV-Cross, not just `spirv-val`. That means
|
|
||||||
the names, decorations, and interface variables reflection depends on, and
|
|
||||||
the three `-fspv-*` flags above.
|
|
||||||
- No `ID3D12ShaderReflection`, linker, or disassembler is needed.
|
|
||||||
- **Fit with the plan:** vs/ps/cs at 6.0 is inside M0.1. Shadercross is the
|
|
||||||
cheapest real client: L0 plus four `-fspv-*` flags.
|
|
||||||
|
|
||||||
### Slang
|
|
||||||
|
|
||||||
- **Platform gate:** `SLANG_ENABLE_DXIL_SUPPORT` defaults to **0 on Apple
|
|
||||||
platforms**, so stock Slang on macOS never calls dxcompiler. Testing on this
|
|
||||||
Mac needs a Slang build configured with it set to 1, or a Linux/Windows host.
|
|
||||||
- **Loading:** `dlopen("dxcompiler")` (or a path set with
|
|
||||||
`setDownstreamCompilerPath(SLANG_PASS_THROUGH_DXC, …)`). It tries `dxil`
|
|
||||||
first but ignores failure, so no dxil stub is needed.
|
|
||||||
`findFuncByName("DxcCreateInstance")`.
|
|
||||||
- **API used (legacy interfaces, so L1 is required):**
|
|
||||||
- `IDxcCompiler` and `IDxcLibrary::CreateBlobWithEncodingFromPinned`
|
|
||||||
(code page 0).
|
|
||||||
- `IDxcCompiler::Compile(source, name, entry, profile, args, …, includeHandler)`
|
|
||||||
with no defines.
|
|
||||||
- On `IDxcOperationResult`: `GetStatus`, `GetResult`, `GetErrorBuffer`.
|
|
||||||
- It queries `IDxcResult` from the operation result for `DXC_OUT_PDB` only
|
|
||||||
when PDB output is requested.
|
|
||||||
- **Version probing decides the language version.** Slang calls
|
|
||||||
`IDxcVersionInfo::GetVersion`, `IDxcVersionInfo2::GetCommitInfo`, and
|
|
||||||
`IDxcVersionInfo3::GetCustomVersionString`, and adds `-HV 2021` only if the
|
|
||||||
version is ≥ 1.7. The oracle reports `1.11(5583-f9fc72ad)`, so libzdxc should
|
|
||||||
report 1.11. The strings returned by `GetCommitInfo` and
|
|
||||||
`GetCustomVersionString` are freed by the client with `CoTaskMemFree`, which
|
|
||||||
is `free` on Unix (`WinAdapter.h:47`) and `CoTaskMemAlloc` on Windows. **So
|
|
||||||
libzdxc must allocate those with libc `malloc` / `CoTaskMemAlloc`, not a Zig
|
|
||||||
allocator**, which means the shared library links libc.
|
|
||||||
- **Include handler blobs are not real DXC blobs.** Slang's `LoadSource`
|
|
||||||
returns an `ISlangBlob` cast to `IDxcBlob*`. Only `GetBufferPointer` and
|
|
||||||
`GetBufferSize` can be trusted, and `QueryInterface` for `IDxcBlobEncoding`
|
|
||||||
fails. libzdxc must treat such blobs as raw bytes with BOM detection, never
|
|
||||||
assume they are its own blob type, and never downcast. Slang also resolves
|
|
||||||
includes itself from its search directories, so its handler is called with
|
|
||||||
dxc's candidate paths.
|
|
||||||
- **Arguments:** `-Zpr`, `-Gis`, `-denorm <mode>`, `-O0..3`/`-Od`, `-Zi`,
|
|
||||||
`-WX`, `-no-warnings` (always), `-enable-16bit-types`,
|
|
||||||
`-enable/-disable-payload-qualifiers`, plus user pass-through. Profiles
|
|
||||||
cover every stage, including `lib_6_x` for ray tracing.
|
|
||||||
- **Diagnostics:** Slang parses `ERRORS` as clang-style
|
|
||||||
`file:line:col: error|warning: msg`. That is zdxc's `clang` format, which
|
|
||||||
must stay the default for library output.
|
|
||||||
- **Optional extras:**
|
|
||||||
- `IDxcLinker` (`RegisterLibrary` + `Link`), used only when linking
|
|
||||||
precompiled DXIL modules. Slang then compiles the source as `lib_6_x`.
|
|
||||||
- `IDxcCompiler::Disassemble`, used only for `-target dxil-asm`.
|
|
||||||
|
|
||||||
Both are on the plan's dropped list; with them returning
|
|
||||||
`REGDB_E_CLASSNOTREG` / `E_NOTIMPL`, ordinary single-module compiles still
|
|
||||||
work.
|
|
||||||
- **Fit with the plan:** single-entry vs/ps/cs is M0.1. The rest of Slang's
|
|
||||||
stage coverage follows the plan's later milestones (hs/ds, ms/as, then `lib_`
|
|
||||||
at M0.5).
|
|
||||||
|
|
||||||
### Revised staging
|
|
||||||
|
|
||||||
1. **L0 + shadercross acceptance.** Build `test/clients/shadercross.sh`: build
|
|
||||||
shadercross against a zdxc install tree, run its CLI over its test shaders
|
|
||||||
for SPIR-V, DXIL (round-trip), and MSL, and compare with the same run
|
|
||||||
against DXC (DXIL through `dxv`, SPIR-V through `spirv-val`, MSL text
|
|
||||||
directly).
|
|
||||||
2. **L1 + Slang acceptance** on Linux, or a Slang built with
|
|
||||||
`SLANG_ENABLE_DXIL_SUPPORT=1`. Corpus: `slangc -target hlsl` output from
|
|
||||||
Slang's tests, compiled through both libraries.
|
|
||||||
3. Linker and disassembler only if Slang's precompiled-module or `dxil-asm`
|
|
||||||
paths turn out to matter.
|
|
||||||
|
|
||||||
## Testing
|
|
||||||
|
|
||||||
An ABI harness under `test/capi/`, written in C++ and compiled with
|
|
||||||
`zig c++` against the DXC tree's `include/dxc/dxcapi.h` (read in place, not
|
|
||||||
vendored). It `dlopen`s a library by path and runs a fixed script: create each
|
|
||||||
CLSID, query each IID, compile the oracle corpus through `IDxcCompiler3` and
|
|
||||||
the legacy interface, use a logging include handler, and dump status, the
|
|
||||||
output kinds present, error text, and object bytes. Running it against
|
|
||||||
`build/lib/libdxcompiler.dylib` and against libzdxc, then diffing (objects
|
|
||||||
compared through `dxv`, as the CLI oracle already does), gives drop-in
|
|
||||||
compatibility the same oracle treatment as the CLI.
|
|
||||||
|
|
||||||
## Open questions
|
|
||||||
|
|
||||||
- Should `zig build` produce the drop-in name by default, or opt-in only?
|
|
||||||
- Acceptance order: SDL_shadercross first, then Slang (see above). hassle-rs
|
|
||||||
and wgpu also use the legacy interfaces, so L1 for Slang covers them too
|
|
||||||
(not yet verified against hassle-rs source).
|
|
||||||
- Shadercross's lookup needs a `dxcapi.h` to exist. Ship a placeholder, or
|
|
||||||
install DXC's header? Its license (NCSA) allows redistribution, but the
|
|
||||||
project rule only allows vendoring data files.
|
|
||||||
- Does any target need 32-bit Windows? That would force the `__thiscall`
|
|
||||||
handling for the two `IDxcResult` methods.
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
// PROFILE: as_6_5
|
|
||||||
// Amplification shader: a groupshared payload (struct-typed, accessed
|
|
||||||
// through GEPs) sent with DispatchMesh.
|
|
||||||
// ZCHECK: call void @dx.op.dispatchMesh.struct.Payload(i32 173
|
|
||||||
struct Payload { uint base; float scale[2]; uint ids[8]; };
|
|
||||||
groupshared Payload pl;
|
|
||||||
[numthreads(8,1,1)]
|
|
||||||
void main(uint tid : SV_GroupIndex) {
|
|
||||||
pl.ids[tid] = tid * 2;
|
|
||||||
if (tid == 0) { pl.base = 7; pl.scale[0] = 1; pl.scale[1] = 2; }
|
|
||||||
GroupMemoryBarrierWithGroupSync();
|
|
||||||
DispatchMesh(2, 1, 1, pl);
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Atomics on groupshared memory, buffers and texels; byte-address buffers.
|
|
||||||
// ZCHECK: atomicrmw add i32 addrspace(3)*
|
|
||||||
// ZCHECK: cmpxchg i32 addrspace(3)*
|
|
||||||
// ZCHECK: @dx.op.atomicBinOp.i32(i32 78, %dx.types.Handle {{.*}}, i32 8,
|
|
||||||
// ZCHECK: @dx.op.atomicCompareExchange.i32(i32 79,
|
|
||||||
groupshared uint cnt;
|
|
||||||
groupshared int mx[4];
|
|
||||||
RWStructuredBuffer<uint> sb : register(u0);
|
|
||||||
RWBuffer<uint> tb : register(u1);
|
|
||||||
RWTexture2D<int> tex : register(u2);
|
|
||||||
RWByteAddressBuffer rb : register(u3);
|
|
||||||
[numthreads(64,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
uint old, o2; int o3;
|
|
||||||
InterlockedAdd(cnt, 1, old);
|
|
||||||
InterlockedMax(mx[i & 3], (int)i);
|
|
||||||
InterlockedCompareExchange(cnt, 5, 6, o2);
|
|
||||||
InterlockedOr(sb[i], 2);
|
|
||||||
InterlockedMin(tb[i], i, o2);
|
|
||||||
InterlockedExchange(tex[uint2(i, 1)], 3, o3);
|
|
||||||
InterlockedCompareStore(sb[0], 1, 2);
|
|
||||||
sb[1] = old + o2 + o3;
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Memory barriers (device, group, all; with and without group sync).
|
|
||||||
// ZCHECK: call void @dx.op.barrier(i32 80, i32 10)
|
|
||||||
// ZCHECK: call void @dx.op.barrier(i32 80, i32 2)
|
|
||||||
RWStructuredBuffer<uint4> o : register(u0);
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
AllMemoryBarrier(); AllMemoryBarrierWithGroupSync(); DeviceMemoryBarrier(); DeviceMemoryBarrierWithGroupSync(); GroupMemoryBarrier();
|
|
||||||
o[0] = uint4(firstbitlow(i), firstbithigh(i), firstbithigh((int)i), f32tof16(asfloat(i)));
|
|
||||||
o[1].x = asuint(f16tof32(i));
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
// PROFILE: cs_6_2
|
|
||||||
// Bitfields: DXIL packs same-size bitfields into one i32 (a, b, c share a
|
|
||||||
// word even though c is signed); reads mask/shift, writes read-modify-write.
|
|
||||||
// ZCHECK: and i32 {{.*}}, -249
|
|
||||||
// ZCHECK: or i32 {{.*}}, 56
|
|
||||||
// ZCHECK: ashr i32
|
|
||||||
struct Base { uint lo : 4; uint hi : 4; };
|
|
||||||
struct P : Base {
|
|
||||||
uint a : 3; uint b : 5; int c : 4;
|
|
||||||
uint d;
|
|
||||||
uint e : 30; uint f : 4;
|
|
||||||
uint sum() { return a + b + lo + hi; }
|
|
||||||
void bump() { b += 1; hi++; }
|
|
||||||
};
|
|
||||||
cbuffer CB { P cp; };
|
|
||||||
RWStructuredBuffer<P> sb : register(u0);
|
|
||||||
RWStructuredBuffer<int> o : register(u1);
|
|
||||||
[numthreads(1,1,1)] void main() {
|
|
||||||
P p = sb[0];
|
|
||||||
p.b = 7;
|
|
||||||
p.c = -3;
|
|
||||||
p.bump();
|
|
||||||
sb[1] = p;
|
|
||||||
P q = {1, 2, 3, 4, -5, 6, 7, 8};
|
|
||||||
sb[2] = q;
|
|
||||||
sb[3].f |= 2;
|
|
||||||
o[0] = p.a + p.c + cp.e + cp.f + p.sum() + q.c;
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Structured buffers of matrices: whole loads and stores, rows (constant
|
|
||||||
// and dynamic) and row components.
|
|
||||||
StructuredBuffer<float4x3> m : register(t0);
|
|
||||||
RWStructuredBuffer<float2x3> r : register(u1);
|
|
||||||
RWStructuredBuffer<float4> o : register(u0);
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
o[i] = float4(m[i][1], 1) + r[i][0].x + float4(m[0][i % 4], m[1][2].y);
|
|
||||||
r[i] = r[i] * 2;
|
|
||||||
o[i + 1] = mul(float4(1, 2, 3, 4), m[i]).xyzz;
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Byte-address buffer loads, stores, atomics and sizes.
|
|
||||||
RWByteAddressBuffer rb : register(u0);
|
|
||||||
ByteAddressBuffer ro : register(t0);
|
|
||||||
RWStructuredBuffer<uint> c : register(u1);
|
|
||||||
AppendStructuredBuffer<float4> ap : register(u2);
|
|
||||||
ConsumeStructuredBuffer<float4> co : register(u3);
|
|
||||||
[numthreads(64,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
uint4 v = ro.Load4(i * 16) + rb.Load2(4).xyxy;
|
|
||||||
rb.Store3(i * 12, v.xyz);
|
|
||||||
uint old; rb.InterlockedAdd(0, 1, old);
|
|
||||||
rb.InterlockedCompareStore(8, 1, 2);
|
|
||||||
uint n = 0;
|
|
||||||
rb.Store(20, n + old);
|
|
||||||
uint w; rb.GetDimensions(w); rb.Store(16, w);
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
// PROFILE: cs_6_2
|
|
||||||
// FLAGS: -enable-16bit-types
|
|
||||||
// Templated byte-address Load/Store of structs, matrices (by row in
|
|
||||||
// DXIL), 16- and 64-bit components (two words before SM 6.3); locals with
|
|
||||||
// components of several sizes in struct-typed memory.
|
|
||||||
// ZCHECK: call double @dx.op.makeDouble.f64(i32 101
|
|
||||||
// ZCHECK: rawBufferLoad.f16
|
|
||||||
struct S { float a; double b; uint16_t c; int2 d; };
|
|
||||||
RWByteAddressBuffer buf : register(u0);
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
S s = buf.Load<S>(i * 32);
|
|
||||||
float3x2 m = buf.Load<float3x2>(64);
|
|
||||||
half4 h = buf.Load<half4>(128);
|
|
||||||
S arr[2] = buf.Load<S[2]>(256);
|
|
||||||
s.a += m[1][0] + h.y + arr[1].d.x;
|
|
||||||
buf.Store<S>(i * 32 + 512, s);
|
|
||||||
buf.Store<float3x2>(96, m);
|
|
||||||
buf.Store<half4>(136, h);
|
|
||||||
buf.Store<double>(160, s.b);
|
|
||||||
}
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# DXIL output checks beyond validation: for each test/dxil/*.hlsl, zdxc's
|
|
||||||
# signature tables (ISG1/OSG1 and PSV0, minus the "Used" column) must match
|
|
||||||
# dxc's, and every `// ZCHECK: text` line must appear in zdxc's disassembly
|
|
||||||
# (`{{.*}}` matches anything).
|
|
||||||
#
|
|
||||||
# Usage: test/dxil/check.sh <path-to-zdxc>
|
|
||||||
set -u
|
|
||||||
ZDXC=$1
|
|
||||||
DXC_BUILD=${DXC_BUILD:-../build}
|
|
||||||
DXC=$DXC_BUILD/bin/dxc
|
|
||||||
DXV=$DXC_BUILD/bin/dxv
|
|
||||||
TMP=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
|
||||||
pass=0
|
|
||||||
fail=0
|
|
||||||
|
|
||||||
# Signature table rows, cut before the "Used" column.
|
|
||||||
sigtables() {
|
|
||||||
awk '/^; (Input|Output|Patch Constant) signature:/ { on = 1; seen = 0; next }
|
|
||||||
on && /^; (-|Name|shader hash)/ { next }
|
|
||||||
on && /^;$/ { if (seen) on = 0; next }
|
|
||||||
on { print substr($0, 1, 63); seen = 1 }' "$1" | sed 's/ *$//'
|
|
||||||
}
|
|
||||||
|
|
||||||
for f in test/dxil/*.hlsl; do
|
|
||||||
profile=$(sed -n 's|^// PROFILE: *||p' "$f")
|
|
||||||
flags=$(sed -n 's|^// FLAGS: *||p' "$f")
|
|
||||||
name=$(basename "$f" .hlsl)
|
|
||||||
if ! "$ZDXC" -T "$profile" $flags "$f" -Fo "$TMP/z.dxo" > "$TMP/log" 2>&1; then
|
|
||||||
fail=$((fail + 1)); echo "FAIL $name: zdxc failed"; head -3 "$TMP/log"; continue
|
|
||||||
fi
|
|
||||||
if ! "$DXV" "$TMP/z.dxo" > "$TMP/log" 2>&1; then
|
|
||||||
fail=$((fail + 1)); echo "FAIL $name: dxv rejected the output"; head -3 "$TMP/log"; continue
|
|
||||||
fi
|
|
||||||
"$DXC" -dumpbin "$TMP/z.dxo" > "$TMP/z.ll" 2>&1
|
|
||||||
rm -f "$TMP/d.ll"
|
|
||||||
if ! "$DXC" -T "$profile" $flags "$f" -Fc "$TMP/d.ll" > "$TMP/log" 2>&1; then
|
|
||||||
fail=$((fail + 1)); echo "FAIL $name: dxc rejects this test"; head -3 "$TMP/log"; continue
|
|
||||||
fi
|
|
||||||
ok=1
|
|
||||||
sigtables "$TMP/z.ll" > "$TMP/z.sig"
|
|
||||||
sigtables "$TMP/d.ll" > "$TMP/d.sig"
|
|
||||||
if ! diff "$TMP/d.sig" "$TMP/z.sig" > "$TMP/diff"; then
|
|
||||||
ok=0; echo "FAIL $name: signatures differ from dxc (< dxc, > zdxc)"; head -10 "$TMP/diff"
|
|
||||||
fi
|
|
||||||
# Runtime data (libraries) and root signatures must match dxc byte for byte.
|
|
||||||
"$DXC" -T "$profile" $flags "$f" -Fo "$TMP/d.dxo" > /dev/null 2>&1
|
|
||||||
if ! python3 test/dxil/compare_parts.py "$TMP/d.dxo" "$TMP/z.dxo" > "$TMP/rdat" 2>&1; then
|
|
||||||
ok=0; echo "FAIL $name: RDAT / RTS0 differ from dxc"; head -10 "$TMP/rdat"
|
|
||||||
fi
|
|
||||||
sed -n 's|^// ZCHECK: *||p' "$f" > "$TMP/checks"
|
|
||||||
while IFS= read -r pat; do
|
|
||||||
re=$(printf '%s\n' "$pat" | sed -e 's/[][\.*^$()+?|{}]/\\&/g' -e 's/\\{\\{\\\.\\\*\\}\\}/.*/g')
|
|
||||||
grep -Eq -- "$re" "$TMP/z.ll" || { ok=0; echo "FAIL $name: missing '$pat'"; }
|
|
||||||
done < "$TMP/checks"
|
|
||||||
if [ $ok = 1 ]; then pass=$((pass + 1)); else fail=$((fail + 1)); fi
|
|
||||||
done
|
|
||||||
echo "dxil checks: $pass passed, $fail failed"
|
|
||||||
[ "$fail" -eq 0 ]
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
"""Exits non-zero if two DXIL containers' RDAT or RTS0 parts differ (or
|
|
||||||
only one has one). Usage: compare_parts.py <expected.dxo> <actual.dxo>"""
|
|
||||||
import struct
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def part(path, fourcc):
|
|
||||||
data = open(path, 'rb').read()
|
|
||||||
count = struct.unpack_from('<I', data, 28)[0]
|
|
||||||
for off in struct.unpack_from('<%dI' % count, data, 32):
|
|
||||||
if data[off:off + 4] == fourcc:
|
|
||||||
size = struct.unpack_from('<I', data, off + 4)[0]
|
|
||||||
return data[off + 8:off + 8 + size]
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
status = 0
|
|
||||||
for fourcc in (b'RDAT', b'RTS0'):
|
|
||||||
a, b = part(sys.argv[1], fourcc), part(sys.argv[2], fourcc)
|
|
||||||
if a != b:
|
|
||||||
print('%s: expected %s bytes, got %s' % (fourcc.decode(), None if a is None else len(a), None if b is None else len(b)))
|
|
||||||
status = 1
|
|
||||||
sys.exit(status)
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
// PROFILE: cs_6_6
|
|
||||||
// Implicit-LOD sampling and derivatives in a compute shader (SM 6.6).
|
|
||||||
Texture2D<float4> t : register(t0);
|
|
||||||
SamplerState s : register(s0);
|
|
||||||
RWStructuredBuffer<float4> o : register(u0);
|
|
||||||
[numthreads(8,8,1)] void main(uint2 id : SV_DispatchThreadID) { float2 uv = id / 64.0; o[id.x] = t.Sample(s, uv) + ddx(uv).x + t.CalculateLevelOfDetail(s, uv); }
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// ConstantBuffer<T>: members (bitfields too), arrays, whole-struct reads,
|
|
||||||
// passing elements of resource arrays to (nested) functions.
|
|
||||||
// ZCHECK: cbufferLoadLegacy
|
|
||||||
struct S { float4 a; float b; uint lo : 8; uint hi : 8; };
|
|
||||||
ConstantBuffer<S> cbs[4] : register(b0);
|
|
||||||
Texture2D<float4> texs[2] : register(t0);
|
|
||||||
SamplerState smp : register(s0);
|
|
||||||
RWStructuredBuffer<float4> o : register(u0);
|
|
||||||
float4 inner(ConstantBuffer<S> c, Texture2D<float4> t) { return c.a * t.SampleLevel(smp, float2(0,0), 0) + c.hi; }
|
|
||||||
float4 outer(ConstantBuffer<S> c, Texture2D<float4> t) { return inner(c, t) + c.lo; }
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_GroupIndex) { S s = cbs[2]; o[0] = outer(cbs[3], texs[1]) + outer(cbs[0], texs[0]) + cbs[i].a + s.b + s.lo; }
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Counters and Append/Consume buffers.
|
|
||||||
// ZCHECK: @dx.op.bufferUpdateCounter(i32 70, {{.*}}, i8 1)
|
|
||||||
// ZCHECK: @dx.op.bufferUpdateCounter(i32 70, {{.*}}, i8 -1)
|
|
||||||
RWStructuredBuffer<uint> c : register(u1);
|
|
||||||
AppendStructuredBuffer<float4> ap : register(u2);
|
|
||||||
ConsumeStructuredBuffer<float4> co : register(u3);
|
|
||||||
[numthreads(1,1,1)] void main() { uint n = c.IncrementCounter(); ap.Append(co.Consume() + n); }
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
// PROFILE: cs_6_6
|
|
||||||
// Descriptor heaps (SM 6.6): resources and samplers taken from the heaps.
|
|
||||||
// ZCHECK: call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218
|
|
||||||
// ZCHECK: createHandleFromHeap(i32 218, i32 {{.*}}, i1 false, i1 true)
|
|
||||||
struct S { float4 a; float b; };
|
|
||||||
RWStructuredBuffer<float4> o : register(u0);
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
ConstantBuffer<S> c = ResourceDescriptorHeap[i];
|
|
||||||
Texture2D<float4> t = ResourceDescriptorHeap[i + 1];
|
|
||||||
SamplerState s = SamplerDescriptorHeap[0];
|
|
||||||
RWStructuredBuffer<float4> b = ResourceDescriptorHeap[NonUniformResourceIndex(i + 2)];
|
|
||||||
o[0] = c.a + t.SampleLevel(s, float2(0,0), 0);
|
|
||||||
b[i] = c.b;
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
// PROFILE: ds_6_0
|
|
||||||
// Domain shader: control points, patch constants, the domain location.
|
|
||||||
// ZCHECK: call float @dx.op.domainLocation.f32(i32 105, i8 1)
|
|
||||||
// ZCHECK: call float @dx.op.loadPatchConstant.f32(i32 104
|
|
||||||
struct HSOut { float4 pos : POSITION; float2 uv : TEXCOORD0; };
|
|
||||||
struct PC {
|
|
||||||
float edges[4] : SV_TessFactor;
|
|
||||||
float inside[2] : SV_InsideTessFactor;
|
|
||||||
float3 extra : EXTRA;
|
|
||||||
uint id : PATCHID;
|
|
||||||
};
|
|
||||||
struct DSOut { float4 pos : SV_Position; float2 uv : TEXCOORD0; nointerpolation uint id : PATCHID; };
|
|
||||||
[domain("quad")]
|
|
||||||
DSOut main(PC pc, float2 uv : SV_DomainLocation, const OutputPatch<HSOut, 4> patch, uint prim : SV_PrimitiveID) {
|
|
||||||
DSOut o;
|
|
||||||
float4 a = lerp(patch[0].pos, patch[1].pos, uv.x);
|
|
||||||
float4 b = lerp(patch[3].pos, patch[2].pos, uv.x);
|
|
||||||
o.pos = lerp(a, b, uv.y) + float4(pc.extra, pc.inside[1]);
|
|
||||||
o.uv = patch[0].uv * pc.edges[3];
|
|
||||||
o.id = pc.id + prim;
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// Gather with four offsets: four gathers (DXIL), ConstOffsets (SPIR-V).
|
|
||||||
// ZCHECK: textureGather.f32(i32 73, {{.*}}, i32 -1, i32 0, i32 1)
|
|
||||||
Texture2D<float4> t : register(t0);
|
|
||||||
SamplerState s : register(s0);
|
|
||||||
float4 main(float2 uv : UV) : SV_Target { return t.GatherGreen(s, uv, int2(1,0), int2(0,1), int2(-1,0), int2(0,-1)); }
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
// PROFILE: gs_6_0
|
|
||||||
// Geometry shader: per-vertex inputs, shadow SV_PrimitiveID, streams.
|
|
||||||
// ZCHECK: @dx.op.emitStream(i32 97, i8 0)
|
|
||||||
// ZCHECK: @dx.op.cutStream(i32 98, i8 0)
|
|
||||||
// ZCHECK: @dx.op.gsInstanceID.i32(i32 100)
|
|
||||||
// ZCHECK: !{i32 3, i32 6, i32 1, i32 5, i32 2}
|
|
||||||
struct VSOut { float4 pos : SV_Position; float2 uv : TEXCOORD0; };
|
|
||||||
struct GSOut { float4 pos : SV_Position; float2 uv : TEXCOORD0; uint layer : SV_RenderTargetArrayIndex; };
|
|
||||||
[maxvertexcount(6)] [instance(2)]
|
|
||||||
void main(triangle VSOut input[3], uint pid : SV_PrimitiveID, uint iid : SV_GSInstanceID, inout TriangleStream<GSOut> stream) {
|
|
||||||
for (int k = 0; k < 3; k++) { GSOut o; o.pos = input[k].pos; o.uv = input[k].uv + pid; o.layer = iid; stream.Append(o); }
|
|
||||||
stream.RestartStrip();
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Groupshared memory: address-space-3 globals, and the PSV byte count.
|
|
||||||
// ZCHECK: @g = external addrspace(3) global [64 x float], align 4
|
|
||||||
groupshared float g[64];
|
|
||||||
RWStructuredBuffer<float> o : register(u0);
|
|
||||||
[numthreads(64,1,1)] void main(uint i : SV_GroupIndex) { g[i] = i; GroupMemoryBarrierWithGroupSync(); o[i] = g[63 - i]; }
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
// PROFILE: hs_6_0
|
|
||||||
// Hull shader: control points in and out, a patch constant function
|
|
||||||
// reading the input patch and the output control points.
|
|
||||||
// ZCHECK: call i32 @dx.op.outputControlPointID.i32(i32 107)
|
|
||||||
// ZCHECK: call void @dx.op.storePatchConstant.f32(i32 106
|
|
||||||
// ZCHECK: call float @dx.op.loadOutputControlPoint.f32(i32 103
|
|
||||||
struct VSOut { float4 pos : POSITION; float2 uv : TEXCOORD0; };
|
|
||||||
struct HSOut { float4 pos : POSITION; float2 uv : TEXCOORD0; };
|
|
||||||
struct PC {
|
|
||||||
float edges[4] : SV_TessFactor;
|
|
||||||
float inside[2] : SV_InsideTessFactor;
|
|
||||||
float3 extra : EXTRA;
|
|
||||||
uint id : PATCHID;
|
|
||||||
};
|
|
||||||
cbuffer CB { float tess; };
|
|
||||||
PC patchConst(InputPatch<VSOut, 4> ip, const OutputPatch<HSOut, 4> op, uint pid : SV_PrimitiveID) {
|
|
||||||
PC o;
|
|
||||||
[unroll] for (int i = 0; i < 4; i++) o.edges[i] = tess + i;
|
|
||||||
o.inside[0] = ip[0].pos.x;
|
|
||||||
o.inside[1] = op[3].uv.y;
|
|
||||||
o.extra = ip[1].pos.xyz + op[2].pos.xyz;
|
|
||||||
o.id = pid;
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
[domain("quad")]
|
|
||||||
[partitioning("fractional_even")]
|
|
||||||
[outputtopology("triangle_ccw")]
|
|
||||||
[outputcontrolpoints(4)]
|
|
||||||
[patchconstantfunc("patchConst")]
|
|
||||||
[maxtessfactor(32.0)]
|
|
||||||
HSOut main(InputPatch<VSOut, 4> ip, uint id : SV_OutputControlPointID) {
|
|
||||||
HSOut o;
|
|
||||||
o.pos = ip[id].pos * 2;
|
|
||||||
o.uv = ip[id].uv;
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
// PROFILE: hs_6_0
|
|
||||||
// Isoline hull shader: line tess factors (density, detail); the main
|
|
||||||
// function declares the input patch but does not read it.
|
|
||||||
struct CP { float3 p : P; };
|
|
||||||
struct PC { float f[2] : SV_TessFactor; };
|
|
||||||
PC pcf(InputPatch<CP, 2> ip) { PC o; o.f[0] = ip[0].p.x; o.f[1] = ip[1].p.y; return o; }
|
|
||||||
[domain("isoline")]
|
|
||||||
[partitioning("integer")]
|
|
||||||
[outputtopology("line")]
|
|
||||||
[outputcontrolpoints(2)]
|
|
||||||
[patchconstantfunc("pcf")]
|
|
||||||
CP main(InputPatch<CP, 2> ip, uint id : SV_OutputControlPointID) { CP c; c.p = float3(id, 0, 1); return c; }
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
// PROFILE: ps_6_6
|
|
||||||
// Intrinsics: firstbit*, f32tof16/f16tof32, and/or/select, isnan & co.,
|
|
||||||
// fmod, integer dot, any/all, fine derivatives, clip, IsHelperLane.
|
|
||||||
// ZCHECK: unaryBits.i32(i32 34
|
|
||||||
// ZCHECK: legacyF32ToF16
|
|
||||||
// ZCHECK: isHelperLane
|
|
||||||
RWStructuredBuffer<uint4> o : register(u0);
|
|
||||||
float4 main(float4 p : SV_Position, uint i : U) : SV_Target {
|
|
||||||
DeviceMemoryBarrier();
|
|
||||||
o[0] = uint4(firstbitlow(i), firstbithigh(i), firstbithigh((int)i), f32tof16(p.x));
|
|
||||||
int3 a = int3(1, 2, i), b = int3(3, i, 5);
|
|
||||||
bool3 m = and(a > 1, b < 4);
|
|
||||||
bool3 n = or(m, isnan(p.xyz));
|
|
||||||
float3 s = select(n, p.xyz, float3(1, 2, 3));
|
|
||||||
float r = fmod(p.x, 3) + f16tof32(i) + dot(a, b) + any(isinf(p)) + all(isfinite(p)) + isnormal(p.w) + ddx_fine(p.x) + ddy_fine(p.y);
|
|
||||||
clip(p.xy - 1);
|
|
||||||
return float4(s, r) + IsHelperLane();
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
// PROFILE: lib_6_6
|
|
||||||
// Graphics shaders in a library: entries with their signatures (no usage
|
|
||||||
// masks), stage state, and the patch constant function defined under its
|
|
||||||
// mangled name in declaration order. RDAT is checked against dxc's.
|
|
||||||
// ZCHECK: define void @"\01?pcf@@YA?AUPC@@V?$InputPatch@UCP@@$02@@@Z"()
|
|
||||||
// ZCHECK: define void @hs()
|
|
||||||
// ZCHECK: !{i32 8, i32 2, i32 1, !{{.*}}, i32 5, !{{.*}}}
|
|
||||||
struct CP { float4 p : POSITION; };
|
|
||||||
struct PC { float e[3] : SV_TessFactor; float i : SV_InsideTessFactor; };
|
|
||||||
PC pcf(InputPatch<CP, 3> ip) { PC o; o.e[0] = o.e[1] = o.e[2] = 2; o.i = 2; return o; }
|
|
||||||
[shader("hull")] [domain("tri")] [partitioning("integer")] [outputtopology("triangle_cw")] [outputcontrolpoints(3)] [patchconstantfunc("pcf")]
|
|
||||||
CP hs(InputPatch<CP, 3> ip, uint id : SV_OutputControlPointID) { return ip[id]; }
|
|
||||||
[shader("domain")] [domain("tri")]
|
|
||||||
float4 ds(PC pc, float3 uvw : SV_DomainLocation, const OutputPatch<CP, 3> op) : SV_Position { return op[0].p * uvw.x + op[1].p * uvw.y + op[2].p * uvw.z; }
|
|
||||||
struct GO { float4 p : SV_Position; };
|
|
||||||
[shader("geometry")] [maxvertexcount(3)]
|
|
||||||
void gs(triangle float4 v[3] : SV_Position, inout TriangleStream<GO> s) { for (int k = 0; k < 3; k++) { GO o; o.p = v[k]; s.Append(o); } }
|
|
||||||
Texture2D t; SamplerState s;
|
|
||||||
struct V { float4 p : SV_Position; float2 uv : TEXCOORD; };
|
|
||||||
[shader("vertex")] V vs(float3 p : POSITION, float2 uv : TEXCOORD) { V o; o.p = float4(p, 1); o.uv = uv; return o; }
|
|
||||||
[shader("pixel")] float4 ps(V i) : SV_Target { return t.Sample(s, i.uv); }
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
// PROFILE: lib_6_6
|
|
||||||
// Mangled names of exported functions whose parameters are structs and
|
|
||||||
// enums in namespaces and structs, class / struct template instances
|
|
||||||
// (type and integral arguments, negative ones too) and classes, with the
|
|
||||||
// back-references dxc uses; RDAT carries them byte for byte. Same-named
|
|
||||||
// nested structs of two instances are distinct types.
|
|
||||||
// ZCHECK: define float @"\01?f2@@YAMU?$Box@M$02@inner@ns@@@Z"(
|
|
||||||
// ZCHECK: define i32 @"\01?f4@@YAHUNested@Outer@inner@ns@@W4E@234@@Z"(
|
|
||||||
// ZCHECK: %struct.In.0 = type { %struct.P }
|
|
||||||
namespace ns { namespace inner {
|
|
||||||
struct P { float a; };
|
|
||||||
template <typename T, int N> struct Box { T v[N]; };
|
|
||||||
class C { float c; };
|
|
||||||
struct Outer { struct Nested { int n; }; enum E { E0, E1 }; };
|
|
||||||
template <typename T> struct TO { struct In { T t; }; using Elem = T; };
|
|
||||||
} }
|
|
||||||
template <int N> struct Neg { int x; };
|
|
||||||
export float f1(ns::inner::P p, ns::inner::P q) { return p.a + q.a; }
|
|
||||||
export float f2(ns::inner::Box<float, 3> b) { return b.v[0]; }
|
|
||||||
export float f3(ns::inner::C c, Neg<-5> n) { return 1; }
|
|
||||||
export int f4(ns::inner::Outer::Nested n, ns::inner::Outer::E e) { return n.n + e; }
|
|
||||||
export float f5(ns::inner::Outer::Nested i, ns::inner::Box<ns::inner::P, 2> b) { return i.n + b.v[1].a; }
|
|
||||||
export float f6(inout ns::inner::P p, ns::inner::Box<float4, 1> b) { return 1; }
|
|
||||||
export float f7(ns::inner::TO<float>::In i, ns::inner::TO<int>::Elem e, ns::inner::TO<ns::inner::P>::In p) { return i.t + e + p.t.a; }
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
// PROFILE: lib_6_6
|
|
||||||
// [noinline] functions in a library stay internal functions of their own,
|
|
||||||
// called with scalars and vectors by value and structs, out and inout
|
|
||||||
// values by pointer; RDAT lists each with its own resources and its
|
|
||||||
// callees' requirements (wave ops) merged into its callers'.
|
|
||||||
// ZCHECK: define internal float @"\01?Leaf@@YAMIAIAMUS@@@Z"(i32, float*, %struct.S*) #
|
|
||||||
// ZCHECK: define internal <4 x float> @"\01?Scale@@YA?AV?$vector@M$03@@V1@M@Z"(<4 x float>, float) #
|
|
||||||
// ZCHECK: call float @"\01?Leaf@@YAMIAIAMUS@@@Z"(i32
|
|
||||||
// ZCHECK: attributes #{{.*}} = { noinline nounwind }
|
|
||||||
RWStructuredBuffer<float4> Output : register(u0);
|
|
||||||
ByteAddressBuffer Input : register(t0);
|
|
||||||
|
|
||||||
struct S { float a; int b; };
|
|
||||||
|
|
||||||
[noinline] float Leaf(uint i, inout float x, out S s) {
|
|
||||||
x += i;
|
|
||||||
s.a = x;
|
|
||||||
s.b = (int)i;
|
|
||||||
Output[i] = x;
|
|
||||||
return x * 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
[noinline] float4 Scale(float4 v, float k) { return v * k; }
|
|
||||||
|
|
||||||
[noinline] uint Lanes() { return WaveActiveCountBits(true); }
|
|
||||||
|
|
||||||
[noinline] void Middle(uint i, S t) {
|
|
||||||
float x = asfloat(Input.Load(i * 4));
|
|
||||||
S s;
|
|
||||||
float r = Leaf(i, x, s);
|
|
||||||
Output[i + 1] = Scale(float4(r, x, s.a, t.a), (float)s.b);
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("compute")]
|
|
||||||
[numthreads(8, 1, 1)]
|
|
||||||
void main(uint i : SV_GroupIndex) {
|
|
||||||
S t = { 1.0f, 2 };
|
|
||||||
Middle(i, t);
|
|
||||||
Output[0] = Lanes();
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("compute")]
|
|
||||||
[numthreads(4, 1, 1)]
|
|
||||||
void other(uint i : SV_GroupIndex) {
|
|
||||||
Output[2] = Scale(float4(1, 2, 3, 4), i);
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
// PROFILE: cs_6_10
|
|
||||||
// FLAGS: -enable-16bit-types
|
|
||||||
// SM 6.10 linear algebra: matrix handles in locals, statics and structs,
|
|
||||||
// the LinAlg builtins and the dx::linalg::Matrix API, with
|
|
||||||
// !dx.targetTypes and the PSV0 usage tables.
|
|
||||||
// ZCHECK: %dx.types.LinAlgMatrixC9M4N4U2S1 = type { i8* }
|
|
||||||
// ZCHECK: @dx.op.linAlgFillMatrix.mC9M4N4U2S1.f32(i32 323, i1 true, float
|
|
||||||
// ZCHECK: @dx.op.linAlgMatrixLoadFromDescriptor.mC9M4N4U0S1(i32 325,
|
|
||||||
// ZCHECK: @dx.op.linAlgMatrixMultiplyAccumulate.mC9M4N4U2S1.mC9M4N4U0S1.mC9M4N4U1S1.mC9M4N4U2S1(i32 322,
|
|
||||||
// ZCHECK: @dx.op.linAlgMatrixGetElement.f32.mC9M4N4U2S1(i32 329,
|
|
||||||
// ZCHECK: @dx.op.linAlgMatrixStoreToMemory.mC9M4N4U2S1.f32(i32 332,
|
|
||||||
// ZCHECK: @dx.op.linAlgMatVecMul.v4f32.mC9M4N4U0S0.v4f32(i32 336,
|
|
||||||
// ZCHECK: LinAlgRuntimeInfoPresent: true
|
|
||||||
// ZCHECK: !dx.targetTypes = !{
|
|
||||||
#include <dx/linalg.h>
|
|
||||||
using namespace dx::linalg;
|
|
||||||
|
|
||||||
using MatA = Matrix<ComponentType::F32, 4, 4, MatrixUse::A, MatrixScope::Wave>;
|
|
||||||
using MatB = Matrix<ComponentType::F32, 4, 4, MatrixUse::B, MatrixScope::Wave>;
|
|
||||||
using Acc = Matrix<ComponentType::F32, 4, 4, MatrixUse::Accumulator, MatrixScope::Wave>;
|
|
||||||
using ThreadA = Matrix<ComponentType::F32, 4, 4, MatrixUse::A, MatrixScope::Thread>;
|
|
||||||
|
|
||||||
ByteAddressBuffer Input : register(t0);
|
|
||||||
RWByteAddressBuffer Output : register(u0);
|
|
||||||
groupshared float Shared[256];
|
|
||||||
static Acc Total;
|
|
||||||
|
|
||||||
[numthreads(32, 1, 1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
MatA a = MatA::Load(Input, 0, 16, MatrixLayout::RowMajor);
|
|
||||||
MatB b = MatB::Load(Input, 64, 16, MatrixLayout::RowMajor);
|
|
||||||
Total = Acc::Splat(1.0f);
|
|
||||||
Total.MultiplyAccumulate(a, b);
|
|
||||||
Total.Store(Shared, 0, 4, MatrixLayout::RowMajor);
|
|
||||||
Output.Store(0, Total.Get(i % Total.Length()));
|
|
||||||
|
|
||||||
__builtin_LinAlgMatrix [[__LinAlgMatrix_Attributes(9, 4, 4, 0, 0)]] t;
|
|
||||||
dx::__builtin_LinAlg_MatrixLoadFromDescriptor(t, Input, 128, 0, 2, 128);
|
|
||||||
float4 v;
|
|
||||||
dx::__builtin_LinAlg_MatrixVectorMultiply(v, t, true, float4(1, 2, 3, 4), 9);
|
|
||||||
Output.Store(16, v);
|
|
||||||
}
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
// PROFILE: lib_6_10
|
|
||||||
// SM 6.10 linear algebra in a library: each function's RDAT
|
|
||||||
// ExtendedProperties (constructions with their shapes, matrix multiplies,
|
|
||||||
// outer products and accumulating stores), shared between functions with
|
|
||||||
// the same usage, must match dxc's byte for byte.
|
|
||||||
// ZCHECK: @dx.op.linAlgMatrixMultiply.mC4M5N6U2S2.mC4M5N7U0S2.mC5M7N6U1S2(i32 334,
|
|
||||||
// ZCHECK: @dx.op.linAlgMatrixOuterProduct.mC9M4N4U2S0.v4f32.v4f32(i32 340,
|
|
||||||
// ZCHECK: @dx.op.linAlgVectorAccumulateToDescriptor.v4f32(i32 342,
|
|
||||||
// ZCHECK: !dx.targetTypes = !{
|
|
||||||
#include <dx/linalg.h>
|
|
||||||
using namespace dx::linalg;
|
|
||||||
|
|
||||||
using WaveA = Matrix<ComponentType::F32, 2, 4, MatrixUse::A, MatrixScope::Wave>;
|
|
||||||
using WaveB = Matrix<ComponentType::I32, 4, 3, MatrixUse::B, MatrixScope::Wave>;
|
|
||||||
using WaveAcc = Matrix<ComponentType::F32, 2, 3, MatrixUse::Accumulator, MatrixScope::Wave>;
|
|
||||||
using GroupA = Matrix<ComponentType::I32, 5, 7, MatrixUse::A, MatrixScope::ThreadGroup>;
|
|
||||||
using GroupB = Matrix<ComponentType::U32, 7, 6, MatrixUse::B, MatrixScope::ThreadGroup>;
|
|
||||||
using GroupAcc = Matrix<ComponentType::I32, 5, 6, MatrixUse::Accumulator, MatrixScope::ThreadGroup>;
|
|
||||||
|
|
||||||
RWByteAddressBuffer Output : register(u0);
|
|
||||||
|
|
||||||
void WaveWork(float f, int i) {
|
|
||||||
WaveA A = WaveA::Splat(f);
|
|
||||||
WaveB B = WaveB::Splat(i);
|
|
||||||
WaveAcc C = Multiply<ComponentType::F32>(A, B);
|
|
||||||
C.InterlockedAccumulate(Output, 0, 12, MatrixLayout::RowMajor);
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("compute")]
|
|
||||||
[numthreads(32, 1, 1)]
|
|
||||||
void Wave1() { WaveWork(1.0f, 2); }
|
|
||||||
|
|
||||||
[shader("compute")]
|
|
||||||
[numthreads(32, 1, 1)]
|
|
||||||
void Wave2() { WaveWork(3.0f, 4); }
|
|
||||||
|
|
||||||
[shader("compute")]
|
|
||||||
[numthreads(64, 1, 1)]
|
|
||||||
void Group() {
|
|
||||||
GroupA A = GroupA::Splat(5);
|
|
||||||
GroupB B = GroupB::Splat(6u);
|
|
||||||
GroupAcc C = Multiply<ComponentType::I32>(A, B);
|
|
||||||
C.InterlockedAccumulate(Output, 64, 24, MatrixLayout::RowMajor);
|
|
||||||
WaveWork(5.0f, 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("compute")]
|
|
||||||
[numthreads(1, 1, 1)]
|
|
||||||
void Outer(uint i : SV_GroupIndex) {
|
|
||||||
float4 v = float4(i, 1, 2, 3);
|
|
||||||
Matrix<ComponentType::F32, 4, 4, MatrixUse::Accumulator, MatrixScope::Thread> M =
|
|
||||||
OuterProduct<ComponentType::F32>(v, v);
|
|
||||||
M.InterlockedAccumulate(Output, 128);
|
|
||||||
InterlockedAccumulate(Output, 256, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("compute")]
|
|
||||||
[numthreads(1, 1, 1)]
|
|
||||||
void NoLinAlg() { Output.Store(0, 1u); }
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
// PROFILE: cs_6_9
|
|
||||||
// FLAGS: -enable-16bit-types
|
|
||||||
// SM 6.9 long vectors (scalarized): structured and byte-address buffer
|
|
||||||
// loads and stores, groupshared arrays, construction from shorter
|
|
||||||
// vectors, comparisons and select, element-wise and reducing
|
|
||||||
// intrinsics, dynamic indexing and functions taking long vectors.
|
|
||||||
// ZCHECK: @dx.op.rawBufferLoad.f32(i32 139, %dx.types.Handle {{.*}}, i32 16, i8 15, i32 4)
|
|
||||||
// ZCHECK: call float @dx.op.unary.f32(i32 13,
|
|
||||||
// ZCHECK: @dx.op.rawBufferStore.f32(i32 140,
|
|
||||||
struct S { float a; vector<half, 6> h; };
|
|
||||||
RWStructuredBuffer<vector<float, 8> > sb : register(u0);
|
|
||||||
RWStructuredBuffer<S> ss : register(u1);
|
|
||||||
RWByteAddressBuffer bab : register(u2);
|
|
||||||
groupshared vector<int, 5> gs[64];
|
|
||||||
|
|
||||||
vector<float, 8> scaleBy(vector<float, 8> v, float k) { return v * k; }
|
|
||||||
|
|
||||||
[numthreads(64, 1, 1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
vector<float, 8> a = sb[i];
|
|
||||||
vector<float, 8> b = bab.Load<vector<float, 8> >(32 * i);
|
|
||||||
vector<float, 8> c = sin(a) * b + 1.0;
|
|
||||||
c[i % 8] = dot(a, b);
|
|
||||||
vector<bool, 8> big = c > 2.0;
|
|
||||||
c = select(big, scaleBy(c, 0.5), clamp(c, -1.0, 1.0));
|
|
||||||
c += float4(1, 2, 3, 4).xxyy.xyzw.x;
|
|
||||||
vector<float, 8> d = vector<float, 8>(float4(1, 2, 3, 4), float2(a[0], a[1]), 7, 8);
|
|
||||||
sb[i] = max(c, d) + (any(big) ? 1.0 : 0.0) + (all(big) ? 1.0 : 0.0);
|
|
||||||
|
|
||||||
S s = ss[i];
|
|
||||||
s.h = s.h * (half)2 + abs(s.h);
|
|
||||||
ss[i] = s;
|
|
||||||
|
|
||||||
gs[i] = vector<int, 5>(i, i + 1, i + 2, i + 3, i + 4);
|
|
||||||
GroupMemoryBarrierWithGroupSync();
|
|
||||||
vector<int, 5> g = gs[63 - i];
|
|
||||||
bab.Store<vector<int, 5> >(4096 + 20 * i, countbits(g) + firstbithigh(g) + (g & 3));
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// Math intrinsics lowered to arithmetic, as dxc does.
|
|
||||||
// ZCHECK: @dx.op.unary.f32(i32 17,
|
|
||||||
// ZCHECK: @dx.op.isSpecialFloat.f32(i32 8,
|
|
||||||
// ZCHECK: @dx.op.unary.f32(i32 22,
|
|
||||||
float4 main(float3 a : A, float3 b : B, float2 c : C, float4x4 m : M, float3x3 m3 : N) : SV_Target {
|
|
||||||
float3 r = cross(a, b) + reflect(a, b) + refract(a, b, c.x) + faceforward(a, b, a);
|
|
||||||
float s = atan2(c.x, c.y) + fmod(c.x, c.y) + distance(a, b) + determinant(m) + determinant(m3);
|
|
||||||
s += smoothstep(0, 1, c.x) + step(0.5, c.y) + degrees(c.x) + radians(c.y) + ldexp(c.x, c.y);
|
|
||||||
int sg = sign(c.x) + sign((int)c.y);
|
|
||||||
return float4(r, s + sg + (isnan(c.x) ? 1 : 0) + (isinf(c.y) ? 2 : 0) + (isfinite(a.x) ? 4 : 0));
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
// PROFILE: ms_6_5
|
|
||||||
// Mesh shader: vertex and primitive outputs written per element, indices,
|
|
||||||
// partial (swizzled) output writes, the payload.
|
|
||||||
// ZCHECK: call void @dx.op.setMeshOutputCounts(i32 168
|
|
||||||
// ZCHECK: call void @dx.op.emitIndices(i32 169
|
|
||||||
// ZCHECK: call void @dx.op.storePrimitiveOutput.i32(i32 172
|
|
||||||
// ZCHECK: getMeshPayload
|
|
||||||
struct V { float4 pos : SV_Position; float2 uv : TEXCOORD0; float c[2] : COLOR; };
|
|
||||||
struct P { nointerpolation uint id : PRIMID; bool cull : SV_CullPrimitive; };
|
|
||||||
struct Payload { uint base; float scale[3]; };
|
|
||||||
[numthreads(4,1,1)]
|
|
||||||
[outputtopology("triangle")]
|
|
||||||
void main(out indices uint3 tris[2], out vertices V verts[4], out primitives P prims[2], in payload Payload pl, uint tid : SV_GroupIndex) {
|
|
||||||
SetMeshOutputCounts(4, 2);
|
|
||||||
verts[tid].pos = float4(tid, 0, 0, 1) * pl.scale[tid % 3];
|
|
||||||
verts[tid].uv.y = 1;
|
|
||||||
verts[tid].uv.x = 0;
|
|
||||||
verts[tid].c[1] = 2;
|
|
||||||
verts[tid].c[0] = 3;
|
|
||||||
if (tid < 2) {
|
|
||||||
tris[tid] = uint3(0, tid + 1, tid + 2);
|
|
||||||
P p;
|
|
||||||
p.id = pl.base + tid;
|
|
||||||
p.cull = tid == 1;
|
|
||||||
prims[tid] = p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Operator overloading: binary operators, [] and () (dxc's subset).
|
|
||||||
struct V2 {
|
|
||||||
float x, y;
|
|
||||||
V2 operator+(V2 o) { V2 r; r.x = x + o.x; r.y = y + o.y; return r; }
|
|
||||||
V2 operator*(float k) { V2 r; r.x = x * k; r.y = y * k; return r; }
|
|
||||||
bool operator==(V2 o) { return x == o.x && y == o.y; }
|
|
||||||
float operator[](uint i) { return i == 0 ? x : y; }
|
|
||||||
float operator()(float a, float b) { return x * a + y * b; }
|
|
||||||
};
|
|
||||||
RWStructuredBuffer<float> o : register(u0);
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_DispatchThreadID) {
|
|
||||||
V2 a; a.x = 1; a.y = 2; V2 b = a * 3.0;
|
|
||||||
V2 c = a + b; c = c + a;
|
|
||||||
o[i] = c[1] + c(1, 2) + (a == a ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// Intrinsics with out parameters.
|
|
||||||
// ZCHECK: @dx.op.splitDouble.f64(i32 102
|
|
||||||
// ZCHECK: @dx.op.unary.f32(i32 29,
|
|
||||||
double d;
|
|
||||||
float4 main(float4 x : X) : SV_Target {
|
|
||||||
float4 s, c; sincos(x, s, c);
|
|
||||||
float3 ip; float3 fr = modf(x.xyz, ip);
|
|
||||||
float e; float m = frexp(x.w, e);
|
|
||||||
uint lo, hi; asuint(d, lo, hi);
|
|
||||||
return s + c + float4(fr + ip, m * e) + lo + hi;
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
// PROFILE: vs_6_0
|
|
||||||
// #pragma pack_matrix sets the orientation of matrices declared after it
|
|
||||||
// (typedefs keep theirs), and may come between any two tokens. Entry
|
|
||||||
// parameters take an orientation written on them or the pragma's, but
|
|
||||||
// not a typedef's (as in dxc), so Q is column_major. Structured buffer
|
|
||||||
// elements ignore it in DXIL. (C is 28 bytes row_major, D 40 + 28.)
|
|
||||||
// ZCHECK: %C* undef, !"", i32 0, i32 0, i32 1, i32 28,
|
|
||||||
// ZCHECK: %D* undef, !"", i32 0, i32 1, i32 1, i32 76,
|
|
||||||
#pragma pack_matrix(row_major)
|
|
||||||
typedef float2x3 R;
|
|
||||||
cbuffer C { float2x3 a; };
|
|
||||||
#pragma pack_matrix(column_major)
|
|
||||||
cbuffer D { float2x3 b; R c; };
|
|
||||||
StructuredBuffer<float2x3> S;
|
|
||||||
float4 main(float2x3 p : P, R q : Q, row_major float2x3 r : R
|
|
||||||
#pragma pack_matrix(row_major)
|
|
||||||
, float2x3 s : S0) : SV_Position {
|
|
||||||
return float4(a._m12, b._m12, c._m12, S[0]._m12) + p[1].xyzx + q[1].xyzx + r[1].xyzx + s[1].xyzx;
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
// PROFILE: vs_6_0
|
|
||||||
// FLAGS: -Zpr
|
|
||||||
// -Zpr: matrices without an orientation are row_major, structured buffer
|
|
||||||
// elements too; column_major and #pragma pack_matrix still win (C is
|
|
||||||
// 28 bytes, padded to 32, then 40).
|
|
||||||
// ZCHECK: %C* undef, !"", i32 0, i32 0, i32 1, i32 72,
|
|
||||||
cbuffer C { float2x3 a; column_major float2x3 b; };
|
|
||||||
StructuredBuffer<float2x3> S;
|
|
||||||
struct V { float4 pos : SV_Position; float3x2 m : M; };
|
|
||||||
V main(float2x3 p : P
|
|
||||||
#pragma pack_matrix(column_major)
|
|
||||||
, float2x3 q : Q) {
|
|
||||||
V v; v.pos = float4(a._m12, b._m12, S[0]._m10, 0) + p[1].xyzx + q[1].xyzx; v.m = transpose(p); return v;
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Writing some components of a vector or matrix in an RW structured
|
|
||||||
// buffer or groupshared memory stores just those components (as dxc), not
|
|
||||||
// the whole value read back: other threads may write the rest. Matrix
|
|
||||||
// rows and elements of buffers, at constant or dynamic rows, are stored
|
|
||||||
// element by element.
|
|
||||||
// ZCHECK: bufferStore.f32(i32 69, %dx.types.Handle {{.*}}, i32 8, float 2.000000e+00, float undef, float undef, float undef, i8 1)
|
|
||||||
// ZCHECK: bufferStore.f32(i32 69, %dx.types.Handle {{.*}}, i32 32, float 3.000000e+00, float undef, float undef, float undef, i8 1)
|
|
||||||
// ZCHECK: bufferStore.f32(i32 69, %dx.types.Handle {{.*}}, i32 28, float 4.000000e+00, float undef, float undef, float undef, i8 1)
|
|
||||||
// ZCHECK: bufferStore.f32(i32 69, %dx.types.Handle {{.*}}, i32 20, float 6.000000e+00, float undef, float undef, float undef, i8 1)
|
|
||||||
// ZCHECK: bufferStore.f32(i32 69, %dx.types.Handle {{.*}}, i32 24, float 8.000000e+00, float undef, float undef, float undef, i8 1)
|
|
||||||
// ZCHECK: mul i32 {{.*}}, 4
|
|
||||||
// ZCHECK: store float 1.000000e+01, float addrspace(3)*
|
|
||||||
// ZCHECK: store float 1.100000e+01, float addrspace(3)*
|
|
||||||
struct S { float4 v; float2x3 m; };
|
|
||||||
RWStructuredBuffer<S> B;
|
|
||||||
RWStructuredBuffer<float2x3> W;
|
|
||||||
RWByteAddressBuffer R;
|
|
||||||
groupshared float4 G[4];
|
|
||||||
groupshared float2x3 GM[4];
|
|
||||||
[numthreads(4, 1, 1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
B[i].v.xz = float2(1, 2);
|
|
||||||
B[i].m._m02_m11 = float2(3, 4);
|
|
||||||
W[i]._m10 = 5;
|
|
||||||
W[i][1][2] = 6;
|
|
||||||
B[i].m[0] = float3(7, 8, 9);
|
|
||||||
B[i + 1].m[i % 2] = float3(1, 2, 3);
|
|
||||||
G[i].y = 10;
|
|
||||||
GM[i]._m12 = 11;
|
|
||||||
GroupMemoryBarrierWithGroupSync();
|
|
||||||
R.Store(i * 4, asuint(G[(i + 1) % 4].x + GM[(i + 1) % 4]._m00));
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
// PROFILE: cs_6_5
|
|
||||||
// FLAGS: -E main
|
|
||||||
// RayQuery: allocated once in the prologue, its type flags as the
|
|
||||||
// allocation's constant flags; state reads by row / column / component.
|
|
||||||
// ZCHECK: call i32 @dx.op.allocateRayQuery(i32 178, i32 1)
|
|
||||||
// ZCHECK: @dx.op.rayQuery_TraceRayInline(i32 179
|
|
||||||
// ZCHECK: @dx.op.rayQuery_Proceed.i1(i32 180
|
|
||||||
// ZCHECK: @dx.op.rayQuery_StateScalar.i32(i32 185
|
|
||||||
// ZCHECK: @dx.op.rayQuery_StateVector.f32(i32 194, i32 {{.*}}, i8 1)
|
|
||||||
// ZCHECK: @dx.op.rayQuery_StateMatrix.f32(i32 188, i32 {{.*}}, i32 0, i8 3)
|
|
||||||
// ZCHECK: @dx.op.rayQuery_Abort(i32 181
|
|
||||||
// ZCHECK: i32 16, i32 0, !{{.*}}
|
|
||||||
RaytracingAccelerationStructure scene : register(t0);
|
|
||||||
RWStructuredBuffer<float4> output : register(u0);
|
|
||||||
|
|
||||||
void start(RayQuery<RAY_FLAG_FORCE_OPAQUE> q, RayDesc ray) {
|
|
||||||
q.TraceRayInline(scene, RAY_FLAG_NONE, 0xFF, ray);
|
|
||||||
}
|
|
||||||
|
|
||||||
[numthreads(8, 1, 1)]
|
|
||||||
void main(uint3 id : SV_DispatchThreadID) {
|
|
||||||
RayDesc ray = { float3(id), 0.0, float3(0, 0, 1), 100.0 };
|
|
||||||
RayQuery<RAY_FLAG_FORCE_OPAQUE> q;
|
|
||||||
start(q, ray);
|
|
||||||
while (q.Proceed()) {
|
|
||||||
if (q.CandidateType() == CANDIDATE_NON_OPAQUE_TRIANGLE)
|
|
||||||
q.CommitNonOpaqueTriangleHit();
|
|
||||||
else
|
|
||||||
q.CommitProceduralPrimitiveHit(q.RayTMin());
|
|
||||||
}
|
|
||||||
float4 r = 0;
|
|
||||||
if (q.CommittedStatus() == COMMITTED_TRIANGLE_HIT) {
|
|
||||||
r.xy = q.CommittedTriangleBarycentrics();
|
|
||||||
r.z = q.CommittedRayT() + q.CommittedInstanceIndex();
|
|
||||||
r.w = q.CommittedObjectToWorld4x3()[3][0];
|
|
||||||
}
|
|
||||||
q.Abort();
|
|
||||||
output[id.x] = r;
|
|
||||||
}
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
||||||
// PROFILE: lib_6_5
|
|
||||||
// Ray tracing shaders in a library: mangled entry functions taking their
|
|
||||||
// payload / attributes by pointer, resources as globals with handles from
|
|
||||||
// createHandleForLib, and RDAT matching dxc's.
|
|
||||||
// ZCHECK: define void @"\01?chit@@YAXUPayload@@UBuiltInTriangleIntersectionAttributes@@@Z"(%struct.Payload*
|
|
||||||
// ZCHECK: @dx.op.createHandleForLib.struct.RaytracingAccelerationStructure(i32 160
|
|
||||||
// ZCHECK: call void @dx.op.traceRay.struct.Payload(i32 157
|
|
||||||
// ZCHECK: call void @dx.op.callShader.struct.CallData(i32 159
|
|
||||||
// ZCHECK: call i1 @dx.op.reportHit.struct.Attr(i32 158
|
|
||||||
// ZCHECK: call void @dx.op.ignoreHit(i32 155)
|
|
||||||
// ZCHECK: call float @dx.op.objectToWorld.f32(i32 151, i32 0, i8 3)
|
|
||||||
// ZCHECK: !{i32 8, i32 10, i32 6, i32 20, i32 7, i32 8, i32 5, !{{.*}}}
|
|
||||||
struct Payload { float4 color; uint depth; };
|
|
||||||
struct Attr { float2 bary; };
|
|
||||||
struct CallData { float3 v; };
|
|
||||||
|
|
||||||
RaytracingAccelerationStructure scene : register(t0);
|
|
||||||
RWTexture2D<float4> output : register(u0);
|
|
||||||
|
|
||||||
[shader("raygeneration")]
|
|
||||||
void rgen() {
|
|
||||||
uint2 id = DispatchRaysIndex().xy;
|
|
||||||
float2 uv = (float2(id) + 0.5) / float2(DispatchRaysDimensions().xy);
|
|
||||||
RayDesc ray;
|
|
||||||
ray.Origin = float3(uv, 0);
|
|
||||||
ray.Direction = float3(0, 0, 1);
|
|
||||||
ray.TMin = 0.001;
|
|
||||||
ray.TMax = 1000;
|
|
||||||
Payload p = { float4(0, 0, 0, 0), 0 };
|
|
||||||
TraceRay(scene, RAY_FLAG_FORCE_OPAQUE, 0xFF, 0, 1, 0, ray, p);
|
|
||||||
CallData c = { p.color.rgb };
|
|
||||||
CallShader(0, c);
|
|
||||||
output[id] = float4(c.v, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("closesthit")]
|
|
||||||
void chit(inout Payload p, in BuiltInTriangleIntersectionAttributes a) {
|
|
||||||
float3x4 m = ObjectToWorld3x4();
|
|
||||||
p.color = float4(a.barycentrics, RayTCurrent(), m[0][3]) + WorldRayDirection().xyzz;
|
|
||||||
p.depth = InstanceID() + PrimitiveIndex() + HitKind() + GeometryIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("miss")]
|
|
||||||
void miss(inout Payload p) {
|
|
||||||
p.color = float4(WorldRayOrigin(), RayTMin());
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("anyhit")]
|
|
||||||
void ahit(inout Payload p, in Attr a) {
|
|
||||||
if (a.bary.x > 0.5)
|
|
||||||
IgnoreHit();
|
|
||||||
if (RayFlags() & RAY_FLAG_CULL_BACK_FACING_TRIANGLES)
|
|
||||||
AcceptHitAndEndSearch();
|
|
||||||
p.depth += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("intersection")]
|
|
||||||
void isect() {
|
|
||||||
Attr a = { ObjectRayOrigin().xy };
|
|
||||||
ReportHit(RayTCurrent() * 0.5, 0, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("callable")]
|
|
||||||
void call(inout CallData c) {
|
|
||||||
c.v *= 2;
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Arrays of resources passed to functions (whole arrays, indexed
|
|
||||||
// constantly and dynamically inside), and an element passed alone.
|
|
||||||
// ZCHECK: @dx.op.sampleLevel.f32(i32 62,
|
|
||||||
// ZCHECK: @dx.op.textureLoad.f32(i32 66,
|
|
||||||
Texture2D<float4> texs[4] : register(t0);
|
|
||||||
Texture2D<float4> more[2] : register(t4);
|
|
||||||
SamplerState samps[2] : register(s0);
|
|
||||||
RWStructuredBuffer<float4> o : register(u0);
|
|
||||||
float4 sum(Texture2D<float4> ts[4], SamplerState s, float2 uv) { float4 r = 0; for (int k = 0; k < 4; k++) r += ts[k].SampleLevel(s, uv, 0); return r; }
|
|
||||||
float4 pick(Texture2D<float4> ts[2], uint i) { return ts[i].Load(int3(0,0,0)); }
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_DispatchThreadID) {
|
|
||||||
o[i] = sum(texs, samps[1], 0.5) + pick(more, i % 2) + pick(more, 0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// Resource arrays are register ranges; elements get handles where used.
|
|
||||||
// ZCHECK: createHandle(i32 57, i8 0, i32 0, i32 3, i1 false)
|
|
||||||
// ZCHECK: createHandle(i32 57, i8 0, i32 0, i32 {{.*}}, i1 true)
|
|
||||||
// ZCHECK: ]* undef, !"", i32 0, i32 1, i32 4, i32 2, i32 0,
|
|
||||||
// ZCHECK: [2 x %struct.SamplerState]* undef
|
|
||||||
Texture2D ts[4] : register(t1);
|
|
||||||
SamplerState ss[2] : register(s0);
|
|
||||||
RWStructuredBuffer<float> bufs[3] : register(u0);
|
|
||||||
float4 main(float2 uv : UV, uint i : I) : SV_Target {
|
|
||||||
float4 c = ts[2].Sample(ss[1], uv) + ts[NonUniformResourceIndex(i)].Sample(ss[0], uv);
|
|
||||||
bufs[1][0] = c.x;
|
|
||||||
return c + bufs[i][3];
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// out / inout resources: a function handing resources back through out
|
|
||||||
// parameters, and inout resources passed through unchanged.
|
|
||||||
// ZCHECK: @dx.op.textureLoad.f32(i32 66,
|
|
||||||
// ZCHECK: @dx.op.sampleLevel.f32(i32 62,
|
|
||||||
Texture2D<float4> texA : register(t0);
|
|
||||||
Texture2D<float4> texB : register(t1);
|
|
||||||
SamplerState samp : register(s0);
|
|
||||||
RWStructuredBuffer<float4> o : register(u0);
|
|
||||||
void getResources(out Texture2D<float4> t, out SamplerState s) { t = texB; s = samp; }
|
|
||||||
float4 useAndKeep(inout Texture2D<float4> t, SamplerState s) { return t.SampleLevel(s, 0.5, 0); }
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_DispatchThreadID) {
|
|
||||||
Texture2D<float4> t;
|
|
||||||
SamplerState s;
|
|
||||||
getResources(t, s);
|
|
||||||
Texture2D<float4> a = texA;
|
|
||||||
o[i] = t.Load(int3(0,0,0)) + useAndKeep(a, s) + useAndKeep(texA, s);
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// Resources passed to functions and held in locals (inlined to handles).
|
|
||||||
// ZCHECK: @dx.op.sample.f32(i32 60
|
|
||||||
Texture2D<float4> t0 : register(t0);
|
|
||||||
Texture2D<float4> t1 : register(t1);
|
|
||||||
SamplerState s : register(s0);
|
|
||||||
StructuredBuffer<float> b0 : register(t2);
|
|
||||||
float4 tap(Texture2D<float4> t, SamplerState ss, float2 uv) { return t.Sample(ss, uv); }
|
|
||||||
float rd(StructuredBuffer<float> b, uint i) { return b[i]; }
|
|
||||||
float4 main(float2 uv : UV) : SV_Target { Texture2D<float4> loc = t1; return tap(t0, s, uv) + tap(loc, s, uv * 2) + rd(b0, 3); }
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Resources in structs: locals, copies, nested structs, arrays, init
|
|
||||||
// lists, functions taking and returning them, and a global struct whose
|
|
||||||
// resources become their own bindings (data members stay in $Globals).
|
|
||||||
// ZCHECK: @dx.op.sampleLevel.f32(i32 62,
|
|
||||||
// ZCHECK: @dx.op.textureLoad.f32(i32 66,
|
|
||||||
// ZCHECK: texture f32 2d T2 t0 1
|
|
||||||
struct Material { Texture2D<float4> albedo; SamplerState samp; float scale; };
|
|
||||||
struct Pair { Material a; Material b; };
|
|
||||||
Texture2D<float4> texA : register(t3);
|
|
||||||
Texture2D<float4> texB : register(t4);
|
|
||||||
SamplerState sampA : register(s1);
|
|
||||||
struct Globals { float a; Texture2D<float4> t; float b; RWBuffer<float> out_buf; };
|
|
||||||
Globals g;
|
|
||||||
RWStructuredBuffer<float4> o : register(u0);
|
|
||||||
float4 shade(Material m, float2 uv) { return m.albedo.SampleLevel(m.samp, uv, 0) * m.scale; }
|
|
||||||
Material make(Texture2D<float4> t, float k) { Material m; m.albedo = t; m.samp = sampA; m.scale = k; return m; }
|
|
||||||
Texture2D<float4> pick() { return texB; }
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_DispatchThreadID) {
|
|
||||||
Material m; m.albedo = texA; m.samp = sampA; m.scale = 2;
|
|
||||||
Material m2 = m; m2.scale = 3;
|
|
||||||
Pair p; p.a = m; p.b = make(texB, 4);
|
|
||||||
Material arr[2] = { m, m2 };
|
|
||||||
o[i] = shade(m, float2(0.5, 0.5)) + shade(m2, 0.25) + shade(p.b, 0.1) + shade(arr[1], 0.2) + pick().Load(int3(0,0,0)) + g.t.Load(int3(1,1,0)) * g.a + g.b;
|
|
||||||
g.out_buf[i] = 1;
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// Root signatures from the RootSignature attribute (a macro of
|
|
||||||
// concatenated strings): an RTS0 part matching dxc's (version 1.1).
|
|
||||||
// ZCHECK: define void @main()
|
|
||||||
#define RS "RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), " \
|
|
||||||
"CBV(b0), DescriptorTable(SRV(t0), visibility=SHADER_VISIBILITY_PIXEL), StaticSampler(s0)"
|
|
||||||
cbuffer C : register(b0) { float4 k; };
|
|
||||||
Texture2D t : register(t0); SamplerState s : register(s0);
|
|
||||||
[RootSignature(RS)]
|
|
||||||
float4 main(float2 uv : TEXCOORD) : SV_Target { return t.Sample(s, uv) * k; }
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
// PROFILE: ps_6_6
|
|
||||||
// Rasterizer-ordered views and globallycoherent UAVs: resource metadata,
|
|
||||||
// annotateHandle properties and the ROVs shader flag.
|
|
||||||
// ZCHECK: Raster Ordered UAVs
|
|
||||||
// ZCHECK: ResourceProperties { i32 20491, i32 0 }
|
|
||||||
// ZCHECK: ResourceProperties { i32 12290, i32 1033 }
|
|
||||||
// ZCHECK: i32 2, i1 false, i1 false, i1 true,
|
|
||||||
// ZCHECK: i32 11, i1 true, i1 false, i1 false,
|
|
||||||
globallycoherent RWByteAddressBuffer buffer1 : register(u0);
|
|
||||||
RasterizerOrderedTexture2D<float4> rov : register(u1);
|
|
||||||
|
|
||||||
float4 main(float4 p : SV_Position) : SV_Target {
|
|
||||||
rov[uint2(p.xy)] += buffer1.Load(0);
|
|
||||||
return rov[uint2(p.xy)];
|
|
||||||
}
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
// PROFILE: vs_6_0
|
|
||||||
float4 main() : SV_Position { return 1; }
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
// PROFILE: vs_6_0
|
|
||||||
// Return value first, then parameters; inout packs its output side; clip
|
|
||||||
// distances and matrices span rows.
|
|
||||||
struct O { float4 a : A; float2 b[2] : B; };
|
|
||||||
float4 main(in float3 x : X, out float y : Y, inout float2 z : Z, float4x2 m : M, row_major float2x3 rm : RM, out O o, uint iid : SV_InstanceID, out float4 p : SV_Position, out float cd[2] : SV_ClipDistance) : R { y = x.x; z += 1; o.a = m[0].xyxy+rm[0].xyzx; o.b[0] = 1; o.b[1] = iid; p = 1; cd[0]=1; cd[1]=2; return 2; }
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// ZCHECK: call void @dx.op.discard(i32 82, i1 true)
|
|
||||||
// ZCHECK: @dx.op.unary.f32(i32 83,
|
|
||||||
struct PSIn { float4 pos : SV_Position; float2 uv : TEXCOORD0; nointerpolation uint id : TEXCOORD1; float3 n : NORMAL; };
|
|
||||||
float4 main(PSIn i, bool ff : SV_IsFrontFace) : SV_Target { if (i.uv.x < 0) discard; return float4(i.n * (ff ? 1 : -1), i.uv.y + i.id + ddx(i.uv.x)); }
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// Interpolation modifiers, shadow (SV_SampleIndex) and unpacked outputs.
|
|
||||||
// ZCHECK: @dx.op.sampleIndex.i32(i32 90)
|
|
||||||
float4 main(float4 p : SV_Position, centroid float c : C, noperspective float2 np : NP, sample float s : S, uint pid : SV_PrimitiveID, uint si : SV_SampleIndex, out float d : SV_Depth, out float4 t1 : SV_Target1, out uint cov : SV_Coverage) : SV_Target0 { d = 0.5; t1 = 1; cov = 3; return c + np.x + pid + si + s+p.x; }
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// SV_Target arrays split into one element per render target.
|
|
||||||
uint i;
|
|
||||||
float4 main(int4 a : A, out float4 o[2] : SV_TARGET, out float4 o2[2][2] : SV_TARGET2) : SV_TARGET7
|
|
||||||
{
|
|
||||||
o[0] = a+2;
|
|
||||||
o[1] = a+3;
|
|
||||||
o[i] = a+10;
|
|
||||||
o2[0][0] = a+5;
|
|
||||||
o2[0][1] = a+6;
|
|
||||||
o2[1][0] = a+7;
|
|
||||||
o2[1][1] = a+8;
|
|
||||||
o2[i][i] = a + 12;
|
|
||||||
return a + 16;
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
// PROFILE: vs_6_0
|
|
||||||
// bool and min16float elements.
|
|
||||||
// ZCHECK: @dx.op.loadInput.f16(
|
|
||||||
struct O { float4 p : SV_Position; bool b : B; min16float h : H; int2 i : I; };
|
|
||||||
O main(bool bi : BI, min16float2 hi : HI, float4 v : SV_Position) { O o; o.p = v; o.b = bi; o.h = hi.x; o.i = 3; return o; }
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
// PROFILE: vs_6_0
|
|
||||||
cbuffer C : register(b0) { float4x4 mvp; };
|
|
||||||
struct VSIn { float3 pos : POSITION; float2 uv : TEXCOORD0; float3 n : NORMAL; uint id : SV_VertexID; };
|
|
||||||
struct VSOut { float4 pos : SV_Position; float2 uv : TEXCOORD0; nointerpolation uint id : TEXCOORD1; float3 n : NORMAL; };
|
|
||||||
VSOut main(VSIn i) { VSOut o; o.pos = mul(mvp, float4(i.pos, 1)); o.uv = i.uv; o.id = i.id; o.n = i.n; return o; }
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
// PROFILE: vs_6_0
|
|
||||||
// Static globals are initialized on entry; float constants keep their value.
|
|
||||||
// ZCHECK: store float 3.000000e+00
|
|
||||||
// ZCHECK: store float 5.000000e+00
|
|
||||||
// ZCHECK: fadd float {{.*}}, 1.500000e+00
|
|
||||||
static const float2 offs[2] = { float2(1, 2), float2(3, 4) };
|
|
||||||
static float g = 5;
|
|
||||||
float4 main(uint id : SV_VertexID) : SV_Position { g += 1.5; return float4(offs[id], g, 1); }
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Static locals: private globals initialized on entry.
|
|
||||||
RWStructuredBuffer<int> o : register(u0);
|
|
||||||
int next() { static int counter = 10; counter += 1; return counter; }
|
|
||||||
[numthreads(1,1,1)] void main() { static const float k[3] = {1, 2, 3}; o[0] = next() + next() + (int)k[2]; }
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// Status arguments (sparse feedback) and CheckAccessFullyMapped.
|
|
||||||
// ZCHECK: checkAccessFullyMapped.i32(i32 71
|
|
||||||
Texture2D<float4> t : register(t0);
|
|
||||||
Buffer<float4> b : register(t2);
|
|
||||||
SamplerState s : register(s0);
|
|
||||||
float4 main(float2 uv : UV) : SV_Target {
|
|
||||||
uint st0, st1, st6;
|
|
||||||
float4 a = t.Sample(s, uv, int2(1, 0), 0.5, st0);
|
|
||||||
if (!CheckAccessFullyMapped(st0)) a = 0;
|
|
||||||
float4 l = t.Load(int3(1, 2, 0), int2(0, 0), st1);
|
|
||||||
bool m = CheckAccessFullyMapped(st1);
|
|
||||||
float4 bb = b.Load(3, st6);
|
|
||||||
bool n = CheckAccessFullyMapped(st6);
|
|
||||||
return a + (m ? l : 1) + (n ? bb : 2);
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
// PROFILE: lib_6_5
|
|
||||||
// State object subobjects go to the RDAT subobject table (checked against
|
|
||||||
// dxc's RDAT).
|
|
||||||
// ZCHECK: define void @"\01?b@@YAXUP@@@Z"
|
|
||||||
StateObjectConfig soc = { STATE_OBJECT_FLAGS_ALLOW_LOCAL_DEPENDENCIES_ON_EXTERNAL_DEFINITONS };
|
|
||||||
SubobjectToExportsAssociation sea = { "rsc", "a;b;foo;c" };
|
|
||||||
SubobjectToExportsAssociation sea2 = { "rsc", ";" };
|
|
||||||
RaytracingShaderConfig rsc = { 128, 64 };
|
|
||||||
RaytracingPipelineConfig rpc = { 512 };
|
|
||||||
TriangleHitGroup trHitGt = { "a", "b" };
|
|
||||||
ProceduralPrimitiveHitGroup ppHitGt = { "a", "b", "c"};
|
|
||||||
RaytracingPipelineConfig1 rpc1 = { 32, RAYTRACING_PIPELINE_FLAG_SKIP_TRIANGLES };
|
|
||||||
struct P { float4 c; };
|
|
||||||
[shader("miss")] void b(inout P p) { p.c = 1; }
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
// PROFILE: ps_6_8
|
|
||||||
// Pixel system values: clip distances in, barycentrics, coverage in and
|
|
||||||
// out, ViewID, shading rate, stencil ref.
|
|
||||||
struct I { float4 pos : SV_Position; float2 c0 : SV_ClipDistance0; float c1 : SV_ClipDistance1; noperspective float3 b2 : SV_Barycentrics1; };
|
|
||||||
struct O { float4 c : SV_Target; uint cov : SV_Coverage; uint st : SV_StencilRef; };
|
|
||||||
O main(I i, float3 b : SV_Barycentrics, uint cov : SV_Coverage, uint v : SV_ViewID, uint sr : SV_ShadingRate) { O o; o.c = float4(b + i.b2, i.c0.y + i.c1 + v + sr); o.cov = cov; o.st = 1; return o; }
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
// PROFILE: vs_6_8
|
|
||||||
// Vertex system values: clip/cull distances, ViewID, start vertex and
|
|
||||||
// instance, viewport / render target index, shading rate.
|
|
||||||
struct O { float4 pos : SV_Position; float2 c0 : SV_ClipDistance0; float c1 : SV_ClipDistance1; float cu : SV_CullDistance; uint vp : SV_ViewportArrayIndex; uint rt : SV_RenderTargetArrayIndex; uint sr : SV_ShadingRate; };
|
|
||||||
O main(uint v : SV_ViewID, uint sv : SV_StartVertexLocation, uint si : SV_StartInstanceLocation) { O o = (O)0; o.pos = v + sv + si; o.c0 = 1; o.c1 = 2; return o; }
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// switch: fallthrough, default, break, continue to the enclosing loop.
|
|
||||||
// ZCHECK: switch i32 {{.*}}, label
|
|
||||||
RWStructuredBuffer<int> o : register(u0);
|
|
||||||
[numthreads(4,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
int r = 0;
|
|
||||||
for (int k = 0; k < 3; k++) {
|
|
||||||
switch (i + k) {
|
|
||||||
case 0: r += 1; break;
|
|
||||||
case 1:
|
|
||||||
case 2: r += 2;
|
|
||||||
case 3: r += 3; break;
|
|
||||||
default: if (r > 4) continue; r -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch (r) { case 7: o[1] = 7; }
|
|
||||||
o[i] = r;
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// tbuffer blocks and TextureBuffer<S>: TBuffer SRVs read a register at a
|
|
||||||
// time (cbuffer layout).
|
|
||||||
// ZCHECK: call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68
|
|
||||||
struct S { float4 a; float b; float3 c; };
|
|
||||||
tbuffer TB : register(t0) { float4 x; float y; S s; };
|
|
||||||
TextureBuffer<S> tbs : register(t1);
|
|
||||||
RWStructuredBuffer<float4> o : register(u0);
|
|
||||||
[numthreads(1,1,1)] void main() { o[0] = x * y + s.a + tbs.a * tbs.b + float4(tbs.c, 1); }
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Templates (function, class, variable; deduction, defaults, specializations) and methods.
|
|
||||||
template<typename T> T square(T x) { return x * x; }
|
|
||||||
template<typename T, int N> vector<T, N> scale(vector<T, N> v, T k) { return v * k; }
|
|
||||||
template<typename T> struct Pair { T a; T b; T sum() { return a + b; } };
|
|
||||||
template<typename T, uint N = 4> struct Arr { T v[N]; T get(uint i) { return v[i]; } };
|
|
||||||
template<typename T> T first(Pair<T> p) { return p.a; }
|
|
||||||
RWStructuredBuffer<float> o : register(u0);
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_DispatchThreadID) {
|
|
||||||
Pair<float> p; p.a = 1; p.b = 2;
|
|
||||||
Arr<int> a; a.v[0] = 3; a.v[1] = 4; a.v[2] = 5; a.v[3] = 6;
|
|
||||||
o[i] = square(2.0f) + square(3) + scale(float3(1, 2, 3), 2.0f).z + p.sum() + a.get(2) + first(p) + square<uint>(2);
|
|
||||||
}
|
|
||||||
template <class, class> static const bool is_same_v = false;
|
|
||||||
template <class T> static const bool is_same_v<T, T> = true;
|
|
||||||
template<typename T> struct Box { T v; };
|
|
||||||
template<> struct Box<int> { int v; int extra; };
|
|
||||||
struct Base { float b; float twice() { return b * 2; } };
|
|
||||||
struct Derived : Base { float d; };
|
|
||||||
[numthreads(1,1,1)] void more(uint i : SV_DispatchThreadID) {
|
|
||||||
Box<int> bi; bi.extra = 2; Derived dv; dv.b = 3;
|
|
||||||
o[i] = is_same_v<int, int> + is_same_v<int, float> + bi.extra + dv.twice();
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// More templates: `S<T>::member`, partial specialization through
|
|
||||||
// matrix<T, N, M>, the injected class name, member function templates,
|
|
||||||
// SFINAE (enable_if), out-of-line member definitions (plain, static and
|
|
||||||
// of class templates), alias template deduction, argument-dependent
|
|
||||||
// lookup.
|
|
||||||
// ZCHECK: @dx.op.bufferStore.f32
|
|
||||||
template <bool C, typename T> struct enable_if {};
|
|
||||||
template <typename T> struct enable_if<true, T> { using type = T; };
|
|
||||||
|
|
||||||
template <typename M> struct traits;
|
|
||||||
template <typename T, int N, int K> struct traits<matrix<T, N, K> > {
|
|
||||||
static const uint Count = N * K;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace ns {
|
|
||||||
template <typename T, int N> struct Vec {
|
|
||||||
T v[N];
|
|
||||||
Vec scaled(T k);
|
|
||||||
template <int L> Vec Shifted() { Vec r; r.v = v; r.v[0] += L; return r; }
|
|
||||||
template <int L> static Vec Make(T x) { Vec r; for (int i = 0; i < N; i++) r.v[i] = x * L; return r; }
|
|
||||||
};
|
|
||||||
template <typename T, int N> Vec<T, N> Vec<T, N>::scaled(T k) {
|
|
||||||
Vec r; for (int i = 0; i < N; i++) r.v[i] = v[i] * k; return r;
|
|
||||||
}
|
|
||||||
template <typename T> using Vec2 = Vec<T, 2>;
|
|
||||||
template <typename T> T head(Vec2<T> x) { return x.v[0]; }
|
|
||||||
}
|
|
||||||
|
|
||||||
struct S { float a; float get(float k); static float twice(float x); };
|
|
||||||
float S::get(float k) { return a * k; }
|
|
||||||
float S::twice(float x) { return x * 2; }
|
|
||||||
|
|
||||||
template <typename T> typename enable_if<(sizeof(T) == 4), T>::type pick(T x) { return x; }
|
|
||||||
template <typename T> typename enable_if<(sizeof(T) == 8), T>::type pick(T x) { return x * 2; }
|
|
||||||
|
|
||||||
RWStructuredBuffer<float> o : register(u0);
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_DispatchThreadID) {
|
|
||||||
S s; s.a = 3;
|
|
||||||
ns::Vec2<float> v = ns::Vec2<float>::Make<3>(2);
|
|
||||||
ns::Vec<float, 2> g = v.scaled(2).Shifted<1>();
|
|
||||||
o[i] = traits<float2x3>::Count + s.get(2) + S::twice(1) + head(v) + g.v[0] + pick(1.0f);
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// Texture and sampler operations; argument layout as dxc emits it.
|
|
||||||
// ZCHECK: @dx.op.sample.f32(i32 60, %dx.types.Handle {{.*}}, float {{.*}}, float undef, float undef, i32 1, i32 2, i32 undef, float undef)
|
|
||||||
// ZCHECK: @dx.op.sampleLevel.f32(i32 62,
|
|
||||||
// ZCHECK: @dx.op.sampleBias.f32(i32 61,
|
|
||||||
// ZCHECK: @dx.op.sampleGrad.f32(i32 63,
|
|
||||||
// ZCHECK: @dx.op.sampleCmp.f32(i32 64,
|
|
||||||
// ZCHECK: @dx.op.sampleCmpLevelZero.f32(i32 65,
|
|
||||||
// ZCHECK: @dx.op.textureLoad.f32(i32 66, %dx.types.Handle {{.*}}, i32 0, i32 1, i32 2, i32 undef, i32 undef, i32 undef, i32 undef)
|
|
||||||
// ZCHECK: @dx.op.textureLoad.i32(i32 66,
|
|
||||||
// ZCHECK: @dx.op.bufferLoad.f32(i32 68,
|
|
||||||
// ZCHECK: @dx.op.textureGather.f32(i32 73, {{.*}}, i32 1, i32 1, i32 1)
|
|
||||||
// ZCHECK: @dx.op.textureGatherCmp.f32(i32 74,
|
|
||||||
// ZCHECK: @dx.op.getDimensions(i32 72, %dx.types.Handle {{.*}}, i32 1)
|
|
||||||
// ZCHECK: @dx.op.calculateLOD.f32(i32 81,
|
|
||||||
// ZCHECK: @dx.op.textureStore.f32(i32 67,
|
|
||||||
// ZCHECK: !{i32 1, %struct.SamplerComparisonState* undef, !"", i32 0, i32 1, i32 1, i32 1, null}
|
|
||||||
Texture2D<float4> t2 : register(t0);
|
|
||||||
Texture2DArray<float> t2a : register(t1);
|
|
||||||
TextureCube tc : register(t2);
|
|
||||||
Texture2DMS<float4> tms : register(t3);
|
|
||||||
Texture3D<uint2> t3 : register(t4);
|
|
||||||
Buffer<float4> buf : register(t5);
|
|
||||||
RWTexture2D<float4> rw : register(u0);
|
|
||||||
SamplerState s : register(s0);
|
|
||||||
SamplerComparisonState sc : register(s1);
|
|
||||||
float4 main(float2 uv : UV) : SV_Target {
|
|
||||||
float4 r = t2.Sample(s, uv) + t2.Sample(s, uv, int2(1, 2)) + t2.SampleLevel(s, uv, 2) + t2.SampleBias(s, uv, 0.5) + t2.SampleGrad(s, uv, uv, uv);
|
|
||||||
r.x += t2a.SampleCmp(sc, float3(uv, 1), 0.5) + t2a.SampleCmpLevelZero(sc, float3(uv, 1), 0.5);
|
|
||||||
r += tc.Sample(s, uv.xyx) + t2.Load(int3(1, 2, 0)) + tms.Load(int2(1, 1), 2) + t3[uint3(1,2,3)].x + buf[3] + buf.Load(2);
|
|
||||||
r += t2.Gather(s, uv) + t2.GatherGreen(s, uv, int2(1, 1)) + t2a.GatherCmp(sc, float3(uv, 0), 0.5);
|
|
||||||
uint w, h, l; t2.GetDimensions(1, w, h, l);
|
|
||||||
float fw, fh; rw.GetDimensions(fw, fh);
|
|
||||||
r.x += w + h + l + fw + fh + t2.CalculateLevelOfDetail(s, uv);
|
|
||||||
rw[uint2(1, 2)] = r; r += rw[uint2(3,4)];
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// Loops unroll so texel offsets become constants (as dxc requires).
|
|
||||||
// ZCHECK: @dx.op.sample.f32(i32 60, {{.*}}, i32 -1, i32 -2, i32 undef, float undef)
|
|
||||||
// ZCHECK: @dx.op.sample.f32(i32 60, {{.*}}, i32 0, i32 -2, i32 undef, float undef)
|
|
||||||
// ZCHECK: @dx.op.sample.f32(i32 60, {{.*}}, i32 1, i32 -2, i32 undef, float undef)
|
|
||||||
// ZCHECK: @dx.op.sample.f32(i32 60, {{.*}}, i32 -1, i32 0, i32 undef, float undef)
|
|
||||||
// ZCHECK: @dx.op.sample.f32(i32 60, {{.*}}, i32 1, i32 2, i32 undef, float undef)
|
|
||||||
// ZCHECK: @dx.op.sampleLevel.f32(i32 62, {{.*}}, i32 -1, i32 0, i32 undef, float 0.000000e+00)
|
|
||||||
// ZCHECK: @dx.op.sampleLevel.f32(i32 62, {{.*}}, i32 2, i32 0, i32 undef, float 0.000000e+00)
|
|
||||||
Texture2D t : register(t0);
|
|
||||||
SamplerState s : register(s0);
|
|
||||||
static const int R = 1;
|
|
||||||
float4 main(float2 uv : UV, uint n : N) : SV_Target {
|
|
||||||
float4 c = 0;
|
|
||||||
// Nested loops whose offsets need constants, with a static const bound.
|
|
||||||
for (int y = -R; y <= R; y++)
|
|
||||||
for (int x = -R; x <= R; x++)
|
|
||||||
c += t.Sample(s, uv, int2(x, y * 2));
|
|
||||||
// [unroll] with a step other than one and a shifted offset.
|
|
||||||
[unroll] for (uint i = 0; i < 6; i += 3) c += t.SampleLevel(s, uv, 0, int2(i - 1, 0));
|
|
||||||
// Kept as loops: [loop], a break, a run-time bound.
|
|
||||||
[loop] for (int j = 0; j < 4; j++) c.x += j;
|
|
||||||
for (int k = 0; k < 4; k++) { if (c.y > 2) break; c.y += k; }
|
|
||||||
for (uint m = 0; m < n; m++) c.z += m;
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Wave and quad intrinsics, as dxc emits them.
|
|
||||||
// ZCHECK: @dx.op.waveActiveOp.i32(i32 119, i32 {{.*}}, i8 2, i8 1)
|
|
||||||
// ZCHECK: @dx.op.waveAllOp(i32 135
|
|
||||||
// ZCHECK: @dx.op.quadOp.f32(i32 123
|
|
||||||
RWStructuredBuffer<uint4> o : register(u0);
|
|
||||||
[numthreads(64,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
uint4 b = WaveActiveBallot(i > 3);
|
|
||||||
int s = WaveActiveSum((int)i) + WavePrefixProduct((int)i) + WaveActiveMax((int)i);
|
|
||||||
uint u = WaveActiveMin(i) + WaveActiveBitXor(i) + WaveReadLaneAt(i, 2) + WaveReadLaneFirst(i) + WaveActiveCountBits(i > 1) + WavePrefixCountBits(i < 9);
|
|
||||||
bool f = WaveIsFirstLane() && WaveActiveAnyTrue(i == 0) && WaveActiveAllTrue(i < 100) && WaveActiveAllEqual(i);
|
|
||||||
float q = QuadReadAcrossX((float)i) + QuadReadLaneAt((float)i, 1);
|
|
||||||
o[i] = b + s + u + f + WaveGetLaneIndex() + WaveGetLaneCount() + (uint)q;
|
|
||||||
}
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# --job=<job.json> checks: a job file listing the DXIL and SPIR-V check
|
|
||||||
# tests (plus two jobs that fail) must give byte-identical outputs and the
|
|
||||||
# same diagnostics, in job order, as one zdxc run per job, with the exit
|
|
||||||
# code of the failures (1 if any failed on its command line, else 5).
|
|
||||||
#
|
|
||||||
# Usage: test/job/check.sh <path-to-zdxc>
|
|
||||||
set -u
|
|
||||||
ZDXC=$1
|
|
||||||
TMP=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
|
||||||
mkdir "$TMP/job" "$TMP/one"
|
|
||||||
n=0
|
|
||||||
# The job file and, one per line, the same command lines for separate runs;
|
|
||||||
# @ stands for the output directory.
|
|
||||||
{
|
|
||||||
printf '{ "args": ["-no-warnings"], "jobs": [\n'
|
|
||||||
for f in test/dxil/*.hlsl test/spirv/*.hlsl; do
|
|
||||||
profile=$(sed -n 's|^// PROFILE: *||p' "$f")
|
|
||||||
flags=$(sed -n 's|^// FLAGS: *||p' "$f")
|
|
||||||
case "$f" in test/spirv/*)
|
|
||||||
env=$(sed -n 's|^// ENV: *||p' "$f")
|
|
||||||
flags="$flags -spirv -fspv-target-env=${env:-vulkan1.0}" ;;
|
|
||||||
esac
|
|
||||||
args=""
|
|
||||||
for a in -T "$profile" $flags "$f" -Fo "@/$n.out"; do args="$args\"$a\", "; done
|
|
||||||
printf ' { "args": [%s] },\n' "${args%, }"
|
|
||||||
n=$((n + 1))
|
|
||||||
done
|
|
||||||
# A compile error (5) and a missing input (1).
|
|
||||||
printf ' { "args": ["-T", "cs_6_0", "test/job/error.hlsl", "-Fo", "@/err.out"] },\n'
|
|
||||||
printf ' { "args": ["-T", "cs_6_0", "test/job/missing.hlsl", "-Fo", "@/missing.out"] }\n'
|
|
||||||
printf '] }\n'
|
|
||||||
} > "$TMP/job.in"
|
|
||||||
sed "s|@|$TMP/job|g" "$TMP/job.in" > "$TMP/job.json"
|
|
||||||
# Each job's args back to a command line.
|
|
||||||
sed -n 's|^ { "args": \[\(.*\)\] },*$|\1|p' "$TMP/job.in" | sed 's|", "| |g; s|"||g' > "$TMP/lines"
|
|
||||||
n=$(($(wc -l < "$TMP/lines") - 2))
|
|
||||||
|
|
||||||
"$ZDXC" --job="$TMP/job.json" > "$TMP/job.stdout" 2> "$TMP/job.stderr"
|
|
||||||
code=$?
|
|
||||||
: > "$TMP/one.stderr"
|
|
||||||
while read -r line; do
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
"$ZDXC" -no-warnings $(printf '%s' "$line" | sed "s|@|$TMP/one|g") 2>> "$TMP/one.stderr" > /dev/null
|
|
||||||
done < "$TMP/lines"
|
|
||||||
|
|
||||||
fail=0
|
|
||||||
for f in "$TMP"/one/*; do
|
|
||||||
cmp -s "$f" "$TMP/job/$(basename "$f")" || { echo "FAIL: $(basename "$f") differs from a run of its own"; fail=1; }
|
|
||||||
done
|
|
||||||
[ "$(ls "$TMP/one" | wc -l)" -eq "$(ls "$TMP/job" | wc -l)" ] || { echo "FAIL: different sets of outputs"; fail=1; }
|
|
||||||
grep -v 'jobs failed$' "$TMP/job.stderr" | sed "s|$TMP/job|@|g" > "$TMP/a"
|
|
||||||
sed "s|$TMP/one|@|g" "$TMP/one.stderr" > "$TMP/b"
|
|
||||||
cmp -s "$TMP/a" "$TMP/b" || { echo "FAIL: diagnostics differ or are out of order"; diff "$TMP/a" "$TMP/b" | head; fail=1; }
|
|
||||||
grep -q '^zdxc: 2 of [0-9]* jobs failed$' "$TMP/job.stderr" || { echo "FAIL: no failure summary"; fail=1; }
|
|
||||||
[ "$code" -eq 1 ] || { echo "FAIL: exit code $code, expected 1"; fail=1; }
|
|
||||||
echo "job checks: $n compiled + 2 failing jobs, $([ $fail = 0 ] && echo passed || echo FAILED)"
|
|
||||||
[ $fail = 0 ]
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
// A compile error, for test/job/check.sh.
|
|
||||||
[numthreads(1, 1, 1)] void main() { undeclared = 1; }
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# Command-line oracle: every dxc invocation in the DXC test corpus (the
|
|
||||||
# arguments of each `RUN: %dxc ...` line) must be understood by zdxc's
|
|
||||||
# dxc-compatible parser. Allowed outcomes: accepted, or rejected as an
|
|
||||||
# unsupported dxc feature. "unknown argument" / "missing argument" fail.
|
|
||||||
#
|
|
||||||
# Usage: test/oracle/cli.sh <path-to-zdxc>
|
|
||||||
set -u
|
|
||||||
ZDXC=$(cd "$(dirname "$1")" && pwd)/$(basename "$1")
|
|
||||||
DXC_ROOT=${DXC_ROOT:-..}
|
|
||||||
TMP=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
|
||||||
|
|
||||||
grep -rh --include='*.hlsl' 'RUN: *%dxc ' "$DXC_ROOT/tools/clang/test" > "$TMP/runs" 2>/dev/null
|
|
||||||
total=0; ok=0; unsupported=0; bad=0
|
|
||||||
while IFS= read -r line; do
|
|
||||||
# Arguments between `%dxc` and the first pipe / redirect; drop the input.
|
|
||||||
# Tokens containing lit substitutions (%s, %t, %S/...) are dropped
|
|
||||||
# whole, as are redirections.
|
|
||||||
args=$(printf '%s' "$line" | sed -E 's/.*RUN: *%dxc //; s/[0-9]?>&[0-9]//g; s/[|<>].*$//' | tr ' ' '\n' | grep -v '%' | tr '\n' ' ')
|
|
||||||
total=$((total + 1))
|
|
||||||
# -zdxc-lex on an empty file: only the command line is exercised.
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
if out=$("$ZDXC" $args -zdxc-lex "$TMP/none.hlsl" 2>&1 < /dev/null); then
|
|
||||||
ok=$((ok + 1))
|
|
||||||
elif printf '%s' "$out" | grep -q "is not supported"; then
|
|
||||||
unsupported=$((unsupported + 1))
|
|
||||||
printf '%s\n' "$out" | grep -m1 "is not supported" | sed -E "s/.*error: '([^']*)'.*/\1/" >> "$TMP/unsupported"
|
|
||||||
elif printf '%s' "$out" | grep -qE "unknown argument|is missing|more than one input"; then
|
|
||||||
bad=$((bad + 1))
|
|
||||||
echo "BAD: $args -> $(printf '%s' "$out" | head -1)"
|
|
||||||
else
|
|
||||||
ok=$((ok + 1)) # other errors (e.g. invalid values) are not parser failures
|
|
||||||
fi
|
|
||||||
done < "$TMP/runs"
|
|
||||||
: > "$TMP/none.hlsl"
|
|
||||||
if [ -s "$TMP/unsupported" ]; then
|
|
||||||
echo "unsupported options seen (count):"
|
|
||||||
sort "$TMP/unsupported" | uniq -c | sort -rn | head -${SHOW:-15}
|
|
||||||
fi
|
|
||||||
echo "oracle cli: $total dxc command lines: $ok accepted, $unsupported unsupported-feature, $bad parse failures"
|
|
||||||
[ "$bad" -eq 0 ]
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# Codegen oracle: compiles every dxc-valid corpus file with zdxc and runs the
|
|
||||||
# validator on what it emits. Files zdxc cannot compile yet ("code
|
|
||||||
# generation: ... not supported yet") are counted as unsupported; any output
|
|
||||||
# the validator rejects is a bug.
|
|
||||||
#
|
|
||||||
# Usage: test/oracle/codegen.sh <path-to-zdxc> spirv|dxil
|
|
||||||
# (run test/oracle/parse.sh first to build the corpus list)
|
|
||||||
set -u
|
|
||||||
ZDXC=$(cd "$(dirname "$1")" && pwd)/$(basename "$1")
|
|
||||||
BACKEND=${2:-spirv}
|
|
||||||
DXC_BUILD=${DXC_BUILD:-../build}
|
|
||||||
SPIRV_VAL=$DXC_BUILD/oracle-spirv-tools/tools/spirv-val
|
|
||||||
DXV=$DXC_BUILD/bin/dxv
|
|
||||||
CACHE=zig-out/oracle/parse-valid.txt
|
|
||||||
[ -s "$CACHE" ] || { echo "run test/oracle/parse.sh first to build $CACHE"; exit 1; }
|
|
||||||
TMP=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
|
||||||
valid=0; invalid=0; unsupported=0; other=0; crashed=0
|
|
||||||
: > "$TMP/invalid"; : > "$TMP/reasons"; : > "$TMP/valid"; : > "$TMP/crashed"
|
|
||||||
while read -r f; do
|
|
||||||
flags=$(sh test/oracle/run_flags.sh "$f") || continue
|
|
||||||
is_spirv=0
|
|
||||||
case "$flags" in *-spirv*) is_spirv=1 ;; esac
|
|
||||||
if [ "$BACKEND" = spirv ]; then
|
|
||||||
[ $is_spirv = 1 ] || flags="$flags -spirv"
|
|
||||||
else
|
|
||||||
[ $is_spirv = 1 ] && continue
|
|
||||||
fi
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
"$ZDXC" -fno-color-diagnostics -no-warnings $flags "$f" -Fo "$TMP/out" > "$TMP/log" 2>&1
|
|
||||||
rc=$?
|
|
||||||
if [ $rc -ge 128 ]; then
|
|
||||||
crashed=$((crashed + 1)); echo "$f" >> "$TMP/crashed"
|
|
||||||
elif [ $rc = 0 ]; then
|
|
||||||
if [ "$BACKEND" = spirv ]; then
|
|
||||||
env=$(printf '%s\n' "$flags" | sed -n 's/.*-fspv-target-env=\([a-z0-9.]*\).*/\1/p'); env=$(printf "%s" "$env" | sed -e "s/spirv1/spv1/" -e "s/universal1/spv1/")
|
|
||||||
"$SPIRV_VAL" --target-env "${env:-vulkan1.0}" --relax-block-layout "$TMP/out" > "$TMP/val" 2>&1
|
|
||||||
else
|
|
||||||
"$DXV" "$TMP/out" > "$TMP/val" 2>&1
|
|
||||||
fi
|
|
||||||
if [ $? = 0 ]; then
|
|
||||||
valid=$((valid + 1)); echo "$f" >> "$TMP/valid"
|
|
||||||
else
|
|
||||||
invalid=$((invalid + 1))
|
|
||||||
echo "$f: $(grep -m1 -i "error" "$TMP/val")" >> "$TMP/invalid"
|
|
||||||
fi
|
|
||||||
elif grep -q "code generation" "$TMP/log"; then
|
|
||||||
unsupported=$((unsupported + 1))
|
|
||||||
grep -m1 "code generation" "$TMP/log" | sed -E 's/^.*code generation: //' >> "$TMP/reasons"
|
|
||||||
else
|
|
||||||
other=$((other + 1))
|
|
||||||
echo "$f: $(grep -m1 "error" "$TMP/log")" >> "$TMP/other"
|
|
||||||
fi
|
|
||||||
done < "$CACHE"
|
|
||||||
echo "most common unsupported constructs:"
|
|
||||||
sed -E "s/'[^']*'/'X'/g" "$TMP/reasons" | sort | uniq -c | sort -rn | head -"${SHOW:-15}"
|
|
||||||
if [ "$invalid" -gt 0 ]; then echo "INVALID OUTPUT:"; head -20 "$TMP/invalid"; fi
|
|
||||||
[ -s "$TMP/other" ] && { echo "front-end errors:"; head -5 "$TMP/other"; }
|
|
||||||
cp "$TMP/valid" "zig-out/oracle/codegen-$BACKEND-valid.txt"
|
|
||||||
cp "$TMP/invalid" "zig-out/oracle/codegen-$BACKEND-invalid.txt"
|
|
||||||
[ -s "$TMP/crashed" ] && { echo "CRASHED:"; cat "$TMP/crashed"; }
|
|
||||||
echo "oracle codegen ($BACKEND): $valid valid, $invalid INVALID, $crashed CRASHED, $unsupported unsupported, $other other errors"
|
|
||||||
[ "$invalid" -eq 0 ] && [ "$crashed" -eq 0 ]
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# Print the file name if dxc compiles it with its RUN-line flags (-HV 2021).
|
|
||||||
flags=$(sh "$(dirname "$0")/run_flags.sh" "$1") || exit 0
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
"$DXC" -HV 2021 $flags "$1" -Fo /dev/null >/dev/null 2>&1 && echo "$1"
|
|
||||||
exit 0
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# M0.0 oracle checks: zdxc output must be accepted by DXC's validator (dxv)
|
|
||||||
# and spirv-val, and zdxc's container hash must match dxc-signed containers.
|
|
||||||
#
|
|
||||||
# Usage: test/oracle/m0.sh <path-to-zdxc>
|
|
||||||
# Oracles default to the DXC build next to this repo; override with
|
|
||||||
# DXC_BUILD=<dir> (needs bin/dxc, bin/dxv, oracle-spirv-tools/tools/spirv-val).
|
|
||||||
set -u
|
|
||||||
|
|
||||||
ZDXC=$1
|
|
||||||
DXC_BUILD=${DXC_BUILD:-../build}
|
|
||||||
DXC=$DXC_BUILD/bin/dxc
|
|
||||||
DXV=$DXC_BUILD/bin/dxv
|
|
||||||
SPIRV_VAL=$DXC_BUILD/oracle-spirv-tools/tools/spirv-val
|
|
||||||
TMP=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
|
||||||
|
|
||||||
pass=0
|
|
||||||
fail=0
|
|
||||||
ok() { pass=$((pass + 1)); }
|
|
||||||
bad() { fail=$((fail + 1)); echo "FAIL: $*"; }
|
|
||||||
|
|
||||||
for tool in "$DXC" "$DXV" "$SPIRV_VAL"; do
|
|
||||||
[ -x "$tool" ] || { echo "missing oracle: $tool"; exit 1; }
|
|
||||||
done
|
|
||||||
|
|
||||||
# 1. Hash: re-verify dxc-signed containers with zdxc's DxilHash port.
|
|
||||||
printf '[numthreads(1,1,1)] void main() {}\n' > "$TMP/empty.hlsl"
|
|
||||||
printf 'RWStructuredBuffer<float> o : register(u0);\n[numthreads(64,1,1)] void main(uint i : SV_DispatchThreadID) { o[i] = sqrt((float)i) * 3.0; }\n' > "$TMP/sqrt.hlsl"
|
|
||||||
for src in empty sqrt; do
|
|
||||||
for t in cs_6_0 cs_6_6; do
|
|
||||||
"$DXC" -T $t -E main "$TMP/$src.hlsl" -Fo "$TMP/ref.dxo" >/dev/null 2>&1 || { bad "dxc failed on $src $t"; continue; }
|
|
||||||
if "$ZDXC" -zdxc-check-hash "$TMP/ref.dxo" >/dev/null; then ok; else bad "hash mismatch on dxc output ($src, $t)"; fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
# 2. DXIL: empty compute shader for every shader model must pass dxv.
|
|
||||||
for m in 0 1 2 3 4 5 6 7 8 9; do
|
|
||||||
out="$TMP/cs_6_$m.dxo"
|
|
||||||
if "$ZDXC" -zdxc-empty -T cs_6_$m -Fo "$out" \
|
|
||||||
&& "$DXV" "$out" >/dev/null 2>&1 \
|
|
||||||
&& "$ZDXC" -zdxc-check-hash "$out" >/dev/null; then ok; else bad "dxv rejected cs_6_$m"; fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# 3. SPIR-V: empty compute shader must pass spirv-val.
|
|
||||||
if "$ZDXC" -zdxc-empty -spirv -T cs_6_0 -Fo "$TMP/cs.spv" \
|
|
||||||
&& "$SPIRV_VAL" --target-env vulkan1.0 "$TMP/cs.spv"; then ok; else bad "spirv-val rejected cs"; fi
|
|
||||||
|
|
||||||
echo "oracle m0: $pass passed, $fail failed"
|
|
||||||
[ "$fail" -eq 0 ]
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# Parser oracle: every corpus file that dxc compiles successfully (with the
|
|
||||||
# target and flags from its RUN line, under -HV 2021) must parse without
|
|
||||||
# syntax errors in zdxc. Prints the pass rate and the most common errors.
|
|
||||||
#
|
|
||||||
# Usage: test/oracle/parse.sh <path-to-zdxc>
|
|
||||||
# The list of dxc-valid files is cached in zig-out/oracle/parse-valid.txt;
|
|
||||||
# delete it to rebuild (takes a few minutes).
|
|
||||||
set -u
|
|
||||||
|
|
||||||
ZDXC=$(cd "$(dirname "$1")" && pwd)/$(basename "$1")
|
|
||||||
DXC_ROOT=${DXC_ROOT:-..}
|
|
||||||
DXC=$(cd "${DXC_BUILD:-$DXC_ROOT/build}" && pwd)/bin/dxc
|
|
||||||
CACHE=zig-out/oracle/parse-valid.txt
|
|
||||||
JOBS=${JOBS:-8}
|
|
||||||
mkdir -p zig-out/oracle
|
|
||||||
|
|
||||||
if [ ! -s "$CACHE" ]; then
|
|
||||||
echo "building list of dxc-valid corpus files (cached in $CACHE)..."
|
|
||||||
tmp=$(mktemp)
|
|
||||||
find "$DXC_ROOT/tools/clang/test/CodeGenHLSL" "$DXC_ROOT/tools/clang/test/CodeGenDXIL" "$DXC_ROOT/tools/clang/test/CodeGenSPIRV" -name '*.hlsl' | sort > "$tmp"
|
|
||||||
export DXC
|
|
||||||
xargs -P "$JOBS" -n 1 sh test/oracle/dxc_valid_one.sh < "$tmp" | sort > "$CACHE"
|
|
||||||
rm -f "$tmp"
|
|
||||||
fi
|
|
||||||
|
|
||||||
TMP=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
|
||||||
pass=0
|
|
||||||
fail=0
|
|
||||||
while read -r f; do
|
|
||||||
flags=$(sh test/oracle/run_flags.sh "$f") || continue
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
if "$ZDXC" -zdxc-parse $flags "$f" > "$TMP/out" 2>&1; then
|
|
||||||
pass=$((pass + 1))
|
|
||||||
else
|
|
||||||
fail=$((fail + 1))
|
|
||||||
echo "$f" >> "$TMP/failed"
|
|
||||||
grep -m1 -E 'error' "$TMP/out" | sed -E 's/^.*(error|fatal): //' >> "$TMP/errors"
|
|
||||||
fi
|
|
||||||
done < "$CACHE"
|
|
||||||
|
|
||||||
if [ "$fail" -gt 0 ]; then
|
|
||||||
echo "most common first errors:"
|
|
||||||
sed -E "s/'[^']*'/'X'/g" "$TMP/errors" | sort | uniq -c | sort -rn | head -${SHOW:-15}
|
|
||||||
echo "first failing files:"
|
|
||||||
head -${SHOW_FILES:-10} "$TMP/failed"
|
|
||||||
fi
|
|
||||||
echo "oracle parse: $pass passed, $fail failed (of $(wc -l < "$CACHE" | tr -d ' ') dxc-valid files)"
|
|
||||||
[ "$fail" -eq 0 ]
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# Print the first parse error of every dxc-valid corpus file that zdxc
|
|
||||||
# fails to parse (run test/oracle/parse.sh first to build the file list).
|
|
||||||
# Usage: test/oracle/parse_errors.sh <path-to-zdxc>
|
|
||||||
while read -r f; do
|
|
||||||
flags=$(sh test/oracle/run_flags.sh "$f") || continue
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
"$1" -zdxc-parse $flags "$f" 2>&1 | grep -m1 -E "error|fatal" | sed -E "s#^[^ ]*: (error|fatal): #$f: #"
|
|
||||||
done < zig-out/oracle/parse-valid.txt
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# Preprocessor oracle: zdxc -P must produce the same token stream as dxc -P
|
|
||||||
# (ignoring #line markers and whitespace) over the DXC HLSL test corpus.
|
|
||||||
#
|
|
||||||
# Usage: test/oracle/pp.sh <path-to-zdxc> [corpus-dir...]
|
|
||||||
set -u
|
|
||||||
|
|
||||||
ZDXC=$(cd "$(dirname "$1")" && pwd)/$(basename "$1")
|
|
||||||
shift
|
|
||||||
DXC_ROOT=${DXC_ROOT:-..}
|
|
||||||
DXC=${DXC_BUILD:-$DXC_ROOT/build}/bin/dxc
|
|
||||||
[ $# -gt 0 ] || set -- "$DXC_ROOT/tools/clang/test/CodeGenHLSL" "$DXC_ROOT/tools/clang/test/CodeGenDXIL" "$DXC_ROOT/tools/clang/test/CodeGenSPIRV"
|
|
||||||
TMP=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
|
||||||
|
|
||||||
find "$@" -name '*.hlsl' | sort > "$TMP/files"
|
|
||||||
|
|
||||||
check_one() {
|
|
||||||
f=$1
|
|
||||||
run=$(grep -m1 'RUN:' "$f")
|
|
||||||
target=$(printf '%s' "$run" | grep -oE -- '-T *[a-z]+_6_[0-9]+' | head -1 | sed 's/-T *//')
|
|
||||||
[ -n "$target" ] || target=cs_6_0
|
|
||||||
defs=$(printf '%s' "$run" | grep -oE -- '-D *[A-Za-z_][A-Za-z0-9_]*(=[^ ]*)?' | sed 's/-D */-D/' | tr '\n' ' ')
|
|
||||||
extra=""
|
|
||||||
printf '%s' "$run" | grep -q -- '-spirv' && extra="$extra -spirv"
|
|
||||||
printf '%s' "$run" | grep -q -- '-enable-16bit-types' && extra="$extra -enable-16bit-types"
|
|
||||||
id=$(printf '%s' "$f" | cksum | cut -d' ' -f1)
|
|
||||||
out="$TMP/$id"
|
|
||||||
# dxc -P exits 0 even on fatal errors (e.g. a missing #include); treat any
|
|
||||||
# reported error as "dxc rejected".
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
"$DXC" -P -HV 2021 -T "$target" $extra $defs "$f" -Fi "$out.ref" >/dev/null 2>"$out.dxcerr" || { echo "SKIP $f"; return; }
|
|
||||||
grep -q 'error' "$out.dxcerr" && { echo "SKIP $f"; return; }
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
if ! "$ZDXC" -P -T "$target" $extra $defs "$f" -Fi "$out.zd" > "$out.err" 2>&1; then
|
|
||||||
echo "FAIL $f (zdxc error: $(head -1 "$out.err"))"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
"$ZDXC" -zdxc-lex "$out.ref" > "$out.ref.tok"
|
|
||||||
"$ZDXC" -zdxc-lex "$out.zd" > "$out.zd.tok"
|
|
||||||
if cmp -s "$out.ref.tok" "$out.zd.tok"; then
|
|
||||||
echo "PASS $f"
|
|
||||||
else
|
|
||||||
echo "FAIL $f (first diff: $(diff "$out.ref.tok" "$out.zd.tok" | grep -m2 '^[<>]' | tr '\n' ' '))"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
export -f check_one 2>/dev/null || true
|
|
||||||
export ZDXC DXC TMP
|
|
||||||
while read -r f; do check_one "$f"; done < "$TMP/files" > "$TMP/results"
|
|
||||||
|
|
||||||
grep '^FAIL' "$TMP/results" | head -${SHOW_FAILS:-30}
|
|
||||||
pass=$(grep -c '^PASS' "$TMP/results")
|
|
||||||
fail=$(grep -c '^FAIL' "$TMP/results")
|
|
||||||
skip=$(grep -c '^SKIP' "$TMP/results")
|
|
||||||
echo "oracle pp: $pass passed, $fail failed, $skip skipped (dxc rejected)"
|
|
||||||
[ "$fail" -eq 0 ]
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# Print the dxc/zdxc flags taken from the first RUN line of an HLSL test:
|
|
||||||
# -T, -E, -D, -spirv, -fspv-target-env and -enable-16bit-types. Exits 1 if
|
|
||||||
# there is no -T.
|
|
||||||
run=$(grep -m1 'RUN:' "$1")
|
|
||||||
target=$(printf '%s' "$run" | grep -oE -- '-T *[a-z]+_6_[0-9]+' | head -1 | sed 's/-T *//')
|
|
||||||
[ -n "$target" ] || exit 1
|
|
||||||
entry=$(printf '%s' "$run" | grep -oE -- '-E *[A-Za-z_][A-Za-z0-9_]*' | head -1 | sed 's/-E */-E /')
|
|
||||||
defs=$(printf '%s' "$run" | grep -oE -- '-D *[A-Za-z_][A-Za-z0-9_]*(=[^ ]*)?' | sed 's/-D */-D/' | tr '\n' ' ')
|
|
||||||
extra=""
|
|
||||||
printf '%s' "$run" | grep -q -- '-spirv' && extra="$extra -spirv"
|
|
||||||
printf '%s' "$run" | grep -q -- '-enable-16bit-types' && extra="$extra -enable-16bit-types"
|
|
||||||
env=$(printf '%s' "$run" | grep -oE -- '-fspv-target-env=[a-z0-9.]+' | head -1)
|
|
||||||
[ -n "$env" ] && extra="$extra $env"
|
|
||||||
echo "-T $target $entry $extra $defs"
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# Sema oracle (no false errors): every corpus file that dxc compiles under
|
|
||||||
# -HV 2021 must pass zdxc's semantic analysis without errors. Files whose
|
|
||||||
# only errors are "not supported yet" (milestone 0.2 features) are counted
|
|
||||||
# separately.
|
|
||||||
#
|
|
||||||
# Usage: test/oracle/sema.sh <path-to-zdxc> (run test/oracle/parse.sh first)
|
|
||||||
set -u
|
|
||||||
ZDXC=$(cd "$(dirname "$1")" && pwd)/$(basename "$1")
|
|
||||||
CACHE=zig-out/oracle/parse-valid.txt
|
|
||||||
[ -s "$CACHE" ] || { echo "run test/oracle/parse.sh first to build $CACHE"; exit 1; }
|
|
||||||
TMP=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
|
||||||
pass=0; later=0; fail=0
|
|
||||||
while read -r f; do
|
|
||||||
flags=$(sh test/oracle/run_flags.sh "$f") || continue
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
if "$ZDXC" -zdxc-sema -fno-color-diagnostics -no-warnings $flags "$f" > "$TMP/out" 2>&1; then
|
|
||||||
pass=$((pass + 1))
|
|
||||||
elif ! grep "error:" "$TMP/out" | grep -v "too many errors emitted" | grep -qv "not supported yet"; then
|
|
||||||
later=$((later + 1))
|
|
||||||
else
|
|
||||||
fail=$((fail + 1))
|
|
||||||
echo "$f" >> "$TMP/failed"
|
|
||||||
grep -m1 "error:" "$TMP/out" | sed -E 's/^.*error: //' >> "$TMP/errors"
|
|
||||||
fi
|
|
||||||
done < "$CACHE"
|
|
||||||
if [ "$fail" -gt 0 ]; then
|
|
||||||
echo "most common first errors:"
|
|
||||||
sed -E "s/'[^']*'/'X'/g; s/[0-9]+/N/g" "$TMP/errors" | sort | uniq -c | sort -rn | head -${SHOW:-25}
|
|
||||||
cp "$TMP/failed" zig-out/oracle/sema-failed.txt
|
|
||||||
fi
|
|
||||||
echo "oracle sema: $pass clean, $later need milestone 0.2 features, $fail false errors (of $(wc -l < "$CACHE" | tr -d ' ') dxc-valid files)"
|
|
||||||
[ "$fail" -eq 0 ]
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# First Sema error of each file listed in zig-out/oracle/sema-failed.txt.
|
|
||||||
while read -r f; do
|
|
||||||
flags=$(sh test/oracle/run_flags.sh "$f") || continue
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
"$1" -zdxc-sema -fno-color-diagnostics -no-warnings $flags "$f" 2>&1 | grep -m1 "error:" | sed -E "s#^[^ ]*: error: #$(basename "$f"): #"
|
|
||||||
done < zig-out/oracle/sema-failed.txt
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# Expected-diagnostics oracle: runs zdxc over dxc's SemaHLSL `-verify` tests
|
|
||||||
# (HLSL 2021 only) and compares the lines zdxc reports errors on with the
|
|
||||||
# lines the tests expect errors on.
|
|
||||||
#
|
|
||||||
# caught expected error lines zdxc also reports an error on
|
|
||||||
# missed expected error lines zdxc is silent on
|
|
||||||
# false lines zdxc reports an error on that expect none
|
|
||||||
#
|
|
||||||
# Files where zdxc reports a "not supported yet" (milestone 0.2) error are
|
|
||||||
# counted separately and left out of the line totals.
|
|
||||||
#
|
|
||||||
# Usage: test/oracle/verify.sh <path-to-zdxc> [corpus-dir]
|
|
||||||
# SHOW=N number of most common missed / false messages to print
|
|
||||||
set -u
|
|
||||||
ZDXC=$(cd "$(dirname "$1")" && pwd)/$(basename "$1")
|
|
||||||
CORPUS=${2:-../tools/clang/test/SemaHLSL}
|
|
||||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
|
||||||
OUT=zig-out/oracle
|
|
||||||
mkdir -p "$OUT"
|
|
||||||
TMP=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
|
||||||
: > "$TMP/missed"; : > "$TMP/false"; : > "$TMP/files"
|
|
||||||
files=0; exact=0; later=0; skipped=0; caught=0; missed=0; false=0
|
|
||||||
for f in $(grep -rl --include='*.hlsl' -e '-verify' "$CORPUS" | sort); do
|
|
||||||
run=$(grep -m1 'RUN:.*-verify' "$f" | sed -E 's#(^| )/([TED]) *#\1-\2 #g')
|
|
||||||
hv=$(printf '%s' "$run" | grep -oE -- '-HV *[0-9a-z]+' | sed 's/-HV *//')
|
|
||||||
target=$(printf '%s' "$run" | grep -oE -- '-T *[a-z]+_[0-9]+_[0-9]+' | head -1 | sed 's/-T *//')
|
|
||||||
if [ -n "$hv" ] && [ "$hv" != 2021 ] || [ -z "$target" ]; then
|
|
||||||
skipped=$((skipped + 1)); continue
|
|
||||||
fi
|
|
||||||
flags="-T $target"
|
|
||||||
flags="$flags $(printf '%s' "$run" | grep -oE -- '-E *[A-Za-z_][A-Za-z0-9_]*' | head -1 | sed 's/-E */-E /')"
|
|
||||||
flags="$flags $(printf '%s' "$run" | grep -oE -- '-D *[A-Za-z_][A-Za-z0-9_]*(=[^ ]*)?' | sed 's/-D */-D/' | tr '\n' ' ')"
|
|
||||||
flags="$flags $(printf '%s' "$run" | grep -oE -- ' -(spirv|enable-16bit-types|W[a-z0-9-]+)' | tr '\n' ' ')"
|
|
||||||
awk -f "$HERE/verify_expect.awk" "$f" > "$TMP/expect"
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
"$ZDXC" -zdxc-sema -fno-color-diagnostics -ferror-limit=0 $flags "$f" > "$TMP/out" 2>&1
|
|
||||||
files=$((files + 1))
|
|
||||||
if grep -q "error: .*not supported yet" "$TMP/out"; then
|
|
||||||
later=$((later + 1)); continue
|
|
||||||
fi
|
|
||||||
# Lines zdxc reports errors on, in this file only.
|
|
||||||
grep -F "$f:" "$TMP/out" | grep -E '^[^ ]+:[0-9]+:[0-9]+: (fatal )?error: ' |
|
|
||||||
sed -E "s#^[^ ]+:([0-9]+):[0-9]+: (fatal )?error: (.*)#\1 \3#" > "$TMP/got"
|
|
||||||
awk -v name="$(basename "$f")" -v missed="$TMP/missed" -v falsef="$TMP/false" '
|
|
||||||
FILENAME == ARGV[1] {
|
|
||||||
if ($1 == "error") { line = $2; $1 = ""; $2 = ""; sub(/^ +/, ""); if (!(line in want)) want[line] = $0 }
|
|
||||||
else warn[$2] = 1
|
|
||||||
next
|
|
||||||
}
|
|
||||||
{ line = $1; $1 = ""; sub(/^ +/, ""); if (!(line in got)) got[line] = $0 }
|
|
||||||
END {
|
|
||||||
c = m = x = 0
|
|
||||||
for (l in want) if (l in got) c++; else { m++; print name ":" l ": " want[l] >> missed }
|
|
||||||
for (l in got) if (!(l in want)) { x++; print name ":" l ": " got[l] (l in warn ? " [dxc: warning]" : "") >> falsef }
|
|
||||||
print c, m, x
|
|
||||||
}' "$TMP/expect" "$TMP/got" > "$TMP/counts"
|
|
||||||
read -r c m x < "$TMP/counts"
|
|
||||||
caught=$((caught + c)); missed=$((missed + m)); false=$((false + x))
|
|
||||||
[ "$m" -eq 0 ] && [ "$x" -eq 0 ] && exact=$((exact + 1))
|
|
||||||
echo "$m $x $f" >> "$TMP/files"
|
|
||||||
done
|
|
||||||
summarize() {
|
|
||||||
sed -E 's/^[^ ]+: //; s/'"'"'[^'"'"']*'"'"'/'"'"'X'"'"'/g; s/[0-9]+/N/g' "$1" | sort | uniq -c | sort -rn | head -"${SHOW:-15}"
|
|
||||||
}
|
|
||||||
echo "most common missed errors (expected by dxc, not reported):"; summarize "$TMP/missed"
|
|
||||||
echo "most common false errors (reported, not expected):"; summarize "$TMP/false"
|
|
||||||
cp "$TMP/missed" "$OUT/verify-missed.txt"
|
|
||||||
cp "$TMP/false" "$OUT/verify-false.txt"
|
|
||||||
sort -rn "$TMP/files" > "$OUT/verify-files.txt"
|
|
||||||
total=$((caught + missed))
|
|
||||||
pct=0; [ "$total" -gt 0 ] && pct=$((caught * 100 / total))
|
|
||||||
echo "oracle verify: $files files ($skipped other -HV skipped), $exact exact, $later need milestone 0.2"
|
|
||||||
echo " error lines: $caught/$total caught ($pct%), $missed missed, $false false"
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
# Print the diagnostics a clang `-verify` test expects in its own file, one
|
|
||||||
# per line: "<severity> <line> <message>". Handles `expected-error`,
|
|
||||||
# `expected-warning` (optionally `-re`), `@+N` / `@-N` / `@N` line offsets
|
|
||||||
# and repeat counts; markers aimed at other files (`@file:N`) and notes are
|
|
||||||
# skipped.
|
|
||||||
{
|
|
||||||
rest = $0
|
|
||||||
while (match(rest, /expected-(error|warning)(-re)?(@[^ {]*)?( +[0-9]+)? *\{\{/)) {
|
|
||||||
marker = substr(rest, RSTART, RLENGTH)
|
|
||||||
rest = substr(rest, RSTART + RLENGTH)
|
|
||||||
sev = (marker ~ /^expected-error/) ? "error" : "warning"
|
|
||||||
line = NR
|
|
||||||
if (match(marker, /@[^ {]*/)) {
|
|
||||||
off = substr(marker, RSTART + 1, RLENGTH - 1)
|
|
||||||
if (off ~ /^\+[0-9]+$/) line = NR + substr(off, 2)
|
|
||||||
else if (off ~ /^-[0-9]+$/) line = NR - substr(off, 2)
|
|
||||||
else if (off ~ /^[0-9]+$/) line = off + 0
|
|
||||||
else continue
|
|
||||||
}
|
|
||||||
msg = rest
|
|
||||||
end = index(msg, "}}")
|
|
||||||
if (end > 0) msg = substr(msg, 1, end - 1)
|
|
||||||
print sev, line, msg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
// PROFILE: as_6_5
|
|
||||||
// ENV: vulkan1.3
|
|
||||||
// Amplification shader: the groupshared payload becomes TaskPayloadWorkgroupEXT
|
|
||||||
// storage, DispatchMesh OpEmitMeshTasksEXT.
|
|
||||||
// ZCHECK: OpEntryPoint TaskEXT
|
|
||||||
// ZCHECK: %pl = OpVariable {{.*}} TaskPayloadWorkgroupEXT
|
|
||||||
// ZCHECK: OpEmitMeshTasksEXT
|
|
||||||
struct Payload { uint base; float scale[2]; uint ids[8]; };
|
|
||||||
groupshared Payload pl;
|
|
||||||
[numthreads(8,1,1)]
|
|
||||||
void main(uint tid : SV_GroupIndex) {
|
|
||||||
pl.ids[tid] = tid * 2;
|
|
||||||
if (tid == 0) { pl.base = 7; pl.scale[0] = 1; pl.scale[1] = 2; }
|
|
||||||
GroupMemoryBarrierWithGroupSync();
|
|
||||||
DispatchMesh(2, 1, 1, pl);
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Atomics on groupshared memory, buffers and texels.
|
|
||||||
// ZCHECK: OpAtomicIAdd %uint {{.*}} %uint_2 %uint_0 %uint_1
|
|
||||||
// ZCHECK: OpImageTexelPointer
|
|
||||||
// ZCHECK: OpAtomicCompareExchange
|
|
||||||
groupshared uint cnt;
|
|
||||||
groupshared int mx[4];
|
|
||||||
RWStructuredBuffer<uint> sb : register(u0);
|
|
||||||
RWBuffer<uint> tb : register(u1);
|
|
||||||
RWTexture2D<int> tex : register(u2);
|
|
||||||
RWByteAddressBuffer rb : register(u3);
|
|
||||||
[numthreads(64,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
uint old, o2; int o3;
|
|
||||||
InterlockedAdd(cnt, 1, old);
|
|
||||||
InterlockedMax(mx[i & 3], (int)i);
|
|
||||||
InterlockedCompareExchange(cnt, 5, 6, o2);
|
|
||||||
InterlockedOr(sb[i], 2);
|
|
||||||
InterlockedMin(tb[i], i, o2);
|
|
||||||
InterlockedExchange(tex[uint2(i, 1)], 3, o3);
|
|
||||||
InterlockedCompareStore(sb[0], 1, 2);
|
|
||||||
sb[1] = old + o2 + o3;
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Memory barriers (device, group, all; with and without group sync).
|
|
||||||
RWStructuredBuffer<uint4> o : register(u0);
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
AllMemoryBarrier(); AllMemoryBarrierWithGroupSync(); DeviceMemoryBarrier(); DeviceMemoryBarrierWithGroupSync(); GroupMemoryBarrier();
|
|
||||||
o[0] = uint4(firstbitlow(i), firstbithigh(i), firstbithigh((int)i), f32tof16(asfloat(i)));
|
|
||||||
o[1].x = asuint(f16tof32(i));
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
// PROFILE: cs_6_2
|
|
||||||
// Bitfields: SPIR-V starts a new storage word when the type changes (c is
|
|
||||||
// int, a and b uint), as dxc does.
|
|
||||||
// ZCHECK: OpTypeStruct %uint %uint %int %uint %uint %uint
|
|
||||||
// ZCHECK: OpShiftRightArithmetic %int
|
|
||||||
struct Base { uint lo : 4; uint hi : 4; };
|
|
||||||
struct P : Base {
|
|
||||||
uint a : 3; uint b : 5; int c : 4;
|
|
||||||
uint d;
|
|
||||||
uint e : 30; uint f : 4;
|
|
||||||
uint sum() { return a + b + lo + hi; }
|
|
||||||
void bump() { b += 1; hi++; }
|
|
||||||
};
|
|
||||||
cbuffer CB { P cp; };
|
|
||||||
RWStructuredBuffer<P> sb : register(u0);
|
|
||||||
RWStructuredBuffer<int> o : register(u1);
|
|
||||||
[numthreads(1,1,1)] void main() {
|
|
||||||
P p = sb[0];
|
|
||||||
p.b = 7;
|
|
||||||
p.c = -3;
|
|
||||||
p.bump();
|
|
||||||
sb[1] = p;
|
|
||||||
P q = {1, 2, 3, 4, -5, 6, 7, 8};
|
|
||||||
sb[2] = q;
|
|
||||||
sb[3].f |= 2;
|
|
||||||
o[0] = p.a + p.c + cp.e + cp.f + p.sum() + q.c;
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Structured buffers of matrices: whole loads and stores, rows (constant
|
|
||||||
// and dynamic) and row components.
|
|
||||||
// ZCHECK: OpMemberDecorate %type_StructuredBuffer_mat4v3float 0 MatrixStride 16
|
|
||||||
// ZCHECK: OpMemberDecorate %type_RWStructuredBuffer_mat2v3float 0 MatrixStride 8
|
|
||||||
StructuredBuffer<float4x3> m : register(t0);
|
|
||||||
RWStructuredBuffer<float2x3> r : register(u1);
|
|
||||||
RWStructuredBuffer<float4> o : register(u0);
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
o[i] = float4(m[i][1], 1) + r[i][0].x + float4(m[0][i % 4], m[1][2].y);
|
|
||||||
r[i] = r[i] * 2;
|
|
||||||
o[i + 1] = mul(float4(1, 2, 3, 4), m[i]).xyzz;
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Byte-address buffer loads, stores, atomics and sizes.
|
|
||||||
RWByteAddressBuffer rb : register(u0);
|
|
||||||
ByteAddressBuffer ro : register(t0);
|
|
||||||
RWStructuredBuffer<uint> c : register(u1);
|
|
||||||
AppendStructuredBuffer<float4> ap : register(u2);
|
|
||||||
ConsumeStructuredBuffer<float4> co : register(u3);
|
|
||||||
[numthreads(64,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
uint4 v = ro.Load4(i * 16) + rb.Load2(4).xyxy;
|
|
||||||
rb.Store3(i * 12, v.xyz);
|
|
||||||
uint old; rb.InterlockedAdd(0, 1, old);
|
|
||||||
rb.InterlockedCompareStore(8, 1, 2);
|
|
||||||
uint n = 0;
|
|
||||||
rb.Store(20, n + old);
|
|
||||||
uint w; rb.GetDimensions(w); rb.Store(16, w);
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
// PROFILE: cs_6_2
|
|
||||||
// FLAGS: -enable-16bit-types
|
|
||||||
// Templated byte-address Load/Store of structs, matrices (by column in
|
|
||||||
// SPIR-V), 16- and 64-bit components from 32-bit words.
|
|
||||||
struct S { float a; double b; uint16_t c; int2 d; };
|
|
||||||
RWByteAddressBuffer buf : register(u0);
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
S s = buf.Load<S>(i * 32);
|
|
||||||
float3x2 m = buf.Load<float3x2>(64);
|
|
||||||
half4 h = buf.Load<half4>(128);
|
|
||||||
S arr[2] = buf.Load<S[2]>(256);
|
|
||||||
s.a += m[1][0] + h.y + arr[1].d.x;
|
|
||||||
buf.Store<S>(i * 32 + 512, s);
|
|
||||||
buf.Store<float3x2>(96, m);
|
|
||||||
buf.Store<half4>(136, h);
|
|
||||||
buf.Store<double>(160, s.b);
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// ENV: vulkan1.3
|
|
||||||
// StorageBuffer + Block from SPIR-V 1.4.
|
|
||||||
// ZCHECK: OpVariable %_ptr_StorageBuffer
|
|
||||||
// Byte-address buffer loads, stores, atomics and sizes.
|
|
||||||
RWByteAddressBuffer rb : register(u0);
|
|
||||||
ByteAddressBuffer ro : register(t0);
|
|
||||||
RWStructuredBuffer<uint> c : register(u1);
|
|
||||||
AppendStructuredBuffer<float4> ap : register(u2);
|
|
||||||
ConsumeStructuredBuffer<float4> co : register(u3);
|
|
||||||
[numthreads(64,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
uint4 v = ro.Load4(i * 16) + rb.Load2(4).xyxy;
|
|
||||||
rb.Store3(i * 12, v.xyz);
|
|
||||||
uint old; rb.InterlockedAdd(0, 1, old);
|
|
||||||
rb.InterlockedCompareStore(8, 1, 2);
|
|
||||||
uint n = 0;
|
|
||||||
rb.Store(20, n + old);
|
|
||||||
uint w; rb.GetDimensions(w); rb.Store(16, w);
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# SPIR-V output checks beyond validation: every test/spirv/*.hlsl must pass
|
|
||||||
# spirv-val, and every `// ZCHECK: text` line must appear in zdxc's
|
|
||||||
# disassembly (`{{.*}}` matches anything), and descriptor bindings and
|
|
||||||
# interface locations must match dxc's.
|
|
||||||
#
|
|
||||||
# Usage: test/spirv/check.sh <path-to-zdxc>
|
|
||||||
set -u
|
|
||||||
ZDXC=$1
|
|
||||||
DXC_BUILD=${DXC_BUILD:-../build}
|
|
||||||
VAL=$DXC_BUILD/oracle-spirv-tools/tools/spirv-val
|
|
||||||
DIS=$DXC_BUILD/oracle-spirv-tools/tools/spirv-dis
|
|
||||||
DXC=$DXC_BUILD/bin/dxc
|
|
||||||
TMP=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
|
||||||
pass=0
|
|
||||||
fail=0
|
|
||||||
for f in test/spirv/*.hlsl; do
|
|
||||||
profile=$(sed -n 's|^// PROFILE: *||p' "$f")
|
|
||||||
flags=$(sed -n 's|^// FLAGS: *||p' "$f")
|
|
||||||
name=$(basename "$f" .hlsl)
|
|
||||||
env=$(sed -n "s|^// ENV: *||p" "$f"); if ! "$ZDXC" -spirv -T "$profile" $flags -fspv-target-env="${env:-vulkan1.0}" "$f" -Fo "$TMP/z.spv" > "$TMP/log" 2>&1; then
|
|
||||||
fail=$((fail + 1)); echo "FAIL $name: zdxc failed"; head -3 "$TMP/log"; continue
|
|
||||||
fi
|
|
||||||
if ! "$VAL" --target-env "$(printf '%s' "${env:-vulkan1.0}" | sed 's/spirv1/spv1/')" --relax-block-layout "$TMP/z.spv" > "$TMP/log" 2>&1; then
|
|
||||||
fail=$((fail + 1)); echo "FAIL $name: spirv-val rejected the output"; head -3 "$TMP/log"; continue
|
|
||||||
fi
|
|
||||||
"$DIS" "$TMP/z.spv" > "$TMP/z.dis" 2>&1
|
|
||||||
ok=1
|
|
||||||
# Bindings and locations must match dxc's (when dxc compiles the test).
|
|
||||||
if "$DXC" -spirv -T "$profile" $flags -fspv-target-env="${env:-vulkan1.0}" "$f" -Fo "$TMP/d.spv" > /dev/null 2>&1; then
|
|
||||||
"$DIS" "$TMP/d.spv" > "$TMP/d.dis" 2>&1
|
|
||||||
if ! python3 test/spirv/compare_bindings.py "$TMP/d.dis" "$TMP/z.dis" > "$TMP/bind" 2>&1; then
|
|
||||||
ok=0; echo "FAIL $name: bindings / locations differ from dxc"; head -5 "$TMP/bind"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
sed -n 's|^// ZCHECK: *||p' "$f" > "$TMP/checks"
|
|
||||||
while IFS= read -r pat; do
|
|
||||||
re=$(printf '%s\n' "$pat" | sed -e 's/[][\.*^$()+?|{}]/\\&/g' -e 's/\\{\\{\\\.\\\*\\}\\}/.*/g')
|
|
||||||
grep -Eq -- "$re" "$TMP/z.dis" || { ok=0; echo "FAIL $name: missing '$pat'"; }
|
|
||||||
done < "$TMP/checks"
|
|
||||||
if [ $ok = 1 ]; then pass=$((pass + 1)); else fail=$((fail + 1)); fi
|
|
||||||
done
|
|
||||||
echo "spirv checks: $pass passed, $fail failed"
|
|
||||||
[ "$fail" -eq 0 ]
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
"""Exits non-zero if the descriptor bindings and interface locations of two
|
|
||||||
SPIR-V disassemblies differ (variables present in both, keyed by name).
|
|
||||||
Usage: compare_bindings.py <expected.dis> <actual.dis>"""
|
|
||||||
import re, sys
|
|
||||||
def parse(path):
|
|
||||||
names = {}; decs = {}; sc = {}
|
|
||||||
for line in open(path):
|
|
||||||
m = re.match(r'\s*OpName (%\S+) "(.*)"', line)
|
|
||||||
if m: names[m.group(1)] = m.group(2); continue
|
|
||||||
m = re.match(r'\s*OpDecorate (%\S+) (DescriptorSet|Binding|Location|Component|Index|BuiltIn|InputAttachmentIndex|SpecId) (\S+)', line)
|
|
||||||
if m: decs.setdefault(m.group(1), {})[m.group(2)] = m.group(3); continue
|
|
||||||
m = re.match(r'\s*(%\S+) = OpVariable %\S+ (\S+)', line)
|
|
||||||
if m: sc[m.group(1)] = m.group(2)
|
|
||||||
out = {}
|
|
||||||
for v, s in sc.items():
|
|
||||||
if s in ('Function', 'Private', 'Workgroup'): continue
|
|
||||||
n = names.get(v, None)
|
|
||||||
if n is None:
|
|
||||||
bi = decs.get(v, {}).get('BuiltIn')
|
|
||||||
if not bi: continue
|
|
||||||
n = 'builtin.' + bi + '.' + s
|
|
||||||
pass
|
|
||||||
d = dict(decs.get(v, {})); d['sc'] = s
|
|
||||||
out.setdefault(n, []).append(tuple(sorted(d.items())))
|
|
||||||
return out
|
|
||||||
a = parse(sys.argv[1]); b = parse(sys.argv[2])
|
|
||||||
bad = []
|
|
||||||
for n in sorted(set(a) & set(b)):
|
|
||||||
if sorted(a.get(n, [])) != sorted(b.get(n, [])): bad.append('%s: dxc %s zdxc %s' % (n, a.get(n), b.get(n)))
|
|
||||||
print('\n'.join(bad))
|
|
||||||
sys.exit(1 if bad else 0)
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
// PROFILE: cs_6_6
|
|
||||||
// Implicit-LOD sampling and derivatives in a compute shader (SM 6.6).
|
|
||||||
// ZCHECK: OpExecutionMode %main DerivativeGroupQuadsKHR
|
|
||||||
Texture2D<float4> t : register(t0);
|
|
||||||
SamplerState s : register(s0);
|
|
||||||
RWStructuredBuffer<float4> o : register(u0);
|
|
||||||
[numthreads(8,8,1)] void main(uint2 id : SV_DispatchThreadID) { float2 uv = id / 64.0; o[id.x] = t.Sample(s, uv) + ddx(uv).x + t.CalculateLevelOfDetail(s, uv); }
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// ConstantBuffer<T>: members (bitfields too), arrays, whole-struct reads,
|
|
||||||
// ZCHECK: OpDecorate %type_ConstantBuffer_S Block
|
|
||||||
// passing elements of resource arrays to (nested) functions.
|
|
||||||
struct S { float4 a; float b; uint lo : 8; uint hi : 8; };
|
|
||||||
ConstantBuffer<S> cbs[4] : register(b0);
|
|
||||||
Texture2D<float4> texs[2] : register(t0);
|
|
||||||
SamplerState smp : register(s0);
|
|
||||||
RWStructuredBuffer<float4> o : register(u0);
|
|
||||||
float4 inner(ConstantBuffer<S> c, Texture2D<float4> t) { return c.a * t.SampleLevel(smp, float2(0,0), 0) + c.hi; }
|
|
||||||
float4 outer(ConstantBuffer<S> c, Texture2D<float4> t) { return inner(c, t) + c.lo; }
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_GroupIndex) { S s = cbs[2]; o[0] = outer(cbs[3], texs[1]) + outer(cbs[0], texs[0]) + cbs[i].a + s.b + s.lo; }
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// FLAGS: -E main
|
|
||||||
// ENV: vulkan1.3
|
|
||||||
// vk::khr::CooperativeMatrix (built on inline SPIR-V types and
|
|
||||||
// instructions): loads, arithmetic, length, multiply-add and stores.
|
|
||||||
// ZCHECK: OpCapability CooperativeMatrixKHR
|
|
||||||
// ZCHECK: OpExtension "SPV_KHR_cooperative_matrix"
|
|
||||||
// ZCHECK: OpMemoryModel Logical Vulkan
|
|
||||||
// ZCHECK: OpTypeCooperativeMatrixKHR %float %uint_3 %uint_16 %uint_4 %uint_0
|
|
||||||
// ZCHECK: OpCooperativeMatrixLoadKHR
|
|
||||||
// ZCHECK: OpCooperativeMatrixLengthKHR %uint
|
|
||||||
// ZCHECK: OpCooperativeMatrixMulAddKHR
|
|
||||||
// ZCHECK: OpCooperativeMatrixStoreKHR
|
|
||||||
#include <vk/khr/cooperative_matrix.h>
|
|
||||||
|
|
||||||
RWStructuredBuffer<float> data;
|
|
||||||
|
|
||||||
[numthreads(64, 1, 1)] void main() {
|
|
||||||
using MatA = vk::khr::CooperativeMatrixA<float, vk::ScopeSubgroup, 16, 4>;
|
|
||||||
using MatB = vk::khr::CooperativeMatrixB<float, vk::ScopeSubgroup, 4, 8>;
|
|
||||||
using MatC = vk::khr::CooperativeMatrixAccumulator<float, vk::ScopeSubgroup, 16, 8>;
|
|
||||||
MatA a = MatA::Load<vk::CooperativeMatrixLayoutRowMajorKHR>(data, 0, 4);
|
|
||||||
MatB b = MatB::Load<vk::CooperativeMatrixLayoutRowMajorKHR>(data, 64, 8);
|
|
||||||
MatC c = MatC::Splat(1.0);
|
|
||||||
a = a * 2.0 + a;
|
|
||||||
data[200] = a.GetLength();
|
|
||||||
c = cooperativeMatrixMultiplyAdd(a, b, c);
|
|
||||||
c.Store<vk::CooperativeMatrixLayoutRowMajorKHR>(data, 100, 8);
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
// PROFILE: cs_6_0
|
|
||||||
// Counters (separate counter buffers, as dxc) and Append/Consume.
|
|
||||||
// ZCHECK: %counter_var_c = OpVariable
|
|
||||||
// ZCHECK: OpAtomicISub %int
|
|
||||||
RWStructuredBuffer<uint> c : register(u1);
|
|
||||||
AppendStructuredBuffer<float4> ap : register(u2);
|
|
||||||
ConsumeStructuredBuffer<float4> co : register(u3);
|
|
||||||
[numthreads(1,1,1)] void main() { uint n = c.IncrementCounter(); ap.Append(co.Consume() + n); }
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
// PROFILE: cs_6_6
|
|
||||||
// Descriptor heaps (SM 6.6): resources and samplers taken from the heaps.
|
|
||||||
// ZCHECK: OpDecorate %ResourceDescriptorHeap Binding 1
|
|
||||||
// ZCHECK: OpDecorate %SamplerDescriptorHeap Binding 2
|
|
||||||
// ZCHECK: RuntimeDescriptorArray
|
|
||||||
struct S { float4 a; float b; };
|
|
||||||
RWStructuredBuffer<float4> o : register(u0);
|
|
||||||
[numthreads(1,1,1)] void main(uint i : SV_GroupIndex) {
|
|
||||||
ConstantBuffer<S> c = ResourceDescriptorHeap[i];
|
|
||||||
Texture2D<float4> t = ResourceDescriptorHeap[i + 1];
|
|
||||||
SamplerState s = SamplerDescriptorHeap[0];
|
|
||||||
RWStructuredBuffer<float4> b = ResourceDescriptorHeap[NonUniformResourceIndex(i + 2)];
|
|
||||||
o[0] = c.a + t.SampleLevel(s, float2(0,0), 0);
|
|
||||||
b[i] = c.b;
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
// PROFILE: ds_6_0
|
|
||||||
// Domain shader: TessCoord, tess levels and patch inputs; locations of
|
|
||||||
// control points and patch constants ordered by semantic, as dxc.
|
|
||||||
// ZCHECK: BuiltIn TessCoord
|
|
||||||
// ZCHECK: OpDecorate %in_var_EXTRA Location 0
|
|
||||||
// ZCHECK: OpDecorate %in_var_PATCHID Location 1
|
|
||||||
struct HSOut { float4 pos : POSITION; float2 uv : TEXCOORD0; };
|
|
||||||
struct PC {
|
|
||||||
float edges[4] : SV_TessFactor;
|
|
||||||
float inside[2] : SV_InsideTessFactor;
|
|
||||||
float3 extra : EXTRA;
|
|
||||||
uint id : PATCHID;
|
|
||||||
};
|
|
||||||
struct DSOut { float4 pos : SV_Position; float2 uv : TEXCOORD0; nointerpolation uint id : PATCHID; };
|
|
||||||
[domain("quad")]
|
|
||||||
DSOut main(PC pc, float2 uv : SV_DomainLocation, const OutputPatch<HSOut, 4> patch, uint prim : SV_PrimitiveID) {
|
|
||||||
DSOut o;
|
|
||||||
float4 a = lerp(patch[0].pos, patch[1].pos, uv.x);
|
|
||||||
float4 b = lerp(patch[3].pos, patch[2].pos, uv.x);
|
|
||||||
o.pos = lerp(a, b, uv.y) + float4(pc.extra, pc.inside[1]);
|
|
||||||
o.uv = patch[0].uv * pc.edges[3];
|
|
||||||
o.id = pc.id + prim;
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
// PROFILE: ps_6_0
|
|
||||||
// Gather with four offsets: four gathers (DXIL), ConstOffsets (SPIR-V).
|
|
||||||
// ZCHECK: ConstOffsets
|
|
||||||
Texture2D<float4> t : register(t0);
|
|
||||||
SamplerState s : register(s0);
|
|
||||||
float4 main(float2 uv : UV) : SV_Target { return t.GatherGreen(s, uv, int2(1,0), int2(0,1), int2(-1,0), int2(0,-1)); }
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
// PROFILE: gs_6_0
|
|
||||||
// Geometry shader: arrayed per-vertex inputs, emit and end primitive.
|
|
||||||
// ZCHECK: OpExecutionMode %main Invocations 2
|
|
||||||
// ZCHECK: OpExecutionMode %main OutputTriangleStrip
|
|
||||||
// ZCHECK: OpEmitVertex
|
|
||||||
// ZCHECK: OpEndPrimitive
|
|
||||||
// ZCHECK: BuiltIn InvocationId
|
|
||||||
struct VSOut { float4 pos : SV_Position; float2 uv : TEXCOORD0; };
|
|
||||||
struct GSOut { float4 pos : SV_Position; float2 uv : TEXCOORD0; uint layer : SV_RenderTargetArrayIndex; };
|
|
||||||
[maxvertexcount(6)] [instance(2)]
|
|
||||||
void main(triangle VSOut input[3], uint pid : SV_PrimitiveID, uint iid : SV_GSInstanceID, inout TriangleStream<GSOut> stream) {
|
|
||||||
for (int k = 0; k < 3; k++) { GSOut o; o.pos = input[k].pos; o.uv = input[k].uv + pid; o.layer = iid; stream.Append(o); }
|
|
||||||
stream.RestartStrip();
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue