From 05076bb91a009b7a840b0d145e06e466085c977c Mon Sep 17 00:00:00 2001 From: Peter Li Date: Sun, 1 Nov 2026 15:39:53 -0800 Subject: [PATCH] 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 --- .claude/skills/zig/SKILL.md | 26 --- bench/pp_bench.zig | 121 ---------- build.zig | 83 ------- build.zig.zon | 2 + docs/batch.md | 2 +- docs/libzdxc-api.md | 310 ------------------------- test/dxil/amplification.hlsl | 13 -- test/dxil/atomics.hlsl | 23 -- test/dxil/barriers.hlsl | 10 - test/dxil/bitfields.hlsl | 28 --- test/dxil/buffer_matrices.hlsl | 11 - test/dxil/byte_address.hlsl | 16 -- test/dxil/byte_address_templated.hlsl | 20 -- test/dxil/check.sh | 60 ----- test/dxil/compare_parts.py | 23 -- test/dxil/compute_derivatives.hlsl | 6 - test/dxil/constant_buffer.hlsl | 12 - test/dxil/counters.hlsl | 8 - test/dxil/descriptor_heap.hlsl | 14 -- test/dxil/domain.hlsl | 22 -- test/dxil/gather4.hlsl | 6 - test/dxil/geometry.hlsl | 13 -- test/dxil/groupshared.hlsl | 6 - test/dxil/hull.hlsl | 36 --- test/dxil/hull_isoline.hlsl | 12 - test/dxil/intrinsics_misc.hlsl | 18 -- test/dxil/lib_graphics.hlsl | 21 -- test/dxil/lib_mangling.hlsl | 24 -- test/dxil/lib_noinline.hlsl | 46 ---- test/dxil/linalg.hlsl | 41 ---- test/dxil/linalg_library.hlsl | 59 ----- test/dxil/long_vectors.hlsl | 37 --- test/dxil/math_intrinsics.hlsl | 12 - test/dxil/mesh.hlsl | 27 --- test/dxil/operators.hlsl | 16 -- test/dxil/out_intrinsics.hlsl | 12 - test/dxil/pack_matrix.hlsl | 19 -- test/dxil/pack_matrix_zpr.hlsl | 14 -- test/dxil/partial_stores.hlsl | 32 --- test/dxil/rayquery.hlsl | 39 ---- test/dxil/raytracing.hlsl | 66 ------ test/dxil/resource_array_params.hlsl | 14 -- test/dxil/resource_arrays.hlsl | 14 -- test/dxil/resource_out_params.hlsl | 18 -- test/dxil/resource_params.hlsl | 10 - test/dxil/resource_structs.hlsl | 26 --- test/dxil/root_signature.hlsl | 10 - test/dxil/rov.hlsl | 15 -- test/dxil/sig_no_inputs.hlsl | 2 - test/dxil/sig_order.hlsl | 5 - test/dxil/sig_ps_struct.hlsl | 5 - test/dxil/sig_ps_sv.hlsl | 4 - test/dxil/sig_target_array.hlsl | 15 -- test/dxil/sig_types.hlsl | 5 - test/dxil/sig_vs_struct.hlsl | 5 - test/dxil/static_init.hlsl | 8 - test/dxil/static_locals.hlsl | 5 - test/dxil/status.hlsl | 16 -- test/dxil/subobjects.hlsl | 14 -- test/dxil/sv_pixel.hlsl | 6 - test/dxil/sv_vertex.hlsl | 5 - test/dxil/switch.hlsl | 18 -- test/dxil/tbuffer.hlsl | 9 - test/dxil/templates.hlsl | 23 -- test/dxil/templates2.hlsl | 43 ---- test/dxil/textures.hlsl | 37 --- test/dxil/unroll.hlsl | 26 --- test/dxil/wave.hlsl | 14 -- test/job/check.sh | 59 ----- test/job/error.hlsl | 2 - test/oracle/cli.sh | 42 ---- test/oracle/codegen.sh | 64 ----- test/oracle/dxc_valid_one.sh | 6 - test/oracle/m0.sh | 50 ---- test/oracle/parse.sh | 50 ---- test/oracle/parse_errors.sh | 9 - test/oracle/pp.sh | 57 ----- test/oracle/run_flags.sh | 15 -- test/oracle/sema.sh | 34 --- test/oracle/sema_errors.sh | 7 - test/oracle/verify.sh | 75 ------ test/oracle/verify_expect.awk | 25 -- test/spirv/amplification.hlsl | 16 -- test/spirv/atomics.hlsl | 22 -- test/spirv/barriers.hlsl | 8 - test/spirv/bitfields.hlsl | 27 --- test/spirv/buffer_matrices.hlsl | 13 -- test/spirv/byte_address.hlsl | 16 -- test/spirv/byte_address_templated.hlsl | 17 -- test/spirv/byte_address_v13.hlsl | 19 -- test/spirv/check.sh | 45 ---- test/spirv/compare_bindings.py | 31 --- test/spirv/compute_derivatives.hlsl | 7 - test/spirv/constant_buffer.hlsl | 12 - test/spirv/coopmatrix.hlsl | 29 --- test/spirv/counters.hlsl | 8 - test/spirv/descriptor_heap.hlsl | 15 -- test/spirv/domain.hlsl | 24 -- test/spirv/gather4.hlsl | 6 - test/spirv/geometry.hlsl | 14 -- test/spirv/hull.hlsl | 38 --- test/spirv/inline_types.hlsl | 32 --- test/spirv/interpolation.hlsl | 23 -- test/spirv/intrinsics_misc.hlsl | 15 -- test/spirv/mesh.hlsl | 30 --- test/spirv/operators.hlsl | 16 -- test/spirv/out_intrinsics.hlsl | 13 -- test/spirv/pack_matrix.hlsl | 23 -- test/spirv/partial_stores.hlsl | 23 -- test/spirv/rayquery.hlsl | 45 ---- test/spirv/raytracing.hlsl | 77 ------ test/spirv/resource_array_params.hlsl | 15 -- test/spirv/resource_arrays.hlsl | 15 -- test/spirv/resource_out_params.hlsl | 19 -- test/spirv/resource_params.hlsl | 12 - test/spirv/resource_structs.hlsl | 16 -- test/spirv/resource_structs2.hlsl | 26 --- test/spirv/rov.hlsl | 21 -- test/spirv/sampled_texture.hlsl | 16 -- test/spirv/static_locals.hlsl | 5 - test/spirv/status.hlsl | 22 -- test/spirv/sv_pixel.hlsl | 8 - test/spirv/sv_vertex.hlsl | 7 - test/spirv/switch.hlsl | 19 -- test/spirv/swizzle_many.hlsl | 26 --- test/spirv/tbuffer.hlsl | 9 - test/spirv/templates.hlsl | 23 -- test/spirv/textures.hlsl | 45 ---- test/spirv/unroll.hlsl | 24 -- test/spirv/vk_bindings.hlsl | 41 ---- test/spirv/vk_ext.hlsl | 37 --- test/spirv/vk_memory_model.hlsl | 22 -- test/spirv/vk_options.hlsl | 30 --- test/spirv/wave.hlsl | 15 -- 134 files changed, 3 insertions(+), 3367 deletions(-) delete mode 100644 .claude/skills/zig/SKILL.md delete mode 100644 bench/pp_bench.zig delete mode 100644 docs/libzdxc-api.md delete mode 100644 test/dxil/amplification.hlsl delete mode 100644 test/dxil/atomics.hlsl delete mode 100644 test/dxil/barriers.hlsl delete mode 100644 test/dxil/bitfields.hlsl delete mode 100644 test/dxil/buffer_matrices.hlsl delete mode 100644 test/dxil/byte_address.hlsl delete mode 100644 test/dxil/byte_address_templated.hlsl delete mode 100644 test/dxil/check.sh delete mode 100644 test/dxil/compare_parts.py delete mode 100644 test/dxil/compute_derivatives.hlsl delete mode 100644 test/dxil/constant_buffer.hlsl delete mode 100644 test/dxil/counters.hlsl delete mode 100644 test/dxil/descriptor_heap.hlsl delete mode 100644 test/dxil/domain.hlsl delete mode 100644 test/dxil/gather4.hlsl delete mode 100644 test/dxil/geometry.hlsl delete mode 100644 test/dxil/groupshared.hlsl delete mode 100644 test/dxil/hull.hlsl delete mode 100644 test/dxil/hull_isoline.hlsl delete mode 100644 test/dxil/intrinsics_misc.hlsl delete mode 100644 test/dxil/lib_graphics.hlsl delete mode 100644 test/dxil/lib_mangling.hlsl delete mode 100644 test/dxil/lib_noinline.hlsl delete mode 100644 test/dxil/linalg.hlsl delete mode 100644 test/dxil/linalg_library.hlsl delete mode 100644 test/dxil/long_vectors.hlsl delete mode 100644 test/dxil/math_intrinsics.hlsl delete mode 100644 test/dxil/mesh.hlsl delete mode 100644 test/dxil/operators.hlsl delete mode 100644 test/dxil/out_intrinsics.hlsl delete mode 100644 test/dxil/pack_matrix.hlsl delete mode 100644 test/dxil/pack_matrix_zpr.hlsl delete mode 100644 test/dxil/partial_stores.hlsl delete mode 100644 test/dxil/rayquery.hlsl delete mode 100644 test/dxil/raytracing.hlsl delete mode 100644 test/dxil/resource_array_params.hlsl delete mode 100644 test/dxil/resource_arrays.hlsl delete mode 100644 test/dxil/resource_out_params.hlsl delete mode 100644 test/dxil/resource_params.hlsl delete mode 100644 test/dxil/resource_structs.hlsl delete mode 100644 test/dxil/root_signature.hlsl delete mode 100644 test/dxil/rov.hlsl delete mode 100644 test/dxil/sig_no_inputs.hlsl delete mode 100644 test/dxil/sig_order.hlsl delete mode 100644 test/dxil/sig_ps_struct.hlsl delete mode 100644 test/dxil/sig_ps_sv.hlsl delete mode 100644 test/dxil/sig_target_array.hlsl delete mode 100644 test/dxil/sig_types.hlsl delete mode 100644 test/dxil/sig_vs_struct.hlsl delete mode 100644 test/dxil/static_init.hlsl delete mode 100644 test/dxil/static_locals.hlsl delete mode 100644 test/dxil/status.hlsl delete mode 100644 test/dxil/subobjects.hlsl delete mode 100644 test/dxil/sv_pixel.hlsl delete mode 100644 test/dxil/sv_vertex.hlsl delete mode 100644 test/dxil/switch.hlsl delete mode 100644 test/dxil/tbuffer.hlsl delete mode 100644 test/dxil/templates.hlsl delete mode 100644 test/dxil/templates2.hlsl delete mode 100644 test/dxil/textures.hlsl delete mode 100644 test/dxil/unroll.hlsl delete mode 100644 test/dxil/wave.hlsl delete mode 100644 test/job/check.sh delete mode 100644 test/job/error.hlsl delete mode 100644 test/oracle/cli.sh delete mode 100644 test/oracle/codegen.sh delete mode 100644 test/oracle/dxc_valid_one.sh delete mode 100644 test/oracle/m0.sh delete mode 100644 test/oracle/parse.sh delete mode 100644 test/oracle/parse_errors.sh delete mode 100644 test/oracle/pp.sh delete mode 100644 test/oracle/run_flags.sh delete mode 100644 test/oracle/sema.sh delete mode 100644 test/oracle/sema_errors.sh delete mode 100644 test/oracle/verify.sh delete mode 100644 test/oracle/verify_expect.awk delete mode 100644 test/spirv/amplification.hlsl delete mode 100644 test/spirv/atomics.hlsl delete mode 100644 test/spirv/barriers.hlsl delete mode 100644 test/spirv/bitfields.hlsl delete mode 100644 test/spirv/buffer_matrices.hlsl delete mode 100644 test/spirv/byte_address.hlsl delete mode 100644 test/spirv/byte_address_templated.hlsl delete mode 100644 test/spirv/byte_address_v13.hlsl delete mode 100644 test/spirv/check.sh delete mode 100644 test/spirv/compare_bindings.py delete mode 100644 test/spirv/compute_derivatives.hlsl delete mode 100644 test/spirv/constant_buffer.hlsl delete mode 100644 test/spirv/coopmatrix.hlsl delete mode 100644 test/spirv/counters.hlsl delete mode 100644 test/spirv/descriptor_heap.hlsl delete mode 100644 test/spirv/domain.hlsl delete mode 100644 test/spirv/gather4.hlsl delete mode 100644 test/spirv/geometry.hlsl delete mode 100644 test/spirv/hull.hlsl delete mode 100644 test/spirv/inline_types.hlsl delete mode 100644 test/spirv/interpolation.hlsl delete mode 100644 test/spirv/intrinsics_misc.hlsl delete mode 100644 test/spirv/mesh.hlsl delete mode 100644 test/spirv/operators.hlsl delete mode 100644 test/spirv/out_intrinsics.hlsl delete mode 100644 test/spirv/pack_matrix.hlsl delete mode 100644 test/spirv/partial_stores.hlsl delete mode 100644 test/spirv/rayquery.hlsl delete mode 100644 test/spirv/raytracing.hlsl delete mode 100644 test/spirv/resource_array_params.hlsl delete mode 100644 test/spirv/resource_arrays.hlsl delete mode 100644 test/spirv/resource_out_params.hlsl delete mode 100644 test/spirv/resource_params.hlsl delete mode 100644 test/spirv/resource_structs.hlsl delete mode 100644 test/spirv/resource_structs2.hlsl delete mode 100644 test/spirv/rov.hlsl delete mode 100644 test/spirv/sampled_texture.hlsl delete mode 100644 test/spirv/static_locals.hlsl delete mode 100644 test/spirv/status.hlsl delete mode 100644 test/spirv/sv_pixel.hlsl delete mode 100644 test/spirv/sv_vertex.hlsl delete mode 100644 test/spirv/switch.hlsl delete mode 100644 test/spirv/swizzle_many.hlsl delete mode 100644 test/spirv/tbuffer.hlsl delete mode 100644 test/spirv/templates.hlsl delete mode 100644 test/spirv/textures.hlsl delete mode 100644 test/spirv/unroll.hlsl delete mode 100644 test/spirv/vk_bindings.hlsl delete mode 100644 test/spirv/vk_ext.hlsl delete mode 100644 test/spirv/vk_memory_model.hlsl delete mode 100644 test/spirv/vk_options.hlsl delete mode 100644 test/spirv/wave.hlsl diff --git a/.claude/skills/zig/SKILL.md b/.claude/skills/zig/SKILL.md deleted file mode 100644 index 3b01d0a..0000000 --- a/.claude/skills/zig/SKILL.md +++ /dev/null @@ -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 `/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 ; download a copy once and -avoid unnecessary traffic. diff --git a/bench/pp_bench.zig b/bench/pp_bench.zig deleted file mode 100644 index c925128..0000000 --- a/bench/pp_bench.zig +++ /dev/null @@ -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] -//! 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; -} diff --git a/build.zig b/build.zig index 09df55d..73d2843 100644 --- a/build.zig +++ b/build.zig @@ -65,87 +65,4 @@ pub fn build(b: *std.Build) void { test_step.dependOn(&b.addRunArtifact(mod_tests).step); const exe_tests = b.addTest(.{ .root_module = exe.root_module }); 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); } diff --git a/build.zig.zon b/build.zig.zon index b94b983..9ef2d76 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -8,7 +8,9 @@ .paths = .{ "build.zig", "build.zig.zon", + "docs", "src", + "tools", "vendor", }, } diff --git a/docs/batch.md b/docs/batch.md index cb69d51..cafda93 100644 --- a/docs/batch.md +++ b/docs/batch.md @@ -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 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 -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 failed: diff --git a/docs/libzdxc-api.md b/docs/libzdxc-api.md deleted file mode 100644 index f856811..0000000 --- a/docs/libzdxc-api.md +++ /dev/null @@ -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 `. - -## 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 `, `-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 `, `-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. diff --git a/test/dxil/amplification.hlsl b/test/dxil/amplification.hlsl deleted file mode 100644 index c982acb..0000000 --- a/test/dxil/amplification.hlsl +++ /dev/null @@ -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); -} diff --git a/test/dxil/atomics.hlsl b/test/dxil/atomics.hlsl deleted file mode 100644 index d2f30ad..0000000 --- a/test/dxil/atomics.hlsl +++ /dev/null @@ -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 sb : register(u0); -RWBuffer tb : register(u1); -RWTexture2D 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; -} diff --git a/test/dxil/barriers.hlsl b/test/dxil/barriers.hlsl deleted file mode 100644 index d7e4b9f..0000000 --- a/test/dxil/barriers.hlsl +++ /dev/null @@ -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 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)); -} diff --git a/test/dxil/bitfields.hlsl b/test/dxil/bitfields.hlsl deleted file mode 100644 index 00e8e67..0000000 --- a/test/dxil/bitfields.hlsl +++ /dev/null @@ -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

sb : register(u0); -RWStructuredBuffer 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; -} diff --git a/test/dxil/buffer_matrices.hlsl b/test/dxil/buffer_matrices.hlsl deleted file mode 100644 index 61b45b3..0000000 --- a/test/dxil/buffer_matrices.hlsl +++ /dev/null @@ -1,11 +0,0 @@ -// PROFILE: cs_6_0 -// Structured buffers of matrices: whole loads and stores, rows (constant -// and dynamic) and row components. -StructuredBuffer m : register(t0); -RWStructuredBuffer r : register(u1); -RWStructuredBuffer 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; -} diff --git a/test/dxil/byte_address.hlsl b/test/dxil/byte_address.hlsl deleted file mode 100644 index a089e8f..0000000 --- a/test/dxil/byte_address.hlsl +++ /dev/null @@ -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 c : register(u1); -AppendStructuredBuffer ap : register(u2); -ConsumeStructuredBuffer 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); -} diff --git a/test/dxil/byte_address_templated.hlsl b/test/dxil/byte_address_templated.hlsl deleted file mode 100644 index 374b502..0000000 --- a/test/dxil/byte_address_templated.hlsl +++ /dev/null @@ -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(i * 32); - float3x2 m = buf.Load(64); - half4 h = buf.Load(128); - S arr[2] = buf.Load(256); - s.a += m[1][0] + h.y + arr[1].d.x; - buf.Store(i * 32 + 512, s); - buf.Store(96, m); - buf.Store(136, h); - buf.Store(160, s.b); -} diff --git a/test/dxil/check.sh b/test/dxil/check.sh deleted file mode 100644 index 1bf9d21..0000000 --- a/test/dxil/check.sh +++ /dev/null @@ -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 -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 ] diff --git a/test/dxil/compare_parts.py b/test/dxil/compare_parts.py deleted file mode 100644 index f55735e..0000000 --- a/test/dxil/compare_parts.py +++ /dev/null @@ -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 """ -import struct -import sys - - -def part(path, fourcc): - data = open(path, 'rb').read() - count = struct.unpack_from(' t : register(t0); -SamplerState s : register(s0); -RWStructuredBuffer 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); } diff --git a/test/dxil/constant_buffer.hlsl b/test/dxil/constant_buffer.hlsl deleted file mode 100644 index 86418c3..0000000 --- a/test/dxil/constant_buffer.hlsl +++ /dev/null @@ -1,12 +0,0 @@ -// PROFILE: cs_6_0 -// ConstantBuffer: 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 cbs[4] : register(b0); -Texture2D texs[2] : register(t0); -SamplerState smp : register(s0); -RWStructuredBuffer o : register(u0); -float4 inner(ConstantBuffer c, Texture2D t) { return c.a * t.SampleLevel(smp, float2(0,0), 0) + c.hi; } -float4 outer(ConstantBuffer c, Texture2D 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; } diff --git a/test/dxil/counters.hlsl b/test/dxil/counters.hlsl deleted file mode 100644 index 2ed405c..0000000 --- a/test/dxil/counters.hlsl +++ /dev/null @@ -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 c : register(u1); -AppendStructuredBuffer ap : register(u2); -ConsumeStructuredBuffer co : register(u3); -[numthreads(1,1,1)] void main() { uint n = c.IncrementCounter(); ap.Append(co.Consume() + n); } diff --git a/test/dxil/descriptor_heap.hlsl b/test/dxil/descriptor_heap.hlsl deleted file mode 100644 index 49d61ce..0000000 --- a/test/dxil/descriptor_heap.hlsl +++ /dev/null @@ -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 o : register(u0); -[numthreads(1,1,1)] void main(uint i : SV_GroupIndex) { - ConstantBuffer c = ResourceDescriptorHeap[i]; - Texture2D t = ResourceDescriptorHeap[i + 1]; - SamplerState s = SamplerDescriptorHeap[0]; - RWStructuredBuffer b = ResourceDescriptorHeap[NonUniformResourceIndex(i + 2)]; - o[0] = c.a + t.SampleLevel(s, float2(0,0), 0); - b[i] = c.b; -} diff --git a/test/dxil/domain.hlsl b/test/dxil/domain.hlsl deleted file mode 100644 index 63d0bda..0000000 --- a/test/dxil/domain.hlsl +++ /dev/null @@ -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 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; -} diff --git a/test/dxil/gather4.hlsl b/test/dxil/gather4.hlsl deleted file mode 100644 index 96ced8e..0000000 --- a/test/dxil/gather4.hlsl +++ /dev/null @@ -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 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)); } diff --git a/test/dxil/geometry.hlsl b/test/dxil/geometry.hlsl deleted file mode 100644 index ffffccc..0000000 --- a/test/dxil/geometry.hlsl +++ /dev/null @@ -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 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(); -} diff --git a/test/dxil/groupshared.hlsl b/test/dxil/groupshared.hlsl deleted file mode 100644 index 2159a69..0000000 --- a/test/dxil/groupshared.hlsl +++ /dev/null @@ -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 o : register(u0); -[numthreads(64,1,1)] void main(uint i : SV_GroupIndex) { g[i] = i; GroupMemoryBarrierWithGroupSync(); o[i] = g[63 - i]; } diff --git a/test/dxil/hull.hlsl b/test/dxil/hull.hlsl deleted file mode 100644 index 66cda28..0000000 --- a/test/dxil/hull.hlsl +++ /dev/null @@ -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 ip, const OutputPatch 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 ip, uint id : SV_OutputControlPointID) { - HSOut o; - o.pos = ip[id].pos * 2; - o.uv = ip[id].uv; - return o; -} diff --git a/test/dxil/hull_isoline.hlsl b/test/dxil/hull_isoline.hlsl deleted file mode 100644 index 2a16351..0000000 --- a/test/dxil/hull_isoline.hlsl +++ /dev/null @@ -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 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 ip, uint id : SV_OutputControlPointID) { CP c; c.p = float3(id, 0, 1); return c; } diff --git a/test/dxil/intrinsics_misc.hlsl b/test/dxil/intrinsics_misc.hlsl deleted file mode 100644 index 7b4ec6a..0000000 --- a/test/dxil/intrinsics_misc.hlsl +++ /dev/null @@ -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 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(); -} diff --git a/test/dxil/lib_graphics.hlsl b/test/dxil/lib_graphics.hlsl deleted file mode 100644 index f107485..0000000 --- a/test/dxil/lib_graphics.hlsl +++ /dev/null @@ -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 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 ip, uint id : SV_OutputControlPointID) { return ip[id]; } -[shader("domain")] [domain("tri")] -float4 ds(PC pc, float3 uvw : SV_DomainLocation, const OutputPatch 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 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); } diff --git a/test/dxil/lib_mangling.hlsl b/test/dxil/lib_mangling.hlsl deleted file mode 100644 index 3331540..0000000 --- a/test/dxil/lib_mangling.hlsl +++ /dev/null @@ -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 struct Box { T v[N]; }; - class C { float c; }; - struct Outer { struct Nested { int n; }; enum E { E0, E1 }; }; - template struct TO { struct In { T t; }; using Elem = T; }; -} } -template 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 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 b) { return i.n + b.v[1].a; } -export float f6(inout ns::inner::P p, ns::inner::Box b) { return 1; } -export float f7(ns::inner::TO::In i, ns::inner::TO::Elem e, ns::inner::TO::In p) { return i.t + e + p.t.a; } diff --git a/test/dxil/lib_noinline.hlsl b/test/dxil/lib_noinline.hlsl deleted file mode 100644 index 41c1177..0000000 --- a/test/dxil/lib_noinline.hlsl +++ /dev/null @@ -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 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); -} diff --git a/test/dxil/linalg.hlsl b/test/dxil/linalg.hlsl deleted file mode 100644 index 61c3339..0000000 --- a/test/dxil/linalg.hlsl +++ /dev/null @@ -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 -using namespace dx::linalg; - -using MatA = Matrix; -using MatB = Matrix; -using Acc = Matrix; -using ThreadA = Matrix; - -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); -} diff --git a/test/dxil/linalg_library.hlsl b/test/dxil/linalg_library.hlsl deleted file mode 100644 index 0365dc6..0000000 --- a/test/dxil/linalg_library.hlsl +++ /dev/null @@ -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 -using namespace dx::linalg; - -using WaveA = Matrix; -using WaveB = Matrix; -using WaveAcc = Matrix; -using GroupA = Matrix; -using GroupB = Matrix; -using GroupAcc = Matrix; - -RWByteAddressBuffer Output : register(u0); - -void WaveWork(float f, int i) { - WaveA A = WaveA::Splat(f); - WaveB B = WaveB::Splat(i); - WaveAcc C = Multiply(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(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 M = - OuterProduct(v, v); - M.InterlockedAccumulate(Output, 128); - InterlockedAccumulate(Output, 256, v); -} - -[shader("compute")] -[numthreads(1, 1, 1)] -void NoLinAlg() { Output.Store(0, 1u); } diff --git a/test/dxil/long_vectors.hlsl b/test/dxil/long_vectors.hlsl deleted file mode 100644 index d9f2f05..0000000 --- a/test/dxil/long_vectors.hlsl +++ /dev/null @@ -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 h; }; -RWStructuredBuffer > sb : register(u0); -RWStructuredBuffer ss : register(u1); -RWByteAddressBuffer bab : register(u2); -groupshared vector gs[64]; - -vector scaleBy(vector v, float k) { return v * k; } - -[numthreads(64, 1, 1)] void main(uint i : SV_GroupIndex) { - vector a = sb[i]; - vector b = bab.Load >(32 * i); - vector c = sin(a) * b + 1.0; - c[i % 8] = dot(a, b); - vector 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 d = vector(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(i, i + 1, i + 2, i + 3, i + 4); - GroupMemoryBarrierWithGroupSync(); - vector g = gs[63 - i]; - bab.Store >(4096 + 20 * i, countbits(g) + firstbithigh(g) + (g & 3)); -} diff --git a/test/dxil/math_intrinsics.hlsl b/test/dxil/math_intrinsics.hlsl deleted file mode 100644 index b0f34d1..0000000 --- a/test/dxil/math_intrinsics.hlsl +++ /dev/null @@ -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)); -} diff --git a/test/dxil/mesh.hlsl b/test/dxil/mesh.hlsl deleted file mode 100644 index 8f43377..0000000 --- a/test/dxil/mesh.hlsl +++ /dev/null @@ -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; - } -} diff --git a/test/dxil/operators.hlsl b/test/dxil/operators.hlsl deleted file mode 100644 index 6e28ed5..0000000 --- a/test/dxil/operators.hlsl +++ /dev/null @@ -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 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); -} diff --git a/test/dxil/out_intrinsics.hlsl b/test/dxil/out_intrinsics.hlsl deleted file mode 100644 index ca0de43..0000000 --- a/test/dxil/out_intrinsics.hlsl +++ /dev/null @@ -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; -} diff --git a/test/dxil/pack_matrix.hlsl b/test/dxil/pack_matrix.hlsl deleted file mode 100644 index 4160844..0000000 --- a/test/dxil/pack_matrix.hlsl +++ /dev/null @@ -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 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; -} diff --git a/test/dxil/pack_matrix_zpr.hlsl b/test/dxil/pack_matrix_zpr.hlsl deleted file mode 100644 index ca77d47..0000000 --- a/test/dxil/pack_matrix_zpr.hlsl +++ /dev/null @@ -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 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; -} diff --git a/test/dxil/partial_stores.hlsl b/test/dxil/partial_stores.hlsl deleted file mode 100644 index 3fc6a94..0000000 --- a/test/dxil/partial_stores.hlsl +++ /dev/null @@ -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 B; -RWStructuredBuffer 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)); -} diff --git a/test/dxil/rayquery.hlsl b/test/dxil/rayquery.hlsl deleted file mode 100644 index d211ad1..0000000 --- a/test/dxil/rayquery.hlsl +++ /dev/null @@ -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 output : register(u0); - -void start(RayQuery 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 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; -} diff --git a/test/dxil/raytracing.hlsl b/test/dxil/raytracing.hlsl deleted file mode 100644 index b48cd6b..0000000 --- a/test/dxil/raytracing.hlsl +++ /dev/null @@ -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 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; -} diff --git a/test/dxil/resource_array_params.hlsl b/test/dxil/resource_array_params.hlsl deleted file mode 100644 index 52532e0..0000000 --- a/test/dxil/resource_array_params.hlsl +++ /dev/null @@ -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 texs[4] : register(t0); -Texture2D more[2] : register(t4); -SamplerState samps[2] : register(s0); -RWStructuredBuffer o : register(u0); -float4 sum(Texture2D 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 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); -} diff --git a/test/dxil/resource_arrays.hlsl b/test/dxil/resource_arrays.hlsl deleted file mode 100644 index e11e5fd..0000000 --- a/test/dxil/resource_arrays.hlsl +++ /dev/null @@ -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 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]; -} diff --git a/test/dxil/resource_out_params.hlsl b/test/dxil/resource_out_params.hlsl deleted file mode 100644 index d0cc542..0000000 --- a/test/dxil/resource_out_params.hlsl +++ /dev/null @@ -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 texA : register(t0); -Texture2D texB : register(t1); -SamplerState samp : register(s0); -RWStructuredBuffer o : register(u0); -void getResources(out Texture2D t, out SamplerState s) { t = texB; s = samp; } -float4 useAndKeep(inout Texture2D t, SamplerState s) { return t.SampleLevel(s, 0.5, 0); } -[numthreads(1,1,1)] void main(uint i : SV_DispatchThreadID) { - Texture2D t; - SamplerState s; - getResources(t, s); - Texture2D a = texA; - o[i] = t.Load(int3(0,0,0)) + useAndKeep(a, s) + useAndKeep(texA, s); -} diff --git a/test/dxil/resource_params.hlsl b/test/dxil/resource_params.hlsl deleted file mode 100644 index c4a537f..0000000 --- a/test/dxil/resource_params.hlsl +++ /dev/null @@ -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 t0 : register(t0); -Texture2D t1 : register(t1); -SamplerState s : register(s0); -StructuredBuffer b0 : register(t2); -float4 tap(Texture2D t, SamplerState ss, float2 uv) { return t.Sample(ss, uv); } -float rd(StructuredBuffer b, uint i) { return b[i]; } -float4 main(float2 uv : UV) : SV_Target { Texture2D loc = t1; return tap(t0, s, uv) + tap(loc, s, uv * 2) + rd(b0, 3); } diff --git a/test/dxil/resource_structs.hlsl b/test/dxil/resource_structs.hlsl deleted file mode 100644 index 9199ad0..0000000 --- a/test/dxil/resource_structs.hlsl +++ /dev/null @@ -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 albedo; SamplerState samp; float scale; }; -struct Pair { Material a; Material b; }; -Texture2D texA : register(t3); -Texture2D texB : register(t4); -SamplerState sampA : register(s1); -struct Globals { float a; Texture2D t; float b; RWBuffer out_buf; }; -Globals g; -RWStructuredBuffer o : register(u0); -float4 shade(Material m, float2 uv) { return m.albedo.SampleLevel(m.samp, uv, 0) * m.scale; } -Material make(Texture2D t, float k) { Material m; m.albedo = t; m.samp = sampA; m.scale = k; return m; } -Texture2D 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; -} diff --git a/test/dxil/root_signature.hlsl b/test/dxil/root_signature.hlsl deleted file mode 100644 index 9abea0e..0000000 --- a/test/dxil/root_signature.hlsl +++ /dev/null @@ -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; } diff --git a/test/dxil/rov.hlsl b/test/dxil/rov.hlsl deleted file mode 100644 index e2143d0..0000000 --- a/test/dxil/rov.hlsl +++ /dev/null @@ -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 rov : register(u1); - -float4 main(float4 p : SV_Position) : SV_Target { - rov[uint2(p.xy)] += buffer1.Load(0); - return rov[uint2(p.xy)]; -} diff --git a/test/dxil/sig_no_inputs.hlsl b/test/dxil/sig_no_inputs.hlsl deleted file mode 100644 index a0efefc..0000000 --- a/test/dxil/sig_no_inputs.hlsl +++ /dev/null @@ -1,2 +0,0 @@ -// PROFILE: vs_6_0 -float4 main() : SV_Position { return 1; } diff --git a/test/dxil/sig_order.hlsl b/test/dxil/sig_order.hlsl deleted file mode 100644 index cea212a..0000000 --- a/test/dxil/sig_order.hlsl +++ /dev/null @@ -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; } diff --git a/test/dxil/sig_ps_struct.hlsl b/test/dxil/sig_ps_struct.hlsl deleted file mode 100644 index 43f168c..0000000 --- a/test/dxil/sig_ps_struct.hlsl +++ /dev/null @@ -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)); } diff --git a/test/dxil/sig_ps_sv.hlsl b/test/dxil/sig_ps_sv.hlsl deleted file mode 100644 index 7ac4352..0000000 --- a/test/dxil/sig_ps_sv.hlsl +++ /dev/null @@ -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; } diff --git a/test/dxil/sig_target_array.hlsl b/test/dxil/sig_target_array.hlsl deleted file mode 100644 index 05fbee2..0000000 --- a/test/dxil/sig_target_array.hlsl +++ /dev/null @@ -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; -} diff --git a/test/dxil/sig_types.hlsl b/test/dxil/sig_types.hlsl deleted file mode 100644 index 9e12939..0000000 --- a/test/dxil/sig_types.hlsl +++ /dev/null @@ -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; } diff --git a/test/dxil/sig_vs_struct.hlsl b/test/dxil/sig_vs_struct.hlsl deleted file mode 100644 index a55702e..0000000 --- a/test/dxil/sig_vs_struct.hlsl +++ /dev/null @@ -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; } diff --git a/test/dxil/static_init.hlsl b/test/dxil/static_init.hlsl deleted file mode 100644 index 2493981..0000000 --- a/test/dxil/static_init.hlsl +++ /dev/null @@ -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); } diff --git a/test/dxil/static_locals.hlsl b/test/dxil/static_locals.hlsl deleted file mode 100644 index d4e334d..0000000 --- a/test/dxil/static_locals.hlsl +++ /dev/null @@ -1,5 +0,0 @@ -// PROFILE: cs_6_0 -// Static locals: private globals initialized on entry. -RWStructuredBuffer 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]; } diff --git a/test/dxil/status.hlsl b/test/dxil/status.hlsl deleted file mode 100644 index bcdf462..0000000 --- a/test/dxil/status.hlsl +++ /dev/null @@ -1,16 +0,0 @@ -// PROFILE: ps_6_0 -// Status arguments (sparse feedback) and CheckAccessFullyMapped. -// ZCHECK: checkAccessFullyMapped.i32(i32 71 -Texture2D t : register(t0); -Buffer 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); -} diff --git a/test/dxil/subobjects.hlsl b/test/dxil/subobjects.hlsl deleted file mode 100644 index 47896c7..0000000 --- a/test/dxil/subobjects.hlsl +++ /dev/null @@ -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; } diff --git a/test/dxil/sv_pixel.hlsl b/test/dxil/sv_pixel.hlsl deleted file mode 100644 index 1fceef2..0000000 --- a/test/dxil/sv_pixel.hlsl +++ /dev/null @@ -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; } diff --git a/test/dxil/sv_vertex.hlsl b/test/dxil/sv_vertex.hlsl deleted file mode 100644 index 79228b1..0000000 --- a/test/dxil/sv_vertex.hlsl +++ /dev/null @@ -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; } diff --git a/test/dxil/switch.hlsl b/test/dxil/switch.hlsl deleted file mode 100644 index 22f1dce..0000000 --- a/test/dxil/switch.hlsl +++ /dev/null @@ -1,18 +0,0 @@ -// PROFILE: cs_6_0 -// switch: fallthrough, default, break, continue to the enclosing loop. -// ZCHECK: switch i32 {{.*}}, label -RWStructuredBuffer 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; -} diff --git a/test/dxil/tbuffer.hlsl b/test/dxil/tbuffer.hlsl deleted file mode 100644 index 492db22..0000000 --- a/test/dxil/tbuffer.hlsl +++ /dev/null @@ -1,9 +0,0 @@ -// PROFILE: cs_6_0 -// tbuffer blocks and TextureBuffer: 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 tbs : register(t1); -RWStructuredBuffer o : register(u0); -[numthreads(1,1,1)] void main() { o[0] = x * y + s.a + tbs.a * tbs.b + float4(tbs.c, 1); } diff --git a/test/dxil/templates.hlsl b/test/dxil/templates.hlsl deleted file mode 100644 index a844d2b..0000000 --- a/test/dxil/templates.hlsl +++ /dev/null @@ -1,23 +0,0 @@ -// PROFILE: cs_6_0 -// Templates (function, class, variable; deduction, defaults, specializations) and methods. -template T square(T x) { return x * x; } -template vector scale(vector v, T k) { return v * k; } -template struct Pair { T a; T b; T sum() { return a + b; } }; -template struct Arr { T v[N]; T get(uint i) { return v[i]; } }; -template T first(Pair p) { return p.a; } -RWStructuredBuffer o : register(u0); -[numthreads(1,1,1)] void main(uint i : SV_DispatchThreadID) { - Pair p; p.a = 1; p.b = 2; - Arr 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(2); -} -template static const bool is_same_v = false; -template static const bool is_same_v = true; -template struct Box { T v; }; -template<> struct Box { 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 bi; bi.extra = 2; Derived dv; dv.b = 3; - o[i] = is_same_v + is_same_v + bi.extra + dv.twice(); -} diff --git a/test/dxil/templates2.hlsl b/test/dxil/templates2.hlsl deleted file mode 100644 index 290aa38..0000000 --- a/test/dxil/templates2.hlsl +++ /dev/null @@ -1,43 +0,0 @@ -// PROFILE: cs_6_0 -// More templates: `S::member`, partial specialization through -// matrix, 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 struct enable_if {}; -template struct enable_if { using type = T; }; - -template struct traits; -template struct traits > { - static const uint Count = N * K; -}; - -namespace ns { -template struct Vec { - T v[N]; - Vec scaled(T k); - template Vec Shifted() { Vec r; r.v = v; r.v[0] += L; return r; } - template static Vec Make(T x) { Vec r; for (int i = 0; i < N; i++) r.v[i] = x * L; return r; } -}; -template Vec Vec::scaled(T k) { - Vec r; for (int i = 0; i < N; i++) r.v[i] = v[i] * k; return r; -} -template using Vec2 = Vec; -template T head(Vec2 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 enable_if<(sizeof(T) == 4), T>::type pick(T x) { return x; } -template typename enable_if<(sizeof(T) == 8), T>::type pick(T x) { return x * 2; } - -RWStructuredBuffer o : register(u0); -[numthreads(1,1,1)] void main(uint i : SV_DispatchThreadID) { - S s; s.a = 3; - ns::Vec2 v = ns::Vec2::Make<3>(2); - ns::Vec g = v.scaled(2).Shifted<1>(); - o[i] = traits::Count + s.get(2) + S::twice(1) + head(v) + g.v[0] + pick(1.0f); -} diff --git a/test/dxil/textures.hlsl b/test/dxil/textures.hlsl deleted file mode 100644 index 059305d..0000000 --- a/test/dxil/textures.hlsl +++ /dev/null @@ -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 t2 : register(t0); -Texture2DArray t2a : register(t1); -TextureCube tc : register(t2); -Texture2DMS tms : register(t3); -Texture3D t3 : register(t4); -Buffer buf : register(t5); -RWTexture2D 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; -} diff --git a/test/dxil/unroll.hlsl b/test/dxil/unroll.hlsl deleted file mode 100644 index b122157..0000000 --- a/test/dxil/unroll.hlsl +++ /dev/null @@ -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; -} diff --git a/test/dxil/wave.hlsl b/test/dxil/wave.hlsl deleted file mode 100644 index 2b3fee7..0000000 --- a/test/dxil/wave.hlsl +++ /dev/null @@ -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 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; -} diff --git a/test/job/check.sh b/test/job/check.sh deleted file mode 100644 index 3961088..0000000 --- a/test/job/check.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/sh -# --job= 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 -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 ] diff --git a/test/job/error.hlsl b/test/job/error.hlsl deleted file mode 100644 index 503b12a..0000000 --- a/test/job/error.hlsl +++ /dev/null @@ -1,2 +0,0 @@ -// A compile error, for test/job/check.sh. -[numthreads(1, 1, 1)] void main() { undeclared = 1; } diff --git a/test/oracle/cli.sh b/test/oracle/cli.sh deleted file mode 100644 index 96d3ff0..0000000 --- a/test/oracle/cli.sh +++ /dev/null @@ -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 -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 ] diff --git a/test/oracle/codegen.sh b/test/oracle/codegen.sh deleted file mode 100644 index 10422f5..0000000 --- a/test/oracle/codegen.sh +++ /dev/null @@ -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 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 ] diff --git a/test/oracle/dxc_valid_one.sh b/test/oracle/dxc_valid_one.sh deleted file mode 100644 index d7c34a4..0000000 --- a/test/oracle/dxc_valid_one.sh +++ /dev/null @@ -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 diff --git a/test/oracle/m0.sh b/test/oracle/m0.sh deleted file mode 100644 index a786757..0000000 --- a/test/oracle/m0.sh +++ /dev/null @@ -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 -# Oracles default to the DXC build next to this repo; override with -# DXC_BUILD=

(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 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 ] diff --git a/test/oracle/parse.sh b/test/oracle/parse.sh deleted file mode 100644 index db1a082..0000000 --- a/test/oracle/parse.sh +++ /dev/null @@ -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 -# 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 ] diff --git a/test/oracle/parse_errors.sh b/test/oracle/parse_errors.sh deleted file mode 100644 index c9b2027..0000000 --- a/test/oracle/parse_errors.sh +++ /dev/null @@ -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 -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 diff --git a/test/oracle/pp.sh b/test/oracle/pp.sh deleted file mode 100644 index 1a3c6f1..0000000 --- a/test/oracle/pp.sh +++ /dev/null @@ -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 [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 ] diff --git a/test/oracle/run_flags.sh b/test/oracle/run_flags.sh deleted file mode 100644 index 000c371..0000000 --- a/test/oracle/run_flags.sh +++ /dev/null @@ -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" diff --git a/test/oracle/sema.sh b/test/oracle/sema.sh deleted file mode 100644 index bf68f94..0000000 --- a/test/oracle/sema.sh +++ /dev/null @@ -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 (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 ] diff --git a/test/oracle/sema_errors.sh b/test/oracle/sema_errors.sh deleted file mode 100644 index e287322..0000000 --- a/test/oracle/sema_errors.sh +++ /dev/null @@ -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 diff --git a/test/oracle/verify.sh b/test/oracle/verify.sh deleted file mode 100644 index e77471c..0000000 --- a/test/oracle/verify.sh +++ /dev/null @@ -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 [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" diff --git a/test/oracle/verify_expect.awk b/test/oracle/verify_expect.awk deleted file mode 100644 index 9a7216c..0000000 --- a/test/oracle/verify_expect.awk +++ /dev/null @@ -1,25 +0,0 @@ -# Print the diagnostics a clang `-verify` test expects in its own file, one -# per line: " ". 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 - } -} diff --git a/test/spirv/amplification.hlsl b/test/spirv/amplification.hlsl deleted file mode 100644 index b588426..0000000 --- a/test/spirv/amplification.hlsl +++ /dev/null @@ -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); -} diff --git a/test/spirv/atomics.hlsl b/test/spirv/atomics.hlsl deleted file mode 100644 index 092f05b..0000000 --- a/test/spirv/atomics.hlsl +++ /dev/null @@ -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 sb : register(u0); -RWBuffer tb : register(u1); -RWTexture2D 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; -} diff --git a/test/spirv/barriers.hlsl b/test/spirv/barriers.hlsl deleted file mode 100644 index ab1e8b3..0000000 --- a/test/spirv/barriers.hlsl +++ /dev/null @@ -1,8 +0,0 @@ -// PROFILE: cs_6_0 -// Memory barriers (device, group, all; with and without group sync). -RWStructuredBuffer 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)); -} diff --git a/test/spirv/bitfields.hlsl b/test/spirv/bitfields.hlsl deleted file mode 100644 index e9598c5..0000000 --- a/test/spirv/bitfields.hlsl +++ /dev/null @@ -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

sb : register(u0); -RWStructuredBuffer 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; -} diff --git a/test/spirv/buffer_matrices.hlsl b/test/spirv/buffer_matrices.hlsl deleted file mode 100644 index df045a3..0000000 --- a/test/spirv/buffer_matrices.hlsl +++ /dev/null @@ -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 m : register(t0); -RWStructuredBuffer r : register(u1); -RWStructuredBuffer 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; -} diff --git a/test/spirv/byte_address.hlsl b/test/spirv/byte_address.hlsl deleted file mode 100644 index a089e8f..0000000 --- a/test/spirv/byte_address.hlsl +++ /dev/null @@ -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 c : register(u1); -AppendStructuredBuffer ap : register(u2); -ConsumeStructuredBuffer 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); -} diff --git a/test/spirv/byte_address_templated.hlsl b/test/spirv/byte_address_templated.hlsl deleted file mode 100644 index 80d0777..0000000 --- a/test/spirv/byte_address_templated.hlsl +++ /dev/null @@ -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(i * 32); - float3x2 m = buf.Load(64); - half4 h = buf.Load(128); - S arr[2] = buf.Load(256); - s.a += m[1][0] + h.y + arr[1].d.x; - buf.Store(i * 32 + 512, s); - buf.Store(96, m); - buf.Store(136, h); - buf.Store(160, s.b); -} diff --git a/test/spirv/byte_address_v13.hlsl b/test/spirv/byte_address_v13.hlsl deleted file mode 100644 index 724087a..0000000 --- a/test/spirv/byte_address_v13.hlsl +++ /dev/null @@ -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 c : register(u1); -AppendStructuredBuffer ap : register(u2); -ConsumeStructuredBuffer 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); -} diff --git a/test/spirv/check.sh b/test/spirv/check.sh deleted file mode 100644 index 8156305..0000000 --- a/test/spirv/check.sh +++ /dev/null @@ -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 -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 ] diff --git a/test/spirv/compare_bindings.py b/test/spirv/compare_bindings.py deleted file mode 100644 index ceec848..0000000 --- a/test/spirv/compare_bindings.py +++ /dev/null @@ -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 """ -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) diff --git a/test/spirv/compute_derivatives.hlsl b/test/spirv/compute_derivatives.hlsl deleted file mode 100644 index d1d14ea..0000000 --- a/test/spirv/compute_derivatives.hlsl +++ /dev/null @@ -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 t : register(t0); -SamplerState s : register(s0); -RWStructuredBuffer 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); } diff --git a/test/spirv/constant_buffer.hlsl b/test/spirv/constant_buffer.hlsl deleted file mode 100644 index df7d817..0000000 --- a/test/spirv/constant_buffer.hlsl +++ /dev/null @@ -1,12 +0,0 @@ -// PROFILE: cs_6_0 -// ConstantBuffer: 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 cbs[4] : register(b0); -Texture2D texs[2] : register(t0); -SamplerState smp : register(s0); -RWStructuredBuffer o : register(u0); -float4 inner(ConstantBuffer c, Texture2D t) { return c.a * t.SampleLevel(smp, float2(0,0), 0) + c.hi; } -float4 outer(ConstantBuffer c, Texture2D 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; } diff --git a/test/spirv/coopmatrix.hlsl b/test/spirv/coopmatrix.hlsl deleted file mode 100644 index 19295fc..0000000 --- a/test/spirv/coopmatrix.hlsl +++ /dev/null @@ -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 - -RWStructuredBuffer data; - -[numthreads(64, 1, 1)] void main() { - using MatA = vk::khr::CooperativeMatrixA; - using MatB = vk::khr::CooperativeMatrixB; - using MatC = vk::khr::CooperativeMatrixAccumulator; - MatA a = MatA::Load(data, 0, 4); - MatB b = MatB::Load(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(data, 100, 8); -} diff --git a/test/spirv/counters.hlsl b/test/spirv/counters.hlsl deleted file mode 100644 index edf1be0..0000000 --- a/test/spirv/counters.hlsl +++ /dev/null @@ -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 c : register(u1); -AppendStructuredBuffer ap : register(u2); -ConsumeStructuredBuffer co : register(u3); -[numthreads(1,1,1)] void main() { uint n = c.IncrementCounter(); ap.Append(co.Consume() + n); } diff --git a/test/spirv/descriptor_heap.hlsl b/test/spirv/descriptor_heap.hlsl deleted file mode 100644 index f70e134..0000000 --- a/test/spirv/descriptor_heap.hlsl +++ /dev/null @@ -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 o : register(u0); -[numthreads(1,1,1)] void main(uint i : SV_GroupIndex) { - ConstantBuffer c = ResourceDescriptorHeap[i]; - Texture2D t = ResourceDescriptorHeap[i + 1]; - SamplerState s = SamplerDescriptorHeap[0]; - RWStructuredBuffer b = ResourceDescriptorHeap[NonUniformResourceIndex(i + 2)]; - o[0] = c.a + t.SampleLevel(s, float2(0,0), 0); - b[i] = c.b; -} diff --git a/test/spirv/domain.hlsl b/test/spirv/domain.hlsl deleted file mode 100644 index c351525..0000000 --- a/test/spirv/domain.hlsl +++ /dev/null @@ -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 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; -} diff --git a/test/spirv/gather4.hlsl b/test/spirv/gather4.hlsl deleted file mode 100644 index b799b05..0000000 --- a/test/spirv/gather4.hlsl +++ /dev/null @@ -1,6 +0,0 @@ -// PROFILE: ps_6_0 -// Gather with four offsets: four gathers (DXIL), ConstOffsets (SPIR-V). -// ZCHECK: ConstOffsets -Texture2D 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)); } diff --git a/test/spirv/geometry.hlsl b/test/spirv/geometry.hlsl deleted file mode 100644 index c64a588..0000000 --- a/test/spirv/geometry.hlsl +++ /dev/null @@ -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 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(); -} diff --git a/test/spirv/hull.hlsl b/test/spirv/hull.hlsl deleted file mode 100644 index 6ba7ef1..0000000 --- a/test/spirv/hull.hlsl +++ /dev/null @@ -1,38 +0,0 @@ -// PROFILE: hs_6_0 -// Hull shader: control points in arrays indexed by InvocationId, the patch -// constant function called once after a barrier, tess levels as builtins. -// ZCHECK: OpExecutionMode %main SpacingFractionalEven -// ZCHECK: OpExecutionMode %main VertexOrderCcw -// ZCHECK: OpControlBarrier %uint_2 %uint_4 %uint_0 -// ZCHECK: BuiltIn TessLevelOuter -// ZCHECK: OpDecorate %out_var_EXTRA Location 0 -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 ip, const OutputPatch 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 ip, uint id : SV_OutputControlPointID) { - HSOut o; - o.pos = ip[id].pos * 2; - o.uv = ip[id].uv; - return o; -} diff --git a/test/spirv/inline_types.hlsl b/test/spirv/inline_types.hlsl deleted file mode 100644 index 0fe7e19..0000000 --- a/test/spirv/inline_types.hlsl +++ /dev/null @@ -1,32 +0,0 @@ -// PROFILE: cs_6_0 -// FLAGS: -E main -// ENV: vulkan1.3 -// Inline SPIR-V types: vk::SpirvType (sized, in a buffer layout) and -// vk::SpirvOpaqueType with type, constant and literal operands; -// capabilities on an alias; vk::WorkgroupSpirvPointer passed to a -// function (zdxc keeps the call, so it needs variable pointers). -// ZCHECK: OpCapability Int8 -// ZCHECK: OpCapability VariablePointers -// ZCHECK: %spirvIntrinsicType = OpTypeInt 8 0 -// ZCHECK: %spirvIntrinsicType_0 = OpTypeArray %{{.*}} %uint_4 -// ZCHECK: OpCopyObject %_ptr_Workgroup_int -#include - -using uint8_t [[vk::ext_capability(/* Int8 */ 39)]] = vk::SpirvType >, vk::Literal > >; -typedef vk::SpirvOpaqueType > ArrayTex2D; - -RWStructuredBuffer data; -groupshared int shared_data[64]; - -[[vk::ext_instruction(/* OpLoad */ 61)]] int Load(vk::WorkgroupSpirvPointer p); - -int read(vk::WorkgroupSpirvPointer p) { return Load(p); } - -[numthreads(64, 1, 1)] void main(uint i : SV_GroupIndex) { - uint8_t bytes[4]; - ArrayTex2D images; - shared_data[i] = (int)i; - GroupMemoryBarrierWithGroupSync(); - vk::WorkgroupSpirvPointer p = vk::GetGroupSharedAddress(shared_data[63 - i]); - data[i] = read(p); -} diff --git a/test/spirv/interpolation.hlsl b/test/spirv/interpolation.hlsl deleted file mode 100644 index 87c4997..0000000 --- a/test/spirv/interpolation.hlsl +++ /dev/null @@ -1,23 +0,0 @@ -// PROFILE: vs_6_0 -// Interpolation modifiers become decorations on vertex outputs (as dxc); -// integers and bools are always flat. -// ZCHECK: OpCapability SampleRateShading -// ZCHECK: OpDecorate %out_var_FPC{{.*}} Centroid -// ZCHECK: OpDecorate %out_var_FPD{{.*}} Flat -// ZCHECK: OpDecorate %out_var_FPE{{.*}} NoPerspective -// ZCHECK: OpDecorate %out_var_FPF{{.*}} Sample -// ZCHECK: OpDecorate %out_var_INTA{{.*}} Flat -// ZCHECK: OpDecorate %out_var_BOOLA{{.*}} Flat -// ZCHECK: OpDecorate %out_var_FPH{{.*}} Flat -struct VSOutput { - float4 pos : SV_Position; - float fp_a : FPA; - centroid float2 fp_c : FPC; - nointerpolation float3 fp_d : FPD; - noperspective float4 fp_e : FPE; - sample float fp_f : FPF; - int int_a : INTA; - bool bool_a : BOOLA; - nointerpolation float4 fp_h[1] : FPH; -}; -VSOutput main() { VSOutput o = (VSOutput)0; return o; } diff --git a/test/spirv/intrinsics_misc.hlsl b/test/spirv/intrinsics_misc.hlsl deleted file mode 100644 index 9535e5c..0000000 --- a/test/spirv/intrinsics_misc.hlsl +++ /dev/null @@ -1,15 +0,0 @@ -// PROFILE: ps_6_6 -// Intrinsics: firstbit*, f32tof16/f16tof32, and/or/select, isnan & co., -// fmod, integer dot, any/all, fine derivatives, clip, IsHelperLane. -RWStructuredBuffer 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(); -} diff --git a/test/spirv/mesh.hlsl b/test/spirv/mesh.hlsl deleted file mode 100644 index b2a2983..0000000 --- a/test/spirv/mesh.hlsl +++ /dev/null @@ -1,30 +0,0 @@ -// PROFILE: ms_6_5 -// ENV: vulkan1.3 -// Mesh shader (SPV_EXT_mesh_shader): per-attribute output arrays, -// triangle indices, per-primitive outputs, the task payload. -// ZCHECK: OpEntryPoint MeshEXT -// ZCHECK: OpSetMeshOutputsEXT -// ZCHECK: BuiltIn PrimitiveTriangleIndicesEXT -// ZCHECK: PerPrimitiveEXT -// ZCHECK: BuiltIn CullPrimitiveEXT -// ZCHECK: TaskPayloadWorkgroupEXT -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; - } -} diff --git a/test/spirv/operators.hlsl b/test/spirv/operators.hlsl deleted file mode 100644 index 6e28ed5..0000000 --- a/test/spirv/operators.hlsl +++ /dev/null @@ -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 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); -} diff --git a/test/spirv/out_intrinsics.hlsl b/test/spirv/out_intrinsics.hlsl deleted file mode 100644 index 6735a89..0000000 --- a/test/spirv/out_intrinsics.hlsl +++ /dev/null @@ -1,13 +0,0 @@ -// PROFILE: ps_6_0 -// Intrinsics with out parameters. -// ZCHECK: FrexpStruct -// ZCHECK: ModfStruct -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; -} -float2x3 mats(float2x3 m) { float2x3 s, c; sincos(m, s, c); float2x3 ip; return modf(m, ip) + s + c + ip; } diff --git a/test/spirv/pack_matrix.hlsl b/test/spirv/pack_matrix.hlsl deleted file mode 100644 index 0b01fc6..0000000 --- a/test/spirv/pack_matrix.hlsl +++ /dev/null @@ -1,23 +0,0 @@ -// PROFILE: cs_6_0 -// FLAGS: -Zpr -// Matrix orientation in SPIR-V layouts: -Zpr makes matrices row_major -// (SPIR-V ColMajor, as HLSL rows are SPIR-V columns) unless written -// column_major or under #pragma pack_matrix(column_major). Unlike DXIL, -// a structured buffer's element takes its orientation from the template -// argument. -// ZCHECK: OpMemberDecorate %type_C 0 ColMajor -// ZCHECK: OpMemberDecorate %type_C 1 RowMajor -// ZCHECK: OpMemberDecorate %type_C 2 RowMajor -// ZCHECK: OpMemberDecorate %type_StructuredBuffer_mat2v3float 0 ColMajor -// ZCHECK: OpMemberDecorate %type_StructuredBuffer_mat2v3float_0 0 RowMajor -cbuffer C { - float2x3 a; - column_major float2x3 b; -#pragma pack_matrix(column_major) - float2x3 c; -}; -#pragma pack_matrix(row_major) -StructuredBuffer A; -StructuredBuffer B; -RWStructuredBuffer O; -[numthreads(1, 1, 1)] void main() { O[0] = a._m12 + b._m12 + c._m12 + A[0]._m12 + B[0]._m12; } diff --git a/test/spirv/partial_stores.hlsl b/test/spirv/partial_stores.hlsl deleted file mode 100644 index 7f6a423..0000000 --- a/test/spirv/partial_stores.hlsl +++ /dev/null @@ -1,23 +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. Arrays with -// the same element and stride are one type (StructuredBuffer and -// RWStructuredBuffer of float2x3 share their runtime array, as in dxc). -// ZCHECK: OpAccessChain %_ptr_Workgroup_float {{.*}} %uint_3 -// ZCHECK: OpStore {{.*}} %float_10 -// ZCHECK: OpAccessChain %_ptr_Uniform_float {{.*}} %uint_2 -// ZCHECK: OpStore {{.*}} %float_3 -// ZCHECK: %type_StructuredBuffer_mat2v3float = OpTypeStruct %_runtimearr_mat2v3float -// ZCHECK: %type_RWStructuredBuffer_mat2v3float = OpTypeStruct %_runtimearr_mat2v3float -struct S { float4 v; float2x3 m; }; -RWStructuredBuffer B; -StructuredBuffer M; -RWStructuredBuffer W; -groupshared float4 G[4]; -[numthreads(4, 1, 1)] void main(uint i : SV_GroupIndex) { - G[i].wy = 10; - B[i].m._m02 = 3; - W[i] = M[i]; - GroupMemoryBarrierWithGroupSync(); - B[i].v.x = G[(i + 1) % 4].y; -} diff --git a/test/spirv/rayquery.hlsl b/test/spirv/rayquery.hlsl deleted file mode 100644 index ec80088..0000000 --- a/test/spirv/rayquery.hlsl +++ /dev/null @@ -1,45 +0,0 @@ -// PROFILE: cs_6_5 -// ENV: vulkan1.2 -// FLAGS: -E main -// RayQuery: a function-storage query object, its type flags joined to the -// TraceRayInline flags, passed to functions by pointer. -// ZCHECK: OpCapability RayQueryKHR -// ZCHECK: OpExtension "SPV_KHR_ray_query" -// ZCHECK: OpTypeRayQueryKHR -// ZCHECK: OpBitwiseOr %uint {{.*}} %uint_1 -// ZCHECK: OpRayQueryInitializeKHR -// ZCHECK: OpRayQueryProceedKHR -// ZCHECK: OpRayQueryGetIntersectionTypeKHR %uint {{.*}} %uint_0 -// ZCHECK: OpRayQueryConfirmIntersectionKHR -// ZCHECK: OpRayQueryGenerateIntersectionKHR -// ZCHECK: OpRayQueryGetIntersectionTypeKHR %uint {{.*}} %uint_1 -// ZCHECK: OpRayQueryGetIntersectionBarycentricsKHR %v2float {{.*}} %uint_1 -// ZCHECK: OpRayQueryGetIntersectionObjectToWorldKHR %mat4v3float -// ZCHECK: OpRayQueryTerminateKHR -RaytracingAccelerationStructure scene : register(t0); -RWStructuredBuffer output : register(u0); - -void start(RayQuery 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 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; -} diff --git a/test/spirv/raytracing.hlsl b/test/spirv/raytracing.hlsl deleted file mode 100644 index 0124d16..0000000 --- a/test/spirv/raytracing.hlsl +++ /dev/null @@ -1,77 +0,0 @@ -// PROFILE: lib_6_3 -// ENV: vulkan1.2 -// Ray tracing shaders in one library: each entry gets its own interface -// (one incoming payload / hit attribute variable each), TraceRay and -// CallShader go through located payload / callable data variables. -// ZCHECK: OpCapability RayTracingKHR -// ZCHECK: OpExtension "SPV_KHR_ray_tracing" -// ZCHECK: OpEntryPoint RayGenerationKHR %rgen "rgen" -// ZCHECK: OpEntryPoint ClosestHitKHR %chit "chit" -// ZCHECK: OpEntryPoint MissKHR %miss "miss" -// ZCHECK: OpEntryPoint AnyHitKHR %ahit "ahit" -// ZCHECK: OpEntryPoint IntersectionKHR %isect "isect" -// ZCHECK: OpEntryPoint CallableKHR %call "call" -// ZCHECK: OpDecorate %ray_payload Location 0 -// ZCHECK: OpDecorate {{.*}} BuiltIn LaunchIdKHR -// ZCHECK: OpDecorate {{.*}} BuiltIn ObjectToWorldKHR -// ZCHECK: OpTypeAccelerationStructureKHR -// ZCHECK: OpTraceRayKHR -// ZCHECK: OpExecuteCallableKHR -// ZCHECK: OpReportIntersectionKHR -// ZCHECK: OpIgnoreIntersectionKHR -// ZCHECK: OpTerminateRayKHR -// ZCHECK: OpTranspose %mat3v4float -struct Payload { float4 color; uint depth; }; -struct Attr { float2 bary; }; -struct CallData { float3 v; }; - -RaytracingAccelerationStructure scene : register(t0); -RWTexture2D 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; -} diff --git a/test/spirv/resource_array_params.hlsl b/test/spirv/resource_array_params.hlsl deleted file mode 100644 index 91cc5ce..0000000 --- a/test/spirv/resource_array_params.hlsl +++ /dev/null @@ -1,15 +0,0 @@ -// PROFILE: cs_6_0 -// FLAGS: -E main -// Arrays of resources passed to functions (whole arrays, indexed -// constantly and dynamically inside), and an element passed alone. -// ZCHECK: OpAccessChain %_ptr_UniformConstant_{{.*}} %texs -// ZCHECK: OpAccessChain %_ptr_UniformConstant_{{.*}} %more -Texture2D texs[4] : register(t0); -Texture2D more[2] : register(t4); -SamplerState samps[2] : register(s0); -RWStructuredBuffer o : register(u0); -float4 sum(Texture2D 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 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); -} diff --git a/test/spirv/resource_arrays.hlsl b/test/spirv/resource_arrays.hlsl deleted file mode 100644 index e21fa61..0000000 --- a/test/spirv/resource_arrays.hlsl +++ /dev/null @@ -1,15 +0,0 @@ -// PROFILE: ps_6_0 -// Resource arrays: array-typed variables, access chains, NonUniform as dxc. -// ZCHECK: OpCapability SampledImageArrayNonUniformIndexing -// ZCHECK: OpExtension "SPV_EXT_descriptor_indexing" -// ZCHECK: OpTypeArray {{.*}} %uint_4 -// ZCHECK: OpAccessChain %_ptr_Uniform_float {{.*}} %int_0 %uint_3 -// ZCHECK: NonUniform -Texture2D ts[4] : register(t1); -SamplerState ss[2] : register(s0); -RWStructuredBuffer 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]; -} diff --git a/test/spirv/resource_out_params.hlsl b/test/spirv/resource_out_params.hlsl deleted file mode 100644 index 0f6bd63..0000000 --- a/test/spirv/resource_out_params.hlsl +++ /dev/null @@ -1,19 +0,0 @@ -// PROFILE: cs_6_0 -// FLAGS: -E main -// out / inout resources: a function handing resources back through out -// parameters, and inout resources passed through unchanged. -// ZCHECK: OpImageFetch %v4float -// ZCHECK: OpImageSampleExplicitLod -Texture2D texA : register(t0); -Texture2D texB : register(t1); -SamplerState samp : register(s0); -RWStructuredBuffer o : register(u0); -void getResources(out Texture2D t, out SamplerState s) { t = texB; s = samp; } -float4 useAndKeep(inout Texture2D t, SamplerState s) { return t.SampleLevel(s, 0.5, 0); } -[numthreads(1,1,1)] void main(uint i : SV_DispatchThreadID) { - Texture2D t; - SamplerState s; - getResources(t, s); - Texture2D a = texA; - o[i] = t.Load(int3(0,0,0)) + useAndKeep(a, s) + useAndKeep(texA, s); -} diff --git a/test/spirv/resource_params.hlsl b/test/spirv/resource_params.hlsl deleted file mode 100644 index 5a837e8..0000000 --- a/test/spirv/resource_params.hlsl +++ /dev/null @@ -1,12 +0,0 @@ -// PROFILE: ps_6_0 -// Resources passed to functions and held in locals: one function copy per -// distinct set of resource arguments (buffers cannot be passed by pointer). -// ZCHECK: %tap_0 = OpFunction -// ZCHECK: OpFunctionCall %float %rd %uint_3 -Texture2D t0 : register(t0); -Texture2D t1 : register(t1); -SamplerState s : register(s0); -StructuredBuffer b0 : register(t2); -float4 tap(Texture2D t, SamplerState ss, float2 uv) { return t.Sample(ss, uv); } -float rd(StructuredBuffer b, uint i) { return b[i]; } -float4 main(float2 uv : UV) : SV_Target { Texture2D loc = t1; return tap(t0, s, uv) + tap(loc, s, uv * 2) + rd(b0, 3); } diff --git a/test/spirv/resource_structs.hlsl b/test/spirv/resource_structs.hlsl deleted file mode 100644 index e260e15..0000000 --- a/test/spirv/resource_structs.hlsl +++ /dev/null @@ -1,16 +0,0 @@ -// PROFILE: ps_6_6 -// FLAGS: -E main -// A global struct of resources: one variable per resource, numbered as -// dxc does (array elements then take a binding each). -// ZCHECK: OpName %TheStruct_Texture "TheStruct.Texture" -// ZCHECK: OpDecorate %TheStruct_Texture Binding 10 -// ZCHECK: OpDecorate %TheStruct_Sampler Binding 11 -Texture2D Textures[10]; -struct StructOfResources { - Texture2D Texture; - SamplerState Sampler; -}; -StructOfResources TheStruct; -float4 main() : SV_Target { - return Textures[0].Sample(TheStruct.Sampler, float2(0, 0)) + TheStruct.Texture.Sample(TheStruct.Sampler, float2(0, 0)); -} diff --git a/test/spirv/resource_structs2.hlsl b/test/spirv/resource_structs2.hlsl deleted file mode 100644 index d6e9662..0000000 --- a/test/spirv/resource_structs2.hlsl +++ /dev/null @@ -1,26 +0,0 @@ -// PROFILE: cs_6_0 -// FLAGS: -E main -// Resources in structs in SPIR-V: locals, copies, nested structs, arrays, -// functions taking (specialized per resource) and returning them, and an -// array of global structs of resources (one variable per element). -// ZCHECK: OpName %globals_1__t "globals[1].t" -// ZCHECK: OpImageSampleExplicitLod -// ZCHECK: OpImageFetch -struct Material { Texture2D albedo; SamplerState samp; float scale; }; -struct Pair { Material a; Material b; }; -Texture2D texA : register(t3); -Texture2D texB : register(t4); -SamplerState sampA : register(s1); -struct TS { Texture2D t; SamplerState s; }; -TS globals[2]; -RWStructuredBuffer o : register(u0); -float4 shade(Material m, float2 uv) { return m.albedo.SampleLevel(m.samp, uv, 0) * m.scale; } -Material make(Texture2D t, float k) { Material m; m.albedo = t; m.samp = sampA; m.scale = k; return m; } -Texture2D 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)) + globals[1].t.SampleLevel(globals[0].s, 0.5, 0); -} diff --git a/test/spirv/rov.hlsl b/test/spirv/rov.hlsl deleted file mode 100644 index 8a1f03d..0000000 --- a/test/spirv/rov.hlsl +++ /dev/null @@ -1,21 +0,0 @@ -// PROFILE: ps_6_0 -// FLAGS: -E main -fspv-use-legacy-buffer-matrix-order -// Rasterizer-ordered views: one fragment interlock critical section -// around the shader; globallycoherent resources are Coherent; legacy -// (row-major) byte-address buffer matrices. -// ZCHECK: OpCapability FragmentShaderPixelInterlockEXT -// ZCHECK: OpExtension "SPV_EXT_fragment_shader_interlock" -// ZCHECK: OpExecutionMode %main PixelInterlockOrderedEXT -// ZCHECK: OpDecorate %buffer1 Coherent -// ZCHECK: OpBeginInvocationInterlockEXT -// ZCHECK: OpEndInvocationInterlockEXT -// ZCHECK: OpIAdd %uint {{.*}} %uint_12 -globallycoherent RWByteAddressBuffer buffer1 : register(u0); -RasterizerOrderedTexture2D rov : register(u1); -ByteAddressBuffer mats : register(t0); - -float4 main(float4 p : SV_Position) : SV_Target { - float2x3 m = mats.Load(0); - rov[uint2(p.xy)] += float4(m[1], buffer1.Load(0)); - return rov[uint2(p.xy)]; -} diff --git a/test/spirv/sampled_texture.hlsl b/test/spirv/sampled_texture.hlsl deleted file mode 100644 index de82cbe..0000000 --- a/test/spirv/sampled_texture.hlsl +++ /dev/null @@ -1,16 +0,0 @@ -// PROFILE: ps_6_0 -// vk::SampledTexture*: combined image samplers (sampling without a sampler -// argument; Load, GetDimensions and [] through OpImage). -// ZCHECK: OpTypeSampledImage -// ZCHECK: OpImage % -vk::SampledTexture2D t2 : register(t0); -vk::SampledTextureCUBE tc : register(t1); -vk::SampledTexture2DArray ta : register(t2); -float4 main(float2 uv : UV) : SV_Target { - uint w, h, st; - t2.GetDimensions(w, h); - float4 a = t2.Sample(uv) + t2.SampleLevel(uv, 1, int2(1, 0)) + t2.Load(int3(1, 2, 0)) + t2[uint2(3, 4)]; - float4 c = tc.SampleBias(float3(uv, 1), 0.5) + t2.Gather(uv, int2(0, 0), st); - float d = ta.SampleCmpLevelZero(float3(uv, 0), 0.5) + t2.CalculateLevelOfDetail(uv); - return a + c + d + w + h + CheckAccessFullyMapped(st); -} diff --git a/test/spirv/static_locals.hlsl b/test/spirv/static_locals.hlsl deleted file mode 100644 index d4e334d..0000000 --- a/test/spirv/static_locals.hlsl +++ /dev/null @@ -1,5 +0,0 @@ -// PROFILE: cs_6_0 -// Static locals: private globals initialized on entry. -RWStructuredBuffer 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]; } diff --git a/test/spirv/status.hlsl b/test/spirv/status.hlsl deleted file mode 100644 index f0706d9..0000000 --- a/test/spirv/status.hlsl +++ /dev/null @@ -1,22 +0,0 @@ -// PROFILE: ps_6_0 -// Status arguments: the sparse image instructions, residency checks. -// ZCHECK: OpImageSparseSampleImplicitLod -// ZCHECK: OpImageSparseTexelsResident -Texture2D t : register(t0); -Texture2DArray ta : register(t1); -RWTexture2D rw : register(u1); -Buffer b : register(t2); -SamplerState s : register(s0); -SamplerComparisonState sc : register(s1); -float4 main(float2 uv : UV) : SV_Target { - uint st0, st1, st2, st3, st4, st5, st6; - float4 a = t.Sample(s, uv, int2(1, 0), 0.5, st0); - float4 c = t.SampleLevel(s, uv, 0, int2(0, 1), st1); - float d = ta.SampleCmpLevelZero(sc, float3(uv, 0), 0.5, int2(0, 0), st2); - float4 g = t.Gather(s, uv, int2(0, 0), st3); - float4 l = t.Load(int3(1, 2, 0), int2(0, 0), st4); - float4 r = rw.Load(int2(1, 2), st5); - float4 bb = b.Load(3, st6); - bool all = CheckAccessFullyMapped(st0) && CheckAccessFullyMapped(st1) && CheckAccessFullyMapped(st2) && CheckAccessFullyMapped(st3) && CheckAccessFullyMapped(st4) && CheckAccessFullyMapped(st5) && CheckAccessFullyMapped(st6); - return all ? a + c + d + g + l + r + bb : 0; -} diff --git a/test/spirv/sv_pixel.hlsl b/test/spirv/sv_pixel.hlsl deleted file mode 100644 index 3055841..0000000 --- a/test/spirv/sv_pixel.hlsl +++ /dev/null @@ -1,8 +0,0 @@ -// PROFILE: ps_6_8 -// Pixel system values: clip distances in, barycentrics, coverage in and -// out, ViewID, shading rate, stencil ref. -// ZCHECK: BuiltIn BaryCoordNoPerspKHR -// ZCHECK: BuiltIn SampleMask -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; } diff --git a/test/spirv/sv_vertex.hlsl b/test/spirv/sv_vertex.hlsl deleted file mode 100644 index 2fc320e..0000000 --- a/test/spirv/sv_vertex.hlsl +++ /dev/null @@ -1,7 +0,0 @@ -// PROFILE: vs_6_8 -// Vertex system values: clip/cull distances, ViewID, start vertex and -// instance, viewport / render target index, shading rate. -// ZCHECK: OpVariable %_ptr_Output__arr_float_uint_3 Output -// ZCHECK: BuiltIn ViewIndex -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; } diff --git a/test/spirv/switch.hlsl b/test/spirv/switch.hlsl deleted file mode 100644 index f3f09c8..0000000 --- a/test/spirv/switch.hlsl +++ /dev/null @@ -1,19 +0,0 @@ -// PROFILE: cs_6_0 -// switch: fallthrough, default, break, continue to the enclosing loop. -// ZCHECK: OpSelectionMerge -// ZCHECK: OpSwitch -RWStructuredBuffer 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; -} diff --git a/test/spirv/swizzle_many.hlsl b/test/spirv/swizzle_many.hlsl deleted file mode 100644 index cfecf8c..0000000 --- a/test/spirv/swizzle_many.hlsl +++ /dev/null @@ -1,26 +0,0 @@ -// PROFILE: ps_6_0 -// Swizzle components stay intact however many swizzles follow (they used -// to live in a 16-entry static buffer that later swizzles overwrote). -// ZCHECK: OpVectorShuffle %v2float {{.*}} 3 2 -float4 main(float4 a : A) : SV_Target { - float2 first = a.wz; - float2 s = 0; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - s += a.xy; - return float4(first, s); -} diff --git a/test/spirv/tbuffer.hlsl b/test/spirv/tbuffer.hlsl deleted file mode 100644 index c352a8e..0000000 --- a/test/spirv/tbuffer.hlsl +++ /dev/null @@ -1,9 +0,0 @@ -// PROFILE: cs_6_0 -// tbuffer blocks and TextureBuffer: read-only std430 buffer blocks. -// ZCHECK: OpMemberDecorate %type_TextureBuffer_S 0 NonWritable -// ZCHECK: OpMemberDecorate %type_TB 0 NonWritable -struct S { float4 a; float b; float3 c; }; -tbuffer TB : register(t0) { float4 x; float y; S s; }; -TextureBuffer tbs : register(t1); -RWStructuredBuffer o : register(u0); -[numthreads(1,1,1)] void main() { o[0] = x * y + s.a + tbs.a * tbs.b + float4(tbs.c, 1); } diff --git a/test/spirv/templates.hlsl b/test/spirv/templates.hlsl deleted file mode 100644 index a844d2b..0000000 --- a/test/spirv/templates.hlsl +++ /dev/null @@ -1,23 +0,0 @@ -// PROFILE: cs_6_0 -// Templates (function, class, variable; deduction, defaults, specializations) and methods. -template T square(T x) { return x * x; } -template vector scale(vector v, T k) { return v * k; } -template struct Pair { T a; T b; T sum() { return a + b; } }; -template struct Arr { T v[N]; T get(uint i) { return v[i]; } }; -template T first(Pair p) { return p.a; } -RWStructuredBuffer o : register(u0); -[numthreads(1,1,1)] void main(uint i : SV_DispatchThreadID) { - Pair p; p.a = 1; p.b = 2; - Arr 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(2); -} -template static const bool is_same_v = false; -template static const bool is_same_v = true; -template struct Box { T v; }; -template<> struct Box { 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 bi; bi.extra = 2; Derived dv; dv.b = 3; - o[i] = is_same_v + is_same_v + bi.extra + dv.twice(); -} diff --git a/test/spirv/textures.hlsl b/test/spirv/textures.hlsl deleted file mode 100644 index c383e71..0000000 --- a/test/spirv/textures.hlsl +++ /dev/null @@ -1,45 +0,0 @@ -// PROFILE: ps_6_0 -// Texture and sampler operations, as dxc emits them for Vulkan. -// ZCHECK: OpCapability SampledBuffer -// ZCHECK: OpCapability ImageQuery -// ZCHECK: OpTypeImage %float 2D 2 0 0 1 Unknown -// ZCHECK: OpTypeImage %float 2D 2 0 1 1 Unknown -// ZCHECK: OpTypeImage %uint 3D 2 0 0 1 Unknown -// ZCHECK: OpTypeImage %float Buffer 2 0 0 1 Rgba32f -// ZCHECK: OpTypeImage %float 2D 2 0 0 2 Rgba32f -// ZCHECK: OpImageSampleImplicitLod %v4float {{.*}} ConstOffset -// ZCHECK: OpImageSampleExplicitLod %v4float {{.*}} Lod %float_2 -// ZCHECK: OpImageSampleImplicitLod %v4float {{.*}} Bias -// ZCHECK: OpImageSampleExplicitLod %v4float {{.*}} Grad -// ZCHECK: OpImageSampleDrefImplicitLod %float -// ZCHECK: OpImageSampleDrefExplicitLod %float {{.*}} Lod %float_0 -// ZCHECK: OpImageFetch %v4float {{.*}} Lod -// ZCHECK: OpImageFetch %v4float {{.*}} Sample %int_2 -// ZCHECK: OpImageGather %v4float {{.*}} %int_1 ConstOffset -// ZCHECK: OpImageDrefGather %v4float -// ZCHECK: OpImageQuerySizeLod %v2uint {{.*}} %uint_1 -// ZCHECK: OpImageQueryLevels %uint -// ZCHECK: OpImageQuerySize %v2uint -// ZCHECK: OpImageQueryLod %v2float -// ZCHECK: OpImageWrite -// ZCHECK: OpImageRead %v4float -Texture2D t2 : register(t0); -Texture2DArray t2a : register(t1); -TextureCube tc : register(t2); -Texture2DMS tms : register(t3); -Texture3D t3 : register(t4); -Buffer buf : register(t5); -RWTexture2D 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; -} diff --git a/test/spirv/unroll.hlsl b/test/spirv/unroll.hlsl deleted file mode 100644 index f70ed62..0000000 --- a/test/spirv/unroll.hlsl +++ /dev/null @@ -1,24 +0,0 @@ -// PROFILE: ps_6_0 -// Loops unroll so texel offsets become constants; [loop], breaks and -// run-time bounds keep their loops. -// ZCHECK: OpConstantComposite %v2int %int_n1 %int_n2 -// ZCHECK: OpConstantComposite %v2int %int_1 %int_2 -// ZCHECK: OpConstantComposite %v2int %int_2 %int_0 -// ZCHECK: OpLoopMerge -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; -} diff --git a/test/spirv/vk_bindings.hlsl b/test/spirv/vk_bindings.hlsl deleted file mode 100644 index c2f55d1..0000000 --- a/test/spirv/vk_bindings.hlsl +++ /dev/null @@ -1,41 +0,0 @@ -// PROFILE: ps_6_0 -// FLAGS: -E main -fvk-t-shift 10 0 -fvk-s-shift 20 all -fvk-bind-globals 7 2 -// Vulkan bindings, numbered as dxc numbers them: [[vk::binding]] and -// [[vk::counter_binding]] first, then registers (shifted), then the rest -// in declaration order (used or not), Append / Consume counters right -// after their buffer. Also push constants, explicit locations / indices -// and specialization constants. -// ZCHECK: OpDecorate %tex DescriptorSet 0 -// ZCHECK: OpDecorate %tex Binding 13 -// ZCHECK: OpDecorate %samp Binding 21 -// ZCHECK: OpDecorate %explicit_ DescriptorSet 3 -// ZCHECK: OpDecorate %_Globals{{.*}} DescriptorSet 2 -// ZCHECK: OpDecorate %_Globals{{.*}} Binding 7 -// ZCHECK: OpDecorate %counter_var_consumed Binding 6 -// ZCHECK: OpDecorate %out_var_SV_Target1 Index 1 -// ZCHECK: OpDecorate %in_var_COLOR Location 4 -// ZCHECK: OpDecorate %spec SpecId 3 -// ZCHECK: OpSpecConstant %int 5 -// ZCHECK: OpVariable %_ptr_PushConstant_type_PushConstant_pc PushConstant -Texture2D tex : register(t3); -SamplerState samp : register(s1); -[[vk::binding(4, 3)]] Texture2D explicit_; -Texture2D unused; -[[vk::counter_binding(6)]] ConsumeStructuredBuffer consumed; -StructuredBuffer later; -float4 tint; -[[vk::constant_id(3)]] const int spec = 5; -struct PC { float4 scale; }; -[[vk::push_constant]] PC pc; - -struct Out { - [[vk::location(0)]] float4 a : SV_Target0; - [[vk::location(0), vk::index(1)]] float4 b : SV_Target1; -}; - -Out main([[vk::location(4)]] float2 uv : COLOR) { - Out o; - o.a = tex.Sample(samp, uv) * tint * pc.scale + explicit_.Sample(samp, uv) + consumed.Consume() + later[spec]; - o.b = o.a; - return o; -} diff --git a/test/spirv/vk_ext.hlsl b/test/spirv/vk_ext.hlsl deleted file mode 100644 index 1816f8d..0000000 --- a/test/spirv/vk_ext.hlsl +++ /dev/null @@ -1,37 +0,0 @@ -// PROFILE: ps_6_0 -// FLAGS: -E main -// Vulkan-only declarations: subpass inputs, explicit image formats, and -// inline SPIR-V (ext_instruction functions with literals and references, -// ext_builtin_input variables, ext_decorate, ext_execution_mode), with the -// capabilities the instructions and enumerants need. -// ZCHECK: OpCapability InputAttachment -// ZCHECK: OpCapability SampleRateShading -// ZCHECK: OpExtInstImport "GLSL.std.450" -// ZCHECK: OpExecutionMode %main EarlyFragmentTests -// ZCHECK: OpDecorate %SI InputAttachmentIndex 2 -// ZCHECK: OpDecorate %gl_SampleID BuiltIn SampleId -// ZCHECK: OpDecorate %gl_SampleID Flat -// ZCHECK: OpDecorate %img RelaxedPrecision -// ZCHECK: OpTypeImage %float SubpassData 2 0 0 2 Unknown -// ZCHECK: OpTypeImage %float 2D 2 0 0 2 Rgba16f -// ZCHECK: OpImageRead %v4float {{.*}} None -// ZCHECK: OpExtInst %v4float {{.*}} Sin -// ZCHECK: OpLoad %float {{.*}} Volatile -[[vk::input_attachment_index(2)]] SubpassInput SI; -[[vk::image_format("rgba16f"), vk::ext_decorate(/* RelaxedPrecision */ 0)]] RWTexture2D img; - -[[vk::ext_builtin_input(/* SampleId */ 18)]] -static const uint gl_SampleID; - -[[vk::ext_instruction(/* Sin */ 13, "GLSL.std.450")]] -float4 spv_sin(float4 v); - -[[vk::ext_instruction(/* OpLoad */ 61)]] -float load_volatile([[vk::ext_reference]] float p, [[vk::ext_literal]] int memoryOperands); - -float4 main(float4 pos : SV_Position) : SV_Target { - vk::ext_execution_mode(/* EarlyFragmentTests */ 9); - float x = pos.x; - float4 v = SI.SubpassLoad() + img[uint2(gl_SampleID, 0)]; - return spv_sin(v) * load_volatile(x, /* Volatile */ 1); -} diff --git a/test/spirv/vk_memory_model.hlsl b/test/spirv/vk_memory_model.hlsl deleted file mode 100644 index 159759d..0000000 --- a/test/spirv/vk_memory_model.hlsl +++ /dev/null @@ -1,22 +0,0 @@ -// PROFILE: ps_6_0 -// FLAGS: -E main -fspv-use-vulkan-memory-model -// ENV: vulkan1.1 -// The Vulkan memory model: coherent accesses carry visibility / -// availability flags and a QueueFamily scope instead of Coherent -// decorations, and atomics use QueueFamily for Device scope. -// ZCHECK: OpCapability VulkanMemoryModel -// ZCHECK: OpExtension "SPV_KHR_vulkan_memory_model" -// ZCHECK: OpMemoryModel Logical Vulkan -// ZCHECK: OpLoad %uint {{.*}} MakePointerVisible|NonPrivatePointer %uint_5 -// ZCHECK: OpStore {{.*}} MakePointerAvailable|NonPrivatePointer %uint_5 -// ZCHECK: OpAtomicIAdd %uint {{.*}} %uint_5 %uint_0 -globallycoherent RWByteAddressBuffer buffer1; -globallycoherent RWStructuredBuffer buffer2; -RWStructuredBuffer buffer3; - -float4 main() : SV_Target { - buffer2[0] = buffer1.Load(0) + buffer3[0]; - uint old; - InterlockedAdd(buffer3[1], 1, old); - return old; -} diff --git a/test/spirv/vk_options.hlsl b/test/spirv/vk_options.hlsl deleted file mode 100644 index 9c24efb..0000000 --- a/test/spirv/vk_options.hlsl +++ /dev/null @@ -1,30 +0,0 @@ -// PROFILE: vs_6_0 -// FLAGS: -E main -fvk-invert-y -fvk-support-nonzero-base-instance -fspv-entrypoint-name=vsmain -fspv-reflect -fvk-use-gl-layout -fspv-enable-maximal-reconvergence -// Vulkan options: flipped SV_Position.y, instance IDs counted from the base -// instance, a renamed entry point, reflection decorations, strict GLSL -// layout, maximal reconvergence, and [[vk::builtin]]. -// ZCHECK: OpEntryPoint Vertex %main "vsmain" -// ZCHECK: OpExecutionMode %main MaximallyReconvergesKHR -// ZCHECK: OpExtension "SPV_GOOGLE_hlsl_functionality1" -// ZCHECK: OpDecorateString %in_var_POSITION UserSemantic "POSITION" -// ZCHECK: OpDecorateString %Params UserTypeGOOGLE "cbuffer" -// ZCHECK: BuiltIn PointSize -// ZCHECK: BuiltIn BaseInstance -// ZCHECK: OpMemberDecorate %type_Params 1 Offset 16 -// ZCHECK: OpFNegate %float -// ZCHECK: OpISub %uint -cbuffer Params { float a; float3 b; }; - -struct Out { - float4 pos : SV_Position; - [[vk::builtin("PointSize")]] float size : PSIZE; - uint id : ID; -}; - -Out main(float3 p : POSITION, uint inst : SV_InstanceID) { - Out o; - o.pos = float4(p * b, a); - o.size = 1; - o.id = inst; - return o; -} diff --git a/test/spirv/wave.hlsl b/test/spirv/wave.hlsl deleted file mode 100644 index fea9357..0000000 --- a/test/spirv/wave.hlsl +++ /dev/null @@ -1,15 +0,0 @@ -// PROFILE: cs_6_0 -// ENV: vulkan1.1 -// Wave and quad intrinsics as GroupNonUniform operations (Vulkan 1.1). -// ZCHECK: OpCapability GroupNonUniformArithmetic -// ZCHECK: OpGroupNonUniformBallot %v4uint -// ZCHECK: OpGroupNonUniformQuadSwap -RWStructuredBuffer 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; -}