From 04e5f9e3c36de0ac35c1e90bb8b70ec70829156a Mon Sep 17 00:00:00 2001 From: Peter Li Date: Sat, 31 Oct 2026 03:17:40 -0700 Subject: [PATCH] Add semantic analysis (Sema) with dxc-derived oracles Sema type-checks a parsed translation unit: an interned type table, scopes and symbols, declarations, statements and expressions, implicit and explicit conversions, user-function overload resolution, and intrinsic / builtin method matching driven by dxc's gen_intrin_main.txt (vendored, turned into a Zig table at build time by tools/gen_intrinsics.zig). Rules ported from dxc where it matters for exact agreement: - operator result types (CombineBasicTypes, shift and bool rules) - literal suffix types and diagnostics, including `1.#INF` - declaration modifier validity and conflicts (DiagnoseHLSLDecl) and row_major / column_major checks, using source-ordered qualifier words - constant folding of asuint / max / min - `_Static_assert`, `__decltype` and `std::is_same` builtins (`static_assert` is an ordinary identifier in HLSL 2021) Templates, operator overloading and bitfields report "not supported yet (planned for milestone 0.2)". Oracles: - zig build oracle-sema: no false errors on the 1604 dxc-valid corpus files (1537 clean, 67 need milestone 0.2 features) - zig build oracle-verify: error-line agreement with dxc's SemaHLSL -verify tests under HLSL 2021 (53% of expected error lines caught, 80 false error lines) Also fixes the provenance commit of gen_intrin_main.txt (55a61aa79). Co-Authored-By: Claude Opus 5.5 --- build.zig | 28 + src/front/ast.zig | 20 +- src/front/ast_dump.zig | 14 +- src/front/lexer.zig | 4 +- src/front/parser.zig | 110 +- src/main.zig | 34 +- src/options.zig | 2 + src/root.zig | 8 + src/sema/intrinsics.zig | 367 +++++ src/sema/sema.zig | 2325 ++++++++++++++++++++++++++++++++ src/sema/types.zig | 531 ++++++++ tools/gen_intrinsics.zig | 233 ++++ vendor/PROVENANCE.md | 1 + vendor/dxc/gen_intrin_main.txt | 1651 +++++++++++++++++++++++ 14 files changed, 5301 insertions(+), 27 deletions(-) create mode 100644 src/sema/intrinsics.zig create mode 100644 src/sema/sema.zig create mode 100644 src/sema/types.zig create mode 100644 tools/gen_intrinsics.zig create mode 100644 vendor/dxc/gen_intrin_main.txt diff --git a/build.zig b/build.zig index 6516174..8f57b35 100644 --- a/build.zig +++ b/build.zig @@ -22,6 +22,18 @@ pub fn build(b: *std.Build) void { gen_options_run.addFileArg(b.path("vendor/dxc/HLSLOptions.td")); const options_table = gen_options_run.addOutputFileArg("options_table.zig"); + // dxc's intrinsic declarations, likewise generated at build time. + const gen_intrinsics = b.addExecutable(.{ + .name = "gen_intrinsics", + .root_module = b.createModule(.{ + .root_source_file = b.path("tools/gen_intrinsics.zig"), + .target = b.graph.host, + }), + }); + const gen_intrinsics_run = b.addRunArtifact(gen_intrinsics); + gen_intrinsics_run.addFileArg(b.path("vendor/dxc/gen_intrin_main.txt")); + const intrinsics_table = gen_intrinsics_run.addOutputFileArg("intrinsics_table.zig"); + const mod = b.addModule("zdxc", .{ .root_source_file = b.path("src/root.zig"), .target = target, @@ -29,6 +41,7 @@ pub fn build(b: *std.Build) void { .imports = &.{.{ .name = "hlsl_headers", .module = hlsl_headers }}, }); mod.addAnonymousImport("options_table", .{ .root_source_file = options_table }); + mod.addAnonymousImport("intrinsics_table", .{ .root_source_file = intrinsics_table }); const exe = b.addExecutable(.{ .name = "zdxc", @@ -68,6 +81,21 @@ pub fn build(b: *std.Build) void { 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_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); diff --git a/src/front/ast.zig b/src/front/ast.zig index 492acdd..e69baf2 100644 --- a/src/front/ast.zig +++ b/src/front/ast.zig @@ -41,6 +41,8 @@ pub const TypeRef = struct { attrs: []const Attribute = &.{}, /// `unorm` / `snorm` inside resource element types. norm: enum { none, unorm, snorm } = .none, + /// `__decltype(expr)`: the type of `expr` (`name` is `__decltype`). + decltype: ?*Expr = null, }; /// Storage classes, type qualifiers and parameter / interpolation @@ -78,9 +80,14 @@ pub const Qualifiers = packed struct(u64) { indices: bool = false, primitives: bool = false, payload: bool = false, - _: u34 = 0, + center: bool = false, + _: u33 = 0, }; +/// A qualifier keyword as written: some diagnostics depend on the order +/// and position of qualifiers, which `Qualifiers` does not keep. +pub const QualWord = struct { loc: Loc, word: []const u8 }; + /// `[name(args)]` or `[[ns::name(args)]]`. pub const Attribute = struct { loc: Loc, @@ -130,6 +137,10 @@ pub const AssignOp = enum { assign, mul, div, rem, add, sub, shl, shr, bit_and, pub const Expr = struct { loc: Loc, kind: Kind, + /// Filled in by Sema: the expression's type (a sema TypeId; 0 is the + /// error type) and an index into Sema's per-expression information. + ty: u32 = 0, + info: u32 = 0, pub const Kind = union(enum) { int_lit: []const u8, @@ -154,6 +165,8 @@ pub const Expr = struct { init_list: []const *Expr, sizeof_type: *TypeRef, sizeof_expr: *Expr, + /// `std::is_same::value` (a dxc builtin). + is_same: struct { a: *TypeRef, b: *TypeRef }, }; }; @@ -190,6 +203,8 @@ pub const VarDecl = struct { /// Qualified out-of-line definitions (`int S::x = 1;`) keep the full /// spelled name, e.g. `S::x`. quals: Qualifiers, + /// The qualifiers in source order. + qual_words: []const QualWord = &.{}, type: *TypeRef, name: []const u8, name_loc: Loc, @@ -210,6 +225,7 @@ pub const TemplateParam = struct { pub const FuncDecl = struct { attrs: []const Attribute, quals: Qualifiers, + qual_words: []const QualWord = &.{}, template_params: []const TemplateParam, ret: *TypeRef, /// Function name; for operators `operator+`, `operator[]`, `operator()`. @@ -258,7 +274,7 @@ pub const Decl = struct { func: FuncDecl, @"struct": StructDecl, cbuffer: CBufferDecl, - typedef: struct { name: []const u8, type: *TypeRef, array_dims: []const ?*Expr, template_params: []const TemplateParam = &.{} }, + typedef: struct { name: []const u8, type: *TypeRef, array_dims: []const ?*Expr, template_params: []const TemplateParam = &.{}, qual_words: []const QualWord = &.{} }, @"enum": EnumDecl, namespace: struct { name: []const u8, decls: []const *Decl }, /// `using namespace N;` diff --git a/src/front/ast_dump.zig b/src/front/ast_dump.zig index bf04d6c..b41b1a9 100644 --- a/src/front/ast_dump.zig +++ b/src/front/ast_dump.zig @@ -37,6 +37,11 @@ fn templateArgs(w: *W, args: []const ast.TemplateArg) W.Error!void { pub fn typeRef(w: *W, t: *const ast.TypeRef) W.Error!void { if (t.norm != .none) try w.print("{s} ", .{@tagName(t.norm)}); + if (t.decltype) |e| { + try w.writeAll("__decltype("); + try expr(w, e); + return w.writeByte(')'); + } try name(w, t.name); if (t.args.len > 0) try templateArgs(w, t.args); try dims(w, t.array_dims); @@ -216,7 +221,7 @@ pub fn decl(w: *W, d: *const ast.Decl, depth: usize) W.Error!void { }, .pragma => |p| try w.print("(pragma {s})", .{p}), .static_assert => |s| { - try w.writeAll("(static_assert "); + try w.writeAll("(_Static_assert "); try expr(w, s.cond); try w.writeByte(')'); }, @@ -405,6 +410,13 @@ pub fn expr(w: *W, e: *const ast.Expr) W.Error!void { try typeRef(w, t); try w.writeByte(')'); }, + .is_same => |x| { + try w.writeAll("(is_same "); + try typeRef(w, x.a); + try w.writeAll(", "); + try typeRef(w, x.b); + try w.writeByte(')'); + }, .sizeof_expr => |x| { try w.writeAll("(sizeof "); try expr(w, x); diff --git a/src/front/lexer.zig b/src/front/lexer.zig index 95dfa6c..dc1ad3b 100644 --- a/src/front/lexer.zig +++ b/src/front/lexer.zig @@ -305,7 +305,8 @@ pub const Lexer = struct { } break; } - if (isIdentChar(c) or c == '.') { + // dxc also takes '#' (for `1.#INF`). + if (isIdentChar(c) or c == '.' or c == '#') { l.pos += 1; continue; } @@ -342,6 +343,7 @@ test "punctuators and literals" { try expectKinds("a+=b<<=c>>1.5e-3f", &.{ .identifier, .plus_equal, .identifier, .less_less_equal, .identifier, .greater_greater, .number }); try expectKinds("x::y->z...", &.{ .identifier, .colon_colon, .identifier, .arrow, .identifier, .ellipsis }); try expectKinds("\"a\\\"b\" 'c' .5h 0x1Fu", &.{ .string, .char, .number, .number }); + try expectKinds("1.#INF.xxx -1.#INF", &.{ .number, .minus, .number }); try expectKinds("# ## #x", &.{ .hash, .hash_hash, .hash, .identifier }); } diff --git a/src/front/parser.zig b/src/front/parser.zig index 4d06d80..835411b 100644 --- a/src/front/parser.zig +++ b/src/front/parser.zig @@ -35,6 +35,10 @@ pub const Parser = struct { /// Name of the struct most recently parsed by parseStructDeclInto /// (synthesized for anonymous structs), for `typedef struct ...`. last_struct_name: []const u8 = "", + /// The qualifier words read by the last parseQualifiers call. + last_quals: []const ast.QualWord = &.{}, + /// Qualifier words for the next parseDeclaratorsInto call. + decl_quals: []const ast.QualWord = &.{}, /// Set while parsing template arguments: a top-level `>` ends the /// argument instead of being a comparison. no_greater: bool = false, @@ -295,6 +299,9 @@ pub const Parser = struct { if (p.toks[i].kind == .identifier and isBuiltinType(p.toks[i].text)) i += 1; return i; } + if (p.toks[i].isIdent("__decltype") and p.toks[i + 1].kind == .l_paren) { + return p.skipTypeAttrs(p.skipParens(i + 1) orelse return null); + } if (p.toks[i].kind == .colon_colon) i += 1; while (true) { const t = p.toks[i]; @@ -347,6 +354,23 @@ pub const Parser = struct { } } + /// Index just past the `)` matching the `(` at `start`, or null. + fn skipParens(p: *const Parser, start: usize) ?usize { + var i = start; + var depth: u32 = 0; + while (true) : (i += 1) { + switch (p.toks[i].kind) { + .l_paren => depth += 1, + .r_paren => { + depth -= 1; + if (depth == 0) return i + 1; + }, + .semi, .l_brace, .r_brace, .eof => return null, + else => {}, + } + } + } + /// Index just past the `>` matching the `<` at `i`, or null. fn skipAngles(p: *const Parser, start: usize) ?usize { var i = start; @@ -425,6 +449,8 @@ pub const Parser = struct { /// `line`, ...) count only when a type or another qualifier follows. fn parseQualifiers(p: *Parser) ast.Qualifiers { var q: ast.Qualifiers = .{}; + var words: std.ArrayList(ast.QualWord) = .empty; + defer p.last_quals = words.items; while (p.at(.identifier)) { const word = p.tok().text; const field = qualifierField(word) orelse break; @@ -433,6 +459,7 @@ pub const Parser = struct { const next_is_qual = n.kind == .identifier and qualifierField(n.text) != null; if (!next_is_qual and !p.isTypeStartAt(p.pos + 1)) break; } + words.append(p.arena, .{ .loc = p.tok().loc, .word = word }) catch {}; _ = p.advance(); if (std.mem.eql(u8, word, "inout")) { q.in = true; @@ -465,6 +492,16 @@ pub const Parser = struct { const n = try p.parseNameWithFinalArgs(); return p.mk(ast.TypeRef, .{ .loc = start.loc, .name = n.name, .args = n.args }); } + if (p.atIdent("__decltype")) { + _ = p.advance(); + _ = try p.expect(.l_paren, "'('"); + const saved = p.no_greater; + p.no_greater = false; + const e = try p.parseExpr(); + p.no_greater = saved; + _ = try p.expect(.r_paren, "')'"); + return p.mk(ast.TypeRef, .{ .loc = start.loc, .name = try p.simpleName(start.loc, "__decltype"), .decltype = e }); + } if (p.atIdent("unsigned") or p.atIdent("signed")) { const signed = p.advance().isIdent("signed"); var base: []const u8 = "int"; @@ -663,14 +700,16 @@ pub const Parser = struct { if (t.isIdent("using")) return out.append(p.arena, try p.parseUsing(template_params)); if (t.isIdent("namespace")) return out.append(p.arena, try p.parseNamespace()); if (t.isIdent("enum")) return p.parseEnumInto(out); - if (t.isIdent("static_assert")) { + if (t.isIdent("_Static_assert")) { const d = try p.parseStaticAssert(); _ = try p.expect(.semi, "';'"); return out.append(p.arena, d); } const quals = p.parseQualifiers(); + const words = p.last_quals; const ty = try p.parseType(); + p.decl_quals = words; try p.parseDeclaratorsInto(out, attrs, quals, template_params, ty, ctx); } @@ -848,6 +887,7 @@ pub const Parser = struct { fn parseTypedefInto(p: *Parser, out: *std.ArrayList(*ast.Decl)) Error!void { const kw = p.advance(); _ = p.parseQualifiers(); + const words = p.last_quals; var ty: *ast.TypeRef = undefined; if (p.atIdent("struct") or p.atIdent("class")) { // `typedef struct { ... } Name;` @@ -858,7 +898,7 @@ pub const Parser = struct { const name = try p.expectIdent("typedef name"); const dims = try p.parseArrayDims(); try p.declareName(name.text, .type); - try out.append(p.arena, try p.mk(ast.Decl, .{ .loc = kw.loc, .kind = .{ .typedef = .{ .name = name.text, .type = ty, .array_dims = dims } } })); + try out.append(p.arena, try p.mk(ast.Decl, .{ .loc = kw.loc, .kind = .{ .typedef = .{ .name = name.text, .type = ty, .array_dims = dims, .qual_words = words } } })); if (!p.eat(.comma)) break; } _ = try p.expect(.semi, "';'"); @@ -935,14 +975,17 @@ pub const Parser = struct { try p.parseDeclaratorsInto(out, &.{}, .{}, &.{}, ty, .global); } + /// `_Static_assert(cond, "message")`: C11's spelling, accepted by dxc in + /// every language version (`static_assert` is an identifier in 2021). fn parseStaticAssert(p: *Parser) Error!*ast.Decl { - // Parsed for recovery, but not part of HLSL 2021 (dxc rejects it). - _ = p.reportAt(p.pos, .@"error", "'static_assert' requires HLSL 202x; zdxc implements HLSL 2021", .{}); const kw = p.advance(); _ = try p.expect(.l_paren, "'('"); const cond = try p.parseAssign(); var message: ?[]const u8 = null; - if (p.eat(.comma)) message = (try p.expect(.string, "string literal")).text; + if (p.eat(.comma)) { + if (!p.at(.string)) return p.fail("expected string literal", .{}); + message = (try p.parsePrimary()).kind.string_lit; // adjacent literals concatenate + } _ = try p.expect(.r_paren, "')'"); return p.mk(ast.Decl, .{ .loc = kw.loc, .kind = .{ .static_assert = .{ .cond = cond, .message = message } } }); } @@ -957,6 +1000,8 @@ pub const Parser = struct { ty: *ast.TypeRef, ctx: DeclContext, ) Error!void { + const words = p.decl_quals; + p.decl_quals = &.{}; // Function names may be qualified (`S::method`) or operators; // variables may be qualified for out-of-line static members. const name_loc = p.tok().loc; @@ -988,7 +1033,11 @@ pub const Parser = struct { } else p.pos = save; } } - if (fname) |n| return out.append(p.arena, try p.parseFunctionRest(attrs, quals, template_params, ty, n, name_loc, ctx)); + if (fname) |n| { + const d = try p.parseFunctionRest(attrs, quals, template_params, ty, n, name_loc, ctx); + if (d.kind == .func) d.kind.func.qual_words = words; + return out.append(p.arena, d); + } var first = true; while (true) { @@ -1010,6 +1059,7 @@ pub const Parser = struct { .attrs = attrs, .template_params = template_params, .quals = quals, + .qual_words = words, .type = ty, .name = name.text, .name_loc = name.loc, @@ -1080,6 +1130,7 @@ pub const Parser = struct { while (!p.at(.r_paren)) { const pattrs = try p.parseAttributes(); const pquals = p.parseQualifiers(); + const pwords = p.last_quals; const pty = try p.parseType(); var pname: []const u8 = ""; var pname_loc = p.tok().loc; @@ -1097,6 +1148,7 @@ pub const Parser = struct { try params.append(p.arena, .{ .attrs = pattrs, .quals = pquals, + .qual_words = pwords, .type = pty, .name = pname, .name_loc = pname_loc, @@ -1342,7 +1394,7 @@ pub const Parser = struct { if (t.kind == .identifier) { const w = t.text; if (std.mem.eql(u8, w, "struct") or std.mem.eql(u8, w, "class") or std.mem.eql(u8, w, "typedef") or - std.mem.eql(u8, w, "using") or std.mem.eql(u8, w, "enum") or std.mem.eql(u8, w, "static_assert")) + std.mem.eql(u8, w, "using") or std.mem.eql(u8, w, "enum") or std.mem.eql(u8, w, "_Static_assert")) return true; if (qualifierField(w) != null) { if (!isContextualQualifier(w)) return true; @@ -1579,6 +1631,12 @@ pub const Parser = struct { switch (t.kind) { .number => { _ = p.advance(); + // HLSL allows swizzles on literals (`0x04.xxx`, `1.0.xxxx`); + // the lexer reads them as one pp-number. + if (splitLiteralSwizzle(t.text)) |split| { + const lit = try p.mkExpr(t.loc, if (isFloatLiteral(split.literal)) .{ .float_lit = split.literal } else .{ .int_lit = split.literal }); + return p.mkExpr(t.loc, .{ .member = .{ .base = lit, .name = split.swizzle, .name_loc = t.loc.advance(@intCast(split.literal.len + 1)) } }); + } return p.mkExpr(t.loc, if (isFloatLiteral(t.text)) .{ .float_lit = t.text } else .{ .int_lit = t.text }); }, .string => { @@ -1616,6 +1674,16 @@ pub const Parser = struct { _ = p.advance(); return p.mkExpr(t.loc, .this); } + if (t.isIdent("std") and p.peek(1).kind == .colon_colon and p.peek(2).isIdent("is_same") and p.peek(3).kind == .less) { + p.pos += 3; + const args = try p.parseTemplateArgs(); + _ = try p.expect(.colon_colon, "'::'"); + const v = try p.expect(.identifier, "'value'"); + if (args.len != 2 or args[0] != .type or args[1] != .type or !v.isIdent("value")) { + return p.fail("expected 'std::is_same::value'", .{}); + } + return p.mkExpr(t.loc, .{ .is_same = .{ .a = args[0].type, .b = args[1].type } }); + } if (t.kind == .identifier and isReserved(t.text)) { return p.fail("expected expression, found '{s}'", .{t.text}); } @@ -1652,6 +1720,22 @@ fn describe(t: Token) []const u8 { return if (t.kind == .eof) "end of file" else t.text; } +/// `0x04.xxx` -> literal `0x04`, swizzle `xxx`; `1.0.xy` -> `1.0`, `xy`. +fn splitLiteralSwizzle(text: []const u8) ?struct { literal: []const u8, swizzle: []const u8 } { + const dot = std.mem.lastIndexOfScalar(u8, text, '.') orelse return null; + const sw = text[dot + 1 ..]; + if (sw.len == 0 or sw.len > 4) return null; + for (sw) |c| if (std.mem.indexOfScalar(u8, "xyzwrgba", c) == null) return null; + const lit = text[0..dot]; + if (lit.len == 0) return null; + // `1.xx`: the literal must not end in an exponent marker. + if (std.ascii.isAlphabetic(lit[lit.len - 1]) and !(lit.len > 1 and lit[0] == '0' and (lit[1] == 'x' or lit[1] == 'X'))) { + const last = lit[lit.len - 1]; + if (last != 'f' and last != 'F' and last != 'h' and last != 'H' and last != 'u' and last != 'U' and last != 'l' and last != 'L') return null; + } + return .{ .literal = lit, .swizzle = sw }; +} + fn isFloatLiteral(text: []const u8) bool { if (text.len > 1 and text[0] == '0' and (text[1] == 'x' or text[1] == 'X')) return false; if (std.mem.indexOfAny(u8, text, ".eE") != null) return true; @@ -1660,14 +1744,7 @@ fn isFloatLiteral(text: []const u8) bool { } /// Words that can never be identifiers. -const reserved_words = [_][]const u8{ - "if", "else", "for", "while", "do", "switch", "case", - "default", "break", "continue", "return", "discard", "struct", "class", - "interface", "cbuffer", "tbuffer", "typedef", "namespace", "enum", "template", - "typename", "true", "false", "this", "sizeof", "static", "const", - "uniform", "extern", "volatile", "groupshared", "inline", "using", "operator", - "static_assert", "inout", "in", "out", -}; +const reserved_words = [_][]const u8{ "if", "else", "for", "while", "do", "switch", "case", "default", "break", "continue", "return", "discard", "struct", "class", "interface", "cbuffer", "tbuffer", "typedef", "namespace", "enum", "template", "typename", "true", "false", "this", "sizeof", "static", "const", "uniform", "extern", "volatile", "groupshared", "inline", "using", "operator", "_Static_assert", "inout", "in", "out", "__decltype" }; /// Qualifier keywords and their ast.Qualifiers field names. const qualifier_words = [_][2][]const u8{ @@ -1681,7 +1758,7 @@ const qualifier_words = [_][2][]const u8{ .{ "export", "export" }, .{ "point", "point" }, .{ "line", "line" }, .{ "triangle", "triangle" }, .{ "lineadj", "lineadj" }, .{ "triangleadj", "triangleadj" }, .{ "vertices", "vertices" }, .{ "indices", "indices" }, .{ "primitives", "primitives" }, - .{ "payload", "payload" }, + .{ "payload", "payload" }, .{ "center", "center" }, }; /// Qualifiers that are ordinary identifiers unless a type follows. @@ -1689,6 +1766,7 @@ const contextual_words = [_][]const u8{ "precise", "shared", "row_major", "column_major", "nointerpolation", "linear", "centroid", "sample", "noperspective", "globallycoherent", "reordercoherent", "export", "point", "line", "triangle", "lineadj", "triangleadj", "vertices", "indices", "primitives", "payload", + "center", }; fn isReserved(w: []const u8) bool { diff --git a/src/main.zig b/src/main.zig index 7753ef1..2c44d27 100644 --- a/src/main.zig +++ b/src/main.zig @@ -29,6 +29,7 @@ const Options = struct { error_limit: u32 = 20, parse: bool = false, dump_ast: bool = false, + sema: bool = false, /// -O0..-O3 / -Od (default -O3, as in dxc). opt_level: enum { od, o0, o1, o2, o3 } = .o3, /// Accepted options with no effect yet, reported once each. @@ -91,6 +92,7 @@ fn parseArgs(cli: Cli, arena: std.mem.Allocator, argv: []const [:0]const u8, std opts.parse = true; opts.dump_ast = true; }, + .zdxc_sema => opts.sema = true, .fcolor_diagnostics => opts.color = true, .fno_color_diagnostics => opts.color = false, }, @@ -211,7 +213,9 @@ fn run(cli: Cli, arena: std.mem.Allocator, args: []const [:0]const u8, stdout: * else null; - if (opts.preprocess or opts.parse) { + // The front end: everything except the development modes that work on + // containers or raw tokens. + if (!opts.empty) { const input = opts.input orelse return cli.fail("no input file", .{}); var disk: front.source.DiskFs = .{ .io = cli.io }; var sm = front.source.SourceManager.init(arena, disk.fileSystem()); @@ -231,20 +235,36 @@ fn run(cli: Cli, arena: std.mem.Allocator, args: []const [:0]const u8, stdout: * }); var out: Io.Writer.Allocating = .init(arena); if (try pp.enterMainFile(input)) { - if (opts.parse) { + if (opts.preprocess) { + try front.pp_print.print(&pp, &out.writer); + } else { var parser = try front.parser.Parser.fromPreprocessor(arena, &diags, &pp); const tu = try parser.parseTranslationUnit(); if (opts.dump_ast) try front.ast_dump.dumpUnit(stdout, tu); - } else try front.pp_print.print(&pp, &out.writer); + if (!opts.parse) { + const is_lib = if (profile) |p| p.kind == .library else true; + var sema = try zdxc.sema.Sema.init(arena, &diags, .{ + .entry = if (opts.sema or is_lib) null else opts.entry, + .spirv = opts.spirv, + .enable_16bit = opts.enable_16bit, + }); + try sema.checkUnit(tu); + } + } } const color = opts.color orelse (Io.File.stderr().supportsAnsiEscapeCodes(cli.io) catch false); try diags.render(&sm, cli.stderr, .{ .format = opts.diag_format, .color = color }); try cli.stderr.flush(); if (diags.hasErrors()) return error.CompileFailed; - if (opts.pp_output) |path| { - try Io.Dir.cwd().writeFile(cli.io, .{ .sub_path = path, .data = out.written() }); - } else try stdout.writeAll(out.written()); - return; + if (opts.preprocess) { + if (opts.pp_output) |path| { + try Io.Dir.cwd().writeFile(cli.io, .{ .sub_path = path, .data = out.written() }); + } else try stdout.writeAll(out.written()); + return; + } + if (opts.parse or opts.sema) return; + if (profile == null) return cli.fail("missing -T ", .{}); + return cli.fail("code generation is not implemented yet: the input was checked but no output was written (use -zdxc-empty for a placeholder shader)", .{}); } const prof = profile orelse return cli.fail("missing -T ", .{}); diff --git a/src/options.zig b/src/options.zig index 262e314..5f098ce 100644 --- a/src/options.zig +++ b/src/options.zig @@ -27,6 +27,7 @@ pub const Extra = enum { zdxc_lex, zdxc_parse, zdxc_ast, + zdxc_sema, fcolor_diagnostics, fno_color_diagnostics, }; @@ -37,6 +38,7 @@ const extra_options = [_]struct { id: Extra, spelling: []const u8, help: []const .{ .id = .zdxc_lex, .spelling = "zdxc-lex", .help = "Print the input's tokens, one per line (development)" }, .{ .id = .zdxc_parse, .spelling = "zdxc-parse", .help = "Preprocess and parse the input, reporting syntax errors only (development)" }, .{ .id = .zdxc_ast, .spelling = "zdxc-ast", .help = "Preprocess, parse and dump the syntax tree (development)" }, + .{ .id = .zdxc_sema, .spelling = "zdxc-sema", .help = "Run the front end through semantic analysis only (development)" }, .{ .id = .fcolor_diagnostics, .spelling = "fcolor-diagnostics", .help = "Always use colors in diagnostics" }, .{ .id = .fno_color_diagnostics, .spelling = "fno-color-diagnostics", .help = "Never use colors in diagnostics" }, }; diff --git a/src/root.zig b/src/root.zig index e0beeb5..fa3d9c9 100644 --- a/src/root.zig +++ b/src/root.zig @@ -23,6 +23,12 @@ pub const dxil = struct { pub const shader = @import("dxil/shader.zig"); }; +pub const sema = struct { + pub const types = @import("sema/types.zig"); + pub const intrinsics = @import("sema/intrinsics.zig"); + pub const Sema = @import("sema/sema.zig").Sema; +}; + pub const spirv = struct { pub const builder = @import("spirv/builder.zig"); }; @@ -33,6 +39,8 @@ test { const std = @import("std"); std.testing.refAllDecls(front); std.testing.refAllDecls(dxil); + _ = @import("sema/types.zig"); + _ = @import("sema/sema.zig"); std.testing.refAllDecls(spirv); _ = @import("diag.zig"); _ = @import("options.zig"); diff --git a/src/sema/intrinsics.zig b/src/sema/intrinsics.zig new file mode 100644 index 0000000..8514293 --- /dev/null +++ b/src/sema/intrinsics.zig @@ -0,0 +1,367 @@ +//! Intrinsic and builtin-method overload resolution against the table +//! generated from dxc's gen_intrin_main.txt. +//! +//! Each declaration's types are indexed 0 (return) .. n (parameters). +//! `$match` links a type's layout to type L and its component to +//! type C (`$typeN` = `$match`); unlinked types are their own group. +//! For each group the component is the common type of its arguments, +//! coerced into the group's class (`float_like`, `numeric`, `any_int`...), +//! and the layout is taken from the declared dimensions (binding symbolic +//! sizes like `c` and `r2` across arguments) or, for `<>`, from the +//! arguments. Candidates are ranked by total conversion cost. + +const std = @import("std"); +const Allocator = std.mem.Allocator; +const table = @import("intrinsics_table"); +const types = @import("types.zig"); +const source = @import("../front/source.zig"); +const TypeId = types.TypeId; +const TypeTable = types.TypeTable; +const Scalar = types.Scalar; + +pub const ArgInfo = struct { + ty: TypeId, + /// Assignable (for out / inout parameters). + lvalue: bool, + loc: source.Loc, + /// Names (part of) a groupshared variable. + groupshared: bool = false, +}; + +pub const Db = struct { + /// "Namespace::name" -> indices into table.intrinsics. + by_name: std.StringHashMapUnmanaged(std.ArrayList(u16)) = .empty, + /// Plain intrinsic names (Intrinsics / VkIntrinsics / DxIntrinsics). + globals: std.StringHashMapUnmanaged(void) = .empty, + vk_globals: std.StringHashMapUnmanaged(void) = .empty, + + pub fn init(a: Allocator) !Db { + var db: Db = .{}; + for (table.intrinsics, 0..) |it, i| { + const key = try std.fmt.allocPrint(a, "{s}::{s}", .{ it.namespace, it.name }); + const gop = try db.by_name.getOrPut(a, key); + if (!gop.found_existing) gop.value_ptr.* = .empty; + try gop.value_ptr.append(a, @intCast(i)); + if (std.mem.eql(u8, it.namespace, "Intrinsics") or std.mem.eql(u8, it.namespace, "DxIntrinsics")) try db.globals.put(a, it.name, {}); + if (std.mem.eql(u8, it.namespace, "VkIntrinsics")) try db.vk_globals.put(a, it.name, {}); + } + return db; + } + + pub fn has(db: *const Db, name: []const u8, spirv: bool) bool { + return db.globals.contains(name) or (spirv and db.vk_globals.contains(name)); + } + + fn candidates(db: *const Db, a: Allocator, ns: []const u8, name: []const u8) ![]const u16 { + var list: std.ArrayList(u16) = .empty; + const namespaces: []const []const u8 = if (std.mem.eql(u8, ns, "Intrinsics")) &.{ "Intrinsics", "DxIntrinsics" } else &.{ns}; + for (namespaces) |n| { + const key = try std.fmt.allocPrint(a, "{s}::{s}", .{ n, name }); + if (db.by_name.get(key)) |l| try list.appendSlice(a, l.items); + } + return list.items; + } + + /// Resolve a call; reports a diagnostic and returns the error type when + /// no overload matches. `sema` is the calling Sema (for conversions and + /// diagnostics); `object` is the method's object type, if any. + pub fn resolve(db: *const Db, sema: anytype, loc: source.Loc, ns: []const u8, name: []const u8, object: ?TypeId, args: []const ArgInfo, explicit: ?TypeId) !TypeId { + const cands = try db.candidates(sema.arena, ns, name); + if (cands.len == 0) { + if (object) |o| { + sema.err(loc, "no member named '{s}' in '{s}'", .{ name, sema.typeName(o) }); + } else sema.err(loc, "use of undeclared identifier '{s}'", .{name}); + return TypeTable.error_type; + } + var best: ?Match = null; + for (cands) |ci| { + const m = try matchOne(sema, &table.intrinsics[ci], object, args, explicit) orelse continue; + if (best == null or m.cost < best.?.cost) best = m; + } + // vk::static_pointer_cast / reinterpret_pointer_cast return a + // BufferPointer of the template argument: not modelled yet. + if (best != null and (std.mem.eql(u8, name, "static_pointer_cast") or std.mem.eql(u8, name, "reinterpret_pointer_cast"))) return TypeTable.error_type; + const m = best orelse { + sema.err(loc, "no matching function for call to '{s}'", .{name}); + return TypeTable.error_type; + }; + for (args, 0..) |a, i| { + if (i < m.out_params.len and m.out_params[i] and !a.lvalue) { + sema.err(a.loc, "cannot bind non-lvalue argument to out parameter", .{}); + } + } + return m.ret; + } +}; + +const Match = struct { + ret: TypeId, + cost: u32, + out_params: []const bool, +}; + +const Layout = struct { rows: u8, cols: u8, kind: TypeTable.Shape }; + +/// Symbolic dimension bindings (`r`, `c`, `r2`, `c2`, ...). +const Bindings = struct { + names: [8][]const u8 = undefined, + values: [8]u8 = undefined, + n: usize = 0, + + fn get(b: *const Bindings, name: []const u8) ?u8 { + for (b.names[0..b.n], b.values[0..b.n]) |k, v| if (std.mem.eql(u8, k, name)) return v; + return null; + } + + /// Bind or check; false on conflict. + fn bind(b: *Bindings, name: []const u8, v: u8) bool { + if (b.get(name)) |old| return old == v; + if (b.n == b.names.len) return false; + b.names[b.n] = name; + b.values[b.n] = v; + b.n += 1; + return true; + } +}; + +fn matchOne(sema: anytype, it: *const table.Intrinsic, object: ?TypeId, args: []const ArgInfo, explicit: ?TypeId) !?Match { + const t = &sema.types; + if (args.len < it.params.len) return null; + if (args.len > it.params.len and !it.varargs) return null; + const n = it.params.len + 1; + const specs = try sema.arena.alloc(*const table.Spec, n); + specs[0] = &it.ret; + for (it.params, 1..) |*p, i| specs[i] = p; + + const obj_elem: TypeId = if (object) |o| switch (t.get(o)) { + .resource => |r| r.elem, + .stream => |s| s.elem, + .patch => |p| p.elem, + else => TypeTable.error_type, + } else TypeTable.error_type; + + // Groups: index of the type that owns a type's layout / component. + const comp_group = try sema.arena.alloc(usize, n); + const layout_group = try sema.arena.alloc(usize, n); + for (specs, 0..) |s, i| { + comp_group[i] = i; + layout_group[i] = i; + if (s.special == .type_n) { + comp_group[i] = s.type_n; + layout_group[i] = s.type_n; + } else { + if (s.match_comp) |c| if (c >= 0 and c < n) { + comp_group[i] = @intCast(c); + }; + if (s.match_layout) |l| if (l >= 0 and l < n) { + layout_group[i] = @intCast(l); + }; + } + } + + // Components: common type of the arguments in each group. + const group_comp = try sema.arena.alloc(?Scalar, n); + @memset(group_comp, null); + for (args[0..it.params.len], 1..) |a, i| { + const g = comp_group[i]; + const c = t.component(a.ty) orelse continue; + group_comp[g] = if (group_comp[g]) |old| common(old, c) else c; + } + + var bindings: Bindings = .{}; + var cost: u32 = 0; + const out_params = try sema.arena.alloc(bool, args.len); + @memset(out_params, false); + + // Parameter types, checked against the arguments. + for (args, 0..) |a, ai| { + if (ai >= it.params.len) break; // varargs: anything goes + const i = ai + 1; + const s = specs[i]; + out_params[ai] = s.qual == .out or s.qual == .inout or s.qual == .ref; + const pt = try paramType(sema, specs, i, comp_group, layout_group, group_comp, &bindings, args, obj_elem, explicit) orelse return null; + if (pt == TypeTable.error_type) continue; // unconstrained object / unknown class + const c = sema.conversionCost(a.ty, pt) orelse return null; + cost += c; + } + + // Return type. + const ret = try paramType(sema, specs, 0, comp_group, layout_group, group_comp, &bindings, args, obj_elem, explicit) orelse return null; + return .{ .ret = ret, .cost = cost, .out_params = out_params }; +} + +/// The concrete type of spec `i`, or null if the arguments cannot fit. +/// Returns the error type for types zdxc does not constrain (objects, +/// strings, classes it does not model). +fn paramType( + sema: anytype, + specs: []const *const table.Spec, + i: usize, + comp_group: []const usize, + layout_group: []const usize, + group_comp: []const ?Scalar, + bindings: *Bindings, + args: []const ArgInfo, + obj_elem: TypeId, + explicit: ?TypeId, +) !?TypeId { + const t = &sema.types; + const s = specs[i]; + switch (s.special) { + .class_t => return obj_elem, + // `$funcT`: the explicit template argument; without one, a return + // defaults to uint (ByteAddressBuffer.Load) and a parameter is + // unconstrained (Store of a struct). + .func_t => return explicit orelse if (i == 0) try t.scalar(.uint) else TypeTable.error_type, + else => {}, + } + // Owner specs define the class and layout of linked types. `$match` + // links the layout's kind; explicit dimensions on the spec itself win + // (`$match<2, 2> float<2> ddx`, transpose's `any`). + const cs = specs[comp_group[i]]; + const ls = if (s.dims.len > 0) s else specs[layout_group[i]]; + + // Non-numeric classes. + const base = if (cs.special == .none) cs.base else s.base; + if (!std.mem.eql(u8, base, "void") and !isNumericClass(base)) { + // Objects (samplers are checked) and classes zdxc does not model + // (HitObject, node records, LinAlg...): unconstrained. + if (i > 0 and i - 1 < args.len and isObjectClass(base)) return objectCheck(sema, base, args[i - 1].ty); + return TypeTable.error_type; + } + if (isObjectClass(base)) { + if (i > 0 and i - 1 < args.len) return objectCheck(sema, base, args[i - 1].ty); + return TypeTable.error_type; + } + if (std.mem.eql(u8, base, "void")) { + // `$match<0, -1> void<4>`: the object's component type. + if (s.match_comp != null and s.match_comp.? == -1 and obj_elem != TypeTable.error_type) { + const comp = t.component(obj_elem) orelse return TypeTable.error_type; + return try layoutType(sema, ls, comp, layout_group[i], bindings, args); + } + if (s.match_layout != null and s.match_layout.? == -1) return obj_elem; + return TypeTable.void_type; + } + + var comp = classComponent(base, group_comp[comp_group[i]]) orelse return null; + if (comp.isLiteral()) comp = comp.concrete(); + return try layoutType(sema, ls, comp, layout_group[i], bindings, args); +} + +fn layoutType(sema: anytype, ls: *const table.Spec, comp: Scalar, group: usize, bindings: *Bindings, args: []const ArgInfo) !?TypeId { + const t = &sema.types; + if (ls.any_layout) { + // `<>`: the shape of the group's arguments (scalars splat to the + // widest one). + var shape: ?TypeTable.Shape = null; + if (group > 0 and group - 1 < args.len) shape = t.shape(args[group - 1].ty); + if (shape == null) { + // Look for any argument in this layout group. + return try t.scalar(comp); + } + return try t.withShape(comp, shape.?); + } + if (ls.dims.len == 0) return try t.scalar(comp); + const arg_shape: ?TypeTable.Shape = if (group > 0 and group - 1 < args.len) t.shape(args[group - 1].ty) else null; + if (ls.dims.len == 1) { + const len = dimValue(ls.dims[0], bindings, if (arg_shape) |sh| (if (sh.kind == .vector) sh.cols else if (sh.kind == .scalar) 1 else sh.cols) else null) orelse return null; + if (len < 1 or len > 4) return null; + return try t.vector(comp, len); + } + const rows = dimValue(ls.dims[0], bindings, if (arg_shape) |sh| sh.rows else null) orelse return null; + const cols = dimValue(ls.dims[1], bindings, if (arg_shape) |sh| sh.cols else null) orelse return null; + if (rows < 1 or rows > 4 or cols < 1 or cols > 4) return null; + return try t.matrix(comp, rows, cols); +} + +/// A layout dimension: a number, or a symbol bound from the argument. +fn dimValue(dim: []const u8, b: *Bindings, from_arg: ?u8) ?u8 { + if (std.fmt.parseInt(u8, dim, 10)) |v| return v else |_| {} + if (b.get(dim)) |v| return v; + const v = from_arg orelse return null; + if (!b.bind(dim, v)) return null; + return v; +} + +fn common(a: Scalar, b: Scalar) Scalar { + return Scalar.combine(a, b); +} + +/// The component a class gives for argument component `c` (null: no +/// argument decided it). Concrete classes ignore the arguments. +fn classComponent(base: []const u8, c: ?Scalar) ?Scalar { + const fixed = [_]struct { []const u8, Scalar }{ + .{ "bool", .bool }, .{ "int", .int }, .{ "uint", .uint }, .{ "float", .float }, + .{ "double", .double }, .{ "u64", .uint64 }, .{ "i64", .int64 }, .{ "int16_t", .int16 }, + .{ "uint16_t", .uint16 }, .{ "float16_t", .float16 }, .{ "half", .half }, .{ "int64_t", .int64 }, + .{ "uint64_t", .uint64 }, .{ "uint_only", .uint }, .{ "int32_only", .int }, .{ "int64_only", .int64 }, + .{ "any_int32", .int }, .{ "any_int64", .int64 }, .{ "uint_only32", .uint }, .{ "p32i8", .uint }, + .{ "p32u8", .uint }, .{ "int8_t4_packed", .int8_4packed }, .{ "uint8_t4_packed", .uint8_4packed }, + }; + for (fixed) |f| { + if (std.mem.eql(u8, f[0], base)) { + // Classes that only fix the width keep the argument's type + // when it fits (int32_only accepts int and uint). + if (c) |arg| { + if (std.mem.eql(u8, base, "int32_only") or std.mem.eql(u8, base, "any_int32") or std.mem.eql(u8, base, "uint_only")) { + if (arg.isInt() and arg.size() == 4) return arg.concrete(); + } + if (std.mem.eql(u8, base, "int64_only") or std.mem.eql(u8, base, "any_int64")) { + if (arg.isInt() and arg.size() == 8) return arg; + } + } + return f[1]; + } + } + const arg = c orelse return switch (base.len) { + else => if (std.mem.eql(u8, base, "float_like") or std.mem.eql(u8, base, "any_float")) Scalar.float else Scalar.int, + }; + if (std.mem.eql(u8, base, "float_like") or std.mem.eql(u8, base, "any_float") or std.mem.eql(u8, base, "float32_only") or std.mem.eql(u8, base, "fldbl") or std.mem.eql(u8, base, "float_like16")) { + return if (arg.isFloat()) arg.concrete() else .float; + } + if (std.mem.eql(u8, base, "any_int") or std.mem.eql(u8, base, "any_int16or32") or std.mem.eql(u8, base, "sint16or32_only") or std.mem.eql(u8, base, "int16_only")) { + return if (arg.isInt()) arg.concrete() else .int; + } + if (std.mem.eql(u8, base, "numeric32_only")) return if (arg.size() == 4 and arg != .bool) arg.concrete() else if (arg.isFloat()) .float else .int; + if (std.mem.eql(u8, base, "numeric16_only")) return if (arg.size() == 2) arg else .int16; + if (std.mem.eql(u8, base, "numeric")) return if (arg == .bool) .int else arg.concrete(); + // any, any_sampler... and unmodelled classes: keep the argument's type. + return arg.concrete(); +} + +/// Component classes that denote numeric types. +fn isNumericClass(base: []const u8) bool { + const names = [_][]const u8{ + "bool", "int", "uint", "float", "double", "u64", "i64", + "int16_t", "uint16_t", "float16_t", "half", "int64_t", "uint64_t", "uint_only", + "int32_only", "int64_only", "any_int32", "any_int64", "uint_only32", "p32i8", "p32u8", + "int8_t4_packed", "uint8_t4_packed", "float_like", "any_float", "float32_only", "fldbl", "float_like16", + "any_int", "any_int16or32", "sint16or32_only", "int16_only", "numeric32_only", "numeric16_only", "numeric", + "any", "float16_t_only", "float32_t_only", "int16_t_only", "uint16_t_only", + }; + for (names) |k| if (std.mem.eql(u8, k, base)) return true; + return false; +} + +fn isObjectClass(base: []const u8) bool { + const names = [_][]const u8{ + "sampler", "sampler_cmp", "any_sampler", "sampler1d", "sampler2d", "sampler3d", "sampler_cube", "string", "wave", + "ray_desc", "acceleration_struct", "udt", "resource", "LinAlg", "LinAlgMatrix", "node_record_or_uav", "any_node_output_record", "Texture1D", + "Texture2D", "Texture2DArray", "Texture3D", "TextureCube", + }; + for (names) |k| if (std.mem.eql(u8, k, base)) return true; + return false; +} + +/// Object parameters: check samplers; anything else is accepted. +fn objectCheck(sema: anytype, base: []const u8, arg: TypeId) ?TypeId { + const t = &sema.types; + const ty = t.get(arg); + if (std.mem.eql(u8, base, "sampler") or std.mem.eql(u8, base, "sampler_cmp") or std.mem.eql(u8, base, "any_sampler")) { + if (ty != .sampler) return if (ty == .@"error") TypeTable.error_type else null; + if (std.mem.eql(u8, base, "sampler_cmp") and !ty.sampler.comparison) return null; + if (std.mem.eql(u8, base, "sampler") and ty.sampler.comparison) return null; + return TypeTable.error_type; + } + return TypeTable.error_type; +} diff --git a/src/sema/sema.zig b/src/sema/sema.zig new file mode 100644 index 0000000..26be702 --- /dev/null +++ b/src/sema/sema.zig @@ -0,0 +1,2325 @@ +//! Semantic analysis for HLSL 2021: name resolution, types, implicit +//! conversions, overload resolution (user functions, intrinsics, builtin +//! methods) and the HLSL-specific rules, annotating the AST with types. +//! +//! Where a construct is not modelled yet, Sema falls back to the error type +//! without a diagnostic so that unimplemented features never produce false +//! errors; follow-on errors are suppressed for error-typed expressions. + +const std = @import("std"); +const Allocator = std.mem.Allocator; +const ast = @import("../front/ast.zig"); +const source = @import("../front/source.zig"); +const diag = @import("../diag.zig"); +const types = @import("types.zig"); +const intrinsics = @import("intrinsics.zig"); +const Loc = source.Loc; +const TypeId = types.TypeId; +const TypeTable = types.TypeTable; +const Scalar = types.Scalar; + +pub const Options = struct { + /// Entry point to require (null: library or check-only). + entry: ?[]const u8 = null, + spirv: bool = false, + enable_16bit: bool = false, +}; + +pub const Storage = enum { global_uniform, global_static, groupshared, cbuffer, local, local_static, param, constant }; + +pub const Variable = struct { + name: []const u8, + type: TypeId, + quals: ast.Qualifiers, + storage: Storage, + loc: Loc, + /// Not assignable (const, uniform, cbuffer member, `in` resources...). + read_only: bool, + /// Initializer of `static const` / `const` variables, for constants. + init: ?*ast.Expr = null, +}; + +pub const Param = struct { + name: []const u8, + type: TypeId, + dir: enum { in, out, inout }, + has_default: bool, + /// `groupshared` parameter (SM 6.8 groupshared arguments). + groupshared: bool = false, +}; + +pub const Function = struct { + name: []const u8, + decl: *const ast.FuncDecl, + loc: Loc, + ret: TypeId, + params: []Param, + defined: bool, + /// Struct the method belongs to. + owner: ?*types.StructInfo = null, +}; + +pub const FuncSet = struct { + funcs: std.ArrayList(*Function) = .empty, +}; + +pub const Symbol = union(enum) { + variable: *Variable, + functions: *FuncSet, + type: TypeId, + namespace: *Scope, + enumerator: struct { type: TypeId, value: i64 }, + /// A template (milestone 0.2); uses report "not supported yet". + template: *const ast.Decl, +}; + +pub const Scope = struct { + parent: ?*Scope, + syms: std.StringHashMapUnmanaged(Symbol) = .empty, + kind: enum { global, namespace, function, block, @"struct" } = .block, + name: []const u8 = "", +}; + +/// Per-struct data kept by Sema (methods, nested scope). +const StructSema = struct { + scope: *Scope, + decl: *const ast.Decl, +}; + +/// Result of checking an expression. +const Typed = struct { + ty: TypeId, + lvalue: bool = false, + read_only: bool = false, + /// The expression names a function or overload set (only valid as a + /// call's callee). + callee: ?Callee = null, +}; + +const Callee = union(enum) { + functions: *FuncSet, + intrinsic: []const u8, + /// `obj.Method`: methods of a builtin object, or of a struct. + method: struct { object: TypeId, name: []const u8, object_lvalue: bool }, + type: TypeId, + /// A callable zdxc does not model yet: the call is unconstrained. + unknown, +}; + +pub const Sema = struct { + arena: Allocator, + diags: *diag.Diagnostics, + types: TypeTable, + opts: Options, + global: *Scope, + scope: *Scope, + current_fn: ?*Function = null, + current_struct: ?*types.StructInfo = null, + loop_depth: u32 = 0, + switch_depth: u32 = 0, + intrinsic_db: intrinsics.Db, + enum_scopes: std.AutoHashMapUnmanaged(*types.EnumInfo, *Scope) = .empty, + + pub fn init(arena: Allocator, diags: *diag.Diagnostics, opts: Options) !Sema { + const global = try arena.create(Scope); + global.* = .{ .parent = null, .kind = .global }; + var s: Sema = .{ + .arena = arena, + .diags = diags, + .types = try TypeTable.init(arena), + .opts = opts, + .global = global, + .scope = global, + .intrinsic_db = try intrinsics.Db.init(arena), + }; + try s.declareBuiltins(); + return s; + } + + // ------------------------------------------------------------------ + // Diagnostics + + pub fn err(s: *Sema, loc: Loc, comptime fmt: []const u8, args: anytype) void { + _ = s.diags.report(.{ .severity = .@"error", .loc = loc }, fmt, args); + } + + fn warn(s: *Sema, loc: Loc, group: []const u8, comptime fmt: []const u8, args: anytype) void { + _ = s.diags.report(.{ .severity = .warning, .loc = loc, .group = group }, fmt, args); + } + + pub fn typeName(s: *Sema, ty: TypeId) []const u8 { + return s.types.format(s.arena, ty) catch "?"; + } + + // ------------------------------------------------------------------ + // Scopes + + fn pushScope(s: *Sema, kind: @FieldType(Scope, "kind")) !*Scope { + const sc = try s.arena.create(Scope); + sc.* = .{ .parent = s.scope, .kind = kind }; + s.scope = sc; + return sc; + } + + fn popScope(s: *Sema) void { + s.scope = s.scope.parent.?; + } + + fn declare(s: *Sema, name: []const u8, sym: Symbol, loc: Loc) !void { + if (name.len == 0) return; + const gop = try s.scope.syms.getOrPut(s.arena, name); + if (gop.found_existing) { + // Functions overload; anything else is a redefinition. + if (sym == .functions and gop.value_ptr.* == .functions) return; + // Template overloads and specializations (milestone 0.2): + // plain functions take precedence over templates of the same name. + if (sym == .template or gop.value_ptr.* == .template) { + if (gop.value_ptr.* != .functions) gop.value_ptr.* = sym; + return; + } + if (s.scope.kind == .global or s.scope.kind == .namespace or s.scope.kind == .@"struct" or s.scope.kind == .block or s.scope.kind == .function) { + s.err(loc, "redefinition of '{s}'", .{name}); + } + } + gop.value_ptr.* = sym; + } + + fn lookup(s: *Sema, name: []const u8) ?Symbol { + var sc: ?*Scope = s.scope; + while (sc) |c| : (sc = c.parent) { + if (c.syms.get(name)) |sym| return sym; + } + return null; + } + + /// Resolve a possibly qualified name. + fn lookupName(s: *Sema, n: ast.Name) ?Symbol { + if (n.parts.len == 1) return s.lookup(n.parts[0]); + var sc: *Scope = if (n.parts[0].len == 0) s.global else blk: { + const first = s.lookup(n.parts[0]) orelse return null; + break :blk s.scopeOf(first) orelse return null; + }; + const start: usize = 1; + for (n.parts[start .. n.parts.len - 1]) |part| { + const sym = sc.syms.get(part) orelse return null; + sc = s.scopeOf(sym) orelse return null; + } + return sc.syms.get(n.last()); + } + + /// The scope named by a namespace, struct or enum symbol. + fn scopeOf(s: *Sema, sym: Symbol) ?*Scope { + return switch (sym) { + .namespace => |sc| sc, + .type => |t| switch (s.types.get(t)) { + .@"struct" => |info| if (info.sema) |p| @as(*StructSema, @ptrCast(@alignCast(p))).scope else null, + .@"enum" => |e| s.enum_scopes.get(e), + else => null, + }, + else => null, + }; + } + + // ------------------------------------------------------------------ + // Builtins + + fn declareBuiltins(s: *Sema) !void { + // RayDesc and BuiltInTriangleIntersectionAttributes are structs. + const f3 = try s.types.vector(.float, 3); + const f = try s.types.scalar(.float); + const ray = try s.arena.create(types.StructInfo); + ray.* = .{ .name = "RayDesc", .complete = true }; + try ray.fields.appendSlice(s.arena, &.{ .{ .name = "Origin", .type = f3 }, .{ .name = "TMin", .type = f }, .{ .name = "Direction", .type = f3 }, .{ .name = "TMax", .type = f } }); + try s.global.syms.put(s.arena, "RayDesc", .{ .type = try s.types.intern(.{ .@"struct" = ray }) }); + const attr = try s.arena.create(types.StructInfo); + attr.* = .{ .name = "BuiltInTriangleIntersectionAttributes", .complete = true }; + try attr.fields.append(s.arena, .{ .name = "barycentrics", .type = try s.types.vector(.float, 2) }); + try s.global.syms.put(s.arena, "BuiltInTriangleIntersectionAttributes", .{ .type = try s.types.intern(.{ .@"struct" = attr }) }); + + // SM 6.6 descriptor heaps. + for ([_]struct { []const u8, bool }{ .{ "ResourceDescriptorHeap", false }, .{ "SamplerDescriptorHeap", true } }) |h| { + const v = try s.arena.create(Variable); + v.* = .{ .name = h[0], .type = try s.types.intern(.{ .descriptor_heap = .{ .sampler = h[1] } }), .quals = .{}, .storage = .global_static, .loc = .none, .read_only = true }; + try s.global.syms.put(s.arena, h[0], .{ .variable = v }); + } + + // Builtin `static const uint` constants and the pseudo-enum typedefs + // they belong to (from dxc's ASTContextHLSL.cpp / DxilConstants.h). + const uint_ty = try s.types.scalar(.uint); + for (builtin_constants) |c| try s.global.syms.put(s.arena, c[0], .{ .enumerator = .{ .type = uint_ty, .value = c[1] } }); + for ([_][]const u8{ "RAY_FLAG", "RAYQUERY_FLAG", "COMMITTED_STATUS", "CANDIDATE_TYPE", "MEMORY_TYPE_FLAG", "BARRIER_SEMANTIC_FLAG" }) |n| { + try s.global.syms.put(s.arena, n, .{ .type = uint_ty }); + } + + // The implicit `vk` namespace (SPIR-V only): memory scope constants. + if (s.opts.spirv) { + const vk = try s.arena.create(Scope); + vk.* = .{ .parent = s.global, .kind = .namespace, .name = "vk" }; + for ([_]struct { []const u8, i64 }{ .{ "CrossDeviceScope", 0 }, .{ "DeviceScope", 1 }, .{ "WorkgroupScope", 2 }, .{ "SubgroupScope", 3 }, .{ "InvocationScope", 4 }, .{ "QueueFamilyScope", 5 } }) |c| { + try vk.syms.put(s.arena, c[0], .{ .enumerator = .{ .type = uint_ty, .value = c[1] } }); + } + try s.global.syms.put(s.arena, "vk", .{ .namespace = vk }); + } + } + + const builtin_constants = [_]struct { []const u8, i64 }{ + .{ "RAY_FLAG_NONE", 0x00 }, .{ "RAY_FLAG_FORCE_OPAQUE", 0x01 }, + .{ "RAY_FLAG_FORCE_NON_OPAQUE", 0x02 }, .{ "RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH", 0x04 }, + .{ "RAY_FLAG_SKIP_CLOSEST_HIT_SHADER", 0x08 }, .{ "RAY_FLAG_CULL_BACK_FACING_TRIANGLES", 0x10 }, + .{ "RAY_FLAG_CULL_FRONT_FACING_TRIANGLES", 0x20 }, .{ "RAY_FLAG_CULL_OPAQUE", 0x40 }, + .{ "RAY_FLAG_CULL_NON_OPAQUE", 0x80 }, .{ "RAY_FLAG_SKIP_TRIANGLES", 0x100 }, + .{ "RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES", 0x200 }, .{ "RAY_FLAG_FORCE_OMM_2_STATE", 0x400 }, + .{ "RAYQUERY_FLAG_NONE", 0 }, .{ "RAYQUERY_FLAG_ALLOW_OPACITY_MICROMAPS", 1 }, + .{ "COMMITTED_NOTHING", 0 }, .{ "COMMITTED_TRIANGLE_HIT", 1 }, + .{ "COMMITTED_PROCEDURAL_PRIMITIVE_HIT", 2 }, .{ "CANDIDATE_NON_OPAQUE_TRIANGLE", 0 }, + .{ "CANDIDATE_PROCEDURAL_PRIMITIVE", 1 }, .{ "HIT_KIND_NONE", 0x00 }, + .{ "HIT_KIND_TRIANGLE_FRONT_FACE", 0xFE }, .{ "HIT_KIND_TRIANGLE_BACK_FACE", 0xFF }, + .{ "CLUSTER_ID_INVALID", 0xffffffff }, .{ "STATE_OBJECT_FLAGS_ALLOW_LOCAL_DEPENDENCIES_ON_EXTERNAL_DEFINITONS", 0x1 }, + .{ "STATE_OBJECT_FLAGS_ALLOW_EXTERNAL_DEPENDENCIES_ON_LOCAL_DEFINITIONS", 0x2 }, .{ "STATE_OBJECT_FLAG_ALLOW_LOCAL_DEPENDENCIES_ON_EXTERNAL_DEFINITONS", 0x1 }, + .{ "STATE_OBJECT_FLAG_ALLOW_EXTERNAL_DEPENDENCIES_ON_LOCAL_DEFINITIONS", 0x2 }, .{ "STATE_OBJECT_FLAG_ALLOW_STATE_OBJECT_ADDITIONS", 0x4 }, + .{ "RAYTRACING_PIPELINE_FLAG_NONE", 0x0 }, .{ "RAYTRACING_PIPELINE_FLAG_SKIP_TRIANGLES", 0x100 }, + .{ "RAYTRACING_PIPELINE_FLAG_SKIP_PROCEDURAL_PRIMITIVES", 0x200 }, .{ "RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS", 0x400 }, + .{ "SAMPLER_FEEDBACK_MIN_MIP", 0 }, .{ "SAMPLER_FEEDBACK_MIP_REGION_USED", 1 }, + .{ "UAV_MEMORY", 0x1 }, .{ "GROUP_SHARED_MEMORY", 0x2 }, + .{ "NODE_INPUT_MEMORY", 0x4 }, .{ "NODE_OUTPUT_MEMORY", 0x8 }, + .{ "ALL_MEMORY", 0xF }, .{ "GROUP_SYNC", 0x1 }, + .{ "GROUP_SCOPE", 0x2 }, .{ "DEVICE_SCOPE", 0x4 }, + .{ "REORDER_SCOPE", 0x8 }, + }; + + // ------------------------------------------------------------------ + // Types + + /// Scalar, vector (`float4`) or matrix (`float4x4`) named by `n`. + fn numericTypeByName(s: *Sema, n: []const u8) !?TypeId { + if (s.scalarByName(n)) |sc| return try s.types.scalar(sc); + if (n.len < 2) return null; + const last = n[n.len - 1]; + if (last < '1' or last > '4') return null; + if (n.len >= 4 and n[n.len - 2] == 'x' and n[n.len - 3] >= '1' and n[n.len - 3] <= '4') { + if (s.scalarByName(n[0 .. n.len - 3])) |sc| return try s.types.matrix(sc, n[n.len - 3] - '0', last - '0'); + } + if (s.scalarByName(n[0 .. n.len - 1])) |sc| return try s.types.vector(sc, last - '0'); + return null; + } + + /// `half` is `float16_t` with -enable-16bit-types, else a distinct + /// 32-bit partial-precision float. + fn scalarByName(s: *const Sema, n: []const u8) ?Scalar { + const sc = Scalar.fromName(n) orelse return null; + return if (sc == .half and s.opts.enable_16bit) .float16 else sc; + } + + fn constArg(s: *Sema, arg: ast.TemplateArg) ?i64 { + return switch (arg) { + .expr => |e| s.evalInt(e), + .type => null, + }; + } + + fn typeArg(s: *Sema, arg: ast.TemplateArg) !?TypeId { + return switch (arg) { + .type => |t| try s.resolveType(t), + .expr => |e| blk: { + // A bare name parsed as an expression may still be a type. + if (e.kind == .name) { + if (s.lookupName(e.kind.name)) |sym| if (sym == .type) break :blk sym.type; + } + break :blk null; + }, + }; + } + + pub fn resolveType(s: *Sema, t: *const ast.TypeRef) Allocator.Error!TypeId { + const base = if (t.decltype) |e| (try s.expr(e)).ty else try s.resolveTypeName(t); + var ty = base; + // Array dimensions on template arguments (`float[3]`). + var i = t.array_dims.len; + while (i > 0) { + i -= 1; + ty = try s.types.array(ty, try s.arrayLen(t.array_dims[i])); + } + return ty; + } + + fn resolveTypeName(s: *Sema, t: *const ast.TypeRef) Allocator.Error!TypeId { + const n = t.name.last(); + const args = t.args; + // User types may reuse builtin object names (`struct sampler2D`). + if (args.len == 0 and t.name.parts.len == 1) { + if (s.lookup(n)) |sym| if (sym == .type) return sym.type; + } + if (t.name.parts.len == 1) { + if (try s.numericTypeByName(n)) |nt| return nt; + if (std.mem.eql(u8, n, "void")) return TypeTable.void_type; + if (std.mem.eql(u8, n, "string")) return s.types.intern(.string); + if (std.mem.eql(u8, n, "vector")) { + if (args.len == 0) return s.types.vector(.float, 4); + const elem = try s.typeArg(args[0]) orelse return TypeTable.error_type; + const len = if (args.len > 1) s.constArg(args[1]) orelse 4 else 4; + const comp = s.types.component(elem) orelse return TypeTable.error_type; + if (len < 1 or len > 4) return TypeTable.error_type; // long vectors: not modelled + return s.types.vector(comp, @intCast(len)); + } + if (std.mem.eql(u8, n, "matrix")) { + if (args.len == 0) return s.types.matrix(.float, 4, 4); + const elem = try s.typeArg(args[0]) orelse return TypeTable.error_type; + const r = if (args.len > 1) s.constArg(args[1]) orelse 4 else 4; + const c = if (args.len > 2) s.constArg(args[2]) orelse 4 else 4; + const comp = s.types.component(elem) orelse return TypeTable.error_type; + if (r < 1 or r > 4 or c < 1 or c > 4) return TypeTable.error_type; + return s.types.matrix(comp, @intCast(r), @intCast(c)); + } + if (std.mem.eql(u8, n, "SamplerState") or std.mem.eql(u8, n, "sampler") or std.mem.eql(u8, n, "sampler1D") or std.mem.eql(u8, n, "sampler2D") or std.mem.eql(u8, n, "sampler3D") or std.mem.eql(u8, n, "samplerCUBE") or std.mem.eql(u8, n, "sampler_state")) { + return s.types.intern(.{ .sampler = .{ .comparison = false } }); + } + if (std.mem.eql(u8, n, "SamplerComparisonState")) return s.types.intern(.{ .sampler = .{ .comparison = true } }); + if (types.ResourceKind.fromName(n)) |kind| { + var elem: TypeId = TypeTable.void_type; + if (args.len > 0) { + elem = try s.typeArg(args[0]) orelse TypeTable.error_type; + } else if (isTextureOrTypedBuffer(kind)) { + elem = try s.types.vector(.float, 4); // Texture2D == Texture2D + } + return s.types.intern(.{ .resource = .{ .kind = kind, .elem = elem, .name = n } }); + } + const streams = [_]struct { []const u8, @FieldType(@FieldType(types.Type, "stream"), "kind") }{ .{ "PointStream", .point }, .{ "LineStream", .line }, .{ "TriangleStream", .triangle } }; + for (streams) |st| if (std.mem.eql(u8, n, st[0])) { + const elem = if (args.len > 0) try s.typeArg(args[0]) orelse TypeTable.error_type else TypeTable.error_type; + return s.types.intern(.{ .stream = .{ .kind = st[1], .elem = elem } }); + }; + if (std.mem.eql(u8, n, "InputPatch") or std.mem.eql(u8, n, "OutputPatch")) { + const elem = if (args.len > 0) try s.typeArg(args[0]) orelse TypeTable.error_type else TypeTable.error_type; + const count: u32 = if (args.len > 1) @intCast(@max(0, s.constArg(args[1]) orelse 0)) else 0; + return s.types.intern(.{ .patch = .{ .output = n[0] == 'O', .elem = elem, .count = count } }); + } + } + if (s.lookupName(t.name)) |sym| switch (sym) { + .type => |ty| return ty, + .template => { + s.err(t.loc, "templates are not supported yet (planned for milestone 0.2)", .{}); + return TypeTable.error_type; + }, + else => { + s.err(t.loc, "'{s}' does not name a type", .{n}); + return TypeTable.error_type; + }, + }; + // Any other builtin object (RayQuery, node records, vk:: types...). + if (isOtherBuiltinObject(n)) { + var elem: TypeId = TypeTable.void_type; + if (args.len > 0) elem = try s.typeArg(args[0]) orelse TypeTable.void_type; + return s.types.intern(.{ .resource = .{ .kind = .other, .elem = elem, .name = n } }); + } + // The parser already reported unknown type names. + return TypeTable.error_type; + } + + fn arrayLen(s: *Sema, dim: ?*ast.Expr) Allocator.Error!u32 { + const e = dim orelse return 0; + _ = try s.expr(e); + const v = s.evalInt(e) orelse { + if (e.ty != TypeTable.error_type) s.err(e.loc, "array size is not a constant expression", .{}); + return 1; + }; + if (v <= 0) { + s.err(e.loc, "array size must be greater than zero", .{}); + return 1; + } + return @intCast(v); + } + + fn applyArrayDims(s: *Sema, base: TypeId, dims: []const ?*ast.Expr) Allocator.Error!TypeId { + var ty = base; + var i = dims.len; + while (i > 0) { + i -= 1; + ty = try s.types.array(ty, try s.arrayLen(dims[i])); + } + return ty; + } + + // ------------------------------------------------------------------ + // Constant evaluation (array sizes, case labels, template arguments) + + pub fn evalInt(s: *Sema, e: *const ast.Expr) ?i64 { + return switch (s.evalConst(e) orelse return null) { + .int => |v| v, + .float => |v| if (std.math.isFinite(v)) @intFromFloat(@trunc(v)) else null, + .bool => |b| @intFromBool(b), + }; + } + + const Const = union(enum) { int: i64, float: f64, bool: bool }; + + /// The intrinsics dxc folds in constant expressions: asuint, max, min. + fn evalIntrinsic(s: *Sema, callee: *const ast.Expr, args: []const *ast.Expr) ?Const { + if (callee.kind != .name or callee.kind.name.parts.len != 1) return null; + const name = callee.kind.name.parts[0]; + if (s.lookupName(callee.kind.name) != null) return null; // user function + if (std.mem.eql(u8, name, "asuint") and args.len == 1) { + return switch (s.evalConst(args[0]) orelse return null) { + .int => |v| .{ .int = @as(u32, @truncate(@as(u64, @bitCast(v)))) }, + .float => |v| .{ .int = @as(u32, @bitCast(@as(f32, @floatCast(v)))) }, + .bool => null, + }; + } + const is_max = std.mem.eql(u8, name, "max"); + if ((is_max or std.mem.eql(u8, name, "min")) and args.len == 2) { + const a = s.evalConst(args[0]) orelse return null; + const b = s.evalConst(args[1]) orelse return null; + if (a == .int and b == .int) return if ((a.int > b.int) == is_max) a else b; + if (a == .float and b == .float) return if ((a.float > b.float) == is_max) a else b; + } + return null; + } + + fn evalConst(s: *Sema, e: *const ast.Expr) ?Const { + return switch (e.kind) { + .int_lit => |t| .{ .int = parseIntLiteral(t) orelse return null }, + .float_lit => |t| .{ .float = parseFloatLiteral(t) orelse return null }, + .bool_lit => |b| .{ .bool = b }, + .is_same => .{ .bool = e.info != 0 }, + .call => |c| s.evalIntrinsic(c.callee, c.args), + .name => |n| blk: { + const sym = s.lookupName(n) orelse break :blk null; + switch (sym) { + .enumerator => |en| break :blk .{ .int = en.value }, + .variable => |v| { + if (!v.quals.@"const" or v.init == null) break :blk null; + break :blk s.evalConst(v.init.?); + }, + else => break :blk null, + } + }, + .unary => |u| blk: { + const v = s.evalConst(u.operand) orelse break :blk null; + break :blk switch (u.op) { + .plus => v, + .minus => switch (v) { + .int => |x| .{ .int = -%x }, + .float => |x| .{ .float = -x }, + .bool => |b| .{ .int = -@as(i64, @intFromBool(b)) }, + }, + .not => .{ .bool = !truthy(v) }, + .bit_not => switch (v) { + .int => |x| .{ .int = ~x }, + else => null, + }, + else => null, + }; + }, + .binary => |b| blk: { + const l = s.evalConst(b.lhs) orelse break :blk null; + const r = s.evalConst(b.rhs) orelse break :blk null; + break :blk evalBinary(b.op, l, r); + }, + .conditional => |c| blk: { + const cond = s.evalConst(c.cond) orelse break :blk null; + break :blk if (truthy(cond)) s.evalConst(c.then) else s.evalConst(c.@"else"); + }, + .cast => |c| s.evalConst(c.operand), + .construct => |c| if (c.args.len == 1) s.evalConst(c.args[0]) else null, + .sizeof_type, .sizeof_expr => null, + else => null, + }; + } + + // ------------------------------------------------------------------ + // Top level + + pub fn checkUnit(s: *Sema, tu: ast.TranslationUnit) Allocator.Error!void { + for (tu.decls) |d| try s.decl(d, .global); + if (s.opts.entry) |entry| { + const found = if (s.global.syms.get(entry)) |sym| sym == .functions else false; + if (!found) _ = s.diags.report(.{ .severity = .@"error", .loc = .none }, "missing entry point definition", .{}); + } + } + + const DeclCtx = enum { global, local, member, cbuffer }; + + fn decl(s: *Sema, d: *const ast.Decl, ctx: DeclCtx) Allocator.Error!void { + switch (d.kind) { + .@"var" => |*v| try s.varDecl(d, v, ctx), + .func => |*f| try s.funcDecl(d, f, null), + .@"struct" => |*st| try s.structDecl(d, st), + .cbuffer => |cb| { + for (cb.members) |m| try s.decl(m, .cbuffer); + if (cb.name.len > 0 and s.scope.syms.get(cb.name) == null) { + // The buffer name is not usable as a value; reserve it. + } + }, + .typedef => |td| { + if (td.template_params.len > 0) return s.declare(td.name, .{ .template = d }, d.loc); + if (ctx == .member) { + s.err(d.loc, "nested typedefs are not supported in HLSL", .{}); + return; + } + const base = try s.resolveType(td.type); + s.checkModifiers(.typedef, td.qual_words, d.loc, base); + const ty = try s.applyArrayDims(base, td.array_dims); + try s.declare(td.name, .{ .type = ty }, d.loc); + }, + .@"enum" => |e| try s.enumDecl(d, e), + .namespace => |n| { + const sc = blk: { + if (s.scope.syms.get(n.name)) |sym| if (sym == .namespace) break :blk sym.namespace; + const sc = try s.arena.create(Scope); + sc.* = .{ .parent = s.scope, .kind = .namespace, .name = n.name }; + try s.declare(n.name, .{ .namespace = sc }, d.loc); + break :blk sc; + }; + const saved = s.scope; + s.scope = sc; + defer s.scope = saved; + for (n.decls) |m| try s.decl(m, .global); + }, + .using_namespace => |n| { + // Bring the namespace's names into this scope. + const sym = s.lookupName(n) orelse return s.err(d.loc, "unknown namespace '{s}'", .{n.last()}); + if (sym != .namespace) return s.err(d.loc, "'{s}' is not a namespace", .{n.last()}); + var it = sym.namespace.syms.iterator(); + while (it.next()) |kv| { + if (s.scope.syms.get(kv.key_ptr.*) == null) try s.scope.syms.put(s.arena, kv.key_ptr.*, kv.value_ptr.*); + } + }, + .using_decl => |n| { + if (s.lookupName(n)) |sym| try s.scope.syms.put(s.arena, n.last(), sym); + }, + .pragma => {}, + .static_assert => |sa| { + const t = try s.expr(sa.cond); + if (t.ty == TypeTable.error_type) return; + const v = s.evalConst(sa.cond) orelse { + s.err(sa.cond.loc, "static_assert expression is not an integral constant expression", .{}); + return; + }; + if (!truthy(v)) s.err(d.loc, "static_assert failed {s}", .{sa.message orelse "\"\""}); + }, + } + } + + fn enumDecl(s: *Sema, d: *const ast.Decl, e: ast.EnumDecl) Allocator.Error!void { + const info = try s.arena.create(types.EnumInfo); + var underlying: Scalar = .int; + if (e.underlying) |u| { + const ut = try s.resolveType(u); + underlying = s.types.component(ut) orelse .int; + } + info.* = .{ .name = e.name orelse "", .underlying = underlying, .scoped = e.scoped }; + const ty = try s.types.intern(.{ .@"enum" = info }); + if (e.name) |n| try s.declare(n, .{ .type = ty }, d.loc); + const sc = try s.arena.create(Scope); + sc.* = .{ .parent = s.scope, .kind = .namespace, .name = info.name }; + try s.enum_scopes.put(s.arena, info, sc); + var next: i64 = 0; + for (e.values) |v| { + if (v.value) |ve| { + _ = try s.expr(ve); + next = s.evalInt(ve) orelse blk: { + s.err(ve.loc, "expression is not an integral constant expression", .{}); + break :blk next; + }; + } + const sym: Symbol = .{ .enumerator = .{ .type = ty, .value = next } }; + try sc.syms.put(s.arena, v.name, sym); + if (!e.scoped) try s.declare(v.name, sym, v.loc); + next += 1; + } + } + + fn structDecl(s: *Sema, d: *const ast.Decl, st: *const ast.StructDecl) Allocator.Error!void { + const name = st.name orelse ""; + if (st.template_params.len > 0 or st.specialization_args.len > 0) { + if (st.template_params.len > 0 and st.specialization_args.len == 0) try s.declare(name, .{ .template = d }, d.loc); + return; + } + // Reuse a forward-declared struct. + var info: *types.StructInfo = undefined; + var ty: TypeId = undefined; + if (s.scope.syms.get(name)) |sym| blk: { + if (sym == .type) if (s.types.get(sym.type) == .@"struct") { + info = s.types.get(sym.type).@"struct"; + ty = sym.type; + if (info.complete and st.members != null) s.err(d.loc, "redefinition of '{s}'", .{name}); + break :blk; + }; + s.err(d.loc, "redefinition of '{s}' as a different kind of symbol", .{name}); + return; + } else { + info = try s.arena.create(types.StructInfo); + info.* = .{ .name = name }; + ty = try s.types.intern(.{ .@"struct" = info }); + try s.declare(name, .{ .type = ty }, d.loc); + } + const members = st.members orelse return; + const sc = try s.arena.create(Scope); + sc.* = .{ .parent = s.scope, .kind = .@"struct", .name = name }; + const ss = try s.arena.create(StructSema); + ss.* = .{ .scope = sc, .decl = d }; + info.sema = ss; + + // Base classes contribute their fields first; their members are + // found through the base's scope (so derived members hide them). + var base_fields: usize = 0; + for (st.bases) |b| { + const bt = try s.resolveType(b); + if (s.types.get(bt) == .@"struct") { + const base = s.types.get(bt).@"struct"; + try info.fields.appendSlice(s.arena, base.fields.items); + try info.bases.append(s.arena, base); + base_fields = info.fields.items.len; + if (base.sema) |bp| { + // The base's scope (and through it, its own bases). + const bs: *StructSema = @ptrCast(@alignCast(bp)); + sc.parent = bs.scope; + } + } + } + + const saved = s.scope; + s.scope = sc; + defer s.scope = saved; + // Fields and nested types first, then methods (which may use any + // field regardless of order). + for (members) |m| switch (m.kind) { + .@"var" => |v| { + if (v.quals.static) { + try s.varDecl(m, &m.kind.@"var", .member); + continue; + } + if (v.bitfield != null) { + s.err(m.loc, "bitfields are not supported yet (planned for milestone 0.2)", .{}); + } + const fbase = try s.resolveType(v.type); + const start = if (v.qual_words.len > 0) v.qual_words[0].loc else v.type.loc; + if (v.array_dims.len > 0 and v.array_dims[0] == null) { + s.err(start, "array dimensions of struct/class members must be explicit", .{}); + continue; + } + s.checkModifiers(.field, v.qual_words, start, fbase); + const ft = try s.applyArrayDims(fbase, v.array_dims); + for (info.fields.items[base_fields..]) |f| if (std.mem.eql(u8, f.name, v.name)) s.err(v.name_loc, "duplicate member '{s}'", .{v.name}); + try info.fields.append(s.arena, .{ .name = v.name, .type = ft }); + }, + .func => {}, + else => try s.decl(m, .member), + }; + info.complete = true; + const saved_struct = s.current_struct; + s.current_struct = info; + defer s.current_struct = saved_struct; + // All method signatures first, then bodies, so methods can call + // methods defined later in the struct. + for (members) |m| if (m.kind == .func) try s.funcDeclMode(m, &m.kind.func, info, .declare_only); + for (members) |m| if (m.kind == .func) try s.funcDeclMode(m, &m.kind.func, info, .body_only); + } + + const DeclKind = enum { + local_variable, + typedef, + function, + method, + global_variable, + parameter, + field, + + fn text(k: DeclKind) []const u8 { + return switch (k) { + .local_variable => "local variable", + .global_variable => "global variable", + inline else => |t| @tagName(t), + }; + } + }; + + /// Which declarations each qualifier may modify, and which qualifiers + /// conflict: a port of dxc's DiagnoseHLSLDecl (modifier part) and its + /// matrix-orientation type-attribute checks. `start` is where the + /// declaration begins; `ty` is the declared (or return) type before + /// declarator array dimensions. + fn checkModifiers(s: *Sema, kind: DeclKind, words: []const ast.QualWord, start: Loc, ty: TypeId) void { + if (words.len == 0) return; + const what = kind.text(); + // Storage classes: the first one wins (typedef counts as one). + var storage: ?[]const u8 = if (kind == .typedef) "typedef" else null; + var is_const = false; + var is_volatile = false; + var orientation: ?[]const u8 = null; + for (words) |w| { + if (eql(w.word, "static") or eql(w.word, "extern")) { + if (storage) |prev| { + if (eql(prev, w.word)) { + s.warn(w.loc, "duplicate-decl-specifier", "duplicate '{s}' declaration specifier", .{w.word}); + } else s.err(w.loc, "cannot combine with previous '{s}' declaration specifier", .{prev}); + } else storage = w.word; + } else if (eql(w.word, "const")) { + is_const = true; + } else if (eql(w.word, "volatile")) { + is_volatile = true; + } else if (eql(w.word, "row_major") or eql(w.word, "column_major")) { + if (s.types.get(ty) != .matrix and ty != TypeTable.error_type) { + s.err(w.loc, "'{s}' can only be used with a matrix type", .{w.word}); + } else if (orientation) |o| { + if (eql(o, w.word)) { + s.warn(w.loc, "ignored-attributes", "attribute '{s}' is already applied", .{w.word}); + } else s.err(w.loc, "'row_major' and 'column_major' attributes are not compatible", .{}); + } else orientation = w.word; + } + } + const is_static = storage != null and eql(storage.?, "static"); + const is_extern = storage != null and eql(storage.?, "extern"); + if (is_extern and !(kind == .function or kind == .global_variable)) s.err(start, "'extern' is not a valid modifier for a {s}", .{what}); + if (is_static and (kind == .typedef or kind == .parameter)) s.err(start, "'static' is not a valid modifier for a {s}", .{what}); + if (is_volatile and !(kind == .local_variable or kind == .typedef)) s.err(start, "'volatile' is not a valid modifier for a {s}", .{what}); + if (is_const and kind == .field and !is_static) s.err(start, "'const' is not a valid modifier for a {s}", .{what}); + + const param = kind == .parameter; + const param_field_fn = param or kind == .field or kind == .function; + var uniform: ?ast.QualWord = null; + var usage: ?ast.QualWord = null; + var nointerp: ?ast.QualWord = null; + var any_linear: ?ast.QualWord = null; + var linear = false; + var center: ?ast.QualWord = null; + var noperspective = false; + var sample: ?ast.QualWord = null; + var centroid: ?ast.QualWord = null; + var topology: ?ast.QualWord = null; + var mesh: ?ast.QualWord = null; + var usage_in = false; + var usage_out = false; + var groupshared = false; + // clang keeps declaration attributes in reverse source order. + var i = words.len; + while (i > 0) { + i -= 1; + const w = words[i]; + const word = w.word; + if (eql(word, "shared")) { + if (kind != .global_variable) s.err(w.loc, "'shared' is not a valid modifier for a {s}", .{what}); + if (is_static) s.err(w.loc, "'static' and 'shared' cannot be used together for a {s}", .{what}); + } else if (eql(word, "groupshared")) { + groupshared = true; + if (param and (usage_in or usage_out)) { + s.err(w.loc, "'{s}' and 'groupshared' cannot be used together for a {s}", .{ if (usage_in and usage_out) "inout" else if (usage_in) "in" else "out", what }); + } + if (!(kind == .global_variable or param)) s.err(w.loc, "'groupshared' is not a valid modifier for a {s}", .{what}); + if (is_extern) s.err(w.loc, "'extern' and 'groupshared' cannot be used together for a {s}", .{what}); + } else if (eql(word, "uniform")) { + if (!(kind == .global_variable or param)) s.err(w.loc, "'uniform' is not a valid modifier for a {s}", .{what}); + if (is_static) s.err(w.loc, "'static' and 'uniform' cannot be used together for a {s}", .{what}); + uniform = w; + } else if (eql(word, "in") or eql(word, "out") or eql(word, "inout")) { + if (!param) { + s.err(w.loc, "HLSL usage '{s}' is only valid on a parameter", .{word}); + } else if (groupshared) { + s.err(w.loc, "'{s}' and 'groupshared' cannot be used together for a {s}", .{ word, what }); + } + const compatible = if (eql(word, "in")) !usage_in else if (eql(word, "out")) !usage_out else !(usage_in or usage_out); + if (eql(word, "in") or eql(word, "inout")) usage_in = true; + if (eql(word, "out") or eql(word, "inout")) usage_out = true; + if (!compatible) s.err(w.loc, "duplicate HLSL parameter usages '{s}'", .{word}); + usage = w; + } else if (eql(word, "nointerpolation")) { + if (!param_field_fn) s.err(w.loc, "'nointerpolation' is not a valid modifier for a {s}", .{what}); + if (nointerp != null) s.warn(w.loc, "ignored-attributes", "duplicate HLSL specifier 'nointerpolation'", .{}); + nointerp = w; + } else if (eql(word, "linear") or eql(word, "center") or eql(word, "noperspective") or eql(word, "sample") or eql(word, "centroid")) { + if (!param_field_fn) s.err(w.loc, "'{s}' is not a valid modifier for a {s}", .{ word, what }); + if (any_linear == null) any_linear = w; + const dup = if (eql(word, "linear")) linear else if (eql(word, "center")) center != null else if (eql(word, "noperspective")) noperspective else if (eql(word, "sample")) sample != null else centroid != null; + if (dup) s.warn(w.loc, "ignored-attributes", "duplicate HLSL specifier '{s}'", .{word}); + if (eql(word, "linear")) linear = true; + if (eql(word, "center")) center = w; + if (eql(word, "noperspective")) noperspective = true; + if (eql(word, "sample")) sample = w; + if (eql(word, "centroid")) centroid = w; + } else if (eql(word, "point") or eql(word, "line") or eql(word, "lineadj") or eql(word, "triangle") or eql(word, "triangleadj")) { + if (!param) s.err(w.loc, "'{s}' is not a valid modifier for a {s}", .{ word, what }); + if (topology) |t| { + if (eql(t.word, word)) { + s.warn(w.loc, "ignored-attributes", "duplicate HLSL specifier '{s}'", .{word}); + } else s.err(w.loc, "'{s}' and '{s}' cannot be used together for a {s}", .{ word, t.word, what }); + } + topology = w; + } else if (eql(word, "export")) { + if (kind != .function) s.err(w.loc, "'export' is not a valid modifier for a {s}", .{what}); + if (is_static) s.err(w.loc, "'static' and 'export' cannot be used together for a {s}", .{what}); + } else if (eql(word, "indices") or eql(word, "vertices") or eql(word, "primitives") or eql(word, "payload")) { + if (!param) s.err(w.loc, "'{s}' is not a valid modifier for a {s}", .{ word, what }); + if (mesh) |m| { + if (eql(m.word, word)) { + s.warn(w.loc, "ignored-attributes", "duplicate HLSL specifier '{s}'", .{word}); + } else s.err(w.loc, "'{s}' and '{s}' cannot be used together for a {s}", .{ word, m.word, what }); + } + mesh = w; + } + } + if (nointerp) |n| if (any_linear) |l| s.err(n.loc, "'nointerpolation' and '{s}' cannot be used together for a {s}", .{ l.word, what }); + if (sample) |sm| if (centroid) |c| s.warn(c.loc, "specifier-override", "'centroid' will be overridden by '{s}'", .{sm.word}); + if (center) |c| if (centroid) |_| s.warn(c.loc, "specifier-override", "'center' will be overridden by 'centroid'", .{}); + if (sample) |_| if (center) |c| s.warn(c.loc, "specifier-override", "'center' will be overridden by 'sample'", .{}); + const non_uniform = any_linear orelse nointerp orelse topology; + if (uniform) |u| if (non_uniform) |nu| s.err(u.loc, "'{s}' and 'uniform' cannot be used together for a {s}", .{ nu.word, what }); + if (any_linear) |l| if (topology) |t| s.err(l.loc, "'{s}' and '{s}' cannot be used together for a {s}", .{ t.word, l.word, what }); + if (nointerp) |n| if (topology) |t| s.err(n.loc, "'{s}' and 'nointerpolation' cannot be used together for a {s}", .{ t.word, what }); + if (uniform) |u| if (usage) |us| if (!eql(us.word, "in")) s.err(u.loc, "'{s}' and 'uniform' cannot be used together for a {s}", .{ us.word, what }); + if (mesh) |m| { + if (eql(m.word, "payload")) { + if (!usage_in) s.err(start, "'payload' object must be an in parameter", .{}); + } else if (!usage_out) s.err(start, "'{s}' object must be an out parameter", .{m.word}); + } + if (param and !(usage_in and usage_out) and s.types.get(ty) == .stream) s.err(start, "stream-output object must be an inout parameter", .{}); + } + + fn varDecl(s: *Sema, d: *const ast.Decl, v: *const ast.VarDecl, ctx: DeclCtx) Allocator.Error!void { + if (v.template_params.len > 0) return s.declare(v.name, .{ .template = d }, d.loc); + if (std.mem.indexOf(u8, v.name, "::") != null) return; // out-of-line static member definition + const is_auto = v.type.name.isSimple("auto"); + const base = if (is_auto) TypeTable.error_type else try s.resolveType(v.type); + s.checkModifiers(switch (ctx) { + .local => .local_variable, + .member => .field, + .global, .cbuffer => .global_variable, + }, v.qual_words, if (v.qual_words.len > 0) v.qual_words[0].loc else v.type.loc, base); + var ty = try s.applyArrayDims(base, v.array_dims); + if (is_auto) { + // `auto x = init`: the initializer's type (literals become + // concrete). + if (v.init) |init_e| { + const t = try s.expr(init_e); + ty = t.ty; + if (s.types.component(ty)) |c| if (c.isLiteral()) { + ty = try s.types.withComponent(ty, c.concrete()); + }; + } + } + if (ty == TypeTable.void_type) { + s.err(v.name_loc, "variable has incomplete type 'void'", .{}); + ty = TypeTable.error_type; + } + const q = v.quals; + const storage: Storage = switch (ctx) { + .cbuffer => .cbuffer, + .local => if (q.static) .local_static else .local, + .global, .member => if (q.groupshared) .groupshared else if (q.static and q.@"const") .constant else if (q.static) .global_static else if (s.isObject(ty)) .global_static else .global_uniform, + }; + // Uniform globals and cbuffer members are read-only, as are consts. + const read_only = q.@"const" or storage == .cbuffer or storage == .global_uniform; + // The variable is in scope in its own initializer (as in C++). + const variable = try s.arena.create(Variable); + variable.* = .{ + .name = v.name, + .type = ty, + .quals = q, + .storage = storage, + .loc = v.name_loc, + .read_only = read_only, + .init = v.init, + }; + try s.declare(v.name, .{ .variable = variable }, v.name_loc); + // Unsized arrays take their size from the initializer. + if (v.init) |init_e| if (!is_auto) { + if (s.types.get(ty) == .array and s.types.get(ty).array.len == 0 and init_e.kind == .init_list) { + const elem = s.types.get(ty).array.elem; + const elem_count = s.types.componentCount(elem) orelse 1; + const flat = s.flatCount(init_e); + ty = try s.types.array(elem, @intCast(@max(1, (flat + elem_count - 1) / @max(1, elem_count)))); + } + variable.type = ty; + try s.checkInitializer(ty, init_e); + }; + if (v.init == null and q.@"const" and ctx == .local) { + s.err(v.name_loc, "default initialization of an object of const type '{s}'", .{s.typeName(ty)}); + } + } + + /// The expression designates (part of) a groupshared variable. + fn isGroupshared(s: *Sema, e: *const ast.Expr) bool { + return switch (e.kind) { + .name => |n| if (s.lookupName(n)) |sym| sym == .variable and sym.variable.storage == .groupshared else false, + .member => |m| s.isGroupshared(m.base), + .index => |x| s.isGroupshared(x.base), + else => false, + }; + } + + fn isObject(s: *Sema, ty: TypeId) bool { + return switch (s.types.get(ty)) { + .resource, .sampler, .stream, .patch => true, + .array => |a| s.isObject(a.elem), + else => false, + }; + } + + fn funcDecl(s: *Sema, d: *const ast.Decl, f: *const ast.FuncDecl, owner: ?*types.StructInfo) Allocator.Error!void { + return s.funcDeclMode(d, f, owner, .both); + } + + const FuncMode = enum { both, declare_only, body_only }; + + fn funcDeclMode(s: *Sema, d: *const ast.Decl, f: *const ast.FuncDecl, owner: ?*types.StructInfo, mode: FuncMode) Allocator.Error!void { + const name = f.name.last(); + if (mode == .body_only) { + if (f.template_params.len > 0 or std.mem.startsWith(u8, name, "operator") or f.name.parts.len > 1) return; + const sym = s.scope.syms.get(name) orelse return; + if (sym != .functions) return; + for (sym.functions.funcs.items) |func| if (func.decl == f) return s.funcBody(func, f); + return; + } + if (f.template_params.len > 0) return s.declare(name, .{ .template = d }, d.loc); + if (std.mem.startsWith(u8, name, "operator")) { + s.err(d.loc, "operator overloading is not supported yet (planned for milestone 0.2)", .{}); + return; + } + if (f.name.parts.len > 1) return; // out-of-line method definition: not modelled yet + // `auto` return types are deduced in HLSL 202x; unconstrained here. + const ret = if (f.ret.name.isSimple("auto")) TypeTable.error_type else try s.applyArrayDims(try s.resolveType(f.ret), f.ret_dims); + const params = try s.arena.alloc(Param, f.params.len); + s.checkModifiers(if (owner != null) .method else .function, f.qual_words, if (f.qual_words.len > 0) f.qual_words[0].loc else f.ret.loc, ret); + for (f.params, params) |p, *out| { + const pbase = try s.resolveType(p.type); + s.checkModifiers(.parameter, p.qual_words, if (p.qual_words.len > 0) p.qual_words[0].loc else p.type.loc, pbase); + const pt = try s.applyArrayDims(pbase, p.array_dims); + out.* = .{ + .name = p.name, + .type = pt, + .dir = if (p.quals.in and p.quals.out) .inout else if (p.quals.out) .out else .in, + .has_default = p.init != null, + .groupshared = p.quals.groupshared, + }; + if (p.init) |init_e| try s.checkInitializer(pt, init_e); + } + const func = try s.arena.create(Function); + func.* = .{ .name = name, .decl = f, .loc = d.loc, .ret = ret, .params = params, .defined = f.body != null, .owner = owner }; + + // Add to the overload set, matching an earlier prototype if any. + const set = blk: { + if (s.scope.syms.get(name)) |sym| { + if (sym == .functions) break :blk sym.functions; + if (sym != .template) { + s.err(d.loc, "redefinition of '{s}' as a different kind of symbol", .{name}); + return; + } + } + const set = try s.arena.create(FuncSet); + set.* = .{}; + try s.declare(name, .{ .functions = set }, d.loc); + break :blk set; + }; + var existing: ?*Function = null; + for (set.funcs.items) |other| { + if (sameSignature(other, func)) existing = other; + } + if (existing) |e| { + if (e.defined and func.defined) { + s.err(d.loc, "redefinition of '{s}'", .{name}); + } else if (e.ret != func.ret and e.ret != TypeTable.error_type and func.ret != TypeTable.error_type) { + s.err(d.loc, "functions that differ only in their return type cannot be overloaded", .{}); + } + if (func.defined) e.* = func.*; + } else try set.funcs.append(s.arena, func); + if (mode == .declare_only) return; + try s.funcBody(func, f); + } + + fn funcBody(s: *Sema, func: *Function, f: *const ast.FuncDecl) Allocator.Error!void { + const params = func.params; + const body = f.body orelse return; + const saved_fn = s.current_fn; + s.current_fn = func; + defer s.current_fn = saved_fn; + _ = try s.pushScope(.function); + defer s.popScope(); + for (f.params, params) |p, pp| { + if (p.name.len == 0) continue; + const pv = try s.arena.create(Variable); + pv.* = .{ .name = p.name, .type = pp.type, .quals = p.quals, .storage = .param, .loc = p.name_loc, .read_only = p.quals.@"const" }; + try s.declare(p.name, .{ .variable = pv }, p.name_loc); + } + // The body's top-level block shares the parameter scope. + for (body.kind.compound) |st| try s.stmt(st); + } + + fn sameSignature(a: *const Function, b: *const Function) bool { + if (a.params.len != b.params.len) return false; + for (a.params, b.params) |x, y| { + // Unresolved parameter types (templates) never collide. + if (x.type == TypeTable.error_type or y.type == TypeTable.error_type) return false; + if (x.type != y.type or x.dir != y.dir or x.groupshared != y.groupshared) return false; + } + return true; + } + + // ------------------------------------------------------------------ + // Statements + + fn stmt(s: *Sema, st: *const ast.Stmt) Allocator.Error!void { + switch (st.kind) { + .compound => |list| { + _ = try s.pushScope(.block); + defer s.popScope(); + for (list) |c| try s.stmt(c); + }, + .decl => |list| for (list) |d| try s.decl(d, .local), + .expr => |e| _ = try s.expr(e), + .empty => {}, + .@"if" => |x| { + _ = try s.pushScope(.block); + defer s.popScope(); + if (x.cond_decl) |d| try s.decl(d, .local); + try s.condition(x.cond, "if statement conditional expressions must evaluate to a scalar"); + try s.stmt(x.then); + if (x.@"else") |e| try s.stmt(e); + }, + .@"for" => |x| { + // HLSL 2021: the init declaration is scoped to the loop. + _ = try s.pushScope(.block); + defer s.popScope(); + if (x.init) |i| try s.stmt(i); + if (x.cond) |c| try s.condition(c, "for statement conditional expressions must evaluate to a scalar"); + if (x.inc) |i| _ = try s.expr(i); + s.loop_depth += 1; + defer s.loop_depth -= 1; + try s.stmt(x.body); + }, + .@"while" => |x| { + _ = try s.pushScope(.block); + defer s.popScope(); + if (x.cond_decl) |d| try s.decl(d, .local); + try s.condition(x.cond, "while statement conditional expressions must evaluate to a scalar"); + s.loop_depth += 1; + defer s.loop_depth -= 1; + try s.stmt(x.body); + }, + .do_while => |x| { + s.loop_depth += 1; + try s.stmt(x.body); + s.loop_depth -= 1; + try s.condition(x.cond, "do-while statement conditional expressions must evaluate to a scalar"); + }, + .@"switch" => |x| { + _ = try s.pushScope(.block); + defer s.popScope(); + if (x.cond_decl) |d| try s.decl(d, .local); + const t = try s.expr(x.cond); + if (t.ty != TypeTable.error_type) { + const comp = s.types.component(t.ty); + const sh = s.types.shape(t.ty); + if (comp == null or sh == null or sh.?.kind != .scalar) { + s.err(x.cond.loc, "statement requires expression of integer type ('{s}' invalid)", .{s.typeName(t.ty)}); + } + } + s.switch_depth += 1; + defer s.switch_depth -= 1; + try s.stmt(x.body); + }, + .case => |c| { + _ = try s.expr(c.value); + if (c.value.ty != TypeTable.error_type and s.evalInt(c.value) == null) { + s.err(c.value.loc, "expression is not an integral constant expression", .{}); + } + if (s.switch_depth == 0) s.err(st.loc, "'case' statement not in switch statement", .{}); + try s.stmt(c.stmt); + }, + .default => |b| { + if (s.switch_depth == 0) s.err(st.loc, "'default' statement not in switch statement", .{}); + try s.stmt(b); + }, + .@"break" => if (s.loop_depth == 0 and s.switch_depth == 0) s.err(st.loc, "'break' statement not in loop or switch statement", .{}), + .@"continue" => if (s.loop_depth == 0) s.err(st.loc, "'continue' statement not in loop statement", .{}), + .discard => {}, + .@"return" => |v| try s.returnStmt(st, v), + } + } + + fn returnStmt(s: *Sema, st: *const ast.Stmt, v: ?*ast.Expr) Allocator.Error!void { + const f = s.current_fn orelse return; + const ret = f.ret; + if (v) |e| { + if (ret == TypeTable.void_type) { + const t = try s.expr(e); + if (t.ty != TypeTable.void_type and t.ty != TypeTable.error_type) s.err(e.loc, "void function '{s}' should not return a value", .{f.name}); + return; + } + try s.checkInitializer(ret, e); + } else if (ret != TypeTable.void_type and ret != TypeTable.error_type) { + s.err(st.loc, "non-void function '{s}' should return a value", .{f.name}); + } + } + + /// A condition: scalar, convertible to bool (HLSL 2021). + fn condition(s: *Sema, e: *ast.Expr, comptime scalar_msg: []const u8) Allocator.Error!void { + const t = try s.expr(e); + if (t.ty == TypeTable.error_type) return; + const sh = s.types.shape(t.ty) orelse { + s.err(e.loc, "value of type '{s}' is not contextually convertible to 'bool'", .{s.typeName(t.ty)}); + return; + }; + if (sh.kind != .scalar and !(sh.rows == 1 and sh.cols == 1)) s.err(e.loc, scalar_msg, .{}); + } + + // ------------------------------------------------------------------ + // Expressions + + fn setType(e: *ast.Expr, t: Typed) Typed { + e.ty = t.ty; + return t; + } + + /// Reports an invalid numeric literal suffix (`1#INF`, `1.5q`); + /// returns false if there was one. + fn checkLiteralSuffix(s: *Sema, loc: Loc, text: []const u8) bool { + if (text[0] == '\'') return true; + const lit = scanLiteral(text); + const suffix = text[lit.end..]; + const ok = if (lit.float) + suffix.len == 0 or (suffix.len == 1 and std.mem.indexOfScalar(u8, "fFhHlL", suffix[0]) != null) + else + isIntSuffix(suffix) or (!lit.inf and suffix.len == 1 and std.mem.indexOfScalar(u8, "fFhH", suffix[0]) != null); + if (ok) return true; + s.err(loc.advance(@intCast(lit.end)), "invalid suffix '{s}' on {s} constant", .{ suffix, if (lit.float) "floating" else "integer" }); + return false; + } + + fn rvalue(ty: TypeId) Typed { + return .{ .ty = ty }; + } + + const err_typed: Typed = .{ .ty = TypeTable.error_type }; + + pub fn expr(s: *Sema, e: *ast.Expr) Allocator.Error!Typed { + const t = try s.exprInner(e); + if (t.callee != null and t.ty == TypeTable.error_type) { + // A function name used as a value is diagnosed by callers. + } + return setType(e, t); + } + + fn exprInner(s: *Sema, e: *ast.Expr) Allocator.Error!Typed { + switch (e.kind) { + .int_lit => |t| { + if (!s.checkLiteralSuffix(e.loc, t)) return err_typed; + return rvalue(try s.types.scalar(intLiteralType(t))); + }, + .float_lit => |t| { + if (!s.checkLiteralSuffix(e.loc, t)) return err_typed; + const sc = floatLiteralType(t); + // `1.5h` is float unless 16-bit types are enabled. + return rvalue(try s.types.scalar(if (sc == .half) (if (s.opts.enable_16bit) .float16 else .float) else sc)); + }, + .bool_lit => return rvalue(try s.types.scalar(.bool)), + .string_lit => return rvalue(try s.types.intern(.string)), + .this => { + const info = s.current_struct orelse { + s.err(e.loc, "invalid use of 'this' outside of a non-static member function", .{}); + return err_typed; + }; + return .{ .ty = try s.types.intern(.{ .@"struct" = info }), .lvalue = true }; + }, + .name => |n| return s.nameExpr(e, n), + .unary => |u| return s.unaryExpr(e, u.op, u.operand), + .binary => |b| return s.binaryExpr(e, b.op, b.lhs, b.rhs), + .assign => |a| return s.assignExpr(e, a.op, a.lhs, a.rhs), + .conditional => |c| return s.conditionalExpr(e, c.cond, c.then, c.@"else"), + .call => |c| return s.callExpr(e, c.callee, c.args, c.template_args), + .construct => |c| return s.constructExpr(e, c.type, c.args), + .cast => |c| { + const target = try s.applyArrayDims(try s.resolveType(c.type), c.array_dims); + const from = try s.expr(c.operand); + if (target != TypeTable.error_type and from.ty != TypeTable.error_type and !s.explicitConvertible(from.ty, target)) { + s.err(e.loc, "cannot convert from '{s}' to '{s}'", .{ s.typeName(from.ty), s.typeName(target) }); + } + // A cast of an lvalue to the same or a related struct type + // is still an lvalue (`(Derived)x = y`). + const ft = s.types.get(from.ty); + const tt = s.types.get(target); + const related = target == from.ty or (ft == .@"struct" and tt == .@"struct" and (derivesFrom(ft.@"struct", tt.@"struct") or derivesFrom(tt.@"struct", ft.@"struct"))); + return .{ .ty = target, .lvalue = from.lvalue and related, .read_only = from.read_only }; + }, + .member => |m| return s.memberExpr(e, m.base, m.name, m.name_loc), + .index => |x| return s.indexExpr(e, x.base, x.index), + .init_list => |items| { + for (items) |i| _ = try s.expr(i); + return err_typed; // typed by checkInitializer + }, + .sizeof_type => |t| { + _ = try s.resolveType(t); + return rvalue(try s.types.scalar(.uint)); + }, + .sizeof_expr => |x| { + _ = try s.expr(x); + return rvalue(try s.types.scalar(.uint)); + }, + .is_same => |x| { + const a = try s.resolveType(x.a); + const b = try s.resolveType(x.b); + // The answer is kept for constant evaluation. + e.info = @intFromBool(a == b); + if (a == TypeTable.error_type or b == TypeTable.error_type) return err_typed; + return rvalue(try s.types.scalar(.bool)); + }, + } + } + + fn nameExpr(s: *Sema, e: *ast.Expr, n: ast.Name) Allocator.Error!Typed { + if (s.lookupName(n)) |sym| switch (sym) { + .variable => |v| return .{ .ty = v.type, .lvalue = true, .read_only = v.read_only }, + .functions => |set| return .{ .ty = TypeTable.error_type, .callee = .{ .functions = set } }, + .enumerator => |en| return rvalue(en.type), + .type => |t| return .{ .ty = TypeTable.error_type, .callee = .{ .type = t } }, + .namespace => { + s.err(e.loc, "unexpected namespace name '{s}'", .{n.last()}); + return err_typed; + }, + .template => { + s.err(e.loc, "templates are not supported yet (planned for milestone 0.2)", .{}); + return err_typed; + }, + }; + // Builtin type names used as values (`half4` in an expression). + if (n.parts.len == 1) { + if (try s.numericTypeByName(n.parts[0])) |t| return .{ .ty = TypeTable.error_type, .callee = .{ .type = t } }; + } + // Struct fields and methods used unqualified inside methods. + if (s.current_struct) |info| { + if (n.parts.len == 1) { + for (info.fields.items) |f| if (std.mem.eql(u8, f.name, n.parts[0])) return .{ .ty = f.type, .lvalue = true }; + } + } + if (n.parts.len > 1) { + for (n.parts[0 .. n.parts.len - 1], 0..) |part, i| { + // `dx::HitObject::MakeNop()` and other static members of + // builtin objects: not modelled yet, accepted unconstrained. + if (isOtherBuiltinObject(part)) return .{ .ty = TypeTable.error_type, .callee = .unknown }; + // `S::member`, or members of a template. + if (n.args.len > 0 and n.args[i].len > 0) { + s.err(e.loc, "templates are not supported yet (planned for milestone 0.2)", .{}); + return err_typed; + } + const prefix: ast.Name = .{ .loc = n.loc, .parts = n.parts[0 .. i + 1] }; + if (s.lookupName(prefix)) |sym| { + if (sym == .template) { + s.err(e.loc, "templates are not supported yet (planned for milestone 0.2)", .{}); + return err_typed; + } + // Members of a type that already failed to resolve + // (e.g. an alias of a template): reported there. + if (sym == .type and sym.type == TypeTable.error_type) return err_typed; + } + } + } + if (s.intrinsic_db.has(n.last(), s.opts.spirv)) return .{ .ty = TypeTable.error_type, .callee = .{ .intrinsic = n.last() } }; + if (n.parts.len > 1 and std.mem.eql(u8, n.parts[0], "dx")) return .{ .ty = TypeTable.error_type, .callee = .unknown }; + s.err(e.loc, "use of undeclared identifier '{s}'", .{n.last()}); + return err_typed; + } + + fn unaryExpr(s: *Sema, e: *ast.Expr, op: ast.UnaryOp, operand: *ast.Expr) Allocator.Error!Typed { + const t = try s.expr(operand); + if (t.ty == TypeTable.error_type) return err_typed; + const comp = s.types.component(t.ty) orelse { + s.err(e.loc, "invalid argument type '{s}' to unary expression", .{s.typeName(t.ty)}); + return err_typed; + }; + switch (op) { + .not => return rvalue(try s.types.withComponent(t.ty, .bool)), + .bit_not => { + if (comp.isFloat()) { + s.err(e.loc, "int or unsigned int type required", .{}); + return err_typed; + } + return rvalue(try s.types.withComponent(t.ty, if (comp == .bool) .int else comp)); + }, + .plus, .minus => return rvalue(try s.types.withComponent(t.ty, if (comp == .bool) .int else comp)), + .pre_inc, .pre_dec, .post_inc, .post_dec => { + if (!t.lvalue) { + s.err(e.loc, "expression is not assignable", .{}); + } else if (t.read_only) { + s.err(e.loc, "cannot assign to {s} with const-qualified type", .{describeTarget(operand)}); + } + if (comp == .bool) s.err(e.loc, "operator on type 'bool' is not allowed", .{}); + // Prefix forms are lvalues, as in C++. + return .{ .ty = t.ty, .lvalue = op == .pre_inc or op == .pre_dec }; + }, + } + } + + fn binaryExpr(s: *Sema, e: *ast.Expr, op: ast.BinaryOp, lhs: *ast.Expr, rhs: *ast.Expr) Allocator.Error!Typed { + const l = try s.expr(lhs); + const r = try s.expr(rhs); + if (op == .comma) return rvalue(r.ty); + if (l.ty == TypeTable.error_type or r.ty == TypeTable.error_type) return err_typed; + if (op == .log_and or op == .log_or) { + const ls = s.types.shape(l.ty); + const rs = s.types.shape(r.ty); + if ((ls != null and ls.?.kind != .scalar) or (rs != null and rs.?.kind != .scalar)) { + s.err(e.loc, "operands for short-circuiting logical binary operator must be scalar, for non-scalar types use '{s}'", .{if (op == .log_and) "and" else "or"}); + return err_typed; + } + if (ls == null or rs == null) { + s.err(e.loc, "invalid operands to binary expression ('{s}' and '{s}')", .{ s.typeName(l.ty), s.typeName(r.ty) }); + return err_typed; + } + return rvalue(try s.types.scalar(.bool)); + } + const res = s.arithmetic(e, l.ty, r.ty) orelse return err_typed; + var comp = s.types.component(res).?; + if (op == .shl or op == .shr) { + // Shifts keep the left operand's component type; a literal + // shifted by a typed amount becomes int (uint for a uint amount). + const lc = s.types.component(l.ty).?; + const rc = s.types.component(r.ty).?; + comp = lc; + if (lc.isLiteral() and !rc.isLiteral()) { + s.warn(e.loc, "ambig-lit-shift", "ambiguous type for bit shift; use a type suffix on literal values, like 'L' or 'U', or a cast", .{}); + comp = if (rc == .uint) .uint else .int; + } + if (comp.isFloat()) { + s.err(e.loc, "int or unsigned int type required", .{}); + return err_typed; + } + return rvalue(try s.types.withComponent(res, if (comp == .bool) .int else comp)); + } + switch (op) { + .lt, .gt, .le, .ge, .eq, .ne => return rvalue(try s.types.withComponent(res, .bool)), + .bit_and, .bit_or, .bit_xor, .shl, .shr => { + if (comp.isFloat()) { + s.err(e.loc, "int or unsigned int type required", .{}); + return err_typed; + } + return rvalue(try s.types.withComponent(res, if (comp == .bool) .int else comp)); + }, + .rem, .mul, .div, .add, .sub => return rvalue(try s.types.withComponent(res, if (comp == .bool) .int else comp)), + .log_and, .log_or, .comma => unreachable, + } + } + + /// Usual arithmetic conversions of two numeric operands: the result + /// type, or null after an error. + fn arithmetic(s: *Sema, e: *ast.Expr, a: TypeId, b: TypeId) ?TypeId { + const ac = s.types.component(a); + const bc = s.types.component(b); + if (s.types.get(a) == .@"struct" or s.types.get(b) == .@"struct") { + s.err(e.loc, "operator overloading is not supported yet (planned for milestone 0.2)", .{}); + return null; + } + if (ac == null or bc == null) { + s.err(e.loc, "invalid operands to binary expression ('{s}' and '{s}')", .{ s.typeName(a), s.typeName(b) }); + return null; + } + const comp = Scalar.combine(ac.?, bc.?); + const as = s.types.shape(a).?; + const bs = s.types.shape(b).?; + var sh = as; + if (as.kind == .scalar) { + sh = bs; + } else if (bs.kind == .scalar) { + sh = as; + } else if (as.kind == bs.kind) { + sh = .{ .rows = @min(as.rows, bs.rows), .cols = @min(as.cols, bs.cols), .kind = as.kind }; + if (sh.rows != as.rows or sh.cols != as.cols or sh.rows != bs.rows or sh.cols != bs.cols) { + s.warn(e.loc, "conversion", "implicit truncation of vector type", .{}); + } + } else { + // vector op matrix: allowed when the element counts agree. + const ac_n = @as(u32, as.rows) * as.cols; + const bc_n = @as(u32, bs.rows) * bs.cols; + if (ac_n != bc_n and !(as.rows == 1 or as.cols == 1 or bs.rows == 1 or bs.cols == 1)) { + s.err(e.loc, "invalid operands to binary expression ('{s}' and '{s}')", .{ s.typeName(a), s.typeName(b) }); + return null; + } + sh = if (as.kind == .matrix) as else bs; + } + return s.types.withShape(comp, sh) catch null; + } + + fn assignExpr(s: *Sema, e: *ast.Expr, op: ast.AssignOp, lhs: *ast.Expr, rhs: *ast.Expr) Allocator.Error!Typed { + const l = try s.expr(lhs); + if (l.ty == TypeTable.error_type) { + _ = try s.expr(rhs); + return err_typed; + } + if (!l.lvalue) { + _ = try s.expr(rhs); + s.err(lhs.loc, "expression is not assignable", .{}); + return err_typed; + } + if (l.read_only) { + s.err(lhs.loc, "cannot assign to {s} with const-qualified type '{s}'", .{ describeTarget(lhs), s.constTypeName(l.ty) }); + } + if (op == .assign) { + try s.checkInitializer(l.ty, rhs); + } else { + const r = try s.expr(rhs); + if (r.ty != TypeTable.error_type) { + const res = s.arithmetic(e, l.ty, r.ty) orelse return rvalue(l.ty); + _ = res; + const comp = s.types.component(l.ty); + if (comp != null and comp.?.isFloat() and (op == .shl or op == .shr or op == .bit_and or op == .bit_or or op == .bit_xor)) { + s.err(e.loc, "int or unsigned int type required", .{}); + } + } + } + // The result of an assignment is an lvalue, as in C++. + return .{ .ty = l.ty, .lvalue = true }; + } + + fn constTypeName(s: *Sema, ty: TypeId) []const u8 { + return std.fmt.allocPrint(s.arena, "const {s}", .{s.shortTypeName(ty)}) catch "const"; + } + + /// dxc spells vectors `float4` in "const-qualified" messages. + fn shortTypeName(s: *Sema, ty: TypeId) []const u8 { + return switch (s.types.get(ty)) { + .vector => |v| std.fmt.allocPrint(s.arena, "{s}{d}", .{ v.elem.name(), v.len }) catch "?", + .matrix => |m| std.fmt.allocPrint(s.arena, "{s}{d}x{d}", .{ m.elem.name(), m.rows, m.cols }) catch "?", + else => s.typeName(ty), + }; + } + + fn conditionalExpr(s: *Sema, e: *ast.Expr, cond: *ast.Expr, then: *ast.Expr, else_e: *ast.Expr) Allocator.Error!Typed { + const c = try s.expr(cond); + const t = try s.expr(then); + const f = try s.expr(else_e); + if (c.ty != TypeTable.error_type) { + if (s.types.shape(c.ty)) |sh| { + if (sh.kind != .scalar) { + s.err(cond.loc, "condition for short-circuiting ternary operator must be scalar, for non-scalar types use 'select'", .{}); + return err_typed; + } + } + } + if (t.ty == TypeTable.error_type or f.ty == TypeTable.error_type) return err_typed; + if (t.ty == f.ty) return rvalue(t.ty); + if (s.types.isNumeric(t.ty) and s.types.isNumeric(f.ty)) { + return rvalue(s.arithmetic(e, t.ty, f.ty) orelse return err_typed); + } + s.err(e.loc, "incompatible operand types ('{s}' and '{s}')", .{ s.typeName(t.ty), s.typeName(f.ty) }); + return err_typed; + } + + fn memberExpr(s: *Sema, e: *ast.Expr, base: *ast.Expr, name: []const u8, name_loc: Loc) Allocator.Error!Typed { + _ = e; + const b = try s.expr(base); + if (b.ty == TypeTable.error_type) return err_typed; + switch (s.types.get(b.ty)) { + .scalar, .vector => { + const comp = s.types.component(b.ty).?; + const len: u8 = if (s.types.get(b.ty) == .vector) s.types.get(b.ty).vector.len else 1; + const sw = parseSwizzle(name, len) orelse { + s.err(name_loc, "invalid format for vector swizzle '{s}'", .{name}); + return err_typed; + }; + const ty = if (sw.count == 1) try s.types.scalar(comp) else try s.types.vector(comp, sw.count); + return .{ .ty = ty, .lvalue = b.lvalue and !sw.repeats, .read_only = b.read_only }; + }, + .matrix => |m| { + const sw = parseMatrixSwizzle(name, m.rows, m.cols) orelse { + s.err(name_loc, "invalid format for matrix subscript '{s}'", .{name}); + return err_typed; + }; + const ty = if (sw.count == 1) try s.types.scalar(m.elem) else try s.types.vector(m.elem, sw.count); + return .{ .ty = ty, .lvalue = b.lvalue and !sw.repeats, .read_only = b.read_only }; + }, + .@"struct" => |info| { + // Search from the end: derived fields hide base fields. + var fi = info.fields.items.len; + while (fi > 0) { + fi -= 1; + const f = info.fields.items[fi]; + if (std.mem.eql(u8, f.name, name)) return .{ .ty = f.type, .lvalue = b.lvalue, .read_only = b.read_only }; + } + if (info.sema) |p| { + const ss: *StructSema = @ptrCast(@alignCast(p)); + if (structMember(ss, name)) |sym| switch (sym) { + .functions => return .{ .ty = TypeTable.error_type, .callee = .{ .method = .{ .object = b.ty, .name = name, .object_lvalue = b.lvalue } } }, + .variable => |v| return .{ .ty = v.type, .lvalue = true, .read_only = v.read_only }, + .template => { + s.err(name_loc, "templates are not supported yet (planned for milestone 0.2)", .{}); + return err_typed; + }, + else => {}, + }; + } + s.err(name_loc, "no member named '{s}' in '{s}'", .{ name, info.name }); + return err_typed; + }, + .resource => |r| { + // ConstantBuffer / TextureBuffer: members of S. + if (r.kind == .constant_buffer or r.kind == .texture_buffer) { + if (s.types.get(r.elem) == .@"struct") { + const info = s.types.get(r.elem).@"struct"; + for (info.fields.items) |f| { + if (std.mem.eql(u8, f.name, name)) return .{ .ty = f.type, .lvalue = true, .read_only = true }; + } + if (info.sema) |p| { + const ss: *StructSema = @ptrCast(@alignCast(p)); + if (ss.scope.syms.get(name)) |sym| if (sym == .functions) { + return .{ .ty = TypeTable.error_type, .callee = .{ .method = .{ .object = r.elem, .name = name, .object_lvalue = false } } }; + }; + } + s.err(name_loc, "no member named '{s}' in '{s}'", .{ name, s.typeName(b.ty) }); + } + return err_typed; + } + return .{ .ty = TypeTable.error_type, .callee = .{ .method = .{ .object = b.ty, .name = name, .object_lvalue = b.lvalue } } }; + }, + .stream, .patch => return .{ .ty = TypeTable.error_type, .callee = .{ .method = .{ .object = b.ty, .name = name, .object_lvalue = b.lvalue } } }, + else => { + s.err(name_loc, "member reference base type '{s}' is not a structure", .{s.typeName(b.ty)}); + return err_typed; + }, + } + } + + fn indexExpr(s: *Sema, e: *ast.Expr, base: *ast.Expr, index: *ast.Expr) Allocator.Error!Typed { + const b = try s.expr(base); + const i = try s.expr(index); + if (b.ty == TypeTable.error_type) return err_typed; + if (i.ty != TypeTable.error_type and !s.types.isNumeric(i.ty)) { + s.err(index.loc, "array subscript is not an integer", .{}); + } + switch (s.types.get(b.ty)) { + .array => |a| return .{ .ty = a.elem, .lvalue = b.lvalue, .read_only = b.read_only }, + .vector => |v| return .{ .ty = try s.types.scalar(v.elem), .lvalue = b.lvalue, .read_only = b.read_only }, + .matrix => |m| return .{ .ty = try s.types.vector(m.elem, m.cols), .lvalue = b.lvalue, .read_only = b.read_only }, + .resource => |r| { + if (r.kind.indexDims() == 0 or r.elem == TypeTable.void_type) { + if (r.kind == .other) return err_typed; + s.err(e.loc, "type '{s}' does not provide a subscript operator", .{s.typeName(b.ty)}); + return err_typed; + } + return .{ .ty = r.elem, .lvalue = true, .read_only = !r.kind.isWritable() }; + }, + .patch => |p| return .{ .ty = p.elem, .lvalue = true, .read_only = !p.output }, + .descriptor_heap => return rvalue(try s.types.intern(.dynamic_resource)), + .@"struct" => { + s.err(e.loc, "operator overloading is not supported yet (planned for milestone 0.2)", .{}); + return err_typed; + }, + else => { + s.err(e.loc, "subscripted value is not an array, matrix, or vector", .{}); + return err_typed; + }, + } + } + + fn constructExpr(s: *Sema, e: *ast.Expr, ty_ref: *const ast.TypeRef, args: []const *ast.Expr) Allocator.Error!Typed { + const target = try s.resolveType(ty_ref); + var total: u32 = 0; + var any_error = false; + for (args) |a| { + const t = try s.expr(a); + if (t.ty == TypeTable.error_type) { + any_error = true; + continue; + } + total += s.types.componentCount(t.ty) orelse blk: { + if (s.types.isNumeric(target)) { + s.err(a.loc, "'{s}' cannot be used to construct '{s}'", .{ s.typeName(t.ty), s.typeName(target) }); + any_error = true; + } + break :blk 0; + }; + } + if (target == TypeTable.error_type or any_error) return rvalue(target); + if (!s.types.isNumeric(target)) return rvalue(target); // vk::BufferPointer(addr) and other objects + switch (s.types.get(target)) { + .scalar, .vector, .matrix => { + const want = s.types.componentCount(target).?; + // `float4(x)` with a scalar splats; otherwise counts must match. + if (total != want and !(args.len == 1 and total == 1)) { + if (total < want) { + s.err(e.loc, "too few elements in vector initialization (expected {d} elements, have {d})", .{ want, total }); + } else { + s.err(e.loc, "too many elements in vector initialization (expected {d} elements, have {d})", .{ want, total }); + } + } + }, + else => {}, + } + return rvalue(target); + } + + // ------------------------------------------------------------------ + // Calls + + fn callExpr(s: *Sema, e: *ast.Expr, callee: *ast.Expr, args: []const *ast.Expr, template_args: []const ast.TemplateArg) Allocator.Error!Typed { + const c = try s.expr(callee); + var arg_types = try s.arena.alloc(intrinsics.ArgInfo, args.len); + for (args, 0..) |a, i| { + const t = try s.expr(a); + arg_types[i] = .{ .ty = t.ty, .lvalue = t.lvalue and !t.read_only, .loc = a.loc, .groupshared = s.isGroupshared(a) }; + } + const target = c.callee orelse { + if (s.types.get(c.ty) == .@"struct") { + s.err(callee.loc, "operator overloading is not supported yet (planned for milestone 0.2)", .{}); + } else if (c.ty != TypeTable.error_type) s.err(callee.loc, "called object type '{s}' is not a function", .{s.typeName(c.ty)}); + return err_typed; + }; + for (arg_types) |a| if (a.ty == TypeTable.error_type) return err_typed; + switch (target) { + .functions => |set| return rvalue(s.resolveUserCall(e, set, arg_types, callee)), + .intrinsic => |name| { + var explicit: ?TypeId = null; + if (template_args.len > 0) explicit = try s.typeArg(template_args[0]); + return rvalue(try s.intrinsic_db.resolve(s, e.loc, if (s.opts.spirv and isVkQualified(callee)) "VkIntrinsics" else "Intrinsics", name, null, arg_types, explicit)); + }, + .method => |m| { + switch (s.types.get(m.object)) { + .@"struct" => |info| { + const ss: *StructSema = @ptrCast(@alignCast(info.sema.?)); + const sym = structMember(ss, m.name) orelse return err_typed; + if (sym != .functions) return err_typed; + return rvalue(s.resolveUserCall(e, sym.functions, arg_types, callee)); + }, + else => { + var explicit: ?TypeId = null; + if (template_args.len > 0) explicit = try s.typeArg(template_args[0]); + const ns = methodNamespace(s.types.get(m.object)) orelse return err_typed; + return rvalue(try s.intrinsic_db.resolve(s, e.loc, ns, m.name, m.object, arg_types, explicit)); + }, + } + }, + .unknown => return err_typed, + .type => |t| { + // `T(args)` with a user type: only a single-argument cast. + if (args.len == 1) { + if (!s.explicitConvertible(arg_types[0].ty, t)) s.err(e.loc, "cannot convert from '{s}' to '{s}'", .{ s.typeName(arg_types[0].ty), s.typeName(t) }); + return rvalue(t); + } + return rvalue(t); + }, + } + } + + /// Overload resolution among user functions by conversion cost. + fn resolveUserCall(s: *Sema, e: *ast.Expr, set: *FuncSet, args: []const intrinsics.ArgInfo, callee: *ast.Expr) TypeId { + var best: ?*Function = null; + var best_cost: u32 = std.math.maxInt(u32); + var ambiguous = false; + for (set.funcs.items) |f| { + if (args.len > f.params.len) continue; + var required: usize = 0; + for (f.params) |p| { + if (!p.has_default) required += 1; + } + if (args.len < required) continue; + var cost: u32 = 0; + var ok = true; + for (args, 0..) |a, i| { + const p = f.params[i]; + const c = s.conversionCost(a.ty, p.type); + // groupshared parameters bind only groupshared arguments + // (and are preferred for them). + if (c == null or (p.groupshared and !a.groupshared)) { + ok = false; + break; + } + cost += c.?; + if (a.groupshared and !p.groupshared) cost += 1; + } + if (!ok) continue; + if (cost < best_cost) { + best = f; + best_cost = cost; + ambiguous = false; + } else if (cost == best_cost) ambiguous = true; + } + const f = best orelse { + const name = if (set.funcs.items.len > 0) set.funcs.items[0].name else "?"; + s.err(callee.loc, "no matching function for call to '{s}'", .{name}); + return TypeTable.error_type; + }; + if (ambiguous) { + s.err(callee.loc, "call to '{s}' is ambiguous", .{f.name}); + return TypeTable.error_type; + } + for (args, 0..) |a, i| { + if (f.params[i].dir != .in and !a.lvalue) { + s.err(a.loc, "cannot bind non-lvalue argument to {s} parameter", .{if (f.params[i].dir == .out) "out" else "inout"}); + } + } + _ = e; + return f.ret; + } + + // ------------------------------------------------------------------ + // Conversions + + /// Cost of an implicit conversion (0: exact), or null if impossible. + pub fn conversionCost(s: *Sema, from: TypeId, to: TypeId) ?u32 { + if (from == to or from == TypeTable.error_type or to == TypeTable.error_type) return 0; + const ft = s.types.get(from); + const tt = s.types.get(to); + const fc = s.types.component(from); + const tc = s.types.component(to); + if (fc != null and tc != null and (ft != .@"enum" or tt != .@"enum")) { + if (tt == .@"enum" and (tt.@"enum".scoped or ft == .@"enum")) return null; // needs a cast + const fs = s.types.shape(from).?; + const ts = s.types.shape(to).?; + var cost: u32 = if (fc.? == tc.?) 0 else if (fc.?.isLiteral()) 1 else if (fc.?.isFloat() == tc.?.isFloat() and tc.?.rank() > fc.?.rank()) 2 else 3; + if ((fs.kind == .scalar or (fs.rows == 1 and fs.cols == 1)) and !(ts.rows == 1 and ts.cols == 1)) { + cost += 4; // splat (float and float1 alike) + } else if (fs.rows == ts.rows and fs.cols == ts.cols) { + if (fs.kind != ts.kind) cost += 1; // float1 <-> float + } else if (fs.rows >= ts.rows and fs.cols >= ts.cols and fs.kind == ts.kind) { + cost += 8; // truncation + } else if (ts.kind == .scalar) { + cost += 10; // vector / matrix -> scalar truncation (worse than shrinking) + } else if (@as(u32, fs.rows) * fs.cols == @as(u32, ts.rows) * ts.cols and (fs.kind == .vector or ts.kind == .vector)) { + cost += 6; // vector <-> matrix of the same size + } else return null; + return cost; + } + // A descriptor heap element converts to any resource or sampler. + if (ft == .dynamic_resource and (tt == .resource or tt == .sampler)) return 0; + // Derived structs convert to their bases. + if (ft == .@"struct" and tt == .@"struct" and derivesFrom(ft.@"struct", tt.@"struct")) return 2; + // int -> unscoped enum (dxc accepts it). + if (tt == .@"enum" and !tt.@"enum".scoped and s.types.isNumeric(from) and ft != .@"enum") return 3; + // ConstantBuffer / TextureBuffer are usable as an S value. + if (ft == .resource and (ft.resource.kind == .constant_buffer or ft.resource.kind == .texture_buffer) and ft.resource.elem == to) return 1; + return switch (ft) { + .array => |fa| switch (tt) { + .array => |ta| if ((ta.len == fa.len or ta.len == 0) and s.conversionCost(fa.elem, ta.elem) == 0) 0 else null, + else => null, + }, + .resource => |fr| switch (tt) { + .resource => |tr| if (fr.kind == tr.kind and (fr.elem == tr.elem or tr.elem == TypeTable.void_type)) 0 else null, + else => null, + }, + else => null, + }; + } + + fn explicitConvertible(s: *Sema, from: TypeId, to: TypeId) bool { + if (to == TypeTable.void_type) return true; + if (s.conversionCost(from, to) != null) return true; + // vk::BufferPointer and other opaque objects to / from integers. + if (s.types.get(from) == .resource and s.types.get(from).resource.kind == .other and s.types.isNumeric(to)) return true; + const fc = s.types.componentCount(from); + const tc = s.types.componentCount(to); + // Scalar to aggregate (`(S)0`), and flattening casts between + // aggregates with enough components. + if (fc == 1 and tc != null) return true; + if (fc != null and tc != null and fc.? >= tc.?) return true; + if (s.types.get(to) == .@"enum" and s.types.isNumeric(from)) return true; + return false; + } + + /// Check `e` as an initializer / assigned value for `target`. + pub fn checkInitializer(s: *Sema, target: TypeId, e: *ast.Expr) Allocator.Error!void { + if (e.kind == .init_list) { + for (e.kind.init_list) |item| { + if (item.kind != .init_list) _ = try s.expr(item) else try s.checkInitializer(TypeTable.error_type, item); + } + e.ty = target; + if (target == TypeTable.error_type) return; + const want = s.types.componentCount(target) orelse return; + const have = s.flatCount(e); + if (have != want and have != 0) { + if (have < want) { + s.err(e.loc, "too few elements in vector initialization (expected {d} elements, have {d})", .{ want, have }); + } else { + s.err(e.loc, "too many elements in vector initialization (expected {d} elements, have {d})", .{ want, have }); + } + } + return; + } + const t = try s.expr(e); + if (t.callee != null and t.ty == TypeTable.error_type) { + if (t.callee.? != .type) s.err(e.loc, "reference to overloaded function could not be resolved", .{}); + return; + } + if (t.ty == TypeTable.error_type or target == TypeTable.error_type) return; + if (s.conversionCost(t.ty, target)) |_| { + s.conversionWarnings(e, t.ty, target); + return; + } + s.err(e.loc, "cannot initialize a variable of type '{s}' with an rvalue of type '{s}'", .{ s.typeName(target), s.typeName(t.ty) }); + } + + fn conversionWarnings(s: *Sema, e: *ast.Expr, from: TypeId, to: TypeId) void { + const fs = s.types.shape(from) orelse return; + const ts = s.types.shape(to) orelse return; + if (fs.kind != .scalar and (ts.rows < fs.rows or ts.cols < fs.cols)) { + s.warn(e.loc, "conversion", "implicit truncation of vector type", .{}); + } + const fc = s.types.component(from).?; + const tc = s.types.component(to).?; + if (fc == .literal_float and tc.isInt()) { + if (s.evalConst(e)) |v| if (v == .float and v.float != @trunc(v.float)) { + s.warn(e.loc, "literal-conversion", "implicit conversion from 'literal float' to '{s}' changes value from {d} to {d}", .{ tc.name(), v.float, @trunc(v.float) }); + }; + } + } + + /// Number of scalars in an initializer list (nested lists flatten). + fn flatCount(s: *Sema, e: *const ast.Expr) u32 { + if (e.kind == .init_list) { + var n: u32 = 0; + for (e.kind.init_list) |item| n += s.flatCount(item); + return n; + } + return s.types.componentCount(e.ty) orelse 1; + } +}; + +// ------------------------------------------------------------------------- +// Helpers + +fn truthy(v: Sema.Const) bool { + return switch (v) { + .int => |x| x != 0, + .float => |x| x != 0, + .bool => |b| b, + }; +} + +fn evalBinary(op: ast.BinaryOp, l: Sema.Const, r: Sema.Const) ?Sema.Const { + if (op == .log_and) return .{ .bool = truthy(l) and truthy(r) }; + if (op == .log_or) return .{ .bool = truthy(l) or truthy(r) }; + const is_float = l == .float or r == .float; + if (is_float) { + const a: f64 = switch (l) { + .int => |x| @floatFromInt(x), + .float => |x| x, + .bool => |b| @floatFromInt(@intFromBool(b)), + }; + const b: f64 = switch (r) { + .int => |x| @floatFromInt(x), + .float => |x| x, + .bool => |x| @floatFromInt(@intFromBool(x)), + }; + return switch (op) { + .add => .{ .float = a + b }, + .sub => .{ .float = a - b }, + .mul => .{ .float = a * b }, + .div => .{ .float = a / b }, + .lt => .{ .bool = a < b }, + .gt => .{ .bool = a > b }, + .le => .{ .bool = a <= b }, + .ge => .{ .bool = a >= b }, + .eq => .{ .bool = a == b }, + .ne => .{ .bool = a != b }, + else => null, + }; + } + const a: i64 = switch (l) { + .int => |x| x, + .bool => |b| @intFromBool(b), + .float => unreachable, + }; + const b: i64 = switch (r) { + .int => |x| x, + .bool => |x| @intFromBool(x), + .float => unreachable, + }; + return switch (op) { + .add => .{ .int = a +% b }, + .sub => .{ .int = a -% b }, + .mul => .{ .int = a *% b }, + .div => if (b == 0) null else .{ .int = @divTrunc(a, b) }, + .rem => if (b == 0) null else .{ .int = @rem(a, b) }, + .shl => .{ .int = if (b < 0 or b >= 64) 0 else a << @intCast(b) }, + .shr => .{ .int = if (b < 0 or b >= 64) 0 else a >> @intCast(b) }, + .bit_and => .{ .int = a & b }, + .bit_or => .{ .int = a | b }, + .bit_xor => .{ .int = a ^ b }, + .lt => .{ .bool = a < b }, + .gt => .{ .bool = a > b }, + .le => .{ .bool = a <= b }, + .ge => .{ .bool = a >= b }, + .eq => .{ .bool = a == b }, + .ne => .{ .bool = a != b }, + else => null, + }; +} + +pub fn parseIntLiteral(text: []const u8) ?i64 { + var end = text.len; + while (end > 0 and std.mem.indexOfScalar(u8, "uUlL", text[end - 1]) != null) end -= 1; + const digits = text[0..end]; + if (digits.len == 0) return null; + if (digits[0] == '\'') return if (digits.len >= 3) digits[1] else null; + var base: u8 = 10; + var body = digits; + if (digits.len > 2 and digits[0] == '0' and (digits[1] == 'x' or digits[1] == 'X')) { + base = 16; + body = digits[2..]; + } else if (digits.len > 1 and digits[0] == '0') { + base = 8; + body = digits[1..]; + } + const v = std.fmt.parseInt(u64, body, base) catch return null; + return @bitCast(v); +} + +fn parseFloatLiteral(text: []const u8) ?f64 { + if (std.mem.indexOf(u8, text, ".#INF") != null) return std.math.inf(f64); + var end = text.len; + while (end > 0 and std.mem.indexOfScalar(u8, "fFhHlL", text[end - 1]) != null) end -= 1; + return std.fmt.parseFloat(f64, text[0..end]) catch null; +} + +/// The digits of a numeric literal (clang's NumericLiteralParser, with +/// dxc's `.#INF`): where the suffix starts and whether it is floating. +fn scanLiteral(text: []const u8) struct { end: usize, float: bool, inf: bool = false } { + var i: usize = 0; + const hex = text.len > 1 and text[0] == '0' and (text[1] == 'x' or text[1] == 'X'); + if (hex) i = 2; + const isDigit = struct { + fn f(c: u8, h: bool) bool { + return if (h) std.ascii.isHex(c) else std.ascii.isDigit(c); + } + }.f; + while (i < text.len and isDigit(text[i], hex)) i += 1; + var float = false; + if (i < text.len and text[i] == '.') { + float = true; + i += 1; + while (i < text.len and isDigit(text[i], hex)) i += 1; + } + const exp_chars: []const u8 = if (hex) "pP" else "eE"; + if (i < text.len and std.mem.indexOfScalar(u8, exp_chars, text[i]) != null) { + var j = i + 1; + if (j < text.len and (text[j] == '+' or text[j] == '-')) j += 1; + if (j < text.len and std.ascii.isDigit(text[j])) { + float = true; + i = j; + while (i < text.len and std.ascii.isDigit(text[i])) i += 1; + } + } + if (float and std.mem.startsWith(u8, text[i..], "#INF")) return .{ .end = i + 4, .float = true, .inf = true }; + return .{ .end = i, .float = float }; +} + +fn isIntSuffix(suffix: []const u8) bool { + const valid = [_][]const u8{ "", "u", "l", "ul", "lu", "ll", "ull", "llu" }; + var buf: [3]u8 = undefined; + if (suffix.len > buf.len) return false; + const lower = std.ascii.lowerString(&buf, suffix); + for (valid) |v| if (std.mem.eql(u8, v, lower)) return true; + return false; +} + +fn intLiteralType(text: []const u8) Scalar { + if (text.len > 0 and text[0] == '\'') return .literal_int; + var unsigned = false; + var longs: u8 = 0; + var i = text.len; + while (i > 0) : (i -= 1) { + switch (text[i - 1]) { + 'u', 'U' => unsigned = true, + 'l', 'L' => longs += 1, + else => break, + } + } + // dxc: `l` is 32-bit, `ll` is 64-bit. + if (longs >= 2) return if (unsigned) .uint64 else .int64; + if (longs == 1) return if (unsigned) .uint else .int; + if (unsigned) return .uint; + return .literal_int; +} + +fn floatLiteralType(text: []const u8) Scalar { + const last = text[text.len - 1]; + return switch (last) { + 'f', 'F' => .float, + 'h', 'H' => .half, + 'l', 'L' => .double, + else => .literal_float, + }; +} + +const Swizzle = struct { count: u8, repeats: bool }; + +/// `xyzw` / `rgba` swizzles (no mixing), up to 4 components. +fn parseSwizzle(name: []const u8, len: u8) ?Swizzle { + if (name.len == 0 or name.len > 4) return null; + const sets = [_][]const u8{ "xyzw", "rgba" }; + for (sets) |set| { + var seen: u8 = 0; + var repeats = false; + var ok = true; + for (name) |c| { + const idx = std.mem.indexOfScalar(u8, set, c) orelse { + ok = false; + break; + }; + if (idx >= len) { + ok = false; + break; + } + const bit = @as(u8, 1) << @intCast(idx); + if (seen & bit != 0) repeats = true; + seen |= bit; + } + if (ok) return .{ .count = @intCast(name.len), .repeats = repeats }; + } + return null; +} + +/// `_m00_m11` (zero-based) or `_11_22` (one-based) matrix subscripts. +fn parseMatrixSwizzle(name: []const u8, rows: u8, cols: u8) ?Swizzle { + var i: usize = 0; + var count: u8 = 0; + var seen: u16 = 0; + var repeats = false; + while (i < name.len) { + if (name[i] != '_') return null; + i += 1; + var zero_based = false; + if (i < name.len and name[i] == 'm') { + zero_based = true; + i += 1; + } + if (i + 2 > name.len) return null; + var r: i32 = @as(i32, name[i]) - '0'; + var c: i32 = @as(i32, name[i + 1]) - '0'; + i += 2; + if (!zero_based) { + r -= 1; + c -= 1; + } + if (r < 0 or c < 0 or r >= rows or c >= cols) return null; + const bit = @as(u16, 1) << @intCast(r * 4 + c); + if (seen & bit != 0) repeats = true; + seen |= bit; + count += 1; + if (count > 4) return null; + } + if (count == 0) return null; + return .{ .count = count, .repeats = repeats }; +} + +fn describeTarget(e: *const ast.Expr) []const u8 { + return switch (e.kind) { + .name => "variable", + else => "expression", + }; +} + +/// Struct member lookup that also searches base structs. +fn structMember(ss: *const StructSema, name: []const u8) ?Symbol { + var sc: ?*Scope = ss.scope; + while (sc) |c| : (sc = c.parent) { + if (c.kind != .@"struct") return null; + if (c.syms.get(name)) |sym| return sym; + } + return null; +} + +/// Resources whose element type defaults to float4 when omitted. +fn isTextureOrTypedBuffer(k: types.ResourceKind) bool { + return switch (k) { + .buffer, .rw_buffer, .texture1d, .texture1d_array, .texture2d, .texture2d_array, .texture2dms, .texture2dms_array, .texture3d, .texture_cube, .texture_cube_array, .rw_texture1d, .rw_texture1d_array, .rw_texture2d, .rw_texture2d_array, .rw_texture2dms, .rw_texture2dms_array, .rw_texture3d => true, + else => false, + }; +} + +fn derivesFrom(derived: *const types.StructInfo, base: *const types.StructInfo) bool { + for (derived.bases.items) |b| { + if (b == base or derivesFrom(b, base)) return true; + } + return false; +} + +fn isVkQualified(callee: *const ast.Expr) bool { + return callee.kind == .name and callee.kind.name.parts.len > 1 and std.mem.eql(u8, callee.kind.name.parts[0], "vk"); +} + +fn isOtherBuiltinObject(n: []const u8) bool { + const names = [_][]const u8{ + "RayQuery", "HitObject", "NodeOutput", "NodeOutputArray", + "EmptyNodeOutput", "EmptyNodeOutputArray", "DispatchNodeInputRecord", "RWDispatchNodeInputRecord", + "GroupNodeInputRecords", "RWGroupNodeInputRecords", "ThreadNodeInputRecord", "RWThreadNodeInputRecord", + "EmptyNodeInput", "GroupNodeOutputRecords", "ThreadNodeOutputRecords", "StateObjectConfig", + "GlobalRootSignature", "LocalRootSignature", "SubobjectToExportsAssociation", "RaytracingShaderConfig", + "RaytracingPipelineConfig", "RaytracingPipelineConfig1", "TriangleHitGroup", "ProceduralPrimitiveHitGroup", + "SubpassInput", "SubpassInputMS", "SpirvType", "SpirvOpaqueType", + "Literal", "integral_constant", "ext_type", "ext_result_id", + "BufferPointer", "SampledTexture2D", "SampledTexture2DArray", "SampledTexture1D", + "SampledTexture1DArray", "SampledTexture3D", "SampledTextureCUBE", "SampledTextureCUBEArray", + "SampledTexture2DMS", "SampledTexture2DMSArray", "WorkgroupSpirvPointer", "__builtin_LinAlgMatrix", + "BuiltInTrianglePositions", "texture", "Texture", "auto", + }; + for (names) |k| if (std.mem.eql(u8, k, n)) return true; + return false; +} + +/// Intrinsic-table namespace holding the methods of a builtin object type. +fn methodNamespace(t: types.Type) ?[]const u8 { + return switch (t) { + .stream => "StreamMethods", + .resource => |r| switch (r.kind) { + .buffer => "BufferMethods", + .rw_buffer => "RWBufferMethods", + .byte_address_buffer => "ByteAddressBufferMethods", + .rw_byte_address_buffer => "RWByteAddressBufferMethods", + .structured_buffer => "StructuredBufferMethods", + .rw_structured_buffer => "RWStructuredBufferMethods", + .append_structured_buffer => "AppendStructuredBufferMethods", + .consume_structured_buffer => "ConsumeStructuredBufferMethods", + .texture1d => "Texture1DMethods", + .texture1d_array => "Texture1DArrayMethods", + .texture2d => "Texture2DMethods", + .texture2d_array => "Texture2DArrayMethods", + .texture2dms => "Texture2DMSMethods", + .texture2dms_array => "Texture2DArrayMSMethods", + .texture3d => "Texture3DMethods", + .texture_cube => "TextureCUBEMethods", + .texture_cube_array => "TextureCUBEArrayMethods", + .rw_texture1d => "RWTexture1DMethods", + .rw_texture1d_array => "RWTexture1DArrayMethods", + .rw_texture2d => "RWTexture2DMethods", + .rw_texture2d_array => "RWTexture2DArrayMethods", + .rw_texture2dms => "RWTexture2DMSMethods", + .rw_texture2dms_array => "RWTexture2DMSArrayMethods", + .rw_texture3d => "RWTexture3DMethods", + .feedback_texture2d => "FeedbackTexture2DMethods", + .feedback_texture2d_array => "FeedbackTexture2DArrayMethods", + .constant_buffer, .texture_buffer, .raytracing_acceleration_structure => null, + .other => null, + }, + else => null, + }; +} + +fn eql(a: []const u8, b: []const u8) bool { + return std.mem.eql(u8, a, b); +} + +// ---------------------------------------------------------------------- +// Tests + +const testing = std.testing; + +/// Runs Sema over `text` (a library: no entry point) and checks every +/// diagnostic, in source order, as "line: severity: message". +fn expectDiags(text: []const u8, opts: Options, expected: []const []const u8) !void { + const gpa = testing.allocator; + var mfs: source.MemoryFs = .{}; + var sm: source.SourceManager = .init(gpa, mfs.fileSystem()); + defer sm.deinit(); + var diags: diag.Diagnostics = .init(gpa); + defer diags.deinit(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const a = arena.allocator(); + var pp = @import("../front/preproc.zig").Preprocessor.init(a, &sm, &diags, .{}); + try pp.enterMainText("t.hlsl", text); + var p = try @import("../front/parser.zig").Parser.fromPreprocessor(a, &diags, &pp); + const tu = try p.parseTranslationUnit(); + var s = try Sema.init(a, &diags, opts); + try s.checkUnit(tu); + var got: std.ArrayList([]const u8) = .empty; + for (diags.sorted()) |d| { + try got.append(a, try std.fmt.allocPrint(a, "{d}: {s}: {s}", .{ sm.presumedLoc(d.loc).line, @tagName(d.severity), d.message })); + } + const joined_got = try std.mem.join(a, "\n", got.items); + const joined_want = try std.mem.join(a, "\n", expected); + try testing.expectEqualStrings(joined_want, joined_got); +} + +test "operator result types follow dxc's CombineBasicTypes" { + try expectDiags( + \\int i; uint u; half h; min16int m16i; min16uint m16u; min12int m12i; min10float m10f; min16float m16f; bool b; + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, "wrong"); + \\_Static_assert(std::is_same::value, "fails"); + \\_Static_assert(std::is_same::value, "fails"); + , .{}, &.{ + "13: warning: ambiguous type for bit shift; use a type suffix on literal values, like 'L' or 'U', or a cast", + "16: error: static_assert failed \"fails\"", + }); +} + +test "literal suffixes" { + try expectDiags( + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(0x7f800000 == asuint(1.#INF), ""); + \\_Static_assert(max(1, -2) == 1, ""); + \\float a = 1#INF; + \\float b = 1.#INFI; + , .{}, &.{ + "8: error: invalid suffix '#INF' on integer constant", + "9: error: invalid suffix 'I' on floating constant", + }); + try expectDiags( + \\_Static_assert(std::is_same::value, ""); + \\_Static_assert(std::is_same::value, ""); + , .{ .enable_16bit = true }, &.{}); +} + +test "declaration modifiers" { + try expectDiags( + \\void f(nointerpolation linear sample float2 g, point line float a, uniform out float b) {} + \\extern static float2 g_ext_sta; + \\typedef extern float2 t_ext; + \\typedef uniform float2 t_uni; + \\groupshared extern float g_gro_ext; + \\struct S { const float c; linear float l; static const float k = 1; }; + \\void g() { in float x; groupshared float y; linear float z; } + \\row_major float3 notMatrix; + \\row_major column_major float2x2 both; + \\linear sample centroid float2 h(float2 p : P) : SV_Target { return p; } + , .{}, &.{ + "1: error: 'nointerpolation' and 'sample' cannot be used together for a parameter", + "1: error: 'point' and 'line' cannot be used together for a parameter", + "1: error: 'out' and 'uniform' cannot be used together for a parameter", + "2: error: cannot combine with previous 'extern' declaration specifier", + "3: error: cannot combine with previous 'typedef' declaration specifier", + "4: error: 'uniform' is not a valid modifier for a typedef", + "5: error: 'extern' and 'groupshared' cannot be used together for a global variable", + "6: error: 'const' is not a valid modifier for a field", + "7: error: HLSL usage 'in' is only valid on a parameter", + "7: error: 'groupshared' is not a valid modifier for a local variable", + "7: error: 'linear' is not a valid modifier for a local variable", + "8: error: 'row_major' can only be used with a matrix type", + "9: error: 'row_major' and 'column_major' attributes are not compatible", + "10: warning: 'centroid' will be overridden by 'sample'", + }); +} + +test "valid code has no diagnostics" { + try expectDiags( + \\struct Base { float a; float get() { return a; } }; + \\struct Derived : Base { float b; }; + \\enum E { A, B }; + \\cbuffer C : register(b0) { float4 tint; row_major float4x4 m; }; + \\Texture2D tex : register(t0); + \\SamplerState samp : register(s0); + \\RWStructuredBuffer buf : register(u0); + \\groupshared float shared_data[64]; + \\float use(Base b) { return b.get(); } + \\float4 main(float2 uv : TEXCOORD, nointerpolation uint id : ID) : SV_Target { + \\ Derived d; d.a = 1; d.b = 2; + \\ E e = A; + \\ auto k = uv.x * 2; + \\ uint n = asuint(k) >> 3u; + \\ InterlockedAdd(buf[id], n); + \\ float4 c = tex.Sample(samp, uv) * tint; + \\ c.xyz = mul(m, c).xyz + max(c.rgb, 0.5); + \\ return c * use((Base)d) * (e == B ? 2.0 : 1.0); + \\} + , .{}, &.{}); +} diff --git a/src/sema/types.zig b/src/sema/types.zig new file mode 100644 index 0000000..7c931a7 --- /dev/null +++ b/src/sema/types.zig @@ -0,0 +1,531 @@ +//! HLSL types, interned in a TypeTable so that type identity is an integer +//! comparison. + +const std = @import("std"); +const Allocator = std.mem.Allocator; + +pub const TypeId = u32; + +/// Scalar (component) types. `literal_*` are the types of unsuffixed +/// literals, which adapt to the other operand as in dxc. +pub const Scalar = enum(u8) { + bool, + int, + uint, + half, + float, + double, + min16float, + min10float, + min16int, + min12int, + min16uint, + int16, + uint16, + int64, + uint64, + float16, + literal_int, + literal_float, + int8_4packed, + uint8_4packed, + + pub fn isFloat(s: Scalar) bool { + return switch (s) { + .half, .float, .double, .min16float, .min10float, .float16, .literal_float => true, + else => false, + }; + } + + pub fn isInt(s: Scalar) bool { + return switch (s) { + .int, .uint, .min16int, .min12int, .min16uint, .int16, .uint16, .int64, .uint64, .literal_int, .int8_4packed, .uint8_4packed => true, + else => false, + }; + } + + pub fn isUnsigned(s: Scalar) bool { + return switch (s) { + .uint, .min16uint, .uint16, .uint64, .uint8_4packed => true, + else => false, + }; + } + + pub fn isLiteral(s: Scalar) bool { + return s == .literal_int or s == .literal_float; + } + + const Props = packed struct(u16) { + boolean: bool = false, + literal: bool = false, + floating: bool = false, + integer: bool = false, + unsigned: bool = false, + min_precision: bool = false, + /// `half` without -enable-16bit-types (32-bit, partial precision). + partial_precision: bool = false, + _: u9 = 0, + }; + + /// dxc's basic-kind properties (g_uBasicKindProps in SemaHLSL.cpp): + /// bit width (0 for bool and literals) and flags. + fn props(s: Scalar) struct { bits: u8, p: Props } { + return switch (s) { + .bool => .{ .bits = 0, .p = .{ .boolean = true, .integer = true } }, + .literal_float => .{ .bits = 0, .p = .{ .floating = true, .literal = true } }, + .literal_int => .{ .bits = 0, .p = .{ .integer = true, .literal = true } }, + .float16 => .{ .bits = 16, .p = .{ .floating = true } }, + .half => .{ .bits = 32, .p = .{ .floating = true, .partial_precision = true } }, + .float => .{ .bits = 32, .p = .{ .floating = true } }, + .double => .{ .bits = 64, .p = .{ .floating = true } }, + .int16 => .{ .bits = 16, .p = .{ .integer = true } }, + .uint16 => .{ .bits = 16, .p = .{ .integer = true, .unsigned = true } }, + .int => .{ .bits = 32, .p = .{ .integer = true } }, + .uint, .int8_4packed, .uint8_4packed => .{ .bits = 32, .p = .{ .integer = true, .unsigned = true } }, + .int64 => .{ .bits = 64, .p = .{ .integer = true } }, + .uint64 => .{ .bits = 64, .p = .{ .integer = true, .unsigned = true } }, + .min10float => .{ .bits = 10, .p = .{ .floating = true, .min_precision = true } }, + .min16float => .{ .bits = 16, .p = .{ .floating = true, .min_precision = true } }, + .min12int => .{ .bits = 12, .p = .{ .integer = true, .min_precision = true } }, + .min16int => .{ .bits = 16, .p = .{ .integer = true, .min_precision = true } }, + .min16uint => .{ .bits = 16, .p = .{ .integer = true, .unsigned = true, .min_precision = true } }, + }; + } + + /// The component type of a binary operation on `a` and `b`: a port of + /// dxc's CombineBasicTypes. + pub fn combine(a: Scalar, b: Scalar) Scalar { + if (a == b) return a; + const l = a.props(); + const r = b.props(); + var bits = @max(l.bits, r.bits); + const lb: u16 = @bitCast(l.p); + const rb: u16 = @bitCast(r.p); + const both: Props = @bitCast(lb & rb); + const either: Props = @bitCast(lb | rb); + if (both.boolean) return .bool; + const float_result = either.floating; + if (both.literal) return if (float_result) .literal_float else .literal_int; + var res: Props = .{ + .integer = both.integer, + .min_precision = both.min_precision, + .partial_precision = both.partial_precision, + .floating = either.floating, + .unsigned = !float_result and either.unsigned, + }; + // A literal or bool operand takes its precision from the other. + if (either.literal or either.boolean) { + res.min_precision = either.min_precision; + res.partial_precision = res.partial_precision or either.partial_precision; + } + if (res.partial_precision) return .half; + // Only one side is floating: the result comes from that side. + if (float_result and !both.floating) { + const f = if (l.p.floating) l else r; + res = f.p; + bits = f.bits; + } + if (bits == 0) bits = 32; + if (float_result) return switch (bits) { + 10 => .min10float, + 16 => if (res.min_precision) .min16float else .float16, + 64 => .double, + else => .float, + }; + return switch (bits) { + 12 => .min12int, + 16 => if (res.unsigned) + (if (res.min_precision) .min16uint else .uint16) + else + (if (res.min_precision) .min16int else .int16), + 64 => if (res.unsigned) .uint64 else .int64, + else => if (res.unsigned) .uint else .int, + }; + } + + /// Rank for the usual arithmetic conversions: higher wins. + pub fn rank(s: Scalar) u8 { + return switch (s) { + .bool => 0, + .literal_int => 1, + .min12int, .min16int => 2, + .min16uint => 3, + .int16 => 4, + .uint16 => 5, + .int, .int8_4packed => 6, + .uint, .uint8_4packed => 7, + .int64 => 8, + .uint64 => 9, + .literal_float => 10, + .min10float, .min16float => 11, + .float16 => 12, + .half => 13, + .float => 14, + .double => 15, + }; + } + + /// Size in bytes of the component as stored (32-bit unless noted). + pub fn size(s: Scalar) u32 { + return switch (s) { + .double, .int64, .uint64 => 8, + .int16, .uint16, .float16 => 2, + else => 4, + }; + } + + /// The concrete type a literal becomes when nothing else decides. + pub fn concrete(s: Scalar) Scalar { + return switch (s) { + .literal_int => .int, + .literal_float => .float, + else => s, + }; + } + + /// HLSL spelling, as dxc prints it. + pub fn name(s: Scalar) []const u8 { + return switch (s) { + .bool => "bool", + .int => "int", + .uint => "uint", + .half => "half", + .float => "float", + .double => "double", + .min16float => "min16float", + .min10float => "min10float", + .min16int => "min16int", + .min12int => "min12int", + .min16uint => "min16uint", + .int16 => "int16_t", + .uint16 => "uint16_t", + .int64 => "int64_t", + .uint64 => "uint64_t", + .float16 => "float16_t", + .literal_int => "literal int", + .literal_float => "literal float", + .int8_4packed => "int8_t4_packed", + .uint8_4packed => "uint8_t4_packed", + }; + } + + /// Scalar named by an HLSL keyword (`dword`, `float32_t` are aliases). + pub fn fromName(n: []const u8) ?Scalar { + const map = [_]struct { []const u8, Scalar }{ + .{ "bool", .bool }, .{ "int", .int }, .{ "uint", .uint }, + .{ "dword", .uint }, .{ "half", .half }, .{ "float", .float }, + .{ "double", .double }, .{ "min16float", .min16float }, .{ "min10float", .min10float }, + .{ "min16int", .min16int }, .{ "min12int", .min12int }, .{ "min16uint", .min16uint }, + .{ "int16_t", .int16 }, .{ "uint16_t", .uint16 }, .{ "int32_t", .int }, + .{ "uint32_t", .uint }, .{ "int64_t", .int64 }, .{ "uint64_t", .uint64 }, + .{ "float16_t", .float16 }, .{ "float32_t", .float }, .{ "float64_t", .double }, + .{ "int8_t4_packed", .int8_4packed }, .{ "uint8_t4_packed", .uint8_4packed }, + }; + for (map) |m| if (std.mem.eql(u8, m[0], n)) return m[1]; + return null; + } +}; + +pub const ResourceKind = enum(u8) { + buffer, + rw_buffer, + byte_address_buffer, + rw_byte_address_buffer, + structured_buffer, + rw_structured_buffer, + append_structured_buffer, + consume_structured_buffer, + texture1d, + texture1d_array, + texture2d, + texture2d_array, + texture2dms, + texture2dms_array, + texture3d, + texture_cube, + texture_cube_array, + rw_texture1d, + rw_texture1d_array, + rw_texture2d, + rw_texture2d_array, + rw_texture2dms, + rw_texture2dms_array, + rw_texture3d, + constant_buffer, + texture_buffer, + raytracing_acceleration_structure, + feedback_texture2d, + feedback_texture2d_array, + /// Any other builtin object (RayQuery, node records, vk:: types...): + /// accepted, with methods resolved through the intrinsic table. + other, + + pub fn isWritable(k: ResourceKind) bool { + return switch (k) { + .rw_buffer, .rw_byte_address_buffer, .rw_structured_buffer, .append_structured_buffer, .rw_texture1d, .rw_texture1d_array, .rw_texture2d, .rw_texture2d_array, .rw_texture2dms, .rw_texture2dms_array, .rw_texture3d => true, + else => false, + }; + } + + /// Dimensions of the integer index used by operator[] (0: no indexing). + pub fn indexDims(k: ResourceKind) u8 { + return switch (k) { + .buffer, .rw_buffer, .structured_buffer, .rw_structured_buffer, .texture1d, .rw_texture1d => 1, + .texture1d_array, .rw_texture1d_array, .texture2d, .rw_texture2d, .texture2dms, .rw_texture2dms => 2, + .texture2d_array, .rw_texture2d_array, .texture2dms_array, .rw_texture2dms_array, .texture3d, .rw_texture3d => 3, + else => 0, + }; + } + + pub const names = [_]struct { []const u8, ResourceKind }{ + .{ "Buffer", .buffer }, .{ "RWBuffer", .rw_buffer }, + .{ "ByteAddressBuffer", .byte_address_buffer }, .{ "RWByteAddressBuffer", .rw_byte_address_buffer }, + .{ "StructuredBuffer", .structured_buffer }, .{ "RWStructuredBuffer", .rw_structured_buffer }, + .{ "AppendStructuredBuffer", .append_structured_buffer }, .{ "ConsumeStructuredBuffer", .consume_structured_buffer }, + .{ "Texture1D", .texture1d }, .{ "Texture1DArray", .texture1d_array }, + .{ "Texture2D", .texture2d }, .{ "Texture2DArray", .texture2d_array }, + .{ "Texture2DMS", .texture2dms }, .{ "Texture2DMSArray", .texture2dms_array }, + .{ "Texture3D", .texture3d }, .{ "TextureCube", .texture_cube }, + .{ "TextureCubeArray", .texture_cube_array }, .{ "RWTexture1D", .rw_texture1d }, + .{ "RWTexture1DArray", .rw_texture1d_array }, .{ "RWTexture2D", .rw_texture2d }, + .{ "RWTexture2DArray", .rw_texture2d_array }, .{ "RWTexture2DMS", .rw_texture2dms }, + .{ "RWTexture2DMSArray", .rw_texture2dms_array }, .{ "RWTexture3D", .rw_texture3d }, + .{ "ConstantBuffer", .constant_buffer }, .{ "TextureBuffer", .texture_buffer }, + .{ "RaytracingAccelerationStructure", .raytracing_acceleration_structure }, .{ "FeedbackTexture2D", .feedback_texture2d }, + .{ "FeedbackTexture2DArray", .feedback_texture2d_array }, + // Rasterizer-ordered views behave like their RW counterparts. + .{ "RasterizerOrderedBuffer", .rw_buffer }, + .{ "RasterizerOrderedByteAddressBuffer", .rw_byte_address_buffer }, .{ "RasterizerOrderedStructuredBuffer", .rw_structured_buffer }, + .{ "RasterizerOrderedTexture1D", .rw_texture1d }, .{ "RasterizerOrderedTexture1DArray", .rw_texture1d_array }, + .{ "RasterizerOrderedTexture2D", .rw_texture2d }, .{ "RasterizerOrderedTexture2DArray", .rw_texture2d_array }, + .{ "RasterizerOrderedTexture3D", .rw_texture3d }, + }; + + pub fn fromName(n: []const u8) ?ResourceKind { + for (names) |m| if (std.mem.eql(u8, m[0], n)) return m[1]; + return null; + } +}; + +pub const Field = struct { + name: []const u8, + type: TypeId, +}; + +/// A struct's layout-relevant information. Methods live in Sema. +pub const StructInfo = struct { + name: []const u8, + fields: std.ArrayList(Field) = .empty, + /// Direct base structs (HLSL 2021 single inheritance, in practice). + bases: std.ArrayList(*StructInfo) = .empty, + /// Opaque pointer to Sema's per-struct data (methods, base). + sema: ?*anyopaque = null, + complete: bool = false, +}; + +pub const EnumInfo = struct { + name: []const u8, + underlying: Scalar, + scoped: bool, +}; + +pub const Type = union(enum) { + void, + /// The type of an ill-formed expression: suppresses follow-on errors. + @"error", + scalar: Scalar, + vector: struct { elem: Scalar, len: u8 }, + matrix: struct { elem: Scalar, rows: u8, cols: u8 }, + /// `len == 0` means unsized (`float a[]`). + array: struct { elem: TypeId, len: u32 }, + @"struct": *StructInfo, + @"enum": *EnumInfo, + /// `elem` is the template argument (or the void type when absent). + resource: struct { kind: ResourceKind, elem: TypeId, name: []const u8 }, + sampler: struct { comparison: bool }, + string, + /// PointStream / LineStream / TriangleStream. + stream: struct { kind: enum { point, line, triangle }, elem: TypeId }, + /// InputPatch / OutputPatch. + patch: struct { output: bool, elem: TypeId, count: u32 }, + /// ResourceDescriptorHeap / SamplerDescriptorHeap (SM 6.6). + descriptor_heap: struct { sampler: bool }, + /// `ResourceDescriptorHeap[i]`: converts to any resource / sampler. + dynamic_resource, +}; + +/// Interns types. Ids 0 and 1 are `error` and `void`. +pub const TypeTable = struct { + gpa: Allocator, + types: std.ArrayList(Type) = .empty, + map: std.AutoHashMapUnmanaged(Key, TypeId) = .empty, + + pub const error_type: TypeId = 0; + pub const void_type: TypeId = 1; + + /// Hashable identity of structural types. + const Key = struct { tag: u8, a: u64, b: u64 }; + + pub fn init(gpa: Allocator) !TypeTable { + var t: TypeTable = .{ .gpa = gpa }; + try t.types.append(gpa, .@"error"); + try t.types.append(gpa, .void); + return t; + } + + pub fn deinit(t: *TypeTable) void { + t.types.deinit(t.gpa); + t.map.deinit(t.gpa); + } + + pub fn get(t: *const TypeTable, id: TypeId) Type { + return t.types.items[id]; + } + + fn keyOf(ty: Type) ?Key { + return switch (ty) { + .void, .@"error" => null, + .scalar => |s| .{ .tag = 1, .a = @backingInt(s), .b = 0 }, + .vector => |v| .{ .tag = 2, .a = @backingInt(v.elem), .b = v.len }, + .matrix => |m| .{ .tag = 3, .a = @backingInt(m.elem), .b = (@as(u64, m.rows) << 8) | m.cols }, + .array => |a| .{ .tag = 4, .a = a.elem, .b = a.len }, + .@"struct" => |s| .{ .tag = 5, .a = @intFromPtr(s), .b = 0 }, + .@"enum" => |e| .{ .tag = 6, .a = @intFromPtr(e), .b = 0 }, + .resource => |r| .{ .tag = 7, .a = (@as(u64, @backingInt(r.kind)) << 32) | r.elem, .b = std.hash.Wyhash.hash(0, r.name) }, + .sampler => |s| .{ .tag = 8, .a = @intFromBool(s.comparison), .b = 0 }, + .string => .{ .tag = 9, .a = 0, .b = 0 }, + .stream => |s| .{ .tag = 10, .a = @backingInt(s.kind), .b = s.elem }, + .patch => |p| .{ .tag = 11, .a = (@as(u64, @intFromBool(p.output)) << 32) | p.elem, .b = p.count }, + .descriptor_heap => |h| .{ .tag = 12, .a = @intFromBool(h.sampler), .b = 0 }, + .dynamic_resource => .{ .tag = 13, .a = 0, .b = 0 }, + }; + } + + pub fn intern(t: *TypeTable, ty: Type) !TypeId { + const key = keyOf(ty) orelse return if (ty == .void) void_type else error_type; + const gop = try t.map.getOrPut(t.gpa, key); + if (gop.found_existing) return gop.value_ptr.*; + try t.types.append(t.gpa, ty); + gop.value_ptr.* = @intCast(t.types.items.len - 1); + return gop.value_ptr.*; + } + + pub fn scalar(t: *TypeTable, s: Scalar) !TypeId { + return t.intern(.{ .scalar = s }); + } + + /// `len == 1` vectors are kept distinct from scalars (float1 != float). + pub fn vector(t: *TypeTable, s: Scalar, len: u8) !TypeId { + return t.intern(.{ .vector = .{ .elem = s, .len = len } }); + } + + pub fn matrix(t: *TypeTable, s: Scalar, rows: u8, cols: u8) !TypeId { + return t.intern(.{ .matrix = .{ .elem = s, .rows = rows, .cols = cols } }); + } + + pub fn array(t: *TypeTable, elem: TypeId, len: u32) !TypeId { + return t.intern(.{ .array = .{ .elem = elem, .len = len } }); + } + + /// Component type of a numeric (scalar / vector / matrix) type. + pub fn component(t: *const TypeTable, id: TypeId) ?Scalar { + return switch (t.get(id)) { + .scalar => |s| s, + .vector => |v| v.elem, + .matrix => |m| m.elem, + .@"enum" => |e| e.underlying, + else => null, + }; + } + + pub const Shape = struct { rows: u8, cols: u8, kind: enum { scalar, vector, matrix } }; + + /// Shape of a numeric type: scalars are 1x1, vectors 1xN. + pub fn shape(t: *const TypeTable, id: TypeId) ?Shape { + return switch (t.get(id)) { + .scalar, .@"enum" => .{ .rows = 1, .cols = 1, .kind = .scalar }, + .vector => |v| .{ .rows = 1, .cols = v.len, .kind = .vector }, + .matrix => |m| .{ .rows = m.rows, .cols = m.cols, .kind = .matrix }, + else => null, + }; + } + + pub fn isNumeric(t: *const TypeTable, id: TypeId) bool { + return t.component(id) != null; + } + + /// Build a numeric type of `shape` with component `s`. + pub fn withShape(t: *TypeTable, s: Scalar, sh: Shape) !TypeId { + return switch (sh.kind) { + .scalar => t.scalar(s), + .vector => t.vector(s, sh.cols), + .matrix => t.matrix(s, sh.rows, sh.cols), + }; + } + + /// Same shape as `id`, different component. + pub fn withComponent(t: *TypeTable, id: TypeId, s: Scalar) !TypeId { + return t.withShape(s, t.shape(id) orelse return error_type); + } + + /// Number of scalar components (flattened), or null for non-numeric + /// aggregates whose size is not defined. + pub fn componentCount(t: *const TypeTable, id: TypeId) ?u32 { + return switch (t.get(id)) { + .scalar, .@"enum" => 1, + .vector => |v| v.len, + .matrix => |m| @as(u32, m.rows) * m.cols, + .array => |a| if (a.len == 0) null else if (t.componentCount(a.elem)) |n| n * a.len else null, + .@"struct" => |s| blk: { + var n: u32 = 0; + for (s.fields.items) |f| n += t.componentCount(f.type) orelse break :blk null; + break :blk n; + }, + else => null, + }; + } + + /// Spelling for diagnostics, close to dxc's (`vector`, + /// `float4`, `MyStruct`, `Texture2D`). + pub fn format(t: *const TypeTable, gpa: Allocator, id: TypeId) Allocator.Error![]const u8 { + return switch (t.get(id)) { + .void => "void", + .@"error" => "", + .scalar => |s| s.name(), + .vector => |v| std.fmt.allocPrint(gpa, "vector<{s}, {d}>", .{ v.elem.name(), v.len }), + .matrix => |m| std.fmt.allocPrint(gpa, "matrix<{s}, {d}, {d}>", .{ m.elem.name(), m.rows, m.cols }), + .array => |a| if (a.len == 0) + std.fmt.allocPrint(gpa, "{s}[]", .{try t.format(gpa, a.elem)}) + else + std.fmt.allocPrint(gpa, "{s}[{d}]", .{ try t.format(gpa, a.elem), a.len }), + .@"struct" => |s| s.name, + .@"enum" => |e| e.name, + .resource => |r| if (r.elem == void_type) r.name else std.fmt.allocPrint(gpa, "{s}<{s}>", .{ r.name, try t.format(gpa, r.elem) }), + .sampler => |s| if (s.comparison) "SamplerComparisonState" else "SamplerState", + .string => "string", + .stream => |s| std.fmt.allocPrint(gpa, "{s}Stream<{s}>", .{ switch (s.kind) { + .point => "Point", + .line => "Line", + .triangle => "Triangle", + }, try t.format(gpa, s.elem) }), + .patch => |p| std.fmt.allocPrint(gpa, "{s}Patch<{s}, {d}>", .{ if (p.output) "Output" else "Input", try t.format(gpa, p.elem), p.count }), + .descriptor_heap => |h| if (h.sampler) "SamplerDescriptorHeap" else "ResourceDescriptorHeap", + .dynamic_resource => "", + }; + } +}; + +test "interning and shapes" { + var t = try TypeTable.init(std.testing.allocator); + defer t.deinit(); + const f4 = try t.vector(.float, 4); + try std.testing.expectEqual(f4, try t.vector(.float, 4)); + try std.testing.expect(f4 != try t.vector(.float, 3)); + try std.testing.expect(try t.vector(.float, 1) != try t.scalar(.float)); + const m = try t.matrix(.float, 4, 4); + try std.testing.expectEqual(@as(?u32, 16), t.componentCount(m)); + try std.testing.expectEqual(try t.vector(.int, 4), try t.withComponent(f4, .int)); + const s = try t.format(std.testing.allocator, f4); + defer std.testing.allocator.free(s); + try std.testing.expectEqualStrings("vector", s); +} diff --git a/tools/gen_intrinsics.zig b/tools/gen_intrinsics.zig new file mode 100644 index 0000000..99ed8af --- /dev/null +++ b/tools/gen_intrinsics.zig @@ -0,0 +1,233 @@ +//! Build-time generator: reads dxc's intrinsic declarations +//! (vendor/dxc/gen_intrin_main.txt) and writes a Zig table that Sema uses +//! for intrinsic and builtin-method overload resolution. +//! +//! Usage: gen_intrinsics +//! +//! Declaration syntax (see the header of gen_intrin_main.txt): +//! [[attrs]] ( , ...) [: ]; +//! grouped into `namespace X { ... } namespace` blocks. + +const std = @import("std"); +const Allocator = std.mem.Allocator; + +const Spec = struct { + qual: []const u8 = "in", + match_layout: i32 = std.math.minInt(i32), + match_comp: i32 = std.math.minInt(i32), + special: []const u8 = "none", + type_n: u32 = 0, + base: []const u8 = "", + any_layout: bool = false, + dims: std.ArrayList([]const u8) = .empty, + name: []const u8 = "", +}; + +const Decl = struct { + ns: []const u8, + name: []const u8, + ret: Spec, + params: std.ArrayList(Spec) = .empty, + varargs: bool = false, + attrs: []const u8, + op: []const u8, +}; + +pub fn main(init: std.process.Init) !void { + const a = init.arena.allocator(); + const io = init.io; + const args = try init.minimal.args.toSlice(a); + if (args.len != 3) return error.Usage; + const text = try std.Io.Dir.cwd().readFileAlloc(io, args[1], a, .limited(1 << 20)); + + var decls: std.ArrayList(Decl) = .empty; + var ns: []const u8 = ""; + var lines = std.mem.splitScalar(u8, text, '\n'); + var lineno: usize = 0; + while (lines.next()) |raw| { + lineno += 1; + const line = std.mem.trim(u8, raw, " \t\r"); + if (line.len == 0 or std.mem.startsWith(u8, line, "//") or line[0] == '#') continue; + if (std.mem.startsWith(u8, line, "namespace ")) { + ns = std.mem.trim(u8, line["namespace ".len..], " {"); + continue; + } + if (line[0] == '}') continue; + const d = parseDecl(a, ns, line) catch |e| { + std.debug.print("gen_intrinsics: line {d}: {s}: {s}\n", .{ lineno, @errorName(e), line }); + return e; + }; + try decls.append(a, d); + } + + var out: std.Io.Writer.Allocating = .init(a); + try emit(&out.writer, decls.items); + try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = args[2], .data = out.written() }); +} + +fn parseDecl(a: Allocator, ns: []const u8, line_in: []const u8) !Decl { + var line = std.mem.trimEnd(u8, line_in, ";"); + // Optional `: op` after the closing parenthesis. + var op: []const u8 = ""; + const close = std.mem.lastIndexOfScalar(u8, line, ')') orelse return error.NoParen; + if (std.mem.indexOfScalarPos(u8, line, close, ':')) |colon| { + op = std.mem.trim(u8, line[colon + 1 ..], " "); + line = line[0..colon]; + } + const open_attr = std.mem.indexOf(u8, line, "[[") orelse return error.NoAttrs; + const close_attr = std.mem.indexOfPos(u8, line, open_attr, "]]") orelse return error.NoAttrs; + const ret_text = std.mem.trim(u8, line[0..open_attr], " "); + const attrs = line[open_attr + 2 .. close_attr]; + const rest = std.mem.trim(u8, line[close_attr + 2 ..], " "); + const lp = std.mem.indexOfScalar(u8, rest, '(') orelse return error.NoParen; + const rp = std.mem.lastIndexOfScalar(u8, rest, ')') orelse return error.NoParen; + var d: Decl = .{ + .ns = ns, + .name = std.mem.trim(u8, rest[0..lp], " "), + .ret = try parseSpec(a, ret_text, false), + .attrs = attrs, + .op = op, + }; + const params_text = std.mem.trim(u8, rest[lp + 1 .. rp], " "); + if (params_text.len > 0) { + var depth: u32 = 0; + var start: usize = 0; + for (params_text, 0..) |c, i| { + if (c == '<') depth += 1; + if (c == '>') depth -= 1; + if ((c == ',' and depth == 0) or i == params_text.len - 1) { + const end = if (c == ',' and depth == 0) i else i + 1; + const p = std.mem.trim(u8, params_text[start..end], " "); + start = i + 1; + if (std.mem.eql(u8, p, "...")) { + d.varargs = true; + continue; + } + try d.params.append(a, try parseSpec(a, p, true)); + } + } + } + return d; +} + +/// `[qual...] type [name]`, where type is `$classT`, `$funcT`, `$typeN`, +/// or `[$match] base[]`. +fn parseSpec(a: Allocator, text: []const u8, is_param: bool) !Spec { + var s: Spec = .{}; + var t = text; + // Qualifiers. + while (true) { + t = std.mem.trimStart(u8, t, " "); + const quals = [_][]const u8{ "inout ", "in ", "out ", "ref ", "row_major ", "col_major " }; + var matched = false; + for (quals) |q| { + if (std.mem.startsWith(u8, t, q)) { + const word = q[0 .. q.len - 1]; + if (!std.mem.eql(u8, word, "row_major") and !std.mem.eql(u8, word, "col_major")) s.qual = word; + t = t[q.len..]; + matched = true; + } + } + if (!matched) break; + } + if (std.mem.startsWith(u8, t, "$match<")) { + const end = std.mem.indexOfScalar(u8, t, '>') orelse return error.BadMatch; + var it = std.mem.splitScalar(u8, t["$match<".len..end], ','); + s.match_layout = try std.fmt.parseInt(i32, std.mem.trim(u8, it.next().?, " "), 10); + s.match_comp = try std.fmt.parseInt(i32, std.mem.trim(u8, it.next() orelse return error.BadMatch, " "), 10); + t = std.mem.trimStart(u8, t[end + 1 ..], " "); + } + if (std.mem.startsWith(u8, t, "$classT")) { + s.special = "class_t"; + t = t["$classT".len..]; + } else if (std.mem.startsWith(u8, t, "$funcT")) { + s.special = "func_t"; + t = t["$funcT".len..]; + } else if (std.mem.startsWith(u8, t, "$type")) { + var i: usize = "$type".len; + while (i < t.len and std.ascii.isDigit(t[i])) i += 1; + s.special = "type_n"; + s.type_n = try std.fmt.parseInt(u32, t["$type".len..i], 10); + t = t[i..]; + } else { + var i: usize = 0; + while (i < t.len and (std.ascii.isAlphanumeric(t[i]) or t[i] == '_')) i += 1; + s.base = t[0..i]; + t = t[i..]; + if (t.len > 0 and t[0] == '<') { + const end = std.mem.indexOfScalar(u8, t, '>') orelse return error.BadLayout; + const inner = std.mem.trim(u8, t[1..end], " "); + if (inner.len == 0) { + s.any_layout = true; + } else { + var it = std.mem.splitScalar(u8, inner, ','); + while (it.next()) |dim| try s.dims.append(a, std.mem.trim(u8, dim, " ")); + } + t = t[end + 1 ..]; + } + } + if (is_param) s.name = std.mem.trim(u8, t, " "); + return s; +} + +fn emitSpec(w: *std.Io.Writer, s: Spec) !void { + try w.print(".{{ .qual = .{s}, .special = .{s}, .type_n = {d}, .base = \"{s}\", .any_layout = {}, .dims = &.{{", .{ if (std.mem.eql(u8, s.qual, "inout")) "inout" else if (std.mem.eql(u8, s.qual, "out")) "out" else if (std.mem.eql(u8, s.qual, "ref")) "ref" else "in", s.special, s.type_n, s.base, s.any_layout }); + for (s.dims.items, 0..) |d, i| { + if (i > 0) try w.writeAll(", "); + try w.print("\"{s}\"", .{d}); + } + try w.writeAll("}, .match_layout = "); + if (s.match_layout == std.math.minInt(i32)) try w.writeAll("null") else try w.print("{d}", .{s.match_layout}); + try w.writeAll(", .match_comp = "); + if (s.match_comp == std.math.minInt(i32)) try w.writeAll("null") else try w.print("{d}", .{s.match_comp}); + try w.print(", .name = \"{s}\" }}", .{s.name}); +} + +fn emit(w: *std.Io.Writer, decls: []const Decl) !void { + try w.writeAll( + \\//! Generated by tools/gen_intrinsics.zig from vendor/dxc/gen_intrin_main.txt. + \\//! Do not edit. + \\ + \\pub const Qual = enum { in, out, inout, ref }; + \\pub const Special = enum { none, class_t, func_t, type_n }; + \\ + \\pub const Spec = struct { + \\ qual: Qual, + \\ special: Special, + \\ type_n: u32, + \\ /// Component class: `float_like`, `numeric`, `uint`, `sampler`, ... + \\ base: []const u8, + \\ /// `<>`: any scalar / vector / matrix layout. + \\ any_layout: bool, + \\ /// Layout dimensions: none (scalar), `{"4"}`, `{"c"}`, `{"r", "c"}` ... + \\ dims: []const []const u8, + \\ match_layout: ?i32, + \\ match_comp: ?i32, + \\ name: []const u8, + \\}; + \\ + \\pub const Intrinsic = struct { + \\ namespace: []const u8, + \\ name: []const u8, + \\ ret: Spec, + \\ params: []const Spec, + \\ varargs: bool, + \\ attrs: []const u8, + \\ op: []const u8, + \\}; + \\ + \\pub const intrinsics = [_]Intrinsic{ + \\ + ); + for (decls) |d| { + try w.print(" .{{ .namespace = \"{s}\", .name = \"{s}\", .ret = ", .{ d.ns, d.name }); + try emitSpec(w, d.ret); + try w.writeAll(", .params = &.{"); + for (d.params.items, 0..) |p, i| { + if (i > 0) try w.writeAll(", "); + try emitSpec(w, p); + } + try w.print("}}, .varargs = {}, .attrs = \"{s}\", .op = \"{s}\" }},\n", .{ d.varargs, d.attrs, d.op }); + } + try w.writeAll("};\n"); +} diff --git a/vendor/PROVENANCE.md b/vendor/PROVENANCE.md index 1daa6aa..41cc1e1 100644 --- a/vendor/PROVENANCE.md +++ b/vendor/PROVENANCE.md @@ -5,6 +5,7 @@ Each entry records the source path and the DXC commit it was copied from. | File | Source in DXC | DXC commit | License | |---|---|---|---| +| `dxc/gen_intrin_main.txt` | `utils/hct/gen_intrin_main.txt` | 55a61aa79 | University of Illinois/NCSA (DXC) | | `dxc/HLSLOptions.td` | `include/dxc/Support/HLSLOptions.td` | d02056da2 | University of Illinois/NCSA (DXC) | | `hlsl-headers/` (all files) | `tools/clang/lib/Headers/hlsl/` | ecb18fb18 | Apache-2.0 WITH LLVM-exception (`hlsl-headers/LICENSE.txt`) | diff --git a/vendor/dxc/gen_intrin_main.txt b/vendor/dxc/gen_intrin_main.txt new file mode 100644 index 0000000..e3cd70b --- /dev/null +++ b/vendor/dxc/gen_intrin_main.txt @@ -0,0 +1,1651 @@ +// Copyright (C) Microsoft Corporation. All rights reserved. +// This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details. +// +// See hctdb.py for the implementation of intrinsic file processing. +// +// Intrinsic declarations are grouped into namespaces that +// turn into qualifiers for the generated names. This lets +// intrinsics be grouped into sets such as base function-style +// intrinsics, Texture1D intrinsics, etc. +// +// Intrinsic declarations are a line of the form: +// +// \[\[[attr]\]\] ([ [, ... ]]) [ : ] +// +// is a C++ identifier for the intrinsic or argument name. +// +// is the D3DIOP_* (or D3DMOP_* if the namespace has "Method" +// in the name) enumerant. By default it's the same as the intrinsic +// name, but can be given to set it arbitrarily. +// +// is one of "in", "out" or "inout" plus optional qualifiers +// "col_major", "row_major". +// variadic functions assume of "in" for any arguments that are not +// explicitly specified. +// +// is where most of the work goes. lets you +// specify particular types and layouts for arguments and +// also lets you indicate which types must share characteristics +// with other types. can be a simple scalar like "bool" +// or it can require an N-vector with "bool" or an N-by-M +// matrix with "bool". You can refer to input columns +// and rows with r, c, r2 and c2, so "float" means a +// float matrix with the same number of rows and columns and +// the size comes from the parse input. "<>" means any kind +// of layout is acceptable. +// +// Basic types are bool, int, uint, u64, float, sampler1d, sampler2d, +// sampler3d, sampler_cube, sampler_cmp, sampler, wave and void. +// There are meta-types too: any_int, uint_only, numeric and any. +// +// Along with a type and layout you can also give relations +// between types in an intrinsic. The types of an intrinsic +// are indexed start with 0 at the return type and increasing +// left to right (first argument is 1, second is 2, etc.). +// $match says that the template type (layout) of +// a particular type must match the template type of the X'th +// type and that the component type (base type) of a particular +// type must match the component type of the Y'th type. +// For example, in "float<> acos(in $match<0, 0> float<> x)" the +// $match<0, 0> means that both the template and component type +// of the argument must match that of the return type (index 0). +// The float<> means that any layout (scalar/vector/matrix) of +// floats is acceptable, and then the parameter and return +// type must match. +// +// A value of -1 for X in $match is a special marker for +// object method intrinsics meaning that the type is taken +// from the object's template type. +// +// A value of -1 for Y in $match is a special marker for +// object method intrinsics meaning that the component type +// of the type is taken from the first subelement of the +// object's template type. +// +// Certain $match situations are aliased for readability +// and conciseness. +// +// $classT - This equates to $match<-1, 0> void and is +// used for method return types that are set from +// the object template type. +// +// $funcT - This equates to $match<-3, 0> void and is +// used for method return types that are set from +// the function template type. +// +// $typeN - This equates to $match and is +// shorthand for a direct match of another type. +// For example, in "$type1 abs(in numeric<> x)" the +// $type means that the return type is a direct match +// of the argument type ($type cannot be used on the +// first argument since there's nothing to match at +// that point and can't refer to the return type as +// it is matched after the inputs). +// + +namespace Intrinsics { + +int<4> [[rn]] D3DCOLORtoUBYTE4(in $match<0, 1> float<4> x) : d3dcolortoubyte4; +uint [[rn]] GetRenderTargetSampleCount() : rtsampleinfo; +float<2> [[rn]] GetRenderTargetSamplePosition(in int s) : rtsamplepos; +void [[]] abort(); +$type1 [[rn,unsigned_op=uabs]] abs(in numeric<> x); +$type1 [[rn]] acos(in float_like<> x); +bool [[rn]] all(in any<> x); +void [[]] AllMemoryBarrier() : syncallmemory_ug; +void [[]] AllMemoryBarrierWithGroupSync() : syncgroupandallmemory_ug; +bool [[rn]] any(in any<> x); +double<> [[rn]] asdouble(in $match<0, 1> uint<> x, in $match<0, 2> uint<> y) : reinterpret_fuse_double; +float<> [[rn]] asfloat(in $match<0, 1> numeric32_only<> x) : reinterpret_float; +float16_t<> [[rn]] asfloat16(in $match<0,1> numeric16_only<> x) : reinterpret_float16; +int16_t<> [[rn]] asint16(in $match<0,1> numeric16_only<> x) : reinterpret_int16; +$type1 [[rn]] asin(in float_like<> x); +int<> [[rn]] asint(in $match<0, 1> numeric32_only<> x) : reinterpret_int; +void [[]] asuint(in double<> d, out $match<1, 2> uint<> x, out $match<1, 3> uint<> y) : reinterpret_split_double_uint; +uint<> [[rn]] asuint(in $match<0, 1> numeric32_only<> x) : reinterpret_uint; +uint16_t<> [[rn]] asuint16(in $match<0,1> numeric16_only<> x) : reinterpret_uint16; +$type1 [[rn]] atan(in float_like<> x); +$type1 [[rn]] atan2(in float_like<> x, in $type1 y); +$type1 [[rn]] ceil(in float_like<> x); +$type1 [[rn,unsigned_op=uclamp]] clamp(in numeric<> x, in $type1 min, in $type1 max); +void [[]] clip(in float<> x); +$type1 [[rn]] cos(in float_like<> x); +$type1 [[rn]] cosh(in float_like<> x); +$match<1, 0> uint<> [[rn]] countbits(in any_int<> x); +$type1 [[rn]] cross(in float_like<3> a, in $type1 b); +$type1 [[rn]] ddx(in float_like<> x); +$type1 [[rn]] ddx_coarse(in float_like<> x); +$type1 [[rn]] ddx_fine(in float_like<> x); +$type1 [[rn]] ddy(in float_like<> x); +$type1 [[rn]] ddy_coarse(in float_like<> x); +$type1 [[rn]] ddy_fine(in float_like<> x); +void [[min_sm=6.10]] DebugBreak(); +$type1 [[rn]] degrees(in float_like<> x); +$match<0, 1> float_like [[rn]] determinant(in float_like x); +void [[]] DeviceMemoryBarrier() : syncdevicememory_ug; +void [[]] DeviceMemoryBarrierWithGroupSync() : syncgroupanddevicememory_ug; +$match<0, 1> float_like [[rn]] distance(in float_like a, in $type1 b); +$match<0, 1> numeric [[rn,unsigned_op=udot]] dot(in numeric a, in $type1 b); +$type1 [[rn]] dst(in numeric<4> a, in $type1 b); +// void errorf(in string Format, ...); +$type1 [[rn]] EvaluateAttributeAtSample(in numeric<> value, in uint index); +$type1 [[rn]] EvaluateAttributeCentroid(in numeric<> value); +$type1 [[rn]] EvaluateAttributeSnapped(in numeric<> value, in int<2> offset); +$type1 [[rn]] GetAttributeAtVertex(in numeric<> value, in uint VertexID); +$type1 [[rn]] exp(in float_like<> x); +$type1 [[rn]] exp2(in float_like<> x); +float<> [[rn]] f16tof32(in uint<> x); +// Use float for DXIL don't support f16 on f32tof16. +uint<> [[rn]] f32tof16(in float<> x); +$type1 [[rn]] faceforward(in float_like N, in $type1 I, in $type1 Ng); +$match<1, 0> uint<> [[rn,unsigned_op=ufirstbithigh,overload=0]] firstbithigh(in any_int<> x); +$match<1, 0> uint<> [[rn]] firstbitlow(in any_int<> x); +$type1 [[rn]] floor(in float_like<> x); +$type1 [[rn]] fma(in double_only<> a, in $type1 b, in $type1 c); +$type1 [[rn]] fmod(in float_like<> a, in $type1 b); +$type1 [[rn]] frac(in float_like<> x); +$type1 [[]] frexp(in float<> x, out $type1 exp); +$type1 [[rn]] fwidth(in float_like<> x); +void [[]] GroupMemoryBarrier() : syncsharedmemory; +void [[]] GroupMemoryBarrierWithGroupSync() : syncgroupandsharedmemory; +// 64-bit integers interlocks +void [[]] InterlockedAdd(ref int64_only result, in u64 value); +void [[]] InterlockedAdd(ref int64_only result, in u64 value, out any_int64 original) : interlockedadd_immediate; +void [[unsigned_op=InterlockedUMin,overload=0]] InterlockedMin(ref int64_only result, in any_int64 value) : interlockedmin; +void [[unsigned_op=InterlockedUMin,overload=0]] InterlockedMin(ref int64_only result, in any_int64 value, out any_int64 original) : interlockedmin_immediate; +void [[unsigned_op=InterlockedUMax,overload=0]] InterlockedMax(ref int64_only result, in any_int64 value) : interlockedmax; +void [[unsigned_op=InterlockedUMax,overload=0]] InterlockedMax(ref int64_only result, in any_int64 value, out any_int64 original) : interlockedmax_immediate; +void [[]] InterlockedAnd(ref int64_only result, in u64 value); +void [[]] InterlockedAnd(ref int64_only result, in u64 value, out any_int64 original) : interlockedand_immediate; +void [[]] InterlockedOr(ref int64_only result, in u64 value); +void [[]] InterlockedOr(ref int64_only result, in u64 value, out any_int64 original) : interlockedor_immediate; +void [[]] InterlockedXor(ref int64_only result, in u64 value); +void [[]] InterlockedXor(ref int64_only result, in u64 value, out any_int64 original) : interlockedxor_immediate; +void [[]] InterlockedCompareStore(ref int64_only result, in u64 compare, in u64 value); +void [[]] InterlockedExchange(ref int64_only result, in any_int64 value, out any_int64 original); +void [[]] InterlockedCompareExchange(ref int64_only result, in u64 compare, in u64 value, out any_int64 original); +// floating point interlocks +void [[]] InterlockedExchange(ref float32_only result, in float value, out float original); +void [[]] InterlockedCompareStoreFloatBitwise(ref float32_only result, in float compare, in float value); +void [[]] InterlockedCompareExchangeFloatBitwise(ref float32_only result, in float compare, in float value, out float original); +// 32-bit integer interlocks +void [[]] InterlockedAdd(ref int32_only result, in uint value); +void [[]] InterlockedAdd(ref int32_only result, in uint value, out any_int32 original) : interlockedadd_immediate; +void [[unsigned_op=InterlockedUMin,overload=0]] InterlockedMin(ref int32_only result, in any_int32 value) : interlockedmin; +void [[unsigned_op=InterlockedUMin,overload=0]] InterlockedMin(ref int32_only result, in any_int32 value, out any_int32 original) : interlockedmin_immediate; +void [[unsigned_op=InterlockedUMax,overload=0]] InterlockedMax(ref int32_only result, in any_int32 value) : interlockedmax; +void [[unsigned_op=InterlockedUMax,overload=0]] InterlockedMax(ref int32_only result, in any_int32 value, out any_int32 original) : interlockedmax_immediate; +void [[]] InterlockedAnd(ref int32_only result, in uint value); +void [[]] InterlockedAnd(ref int32_only result, in uint value, out any_int32 original) : interlockedand_immediate; +void [[]] InterlockedOr(ref int32_only result, in uint value); +void [[]] InterlockedOr(ref int32_only result, in uint value, out any_int32 original) : interlockedor_immediate; +void [[]] InterlockedXor(ref int32_only result, in uint value); +void [[]] InterlockedXor(ref int32_only result, in uint value, out any_int32 original) : interlockedxor_immediate; +void [[]] InterlockedCompareStore(ref int32_only result, in uint compare, in uint value); +void [[]] InterlockedExchange(ref int32_only result, in uint value, out any_int32 original); +void [[]] InterlockedCompareExchange(ref int32_only result, in uint compare, in uint value, out any_int32 original); +$match<1, 0> bool<> [[rn]] isfinite(in float_like<> x); +$match<1, 0> bool<> [[rn]] isinf(in float_like<> x); +$match<1, 0> bool<> [[rn]] isnan(in float_like<> x); +$match<1, 0> bool<> [[rn]] isnormal(in float_like<> x); +$type1 [[rn]] ldexp(in float_like<> x, in $type1 exp); +$match<0, 1> float_like [[rn]] length(in float_like x); +$type1 [[rn]] lerp(in float_like<> a, in $type1 b, in $type1 s); +$match<0, 1> float_like<4> [[rn]] lit(in float_like l, in $match<2, 1> float_like h, in $match<3, 1> float_like m); +$type1 [[rn]] log(in float_like<> x); +$type1 [[rn]] log10(in float_like<> x); +$type1 [[rn]] log2(in float_like<> x); +$type1 [[rn,unsigned_op=umad]] mad(in numeric<> a, in $type1 b, in $type1 c); +$type1 [[rn,unsigned_op=umax]] max(in numeric<> a, in $type1 b); +$type1 [[rn,unsigned_op=umin]] min(in numeric<> a, in $type1 b); +$type1 [[]] modf(in float_like<> x, out $type1 ip); +uint<4> [[rn]] msad4(in uint reference, in uint<2> source, in uint<4> accum); +numeric [[rn,unsigned_op=umul]] mul(in $match<1, 0> numeric a, in $match<2, 0> numeric b) : mul_ss; +numeric [[rn,unsigned_op=umul]] mul(in $match<1, 0> numeric a, in $match<2, 0> numeric b) : mul_sv; +numeric [[rn,unsigned_op=umul]] mul(in $match<1, 0> numeric a, in $match<2, 0> numeric b) : mul_sm; +numeric [[rn,unsigned_op=umul]] mul(in $match<1, 0> numeric a, in $match<2, 0> numeric b) : mul_vs; +numeric [[rn,unsigned_op=umul]] mul(in $match<1, 0> numeric a, in $match<2, 0> numeric b) : mul_vv; +numeric [[rn,unsigned_op=umul]] mul(in $match<1, 0> numeric a, in col_major $match<2, 0> numeric b) : mul_vm; +numeric [[rn,unsigned_op=umul]] mul(in $match<1, 0> numeric a, in $match<2, 0> numeric b) : mul_ms; +numeric [[rn,unsigned_op=umul]] mul(in row_major $match<1, 0> numeric a, in $match<2, 0> numeric b) : mul_mv; +numeric [[rn,unsigned_op=umul]] mul(in row_major $match<1, 0> numeric a, in col_major $match<2, 0> numeric b) : mul_mm; +$type1 [[rn]] normalize(in float_like x); +$type1 [[rn]] pow(in float_like<> x, in $type1 y); +void [[]] printf(in string Format, ...); +void [[]] Process2DQuadTessFactorsAvg(in float<4> RawEdgeFactors, in float<2> InsideScale, out float<4> RoundedEdgeFactors, out float<2> RoundedInsideFactors, out float<2> UnroundedInsideFactors) : ptf_2dqavg; +void [[]] Process2DQuadTessFactorsMax(in float<4> RawEdgeFactors, in float<2> InsideScale, out float<4> RoundedEdgeFactors, out float<2> RoundedInsideFactors, out float<2> UnroundedInsideFactors) : ptf_2dqmax; +void [[]] Process2DQuadTessFactorsMin(in float<4> RawEdgeFactors, in float<2> InsideScale, out float<4> RoundedEdgeFactors, out float<2> RoundedInsideFactors, out float<2> UnroundedInsideFactors) : ptf_2dqmin; +void [[]] ProcessIsolineTessFactors(in float<1> RawDetailFactor, in float<1> RawDensityFactor, out float<1> RoundedDetailFactorr, out float<1> RoundedDensityFactor) : ptf_i; +void [[]] ProcessQuadTessFactorsAvg(in float<4> RawEdgeFactors, in float<1> InsideScale, out float<4> RoundedEdgeFactors, out float<2> RoundedInsideFactors, out float<2> UnroundedInsideFactors) : ptf_qavg; +void [[]] ProcessQuadTessFactorsMax(in float<4> RawEdgeFactors, in float<1> InsideScale, out float<4> RoundedEdgeFactors, out float<2> RoundedInsideFactors, out float<2> UnroundedInsideFactors) : ptf_qmax; +void [[]] ProcessQuadTessFactorsMin(in float<4> RawEdgeFactors, in float<1> InsideScale, out float<4> RoundedEdgeFactors, out float<2> RoundedInsideFactors, out float<2> UnroundedInsideFactors) : ptf_qmin; +void [[]] ProcessTriTessFactorsAvg(in float<3> RawEdgeFactors, in float<1> InsideScale, out float<3> RoundedEdgeFactors, out float<1> RoundedInsideFactor, out float<1> UnroundedInsideFactor) : ptf_tmin; +void [[]] ProcessTriTessFactorsMax(in float<3> RawEdgeFactors, in float<1> InsideScale, out float<3> RoundedEdgeFactors, out float<1> RoundedInsideFactor, out float<1> UnroundedInsideFactor) : ptf_tmax; +void [[]] ProcessTriTessFactorsMin(in float<3> RawEdgeFactors, in float<1> InsideScale, out float<3> RoundedEdgeFactors, out float<1> RoundedInsideFactor, out float<1> UnroundedInsideFactor) : ptf_tavg; +$type1 [[rn]] radians(in float_like<> x); +$type1 [[rn]] rcp(in any_float<> x) : rcp_approx; +$type1 [[rn]] reflect(in float_like i, in $type1 n); +$type1 [[rn]] refract(in float_like i, in $type1 n, in $match<3, 1> float_like ri); +$type1 [[rn]] reversebits(in any_int<> x); +$type1 [[rn]] round(in float_like<> x); +$type1 [[rn]] rsqrt(in float_like<> x); +$type1 [[rn]] saturate(in any_float<> x); +$match<1, 0> int<> [[rn,unsigned_op=usign,overload=0]] sign(in numeric<> x); +$type1 [[rn]] sin(in float_like<> x); +void [[]] sincos(in float_like<> x, out $type1 s, out $type1 c); +$type1 [[rn]] sinh(in float_like<> x); +$type1 [[rn]] smoothstep(in float_like<> a, in $type1 b, in $type1 x); +void [[]] source_mark(); +$type1 [[rn]] sqrt(in float_like<> x); +$type1 [[rn]] step(in float_like<> a, in $type1 x); +$type1 [[rn]] tan(in float_like<> x); +$type1 [[rn]] tanh(in float_like<> x); +float_like<4> [[ro]] tex1D(in sampler1d s, in float_like x) : tex1d; +float_like<4> [[ro]] tex1D(in sampler1d s, in float_like<1> x, in $type2 ddx, in $type2 ddy) : tex1d_dd; +float_like<4> [[ro]] tex1Dbias(in sampler1d s, in float_like<4> x) : tex1d_bias; +float_like<4> [[ro]] tex1Dgrad(in sampler1d s, in float_like<1> x, in $type2 ddx, in $type2 ddy) : tex1d_dd; +float_like<4> [[ro]] tex1Dlod(in sampler1d s, in float_like<4> x) : tex1d_lod; +float_like<4> [[ro]] tex1Dproj(in sampler1d s, in float_like<4> x) : tex1d_proj; +float_like<4> [[ro]] tex2D(in sampler2d s, in float_like<2> x) : tex2d; +float_like<4> [[ro]] tex2D(in sampler2d s, in float_like<2> x, in $type2 ddx, in $type2 ddy) : tex2d_dd; +float_like<4> [[ro]] tex2Dbias(in sampler2d s, in float_like<4> x) : tex2d_bias; +float_like<4> [[ro]] tex2Dgrad(in sampler2d s, in float_like<2> x, in $type2 ddx, in $type2 ddy) : tex2d_dd; +float_like<4> [[ro]] tex2Dlod(in sampler2d s, in float_like<4> x) : tex2d_lod; +float_like<4> [[ro]] tex2Dproj(in sampler2d s, in float_like<4> x) : tex2d_proj; +float_like<4> [[ro]] tex3D(in sampler3d s, in float_like<3> x) : tex3d; +float_like<4> [[ro]] tex3D(in sampler3d s, in float_like<3> x, in $type2 ddx, in $type2 ddy) : tex3d_dd; +float_like<4> [[ro]] tex3Dbias(in sampler3d s, in float_like<4> x) : tex3d_bias; +float_like<4> [[ro]] tex3Dgrad(in sampler3d s, in float_like<3> x, in $type2 ddx, in $type2 ddy) : tex3d_dd; +float_like<4> [[ro]] tex3Dlod(in sampler3d s, in float_like<4> x) : tex3d_lod; +float_like<4> [[ro]] tex3Dproj(in sampler3d s, in float_like<4> x) : tex3d_proj; +float_like<4> [[ro]] texCUBE(in sampler_cube s, in float_like<3> x) : texcube; +float_like<4> [[ro]] texCUBE(in sampler_cube s, in float_like<3> x, in $type2 ddx, in $type2 ddy) : texcube_dd; +float_like<4> [[ro]] texCUBEbias(in sampler_cube s, in float_like<4> x) : texcube_bias; +float_like<4> [[ro]] texCUBEgrad(in sampler_cube s, in float_like<3> x, in $type2 ddx, in $type2 ddy) : texcube_dd; +float_like<4> [[ro]] texCUBElod(in sampler_cube s, in float_like<4> x) : texcube_lod; +float_like<4> [[ro]] texCUBEproj(in sampler_cube s, in float_like<4> x) : texcube_proj; +$match<1, 1> any [[rn]] transpose(in any x); +$type1 [[rn]] trunc(in float_like<> x); +bool [[rn]] CheckAccessFullyMapped(in uint_only status) : check_access_fully_mapped; +uint [[rn]] AddUint64(in $match<1, 0> uint a, in $match<2, 0> uint b) : adduint64; +$type1 [[rn]] NonUniformResourceIndex(in any<> index) : nonuniform_resource_index; + +// Wave intrinsics. Only those that depend on the exec mask are marked as wave-sensitive +bool [[wv]] WaveIsFirstLane(); +uint [[ro]] WaveGetLaneIndex(); +uint [[rn]] WaveGetLaneCount(); +bool [[wv]] WaveActiveAnyTrue(in bool cond); +bool [[wv]] WaveActiveAllTrue(in bool cond); +$match<1, 0> bool<> [[wv]] WaveActiveAllEqual(in any<> value); +uint<4> [[wv]] WaveActiveBallot(in bool cond); +$type1 [[]] WaveReadLaneAt(in any<> value, in uint lane); +$type1 [[wv]] WaveReadLaneFirst(in any<> value); +uint [[wv]] WaveActiveCountBits(in bool value); +$type1 [[unsigned_op=WaveActiveUSum,wv]] WaveActiveSum(in numeric<> value); +$type1 [[unsigned_op=WaveActiveUProduct,wv]] WaveActiveProduct(in numeric<> value); +$type1 [[wv]] WaveActiveBitAnd(in uint_only<> value); +$type1 [[wv]] WaveActiveBitOr(in uint_only<> value); +$type1 [[wv]] WaveActiveBitXor(in uint_only<> value); +$type1 [[unsigned_op=WaveActiveUMin,wv]] WaveActiveMin(in numeric<> value); +$type1 [[unsigned_op=WaveActiveUMax,wv]] WaveActiveMax(in numeric<> value); +uint [[wv]] WavePrefixCountBits(in bool value); +$type1 [[unsigned_op=WavePrefixUSum,wv]] WavePrefixSum(in numeric<> value); +$type1 [[unsigned_op=WavePrefixUProduct,wv]] WavePrefixProduct(in numeric<> value); +uint<4> [[wv]] WaveMatch(in numeric<> value); +$type1 [[wv]] WaveMultiPrefixBitAnd(in any_int<> value, in uint<4> mask); +$type1 [[wv]] WaveMultiPrefixBitOr(in any_int<> value, in uint<4> mask); +$type1 [[wv]] WaveMultiPrefixBitXor(in any_int<> value, in uint<4> mask); +uint [[wv]] WaveMultiPrefixCountBits(in bool value, in uint<4> mask); +$type1 [[unsigned_op=WaveMultiPrefixUProduct,wv]] WaveMultiPrefixProduct(in numeric<> value, in uint<4> mask); +$type1 [[unsigned_op=WaveMultiPrefixUSum,wv]] WaveMultiPrefixSum(in numeric<> value, in uint<4> mask); +$type1 [[]] QuadReadLaneAt(in numeric<> value, in uint quadLane); +$type1 [[]] QuadReadAcrossX(in numeric<> value); +$type1 [[]] QuadReadAcrossY(in numeric<> value); +$type1 [[]] QuadReadAcrossDiagonal(in numeric<> value); +bool [[]] QuadAny(in bool cond); +bool [[]] QuadAll(in bool cond); +uint [[rn,min_sm=6.10]] GetGroupWaveIndex(); +uint [[rn,min_sm=6.10]] GetGroupWaveCount(); + +// Raytracing +void [[]] TraceRay(in acceleration_struct AccelerationStructure, in uint RayFlags, in uint InstanceInclusionMask, in uint RayContributionToHitGroupIndex, in uint MultiplierForGeometryContributionToHitGroupIndex, in uint MissShaderIndex, in ray_desc Ray, inout udt Payload); + +bool [[]] ReportHit(in float THit, in uint HitKind, in udt Attributes); +void [[]] CallShader(in uint ShaderIndex, inout udt Parameter); +void [[]] IgnoreHit(); +void [[]] AcceptHitAndEndSearch(); +uint<3> [[rn]] DispatchRaysIndex(); +uint<3> [[rn]] DispatchRaysDimensions(); +// group: Ray Vectors +float<3> [[rn]] WorldRayOrigin(); +float<3> [[rn]] WorldRayDirection(); +float<3> [[rn]] ObjectRayOrigin(); +float<3> [[rn]] ObjectRayDirection(); +// group: RayT +float [[rn]] RayTMin(); +float [[rn]] RayTCurrent(); +// group: Raytracing uint System Values +uint [[rn]] PrimitiveIndex(); +uint [[rn]] InstanceID(); +uint [[rn]] InstanceIndex(); +uint [[rn]] GeometryIndex(); +uint [[rn]] HitKind(); +uint [[rn]] RayFlags(); +// group: Ray Transforms +float<3,4> [[rn]] ObjectToWorld(); +float<3,4> [[rn]] WorldToObject(); +float<3,4> [[rn]] ObjectToWorld3x4(); +float<3,4> [[rn]] WorldToObject3x4(); +float<4,3> [[rn]] ObjectToWorld4x3(); +float<4,3> [[rn]] WorldToObject4x3(); + +uint [[rn,min_sm=6.10]] ClusterID(); +triangle_positions [[rn,min_sm=6.10]] TriangleObjectPositions(); + +// Packed dot products with accumulate: +uint [[rn]] dot4add_u8packed(in uint a, in $type1 b, in uint c); +int [[rn]] dot4add_i8packed(in uint a, in $type1 b, in int c); +float [[rn]] dot2add(in float16_t<2> a, in $type1 b, in float c); + +// Unpacking intrinsics +int16_t<4> [[rn]] unpack_s8s16(in p32i8 pk); +uint16_t<4> [[rn]] unpack_u8u16(in p32u8 pk); +int<4> [[rn]] unpack_s8s32(in p32i8 pk); +uint<4> [[rn]] unpack_u8u32(in p32u8 pk); + +// Packing intrinsics +p32i8 [[rn]] pack_s8(in any_int16or32<4> v); +p32u8 [[rn]] pack_u8(in any_int16or32<4> v); +p32i8 [[rn]] pack_clamp_s8(in sint16or32_only<4> v); +p32u8 [[rn]] pack_clamp_u8(in sint16or32_only<4> v); + +// Mesh shader intrinsics: +void [[]] SetMeshOutputCounts(in uint numVertices, in uint numPrimitives); + +// Amplification shader intrinsics: +void [[]] DispatchMesh(in uint threadGroupCountX, in uint threadGroupCountY, in uint threadGroupCountZ, in udt meshPayload); + +// Return true if the current lane is a helper lane +bool [[ro]] IsHelperLane(); + +// HL Op for allocating ray query object +uint [[hidden]] AllocateRayQuery(in uint flags, in uint rayqueryflags); + +resource [[hidden]] CreateResourceFromHeap(in uint index); + +// Replacement for vector logical &&, ||, and ternary conditional operators, +// For use when HLSL changes to support short-circuiting and only scalar +// conditions to maintain clarity. +$match<1, 0> bool<> [[rn]] and(in bool<> x, in $type1 y); +$match<1, 0> bool<> [[rn]] or(in bool<> x, in $type1 y); +$type2 [[rn]] select(in bool<> cond, in $match<1, 2> any<> t, in $type2 f); +$type2 [[rn]] select(in bool cond, in any_sampler t, in $type2 f); + +// Work Graph intrinsics +void [[]] Barrier(in uint MemoryTypeFlags, in uint SemanticFlags); +void [[]] Barrier(in NodeRecordOrUAV o, in uint SemanticFlags); + +uint [[min_sm=6.8,max_sm=6.9]] GetRemainingRecursionLevels(); + +} namespace + + +// SPIRV Change Starts +namespace VkIntrinsics { + +u64 [[]] ReadClock(in uint scope); +$funcT [[ro]] RawBufferLoad(in u64 addr); +$funcT [[ro]] RawBufferLoad(in u64 addr, in uint alignment); +void [[]] RawBufferStore(in u64 addr, in $funcT value); +void [[]] RawBufferStore(in u64 addr, in $funcT value, in uint alignment); +void [[]] ext_execution_mode(in uint mode, ...); +void [[]] ext_execution_mode_id(in uint mode, ...); +$funcT2 [[]] static_pointer_cast(in VkBufferPointer ptr); +$funcT2 [[]] reinterpret_pointer_cast(in VkBufferPointer ptr); + +} namespace + +namespace BufferPointerMethods { +$classT [[ro]] GetBufferContents(); +} namespace +// SPIRV Change Ends + +namespace StreamMethods { + +void [[]] Append(in $match<-1, 1> void x) : stream_append; +void [[]] RestartStrip() : stream_restart; + +} namespace + +namespace Texture1DMethods { +// Use float for DXIL don't support f16 on CalcLOD. +float [[ro]] CalculateLevelOfDetail(in any_sampler s, in float<1> x) : tex1d_t_calc_lod; +float [[ro]] CalculateLevelOfDetailUnclamped(in any_sampler s, in float<1> x) : tex1d_t_calc_lod_unclamped; +void [[]] GetDimensions(in uint x, out uint_only width, out $type2 levels) : resinfo_uint; +void [[]] GetDimensions(in uint x, out float_like width, out $type2 levels) : resinfo; +void [[]] GetDimensions(out uint_only width) : resinfo_o; +void [[]] GetDimensions(out float_like width) : resinfo_o; +$classT [[ro]] Load(in int<2> x) : tex1d_t_load; +$classT [[ro]] Load(in int<2> x, in int<1> o) : tex1d_t_load_o; +$classT [[]] Load(in int<2> x, in int<1> o, out uint_only status) : tex1d_t_load_o_s; +$classT [[ro]] Sample(in sampler s, in float<1> x) : tex1d_t; +$classT [[ro]] Sample(in sampler s, in float<1> x, in int<1> o) : tex1d_t_o; +$classT [[ro]] SampleBias(in sampler s, in float<1> x, in float bias) : tex1d_t_bias; +$classT [[ro]] SampleBias(in sampler s, in float<1> x, in float bias, in int<1> o) : tex1d_t_bias_o; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<1> x, in float compareValue) : tex1d_t_comp; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<1> x, in float compareValue, in int<1> o) : tex1d_t_comp_o; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<1> x, in float compareValue, in float bias) : tex1d_t_comp_bias; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<1> x, in float compareValue, in float bias, in int<1> o) : tex1d_t_comp_bias_o; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<1> x, in float compareValue, in $type2 ddx, in $type2 ddy) : tex1d_t_comp_dd; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<1> x, in float compareValue, in $type2 ddx, in $type2 ddy, in int<1> o) : tex1d_t_comp_dd_o; +float_like [[ro]] SampleCmpLevel(in sampler_cmp s, in float<1> x, in float compareValue, in float lod); +float_like [[ro]] SampleCmpLevel(in sampler_cmp s, in float<1> x, in float compareValue, in float lod, in int<1> o); +float_like [[ro]] SampleCmpLevelZero(in sampler_cmp s, in float<1> x, in float compareValue) : tex1d_t_comp_lz; +float_like [[ro]] SampleCmpLevelZero(in sampler_cmp s, in float<1> x, in float compareValue, in int<1> o) : tex1d_t_comp_lz_o; +$classT [[ro]] SampleGrad(in sampler s, in float<1> x, in $type2 ddx, in $type2 ddy) : tex1d_t_dd; +$classT [[ro]] SampleGrad(in sampler s, in float<1> x, in $type2 ddx, in $type2 ddy, in int<1> o) : tex1d_t_dd_o; +$classT [[ro]] SampleLevel(in sampler s, in float<1> x, in float lod) : tex1d_t_lod; +$classT [[ro]] SampleLevel(in sampler s, in float<1> x, in float lod, in int<1> o) : tex1d_t_lod_o; +$classT [[ro]] Sample(in sampler s, in float<1> x, in int<1> o, in float clamp) : tex1d_t_o_cl; +$classT [[]] Sample(in sampler s, in float<1> x, in int<1> o, in float clamp, out uint_only status) : tex1d_t_o_cl_s; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<1> x, in float compareValue, in int<1> o, in float clamp) : tex1d_t_comp_o_cl; +float_like [[]] SampleCmp(in sampler_cmp s, in float<1> x, in float compareValue, in int<1> o, in float clamp, out uint_only status) : tex1d_t_comp_o_cl_s; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<1> x, in float compareValue, in float bias, in int<1> o, in float clamp) : tex1d_t_comp_bias_o_cl; +float_like [[]] SampleCmpBias(in sampler_cmp s, in float<1> x, in float compareValue, in float bias, in int<1> o, in float clamp, out uint_only status) : tex1d_t_comp_bias_o_cl_s; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<1> x, in float compareValue, in $type2 ddx, in $type2 ddy, in int<1> o, in float clamp) : tex1d_t_comp_dd_o_cl; +float_like [[]] SampleCmpGrad(in sampler_cmp s, in float<1> x, in float compareValue, in $type2 ddx, in $type2 ddy, in int<1> o, in float clamp, out uint_only status) : tex1d_t_comp_dd_o_cl_s; +float_like [[]] SampleCmpLevel(in sampler_cmp s, in float<1> x, in float compareValue, in float lod, in int<1> o, out uint_only status); +float_like [[]] SampleCmpLevelZero(in sampler_cmp s, in float<1> x, in float compareValue, in int<1> o, out uint_only status) : tex1d_t_comp_o_s; +$classT [[]] SampleLevel(in sampler s, in float<1> x, in float lod, in int<1> o, out uint_only status) : tex1d_t_lod_o_s; +$classT [[ro]] SampleBias(in sampler s, in float<1> x, in float bias, in int<1> o, in float clamp) : tex1d_t_bias_o_cl; +$classT [[]] SampleBias(in sampler s, in float<1> x, in float bias, in int<1> o, in float clamp, out uint_only status) : tex1d_t_bias_o_cl_s; +$classT [[]] SampleGrad(in sampler s, in float<1> x, in $type2 ddx, in $type2 ddy, in int<1> o, in float clamp) : tex1d_t_dd_o_cl; +$classT [[]] SampleGrad(in sampler s, in float<1> x, in $type2 ddx, in $type2 ddy, in int<1> o, in float clamp, out uint_only status) : tex1d_t_dd_o_cl_s; +} namespace + +namespace Texture1DArrayMethods { + +float [[ro]] CalculateLevelOfDetail(in any_sampler s, in float<1> x) : tex1d_t_calc_lod_array; +float [[ro]] CalculateLevelOfDetailUnclamped(in any_sampler s, in float<1> x) : tex1d_t_calc_lod_unclamped_array; +void [[]] GetDimensions(in uint x, out uint_only width, out $type2 elements, out $type2 levels) : resinfo_uint; +void [[]] GetDimensions(in uint x, out float_like width, out $type2 elements, out $type2 levels) : resinfo; +void [[]] GetDimensions(out uint_only width, out $type1 elements) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 elements) : resinfo_o; +$classT [[ro]] Load(in int<3> x) : tex1d_t_load_array; +$classT [[ro]] Load(in int<3> x, in int<1> o) : tex1d_t_load_array_o; +$classT [[]] Load(in int<3> x, in int<1> o, out uint_only status) : tex1d_t_load_array_o_s; +$classT [[ro]] Sample(in sampler s, in float<2> x) : tex1d_t_array; +$classT [[ro]] Sample(in sampler s, in float<2> x, in int<1> o) : tex1d_t_array_o; +$classT [[ro]] SampleBias(in sampler s, in float<2> x, in float bias) : tex1d_t_bias_array; +$classT [[ro]] SampleBias(in sampler s, in float<2> x, in float bias, in int<1> o) : tex1d_t_bias_array_o; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<2> x, in float compareValue) : tex1d_t_comp_array; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<2> x, in float compareValue, in int<1> o) : tex1d_t_comp_array_o; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<2> x, in float compareValue, in float bias) : tex1d_t_comp_bias_array; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<2> x, in float compareValue, in float bias, in int<1> o) : tex1d_t_comp_bias_array_o; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<2> x, in float compareValue, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy) : tex1d_t_comp_dd_array; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<2> x, in float compareValue, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy, in int<1> o) : tex1d_t_comp_dd_array_o; +float_like [[ro]] SampleCmpLevel(in sampler_cmp s, in float<2> x, in float compareValue, in float lod); +float_like [[ro]] SampleCmpLevel(in sampler_cmp s, in float<2> x, in float compareValue, in float lod, in int<1> o); +float_like [[ro]] SampleCmpLevelZero(in sampler_cmp s, in float<2> x, in float compareValue) : tex1d_t_comp_lz_array; +float_like [[ro]] SampleCmpLevelZero(in sampler_cmp s, in float<2> x, in float compareValue, in int<1> o) : tex1d_t_comp_lz_array_o; +$classT [[ro]] SampleGrad(in sampler s, in float<2> x, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy) : tex1d_t_dd_array; +$classT [[ro]] SampleGrad(in sampler s, in float<2> x, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy, in int<1> o) : tex1d_t_dd_array_o; +$classT [[ro]] SampleLevel(in sampler s, in float<2> x, in float lod) : tex1d_t_lod_array; +$classT [[ro]] SampleLevel(in sampler s, in float<2> x, in float lod, in int<1> o) : tex1d_t_lod_array_o; +$classT [[ro]] Sample(in sampler s, in float<2> x, in int<1> o, in float clamp) : tex1d_t_array_o_cl; +$classT [[]] Sample(in sampler s, in float<2> x, in int<1> o, in float clamp, out uint_only status) : tex1d_t_array_o_cl_s; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<2> x, in float compareValue, in int<1> o, in float clamp) : tex1d_t_comp_array_o_cl; +float_like [[]] SampleCmp(in sampler_cmp s, in float<2> x, in float compareValue, in int<1> o, in float clamp, out uint_only status) : tex1d_t_comp_array_o_cl_s; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<2> x, in float compareValue, in float bias, in int<1> o, in float clamp) : tex1d_t_comp_bias_array_o_cl; +float_like [[]] SampleCmpBias(in sampler_cmp s, in float<2> x, in float compareValue, in float bias, in int<1> o, in float clamp, out uint_only status) : tex1d_t_comp_bias_array_o_cl_s; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<2> x, in float compareValue, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy, in int<1> o, in float clamp) : tex1d_t_comp_dd_array_o_cl; +float_like [[]] SampleCmpGrad(in sampler_cmp s, in float<2> x, in float compareValue, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy, in int<1> o, in float clamp, out uint_only status) : tex1d_t_comp_dd_array_o_cl_s; +float_like [[]] SampleCmpLevel(in sampler_cmp s, in float<2> x, in float compareValue, in float lod, in int<1> o, out uint_only status); +float_like [[]] SampleCmpLevelZero(in sampler_cmp s, in float<2> x, in float compareValue, in int<1> o, out uint_only status) : tex1d_t_comp_array_o_s; +$classT [[]] SampleLevel(in sampler s, in float<2> x, in float lod, in int<1> o, out uint_only status) : tex1d_t_lod_array_o_s; +$classT [[ro]] SampleBias(in sampler s, in float<2> x, in float bias, in int<1> o, in float clamp) : tex1d_t_bias_array_o_cl; +$classT [[]] SampleBias(in sampler s, in float<2> x, in float bias, in int<1> o, in float clamp, out uint_only status) : tex1d_t_bias_array_o_cl_s; +$classT [[ro]] SampleGrad(in sampler s, in float<2> x, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy, in int<1> o, in float clamp) : tex1d_t_dd_array_o_cl; +$classT [[]] SampleGrad(in sampler s, in float<2> x, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy, in int<1> o, in float clamp, out uint_only status) : tex1d_t_dd_array_o_cl_s; +} namespace + +namespace Texture2DMethods { + +float [[ro]] CalculateLevelOfDetail(in any_sampler s, in float<2> x) : tex2d_t_calc_lod; +float [[ro]] CalculateLevelOfDetailUnclamped(in any_sampler s, in float<2> x) : tex2d_t_calc_lod_unclamped; +$match<0, -1> void<4> [[ro]] Gather(in sampler s, in float<2> x) : tex2d_t_gather; +$match<0, -1> void<4> [[ro]] Gather(in sampler s, in float<2> x, in int<2> o) : tex2d_t_gather_o; +$match<0, -1> void<4> [[ro]] GatherAlpha(in sampler s, in float<2> x) : tex2d_t_gather_alpha; +$match<0, -1> void<4> [[ro]] GatherAlpha(in sampler s, in float<2> x, in int<2> o) : tex2d_t_gather_alpha_o; +$match<0, -1> void<4> [[ro]] GatherAlpha(in sampler s, in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_alpha_o4; +$match<0, -1> void<4> [[ro]] GatherBlue(in sampler s, in float<2> x) : tex2d_t_gather_blue; +$match<0, -1> void<4> [[ro]] GatherBlue(in sampler s, in float<2> x, in int<2> o) : tex2d_t_gather_blue_o; +$match<0, -1> void<4> [[ro]] GatherBlue(in sampler s, in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_blue_o4; +$match<0, -1> void<4> [[ro]] GatherCmp(in sampler_cmp s, in float<2> x, in float compareValue) : tex2d_t_gather_comp; +$match<0, -1> void<4> [[ro]] GatherCmp(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_o; +$match<0, -1> void<4> [[ro]] GatherCmpAlpha(in sampler_cmp s, in float<2> x, in float compareValue) : tex2d_t_gather_comp_alpha; +$match<0, -1> void<4> [[ro]] GatherCmpAlpha(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_alpha_o; +$match<0, -1> void<4> [[ro]] GatherCmpAlpha(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_alpha_o4; +$match<0, -1> void<4> [[ro]] GatherCmpBlue(in sampler_cmp s, in float<2> x, in float compareValue) : tex2d_t_gather_comp_blue; +$match<0, -1> void<4> [[ro]] GatherCmpBlue(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_blue_o; +$match<0, -1> void<4> [[ro]] GatherCmpBlue(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_blue_o4; +$match<0, -1> void<4> [[ro]] GatherCmpGreen(in sampler_cmp s, in float<2> x, in float compareValue) : tex2d_t_gather_comp_green; +$match<0, -1> void<4> [[ro]] GatherCmpGreen(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_green_o; +$match<0, -1> void<4> [[ro]] GatherCmpGreen(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_green_o4; +$match<0, -1> void<4> [[ro]] GatherCmpRed(in sampler_cmp s, in float<2> x, in float compareValue) : tex2d_t_gather_comp_red; +$match<0, -1> void<4> [[ro]] GatherCmpRed(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_red_o; +$match<0, -1> void<4> [[ro]] GatherCmpRed(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_red_o4; +$match<0, -1> void<4> [[ro]] GatherGreen(in sampler s, in float<2> x) : tex2d_t_gather_green; +$match<0, -1> void<4> [[ro]] GatherGreen(in sampler s, in float<2> x, in int<2> o) : tex2d_t_gather_green_o; +$match<0, -1> void<4> [[ro]] GatherGreen(in sampler s, in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_green_o4; +$match<0, -1> void<4> [[ro]] GatherRed(in sampler s, in float<2> x) : tex2d_t_gather_red; +$match<0, -1> void<4> [[ro]] GatherRed(in sampler s, in float<2> x, in int<2> o) : tex2d_t_gather_red_o; +$match<0, -1> void<4> [[ro]] GatherRed(in sampler s, in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_red_o4; +void [[]] GetDimensions(in uint x, out uint_only width, out $type2 height, out $type2 levels) : resinfo_uint; +void [[]] GetDimensions(in uint x, out float_like width, out $type2 height, out $type2 levels) : resinfo; +void [[]] GetDimensions(out uint_only width, out $type1 height) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height) : resinfo_o; +$classT [[ro]] Load(in int<3> x) : tex2d_t_load; +$classT [[ro]] Load(in int<3> x, in int<2> o) : tex2d_t_load_o; +$classT [[]] Load(in int<3> x, in int<2> o, out uint_only status) : tex2d_t_load_o_s; +$classT [[ro]] Sample(in sampler s, in float<2> x) : tex2d_t; +$classT [[ro]] Sample(in sampler s, in float<2> x, in int<2> o) : tex2d_t_o; +$classT [[ro]] SampleBias(in sampler s, in float<2> x, in float bias) : tex2d_t_bias; +$classT [[ro]] SampleBias(in sampler s, in float<2> x, in float bias, in int<2> o) : tex2d_t_bias_o; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<2> x, in float compareValue) : tex2d_t_comp; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o) : tex2d_t_comp_o; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<2> x, in float compareValue, in float bias) : tex2d_t_comp_bias; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<2> x, in float compareValue, in float bias, in int<2> o) : tex2d_t_comp_bias_o; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<2> x, in float compareValue, in $type2 ddx, in $type2 ddy) : tex2d_t_comp_dd; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<2> x, in float compareValue, in $type2 ddx, in $type2 ddy, in int<2> o) : tex2d_t_comp_dd_o; +float_like [[ro]] SampleCmpLevel(in sampler_cmp s, in float<2> x, in float compareValue, in float lod); +float_like [[ro]] SampleCmpLevel(in sampler_cmp s, in float<2> x, in float compareValue, in float lod, in int<2> o); +float_like [[ro]] SampleCmpLevelZero(in sampler_cmp s, in float<2> x, in float compareValue) : tex2d_t_comp_lz; +float_like [[ro]] SampleCmpLevelZero(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o) : tex2d_t_comp_lz_o; +$classT [[ro]] SampleGrad(in sampler s, in float<2> x, in $type2 ddx, in $type2 ddy) : tex2d_t_dd; +$classT [[ro]] SampleGrad(in sampler s, in float<2> x, in $type2 ddx, in $type2 ddy, in int<2> o) : tex2d_t_dd_o; +$classT [[ro]] SampleLevel(in sampler s, in float<2> x, in float lod) : tex2d_t_lod; +$classT [[ro]] SampleLevel(in sampler s, in float<2> x, in float lod, in int<2> o) : tex2d_t_lod_o; +$classT [[ro]] Sample(in sampler s, in float<2> x, in int<2> o, in float clamp) : tex2d_t_o_cl; +$classT [[]] Sample(in sampler s, in float<2> x, in int<2> o, in float clamp, out uint_only status) : tex2d_t_o_cl_s; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o, in float clamp) : tex2d_t_comp_o_cl; +float_like [[]] SampleCmp(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o, in float clamp, out uint_only status) : tex2d_t_comp_o_cl_s; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<2> x, in float compareValue, in float bias, in int<2> o, in float clamp) : tex2d_t_comp_bias_o_cl; +float_like [[]] SampleCmpBias(in sampler_cmp s, in float<2> x, in float compareValue, in float bias, in int<2> o, in float clamp, out uint_only status) : tex2d_t_comp_bias_o_cl_s; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<2> x, in float compareValue, in $type2 ddx, in $type2 ddy, in int<2> o, in float clamp) : tex2d_t_comp_dd_o_cl; +float_like [[]] SampleCmpGrad(in sampler_cmp s, in float<2> x, in float compareValue, in $type2 ddx, in $type2 ddy, in int<2> o, in float clamp, out uint_only status) : tex2d_t_comp_dd_o_cl_s; +float_like [[]] SampleCmpLevel(in sampler_cmp s, in float<2> x, in float compareValue, in float lod, in int<2> o, out uint_only status); +float_like [[]] SampleCmpLevelZero(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_comp_o_s; +$classT [[]] SampleLevel(in sampler s, in float<2> x, in float lod, in int<2> o, out uint_only status) : tex2d_t_lod_o_s; +$classT [[ro]] SampleBias(in sampler s, in float<2> x, in float bias, in int<2> o, in float clamp) : tex2d_t_bias_o_cl; +$classT [[]] SampleBias(in sampler s, in float<2> x, in float bias, in int<2> o, in float clamp, out uint_only status) : tex2d_t_bias_o_cl_s; +$classT [[ro]] SampleGrad(in sampler s, in float<2> x, in $type2 ddx, in $type2 ddy, in int<2> o, in float clamp) : tex2d_t_dd_o_cl; +$classT [[]] SampleGrad(in sampler s, in float<2> x, in $type2 ddx, in $type2 ddy, in int<2> o, in float clamp, out uint_only status) : tex2d_t_dd_o_cl_s; +$match<0, -1> void<4> [[]] Gather(in sampler s, in float<2> x, in int<2> o, out uint_only status) : tex2d_t_gather_o_s; +$match<0, -1> void<4> [[]] GatherRed(in sampler s, in float<2> x, in int<2> o, out uint_only status) : tex2d_t_gather_red_o_s; +$match<0, -1> void<4> [[]] GatherRed(in sampler s, in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_red_o4_s; +$match<0, -1> void<4> [[]] GatherGreen(in sampler s, in float<2> x, in int<2> o, out uint_only status) : tex2d_t_gather_green_o_s; +$match<0, -1> void<4> [[]] GatherGreen(in sampler s, in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_green_o4_s; +$match<0, -1> void<4> [[]] GatherBlue(in sampler s, in float<2> x, in int<2> o, out uint_only status) : tex2d_t_gather_blue_o_s; +$match<0, -1> void<4> [[]] GatherBlue(in sampler s, in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_blue_o4_s; +$match<0, -1> void<4> [[]] GatherAlpha(in sampler s, in float<2> x, in int<2> o, out uint_only status) : tex2d_t_gather_alpha_o_s; +$match<0, -1> void<4> [[]] GatherAlpha(in sampler s, in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_alpha_o4_s; + +$match<0, -1> void<4> [[]] GatherCmp(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_o_s; +$match<0, -1> void<4> [[]] GatherCmpRed(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_red_o_s; +$match<0, -1> void<4> [[]] GatherCmpGreen(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_green_o_s; +$match<0, -1> void<4> [[]] GatherCmpBlue(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_blue_o_s; +$match<0, -1> void<4> [[]] GatherCmpAlpha(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_alpha_o_s; + +$match<0, -1> void<4> [[]] GatherCmpRed(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_red_o4_s; +$match<0, -1> void<4> [[]] GatherCmpGreen(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_green_o4_s; +$match<0, -1> void<4> [[]] GatherCmpBlue(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_blue_o4_s; +$match<0, -1> void<4> [[]] GatherCmpAlpha(in sampler_cmp s, in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_alpha_o4_s; +$match<0, -1> void<4> [[ro]] GatherRaw(in sampler s, in float<2> x); +$match<0, -1> void<4> [[ro]] GatherRaw(in sampler s, in float<2> x, in int<2> o); +$match<0, -1> void<4> [[]] GatherRaw(in sampler s, in float<2> x, in int<2> o, out uint_only status); +} namespace + +namespace Texture2DMSMethods { + +void [[]] GetDimensions(out uint_only width, out $type1 height, out $type2 samples) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height, out $type2 samples) : resinfo_o; +float_like<2> [[ro]] GetSamplePosition(in int s) : samplepos; +$classT [[]] Load(in int<2> x, in int s) : texture2d_ms; +$classT [[]] Load(in int<2> x, in int s, in int<2> o) : texture2d_ms_o; +$classT [[]] Load(in int<2> x, in int s, in int<2> o, out uint_only status) : texture2d_ms_o_s; + +} namespace + +namespace Texture2DArrayMethods { + +float [[ro]] CalculateLevelOfDetail(in any_sampler s, in float<2> x) : tex2d_t_calc_lod_array; +float [[ro]] CalculateLevelOfDetailUnclamped(in any_sampler s, in float<2> x) : tex2d_t_calc_lod_unclamped_array; +$match<0, -1> void<4> [[ro]] Gather(in sampler s, in float<3> x) : tex2d_t_gather_array; +$match<0, -1> void<4> [[ro]] Gather(in sampler s, in float<3> x, in int<2> o) : tex2d_t_gather_array_o; +$match<0, -1> void<4> [[ro]] GatherAlpha(in sampler s, in float<3> x) : tex2d_t_gather_alpha_array; +$match<0, -1> void<4> [[ro]] GatherAlpha(in sampler s, in float<3> x, in int<2> o) : tex2d_t_gather_alpha_array_o; +$match<0, -1> void<4> [[ro]] GatherAlpha(in sampler s, in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_alpha_array_o4; +$match<0, -1> void<4> [[ro]] GatherBlue(in sampler s, in float<3> x) : tex2d_t_gather_blue_array; +$match<0, -1> void<4> [[ro]] GatherBlue(in sampler s, in float<3> x, in int<2> o) : tex2d_t_gather_blue_array_o; +$match<0, -1> void<4> [[ro]] GatherBlue(in sampler s, in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_blue_array_o4; +$match<0, -1> void<4> [[ro]] GatherCmp(in sampler_cmp s, in float<3> x, in float compareValue) : tex2d_t_gather_comp_array; +$match<0, -1> void<4> [[ro]] GatherCmp(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_array_o; +$match<0, -1> void<4> [[ro]] GatherCmpAlpha(in sampler_cmp s, in float<3> x, in float compareValue) : tex2d_t_gather_comp_alpha_array; +$match<0, -1> void<4> [[ro]] GatherCmpAlpha(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_alpha_array_o; +$match<0, -1> void<4> [[ro]] GatherCmpAlpha(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_alpha_array_o4; +$match<0, -1> void<4> [[ro]] GatherCmpBlue(in sampler_cmp s, in float<3> x, in float compareValue) : tex2d_t_gather_comp_blue_array; +$match<0, -1> void<4> [[ro]] GatherCmpBlue(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_blue_array_o; +$match<0, -1> void<4> [[ro]] GatherCmpBlue(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_blue_array_o4; +$match<0, -1> void<4> [[ro]] GatherCmpGreen(in sampler_cmp s, in float<3> x, in float compareValue) : tex2d_t_gather_comp_green_array; +$match<0, -1> void<4> [[ro]] GatherCmpGreen(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_green_array_o; +$match<0, -1> void<4> [[ro]] GatherCmpGreen(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_green_array_o4; +$match<0, -1> void<4> [[ro]] GatherCmpRed(in sampler_cmp s, in float<3> x, in float compareValue) : tex2d_t_gather_comp_red_array; +$match<0, -1> void<4> [[ro]] GatherCmpRed(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_red_array_o; +$match<0, -1> void<4> [[ro]] GatherCmpRed(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_red_array_o4; +$match<0, -1> void<4> [[ro]] GatherGreen(in sampler s, in float<3> x) : tex2d_t_gather_green_array; +$match<0, -1> void<4> [[ro]] GatherGreen(in sampler s, in float<3> x, in int<2> o) : tex2d_t_gather_green_array_o; +$match<0, -1> void<4> [[ro]] GatherGreen(in sampler s, in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_green_array_o4; +$match<0, -1> void<4> [[ro]] GatherRed(in sampler s, in float<3> x) : tex2d_t_gather_red_array; +$match<0, -1> void<4> [[ro]] GatherRed(in sampler s, in float<3> x, in int<2> o) : tex2d_t_gather_red_array_o; +$match<0, -1> void<4> [[ro]] GatherRed(in sampler s, in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_red_array_o4; +void [[]] GetDimensions(in uint x, out uint_only width, out $type2 height, out $type2 elements, out $type2 levels) : resinfo_uint; +void [[]] GetDimensions(in uint x, out float_like width, out $type2 height, out $type2 elements, out $type2 levels) : resinfo; +void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 elements) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 elements) : resinfo_o; +$classT [[ro]] Load(in int<4> x) : tex2d_t_load_array; +$classT [[ro]] Load(in int<4> x, in int<2> o) : tex2d_t_load_array_o; +$classT [[]] Load(in int<4> x, in int<2> o, out uint_only status) : tex2d_t_load_array_o_s; +$classT [[ro]] Sample(in sampler s, in float<3> x) : tex2d_t_array; +$classT [[ro]] Sample(in sampler s, in float<3> x, in int<2> o) : tex2d_t_array_o; +$classT [[ro]] SampleBias(in sampler s, in float<3> x, in float bias) : tex2d_t_bias_array; +$classT [[ro]] SampleBias(in sampler s, in float<3> x, in float bias, in int<2> o) : tex2d_t_bias_array_o; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<3> x, in float compareValue) : tex2d_t_comp_array; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o) : tex2d_t_comp_array_o; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<3> x, in float compareValue, in float bias) : tex2d_t_comp_bias_array; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<3> x, in float compareValue, in float bias, in int<2> o) : tex2d_t_comp_bias_array_o; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<3> x, in float compareValue, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy) : tex2d_t_comp_dd_array; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<3> x, in float compareValue, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy, in int<2> o) : tex2d_t_comp_dd_array_o; +float_like [[ro]] SampleCmpLevel(in sampler_cmp s, in float<3> x, in float compareValue, in float lod); +float_like [[ro]] SampleCmpLevel(in sampler_cmp s, in float<3> x, in float compareValue, in float lod, in int<2> o); +float_like [[ro]] SampleCmpLevelZero(in sampler_cmp s, in float<3> x, in float compareValue) : tex2d_t_comp_lz_array; +float_like [[ro]] SampleCmpLevelZero(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o) : tex2d_t_comp_lz_array_o; +$classT [[ro]] SampleGrad(in sampler s, in float<3> x, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy) : tex2d_t_dd_array; +$classT [[ro]] SampleGrad(in sampler s, in float<3> x, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy, in int<2> o) : tex2d_t_dd_array_o; +$classT [[ro]] SampleLevel(in sampler s, in float<3> x, in float lod) : tex2d_t_lod_array; +$classT [[ro]] SampleLevel(in sampler s, in float<3> x, in float lod, in int<2> o) : tex2d_t_lod_array_o; +$classT [[ro]] Sample(in sampler s, in float<3> x, in int<2> o, in float clamp) : tex2d_t_array_o_cl; +$classT [[]] Sample(in sampler s, in float<3> x, in int<2> o, in float clamp, out uint_only status) : tex2d_t_array_o_cl_s; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o, in float clamp) : tex2d_t_comp_array_o_cl; +float_like [[]] SampleCmp(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o, in float clamp, out uint_only status) : tex2d_t_comp_array_o_cl_s; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<3> x, in float compareValue, in float bias, in int<2> o, in float clamp) : tex2d_t_comp_bias_array_o_cl; +float_like [[]] SampleCmpBias(in sampler_cmp s, in float<3> x, in float compareValue, in float bias, in int<2> o, in float clamp, out uint_only status) : tex2d_t_comp_bias_array_o_cl_s; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<3> x, in float compareValue, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy, in int<2> o, in float clamp) : tex2d_t_comp_dd_array_o_cl; +float_like [[]] SampleCmpGrad(in sampler_cmp s, in float<3> x, in float compareValue, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy, in int<2> o, in float clamp, out uint_only status) : tex2d_t_comp_dd_array_o_cl_s; +float_like [[]] SampleCmpLevel(in sampler_cmp s, in float<3> x, in float compareValue, in float lod, in int<2> o, out uint_only status); +float_like [[]] SampleCmpLevelZero(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_comp_array_o_s; +$classT [[]] SampleLevel(in sampler s, in float<3> x, in float lod, in int<2> o, out uint_only status) : tex2d_t_lod_array_o_s; +$classT [[ro]] SampleBias(in sampler s, in float<3> x, in float bias, in int<2> o, in float clamp) : tex2d_t_bias_array_o_cl; +$classT [[]] SampleBias(in sampler s, in float<3> x, in float bias, in int<2> o, in float clamp, out uint_only status) : tex2d_t_bias_array_o_cl_s; +$classT [[ro]] SampleGrad(in sampler s, in float<3> x, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy, in int<2> o, in float clamp) : tex2d_t_dd_array_o_cl; +$classT [[]] SampleGrad(in sampler s, in float<3> x, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy, in int<2> o, in float clamp, out uint_only status) : tex2d_t_dd_array_o_cl_s; +$match<0, -1> void<4> [[]] Gather(in sampler s, in float<3> x, in int<2> o, out uint_only status) : tex2d_t_gather_array_o_s; +$match<0, -1> void<4> [[]] GatherRed(in sampler s, in float<3> x, in int<2> o, out uint_only status) : tex2d_t_gather_red_array_o_s; +$match<0, -1> void<4> [[]] GatherRed(in sampler s, in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_red_array_o4_s; +$match<0, -1> void<4> [[]] GatherGreen(in sampler s, in float<3> x, in int<2> o, out uint_only status) : tex2d_t_gather_green_array_o_s; +$match<0, -1> void<4> [[]] GatherGreen(in sampler s, in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_green_array_o4_s; +$match<0, -1> void<4> [[]] GatherBlue(in sampler s, in float<3> x, in int<2> o, out uint_only status) : tex2d_t_gather_blue_array_o_s; +$match<0, -1> void<4> [[]] GatherBlue(in sampler s, in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_blue_array_o4_s; +$match<0, -1> void<4> [[]] GatherAlpha(in sampler s, in float<3> x, in int<2> o, out uint_only status) : tex2d_t_gather_alpha_array_o_s; +$match<0, -1> void<4> [[]] GatherAlpha(in sampler s, in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_alpha_array_o4_s; +$match<0, -1> void<4> [[]] GatherCmp(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_array_o_s; +$match<0, -1> void<4> [[]] GatherCmpRed(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_red_array_o_s; +$match<0, -1> void<4> [[]] GatherCmpGreen(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_green_array_o_s; +$match<0, -1> void<4> [[]] GatherCmpBlue(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_blue_array_o_s; +$match<0, -1> void<4> [[]] GatherCmpAlpha(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_alpha_array_o_s; +$match<0, -1> void<4> [[]] GatherCmpRed(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_red_array_o4_s; +$match<0, -1> void<4> [[]] GatherCmpGreen(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_green_array_o4_s; +$match<0, -1> void<4> [[]] GatherCmpBlue(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_blue_array_o4_s; +$match<0, -1> void<4> [[]] GatherCmpAlpha(in sampler_cmp s, in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_alpha_array_o4_s; +$match<0, -1> void<4> [[ro]] GatherRaw(in sampler s, in float<3> x); +$match<0, -1> void<4> [[ro]] GatherRaw(in sampler s, in float<3> x, in int<2> o); +$match<0, -1> void<4> [[]] GatherRaw(in sampler s, in float<3> x, in int<2> o, out uint_only status); +} namespace + +namespace Texture2DArrayMSMethods { + +void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 elements, out $type1 samples) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 elements, out $type1 samples) : resinfo_o; +float_like<2> [[ro]] GetSamplePosition(in int s) : samplepos; +$classT [[ro]] Load(in int<3> x, in int s) : texture2darray_ms; +$classT [[ro]] Load(in int<3> x, in int s, in int<2> o) : texture2darray_ms_o; +$classT [[]] Load(in int<3> x, in int s, in int<2> o, out uint_only status) : texture2darray_ms_o_s; + +} namespace + +namespace Texture3DMethods { + +float [[ro]] CalculateLevelOfDetail(in sampler s, in float<3> x) : tex3d_t_calc_lod; +float [[ro]] CalculateLevelOfDetailUnclamped(in sampler s, in float<3> x) : tex3d_t_calc_lod_unclamped; +void [[]] GetDimensions(in uint x, out uint_only width, out $type2 height, out $type2 depth, out $type2 levels) : resinfo_uint; +void [[]] GetDimensions(in uint x, out float_like width, out $type2 height, out $type2 depth, out $type2 levels) : resinfo; +void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 depth) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 depth) : resinfo_o; +$classT [[ro]] Load(in int<4> x) : tex3d_t_load; +$classT [[ro]] Load(in int<4> x, in int<3> o) : tex3d_t_load_o; +$classT [[]] Load(in int<4> x, in int<3> o, out uint_only status) : tex3d_t_load_o_s; +$classT [[ro]] Sample(in sampler s, in float<3> x) : tex3d_t; +$classT [[ro]] Sample(in sampler s, in float<3> x, in int<3> o) : tex3d_t_o; +$classT [[ro]] SampleBias(in sampler s, in float<3> x, in float bias) : tex3d_t_bias; +$classT [[ro]] SampleBias(in sampler s, in float<3> x, in float bias, in int<3> o) : tex3d_t_bias_o; +$classT [[ro]] SampleGrad(in sampler s, in float<3> x, in $type2 ddx, in $type2 ddy) : tex3d_t_dd; +$classT [[ro]] SampleGrad(in sampler s, in float<3> x, in $type2 ddx, in $type2 ddy, in int<3> o) : tex3d_t_dd_o; +$classT [[ro]] SampleLevel(in sampler s, in float<3> x, in float lod) : tex3d_t_lod; +$classT [[ro]] SampleLevel(in sampler s, in float<3> x, in float lod, in int<3> o) : tex3d_t_lod_o; +$classT [[ro]] Sample(in sampler s, in float<3> x, in int<3> o, in float clamp) : tex3d_t_o_cl; +$classT [[]] Sample(in sampler s, in float<3> x, in int<3> o, in float clamp, out uint_only status) : tex3d_t_o_cl_s; +$classT [[]] SampleLevel(in sampler s, in float<3> x, in float lod, in int<3> o, out uint_only status) : tex3d_t_lod_o_s; +$classT [[ro]] SampleBias(in sampler s, in float<3> x, in float bias, in int<3> o, in float clamp) : tex3d_t_bias_o_cl; +$classT [[]] SampleBias(in sampler s, in float<3> x, in float bias, in int<3> o, in float clamp, out uint_only status) : tex3d_t_bias_o_cl_s; +$classT [[ro]] SampleGrad(in sampler s, in float<3> x, in $type2 ddx, in $type2 ddy, in int<3> o, in float clamp) : tex3d_t_dd_o_cl; +$classT [[]] SampleGrad(in sampler s, in float<3> x, in $type2 ddx, in $type2 ddy, in int<3> o, in float clamp, out uint_only status) : tex3d_t_dd_o_cl_s; +} namespace + +namespace TextureCUBEMethods { + +float [[ro]] CalculateLevelOfDetail(in any_sampler s, in float<3> x) : texcube_t_calc_lod; +float [[ro]] CalculateLevelOfDetailUnclamped(in any_sampler s, in float<3> x) : texcube_t_calc_lod_unclamped; +$match<0, -1> void<4> [[ro]] Gather(in sampler s, in float<3> x) : texcube_t_gather; +$match<0, -1> void<4> [[ro]] GatherAlpha(in sampler s, in float<3> x) : texcube_t_gather_alpha; +$match<0, -1> void<4> [[ro]] GatherBlue(in sampler s, in float<3> x) : texcube_t_gather_blue; +$match<0, -1> void<4> [[ro]] GatherCmp(in sampler_cmp s, in float<3> x, in float compareValue) : texcube_t_gather_comp; +$match<0, -1> void<4> [[ro]] GatherCmpAlpha(in sampler_cmp s, in float<3> x, in float compareValue) : texcube_t_gather_comp_alpha; +$match<0, -1> void<4> [[ro]] GatherCmpBlue(in sampler_cmp s, in float<3> x, in float compareValue) : texcube_t_gather_comp_blue; +$match<0, -1> void<4> [[ro]] GatherCmpGreen(in sampler_cmp s, in float<3> x, in float compareValue) : texcube_t_gather_comp_green; +$match<0, -1> void<4> [[ro]] GatherCmpRed(in sampler_cmp s, in float<3> x, in float compareValue) : texcube_t_gather_comp_red; +$match<0, -1> void<4> [[ro]] GatherGreen(in sampler s, in float<3> x) : texcube_t_gather_green; +$match<0, -1> void<4> [[ro]] GatherRed(in sampler s, in float<3> x) : texcube_t_gather_red; +void [[]] GetDimensions(in uint x, out uint_only width, out $type2 height, out $type2 levels) : resinfo_uint; +void [[]] GetDimensions(in uint x, out float_like width, out $type2 height, out $type2 levels) : resinfo; +void [[]] GetDimensions(out uint_only width, out $type1 height) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height) : resinfo_o; +$classT [[ro]] Sample(in sampler s, in float<3> x) : texcube_t; +$classT [[ro]] SampleBias(in sampler s, in float<3> x, in float bias) : texcube_t_bias; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<3> x, in float c) : texcube_t_comp; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<3> x, in float compareValue, in float bias) : texcube_t_comp_bias; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<3> x, in float compareValue, in $type2 ddx, in $type2 ddy) : texcube_t_comp_dd; +float_like [[ro]] SampleCmpLevel(in sampler_cmp s, in float<3> x, in float c, in float lod); +float_like [[ro]] SampleCmpLevelZero(in sampler_cmp s, in float<3> x, in float c) : texcube_t_comp_lz; +$classT [[ro]] SampleGrad(in sampler s, in float<3> x, in $type2 ddx, in $type2 ddy) : texcube_t_dd; +$classT [[ro]] SampleLevel(in sampler s, in float<3> x, in float lod) : texcube_t_lod; +$classT [[ro]] Sample(in sampler s, in float<3> x, in float clamp) : texcube_t_cl; +$classT [[]] Sample(in sampler s, in float<3> x, in float clamp, out uint_only status) : texcube_t_cl_s; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<3> x, in float compareValue, in float clamp) : texcube_t_comp_cl; +float_like [[]] SampleCmp(in sampler_cmp s, in float<3> x, in float compareValue, in float clamp, out uint_only status) : texcube_t_comp_cl_s; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<3> x, in float compareValue, in float bias, in float clamp) : texcube_t_comp_bias_cl; +float_like [[]] SampleCmpBias(in sampler_cmp s, in float<3> x, in float compareValue, in float bias, in float clamp, out uint_only status) : texcube_t_comp_bias_cl_s; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<3> x, in float compareValue, in $type2 ddx, in $type2 ddy, in float clamp) : texcube_t_comp_dd_o_cl; +float_like [[]] SampleCmpGrad(in sampler_cmp s, in float<3> x, in float compareValue, in $type2 ddx, in $type2 ddy, in float clamp, out uint_only status) : texcube_t_comp_dd_o_cl_s; +float_like [[]] SampleCmpLevel(in sampler_cmp s, in float<3> x, in float compareValue, in float lod, out uint_only status); +float_like [[]] SampleCmpLevelZero(in sampler_cmp s, in float<3> x, in float compareValue, out uint_only status) : texcube_t_comp_s; +$classT [[]] SampleLevel(in sampler s, in float<3> x, in float lod, out uint_only status) : texcube_t_lod_s; +$classT [[ro]] SampleBias(in sampler s, in float<3> x, in float bias, in float clamp) : texcube_t_bias_cl; +$classT [[]] SampleBias(in sampler s, in float<3> x, in float bias, in float clamp, out uint_only status) : texcube_t_bias_cl_s; +$classT [[ro]] SampleGrad(in sampler s, in float<3> x, in $type2 ddx, in $type2 ddy, in float clamp) : texcube_t_dd_cl; +$classT [[]] SampleGrad(in sampler s, in float<3> x, in $type2 ddx, in $type2 ddy, in float clamp, out uint_only status) : texcube_t_dd_cl_s; +$match<0, -1> void<4> [[]] Gather(in sampler s, in float<3> x, out uint_only status) : texcube_t_gather_s; +$match<0, -1> void<4> [[]] GatherRed(in sampler s, in float<3> x, out uint_only status) : texcube_t_gather_red_s; +$match<0, -1> void<4> [[]] GatherGreen(in sampler s, in float<3> x, out uint_only status) : texcube_t_gather_green_s; +$match<0, -1> void<4> [[]] GatherBlue(in sampler s, in float<3> x, out uint_only status) : texcube_t_gather_blue_s; +$match<0, -1> void<4> [[]] GatherAlpha(in sampler s, in float<3> x, out uint_only status) : texcube_t_gather_alpha_s; +$match<0, -1> void<4> [[]] GatherCmp(in sampler_cmp s, in float<3> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_s; +$match<0, -1> void<4> [[]] GatherCmpRed(in sampler_cmp s, in float<3> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_red_s; +$match<0, -1> void<4> [[]] GatherCmpGreen(in sampler_cmp s, in float<3> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_green_s; +$match<0, -1> void<4> [[]] GatherCmpBlue(in sampler_cmp s, in float<3> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_blue_s; +$match<0, -1> void<4> [[]] GatherCmpAlpha(in sampler_cmp s, in float<3> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_alpha_s; +} namespace + +namespace TextureCUBEArrayMethods { + +float [[ro]] CalculateLevelOfDetail(in any_sampler s, in float<3> x) : texcube_t_calc_lod_array; +float [[ro]] CalculateLevelOfDetailUnclamped(in any_sampler s, in float<3> x) : texcube_t_calc_lod_unclamped_array; +$match<0, -1> void<4> [[ro]] Gather(in sampler s, in float<4> x) : texcube_t_gather_array; +$match<0, -1> void<4> [[ro]] GatherAlpha(in sampler s, in float<4> x) : texcube_t_gather_alpha_array; +$match<0, -1> void<4> [[ro]] GatherBlue(in sampler s, in float<4> x) : texcube_t_gather_blue_array; +$match<0, -1> void<4> [[ro]] GatherCmp(in sampler_cmp s, in float<4> x, in float compareValue) : texcube_t_gather_comp_array; +$match<0, -1> void<4> [[ro]] GatherCmpAlpha(in sampler_cmp s, in float<4> x, in float compareValue) : texcube_t_gather_comp_alpha_array; +$match<0, -1> void<4> [[ro]] GatherCmpBlue(in sampler_cmp s, in float<4> x, in float compareValue) : texcube_t_gather_comp_blue_array; +$match<0, -1> void<4> [[ro]] GatherCmpGreen(in sampler_cmp s, in float<4> x, in float compareValue) : texcube_t_gather_comp_green_array; +$match<0, -1> void<4> [[ro]] GatherCmpRed(in sampler_cmp s, in float<4> x, in float compareValue) : texcube_t_gather_comp_red_array; +$match<0, -1> void<4> [[ro]] GatherGreen(in sampler s, in float<4> x) : texcube_t_gather_green_array; +$match<0, -1> void<4> [[ro]] GatherRed(in sampler s, in float<4> x) : texcube_t_gather_red_array; +void [[]] GetDimensions(in uint x, out uint_only width, out $type2 height, out $type2 elements, out $type2 levels) : resinfo_uint; +void [[]] GetDimensions(in uint x, out float_like width, out $type2 height, out $type2 elements, out $type2 levels) : resinfo; +void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 elements) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 elements) : resinfo_o; +$classT [[ro]] Sample(in sampler s, in float<4> x) : texcube_t_array; +$classT [[ro]] SampleBias(in sampler s, in float<4> x, in float bias) : texcube_t_bias_array; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<4> x, in float c) : texcube_t_comp_array; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<4> x, in float compareValue, in float bias) : texcube_t_comp_bias_array; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<4> x, in float compareValue, in $match<2, 2> float<3> ddx, in $match<2, 2> float<3> ddy) : texcube_t_comp_dd_array; +float_like [[ro]] SampleCmpLevel(in sampler_cmp s, in float<4> x, in float c, in float lod); +float_like [[ro]] SampleCmpLevelZero(in sampler_cmp s, in float<4> x, in float c) : texcube_t_comp_lz_array; +$classT [[ro]] SampleGrad(in sampler s, in float<4> x, in $match<2, 2> float<3> ddx, in $match<2, 2> float<3> ddy) : texcube_t_dd_array; +$classT [[ro]] SampleLevel(in sampler s, in float<4> x, in float lod) : texcube_t_lod_array; +$classT [[ro]] Sample(in sampler s, in float<4> x, in float clamp) : texcube_t_array_cl; +$classT [[]] Sample(in sampler s, in float<4> x, in float clamp, out uint_only status) : texcube_t_array_cl_s; +float_like [[ro]] SampleCmp(in sampler_cmp s, in float<4> x, in float compareValue, in float clamp) : texcube_t_comp_array_cl; +float_like [[]] SampleCmp(in sampler_cmp s, in float<4> x, in float compareValue, in float clamp, out uint_only status) : texcube_t_comp_array_cl_s; +float_like [[ro]] SampleCmpBias(in sampler_cmp s, in float<4> x, in float compareValue, in float bias, in float clamp) : texcube_t_comp_bias_array_cl; +float_like [[]] SampleCmpBias(in sampler_cmp s, in float<4> x, in float compareValue, in float bias, in float clamp, out uint_only status) : texcube_t_comp_bias_array_cl_s; +float_like [[ro]] SampleCmpGrad(in sampler_cmp s, in float<4> x, in float compareValue, in $match<2, 2> float<3> ddx, in $match<2, 2> float<3> ddy, in float clamp) : texcube_t_comp_dd_array_cl; +float_like [[]] SampleCmpGrad(in sampler_cmp s, in float<4> x, in float compareValue, in $match<2, 2> float<3> ddx, in $match<2, 2> float<3> ddy, in float clamp, out uint_only status) : texcube_t_comp_dd_array_cl_s; +float_like [[]] SampleCmpLevel(in sampler_cmp s, in float<4> x, in float compareValue, in float lod, out uint_only status); +float_like [[]] SampleCmpLevelZero(in sampler_cmp s, in float<4> x, in float compareValue, out uint_only status) : texcube_t_comp_array_s; +$classT [[]] SampleLevel(in sampler s, in float<4> x, in float lod, out uint_only status) : texcube_t_lod_array_s; +$classT [[ro]] SampleBias(in sampler s, in float<4> x, in float bias, in float clamp) : texcube_t_bias_array_cl; +$classT [[]] SampleBias(in sampler s, in float<4> x, in float bias, in float clamp, out uint_only status) : texcube_t_bias_array_cl_s; +$classT [[ro]] SampleGrad(in sampler s, in float<4> x, in $match<2, 2> float<3> ddx, in $match<2, 2> float<3> ddy, in float clamp) : texcube_t_dd_array_cl; +$classT [[]] SampleGrad(in sampler s, in float<4> x, in $match<2, 2> float<3> ddx, in $match<2, 2> float<3> ddy, in float clamp, out uint_only status) : texcube_t_dd_array_cl_s; +$match<0, -1> void<4> [[]] Gather(in sampler s, in float<4> x, out uint_only status) : texcube_t_gather_array_s; +$match<0, -1> void<4> [[]] GatherRed(in sampler s, in float<4> x, out uint_only status) : texcube_t_gather_red_array_s; +$match<0, -1> void<4> [[]] GatherGreen(in sampler s, in float<4> x, out uint_only status) : texcube_t_gather_green_array_s; +$match<0, -1> void<4> [[]] GatherBlue(in sampler s, in float<4> x, out uint_only status) : texcube_t_gather_blue_array_s; +$match<0, -1> void<4> [[]] GatherAlpha(in sampler s, in float<4> x, out uint_only status) : texcube_t_gather_alpha_array_s; +$match<0, -1> void<4> [[]] GatherCmp(in sampler_cmp s, in float<4> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_array_s; +$match<0, -1> void<4> [[]] GatherCmpRed(in sampler_cmp s, in float<4> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_red_array_s; +$match<0, -1> void<4> [[]] GatherCmpGreen(in sampler_cmp s, in float<4> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_green_array_s; +$match<0, -1> void<4> [[]] GatherCmpBlue(in sampler_cmp s, in float<4> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_blue_array_s; +$match<0, -1> void<4> [[]] GatherCmpAlpha(in sampler_cmp s, in float<4> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_alpha_array_s; +} namespace + +namespace BufferMethods { + +void [[]] GetDimensions(out uint_only width) : bufinfo; +$classT [[ro]] Load(in int<1> x) : buffer_load; +$classT [[]] Load(in int<1> x, out uint_only status) : buffer_load_s; + +} namespace + +namespace RWTexture1DMethods { + +void [[]] GetDimensions(out uint_only width) : resinfo_o; +void [[]] GetDimensions(out float_like width) : resinfo_o; +$classT [[ro]] Load(in int<1> x) : rwtex1d_load; +$classT [[]] Load(in int<1> x, out uint_only status) : rwtex1d_load_s; +} namespace + +namespace RWTexture1DArrayMethods { + +void [[]] GetDimensions(out uint_only width, out $type1 elements) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 elements) : resinfo_o; +$classT [[ro]] Load(in int<2> x) : rwtex1d_load_array; +$classT [[]] Load(in int<2> x, out uint_only status) : rwtex1d_load_array_s; +} namespace + +namespace RWTexture2DMethods { + +void [[]] GetDimensions(out uint_only width, out $type1 height) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height) : resinfo_o; +$classT [[ro]] Load(in int<2> x) : rwtex2d_load; +$classT [[]] Load(in int<2> x, out uint_only status) : rwtex2d_load_s; +} namespace + +namespace RWTexture2DArrayMethods { + +void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 elements) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 elements) : resinfo_o; +$classT [[ro]] Load(in int<3> x) : rwtex2d_load_array; +$classT [[]] Load(in int<3> x, out uint_only status) : rwtex2d_load_array_s; +} namespace + +namespace RWTexture2DMSMethods { + +void [[]] GetDimensions(out uint_only width, out $type1 height, out $type2 samples); +void [[]] GetDimensions(out float_like width, out $type1 height, out $type2 samples); +float_like<2> [[ro]] GetSamplePosition(in int s); +$classT [[ro]] Load(in int<2> x, in int s); +$classT [[]] Load(in int<2> x, in int s, out uint_only status); +} namespace + +namespace RWTexture2DMSArrayMethods { + +void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 elements, out $type1 samples); +void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 elements, out $type1 samples); +float_like<2> [[ro]] GetSamplePosition(in int s); +$classT [[ro]] Load(in int<3> x, in int s); +$classT [[]] Load(in int<3> x, in int s, out uint_only status); +} namespace + +namespace RWTexture3DMethods { + +void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 depth) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 depth) : resinfo_o; +$classT [[ro]] Load(in int<3> x) : rwtex3d_load; +$classT [[]] Load(in int<3> x, out uint_only status) : rwtex3d_load_s; +} namespace + +namespace RWBufferMethods { + +void [[]] GetDimensions(out uint_only width) : bufinfo; +$classT [[ro]] Load(in int x) : rwbuffer_load; +$classT [[]] Load(in int x, out uint_only status) : rwbuffer_load_s; + +} namespace + +namespace ByteAddressBufferMethods { + +void [[]] GetDimensions(out uint_only width) : bufinfo; +$funcT [[ro]] Load(in uint byteOffset) : byteaddress_load; +uint<2> [[ro]] Load2(in uint byteOffset) : byteaddress_load; +uint<3> [[ro]] Load3(in uint byteOffset) : byteaddress_load; +uint<4> [[ro]] Load4(in uint byteOffset) : byteaddress_load; +$funcT [[]] Load(in uint byteOffset, out uint_only status) : byteaddress_load_s; +uint<2> [[]] Load2(in uint byteOffset, out uint_only status) : byteaddress_load_s; +uint<3> [[]] Load3(in uint byteOffset, out uint_only status) : byteaddress_load_s; +uint<4> [[]] Load4(in uint byteOffset, out uint_only status) : byteaddress_load_s; + +} namespace + +namespace RWByteAddressBufferMethods { + +void [[]] GetDimensions(out uint_only width) : bufinfo; +$funcT [[ro]] Load(in uint byteOffset) : byteaddress_load; +uint<2> [[ro]] Load2(in uint byteOffset) : byteaddress_load; +uint<3> [[ro]] Load3(in uint byteOffset) : byteaddress_load; +uint<4> [[ro]] Load4(in uint byteOffset) : byteaddress_load; +$funcT [[]] Load(in uint byteOffset, out uint_only status) : byteaddress_load_s; +uint<2> [[]] Load2(in uint byteOffset, out uint_only status) : byteaddress_load_s; +uint<3> [[]] Load3(in uint byteOffset, out uint_only status) : byteaddress_load_s; +uint<4> [[]] Load4(in uint byteOffset, out uint_only status) : byteaddress_load_s; +void [[]] Store(in uint byteOffset, in $funcT value) : byteaddress_store; +void [[]] Store2(in uint byteOffset, in uint<2> value) : byteaddress_store; +void [[]] Store3(in uint byteOffset, in uint<3> value) : byteaddress_store; +void [[]] Store4(in uint byteOffset, in uint<4> value) : byteaddress_store; +// 64-bit integer interlocks +void [[]] InterlockedAdd64(in uint byteOffset, in u64 value); +void [[]] InterlockedAdd64(in uint byteOffset, in u64 value, out any_int64 original) : interlockedadd_immediate; +void [[unsigned_op=InterlockedUMin,overload=1]] InterlockedMin64(in uint byteOffset, in any_int64 value) : interlockedmin; +void [[unsigned_op=InterlockedUMin,overload=1]] InterlockedMin64(in uint byteOffset, in any_int64 value, out any_int64 original) : interlockedmin_immediate; +void [[unsigned_op=InterlockedUMax,overload=1]] InterlockedMax64(in uint byteOffset, in any_int64 value) : interlockedmax; +void [[unsigned_op=InterlockedUMax,overload=1]] InterlockedMax64(in uint byteOffset, in any_int64 value, out any_int64 original) : interlockedmax_immediate; +void [[]] InterlockedAnd64(in uint byteOffset, in u64 value); +void [[]] InterlockedAnd64(in uint byteOffset, in u64 value, out any_int64 original) : interlockedand_immediate; +void [[]] InterlockedOr64(in uint byteOffset, in u64 value); +void [[]] InterlockedOr64(in uint byteOffset, in u64 value, out any_int64 original) : interlockedor_immediate; +void [[]] InterlockedXor64(in uint byteOffset, in u64 value); +void [[]] InterlockedXor64(in uint byteOffset, in u64 value, out any_int64 original) : interlockedxor_immediate; +void [[]] InterlockedCompareStore64(in uint byteOffset, in u64 compare, in u64 value); +void [[]] InterlockedExchange64(in uint byteOffset, in any_int64 value, out any_int64 original); +void [[]] InterlockedCompareExchange64(in uint byteOffset, in u64 compare, in u64 value, out any_int64 original); +// floating point interlocks +void [[]] InterlockedExchangeFloat(in uint byteOffest, in float value, out float original); +void [[]] InterlockedCompareStoreFloatBitwise(in uint byteOffest, in float compare, in float value); +void [[]] InterlockedCompareExchangeFloatBitwise(in uint byteOffest, in float compare, in float value, out float original); +// 32-bit integer interlocks +void [[]] InterlockedAdd(in uint byteOffset, in uint value); +void [[]] InterlockedAdd(in uint byteOffset, in uint value, out uint original) : interlockedadd_immediate; +void [[unsigned_op=InterlockedUMin,overload=1]] InterlockedMin(in uint byteOffset, in any_int32 value) : interlockedmin; +void [[unsigned_op=InterlockedUMin,overload=1]] InterlockedMin(in uint byteOffset, in any_int32 value, out uint original) : interlockedmin_immediate; +void [[unsigned_op=InterlockedUMax,overload=1]] InterlockedMax(in uint byteOffset, in any_int32 value) : interlockedmax; +void [[unsigned_op=InterlockedUMax,overload=1]] InterlockedMax(in uint byteOffset, in any_int32 value, out uint original) : interlockedmax_immediate; +void [[]] InterlockedAnd(in uint byteOffset, in uint value); +void [[]] InterlockedAnd(in uint byteOffset, in uint value, out uint original) : interlockedand_immediate; +void [[]] InterlockedOr(in uint byteOffset, in uint value); +void [[]] InterlockedOr(in uint byteOffset, in uint value, out uint original) : interlockedor_immediate; +void [[]] InterlockedXor(in uint byteOffset, in uint value); +void [[]] InterlockedXor(in uint byteOffset, in uint value, out uint original) : interlockedxor_immediate; +void [[]] InterlockedCompareStore(in uint byteOffset, in uint compare, in uint value); +void [[]] InterlockedExchange(in uint byteOffset, in uint value, out uint original); +void [[]] InterlockedCompareExchange(in uint byteOffset, in uint compare, in uint value, out uint original); + +} namespace + +namespace StructuredBufferMethods { + +void [[]] GetDimensions(out uint_only count, out uint_only stride) : bufinfo; +$classT [[ro]] Load(in int x) : structured_buffer_load; +$classT [[]] Load(in int x, out uint_only status) : structured_buffer_load_s; + +} namespace + +namespace RWStructuredBufferMethods { + +void [[]] GetDimensions(out uint_only count, out uint_only stride) : bufinfo; +uint [[]] IncrementCounter() : structuredbuffer_inc; +uint [[]] DecrementCounter() : structuredbuffer_dec; +$classT [[ro]] Load(in int x) : rwstructured_buffer_load; +$classT [[]] Load(in int x, out uint_only status) : rwstructured_buffer_load_s; + +} namespace + +namespace AppendStructuredBufferMethods { + +void [[]] GetDimensions(out uint_only count, out uint_only stride) : bufinfo; +void [[]] Append(in $match<-1,0> void value ) : structuredbuffer_append; + +} namespace + +namespace ConsumeStructuredBufferMethods { + +void [[]] GetDimensions(out uint_only count, out uint_only stride) : bufinfo; +$classT [[]] Consume() : structuredbuffer_consume; + +} namespace + +namespace FeedbackTexture2DMethods { + +void [[]] WriteSamplerFeedback(in Texture2D t, in sampler s, in float<2> x); +void [[]] WriteSamplerFeedback(in Texture2D t, in sampler s, in float<2> x, in float clamp); +void [[]] WriteSamplerFeedbackBias(in Texture2D t, in sampler s, in float<2> x, in float bias); +void [[]] WriteSamplerFeedbackBias(in Texture2D t, in sampler s, in float<2> x, in float bias, in float clamp); +void [[]] WriteSamplerFeedbackGrad(in Texture2D t, in sampler s, in float<2> x, in float<2> ddx, in float<2> ddy); +void [[]] WriteSamplerFeedbackGrad(in Texture2D t, in sampler s, in float<2> x, in float<2> ddx, in float<2> ddy, in float clamp); +void [[]] WriteSamplerFeedbackLevel(in Texture2D t, in sampler s, in float<2> x, in float lod); + +} namespace + +namespace FeedbackTexture2DArrayMethods { + +void [[]] WriteSamplerFeedback(in Texture2DArray t, in sampler s, in float<3> x); +void [[]] WriteSamplerFeedback(in Texture2DArray t, in sampler s, in float<3> x, in float clamp); +void [[]] WriteSamplerFeedbackBias(in Texture2DArray t, in sampler s, in float<3> x, in float bias); +void [[]] WriteSamplerFeedbackBias(in Texture2DArray t, in sampler s, in float<3> x, in float bias, in float clamp); +void [[]] WriteSamplerFeedbackGrad(in Texture2DArray t, in sampler s, in float<3> x, in float<2> ddx, in float<2> ddy); +void [[]] WriteSamplerFeedbackGrad(in Texture2DArray t, in sampler s, in float<3> x, in float<2> ddx, in float<2> ddy, in float clamp); +void [[]] WriteSamplerFeedbackLevel(in Texture2DArray t, in sampler s, in float<3> x, in float lod); + +} namespace + +namespace RayQueryMethods { + +void [[mutable]] TraceRayInline(in acceleration_struct AccelerationStructure, in uint RayFlags, in uint InstanceInclusionMask, in ray_desc Ray); +bool [[mutable]] Proceed(); +void [[mutable]] Abort(); +void [[mutable]] CommitNonOpaqueTriangleHit(); +void [[mutable]] CommitProceduralPrimitiveHit(in float t); +uint [[ro]] CommittedStatus(); +uint [[ro]] CandidateType(); +float<3,4> [[ro]] CandidateObjectToWorld3x4(); +float<4,3> [[ro]] CandidateObjectToWorld4x3(); +float<3,4> [[ro]] CandidateWorldToObject3x4(); +float<4,3> [[ro]] CandidateWorldToObject4x3(); +float<3,4> [[ro]] CommittedObjectToWorld3x4(); +float<4,3> [[ro]] CommittedObjectToWorld4x3(); +float<3,4> [[ro]] CommittedWorldToObject3x4(); +float<4,3> [[ro]] CommittedWorldToObject4x3(); +bool [[ro]] CandidateProceduralPrimitiveNonOpaque(); +bool [[ro]] CandidateTriangleFrontFace(); +bool [[ro]] CommittedTriangleFrontFace(); +float<2> [[ro]] CandidateTriangleBarycentrics(); +float<2> [[ro]] CommittedTriangleBarycentrics(); +uint [[ro]] RayFlags(); +float<3> [[ro]] WorldRayOrigin(); +float<3> [[ro]] WorldRayDirection(); +float [[ro]] RayTMin(); +float [[ro]] CandidateTriangleRayT(); +float [[ro]] CommittedRayT(); +uint [[ro]] CandidateInstanceIndex(); +uint [[ro]] CandidateInstanceID(); +uint [[ro]] CandidateGeometryIndex(); +uint [[ro]] CandidatePrimitiveIndex(); +float<3> [[ro]] CandidateObjectRayOrigin(); +float<3> [[ro]] CandidateObjectRayDirection(); +uint [[ro]] CommittedInstanceIndex(); +uint [[ro]] CommittedInstanceID(); +uint [[ro]] CommittedGeometryIndex(); +uint [[ro]] CommittedPrimitiveIndex(); +float<3> [[ro]] CommittedObjectRayOrigin(); +float<3> [[ro]] CommittedObjectRayDirection(); +uint [[ro]] CandidateInstanceContributionToHitGroupIndex(); +uint [[ro]] CommittedInstanceContributionToHitGroupIndex(); +uint [[ro,min_sm=6.10]] CandidateClusterID(); +uint [[ro,min_sm=6.10]] CommittedClusterID(); +triangle_positions [[ro,min_sm=6.10]] CandidateTriangleObjectPositions(); +triangle_positions [[ro,min_sm=6.10]] CommittedTriangleObjectPositions(); + +} namespace + +// Shader Execution Reordering +namespace DxHitObjectMethods { + DxHitObject [[static,class_prefix,min_sm=6.9]] MakeNop(); + DxHitObject [[static,class_prefix,min_sm=6.9]] MakeMiss(in uint RayFlags, in uint MissShaderIndex, in ray_desc Ray); + DxHitObject [[static,class_prefix,min_sm=6.9]] FromRayQuery(in RayQuery rq); + DxHitObject [[static,class_prefix,min_sm=6.9]] FromRayQuery(in RayQuery rq, in uint HitKind, in udt Attributes); + DxHitObject [[static,class_prefix,min_sm=6.9]] TraceRay(in acceleration_struct AccelerationStructure, in uint RayFlags, in uint InstanceInclusionMask, in uint RayContributionToHitGroupIndex, in uint MultiplierForGeometryContributionToHitGroupIndex, in uint MissShaderIndex, in ray_desc Ray, inout udt Payload); + void [[static,class_prefix,min_sm=6.9]] Invoke(in DxHitObject ho, inout udt Payload); + bool [[rn,class_prefix,min_sm=6.9]] IsMiss(); + bool [[rn,class_prefix,min_sm=6.9]] IsHit(); + bool [[rn,class_prefix,min_sm=6.9]] IsNop(); + uint [[rn,class_prefix,min_sm=6.9]] GetRayFlags(); + float [[rn,class_prefix,min_sm=6.9]] GetRayTMin(); + float [[rn,class_prefix,min_sm=6.9]] GetRayTCurrent(); + float<3> [[rn,class_prefix,min_sm=6.9]] GetWorldRayOrigin(); + float<3> [[rn,class_prefix,min_sm=6.9]] GetWorldRayDirection(); + float<3> [[rn,class_prefix,min_sm=6.9]] GetObjectRayOrigin(); + float<3> [[rn,class_prefix,min_sm=6.9]] GetObjectRayDirection(); + float<3,4> [[rn,class_prefix,min_sm=6.9]] GetObjectToWorld3x4(); + float<4,3> [[rn,class_prefix,min_sm=6.9]] GetObjectToWorld4x3(); + float<3,4> [[rn,class_prefix,min_sm=6.9]] GetWorldToObject3x4(); + float<4,3> [[rn,class_prefix,min_sm=6.9]] GetWorldToObject4x3(); + uint [[rn,class_prefix,min_sm=6.9]] GetGeometryIndex(); + uint [[rn,class_prefix,min_sm=6.9]] GetInstanceIndex(); + uint [[rn,class_prefix,min_sm=6.9]] GetInstanceID(); + uint [[rn,class_prefix,min_sm=6.9]] GetPrimitiveIndex(); + uint [[rn,class_prefix,min_sm=6.9]] GetHitKind(); + uint [[rn,class_prefix,min_sm=6.9]] GetShaderTableIndex(); + void [[class_prefix,min_sm=6.9]] GetAttributes(out udt Attributes); + void [[mutable,class_prefix,min_sm=6.9]] SetShaderTableIndex(in uint RecordIndex); + uint [[ro,class_prefix,min_sm=6.9]] LoadLocalRootTableConstant(in uint RootConstantOffsetInBytes); + uint [[rn,class_prefix,min_sm=6.10]] GetClusterID(); + triangle_positions [[rn,class_prefix,min_sm=6.10]] TriangleObjectPositions(); +} namespace + +namespace DxIntrinsics { +bool [[min_sm=6.10]] IsDebuggingEnabled(); +void [[min_sm=6.9]] MaybeReorderThread(in DxHitObject HitObject); +void [[min_sm=6.9]] MaybeReorderThread(in uint CoherenceHint, in uint NumCoherenceHintBitsFromLSB); +void [[min_sm=6.9]] MaybeReorderThread(in DxHitObject HitObject, in uint CoherenceHint, in uint NumCoherenceHintBitsFromLSB); + +// LinAlg intrinsics +void [[min_sm=6.10]] __builtin_LinAlg_FillMatrix(out LinAlgMatrix ret, in bool isInputSigned, in numeric value); +void [[min_sm=6.10]] __builtin_LinAlg_CopyConvertMatrix(out LinAlgMatrix ret, in LinAlgMatrix source, in bool transpose); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixLoadFromDescriptor(out LinAlgMatrix ret, in ByteAddressBuffer buf, in uint offset, in uint stride, in uint layout, in uint align); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixLoadFromDescriptor(out LinAlgMatrix ret, in RWByteAddressBuffer buf, in uint offset, in uint stride, in uint layout, in uint align); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixLoadFromMemory(out LinAlgMatrix ret, groupshared LinAlg<>[] memory, in uint offset, in uint stride, in uint layout); +uint [[min_sm=6.10]] __builtin_LinAlg_MatrixLength(in LinAlgMatrix matrix); +uint<2> [[min_sm=6.10]] __builtin_LinAlg_MatrixGetCoordinate(in LinAlgMatrix matrix, in uint threadLocalIndex); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixGetElement(out LinAlg ret, in LinAlgMatrix matrix, in uint threadLocalIndex); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixSetElement(ref LinAlgMatrix ret, in LinAlgMatrix matrix, in uint threadLocalIndex, in LinAlg value); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixStoreToDescriptor(in LinAlgMatrix matrix, in RWByteAddressBuffer buf, in uint offset, in uint stride, in uint layout, in uint align); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixStoreToMemory(in LinAlgMatrix matrix, groupshared LinAlg<>[] memory, in uint offset, in uint stride, in uint layout); +uint [[min_sm=6.10]] __builtin_LinAlg_MatrixQueryAccumulatorLayout(); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixMatrixMultiply(out LinAlgMatrix matrixC, in LinAlgMatrix matrixA, in LinAlgMatrix matrixB); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixMatrixMultiplyAccumulate(ref LinAlgMatrix matrixR, in LinAlgMatrix matrixA, in LinAlgMatrix matrixB, in LinAlgMatrix matrixC); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixAccumulate(ref LinAlgMatrix matrixC, in LinAlgMatrix matrixLHS, in LinAlgMatrix matrixRHS); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixVectorMultiply(out LinAlg ret, in LinAlgMatrix mat, in bool isOutputSigned, in LinAlg input, in uint inputInterp); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixVectorMultiplyAdd(out LinAlg ret, in LinAlgMatrix mat, in bool isOutputSigned, in LinAlg input, in uint inputInterp, in LinAlg bias); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixAccumulateToDescriptor(in LinAlgMatrix matrix, in RWByteAddressBuffer buf, in uint offset, in uint stride, in uint layout, in uint align); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixAccumulateToMemory(in LinAlgMatrix matrix, groupshared LinAlg<>[] memory, in uint offset, in uint stride, in uint layout); +void [[min_sm=6.10]] __builtin_LinAlg_MatrixOuterProduct(out LinAlgMatrix ret, in bool isInputSigned, in LinAlg vecA, in LinAlg vecB); +void [[min_sm=6.10]] __builtin_LinAlg_Convert(out LinAlg ret, in LinAlg vec, in uint input_interp, in uint output_interp); +void [[min_sm=6.10]] __builtin_LinAlg_VectorAccumulateToDescriptor(in RWByteAddressBuffer buf, in uint offset, in uint align, in LinAlg<> vec); +} namespace + +// Work Graphs objects and methods + +// EmptyNodeInput +namespace EmptyNodeInputMethods { + uint [[ro]] Count(); +} namespace + +// RWDispatchNodeInputRecord methods (in addition to Get) +namespace RWDispatchNodeInputRecordMethods { + bool [[]] FinishedCrossGroupSharing(); +} namespace + +// GroupNodeInputRecords methods (in addition to Get and array access subscript) +namespace GroupNodeInputRecordsMethods { + uint [[ro]] Count(); +} namespace + +// NodeOutput +namespace NodeOutputMethods { + $match<0,-2> ThreadNodeOutputRecords [[]] GetThreadNodeOutputRecords(in uint numRecords); + $match<0,-2> GroupNodeOutputRecords [[]] GetGroupNodeOutputRecords(in uint numRecords); + bool [[]] IsValid(); +} namespace + +// EmptyNodeOutput +namespace EmptyNodeOutputMethods { + void [[]] GroupIncrementOutputCount(in uint count); + void [[]] ThreadIncrementOutputCount(in uint count); + bool [[]] IsValid(); +} namespace + +// ThreadNodeOutputRecords, GroupNodeOutputRecords +namespace GroupOrThreadNodeOutputRecordsMethods { + void [[]] OutputComplete(); +} namespace + +// SPIRV Change Starts + +namespace VkSubpassInputMethods { +$classT [[]] SubpassLoad() : subpassinput_load; +} namespace + +namespace VkSubpassInputMSMethods { +$classT [[]] SubpassLoad(in int sample) : subpassinputms_load; +} namespace + +namespace VkSampledTexture1DMethods { + // Use float for DXIL don't support f16 on CalcLOD. + float [[ro]] CalculateLevelOfDetail(in float<1> x) : tex1d_t_calc_lod; + float [[ro]] CalculateLevelOfDetailUnclamped(in float<1> x) : tex1d_t_calc_lod_unclamped; + void [[]] GetDimensions(in uint x, out uint_only width, out $type2 levels) : resinfo_uint; + void [[]] GetDimensions(in uint x, out float_like width, out $type2 levels) : resinfo; + void [[]] GetDimensions(out uint_only width) : resinfo_o; + void [[]] GetDimensions(out float_like width) : resinfo_o; + $classT [[ro]] Load(in int<2> x) : tex1d_t_load; + $classT [[ro]] Load(in int<2> x, in int<1> o) : tex1d_t_load_o; + $classT [[]] Load(in int<2> x, in int<1> o, out uint_only status) : tex1d_t_load_o_s; + $classT [[ro]] Sample(in float<1> x) : tex1d_t; + $classT [[ro]] Sample(in float<1> x, in int<1> o) : tex1d_t_o; + $classT [[ro]] SampleBias(in float<1> x, in float bias) : tex1d_t_bias; + $classT [[ro]] SampleBias(in float<1> x, in float bias, in int<1> o) : tex1d_t_bias_o; + float_like [[ro]] SampleCmp(in float<1> x, in float compareValue) : tex1d_t_comp; + float_like [[ro]] SampleCmp(in float<1> x, in float compareValue, in int<1> o) : tex1d_t_comp_o; + float_like [[ro]] SampleCmpBias(in float<1> x, in float compareValue, in float bias) : tex1d_t_comp_bias; + float_like [[ro]] SampleCmpBias(in float<1> x, in float compareValue, in float bias, in int<1> o) : tex1d_t_comp_bias_o; + float_like [[ro]] SampleCmpGrad(in float<1> x, in float compareValue, in $type1 ddx, in $type1 ddy) : tex1d_t_comp_dd; + float_like [[ro]] SampleCmpGrad(in float<1> x, in float compareValue, in $type1 ddx, in $type1 ddy, in int<1> o) : tex1d_t_comp_dd_o; + float_like [[ro]] SampleCmpLevel(in float<1> x, in float compareValue, in float lod); + float_like [[ro]] SampleCmpLevel(in float<1> x, in float compareValue, in float lod, in int<1> o); + float_like [[ro]] SampleCmpLevelZero(in float<1> x, in float compareValue) : tex1d_t_comp_lz; + float_like [[ro]] SampleCmpLevelZero(in float<1> x, in float compareValue, in int<1> o) : tex1d_t_comp_lz_o; + $classT [[ro]] SampleGrad(in float<1> x, in $type1 ddx, in $type1 ddy) : tex1d_t_dd; + $classT [[ro]] SampleGrad(in float<1> x, in $type1 ddx, in $type1 ddy, in int<1> o) : tex1d_t_dd_o; + $classT [[ro]] SampleLevel(in float<1> x, in float lod) : tex1d_t_lod; + $classT [[ro]] SampleLevel(in float<1> x, in float lod, in int<1> o) : tex1d_t_lod_o; + $classT [[ro]] Sample(in float<1> x, in int<1> o, in float clamp) : tex1d_t_o_cl; + $classT [[]] Sample(in float<1> x, in int<1> o, in float clamp, out uint_only status) : tex1d_t_o_cl_s; + float_like [[ro]] SampleCmp(in float<1> x, in float compareValue, in int<1> o, in float clamp) : tex1d_t_comp_o_cl; + float_like [[]] SampleCmp(in float<1> x, in float compareValue, in int<1> o, in float clamp, out uint_only status) : tex1d_t_comp_o_cl_s; + float_like [[ro]] SampleCmpBias(in float<1> x, in float compareValue, in float bias, in int<1> o, in float clamp) : tex1d_t_comp_bias_o_cl; + float_like [[]] SampleCmpBias(in float<1> x, in float compareValue, in float bias, in int<1> o, in float clamp, out uint_only status) : tex1d_t_comp_bias_o_cl_s; + float_like [[ro]] SampleCmpGrad(in float<1> x, in float compareValue, in $type1 ddx, in $type1 ddy, in int<1> o, in float clamp) : tex1d_t_comp_dd_o_cl; + float_like [[]] SampleCmpGrad(in float<1> x, in float compareValue, in $type1 ddx, in $type1 ddy, in int<1> o, in float clamp, out uint_only status) : tex1d_t_comp_dd_o_cl_s; + float_like [[]] SampleCmpLevel(in float<1> x, in float compareValue, in float lod, in int<1> o, out uint_only status); + float_like [[]] SampleCmpLevelZero(in float<1> x, in float compareValue, in int<1> o, out uint_only status) : tex1d_t_comp_o_s; + $classT [[]] SampleLevel(in float<1> x, in float lod, in int<1> o, out uint_only status) : tex1d_t_lod_o_s; + $classT [[ro]] SampleBias(in float<1> x, in float bias, in int<1> o, in float clamp) : tex1d_t_bias_o_cl; + $classT [[]] SampleBias(in float<1> x, in float bias, in int<1> o, in float clamp, out uint_only status) : tex1d_t_bias_o_cl_s; + $classT [[]] SampleGrad(in float<1> x, in $type1 ddx, in $type1 ddy, in int<1> o, in float clamp) : tex1d_t_dd_o_cl; + $classT [[]] SampleGrad(in float<1> x, in $type1 ddx, in $type1 ddy, in int<1> o, in float clamp, out uint_only status) : tex1d_t_dd_o_cl_s; +} namespace + +namespace VkSampledTexture1DArrayMethods { + float [[ro]] CalculateLevelOfDetail(in float<1> x) : tex1d_t_calc_lod_array; + float [[ro]] CalculateLevelOfDetailUnclamped(in float<1> x) : tex1d_t_calc_lod_unclamped_array; + void [[]] GetDimensions(in uint x, out uint_only width, out $type2 elements, out $type2 levels) : resinfo_uint; + void [[]] GetDimensions(in uint x, out float_like width, out $type2 elements, out $type2 levels) : resinfo; + void [[]] GetDimensions(out uint_only width, out $type1 elements) : resinfo_uint_o; + void [[]] GetDimensions(out float_like width, out $type1 elements) : resinfo_o; + $classT [[ro]] Load(in int<3> x) : tex1d_t_load_array; + $classT [[ro]] Load(in int<3> x, in int<1> o) : tex1d_t_load_array_o; + $classT [[]] Load(in int<3> x, in int<1> o, out uint_only status) : tex1d_t_load_array_o_s; + $classT [[ro]] Sample(in float<2> x) : tex1d_t_array; + $classT [[ro]] Sample(in float<2> x, in int<1> o) : tex1d_t_array_o; + $classT [[ro]] SampleBias(in float<2> x, in float bias) : tex1d_t_bias_array; + $classT [[ro]] SampleBias(in float<2> x, in float bias, in int<1> o) : tex1d_t_bias_array_o; + float_like [[ro]] SampleCmp(in float<2> x, in float compareValue) : tex1d_t_comp_array; + float_like [[ro]] SampleCmp(in float<2> x, in float compareValue, in int<1> o) : tex1d_t_comp_array_o; + float_like [[ro]] SampleCmpBias(in float<2> x, in float compareValue, in float bias) : tex1d_t_comp_bias_array; + float_like [[ro]] SampleCmpBias(in float<2> x, in float compareValue, in float bias, in int<1> o) : tex1d_t_comp_bias_array_o; + float_like [[ro]] SampleCmpGrad(in float<2> x, in float compareValue, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy) : tex1d_t_comp_dd_array; + float_like [[ro]] SampleCmpGrad(in float<2> x, in float compareValue, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy, in int<1> o) : tex1d_t_comp_dd_array_o; + float_like [[ro]] SampleCmpLevel(in float<2> x, in float compareValue, in float lod); + float_like [[ro]] SampleCmpLevel(in float<2> x, in float compareValue, in float lod, in int<1> o); + float_like [[ro]] SampleCmpLevelZero(in float<2> x, in float compareValue) : tex1d_t_comp_lz_array; + float_like [[ro]] SampleCmpLevelZero(in float<2> x, in float compareValue, in int<1> o) : tex1d_t_comp_lz_array_o; + $classT [[ro]] SampleGrad(in float<2> x, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy) : tex1d_t_dd_array; + $classT [[ro]] SampleGrad(in float<2> x, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy, in int<1> o) : tex1d_t_dd_array_o; + $classT [[ro]] SampleLevel(in float<2> x, in float lod) : tex1d_t_lod_array; + $classT [[ro]] SampleLevel(in float<2> x, in float lod, in int<1> o) : tex1d_t_lod_array_o; + $classT [[ro]] Sample(in float<2> x, in int<1> o, in float clamp) : tex1d_t_array_o_cl; + $classT [[]] Sample(in float<2> x, in int<1> o, in float clamp, out uint_only status) : tex1d_t_array_o_cl_s; + float_like [[ro]] SampleCmp(in float<2> x, in float compareValue, in int<1> o, in float clamp) : tex1d_t_comp_array_o_cl; + float_like [[]] SampleCmp(in float<2> x, in float compareValue, in int<1> o, in float clamp, out uint_only status) : tex1d_t_comp_array_o_cl_s; + float_like [[ro]] SampleCmpBias(in float<2> x, in float compareValue, in float bias, in int<1> o, in float clamp) : tex1d_t_comp_bias_array_o_cl; + float_like [[]] SampleCmpBias(in float<2> x, in float compareValue, in float bias, in int<1> o, in float clamp, out uint_only status) : tex1d_t_comp_bias_array_o_cl_s; + float_like [[ro]] SampleCmpGrad(in float<2> x, in float compareValue, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy, in int<1> o, in float clamp) : tex1d_t_comp_dd_array_o_cl; + float_like [[]] SampleCmpGrad(in float<2> x, in float compareValue, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy, in int<1> o, in float clamp, out uint_only status) : tex1d_t_comp_dd_array_o_cl_s; + float_like [[]] SampleCmpLevel(in float<2> x, in float compareValue, in float lod, in int<1> o, out uint_only status); + float_like [[]] SampleCmpLevelZero(in float<2> x, in float compareValue, in int<1> o, out uint_only status) : tex1d_t_comp_array_o_s; + $classT [[]] SampleLevel(in float<2> x, in float lod, in int<1> o, out uint_only status) : tex1d_t_lod_array_o_s; + $classT [[ro]] SampleBias(in float<2> x, in float bias, in int<1> o, in float clamp) : tex1d_t_bias_array_o_cl; + $classT [[]] SampleBias(in float<2> x, in float bias, in int<1> o, in float clamp, out uint_only status) : tex1d_t_bias_array_o_cl_s; + $classT [[ro]] SampleGrad(in float<2> x, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy, in int<1> o, in float clamp) : tex1d_t_dd_array_o_cl; + $classT [[]] SampleGrad(in float<2> x, in $match<2, 2> float<1> ddx, in $match<2, 2> float<1> ddy, in int<1> o, in float clamp, out uint_only status) : tex1d_t_dd_array_o_cl_s; +} namespace + +namespace VkSampledTexture2DMethods { + $classT [[ro]] Sample(in float<2> x) : tex2d_t; + $classT [[ro]] Sample(in float<2> x, in int<2> o) : tex2d_t_o; + $classT [[ro]] Sample(in float<2> x, in int<2> o, in float clamp) : tex2d_t_o_cl; + $classT [[]] Sample(in float<2> x, in int<2> o, in float clamp, out uint_only status) : tex2d_t_o_cl_s; + float [[ro]] CalculateLevelOfDetail(in float<2> x) : tex2d_t_calc_lod; + float [[ro]] CalculateLevelOfDetailUnclamped(in float<2> x) : tex2d_t_calc_lod_unclamped; + $match<0, -1> void<4> [[ro]] Gather(in float<2> x) : tex2d_t_gather; + $match<0, -1> void<4> [[ro]] Gather(in float<2> x, in int<2> o) : tex2d_t_gather_o; + $match<0, -1> void<4> [[]] Gather(in float<2> x, in int<2> o, out uint_only status) : tex2d_t_gather_o_s; + void [[]] GetDimensions(in uint x, out uint_only width, out $type2 height, out $type2 levels) : resinfo_uint; + void [[]] GetDimensions(in uint x, out float_like width, out $type2 height, out $type2 levels) : resinfo; + void [[]] GetDimensions(out uint_only width, out $type1 height) : resinfo_uint_o; + void [[]] GetDimensions(out float_like width, out $type1 height) : resinfo_o; + $classT [[ro]] Load(in int<3> x) : tex2d_t_load; + $classT [[ro]] Load(in int<3> x, in int<2> o) : tex2d_t_load_o; + $classT [[]] Load(in int<3> x, in int<2> o, out uint_only status) : tex2d_t_load_o_s; + $classT [[ro]] SampleBias(in float<2> x, in float bias) : tex2d_t_bias; + $classT [[ro]] SampleBias(in float<2> x, in float bias, in int<2> o) : tex2d_t_bias_o; + float_like [[ro]] SampleCmp(in float<2> x, in float compareValue) : tex2d_t_comp; + float_like [[ro]] SampleCmp(in float<2> x, in float compareValue, in int<2> o) : tex2d_t_comp_o; + float_like [[ro]] SampleCmpBias(in float<2> x, in float compareValue, in float bias) : tex2d_t_comp_bias; + float_like [[ro]] SampleCmpBias(in float<2> x, in float compareValue, in float bias, in int<2> o) : tex2d_t_comp_bias_o; + float_like [[ro]] SampleCmpGrad(in float<2> x, in float compareValue, in $type1 ddx, in $type1 ddy) : tex2d_t_comp_dd; + float_like [[ro]] SampleCmpGrad(in float<2> x, in float compareValue, in $type1 ddx, in $type1 ddy, in int<2> o) : tex2d_t_comp_dd_o; + float_like [[ro]] SampleCmpLevel(in float<2> x, in float compareValue, in float lod); + float_like [[ro]] SampleCmpLevel(in float<2> x, in float compareValue, in float lod, in int<2> o); + float_like [[ro]] SampleCmpLevelZero(in float<2> x, in float compareValue) : tex2d_t_comp_lz; + float_like [[ro]] SampleCmpLevelZero(in float<2> x, in float compareValue, in int<2> o) : tex2d_t_comp_lz_o; + $classT [[ro]] SampleGrad(in float<2> x, in $type1 ddx, in $type1 ddy) : tex2d_t_dd; + $classT [[ro]] SampleGrad(in float<2> x, in $type1 ddx, in $type1 ddy, in int<2> o) : tex2d_t_dd_o; + $classT [[ro]] SampleLevel(in float<2> x, in float lod) : tex2d_t_lod; + $classT [[ro]] SampleLevel(in float<2> x, in float lod, in int<2> o) : tex2d_t_lod_o; + float_like [[ro]] SampleCmp(in float<2> x, in float compareValue, in int<2> o, in float clamp) : tex2d_t_comp_o_cl; + float_like [[]] SampleCmp(in float<2> x, in float compareValue, in int<2> o, in float clamp, out uint_only status) : tex2d_t_comp_o_cl_s; + float_like [[ro]] SampleCmpBias(in float<2> x, in float compareValue, in float bias, in int<2> o, in float clamp) : tex2d_t_comp_bias_o_cl; + float_like [[]] SampleCmpBias(in float<2> x, in float compareValue, in float bias, in int<2> o, in float clamp, out uint_only status) : tex2d_t_comp_bias_o_cl_s; + float_like [[ro]] SampleCmpGrad(in float<2> x, in float compareValue, in $type1 ddx, in $type1 ddy, in int<2> o, in float clamp) : tex2d_t_comp_dd_o_cl; + float_like [[]] SampleCmpGrad(in float<2> x, in float compareValue, in $type1 ddx, in $type1 ddy, in int<2> o, in float clamp, out uint_only status) : tex2d_t_comp_dd_o_cl_s; + float_like [[]] SampleCmpLevel(in float<2> x, in float compareValue, in float lod, in int<2> o, out uint_only status); + float_like [[]] SampleCmpLevelZero(in float<2> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_comp_o_s; + $classT [[]] SampleLevel(in float<2> x, in float lod, in int<2> o, out uint_only status) : tex2d_t_lod_o_s; + $classT [[ro]] SampleBias(in float<2> x, in float bias, in int<2> o, in float clamp) : tex2d_t_bias_o_cl; + $classT [[]] SampleBias(in float<2> x, in float bias, in int<2> o, in float clamp, out uint_only status) : tex2d_t_bias_o_cl_s; + $classT [[ro]] SampleGrad(in float<2> x, in $type1 ddx, in $type1 ddy, in int<2> o, in float clamp) : tex2d_t_dd_o_cl; + $classT [[]] SampleGrad(in float<2> x, in $type1 ddx, in $type1 ddy, in int<2> o, in float clamp, out uint_only status) : tex2d_t_dd_o_cl_s; + $match<0, -1> void<4> [[ro]] GatherAlpha(in float<2> x) : tex2d_t_gather_alpha; + $match<0, -1> void<4> [[ro]] GatherAlpha(in float<2> x, in int<2> o) : tex2d_t_gather_alpha_o; + $match<0, -1> void<4> [[ro]] GatherAlpha(in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_alpha_o4; + $match<0, -1> void<4> [[ro]] GatherBlue(in float<2> x) : tex2d_t_gather_blue; + $match<0, -1> void<4> [[ro]] GatherBlue(in float<2> x, in int<2> o) : tex2d_t_gather_blue_o; + $match<0, -1> void<4> [[ro]] GatherBlue(in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_blue_o4; + $match<0, -1> void<4> [[ro]] GatherCmp(in float<2> x, in float compareValue) : tex2d_t_gather_comp; + $match<0, -1> void<4> [[ro]] GatherCmp(in float<2> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_o; + $match<0, -1> void<4> [[ro]] GatherCmpAlpha(in float<2> x, in float compareValue) : tex2d_t_gather_comp_alpha; + $match<0, -1> void<4> [[ro]] GatherCmpAlpha(in float<2> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_alpha_o; + $match<0, -1> void<4> [[ro]] GatherCmpAlpha(in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_alpha_o4; + $match<0, -1> void<4> [[ro]] GatherCmpBlue(in float<2> x, in float compareValue) : tex2d_t_gather_comp_blue; + $match<0, -1> void<4> [[ro]] GatherCmpBlue(in float<2> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_blue_o; + $match<0, -1> void<4> [[ro]] GatherCmpBlue(in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_blue_o4; + $match<0, -1> void<4> [[ro]] GatherCmpGreen(in float<2> x, in float compareValue) : tex2d_t_gather_comp_green; + $match<0, -1> void<4> [[ro]] GatherCmpGreen(in float<2> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_green_o; + $match<0, -1> void<4> [[ro]] GatherCmpGreen(in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_green_o4; + $match<0, -1> void<4> [[ro]] GatherCmpRed(in float<2> x, in float compareValue) : tex2d_t_gather_comp_red; + $match<0, -1> void<4> [[ro]] GatherCmpRed(in float<2> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_red_o; + $match<0, -1> void<4> [[ro]] GatherCmpRed(in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_red_o4; + $match<0, -1> void<4> [[ro]] GatherGreen(in float<2> x) : tex2d_t_gather_green; + $match<0, -1> void<4> [[ro]] GatherGreen(in float<2> x, in int<2> o) : tex2d_t_gather_green_o; + $match<0, -1> void<4> [[ro]] GatherGreen(in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_green_o4; + $match<0, -1> void<4> [[ro]] GatherRed(in float<2> x) : tex2d_t_gather_red; + $match<0, -1> void<4> [[ro]] GatherRed(in float<2> x, in int<2> o) : tex2d_t_gather_red_o; + $match<0, -1> void<4> [[ro]] GatherRed(in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_red_o4; + $match<0, -1> void<4> [[]] GatherRed(in float<2> x, in int<2> o, out uint_only status) : tex2d_t_gather_red_o_s; + $match<0, -1> void<4> [[]] GatherRed(in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_red_o4_s; + $match<0, -1> void<4> [[]] GatherGreen(in float<2> x, in int<2> o, out uint_only status) : tex2d_t_gather_green_o_s; + $match<0, -1> void<4> [[]] GatherGreen(in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_green_o4_s; + $match<0, -1> void<4> [[]] GatherBlue(in float<2> x, in int<2> o, out uint_only status) : tex2d_t_gather_blue_o_s; + $match<0, -1> void<4> [[]] GatherBlue(in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_blue_o4_s; + $match<0, -1> void<4> [[]] GatherAlpha(in float<2> x, in int<2> o, out uint_only status) : tex2d_t_gather_alpha_o_s; + $match<0, -1> void<4> [[]] GatherAlpha(in float<2> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_alpha_o4_s; + $match<0, -1> void<4> [[]] GatherCmp(in float<2> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_o_s; + $match<0, -1> void<4> [[]] GatherCmpRed(in float<2> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_red_o_s; + $match<0, -1> void<4> [[]] GatherCmpGreen(in float<2> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_green_o_s; + $match<0, -1> void<4> [[]] GatherCmpBlue(in float<2> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_blue_o_s; + $match<0, -1> void<4> [[]] GatherCmpAlpha(in float<2> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_alpha_o_s; + $match<0, -1> void<4> [[]] GatherCmpRed(in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_red_o4_s; + $match<0, -1> void<4> [[]] GatherCmpGreen(in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_green_o4_s; + $match<0, -1> void<4> [[]] GatherCmpBlue(in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_blue_o4_s; + $match<0, -1> void<4> [[]] GatherCmpAlpha(in float<2> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_alpha_o4_s; +} namespace + +namespace VkSampledTexture2DArrayMethods { + float [[ro]] CalculateLevelOfDetail(in float<2> x) : tex2d_t_calc_lod_array; + float [[ro]] CalculateLevelOfDetailUnclamped(in float<2> x) : tex2d_t_calc_lod_unclamped_array; + $match<0, -1> void<4> [[ro]] Gather(in float<3> x) : tex2d_t_gather_array; + $match<0, -1> void<4> [[ro]] Gather(in float<3> x, in int<2> o) : tex2d_t_gather_array_o; + $match<0, -1> void<4> [[ro]] GatherAlpha(in float<3> x) : tex2d_t_gather_alpha_array; + $match<0, -1> void<4> [[ro]] GatherAlpha(in float<3> x, in int<2> o) : tex2d_t_gather_alpha_array_o; + $match<0, -1> void<4> [[ro]] GatherAlpha(in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_alpha_array_o4; + $match<0, -1> void<4> [[ro]] GatherBlue(in float<3> x) : tex2d_t_gather_blue_array; + $match<0, -1> void<4> [[ro]] GatherBlue(in float<3> x, in int<2> o) : tex2d_t_gather_blue_array_o; + $match<0, -1> void<4> [[ro]] GatherBlue(in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_blue_array_o4; + $match<0, -1> void<4> [[ro]] GatherCmp(in float<3> x, in float compareValue) : tex2d_t_gather_comp_array; + $match<0, -1> void<4> [[ro]] GatherCmp(in float<3> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_array_o; + $match<0, -1> void<4> [[ro]] GatherCmpAlpha(in float<3> x, in float compareValue) : tex2d_t_gather_comp_alpha_array; + $match<0, -1> void<4> [[ro]] GatherCmpAlpha(in float<3> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_alpha_array_o; + $match<0, -1> void<4> [[ro]] GatherCmpAlpha(in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_alpha_array_o4; + $match<0, -1> void<4> [[ro]] GatherCmpBlue(in float<3> x, in float compareValue) : tex2d_t_gather_comp_blue_array; + $match<0, -1> void<4> [[ro]] GatherCmpBlue(in float<3> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_blue_array_o; + $match<0, -1> void<4> [[ro]] GatherCmpBlue(in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_blue_array_o4; + $match<0, -1> void<4> [[ro]] GatherCmpGreen(in float<3> x, in float compareValue) : tex2d_t_gather_comp_green_array; + $match<0, -1> void<4> [[ro]] GatherCmpGreen(in float<3> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_green_array_o; + $match<0, -1> void<4> [[ro]] GatherCmpGreen(in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_green_array_o4; + $match<0, -1> void<4> [[ro]] GatherCmpRed(in float<3> x, in float compareValue) : tex2d_t_gather_comp_red_array; + $match<0, -1> void<4> [[ro]] GatherCmpRed(in float<3> x, in float compareValue, in int<2> o) : tex2d_t_gather_comp_red_array_o; + $match<0, -1> void<4> [[ro]] GatherCmpRed(in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_comp_red_array_o4; + $match<0, -1> void<4> [[ro]] GatherGreen(in float<3> x) : tex2d_t_gather_green_array; + $match<0, -1> void<4> [[ro]] GatherGreen(in float<3> x, in int<2> o) : tex2d_t_gather_green_array_o; + $match<0, -1> void<4> [[ro]] GatherGreen(in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_green_array_o4; + $match<0, -1> void<4> [[ro]] GatherRed(in float<3> x) : tex2d_t_gather_red_array; + $match<0, -1> void<4> [[ro]] GatherRed(in float<3> x, in int<2> o) : tex2d_t_gather_red_array_o; + $match<0, -1> void<4> [[ro]] GatherRed(in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4) : tex2d_t_gather_red_array_o4; + void [[]] GetDimensions(in uint x, out uint_only width, out $type2 height, out $type2 elements, out $type2 levels) : resinfo_uint; + void [[]] GetDimensions(in uint x, out float_like width, out $type2 height, out $type2 elements, out $type2 levels) : resinfo; + void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 elements) : resinfo_uint_o; + void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 elements) : resinfo_o; + $classT [[ro]] Load(in int<4> x) : tex2d_t_load_array; + $classT [[ro]] Load(in int<4> x, in int<2> o) : tex2d_t_load_array_o; + $classT [[]] Load(in int<4> x, in int<2> o, out uint_only status) : tex2d_t_load_array_o_s; + $classT [[ro]] Sample(in float<3> x) : tex2d_t_array; + $classT [[ro]] Sample(in float<3> x, in int<2> o) : tex2d_t_array_o; + $classT [[ro]] SampleBias(in float<3> x, in float bias) : tex2d_t_bias_array; + $classT [[ro]] SampleBias(in float<3> x, in float bias, in int<2> o) : tex2d_t_bias_array_o; + float_like [[ro]] SampleCmp(in float<3> x, in float compareValue) : tex2d_t_comp_array; + float_like [[ro]] SampleCmp(in float<3> x, in float compareValue, in int<2> o) : tex2d_t_comp_array_o; + float_like [[ro]] SampleCmpBias(in float<3> x, in float compareValue, in float bias) : tex2d_t_comp_bias_array; + float_like [[ro]] SampleCmpBias(in float<3> x, in float compareValue, in float bias, in int<2> o) : tex2d_t_comp_bias_array_o; + float_like [[ro]] SampleCmpGrad(in float<3> x, in float compareValue, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy) : tex2d_t_comp_dd_array; + float_like [[ro]] SampleCmpGrad(in float<3> x, in float compareValue, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy, in int<2> o) : tex2d_t_comp_dd_array_o; + float_like [[ro]] SampleCmpLevel(in float<3> x, in float compareValue, in float lod); + float_like [[ro]] SampleCmpLevel(in float<3> x, in float compareValue, in float lod, in int<2> o); + float_like [[ro]] SampleCmpLevelZero(in float<3> x, in float compareValue) : tex2d_t_comp_lz_array; + float_like [[ro]] SampleCmpLevelZero(in float<3> x, in float compareValue, in int<2> o) : tex2d_t_comp_lz_array_o; + $classT [[ro]] SampleGrad(in float<3> x, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy) : tex2d_t_dd_array; + $classT [[ro]] SampleGrad(in float<3> x, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy, in int<2> o) : tex2d_t_dd_array_o; + $classT [[ro]] SampleLevel(in float<3> x, in float lod) : tex2d_t_lod_array; + $classT [[ro]] SampleLevel(in float<3> x, in float lod, in int<2> o) : tex2d_t_lod_array_o; + $classT [[ro]] Sample(in float<3> x, in int<2> o, in float clamp) : tex2d_t_array_o_cl; + $classT [[]] Sample(in float<3> x, in int<2> o, in float clamp, out uint_only status) : tex2d_t_array_o_cl_s; + float_like [[ro]] SampleCmp(in float<3> x, in float compareValue, in int<2> o, in float clamp) : tex2d_t_comp_array_o_cl; + float_like [[]] SampleCmp(in float<3> x, in float compareValue, in int<2> o, in float clamp, out uint_only status) : tex2d_t_comp_array_o_cl_s; + float_like [[ro]] SampleCmpBias(in float<3> x, in float compareValue, in float bias, in int<2> o, in float clamp) : tex2d_t_comp_bias_array_o_cl; + float_like [[]] SampleCmpBias(in float<3> x, in float compareValue, in float bias, in int<2> o, in float clamp, out uint_only status) : tex2d_t_comp_bias_array_o_cl_s; + float_like [[ro]] SampleCmpGrad(in float<3> x, in float compareValue, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy, in int<2> o, in float clamp) : tex2d_t_comp_dd_array_o_cl; + float_like [[]] SampleCmpGrad(in float<3> x, in float compareValue, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy, in int<2> o, in float clamp, out uint_only status) : tex2d_t_comp_dd_array_o_cl_s; + float_like [[]] SampleCmpLevel(in float<3> x, in float compareValue, in float lod, in int<2> o, out uint_only status); + float_like [[]] SampleCmpLevelZero(in float<3> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_comp_array_o_s; + $classT [[]] SampleLevel(in float<3> x, in float lod, in int<2> o, out uint_only status) : tex2d_t_lod_array_o_s; + $classT [[ro]] SampleBias(in float<3> x, in float bias, in int<2> o, in float clamp) : tex2d_t_bias_array_o_cl; + $classT [[]] SampleBias(in float<3> x, in float bias, in int<2> o, in float clamp, out uint_only status) : tex2d_t_bias_array_o_cl_s; + $classT [[ro]] SampleGrad(in float<3> x, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy, in int<2> o, in float clamp) : tex2d_t_dd_array_o_cl; + $classT [[]] SampleGrad(in float<3> x, in $match<2, 2> float<2> ddx, in $match<2, 2> float<2> ddy, in int<2> o, in float clamp, out uint_only status) : tex2d_t_dd_array_o_cl_s; + $match<0, -1> void<4> [[]] Gather(in float<3> x, in int<2> o, out uint_only status) : tex2d_t_gather_array_o_s; + $match<0, -1> void<4> [[]] GatherRed(in float<3> x, in int<2> o, out uint_only status) : tex2d_t_gather_red_array_o_s; + $match<0, -1> void<4> [[]] GatherRed(in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_red_array_o4_s; + $match<0, -1> void<4> [[]] GatherGreen(in float<3> x, in int<2> o, out uint_only status) : tex2d_t_gather_green_array_o_s; + $match<0, -1> void<4> [[]] GatherGreen(in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_green_array_o4_s; + $match<0, -1> void<4> [[]] GatherBlue(in float<3> x, in int<2> o, out uint_only status) : tex2d_t_gather_blue_array_o_s; + $match<0, -1> void<4> [[]] GatherBlue(in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_blue_array_o4_s; + $match<0, -1> void<4> [[]] GatherAlpha(in float<3> x, in int<2> o, out uint_only status) : tex2d_t_gather_alpha_array_o_s; + $match<0, -1> void<4> [[]] GatherAlpha(in float<3> x, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_alpha_array_o4_s; + $match<0, -1> void<4> [[]] GatherCmp(in float<3> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_array_o_s; + $match<0, -1> void<4> [[]] GatherCmpRed(in float<3> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_red_array_o_s; + $match<0, -1> void<4> [[]] GatherCmpGreen(in float<3> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_green_array_o_s; + $match<0, -1> void<4> [[]] GatherCmpBlue(in float<3> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_blue_array_o_s; + $match<0, -1> void<4> [[]] GatherCmpAlpha(in float<3> x, in float compareValue, in int<2> o, out uint_only status) : tex2d_t_gather_comp_alpha_array_o_s; + $match<0, -1> void<4> [[]] GatherCmpRed(in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_red_array_o4_s; + $match<0, -1> void<4> [[]] GatherCmpGreen(in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_green_array_o4_s; + $match<0, -1> void<4> [[]] GatherCmpBlue(in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_blue_array_o4_s; + $match<0, -1> void<4> [[]] GatherCmpAlpha(in float<3> x, in float compareValue, in int<2> o1, in int<2> o2, in int<2> o3, in int<2> o4, out uint_only status) : tex2d_t_gather_comp_alpha_array_o4_s; + $match<0, -1> void<4> [[ro]] GatherRaw(in float<3> x); + $match<0, -1> void<4> [[ro]] GatherRaw(in float<3> x, in int<2> o); + $match<0, -1> void<4> [[]] GatherRaw(in float<3> x, in int<2> o, out uint_only status); +} namespace + +namespace VkSampledTexture2DMSMethods { + void [[]] GetDimensions(out uint_only width, out $type1 height, out $type2 samples) : resinfo_uint_o; + void [[]] GetDimensions(out float_like width, out $type1 height, out $type2 samples) : resinfo_o; + float_like<2> [[ro]] GetSamplePosition(in int s) : samplepos; + $classT [[]] Load(in int<2> x, in int s) : texture2d_ms; + $classT [[]] Load(in int<2> x, in int s, in int<2> o) : texture2d_ms_o; + $classT [[]] Load(in int<2> x, in int s, in int<2> o, out uint_only status) : texture2d_ms_o_s; +} namespace + +namespace VkSampledTexture2DMSArrayMethods { + void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 elements, out $type1 samples) : resinfo_uint_o; + void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 elements, out $type1 samples) : resinfo_o; + float_like<2> [[ro]] GetSamplePosition(in int s) : samplepos; + $classT [[ro]] Load(in int<3> x, in int s) : texture2darray_ms; + $classT [[ro]] Load(in int<3> x, in int s, in int<2> o) : texture2darray_ms_o; + $classT [[]] Load(in int<3> x, in int s, in int<2> o, out uint_only status) : texture2darray_ms_o_s; +} namespace + +namespace VkSampledTexture3DMethods { + +float [[ro]] CalculateLevelOfDetail(in float<3> x) : tex3d_t_calc_lod; +float [[ro]] CalculateLevelOfDetailUnclamped(in float<3> x) : tex3d_t_calc_lod_unclamped; +void [[]] GetDimensions(in uint x, out uint_only width, out $type2 height, out $type2 depth, out $type2 levels) : resinfo_uint; +void [[]] GetDimensions(in uint x, out float_like width, out $type2 height, out $type2 depth, out $type2 levels) : resinfo; +void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 depth) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 depth) : resinfo_o; +$classT [[ro]] Load(in int<4> x) : tex3d_t_load; +$classT [[ro]] Load(in int<4> x, in int<3> o) : tex3d_t_load_o; +$classT [[]] Load(in int<4> x, in int<3> o, out uint_only status) : tex3d_t_load_o_s; +$classT [[ro]] Sample(in float<3> x) : tex3d_t; +$classT [[ro]] Sample(in float<3> x, in int<3> o) : tex3d_t_o; +$classT [[ro]] SampleBias(in float<3> x, in float bias) : tex3d_t_bias; +$classT [[ro]] SampleBias(in float<3> x, in float bias, in int<3> o) : tex3d_t_bias_o; +$classT [[ro]] SampleGrad(in float<3> x, in $type1 ddx, in $type1 ddy) : tex3d_t_dd; +$classT [[ro]] SampleGrad(in float<3> x, in $type1 ddx, in $type1 ddy, in int<3> o) : tex3d_t_dd_o; +$classT [[ro]] SampleLevel(in float<3> x, in float lod) : tex3d_t_lod; +$classT [[ro]] SampleLevel(in float<3> x, in float lod, in int<3> o) : tex3d_t_lod_o; +$classT [[ro]] Sample(in float<3> x, in int<3> o, in float clamp) : tex3d_t_o_cl; +$classT [[]] Sample(in float<3> x, in int<3> o, in float clamp, out uint_only status) : tex3d_t_o_cl_s; +$classT [[]] SampleLevel(in float<3> x, in float lod, in int<3> o, out uint_only status) : tex3d_t_lod_o_s; +$classT [[ro]] SampleBias(in float<3> x, in float bias, in int<3> o, in float clamp) : tex3d_t_bias_o_cl; +$classT [[]] SampleBias(in float<3> x, in float bias, in int<3> o, in float clamp, out uint_only status) : tex3d_t_bias_o_cl_s; +$classT [[]] SampleGrad(in float<3> x, in $type1 ddx, in $type1 ddy, in int<3> o, in float clamp) : tex3d_t_dd_o_cl; +$classT [[]] SampleGrad(in float<3> x, in $type1 ddx, in $type1 ddy, in int<3> o, in float clamp, out uint_only status) : tex3d_t_dd_o_cl_s; +} namespace + + + +namespace VkSampledTextureCUBEMethods { + +float [[ro]] CalculateLevelOfDetail(in float<3> x) : texcube_t_calc_lod; +float [[ro]] CalculateLevelOfDetailUnclamped(in float<3> x) : texcube_t_calc_lod_unclamped; +$match<0, -1> void<4> [[ro]] Gather(in float<3> x) : texcube_t_gather; +$match<0, -1> void<4> [[ro]] GatherAlpha(in float<3> x) : texcube_t_gather_alpha; +$match<0, -1> void<4> [[ro]] GatherBlue(in float<3> x) : texcube_t_gather_blue; +$match<0, -1> void<4> [[ro]] GatherCmp(in float<3> x, in float compareValue) : texcube_t_gather_comp; +$match<0, -1> void<4> [[ro]] GatherCmpAlpha(in float<3> x, in float compareValue) : texcube_t_gather_comp_alpha; +$match<0, -1> void<4> [[ro]] GatherCmpBlue(in float<3> x, in float compareValue) : texcube_t_gather_comp_blue; +$match<0, -1> void<4> [[ro]] GatherCmpGreen(in float<3> x, in float compareValue) : texcube_t_gather_comp_green; +$match<0, -1> void<4> [[ro]] GatherCmpRed(in float<3> x, in float compareValue) : texcube_t_gather_comp_red; +$match<0, -1> void<4> [[ro]] GatherGreen(in float<3> x) : texcube_t_gather_green; +$match<0, -1> void<4> [[ro]] GatherRed(in float<3> x) : texcube_t_gather_red; +void [[]] GetDimensions(in uint x, out uint_only width, out $type2 height, out $type2 levels) : resinfo_uint; +void [[]] GetDimensions(in uint x, out float_like width, out $type2 height, out $type2 levels) : resinfo; +void [[]] GetDimensions(out uint_only width, out $type1 height) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height) : resinfo_o; +$classT [[ro]] Sample(in float<3> x) : texcube_t; +$classT [[ro]] SampleBias(in float<3> x, in float bias) : texcube_t_bias; +float_like [[ro]] SampleCmp(in float<3> x, in float c) : texcube_t_comp; +float_like [[ro]] SampleCmpBias(in float<3> x, in float compareValue, in float bias) : texcube_t_comp_bias; +float_like [[ro]] SampleCmpGrad(in float<3> x, in float compareValue, in $match<1, 1> float<3> ddx, in $match<1, 1> float<3> ddy) : texcube_t_comp_dd; +float_like [[ro]] SampleCmpLevel(in float<3> x, in float c, in float lod); +float_like [[ro]] SampleCmpLevelZero(in float<3> x, in float c) : texcube_t_comp_lz; +$classT [[ro]] SampleGrad(in float<3> x, in $match<1, 1> float<3> ddx, in $match<1, 1> float<3> ddy) : texcube_t_dd; +$classT [[ro]] SampleLevel(in float<3> x, in float lod) : texcube_t_lod; +$classT [[ro]] Sample(in float<3> x, in float clamp) : texcube_t_cl; +$classT [[]] Sample(in float<3> x, in float clamp, out uint_only status) : texcube_t_cl_s; +float_like [[ro]] SampleCmp(in float<3> x, in float compareValue, in float clamp) : texcube_t_comp_cl; +float_like [[]] SampleCmp(in float<3> x, in float compareValue, in float clamp, out uint_only status) : texcube_t_comp_cl_s; +float_like [[ro]] SampleCmpBias(in float<3> x, in float compareValue, in float bias, in float clamp) : texcube_t_comp_bias_cl; +float_like [[]] SampleCmpBias(in float<3> x, in float compareValue, in float bias, in float clamp, out uint_only status) : texcube_t_comp_bias_cl_s; +float_like [[ro]] SampleCmpGrad(in float<3> x, in float compareValue, in $match<1, 1> float<3> ddx, in $match<1, 1> float<3> ddy, in float clamp) : texcube_t_comp_dd_o_cl; +float_like [[]] SampleCmpGrad(in float<3> x, in float compareValue, in $match<1, 1> float<3> ddx, in $match<1, 1> float<3> ddy, in float clamp, out uint_only status) : texcube_t_comp_dd_o_cl_s; +float_like [[]] SampleCmpLevel(in float<3> x, in float compareValue, in float lod, out uint_only status); +float_like [[]] SampleCmpLevelZero(in float<3> x, in float compareValue, out uint_only status) : texcube_t_comp_s; +$classT [[]] SampleLevel(in float<3> x, in float lod, out uint_only status) : texcube_t_lod_s; +$classT [[ro]] SampleBias(in float<3> x, in float bias, in float clamp) : texcube_t_bias_cl; +$classT [[]] SampleBias(in float<3> x, in float bias, in float clamp, out uint_only status) : texcube_t_bias_cl_s; +$classT [[ro]] SampleGrad(in float<3> x, in $match<1, 1> float<3> ddx, in $match<1, 1> float<3> ddy, in float clamp) : texcube_t_dd_cl; +$classT [[]] SampleGrad(in float<3> x, in $match<1, 1> float<3> ddx, in $match<1, 1> float<3> ddy, in float clamp, out uint_only status) : texcube_t_dd_cl_s; +$match<0, -1> void<4> [[]] Gather(in float<3> x, out uint_only status) : texcube_t_gather_s; +$match<0, -1> void<4> [[]] GatherRed(in float<3> x, out uint_only status) : texcube_t_gather_red_s; +$match<0, -1> void<4> [[]] GatherGreen(in float<3> x, out uint_only status) : texcube_t_gather_green_s; +$match<0, -1> void<4> [[]] GatherBlue(in float<3> x, out uint_only status) : texcube_t_gather_blue_s; +$match<0, -1> void<4> [[]] GatherAlpha(in float<3> x, out uint_only status) : texcube_t_gather_alpha_s; +$match<0, -1> void<4> [[]] GatherCmp(in float<3> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_s; +$match<0, -1> void<4> [[]] GatherCmpRed(in float<3> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_red_s; +$match<0, -1> void<4> [[]] GatherCmpGreen(in float<3> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_green_s; +$match<0, -1> void<4> [[]] GatherCmpBlue(in float<3> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_blue_s; +$match<0, -1> void<4> [[]] GatherCmpAlpha(in float<3> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_alpha_s; +} namespace + +namespace VkSampledTextureCUBEArrayMethods { + +float [[ro]] CalculateLevelOfDetail(in float<3> x) : texcube_t_calc_lod_array; +float [[ro]] CalculateLevelOfDetailUnclamped(in float<3> x) : texcube_t_calc_lod_unclamped_array; +$match<0, -1> void<4> [[ro]] Gather(in float<4> x) : texcube_t_gather_array; +$match<0, -1> void<4> [[ro]] GatherAlpha(in float<4> x) : texcube_t_gather_alpha_array; +$match<0, -1> void<4> [[ro]] GatherBlue(in float<4> x) : texcube_t_gather_blue_array; +$match<0, -1> void<4> [[ro]] GatherCmp(in float<4> x, in float compareValue) : texcube_t_gather_comp_array; +$match<0, -1> void<4> [[ro]] GatherCmpAlpha(in float<4> x, in float compareValue) : texcube_t_gather_comp_alpha_array; +$match<0, -1> void<4> [[ro]] GatherCmpBlue(in float<4> x, in float compareValue) : texcube_t_gather_comp_blue_array; +$match<0, -1> void<4> [[ro]] GatherCmpGreen(in float<4> x, in float compareValue) : texcube_t_gather_comp_green_array; +$match<0, -1> void<4> [[ro]] GatherCmpRed(in float<4> x, in float compareValue) : texcube_t_gather_comp_red_array; +$match<0, -1> void<4> [[ro]] GatherGreen(in float<4> x) : texcube_t_gather_green_array; +$match<0, -1> void<4> [[ro]] GatherRed(in float<4> x) : texcube_t_gather_red_array; +void [[]] GetDimensions(in uint x, out uint_only width, out $type2 height, out $type2 elements, out $type2 levels) : resinfo_uint; +void [[]] GetDimensions(in uint x, out float_like width, out $type2 height, out $type2 elements, out $type2 levels) : resinfo; +void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 elements) : resinfo_uint_o; +void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 elements) : resinfo_o; +$classT [[ro]] Sample(in float<4> x) : texcube_t_array; +$classT [[ro]] SampleBias(in float<4> x, in float bias) : texcube_t_bias_array; +float_like [[ro]] SampleCmp(in float<4> x, in float c) : texcube_t_comp_array; +float_like [[ro]] SampleCmpBias(in float<4> x, in float compareValue, in float bias) : texcube_t_comp_bias_array; +float_like [[ro]] SampleCmpLevel(in float<4> x, in float c, in float lod); +float_like [[ro]] SampleCmpLevelZero(in float<4> x, in float c) : texcube_t_comp_lz_array; +$classT [[ro]] SampleGrad(in float<4> x, in $match<2, 2> float<3> ddx, in $match<2, 2> float<3> ddy) : texcube_t_dd_array; +$classT [[ro]] SampleLevel(in float<4> x, in float lod) : texcube_t_lod_array; +$classT [[ro]] Sample(in float<4> x, in float clamp) : texcube_t_array_cl; +$classT [[]] Sample(in float<4> x, in float clamp, out uint_only status) : texcube_t_array_cl_s; +float_like [[ro]] SampleCmp(in float<4> x, in float compareValue, in float clamp) : texcube_t_comp_array_cl; +float_like [[]] SampleCmp(in float<4> x, in float compareValue, in float clamp, out uint_only status) : texcube_t_comp_array_cl_s; +float_like [[ro]] SampleCmpBias(in float<4> x, in float compareValue, in float bias, in float clamp) : texcube_t_comp_bias_array_cl; +float_like [[]] SampleCmpBias(in float<4> x, in float compareValue, in float bias, in float clamp, out uint_only status) : texcube_t_comp_bias_array_cl_s; +float_like [[]] SampleCmpLevel(in float<4> x, in float compareValue, in float lod, out uint_only status); +float_like [[]] SampleCmpLevelZero(in float<4> x, in float compareValue, out uint_only status) : texcube_t_comp_array_s; +$classT [[]] SampleLevel(in float<4> x, in float lod, out uint_only status) : texcube_t_lod_array_s; +$classT [[ro]] SampleBias(in float<4> x, in float bias, in float clamp) : texcube_t_bias_array_cl; +$classT [[]] SampleBias(in float<4> x, in float bias, in float clamp, out uint_only status) : texcube_t_bias_array_cl_s; +$classT [[ro]] SampleGrad(in float<4> x, in $match<2, 2> float<3> ddx, in $match<2, 2> float<3> ddy, in float clamp) : texcube_t_dd_array_cl; +$classT [[]] SampleGrad(in float<4> x, in $match<2, 2> float<3> ddx, in $match<2, 2> float<3> ddy, in float clamp, out uint_only status) : texcube_t_dd_array_cl_s; +$match<0, -1> void<4> [[]] Gather(in float<4> x, out uint_only status) : texcube_t_gather_array_s; +$match<0, -1> void<4> [[]] GatherRed(in float<4> x, out uint_only status) : texcube_t_gather_red_array_s; +$match<0, -1> void<4> [[]] GatherGreen(in float<4> x, out uint_only status) : texcube_t_gather_green_array_s; +$match<0, -1> void<4> [[]] GatherBlue(in float<4> x, out uint_only status) : texcube_t_gather_blue_array_s; +$match<0, -1> void<4> [[]] GatherAlpha(in float<4> x, out uint_only status) : texcube_t_gather_alpha_array_s; +$match<0, -1> void<4> [[]] GatherCmp(in float<4> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_array_s; +$match<0, -1> void<4> [[]] GatherCmpRed(in float<4> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_red_array_s; +$match<0, -1> void<4> [[]] GatherCmpGreen(in float<4> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_green_array_s; +$match<0, -1> void<4> [[]] GatherCmpBlue(in float<4> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_blue_array_s; +$match<0, -1> void<4> [[]] GatherCmpAlpha(in float<4> x, in float compareValue, out uint_only status) : texcube_t_gather_comp_alpha_array_s; +} namespace + + +// SPIRV Change Ends