CGBJ's renderer, DLSS, an F1 settings menu, frame generation, ray tracing switch
The default of scripts\play-nvidia.ps1 changes: the game renders its own 720p and DLSS takes it to 1080p (Series S), in place of the half render scale and the title's upscaler. -Resolution still reaches the older path. - Renderer: codec-d/cool_fox f4b48ad (GPL-3.0) with this fork's NVIDIA fixes on top (residency.rs, stretch.rs, the ffx upscale dispatch). - DLSS for the title's upscale, from avatarmanz/VIctory-7900XTX pull request 203 (feature `dlss`, VICTORY_UPSCALE=dlss), with VICTORY_DLSS_PRESET and a live sharpness setting. - F1 settings menu in the game (host/menu.rs): saved to victory-settings.txt, applied by the launcher at the next start, "save and restart" from the menu. F3: the panel, now with the generated frame rate beside the real one. - DLSS frame generation through NVIDIA Streamline (streamline.rs, fg.rs), 2x to 6x, the amount changed while playing. Constants and the depth and motion vector tags are handed over at each present. - VICTORY_FPS_CAP: the title's own 30 frames a second can be lifted (60, 120, none), live from the menu. - Real ray tracing as an option (-RayTracing, VICTORY_BVH_BUILDER=1): on this renderer the structure builder runs on NVIDIA. Frame generation is left off with it: the two together run at about 0.1 fps, cause not found. - VICTORY_HEAP_RECHECK_EVERY: textures picked by index looked at again for the whole run (a test against the posterized look). - Get-NVIDIA-DLSS.cmd / scripts\get-nvidia-sdks.ps1: fetch the few NVIDIA files DLSS and frame generation need (about 70 MB) from NVIDIA's GitHub into nvidia-sdk\ (git-ignored). They are NVIDIA's, under NVIDIA's licences, and are not part of this repository. Without them the picture is stretched and there is no frame generation. - scripts\build-nvidia.ps1; the launcher builds the layer when it is not built, and again with DLSS once those files are there. Measured on an RTX 5070 (Series S, DLSS, opening rooms): about 15-17 fps without ray tracing, 13-15 with it, before generated frames. What is known to be wrong is in the README's new section. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
1 parent
9e7ab9d9a2
commit
63957271cd
55 files changed
+8030
-1313
No files matched your search
@@ -181,7 +181,6 @@ fn build_cs(body: &[u32], threads: u32, lds_bytes: u32) -> HostShader {
|
||||
root_srvs: lowered.root_srvs,
|
||||
root_uavs: lowered.root_uavs,
|
||||
root_indexed_views: res.root_indexed_views,
|
||||
half_views: lowered.half_views,
|
||||
};
|
||||
|
||||
if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) {
|
||||
@@ -1919,7 +1918,6 @@ fn whole_wave_f64_sum_and_cvt_f32_f64() {
|
||||
root_srvs: lowered.root_srvs,
|
||||
root_uavs: lowered.root_uavs,
|
||||
root_indexed_views: Vec::new(),
|
||||
half_views: lowered.half_views,
|
||||
};
|
||||
if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) {
|
||||
let mut copy = shader.dxil.clone();
|
||||
@@ -2060,76 +2058,48 @@ fn rdna_forms_give_what_the_spelled_out_ones_give() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A program that moves a typed buffer's 16-bit channels
|
||||
/// (`buffer_load_format_d16_xyzw` from the table's first view,
|
||||
/// `buffer_store_format_d16_xyzw` to its second) names both places for the
|
||||
/// host (`HostShader::half_views`) and moves every pattern as it is through
|
||||
/// unsigned views: half floats, the not-a-number ones among them, and
|
||||
/// plain 16-bit integers (the title keeps both in such buffers; the
|
||||
/// network that moves its faces reads indices this way). A program that
|
||||
/// moves no halves names nothing.
|
||||
#[test]
|
||||
fn halves_go_through_a_table_as_they_are_and_name_their_views() {
|
||||
use super::host::Stride;
|
||||
use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R16G16B16A16_UINT;
|
||||
/// MUBUF `op vdata, vaddr, s[srsrc:srsrc+3], 0 idxen`.
|
||||
const fn mubuf_idxen(op: u32, vdata: u8, vaddr: u8, srsrc: u8) -> [u32; 2] {
|
||||
[
|
||||
0x38 << 26 | op << 18 | 1 << 13,
|
||||
0x80 << 24 | ((srsrc as u32 >> 2) & 0x1F) << 16 | (vdata as u32) << 8 | vaddr as u32,
|
||||
]
|
||||
}
|
||||
const LOAD_D16_XYZW: u32 = 0x83;
|
||||
const STORE_D16_XYZW: u32 = 0x87;
|
||||
const THREADS: u32 = 32;
|
||||
// The table's second descriptor, 0x20 bytes on.
|
||||
let mut second = s_load_dwordx4(12, 4);
|
||||
second[1] |= 0x20;
|
||||
let mut words = vec![s_mov_b32(5, 0x80)];
|
||||
words.extend_from_slice(&s_load_dwordx4(8, 4));
|
||||
words.extend_from_slice(&second);
|
||||
// v[1:2] = first[thread] (four halves), second[thread] = v[1:2].
|
||||
words.extend_from_slice(&mubuf_idxen(LOAD_D16_XYZW, 1, 0, 8));
|
||||
words.extend_from_slice(&mubuf_idxen(STORE_D16_XYZW, 1, 0, 12));
|
||||
/// MUBUF `op vdata, vaddr, s[srsrc:srsrc+3], 0 idxen`.
|
||||
const fn mubuf_idxen(op: u8, vdata: u8, vaddr: u8, srsrc: u8) -> [u32; 2] {
|
||||
[
|
||||
0x38 << 26 | (op as u32) << 18 | 1 << 13,
|
||||
0x80 << 24 | ((srsrc as u32 >> 2) & 0x1F) << 16 | (vdata as u32) << 8 | vaddr as u32,
|
||||
]
|
||||
}
|
||||
|
||||
/// SMEM `s_load_dwordx4 s[dst:dst+3], s[base:base+1], byte_offset` (soffset = null).
|
||||
const fn s_load_dwordx4_off(dst: u8, base: u8, byte_offset: u32) -> [u32; 2] {
|
||||
[
|
||||
0x3D << 26 | 0x02 << 18 | (dst as u32) << 6 | (base as u32 >> 1),
|
||||
(125 << 25) | (byte_offset & 0x1F_FFFF),
|
||||
]
|
||||
}
|
||||
|
||||
/// Builds a compute shader whose descriptors live in a `RootType::Table` at
|
||||
/// `s4` (like `compute_graph_ops` and `ped_standard_head_cs`).
|
||||
fn build_table_typed_cs(body: &[u32], used: Vec<UsedResource>) -> HostShader {
|
||||
let mut words = Vec::new();
|
||||
words.push(s_mov_b32(5, 0x80)); // s5 = 0
|
||||
words.extend_from_slice(body);
|
||||
words.push(S_ENDPGM);
|
||||
let view = |kind: ResourceType, table_offset_dwords: u32| UsedResource {
|
||||
kind,
|
||||
root: RootType::Table,
|
||||
table_offset_dwords,
|
||||
lower_bound: table_offset_dwords / 8,
|
||||
stride: 4,
|
||||
dwords: 4,
|
||||
user_data: 4,
|
||||
slot: 1,
|
||||
};
|
||||
let code: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect();
|
||||
let native = NativeProgram {
|
||||
stage: HwStage::Cs,
|
||||
wave64: false,
|
||||
vgprs: 8,
|
||||
layout: vec![
|
||||
RootParam {
|
||||
root: RootType::Constants,
|
||||
table_offset_dwords: 0,
|
||||
sgprs: 4,
|
||||
base_register: 0,
|
||||
user_data: 0,
|
||||
slot: 0,
|
||||
},
|
||||
RootParam {
|
||||
root: RootType::Table,
|
||||
table_offset_dwords: 0,
|
||||
sgprs: 1,
|
||||
base_register: 0,
|
||||
user_data: 4,
|
||||
slot: 1,
|
||||
},
|
||||
],
|
||||
used: vec![view(ResourceType::Srv, 0), view(ResourceType::Uav, 8)],
|
||||
layout: vec![RootParam {
|
||||
root: RootType::Table,
|
||||
table_offset_dwords: 0,
|
||||
sgprs: 1,
|
||||
base_register: 0,
|
||||
user_data: 4,
|
||||
slot: 0,
|
||||
}],
|
||||
used,
|
||||
io: StageIo::Cs(ComputeIo {
|
||||
rsrc2: 5 << 1,
|
||||
threads: [THREADS, 1, 1],
|
||||
rsrc2: 5 << 1, // 5 user SGPRs: s0..s4
|
||||
threads: [4, 1, 1],
|
||||
}),
|
||||
code: words.iter().flat_map(|w| w.to_le_bytes()).collect(),
|
||||
code,
|
||||
};
|
||||
let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir::build");
|
||||
let st = structure::structure(&p).expect("structure");
|
||||
@@ -2148,7 +2118,6 @@ fn halves_go_through_a_table_as_they_are_and_name_their_views() {
|
||||
mesh_stride: 0,
|
||||
})
|
||||
.expect("lower");
|
||||
assert_eq!(lowered.half_views, [(1, 0), (1, 8)]);
|
||||
let shader = HostShader {
|
||||
stage: HwStage::Cs,
|
||||
dxil: lowered.dxil,
|
||||
@@ -2159,362 +2128,252 @@ fn halves_go_through_a_table_as_they_are_and_name_their_views() {
|
||||
root_srvs: lowered.root_srvs,
|
||||
root_uavs: lowered.root_uavs,
|
||||
root_indexed_views: res.root_indexed_views,
|
||||
half_views: lowered.half_views,
|
||||
};
|
||||
if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) {
|
||||
let mut dxil = shader.dxil.clone();
|
||||
v.validate(&mut dxil).expect("DXIL validation failed");
|
||||
let mut copy = shader.dxil.clone();
|
||||
v.validate(&mut copy).expect("DXIL validation failed");
|
||||
}
|
||||
// A raw store through the same table: no halves, nothing named.
|
||||
assert!(build_valu_cs(&[]).half_views.is_empty());
|
||||
|
||||
// Four halves a thread: numbers, both zeros, subnormals, infinities,
|
||||
// not-a-numbers of both signs, and integers past the largest number's
|
||||
// pattern, as indices are.
|
||||
const SPECIAL: [u16; 16] = [
|
||||
0x0000, 0x0001, 0x03ff, 0x0400, 0x3c00, 0x7bff, 0x7c00, 0x7c01, 0x7e00, 0x7fff, 0x8000,
|
||||
0x8001, 0xbc00, 0xfc00, 0xfc01, 0xffff,
|
||||
];
|
||||
let halves: Vec<u16> = (0..4 * THREADS as usize)
|
||||
.map(|i| match i {
|
||||
0..16 => SPECIAL[i],
|
||||
_ => (i as u16).wrapping_mul(0x0203).wrapping_add(0x7b00),
|
||||
})
|
||||
.collect();
|
||||
let data: Vec<u32> = halves
|
||||
.chunks(2)
|
||||
.map(|pair| u32::from(pair[0]) | u32::from(pair[1]) << 16)
|
||||
.collect();
|
||||
let _one = ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut ran = 0;
|
||||
for (label, warp) in [("hardware", false), ("warp", true)] {
|
||||
let Ok(host) = Host::new(warp) else {
|
||||
eprintln!("no SM 6.6 {label} device; skipped");
|
||||
continue;
|
||||
};
|
||||
let (root, pso) = host
|
||||
.compute_pipeline(&shader)
|
||||
.unwrap_or_else(|e| panic!("{label}: compute_pipeline failed: {e}"));
|
||||
let mut ud = vec![0u32; shader.user_data_dwords().max(1) as usize];
|
||||
for u in &shader.user_data {
|
||||
ud[u.index as usize] = match (u.root, u.slot) {
|
||||
(RootType::Table, 1) => 0,
|
||||
other => panic!("unexpected user data {other:?}"),
|
||||
};
|
||||
}
|
||||
let out = host
|
||||
.dispatch(
|
||||
&root,
|
||||
&pso,
|
||||
&Dispatch {
|
||||
roots: vec![(0, Root::Constants(ud))],
|
||||
views: &[
|
||||
View::Buffer {
|
||||
data: &data,
|
||||
stride: Stride::Format(DXGI_FORMAT_R16G16B16A16_UINT, 8),
|
||||
},
|
||||
View::HalfUintUav(THREADS),
|
||||
],
|
||||
samplers: &[],
|
||||
groups: [1, 1, 1],
|
||||
},
|
||||
)
|
||||
.unwrap_or_else(|e| panic!("{label}: dispatch failed: {e}"));
|
||||
assert_eq!(
|
||||
out[0], data,
|
||||
"{label}: the halves stored are the halves loaded"
|
||||
);
|
||||
ran += 1;
|
||||
}
|
||||
assert!(ran > 0, "no SM 6.6 device available");
|
||||
shader
|
||||
}
|
||||
|
||||
/// The places a program that moves halves names are the descriptors it
|
||||
/// loads, not the start of the range their used-resource entry describes:
|
||||
/// with one entry for a range from dword 0, a load at byte 0x20 names
|
||||
/// dword 8 (a host view there in a 16-bit float format is the one shown
|
||||
/// as its unsigned twin). A descriptor picked at run time (the load's
|
||||
/// offset in an SGPR) names nothing and keeps the float path: which slot
|
||||
/// it reads, and in which format, is known only then.
|
||||
/// `compute_graph_ops` (facial lip-sync & wrapped submesh solver) binds
|
||||
/// `R16G16B16A16_UINT` / `R16_UINT` UAVs via `RootType::Table` (which on NVIDIA
|
||||
/// are snapshotted into dynamic descriptor slots) and reads/writes FP16 bit
|
||||
/// patterns with `buffer_load_format_d16_xyzw` and `buffer_store_format_d16_xyzw`.
|
||||
/// Verify bit-exact round-trips for UINT, SINT, and FLOAT views (including
|
||||
/// non-zero table offsets matching dynamic descriptor snapshots) on hardware
|
||||
/// GPU and WARP.
|
||||
#[test]
|
||||
fn half_places_are_the_descriptors_the_program_loads() {
|
||||
/// MUBUF `op vdata, vaddr, s[srsrc:srsrc+3], 0 idxen`.
|
||||
const fn mubuf_idxen(op: u32, vdata: u8, vaddr: u8, srsrc: u8) -> [u32; 2] {
|
||||
[
|
||||
0x38 << 26 | op << 18 | 1 << 13,
|
||||
0x80 << 24 | ((srsrc as u32 >> 2) & 0x1F) << 16 | (vdata as u32) << 8 | vaddr as u32,
|
||||
]
|
||||
}
|
||||
const LOAD_D16_XYZW: u32 = 0x83;
|
||||
const STORE_D16_XYZW: u32 = 0x87;
|
||||
let lowered = |words: &[u32]| {
|
||||
let range = |kind: ResourceType, table_offset_dwords: u32| UsedResource {
|
||||
kind,
|
||||
fn typed_d16_table_uav_roundtrip_uint_sint_and_float() {
|
||||
use windows::Win32::Graphics::Dxgi::Common::{
|
||||
DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_SINT,
|
||||
DXGI_FORMAT_R16G16B16A16_UINT,
|
||||
};
|
||||
let _serial = ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut body = Vec::new();
|
||||
// s[8:11] = table[0] (src typed UAV), s[12:15] = table[1] (dst typed UAV),
|
||||
// s[16:19] = table[2] (raw UAV dump of loaded v[2:3]).
|
||||
body.extend_from_slice(&s_load_dwordx4_off(8, 4, 0));
|
||||
body.extend_from_slice(&s_load_dwordx4_off(12, 4, 32));
|
||||
body.extend_from_slice(&s_load_dwordx4_off(16, 4, 64));
|
||||
// buffer_load_format_d16_xyzw v[2:3], v0, s[8:11], 0 idxen (op 0x83)
|
||||
body.extend_from_slice(&mubuf_idxen(0x83, 2, 0, 8));
|
||||
// buffer_store_format_d16_xyzw v[2:3], v0, s[12:15], 0 idxen (op 0x87)
|
||||
body.extend_from_slice(&mubuf_idxen(0x87, 2, 0, 12));
|
||||
// Also dump thread 0's loaded v[2:3] into raw UAV (table[2]) to verify the load itself.
|
||||
// v4 = v0 << 3 (byte offset = thread * 8)
|
||||
body.push(0x3408_0083); // v_lshlrev_b32 v4, 3, v0
|
||||
// buffer_store_dwordx2 v[2:3], v4, s[16:19], 0 offen (op 0x1D, offen bit 12)
|
||||
body.extend_from_slice(&[
|
||||
0x38 << 26 | 0x1D << 18 | 1 << 12,
|
||||
0x80 << 24 | (16u32 >> 2) << 16 | (2u32 << 8) | 4u32,
|
||||
]);
|
||||
let used = (0..3u32)
|
||||
.map(|k| UsedResource {
|
||||
kind: ResourceType::Uav,
|
||||
root: RootType::Table,
|
||||
table_offset_dwords,
|
||||
lower_bound: table_offset_dwords / 8,
|
||||
table_offset_dwords: k * 8,
|
||||
lower_bound: k,
|
||||
stride: 4,
|
||||
dwords: 4,
|
||||
user_data: 4,
|
||||
slot: 1,
|
||||
};
|
||||
let native = NativeProgram {
|
||||
stage: HwStage::Cs,
|
||||
wave64: false,
|
||||
vgprs: 8,
|
||||
layout: vec![
|
||||
RootParam {
|
||||
root: RootType::Constants,
|
||||
table_offset_dwords: 0,
|
||||
sgprs: 4,
|
||||
base_register: 0,
|
||||
user_data: 0,
|
||||
slot: 0,
|
||||
},
|
||||
RootParam {
|
||||
root: RootType::Table,
|
||||
table_offset_dwords: 0,
|
||||
sgprs: 1,
|
||||
base_register: 0,
|
||||
user_data: 4,
|
||||
slot: 1,
|
||||
},
|
||||
],
|
||||
// One entry for a range of views from dword 0, one at 16.
|
||||
used: vec![range(ResourceType::Srv, 0), range(ResourceType::Uav, 16)],
|
||||
io: StageIo::Cs(ComputeIo {
|
||||
rsrc2: 5 << 1,
|
||||
threads: [32, 1, 1],
|
||||
}),
|
||||
code: words.iter().flat_map(|w| w.to_le_bytes()).collect(),
|
||||
};
|
||||
let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir::build");
|
||||
let st = structure::structure(&p).expect("structure");
|
||||
let res =
|
||||
resource::track(&p, &native.layout, native.stage, Some(&st)).expect("resource::track");
|
||||
let io = io::raise(&p, &native).expect("io::raise");
|
||||
lower::lower(&lower::Parts {
|
||||
native: &native,
|
||||
p: &p,
|
||||
st: &st,
|
||||
io: &io,
|
||||
res: &res,
|
||||
inputs: Vec::new(),
|
||||
outputs: Vec::new(),
|
||||
prims: Vec::new(),
|
||||
mesh_stride: 0,
|
||||
slot: 0,
|
||||
})
|
||||
.expect("lower")
|
||||
};
|
||||
// `s_load_dwordx4 s[dst:dst+3], s[4:5], offset` (soffset null), or with
|
||||
// the offset in `soffset` instead.
|
||||
let at = |dst: u8, offset: u32| {
|
||||
let mut w = s_load_dwordx4(dst, 4);
|
||||
w[1] |= offset;
|
||||
w
|
||||
};
|
||||
let picked = |dst: u8, soffset: u8| {
|
||||
let mut w = s_load_dwordx4(dst, 4);
|
||||
w[1] = u32::from(soffset) << 25;
|
||||
w
|
||||
};
|
||||
let mut fixed = vec![s_mov_b32(5, 0x80)];
|
||||
fixed.extend_from_slice(&at(8, 0x20));
|
||||
fixed.extend_from_slice(&at(12, 0x40));
|
||||
fixed.extend_from_slice(&mubuf_idxen(LOAD_D16_XYZW, 1, 0, 8));
|
||||
fixed.extend_from_slice(&mubuf_idxen(STORE_D16_XYZW, 1, 0, 12));
|
||||
fixed.push(S_ENDPGM);
|
||||
assert_eq!(lowered(&fixed).half_views, [(1, 8), (1, 16)]);
|
||||
// The load's offset in s20, from the first lane's thread index
|
||||
// (`v_readfirstlane_b32 s20, v0`): picked at run time. The pick may land
|
||||
// on the store's place too, so no place of that table is named: the d16
|
||||
// accesses there take the float path, as before half views.
|
||||
let mut runtime = vec![s_mov_b32(5, 0x80), vop1(0x02, 20, vgpr(0))];
|
||||
runtime.extend_from_slice(&picked(8, 20));
|
||||
runtime.extend_from_slice(&at(12, 0x40));
|
||||
runtime.extend_from_slice(&mubuf_idxen(LOAD_D16_XYZW, 1, 0, 8));
|
||||
runtime.extend_from_slice(&mubuf_idxen(STORE_D16_XYZW, 1, 0, 12));
|
||||
runtime.push(S_ENDPGM);
|
||||
assert!(lowered(&runtime).half_views.is_empty());
|
||||
}
|
||||
|
||||
/// A format load of whole dwords (`buffer_load_format_x`, not d16) whose
|
||||
/// result the program only reads one half of as a half float
|
||||
/// (`v_cvt_f32_f16`) is moving 16-bit integers: the head program reads the
|
||||
/// face network's output so, from an `R16_UINT` view. It names its view for
|
||||
/// the host and loads the integer: 0x3c00 comes through as 1.0. Used as a
|
||||
/// whole float instead (`v_add_f32`), the load stays a float load and names
|
||||
/// nothing; so does a load of halves beside a load of the same view read as
|
||||
/// a whole float (a view of numbers the program also picks one half float
|
||||
/// out of, as hundreds of the title's pixel programs do).
|
||||
#[test]
|
||||
fn a_format_load_read_as_halves_loads_the_integer() {
|
||||
use super::host::Stride;
|
||||
use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R16_UINT;
|
||||
/// MUBUF `op vdata, vaddr, s[srsrc:srsrc+3], 0 idxen`.
|
||||
const fn mubuf_idxen(op: u32, vdata: u8, vaddr: u8, srsrc: u8) -> [u32; 2] {
|
||||
[
|
||||
0x38 << 26 | op << 18 | 1 << 13,
|
||||
0x80 << 24 | ((srsrc as u32 >> 2) & 0x1F) << 16 | (vdata as u32) << 8 | vaddr as u32,
|
||||
]
|
||||
}
|
||||
const LOAD_FORMAT_X: u32 = 0x00;
|
||||
const V_CVT_F32_F16: u16 = 0x0B;
|
||||
const V_ADD_F32: u8 = 0x03;
|
||||
let lowered = |body: &[u32]| {
|
||||
let view = |kind: ResourceType, table_offset_dwords: u32, stride: u32| UsedResource {
|
||||
kind,
|
||||
root: RootType::Table,
|
||||
table_offset_dwords,
|
||||
lower_bound: table_offset_dwords / 8,
|
||||
stride,
|
||||
dwords: 4,
|
||||
user_data: 4,
|
||||
slot: 1,
|
||||
};
|
||||
let mut second = s_load_dwordx4(12, 4);
|
||||
second[1] |= 0x20;
|
||||
let mut words = vec![s_mov_b32(5, 0x80)];
|
||||
words.extend_from_slice(&s_load_dwordx4(8, 4));
|
||||
words.extend_from_slice(&second);
|
||||
// `body` leaves v2, stored raw.
|
||||
words.extend_from_slice(body);
|
||||
words.extend_from_slice(&buffer_store_dword(2, 12, 0));
|
||||
words.push(S_ENDPGM);
|
||||
let native = NativeProgram {
|
||||
stage: HwStage::Cs,
|
||||
wave64: false,
|
||||
vgprs: 8,
|
||||
layout: vec![
|
||||
RootParam {
|
||||
root: RootType::Constants,
|
||||
table_offset_dwords: 0,
|
||||
sgprs: 4,
|
||||
base_register: 0,
|
||||
user_data: 0,
|
||||
slot: 0,
|
||||
},
|
||||
RootParam {
|
||||
root: RootType::Table,
|
||||
table_offset_dwords: 0,
|
||||
sgprs: 1,
|
||||
base_register: 0,
|
||||
user_data: 4,
|
||||
slot: 1,
|
||||
},
|
||||
],
|
||||
used: vec![view(ResourceType::Srv, 0, 4), view(ResourceType::Uav, 8, 0)],
|
||||
io: StageIo::Cs(ComputeIo {
|
||||
rsrc2: 5 << 1,
|
||||
threads: [1, 1, 1],
|
||||
}),
|
||||
code: words.iter().flat_map(|w| w.to_le_bytes()).collect(),
|
||||
};
|
||||
let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir::build");
|
||||
let st = structure::structure(&p).expect("structure");
|
||||
let res =
|
||||
resource::track(&p, &native.layout, native.stage, Some(&st)).expect("resource::track");
|
||||
let io = io::raise(&p, &native).expect("io::raise");
|
||||
let l = lower::lower(&lower::Parts {
|
||||
native: &native,
|
||||
p: &p,
|
||||
st: &st,
|
||||
io: &io,
|
||||
res: &res,
|
||||
inputs: Vec::new(),
|
||||
outputs: Vec::new(),
|
||||
prims: Vec::new(),
|
||||
mesh_stride: 0,
|
||||
})
|
||||
.expect("lower");
|
||||
HostShader {
|
||||
stage: HwStage::Cs,
|
||||
dxil: l.dxil,
|
||||
user_data: l.user_data,
|
||||
samplers: l.samplers,
|
||||
static_samplers: Vec::new(),
|
||||
root_cbvs: l.root_cbvs,
|
||||
root_srvs: l.root_srvs,
|
||||
root_uavs: l.root_uavs,
|
||||
root_indexed_views: res.root_indexed_views,
|
||||
half_views: l.half_views,
|
||||
}
|
||||
};
|
||||
// v1 = first[v0] (one channel).
|
||||
let load = mubuf_idxen(LOAD_FORMAT_X, 1, 0, 8);
|
||||
let half = vop1(V_CVT_F32_F16, 2, vgpr(1));
|
||||
let as_halves = lowered(&[&load[..], &[half]].concat());
|
||||
assert_eq!(as_halves.half_views, [(1, 0)]);
|
||||
let as_float = lowered(&[&load[..], &[vop2(V_ADD_F32, 2, vgpr(1), 1)]].concat());
|
||||
assert!(as_float.half_views.is_empty());
|
||||
// v3 = first[v0] too, read as a whole float: v2 = half(v1) + v3.
|
||||
let mut beside = load.to_vec();
|
||||
beside.extend_from_slice(&mubuf_idxen(LOAD_FORMAT_X, 3, 0, 8));
|
||||
beside.push(half);
|
||||
beside.push(vop2(V_ADD_F32, 2, vgpr(3), 2));
|
||||
assert!(lowered(&beside).half_views.is_empty());
|
||||
// Behind a branch, as the head program has it: where the lanes meet
|
||||
// again the loaded value goes on through a phi, and a later write of
|
||||
// v1 under EXEC reads it only to keep it in the lanes it leaves alone.
|
||||
const SAVE_EXEC: u32 = 0xBE90_037E; // s_mov_b32 s16, exec_lo
|
||||
const ONLY_LANE_0: u32 = 0x7DA4_0080; // v_cmpx_eq_u32 exec_lo, 0, v0
|
||||
const SKIP_3: u32 = 0xBF88_0003; // s_cbranch_execz over the next 3 words
|
||||
const RESTORE_EXEC: u32 = 0xBEFE_0310; // s_mov_b32 exec_lo, s16
|
||||
let zero = vop1(0x01, 2, 128); // v_mov_b32 v2, 0
|
||||
let rewrite = vop1(0x01, 1, 128); // v_mov_b32 v1, 0
|
||||
let branched = lowered(
|
||||
&[
|
||||
&[zero, SAVE_EXEC, ONLY_LANE_0, SKIP_3][..],
|
||||
&load,
|
||||
&[
|
||||
half,
|
||||
RESTORE_EXEC,
|
||||
SAVE_EXEC,
|
||||
ONLY_LANE_0,
|
||||
rewrite,
|
||||
RESTORE_EXEC,
|
||||
],
|
||||
]
|
||||
.concat(),
|
||||
.collect();
|
||||
let shader = build_table_typed_cs(&body, used);
|
||||
assert!(
|
||||
shader.root_srvs.contains(&super::SLOT_TABLE_STRIDES),
|
||||
"table typed d16 shader should request SLOT_TABLE_STRIDES"
|
||||
);
|
||||
assert_eq!(branched.half_views, [(1, 0)]);
|
||||
// A d16 load names its place where it is the only access there...
|
||||
const LOAD_FORMAT_D16_X: u32 = 0x80;
|
||||
let d16 = mubuf_idxen(LOAD_FORMAT_D16_X, 1, 0, 8);
|
||||
let d16_alone = lowered(&[&d16[..], &[half]].concat());
|
||||
assert_eq!(d16_alone.half_views, [(1, 0)]);
|
||||
// ...and not beside a whole float read through the same place, which
|
||||
// would see the unsigned twin: v2 = half(d16 v1) + v3.
|
||||
let mut d16_beside = d16.to_vec();
|
||||
d16_beside.extend_from_slice(&mubuf_idxen(LOAD_FORMAT_X, 3, 0, 8));
|
||||
d16_beside.push(half);
|
||||
d16_beside.push(vop2(V_ADD_F32, 2, vgpr(3), 2));
|
||||
assert!(lowered(&d16_beside).half_views.is_empty());
|
||||
if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) {
|
||||
for shader in [&as_halves, &branched, &d16_alone] {
|
||||
let mut dxil = shader.dxil.clone();
|
||||
v.validate(&mut dxil).expect("DXIL validation failed");
|
||||
}
|
||||
}
|
||||
// Element 0 of an R16_UINT buffer holds the half 1.0 (0x3c00).
|
||||
let data = [0x0000_3c00u32, 0];
|
||||
let _one = ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut ran = 0;
|
||||
for (label, warp) in [("hardware", false), ("warp", true)] {
|
||||
let Ok(host) = Host::new(warp) else {
|
||||
eprintln!("no SM 6.6 {label} device; skipped");
|
||||
continue;
|
||||
};
|
||||
for (name, shader) in [("straight", &as_halves), ("branched", &branched)] {
|
||||
let (root, pso) = host
|
||||
.compute_pipeline(shader)
|
||||
.unwrap_or_else(|e| panic!("{label}: compute_pipeline failed: {e}"));
|
||||
assert!(
|
||||
!shader.root_srvs.contains(&super::SLOT_STRIDES),
|
||||
"table-only shader must not trigger the bindless SLOT_STRIDES sweep"
|
||||
);
|
||||
|
||||
// 4 elements x 4 u16 channels = 8 u32 dwords.
|
||||
// Includes FP16 subnormal (0x0001), -0.0 (0x8000), 1.0 (0x3C00), -1.0 (0xBC00),
|
||||
// NaN (0x7E00), max u16 (0xFFFF), and arbitrary patterns.
|
||||
let uint_bits: [u32; 8] = [
|
||||
0x3C00_0001, 0x7E00_BC00,
|
||||
0xFFFF_8000, 0xABCD_1234,
|
||||
0x0002_0000, 0x7BFF_FBFF,
|
||||
0xDEAD_BEEF, 0xCAFE_BABE,
|
||||
];
|
||||
let sint_bits: [u32; 8] = [
|
||||
0xFFFF_8000, 0x7FFF_0001,
|
||||
0xC000_0000, 0x8001_7FFE,
|
||||
0xFFFF_FFFF, 0x0000_0000,
|
||||
0xFEDC_BA98, 0x7654_3210,
|
||||
];
|
||||
// Normal finite FP16 values that round-trip cleanly through f32.
|
||||
let float_bits: [u32; 8] = [
|
||||
0x4000_3C00, 0x3800_BC00, // 1.0, 2.0, -1.0, 0.5
|
||||
0xC200_3400, 0x4500_0000, // 0.25, -3.0, 0.0, 5.0
|
||||
0x3E00_BE00, 0x4400_C400, // -1.5, 1.5, -4.0, 4.0
|
||||
0x3C00_0000, 0x4200_C000, // 0.0, 1.0, -2.0, 3.0
|
||||
];
|
||||
let zeros = [0u32; 8];
|
||||
|
||||
let cases = [
|
||||
("R16G16B16A16_UINT @0", DXGI_FORMAT_R16G16B16A16_UINT, 8 | super::VIEW_INTEGER, &uint_bits, 0u32),
|
||||
("R16G16B16A16_UINT @3 (dynamic offset)", DXGI_FORMAT_R16G16B16A16_UINT, 8 | super::VIEW_INTEGER, &uint_bits, 3u32),
|
||||
("R16G16B16A16_SINT @0", DXGI_FORMAT_R16G16B16A16_SINT, 8 | super::VIEW_INTEGER | super::VIEW_SIGNED, &sint_bits, 0u32),
|
||||
("R16G16B16A16_FLOAT @0", DXGI_FORMAT_R16G16B16A16_FLOAT, 8, &float_bits, 0u32),
|
||||
];
|
||||
|
||||
for (backend, warp) in [("hardware", false), ("warp", true)] {
|
||||
let Ok(host) = Host::new(warp) else { continue };
|
||||
let (root, pso) = host
|
||||
.compute_pipeline(&shader)
|
||||
.unwrap_or_else(|e| panic!("{backend}: compute_pipeline failed: {e}"));
|
||||
for &(label, format, stride_word, input, base_slot) in &cases {
|
||||
let mut views = Vec::new();
|
||||
let mut strides = Vec::new();
|
||||
for _ in 0..base_slot {
|
||||
views.push(View::RawUav(1));
|
||||
strides.push(0u32);
|
||||
}
|
||||
let uav_base = base_slot as usize;
|
||||
views.push(View::TypedUav { data: input, format, elem_bytes: 8 });
|
||||
strides.push(stride_word);
|
||||
views.push(View::TypedUav { data: &zeros, format, elem_bytes: 8 });
|
||||
strides.push(stride_word);
|
||||
views.push(View::RawUav(8));
|
||||
strides.push(1);
|
||||
|
||||
let mut ud = vec![0u32; shader.user_data_dwords().max(1) as usize];
|
||||
for u in &shader.user_data {
|
||||
ud[u.index as usize] = match (u.root, u.slot) {
|
||||
(RootType::Table, 1) => 0,
|
||||
other => panic!("unexpected user data {other:?}"),
|
||||
};
|
||||
if u.root == RootType::Table && u.slot == 0 {
|
||||
ud[u.index as usize] = base_slot * 32;
|
||||
}
|
||||
}
|
||||
let out = host
|
||||
.dispatch(
|
||||
&root,
|
||||
&pso,
|
||||
&Dispatch {
|
||||
roots: vec![
|
||||
(0, Root::Constants(ud)),
|
||||
(1, Root::View { srv: true, data: strides }),
|
||||
],
|
||||
views: &views,
|
||||
samplers: &[],
|
||||
groups: [1, 1, 1],
|
||||
},
|
||||
)
|
||||
.unwrap_or_else(|e| panic!("{backend} {label}: dispatch failed: {e}"));
|
||||
assert_eq!(
|
||||
out[uav_base + 2],
|
||||
input,
|
||||
"{backend} {label}: buffer_load_format_d16_xyzw mismatch"
|
||||
);
|
||||
assert_eq!(
|
||||
out[uav_base + 1],
|
||||
input,
|
||||
"{backend} {label}: buffer_store_format_d16_xyzw mismatch"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Non-`d16` typed loads (`buffer_load_format_x`) are used by
|
||||
/// `CS_BlendshapeTranslationsHSSGraphOutputExtract` (reading `HSSGraphOut`
|
||||
/// `R16_UINT`) and `CS_PedStandardSkinning_*` (reading bone indices). Verify
|
||||
/// exact integer bits for `R16_UINT`, `R16_SINT`, and `R32_UINT`.
|
||||
#[test]
|
||||
fn typed_non_d16_table_load_preserves_integer_bits() {
|
||||
use windows::Win32::Graphics::Dxgi::Common::{
|
||||
DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R32_UINT,
|
||||
};
|
||||
let _serial = ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut body = Vec::new();
|
||||
// s[8:11] = table[0] (src typed SRV), s[12:15] = table[1] (raw UAV out)
|
||||
body.extend_from_slice(&s_load_dwordx4_off(8, 4, 0));
|
||||
body.extend_from_slice(&s_load_dwordx4_off(12, 4, 32));
|
||||
// buffer_load_format_x v2, v0, s[8:11], 0 idxen (op 0x00)
|
||||
body.extend_from_slice(&mubuf_idxen(0x00, 2, 0, 8));
|
||||
// v4 = v0 << 2 (byte offset = thread * 4)
|
||||
body.push(0x3408_0082); // v_lshlrev_b32 v4, 2, v0
|
||||
// buffer_store_dword v2, v4, s[12:15], 0 offen (op 0x1C, offen bit 12)
|
||||
body.extend_from_slice(&[
|
||||
0x38 << 26 | 0x1C << 18 | 1 << 12,
|
||||
0x80 << 24 | (12u32 >> 2) << 16 | (2u32 << 8) | 4u32,
|
||||
]);
|
||||
let used = vec![
|
||||
UsedResource {
|
||||
kind: ResourceType::Srv,
|
||||
root: RootType::Table,
|
||||
table_offset_dwords: 0,
|
||||
lower_bound: 0,
|
||||
stride: 4,
|
||||
dwords: 4,
|
||||
user_data: 4,
|
||||
slot: 0,
|
||||
},
|
||||
UsedResource {
|
||||
kind: ResourceType::Uav,
|
||||
root: RootType::Table,
|
||||
table_offset_dwords: 8,
|
||||
lower_bound: 1,
|
||||
stride: 4,
|
||||
dwords: 4,
|
||||
user_data: 4,
|
||||
slot: 0,
|
||||
},
|
||||
];
|
||||
let shader = build_table_typed_cs(&body, used);
|
||||
// Non-d16 typed loads stay untouched (no SLOT_TABLE_STRIDES root SRV, no
|
||||
// CFG branches) so non-d16 pixel/mesh/particle/skinning shaders keep
|
||||
// identical DXIL and pipeline cache keys while still preserving raw bits.
|
||||
assert!(
|
||||
!shader.root_srvs.contains(&super::SLOT_TABLE_STRIDES),
|
||||
"non-d16 typed load should not add SLOT_TABLE_STRIDES"
|
||||
);
|
||||
|
||||
let r16_data = [0x3C00_0001u32, 0xFFFF_BC00u32];
|
||||
let r32_data = [0xDEAD_BEEFu32, 0x0000_0001, 0x8000_0000, 0x7FFF_FFFF];
|
||||
let cases: [(&str, _, u32, &[u32], [u32; 4]); 3] = [
|
||||
(
|
||||
"R16_UINT",
|
||||
DXGI_FORMAT_R16_UINT,
|
||||
2,
|
||||
&r16_data,
|
||||
[0x0001, 0x3C00, 0xBC00, 0xFFFF],
|
||||
),
|
||||
(
|
||||
"R16_SINT",
|
||||
DXGI_FORMAT_R16_SINT,
|
||||
2,
|
||||
&r16_data,
|
||||
[0x0001, 0x3C00, 0xFFFF_BC00, 0xFFFF_FFFF],
|
||||
),
|
||||
(
|
||||
"R32_UINT",
|
||||
DXGI_FORMAT_R32_UINT,
|
||||
4,
|
||||
&r32_data,
|
||||
r32_data,
|
||||
),
|
||||
];
|
||||
|
||||
for (backend, warp) in [("hardware", false), ("warp", true)] {
|
||||
let Ok(host) = Host::new(warp) else { continue };
|
||||
let (root, pso) = host
|
||||
.compute_pipeline(&shader)
|
||||
.unwrap_or_else(|e| panic!("{backend}: compute_pipeline failed: {e}"));
|
||||
for &(label, format, elem_bytes, input, want) in &cases {
|
||||
let views = [
|
||||
View::Buffer {
|
||||
data: input,
|
||||
stride: super::host::Stride::Format(format, elem_bytes),
|
||||
},
|
||||
View::RawUav(4),
|
||||
];
|
||||
let mut ud = vec![0u32; shader.user_data_dwords().max(1) as usize];
|
||||
for u in &shader.user_data {
|
||||
if u.root == RootType::Table && u.slot == 0 {
|
||||
ud[u.index as usize] = 0;
|
||||
}
|
||||
}
|
||||
let out = host
|
||||
.dispatch(
|
||||
@@ -2522,25 +2381,13 @@ fn a_format_load_read_as_halves_loads_the_integer() {
|
||||
&pso,
|
||||
&Dispatch {
|
||||
roots: vec![(0, Root::Constants(ud))],
|
||||
views: &[
|
||||
View::Buffer {
|
||||
data: &data,
|
||||
stride: Stride::Format(DXGI_FORMAT_R16_UINT, 2),
|
||||
},
|
||||
View::RawUav(1),
|
||||
],
|
||||
views: &views,
|
||||
samplers: &[],
|
||||
groups: [1, 1, 1],
|
||||
},
|
||||
)
|
||||
.unwrap_or_else(|e| panic!("{label}: dispatch failed: {e}"));
|
||||
assert_eq!(
|
||||
out[0][0],
|
||||
1.0f32.to_bits(),
|
||||
"{label}, {name}: the half read as an integer's bits"
|
||||
);
|
||||
.unwrap_or_else(|e| panic!("{backend} {label}: dispatch failed: {e}"));
|
||||
assert_eq!(out[0], want, "{backend} {label}: buffer_load_format_x mismatch");
|
||||
}
|
||||
ran += 1;
|
||||
}
|
||||
assert!(ran > 0, "no SM 6.6 device available");
|
||||
}
|
||||
Reference in new issue
Block a user