sema: a vector size shared by intrinsic arguments takes the widest
`dot(1, v)` bound dot's `numeric<c>` size from its first argument, a scalar: c = 1, and v converted to a float (its x). dxc splats the scalar to v's size instead, and so does zdxc now, for every intrinsic whose arguments share a symbolic size (dot, distance, reflect, faceforward...). Unreal decodes every instance's rotation with `dot(1, abs(Oct))` (HemiOctahedronToUnitVector): StarterMap's beams were drawn rotated, or not where they belong. 3,666 of Unreal's 11,488 compiles change.
This commit is contained in:
parent
987b2a573c
commit
24bdbfe7e9
|
|
@ -254,6 +254,44 @@ fn matchOne(sema: anytype, it: *const table.Intrinsic, object: ?TypeId, args: []
|
||||||
}
|
}
|
||||||
|
|
||||||
var bindings: Bindings = .{};
|
var bindings: Bindings = .{};
|
||||||
|
// A vector size (`c` of `numeric<c>`) shared by several arguments takes
|
||||||
|
// the widest of them, scalars splatting to it, as in dxc: `dot(1, v)`
|
||||||
|
// is a dot product of v's size, not v truncated to a scalar.
|
||||||
|
{
|
||||||
|
var syms: [8][]const u8 = undefined;
|
||||||
|
var widest: [8]u16 = undefined;
|
||||||
|
var ok: [8]bool = undefined;
|
||||||
|
var ns: usize = 0;
|
||||||
|
for (args[0..it.params.len], 1..) |a, i| {
|
||||||
|
const ls = if (specs[i].dims.len > 0) specs[i] else specs[layout_group[i]];
|
||||||
|
if (ls.any_layout or ls.dims.len != 1) continue;
|
||||||
|
const sym = ls.dims[0];
|
||||||
|
if (std.fmt.parseInt(u16, sym, 10)) |_| continue else |_| {}
|
||||||
|
const sh = t.shape(a.ty) orelse continue;
|
||||||
|
const len: u16 = switch (sh.kind) {
|
||||||
|
.scalar => 1,
|
||||||
|
.vector => sh.cols,
|
||||||
|
else => continue,
|
||||||
|
};
|
||||||
|
const k = for (syms[0..ns], 0..) |s, j| {
|
||||||
|
if (std.mem.eql(u8, s, sym)) break j;
|
||||||
|
} else blk: {
|
||||||
|
if (ns == syms.len) break :blk null;
|
||||||
|
syms[ns] = sym;
|
||||||
|
widest[ns] = len;
|
||||||
|
ok[ns] = true;
|
||||||
|
ns += 1;
|
||||||
|
break :blk ns - 1;
|
||||||
|
} orelse continue;
|
||||||
|
// (Vectors of two different sizes: left to the usual binding,
|
||||||
|
// which converts to the first.)
|
||||||
|
if (len != 1 and widest[k] != 1 and len != widest[k]) ok[k] = false;
|
||||||
|
widest[k] = @max(widest[k], len);
|
||||||
|
}
|
||||||
|
for (syms[0..ns], widest[0..ns], ok[0..ns]) |s, w, good| if (good and w > 1) {
|
||||||
|
_ = bindings.bind(s, w);
|
||||||
|
};
|
||||||
|
}
|
||||||
for (args[0..it.params.len], 1..) |a, i| {
|
for (args[0..it.params.len], 1..) |a, i| {
|
||||||
// (Also arguments whose layout links to a `<>` one.)
|
// (Also arguments whose layout links to a `<>` one.)
|
||||||
if (!specs[i].any_layout and !specs[layout_group[i]].any_layout) continue;
|
if (!specs[i].any_layout and !specs[layout_group[i]].any_layout) continue;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue