Run Grand Theft Auto VI from first boot into the world
The title now boots through every first-boot and menu screen at its own 30 fps, drawing with translated shaders, with input, sound, saves and loading served; it reaches the world, where the host GPU path still fails (see "Not working yet"). Loader and runtime - Crash reports unwind properly, name C++ throws and host GPU failures, carry the title's last debug lines and are appended to crashes.log. - Thread notices on our own threads, reentrant late DLL loading, exit in the console's order, relaunch on a launch-new-game request. - Offline guard: the title cannot reach the network (sockets, name lookups, WinHTTP, the media source resolver); by-name lookups and loads follow the import rules. - Every runtime area the title calls is served (networking hint, packages, store, saves, display, UI, speech stubs, user, async pool). Saves persist; an update is one rename and survives a kill at any step. - DirectStorage reads for real: shared worker pool, priorities, zlib and BCPack. BCPack is our own decoder; the format's constant tables ship in crates/victory-formats/src/bcpack-tables.bin (the asset policy's one exception, see docs/asset-policy.md). - GameInput from XInput pads and the keyboard, with a keyboard stand-in pad; console timers (1 ms) for the whole process. - Audio: XMA2 decoding on the emulated contexts, Opus on the decoder queues, the DSP interface as a stub; title memory placed below 2^40. - Console texture layouts (sizes, tiling, detiling) and the layout library's imports. GPU - Draws, mesh dispatches and compute dispatches run on the host with shaders translated at first use and cached on disk; descriptor heaps, views, root signatures, barriers and host texture states; rectangle lists; comparison samplers. - Title memory reaches the host through persistent mirrors that copy only pages written since the last copy; shader-written buffers are copied back. - Presentation with frame pacing per event kind; framerate in the window caption. Shaders - DXIL emission for vertex, pixel, compute and mesh programs from the console's native code, with a differential test suite against the PC compile. World set: mesh 8,191 of 8,506, vertex/pixel 10,617 of 12,346, compute 1,643 of 2,539; utility set complete. Build - Debugging aids (debug logs, frame capture, stack dumps, scripted keys, the host debug layer, the software adapter) exist only with the `diagnostics` feature; `[profile.diag]` keeps that build apart. Not working yet - In the world the host device is removed within seconds (descriptor handling fixes are in, unproven by a surviving run) and frames present black. - 64-bit image atomics, merged geometry stages and the BVH builder's own shaders do not translate; reverb is silent. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
1 parent
bc3070991a
commit
2849477415
107 files changed
+42526
-868
No files matched your search
@@ -0,0 +1,221 @@
|
||||
//! The DXIL validator in `dxil.dll` (`IDxcValidator`), for tests and the
|
||||
//! offline batch. Translated shaders do not need it: they carry the
|
||||
//! container hash we compute ([`super::container::hash`]).
|
||||
//!
|
||||
//! The DLL is found at `VICTORY_DXIL` if set, else the newest Windows SDK's
|
||||
//! `bin\<version>\x64\dxil.dll`, else wherever `LoadLibrary` finds it.
|
||||
|
||||
use std::ffi::c_void;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use windows_sys::Win32::System::LibraryLoader::{GetProcAddress, LoadLibraryW};
|
||||
|
||||
type Hresult = i32;
|
||||
|
||||
#[repr(C)]
|
||||
struct Guid(u32, u16, u16, [u8; 8]);
|
||||
|
||||
const CLSID_DXC_VALIDATOR: Guid = Guid(
|
||||
0x8ca3_e215,
|
||||
0xf728,
|
||||
0x4cf3,
|
||||
[0x8c, 0xdd, 0x88, 0xaf, 0x91, 0x75, 0x87, 0xa1],
|
||||
);
|
||||
const IID_IDXC_VALIDATOR: Guid = Guid(
|
||||
0xa6e8_2bd2,
|
||||
0x1fd7,
|
||||
0x4826,
|
||||
[0x98, 0x11, 0x28, 0x57, 0xe7, 0x97, 0xf4, 0x9a],
|
||||
);
|
||||
/// `DxcValidatorFlags_InPlaceEdit`: sign the container we pass.
|
||||
const IN_PLACE_EDIT: u32 = 1;
|
||||
|
||||
type CreateInstance =
|
||||
unsafe extern "system" fn(*const Guid, *const Guid, *mut *mut c_void) -> Hresult;
|
||||
|
||||
/// COM object: a pointer to a table of method pointers.
|
||||
type Object = *mut *const usize;
|
||||
|
||||
unsafe fn method<F: Copy>(obj: Object, slot: usize) -> F {
|
||||
// SAFETY: the caller names a slot of the object's interface.
|
||||
unsafe { std::mem::transmute_copy(&*(*obj).add(slot)) }
|
||||
}
|
||||
|
||||
unsafe fn release(obj: Object) {
|
||||
if !obj.is_null() {
|
||||
// SAFETY: slot 2 of every COM interface is Release.
|
||||
unsafe { method::<unsafe extern "system" fn(Object) -> u32>(obj, 2)(obj) };
|
||||
}
|
||||
}
|
||||
|
||||
/// An `IDxcBlob` over our bytes: QueryInterface, AddRef, Release,
|
||||
/// GetBufferPointer, GetBufferSize. Lives on the caller's stack.
|
||||
#[repr(C)]
|
||||
struct Blob {
|
||||
vtable: *const BlobVtable,
|
||||
data: *mut u8,
|
||||
len: usize,
|
||||
}
|
||||
|
||||
/// IUnknown and IDxcBlob, as raw GUID bytes.
|
||||
const IUNKNOWN: [u8; 16] = [0, 0, 0, 0, 0, 0, 0, 0, 0xc0, 0, 0, 0, 0, 0, 0, 0x46];
|
||||
const IDXC_BLOB: [u8; 16] = [
|
||||
0x08, 0xfb, 0xa5, 0x8b, 0x95, 0x51, 0xe2, 0x40, 0xac, 0x58, 0x0d, 0x98, 0x9c, 0x3a, 0x01, 0x02,
|
||||
];
|
||||
|
||||
unsafe extern "system" fn blob_qi(
|
||||
this: *mut Blob,
|
||||
iid: *const [u8; 16],
|
||||
out: *mut *mut c_void,
|
||||
) -> Hresult {
|
||||
// SAFETY: the validator passes valid pointers.
|
||||
unsafe {
|
||||
if *iid == IUNKNOWN || *iid == IDXC_BLOB {
|
||||
*out = this.cast();
|
||||
0
|
||||
} else {
|
||||
*out = std::ptr::null_mut();
|
||||
0x8000_4002_u32 as i32 // E_NOINTERFACE
|
||||
}
|
||||
}
|
||||
}
|
||||
unsafe extern "system" fn blob_ref(_: *mut Blob) -> u32 {
|
||||
1
|
||||
}
|
||||
unsafe extern "system" fn blob_ptr(this: *mut Blob) -> *mut u8 {
|
||||
// SAFETY: `this` is our blob.
|
||||
unsafe { (*this).data }
|
||||
}
|
||||
unsafe extern "system" fn blob_len(this: *mut Blob) -> usize {
|
||||
// SAFETY: `this` is our blob.
|
||||
unsafe { (*this).len }
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct BlobVtable {
|
||||
qi: unsafe extern "system" fn(*mut Blob, *const [u8; 16], *mut *mut c_void) -> Hresult,
|
||||
add_ref: unsafe extern "system" fn(*mut Blob) -> u32,
|
||||
release: unsafe extern "system" fn(*mut Blob) -> u32,
|
||||
ptr: unsafe extern "system" fn(*mut Blob) -> *mut u8,
|
||||
len: unsafe extern "system" fn(*mut Blob) -> usize,
|
||||
}
|
||||
|
||||
static BLOB_VTABLE: BlobVtable = BlobVtable {
|
||||
qi: blob_qi,
|
||||
add_ref: blob_ref,
|
||||
release: blob_ref,
|
||||
ptr: blob_ptr,
|
||||
len: blob_len,
|
||||
};
|
||||
|
||||
pub struct Validator {
|
||||
object: Object,
|
||||
}
|
||||
|
||||
// SAFETY: the validator object is free-threaded (DXC's validator has no
|
||||
// thread affinity); calls are serialised by `&mut self`.
|
||||
unsafe impl Send for Validator {}
|
||||
|
||||
impl Validator {
|
||||
/// Where `dxil.dll` is looked for.
|
||||
pub fn default_path() -> Option<PathBuf> {
|
||||
if let Some(p) = std::env::var_os("VICTORY_DXIL") {
|
||||
return Some(p.into());
|
||||
}
|
||||
let kits = PathBuf::from(r"C:\Program Files (x86)\Windows Kits\10\bin");
|
||||
let mut versions: Vec<PathBuf> = std::fs::read_dir(&kits)
|
||||
.ok()?
|
||||
.filter_map(Result::ok)
|
||||
.map(|e| e.path().join(r"x64\dxil.dll"))
|
||||
.filter(|p| p.exists())
|
||||
.collect();
|
||||
versions.sort();
|
||||
versions.pop()
|
||||
}
|
||||
|
||||
/// Loads `path`'s validator (or `dxil.dll` from the DLL search path).
|
||||
pub fn load(path: Option<&std::path::Path>) -> Result<Self, String> {
|
||||
let name: Vec<u16> = path
|
||||
.map_or_else(|| "dxil.dll".into(), |p| p.as_os_str().to_owned())
|
||||
.to_string_lossy()
|
||||
.encode_utf16()
|
||||
.chain([0])
|
||||
.collect();
|
||||
// SAFETY: plain Win32 calls with a NUL-terminated name.
|
||||
unsafe {
|
||||
let module = LoadLibraryW(name.as_ptr());
|
||||
if module.is_null() {
|
||||
return Err(format!("cannot load {}", String::from_utf16_lossy(&name)));
|
||||
}
|
||||
let create = GetProcAddress(module, c"DxcCreateInstance".as_ptr().cast())
|
||||
.ok_or("dxil.dll lacks DxcCreateInstance")?;
|
||||
let create: CreateInstance = std::mem::transmute(create);
|
||||
let mut object = std::ptr::null_mut();
|
||||
let hr = create(&CLSID_DXC_VALIDATOR, &IID_IDXC_VALIDATOR, &mut object);
|
||||
if hr < 0 || object.is_null() {
|
||||
return Err(format!("DxcCreateInstance(validator) failed: {hr:#x}"));
|
||||
}
|
||||
Ok(Validator {
|
||||
object: object.cast(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Validates `container` and signs it in place; the error text if it
|
||||
/// is rejected.
|
||||
pub fn validate(&mut self, container: &mut [u8]) -> Result<(), String> {
|
||||
let mut blob = Blob {
|
||||
vtable: &BLOB_VTABLE,
|
||||
data: container.as_mut_ptr(),
|
||||
len: container.len(),
|
||||
};
|
||||
// SAFETY: IDxcValidator::Validate (slot 3) with our blob; then
|
||||
// IDxcOperationResult GetStatus (3) and GetErrorBuffer (5), and
|
||||
// IDxcBlob GetBufferPointer (3) / GetBufferSize (4).
|
||||
unsafe {
|
||||
let mut result: Object = std::ptr::null_mut();
|
||||
let validate: unsafe extern "system" fn(
|
||||
Object,
|
||||
*mut Blob,
|
||||
u32,
|
||||
*mut Object,
|
||||
) -> Hresult = method(self.object, 3);
|
||||
let hr = validate(self.object, &mut blob, IN_PLACE_EDIT, &mut result);
|
||||
if hr < 0 || result.is_null() {
|
||||
return Err(format!("Validate failed: {hr:#x}"));
|
||||
}
|
||||
let mut status = 0;
|
||||
let get_status: unsafe extern "system" fn(Object, *mut Hresult) -> Hresult =
|
||||
method(result, 3);
|
||||
get_status(result, &mut status);
|
||||
let mut text = String::new();
|
||||
if status < 0 {
|
||||
let mut errors: Object = std::ptr::null_mut();
|
||||
let get_errors: unsafe extern "system" fn(Object, *mut Object) -> Hresult =
|
||||
method(result, 5);
|
||||
if get_errors(result, &mut errors) >= 0 && !errors.is_null() {
|
||||
let ptr: unsafe extern "system" fn(Object) -> *const u8 = method(errors, 3);
|
||||
let len: unsafe extern "system" fn(Object) -> usize = method(errors, 4);
|
||||
let bytes = std::slice::from_raw_parts(ptr(errors), len(errors));
|
||||
text = String::from_utf8_lossy(bytes)
|
||||
.trim_end_matches('\0')
|
||||
.trim()
|
||||
.into();
|
||||
release(errors);
|
||||
}
|
||||
if text.is_empty() {
|
||||
text = format!("rejected ({status:#x})");
|
||||
}
|
||||
}
|
||||
release(result);
|
||||
if status < 0 { Err(text) } else { Ok(()) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Validator {
|
||||
fn drop(&mut self) {
|
||||
// SAFETY: we own one reference.
|
||||
unsafe { release(self.object) };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user