dxil: write [WaveSize] to the entry, PSV and RDAT
[WaveSize] was checked but not written: the entry properties had no wave
size, so a shader written for one wave size could run with another.
DXC writes tag 11 { size } before SM 6.8 and tag 23 { min, max,
preferred } from 6.8; PSV's and RDAT's expected wave lane counts take
the minimum and the maximum (or the minimum again).
Unreal: 44 of the 2,080 verify compiles use WaveSize and change; all
11,488 validate (validator 1.8).
This commit is contained in:
parent
cedf1b46e9
commit
285505e36b
|
|
@ -6783,6 +6783,9 @@ const Emitter = struct {
|
|||
.feature_info2 = @truncate(libinfo.featureInfo(info.flags) >> 32),
|
||||
.shader_stage_flag = if (lf.stage == .library) info.mask & 0xffff else info.mask & (@as(u32, 1) << @intCast(kind)),
|
||||
.min_shader_target = (kind << 16) | (6 << 4) | libinfo.minMinor(info, if (lf.stage == .library) null else kind),
|
||||
// (RDAT: 0 where none is specified.)
|
||||
.min_wave_lanes = @intCast(lf.entry.wave_size[0]),
|
||||
.max_wave_lanes = @intCast(if (lf.entry.wave_size[1] != 0) lf.entry.wave_size[1] else lf.entry.wave_size[0]),
|
||||
.extended_properties = props,
|
||||
});
|
||||
}
|
||||
|
|
@ -6838,6 +6841,14 @@ const Emitter = struct {
|
|||
});
|
||||
}
|
||||
|
||||
/// The wave lane counts PSV and RDAT give: WaveSize's minimum, and its
|
||||
/// maximum (a range) or the minimum again; with none, 0 and maxInt.
|
||||
fn waveLanes(entry: ir.Entry) [2]u32 {
|
||||
const ws = entry.wave_size;
|
||||
if (ws[0] == 0) return .{ 0, std.math.maxInt(u32) };
|
||||
return .{ ws[0], if (ws[1] != 0) ws[1] else ws[0] };
|
||||
}
|
||||
|
||||
/// Entry properties of the stage: thread group size and the GS / HS /
|
||||
/// DS / MS / AS state.
|
||||
fn stageProps(e: *Emitter, entry: ir.Entry, props: *std.ArrayList(?module.MdId)) Error!void {
|
||||
|
|
@ -6849,6 +6860,14 @@ const Emitter = struct {
|
|||
}.f;
|
||||
const threads = try dm.mdNode(&.{ try mdI32(dm, entry.num_threads[0]), try mdI32(dm, entry.num_threads[1]), try mdI32(dm, entry.num_threads[2]) });
|
||||
if (entry.stage == .compute) try props.appendSlice(e.arena, &.{ try mdI32(dm, 4), threads });
|
||||
// WaveSize: a value (tag 11) before SM 6.8, a range with a
|
||||
// preferred size after (tag 23; zeros where not given).
|
||||
if (entry.wave_size[0] != 0) {
|
||||
const ws = entry.wave_size;
|
||||
if (e.profile.minor >= 8) {
|
||||
try props.appendSlice(e.arena, &.{ try mdI32(dm, 23), try dm.mdNode(&.{ try mdI32(dm, ws[0]), try mdI32(dm, ws[1]), try mdI32(dm, ws[2]) }) });
|
||||
} else try props.appendSlice(e.arena, &.{ try mdI32(dm, 11), try dm.mdNode(&.{try mdI32(dm, ws[0])}) });
|
||||
}
|
||||
const payload_size: u32 = if (entry.mesh.payload) |p| try e.payloadSize(p) else 0;
|
||||
if (entry.stage == .mesh) {
|
||||
// MS state: thread group, max vertices, max primitives,
|
||||
|
|
@ -7064,6 +7083,7 @@ const Emitter = struct {
|
|||
.entry = entry.name,
|
||||
.stage_info = stage_info,
|
||||
.num_threads = if (threaded) entry.num_threads else .{ 0, 0, 0 },
|
||||
.wave_lanes = waveLanes(entry),
|
||||
.mesh_topology = if (entry.stage == .mesh) @backingInt(entry.mesh.topology) else 0,
|
||||
.uses_view_id = e.uses_view_id,
|
||||
.resources = binds.items,
|
||||
|
|
|
|||
|
|
@ -143,6 +143,8 @@ pub const PsvInfo = struct {
|
|||
/// The stage-specific PSVRuntimeInfo0 union.
|
||||
stage_info: [16]u8 = @splat(0),
|
||||
num_threads: [3]u32 = .{ 0, 0, 0 },
|
||||
/// Minimum and maximum expected wave lane counts (WaveSize).
|
||||
wave_lanes: [2]u32 = .{ 0, 0xFFFFFFFF },
|
||||
resources: []const ResourceBind = &.{},
|
||||
inputs: []const signature.Element = &.{},
|
||||
outputs: []const signature.Element = &.{},
|
||||
|
|
@ -172,8 +174,8 @@ pub fn psv(gpa: Allocator, info: PsvInfo) ![]u8 {
|
|||
try w(&buf, gpa, 60); // sizeof(PSVRuntimeInfo4)
|
||||
// PSVRuntimeInfo0
|
||||
try buf.appendSlice(gpa, &info.stage_info);
|
||||
try w(&buf, gpa, 0); // MinimumExpectedWaveLaneCount
|
||||
try w(&buf, gpa, 0xFFFFFFFF); // MaximumExpectedWaveLaneCount
|
||||
try w(&buf, gpa, info.wave_lanes[0]); // MinimumExpectedWaveLaneCount
|
||||
try w(&buf, gpa, info.wave_lanes[1]); // MaximumExpectedWaveLaneCount
|
||||
// PSVRuntimeInfo1: stage, UsesViewID, MaxVertexCount, element counts,
|
||||
// vector counts.
|
||||
// (The MaxVertexCount union holds SigPatchConstOrPrimVectors for hull
|
||||
|
|
@ -221,7 +223,7 @@ pub fn psv(gpa: Allocator, info: PsvInfo) ![]u8 {
|
|||
try w(&records, gpa, idx_off);
|
||||
var cols_and_start: u8 = @intCast(e.cols);
|
||||
if (e.start_row != null) cols_and_start |= 0x40 | @as(u8, @intCast(e.start_col << 4));
|
||||
try records.appendSlice(gpa, &.{ @intCast(e.rows), @intCast(e.start_row orelse 0), cols_and_start, @intFromEnum(e.kind), @intCast(e.comp.sigCompType()), @intFromEnum(e.interp), @intCast((e.stream & 3) << 4), 0 });
|
||||
try records.appendSlice(gpa, &.{ @intCast(e.rows), @intCast(e.start_row orelse 0), cols_and_start, @backingInt(e.kind), @intCast(e.comp.sigCompType()), @backingInt(e.interp), @intCast((e.stream & 3) << 4), 0 });
|
||||
};
|
||||
const entry_off: u32 = @intCast(strings.items.len);
|
||||
try strings.appendSlice(gpa, info.entry);
|
||||
|
|
|
|||
|
|
@ -436,6 +436,9 @@ pub const Entry = struct {
|
|||
name: []const u8,
|
||||
stage: Stage,
|
||||
num_threads: [3]u32 = .{ 1, 1, 1 },
|
||||
/// `[WaveSize(min[, max[, preferred]])]`: zeros where not given (no
|
||||
/// attribute: min 0).
|
||||
wave_size: [3]u32 = .{ 0, 0, 0 },
|
||||
geometry: GeometryInfo = .{},
|
||||
tess: TessInfo = .{},
|
||||
mesh: MeshInfo = .{},
|
||||
|
|
|
|||
|
|
@ -2429,6 +2429,9 @@ const Lowerer = struct {
|
|||
if (std.ascii.eqlIgnoreCase(a.name, "numthreads") and a.args.len == 3) {
|
||||
for (a.args, 0..) |arg, i| entry.num_threads[i] = @intCast(@max(1, l.s.evalInt(arg) orelse 1));
|
||||
}
|
||||
if (std.ascii.eqlIgnoreCase(a.name, "wavesize") and a.args.len >= 1 and a.args.len <= 3) {
|
||||
for (a.args, 0..) |arg, i| entry.wave_size[i] = @intCast(@max(0, l.s.evalInt(arg) orelse 0));
|
||||
}
|
||||
if (std.ascii.eqlIgnoreCase(a.name, "maxvertexcount") and a.args.len == 1) entry.geometry.max_vertex_count = @intCast(@max(1, l.s.evalInt(a.args[0]) orelse 1));
|
||||
if (std.ascii.eqlIgnoreCase(a.name, "instance") and a.args.len == 1) entry.geometry.instance_count = @intCast(@max(1, l.s.evalInt(a.args[0]) orelse 1));
|
||||
if (std.ascii.eqlIgnoreCase(a.name, "RootSignature") and a.args.len == 1 and a.args[0].kind == .string_lit) entry.root_signature = try stringContents(l.arena, a.args[0].kind.string_lit);
|
||||
|
|
@ -2748,7 +2751,6 @@ pub fn isObject(t: *TypeTable, ty: TypeId) bool {
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
fn semanticOf(sems: []const ast.Semantic) ?[]const u8 {
|
||||
for (sems) |sem| if (sem.kind == .semantic) return sem.values[0];
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue