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
+725
-48
@@ -5,9 +5,9 @@
|
||||
//! lists keep the pointer and every limit at zero, so every command reaches
|
||||
//! the table as a call.
|
||||
//!
|
||||
//! shortcut: the methods record nothing yet; unwritten ones log once, so a
|
||||
//! run lists what to translate. Translate them onto host command lists
|
||||
//! (TODO.md, GPU).
|
||||
//! Each list records onto a host command list as its methods are called
|
||||
//! (decision 0007); draw state lives in [`crate::draw`]. Methods not
|
||||
//! written yet log once with their caller, so a run lists what to do next.
|
||||
#![allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
|
||||
use std::mem::offset_of;
|
||||
@@ -15,6 +15,7 @@ use std::mem::offset_of;
|
||||
use crate::object::{
|
||||
self, ALLOCATOR, E_INVALIDARG, HRESULT, Iid, LIST, Object, S_OK, Table, This, guid,
|
||||
};
|
||||
use crate::queue::Written;
|
||||
use crate::resource::PAGEABLE_IIDS;
|
||||
|
||||
const ALLOCATOR_IIDS: [Iid; 4] = [
|
||||
@@ -29,9 +30,11 @@ const ALLOCATOR_IIDS: [Iid; 4] = [
|
||||
PAGEABLE_IIDS[2],
|
||||
];
|
||||
|
||||
/// The list interfaces whose ids are the same as on PC, then the device
|
||||
/// child's.
|
||||
const LIST_IIDS: [Iid; 8] = [
|
||||
/// The list interfaces up to `ID3D12GraphicsCommandList6` (the table has
|
||||
/// all their slots): those whose ids are the same as on PC, the console's
|
||||
/// own List5 and List6 (Grand Theft Auto VI asks for List6), then the
|
||||
/// device child's.
|
||||
const LIST_IIDS: [Iid; 10] = [
|
||||
guid(
|
||||
0x7116d91c,
|
||||
0xe7e4,
|
||||
@@ -68,6 +71,18 @@ const LIST_IIDS: [Iid; 8] = [
|
||||
0x4541,
|
||||
[0x98, 0xcf, 0x64, 0x5b, 0x50, 0xdc, 0x48, 0x74],
|
||||
),
|
||||
guid(
|
||||
0x55050859,
|
||||
0x4024,
|
||||
0x474c,
|
||||
[0x98, 0xcf, 0x64, 0x5b, 0x51, 0xdc, 0x48, 0x74],
|
||||
),
|
||||
guid(
|
||||
0xc3827890,
|
||||
0x4024,
|
||||
0x474c,
|
||||
[0x98, 0xcf, 0x64, 0x5b, 0x51, 0xdc, 0x48, 0x74],
|
||||
),
|
||||
PAGEABLE_IIDS[1],
|
||||
PAGEABLE_IIDS[2],
|
||||
];
|
||||
@@ -91,14 +106,33 @@ struct List {
|
||||
graphics_root_headers: [u32; 128],
|
||||
compute_root_headers: [u32; 128],
|
||||
pipeline_shadow: [u32; 8],
|
||||
/// Ours, after the console layout: the host list the calls record
|
||||
/// into (decision 0007).
|
||||
/// Newer titles' lists are larger: Grand Theft Auto VI's state flush
|
||||
/// (title+0x32786) copies a pipeline's 32 bytes to +0x544..+0x564 and
|
||||
/// tests +0x548, so its layout runs past 0x560. Its size is unknown;
|
||||
/// this keeps our fields clear of whatever the title writes there.
|
||||
newer: [u32; 256],
|
||||
/// Ours, after the console layout: memory handed out by
|
||||
/// [`allocate_upload`], kept until the list is reset; the host list the
|
||||
/// calls record into (decision 0007), and the draw state the title set.
|
||||
uploads: std::sync::Mutex<Vec<Vec<u8>>>,
|
||||
#[cfg(windows)]
|
||||
host: Option<crate::host::HostList>,
|
||||
#[cfg(windows)]
|
||||
state: std::sync::Mutex<crate::draw::State>,
|
||||
}
|
||||
const _: () = assert!(offset_of!(List, put) == 0x18);
|
||||
const _: () = assert!(offset_of!(List, pipeline_shadow) + 32 == 0x560);
|
||||
|
||||
/// Runs `f` with the host list and draw state of a title list, if there
|
||||
/// is a host GPU.
|
||||
#[cfg(windows)]
|
||||
fn with_state(this: This, f: impl FnOnce(&crate::host::HostList, &mut crate::draw::State)) {
|
||||
let Some(list) = host_list(this) else { return };
|
||||
// SAFETY: the title passes one of our lists.
|
||||
let state = unsafe { &(*this.cast::<List>()).state };
|
||||
f(list, &mut state.lock().unwrap_or_else(|e| e.into_inner()));
|
||||
}
|
||||
|
||||
/// The host list behind a title list, if there is a host GPU.
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn host_list<'a>(this: This) -> Option<&'a crate::host::HostList> {
|
||||
@@ -168,13 +202,19 @@ fn new_list(kind: u32, allocator: This, iid: *const Iid, out: *mut This) -> HRES
|
||||
}
|
||||
tracing::debug!(kind, "command list");
|
||||
let list = Box::new(List {
|
||||
object: Object::new(&LIST_FUNCTIONS),
|
||||
object: if crate::device::newer() {
|
||||
Object::new(&NEWER_LIST_FUNCTIONS)
|
||||
} else {
|
||||
Object::new(&LIST_FUNCTIONS)
|
||||
},
|
||||
kind,
|
||||
put: [0; 5],
|
||||
reserved: [0; 64],
|
||||
graphics_root_headers: [0; 128],
|
||||
compute_root_headers: [0; 128],
|
||||
pipeline_shadow: [0; 8],
|
||||
newer: [0; 256],
|
||||
uploads: Default::default(),
|
||||
#[cfg(windows)]
|
||||
host: crate::host::host().and_then(|h| match h.new_list() {
|
||||
Ok(list) => Some(list),
|
||||
@@ -183,6 +223,8 @@ fn new_list(kind: u32, allocator: This, iid: *const Iid, out: *mut This) -> HRES
|
||||
None
|
||||
}
|
||||
}),
|
||||
#[cfg(windows)]
|
||||
state: Default::default(),
|
||||
});
|
||||
object::hand_out(LIST, list, iid, &LIST_IIDS, out)
|
||||
}
|
||||
@@ -216,14 +258,21 @@ extern "system" fn close(this: This) -> HRESULT {
|
||||
}
|
||||
S_OK
|
||||
}
|
||||
extern "system" fn reset(this: This, allocator: This, _pipeline: This) -> HRESULT {
|
||||
extern "system" fn reset(this: This, allocator: This, pipeline: This) -> HRESULT {
|
||||
if allocator.is_null() {
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
// Every submission of the list has run (submissions are waited for).
|
||||
// SAFETY: the title passes one of our lists.
|
||||
let uploads = unsafe { &(*this.cast::<List>()).uploads };
|
||||
uploads.lock().unwrap_or_else(|e| e.into_inner()).clear();
|
||||
#[cfg(windows)]
|
||||
if let Some(host) = host_list(this) {
|
||||
with_state(this, |host, state| {
|
||||
host.reset();
|
||||
}
|
||||
state.reset(pipeline);
|
||||
});
|
||||
#[cfg(not(windows))]
|
||||
let _ = (this, pipeline);
|
||||
S_OK
|
||||
}
|
||||
|
||||
@@ -243,7 +292,7 @@ pub(crate) struct Barrier {
|
||||
/// The barrier on host resources, or `None` if it names a resource the host
|
||||
/// GPU does not have (buffers so far).
|
||||
#[cfg(windows)]
|
||||
fn host_barrier(b: &Barrier) -> Option<Barrier> {
|
||||
fn host_barrier(list: &crate::host::HostList, b: &Barrier) -> Option<Barrier> {
|
||||
use windows::core::Interface;
|
||||
let host = |r: This| crate::resource::host_resource(r).map(|h| h.as_raw().cast_const().cast());
|
||||
match b.kind {
|
||||
@@ -253,16 +302,16 @@ fn host_barrier(b: &Barrier) -> Option<Barrier> {
|
||||
if b.flags & BEGIN_ONLY != 0 {
|
||||
return None;
|
||||
}
|
||||
// shortcut: whole resources, from the state we tracked (see
|
||||
// `host_transition`); subresources are not told apart.
|
||||
// shortcut: whole resources, from the state the list tracked
|
||||
// (`HostList::transition`); subresources are not told apart.
|
||||
let wanted = crate::host::texture_state(b.last as u32);
|
||||
let (resource, before) = crate::resource::host_transition(b.first, wanted)?;
|
||||
let (texture, before) = list.transition(b.first, wanted)?;
|
||||
Some(Barrier {
|
||||
kind: 0,
|
||||
flags: 0,
|
||||
first: resource.cast_const().cast(),
|
||||
first: texture.as_raw().cast_const().cast(),
|
||||
second: 0xffff_ffff | (u64::from(before) << 32),
|
||||
last: u64::from(wanted),
|
||||
last: u64::from(crate::host::legal_state(texture, wanted)),
|
||||
})
|
||||
}
|
||||
1 => Some(Barrier {
|
||||
@@ -290,6 +339,16 @@ fn host_barrier(b: &Barrier) -> Option<Barrier> {
|
||||
}
|
||||
}
|
||||
|
||||
/// An unordered access barrier on every resource: earlier shader writes
|
||||
/// finish before later work reads or writes.
|
||||
const UAV_BARRIER: Barrier = Barrier {
|
||||
kind: 2,
|
||||
flags: 0,
|
||||
first: std::ptr::null(),
|
||||
second: 0,
|
||||
last: 0,
|
||||
};
|
||||
|
||||
/// Returns the console's barrier "actions" (none).
|
||||
extern "system" fn barrier(this: This, count: u32, barriers: *const Barrier) -> u32 {
|
||||
#[cfg(windows)]
|
||||
@@ -298,7 +357,17 @@ extern "system" fn barrier(this: This, count: u32, barriers: *const Barrier) ->
|
||||
{
|
||||
// SAFETY: the title passes `count` barriers.
|
||||
let barriers = unsafe { std::slice::from_raw_parts(barriers, count as usize) };
|
||||
let host: Vec<Barrier> = barriers.iter().filter_map(host_barrier).collect();
|
||||
let mut host: Vec<Barrier> = barriers
|
||||
.iter()
|
||||
.filter_map(|b| host_barrier(list, b))
|
||||
.collect();
|
||||
// Buffers have host copies, not resources the barrier can name:
|
||||
// a barrier on one waits for every shader write before it.
|
||||
if barriers.iter().any(|b| {
|
||||
b.kind != 1 && !b.first.is_null() && crate::resource::buffer_bytes(b.first).is_some()
|
||||
}) {
|
||||
host.push(UAV_BARRIER);
|
||||
}
|
||||
if !host.is_empty() {
|
||||
use windows::Win32::Graphics::Direct3D12::D3D12_RESOURCE_BARRIER;
|
||||
const _: () = assert!(size_of::<Barrier>() == size_of::<D3D12_RESOURCE_BARRIER>());
|
||||
@@ -319,11 +388,10 @@ extern "system" fn barrier(this: This, count: u32, barriers: *const Barrier) ->
|
||||
|
||||
/// Moves a title texture's host copy to `state` in the list, if needed.
|
||||
#[cfg(windows)]
|
||||
fn ensure_state(list: &crate::host::HostList, resource: This, state: u32) {
|
||||
pub(crate) fn ensure_state(list: &crate::host::HostList, resource: This, state: u32) {
|
||||
use windows::Win32::Graphics::Direct3D12::D3D12_RESOURCE_STATES as State;
|
||||
if let Some(texture) = crate::resource::host_resource(resource)
|
||||
&& let Some((_, before)) = crate::resource::host_transition(resource, state)
|
||||
{
|
||||
if let Some((texture, before)) = list.transition(resource, state) {
|
||||
let state = crate::host::legal_state(texture, state);
|
||||
let barrier = crate::host::transition(texture, State(before as i32), State(state as i32));
|
||||
// SAFETY: an open list and a live texture.
|
||||
unsafe { list.list.ResourceBarrier(&[barrier]) };
|
||||
@@ -380,6 +448,9 @@ extern "system" fn copy_resource(this: This, dst: This, src: This) {
|
||||
) {
|
||||
ensure_state(list, dst, COPY_DEST);
|
||||
ensure_state(list, src, COPY_SOURCE);
|
||||
crate::texture::host_written(dst);
|
||||
#[cfg(feature = "diagnostics")]
|
||||
list.note_op(|| format!("copy resource {src:?} to {dst:?}"));
|
||||
// SAFETY: an open list and live textures.
|
||||
unsafe { list.list.CopyResource(to, from) };
|
||||
} else if let (Some((to, a)), Some((from, b))) = (
|
||||
@@ -461,9 +532,26 @@ extern "system" fn copy_texture_region(
|
||||
from.resource = texture.as_raw().cast_const().cast();
|
||||
}
|
||||
ensure_state(list, dst.resource, COPY_DEST);
|
||||
crate::texture::host_written(dst.resource);
|
||||
let mut to_location = dst;
|
||||
to_location.resource = to.as_raw().cast_const().cast();
|
||||
let host_box = (!source_box.is_null()).then(|| source_box.cast::<D3D12_BOX>());
|
||||
#[cfg(feature = "diagnostics")]
|
||||
list.note_op(|| {
|
||||
// SAFETY: a live texture; the box is the title's or null.
|
||||
let (d, b) = unsafe { (to.GetDesc(), host_box.map(|b| *b)) };
|
||||
format!(
|
||||
"copy to {:?} {}x{} f{} sub/kind {} at {x},{y},{z} from {:?} kind {} footprint {:?} box {b:?}",
|
||||
dst.resource,
|
||||
d.Width,
|
||||
d.Height,
|
||||
d.Format.0,
|
||||
dst.kind,
|
||||
src.resource,
|
||||
src.kind,
|
||||
(src.kind == FOOTPRINT).then_some(src.footprint)
|
||||
)
|
||||
});
|
||||
const _: () =
|
||||
assert!(size_of::<CopyLocation>() == size_of::<D3D12_TEXTURE_COPY_LOCATION>());
|
||||
// SAFETY: an open list; both locations in the host's layout, naming
|
||||
@@ -522,6 +610,9 @@ extern "system" fn resolve(
|
||||
const RESOLVE_SOURCE: u32 = 0x2000;
|
||||
ensure_state(list, dst, RESOLVE_DEST);
|
||||
ensure_state(list, src, RESOLVE_SOURCE);
|
||||
crate::texture::host_written(dst);
|
||||
#[cfg(feature = "diagnostics")]
|
||||
list.note_op(|| format!("resolve {src:?} to {dst:?} format {format}"));
|
||||
// SAFETY: an open list and live textures; the region is inside both.
|
||||
unsafe {
|
||||
let (a, b) = (to.GetDesc(), from.GetDesc());
|
||||
@@ -594,9 +685,7 @@ extern "system" fn clear_rtv(
|
||||
let rtv = host.rtv(texture, record.desc().as_ref());
|
||||
// SAFETY: an open list, a fresh view of a live texture.
|
||||
unsafe {
|
||||
if let Some((_, before)) =
|
||||
crate::resource::host_transition(record.resource, RENDER_TARGET)
|
||||
{
|
||||
if let Some((_, before)) = list.transition(record.resource, RENDER_TARGET) {
|
||||
use windows::Win32::Graphics::Direct3D12::D3D12_RESOURCE_STATES as State;
|
||||
list.list.ResourceBarrier(&[crate::host::transition(
|
||||
texture,
|
||||
@@ -611,9 +700,137 @@ extern "system" fn clear_rtv(
|
||||
let _ = (this, handle, color, count, rects);
|
||||
}
|
||||
|
||||
/// `ClearDepthStencilView(handle, flags, depth, stencil, count, rects)`;
|
||||
/// flags: 1 depth, 2 stencil.
|
||||
extern "system" fn clear_dsv(
|
||||
this: This,
|
||||
handle: u64,
|
||||
flags: u32,
|
||||
depth: f32,
|
||||
stencil: u8,
|
||||
count: u32,
|
||||
rects: *const Rect,
|
||||
) {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use windows::Win32::Graphics::Direct3D12::D3D12_CLEAR_FLAGS;
|
||||
let (Some(list), Some(record)) = (host_list(this), crate::descriptor::dsv_record(handle))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let (Some(texture), Some(host)) = (
|
||||
crate::resource::host_resource(record.resource),
|
||||
crate::host::host(),
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
let rects = (count > 0 && !rects.is_null()).then(|| {
|
||||
// SAFETY: the title passes `count` rectangles, laid out as the host's.
|
||||
unsafe { std::slice::from_raw_parts(rects.cast(), count as usize) }
|
||||
});
|
||||
const DEPTH_WRITE: u32 = 0x10;
|
||||
ensure_state(list, record.resource, DEPTH_WRITE);
|
||||
let dsv = host.dsv(texture, record.depth_desc().as_ref());
|
||||
// SAFETY: an open list, a fresh view of a live texture.
|
||||
unsafe {
|
||||
list.list
|
||||
.ClearDepthStencilView(dsv, D3D12_CLEAR_FLAGS(flags as i32 & 3), depth, stencil, rects)
|
||||
};
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
let _ = (this, handle, flags, depth, stencil, count, rects);
|
||||
}
|
||||
|
||||
/// `CopyMemoryToMemoryX(destination, source, size, flags)`: GPU addresses
|
||||
/// are title memory, copied at submission like buffer copies (if mapped).
|
||||
extern "system" fn copy_memory(this: This, dst: u64, src: u64, len: u64, _flags: u32) {
|
||||
#[cfg(windows)]
|
||||
if let Some(list) = host_list(this)
|
||||
&& dst != 0
|
||||
&& src != 0
|
||||
{
|
||||
let len = len as usize;
|
||||
list.defer(move || {
|
||||
if crate::texture::committed(src as *const u8, len)
|
||||
&& crate::texture::committed(dst as *const u8, len)
|
||||
{
|
||||
// SAFETY: both ranges are committed title memory.
|
||||
unsafe { std::ptr::copy(src as *const u8, dst as *mut u8, len) };
|
||||
}
|
||||
});
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
let _ = (this, dst, src, len);
|
||||
}
|
||||
|
||||
/// `DriverHintX(feature, value)`: no hints for the host.
|
||||
extern "system" fn driver_hint(_: This, _feature: u64, _value: u64) -> u64 {
|
||||
0
|
||||
}
|
||||
|
||||
/// `DispatchX(x, y, z, flags)`: a dispatch with console flags, which the
|
||||
/// host has no use for (the ray-tracing builder dispatches this way).
|
||||
extern "system" fn dispatch_x(this: This, x: u32, y: u32, z: u32, _flags: u32) {
|
||||
#[cfg(windows)]
|
||||
state::dispatch(this, x, y, z);
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let _ = (this, x, y, z);
|
||||
count_dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
/// `BeginQuery`/`EndQuery(heap, type, index)`: queries are answered when
|
||||
/// resolved.
|
||||
extern "system" fn query_mark(_: This, _heap: This, _kind: u32, _index: u32) {}
|
||||
|
||||
/// `ResolveQueryData(heap, type, first, count, buffer, offset)`: writes
|
||||
/// each query's result into the buffer once the list has run. Timestamps
|
||||
/// (type 2) are the GPU clock then; occlusion counts (0) say a million
|
||||
/// samples passed and binary occlusion (1) visible, so nothing is culled
|
||||
/// by a query.
|
||||
/// shortcut: no query runs on the host GPU; results are plausible values,
|
||||
/// not measured ones (time spans come out as the submission's length).
|
||||
extern "system" fn resolve_queries(
|
||||
this: This,
|
||||
_heap: This,
|
||||
kind: u32,
|
||||
_first: u32,
|
||||
count: u32,
|
||||
buffer: This,
|
||||
offset: u64,
|
||||
) {
|
||||
const OCCLUSION: u32 = 0;
|
||||
const BINARY: u32 = 1;
|
||||
const TIMESTAMP: u32 = 2;
|
||||
const PIPELINE_STATISTICS: u32 = 3;
|
||||
let Some((data, size)) = crate::resource::buffer_bytes(buffer) else {
|
||||
return;
|
||||
};
|
||||
let (what, bytes) = match kind {
|
||||
OCCLUSION => (Written::Value(1 << 20), 8),
|
||||
BINARY => (Written::Value(1), 8),
|
||||
TIMESTAMP => (Written::GpuTimestamp, 8),
|
||||
PIPELINE_STATISTICS => (Written::Value(0), 88),
|
||||
_ => (Written::Value(0), 16),
|
||||
};
|
||||
if offset + u64::from(count) * bytes > size {
|
||||
return;
|
||||
}
|
||||
for i in 0..u64::from(count) {
|
||||
// Wider results are written as 8-byte pieces.
|
||||
for piece in 0..bytes / 8 {
|
||||
// SAFETY: inside the buffer, checked above.
|
||||
let at = unsafe { data.add((offset + i * bytes + piece * 8) as usize) };
|
||||
let what = if piece == 0 { what } else { Written::Value(0) };
|
||||
defer_write(this, at as u64, what, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// IUnknown 3, object 4, device child 1, allocator 2.
|
||||
static ALLOCATOR_FUNCTIONS: Table<10> = {
|
||||
let mut f = object::d3d12_object(object::missing_table::<ALLOCATOR, 10>());
|
||||
static ALLOCATOR_FUNCTIONS: Table<24> = {
|
||||
let mut f = object::d3d12_object(object::missing_table::<ALLOCATOR, 24>());
|
||||
f[0] = allocator_query as *const ();
|
||||
f[2] = allocator_release as *const ();
|
||||
f[7] = object::parent_device as *const (); // 0x38
|
||||
@@ -622,26 +839,472 @@ static ALLOCATOR_FUNCTIONS: Table<10> = {
|
||||
Table(f)
|
||||
};
|
||||
|
||||
/// IUnknown 3, object 4, device child 1, list 1, graphics list 96 (59 as
|
||||
/// on PC, then console ones), then versions 1-6 (6 + 1 + 1 + 11 + 3 + 13).
|
||||
static LIST_FUNCTIONS: Table<140> = {
|
||||
let mut f = object::d3d12_object(object::missing_table::<LIST, 140>());
|
||||
f[0] = list_query as *const ();
|
||||
f[2] = list_release as *const ();
|
||||
f[7] = object::parent_device as *const (); // 0x38
|
||||
f[8] = list_type as *const (); // 0x40
|
||||
f[9] = close as *const (); // 0x48
|
||||
f[10] = reset as *const (); // 0x50
|
||||
f[15] = copy_buffer_region as *const (); // 0x78
|
||||
f[16] = copy_texture_region as *const (); // 0x80
|
||||
f[17] = copy_resource as *const (); // 0x88
|
||||
f[19] = resolve as *const (); // 0x98
|
||||
f[26] = barrier as *const (); // 0xd0
|
||||
f[83] = copy_texture_region_x as *const (); // 0x298
|
||||
f[84] = copy_resource_x as *const (); // 0x2a0
|
||||
f[52] = clear_rtv as *const (); // 0x1a0
|
||||
Table(f)
|
||||
};
|
||||
extern "system" fn set_pipeline(this: This, pipeline: This) {
|
||||
crate::pipeline::bound(pipeline);
|
||||
#[cfg(windows)]
|
||||
with_state(this, |_, state| state.set_pipeline(pipeline));
|
||||
#[cfg(not(windows))]
|
||||
let _ = this;
|
||||
}
|
||||
|
||||
/// Pipeline syncs: waits for earlier work and cache flushes, at the top or
|
||||
/// bottom of the pipe `(flags, control, address, size)`. Host lists order
|
||||
/// their own work and every submission is waited for, so there is nothing
|
||||
/// to do.
|
||||
extern "system" fn sync(_: This, _flags: u32, _control: u32, _address: u64, _size: u64) {}
|
||||
|
||||
/// Reset with console flags `(allocator, pipeline, flags)`; the flags only
|
||||
/// tune the console's command memory.
|
||||
extern "system" fn reset_x(this: This, allocator: This, pipeline: This, _flags: u32) -> HRESULT {
|
||||
reset(this, allocator, pipeline)
|
||||
}
|
||||
|
||||
/// Newer lists' 0x4a0 `(size, alignment) -> pointer`: memory the list
|
||||
/// owns until it is reset, which the CPU writes and the GPU reads at the
|
||||
/// same address; null on failure. Grand Theft Auto VI's BVH builder puts
|
||||
/// its instance descriptions there (and wrote through our old
|
||||
/// `E_NOTIMPL` as a pointer).
|
||||
extern "system" fn allocate_upload(this: This, size: u64, alignment: u64) -> *mut u8 {
|
||||
let align = usize::try_from(alignment).unwrap_or(0).max(16);
|
||||
let Some(len) = usize::try_from(size).ok().and_then(|s| s.checked_add(align)) else {
|
||||
return std::ptr::null_mut();
|
||||
};
|
||||
if this.is_null() || !align.is_power_of_two() {
|
||||
return std::ptr::null_mut();
|
||||
}
|
||||
let mut block = vec![0u8; len];
|
||||
let start = block.as_mut_ptr();
|
||||
// SAFETY: the offset is below `align`, so `size` bytes fit after it.
|
||||
let at = unsafe { start.add(start.align_offset(align)) };
|
||||
// SAFETY: the title passes one of our lists.
|
||||
let uploads = unsafe { &(*this.cast::<List>()).uploads };
|
||||
// Moving the vector keeps its heap block where it is.
|
||||
uploads.lock().unwrap_or_else(|e| e.into_inner()).push(block);
|
||||
at
|
||||
}
|
||||
|
||||
/// Draw state the host has no use for (root signatures: ours come with
|
||||
/// the pipeline; depth bounds, depth order and shading rate hints): any
|
||||
/// arguments, nothing returned.
|
||||
extern "system" fn ignored_state(_: This) {}
|
||||
|
||||
/// The title's draw state (decision 0007, step 3), kept for its draws or
|
||||
/// set on the host list at once. Without a host GPU these do nothing.
|
||||
#[cfg(windows)]
|
||||
mod state {
|
||||
use super::{This, host_list, with_state};
|
||||
use crate::draw::{IndexView, VertexView};
|
||||
use windows::Win32::Foundation::RECT;
|
||||
use windows::Win32::Graphics::Direct3D12::D3D12_VIEWPORT;
|
||||
|
||||
/// `count` items at `items`, or none.
|
||||
fn items<'a, T>(items: *const T, count: u32) -> &'a [T] {
|
||||
if items.is_null() || count == 0 {
|
||||
return &[];
|
||||
}
|
||||
// SAFETY: the title passes `count` items.
|
||||
unsafe { std::slice::from_raw_parts(items, count as usize) }
|
||||
}
|
||||
|
||||
pub(super) extern "system" fn topology(this: This, topology: u32) {
|
||||
with_state(this, |list, s| s.set_topology(list, topology));
|
||||
}
|
||||
pub(super) extern "system" fn viewports(
|
||||
this: This,
|
||||
count: u32,
|
||||
viewports: *const D3D12_VIEWPORT,
|
||||
) {
|
||||
if let Some(list) = host_list(this) {
|
||||
crate::draw::viewports(list, items(viewports, count));
|
||||
}
|
||||
}
|
||||
pub(super) extern "system" fn scissors(this: This, count: u32, rects: *const RECT) {
|
||||
if let Some(list) = host_list(this) {
|
||||
crate::draw::scissors(list, items(rects, count));
|
||||
}
|
||||
}
|
||||
pub(super) extern "system" fn blend_factor(this: This, factor: *const [f32; 4]) {
|
||||
if let Some(list) = host_list(this) {
|
||||
// SAFETY: the title passes four floats or null.
|
||||
crate::draw::blend_factor(list, unsafe { factor.as_ref() });
|
||||
}
|
||||
}
|
||||
pub(super) extern "system" fn stencil_ref(this: This, reference: u32) {
|
||||
if let Some(list) = host_list(this) {
|
||||
crate::draw::stencil_ref(list, reference);
|
||||
}
|
||||
}
|
||||
pub(super) extern "system" fn heaps(this: This, count: u32, heaps: *const This) {
|
||||
with_state(this, |_, s| s.set_heaps(items(heaps, count)));
|
||||
}
|
||||
pub(super) extern "system" fn compute_table(this: This, slot: u32, handle: u64) {
|
||||
with_state(this, |_, s| s.set_table(true, slot, handle));
|
||||
}
|
||||
pub(super) extern "system" fn graphics_table(this: This, slot: u32, handle: u64) {
|
||||
with_state(this, |_, s| s.set_table(false, slot, handle));
|
||||
}
|
||||
pub(super) extern "system" fn compute_constant(this: This, slot: u32, value: u32, offset: u32) {
|
||||
with_state(this, |_, s| s.set_constants(true, slot, &[value], offset));
|
||||
}
|
||||
pub(super) extern "system" fn graphics_constant(
|
||||
this: This,
|
||||
slot: u32,
|
||||
value: u32,
|
||||
offset: u32,
|
||||
) {
|
||||
with_state(this, |_, s| s.set_constants(false, slot, &[value], offset));
|
||||
}
|
||||
pub(super) extern "system" fn compute_constants(
|
||||
this: This,
|
||||
slot: u32,
|
||||
count: u32,
|
||||
values: *const u32,
|
||||
offset: u32,
|
||||
) {
|
||||
with_state(this, |_, s| {
|
||||
s.set_constants(true, slot, items(values, count), offset)
|
||||
});
|
||||
}
|
||||
pub(super) extern "system" fn graphics_constants(
|
||||
this: This,
|
||||
slot: u32,
|
||||
count: u32,
|
||||
values: *const u32,
|
||||
offset: u32,
|
||||
) {
|
||||
with_state(this, |_, s| {
|
||||
s.set_constants(false, slot, items(values, count), offset)
|
||||
});
|
||||
}
|
||||
/// Root constant buffer, shader resource and unordered access views.
|
||||
pub(super) extern "system" fn compute_view(this: This, slot: u32, address: u64) {
|
||||
with_state(this, |_, s| s.set_view(true, slot, address));
|
||||
}
|
||||
pub(super) extern "system" fn graphics_view(this: This, slot: u32, address: u64) {
|
||||
with_state(this, |_, s| s.set_view(false, slot, address));
|
||||
}
|
||||
pub(super) extern "system" fn index_buffer(this: This, view: *const IndexView) {
|
||||
// SAFETY: the title passes a view or null.
|
||||
with_state(this, |_, s| s.set_index_buffer(unsafe { view.as_ref() }));
|
||||
}
|
||||
pub(super) extern "system" fn vertex_buffers(
|
||||
this: This,
|
||||
start: u32,
|
||||
count: u32,
|
||||
views: *const VertexView,
|
||||
) {
|
||||
with_state(this, |_, s| {
|
||||
s.set_vertex_buffers(start, items(views, count))
|
||||
});
|
||||
}
|
||||
/// `(count, handles, one range, depth)`: with one range, the handles
|
||||
/// follow the first at the render target view size (128 bytes).
|
||||
pub(super) extern "system" fn targets(
|
||||
this: This,
|
||||
count: u32,
|
||||
handles: *const u64,
|
||||
one_range: i32,
|
||||
depth: *const u64,
|
||||
) {
|
||||
let handles: Vec<u64> = if one_range != 0 && !handles.is_null() {
|
||||
// SAFETY: the title passes the first handle.
|
||||
let first = unsafe { *handles };
|
||||
(0..u64::from(count)).map(|i| first + 128 * i).collect()
|
||||
} else {
|
||||
items(handles, count).to_vec()
|
||||
};
|
||||
// SAFETY: the title passes a handle or null.
|
||||
let depth = unsafe { depth.as_ref() }.copied().unwrap_or(0);
|
||||
with_state(this, |list, s| s.set_targets(list, &handles, depth));
|
||||
}
|
||||
pub(super) extern "system" fn draw(
|
||||
this: This,
|
||||
vertices: u32,
|
||||
instances: u32,
|
||||
first: u32,
|
||||
first_instance: u32,
|
||||
) {
|
||||
super::count_draw();
|
||||
with_state(this, |list, s| {
|
||||
s.draw(list, vertices, instances, first, first_instance)
|
||||
});
|
||||
}
|
||||
pub(super) extern "system" fn dispatch(this: This, x: u32, y: u32, z: u32) {
|
||||
super::count_dispatch();
|
||||
with_state(this, |list, s| s.dispatch(list, x, y, z));
|
||||
}
|
||||
/// `DispatchMesh(x, y, z)` (the PC method of List6); the title's mesh
|
||||
/// programs take `x` groups only.
|
||||
pub(super) extern "system" fn dispatch_mesh(this: This, x: u32, y: u32, z: u32) {
|
||||
super::count_draw();
|
||||
if y * z != 1 {
|
||||
static ONCE: std::sync::Once = std::sync::Once::new();
|
||||
ONCE.call_once(|| tracing::warn!(x, y, z, "a mesh dispatch with y or z groups"));
|
||||
}
|
||||
with_state(this, |list, s| s.dispatch_mesh(list, x));
|
||||
}
|
||||
/// `DispatchMeshX(x, flags, indirect arguments, payload)`.
|
||||
/// shortcut: dispatches whose group count is in GPU memory (indirect)
|
||||
/// are dropped; make them ExecuteIndirect when the title uses them.
|
||||
pub(super) extern "system" fn dispatch_mesh_x(
|
||||
this: This,
|
||||
x: u32,
|
||||
_flags: u64,
|
||||
indirect: u64,
|
||||
_payload: u64,
|
||||
) {
|
||||
super::count_draw();
|
||||
if indirect != 0 {
|
||||
static ONCE: std::sync::Once = std::sync::Once::new();
|
||||
ONCE.call_once(|| tracing::warn!("indirect mesh dispatches dropped"));
|
||||
return;
|
||||
}
|
||||
with_state(this, |list, s| s.dispatch_mesh(list, x));
|
||||
}
|
||||
pub(super) extern "system" fn draw_indexed(
|
||||
this: This,
|
||||
indices: u32,
|
||||
instances: u32,
|
||||
first: u32,
|
||||
base: i32,
|
||||
first_instance: u32,
|
||||
) {
|
||||
super::count_draw();
|
||||
with_state(this, |list, s| {
|
||||
s.draw_indexed(list, indices, instances, first, base, first_instance)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Without a host GPU every draw state call is ignored.
|
||||
#[cfg(not(windows))]
|
||||
mod state {
|
||||
pub(super) use super::dispatch;
|
||||
pub(super) use super::draw;
|
||||
pub(super) use super::draw as draw_indexed;
|
||||
pub(super) use super::draw as dispatch_mesh;
|
||||
pub(super) use super::draw as dispatch_mesh_x;
|
||||
pub(super) use super::ignored_state as blend_factor;
|
||||
pub(super) use super::ignored_state as compute_constant;
|
||||
pub(super) use super::ignored_state as compute_constants;
|
||||
pub(super) use super::ignored_state as compute_table;
|
||||
pub(super) use super::ignored_state as compute_view;
|
||||
pub(super) use super::ignored_state as graphics_constant;
|
||||
pub(super) use super::ignored_state as graphics_constants;
|
||||
pub(super) use super::ignored_state as graphics_table;
|
||||
pub(super) use super::ignored_state as graphics_view;
|
||||
pub(super) use super::ignored_state as heaps;
|
||||
pub(super) use super::ignored_state as index_buffer;
|
||||
pub(super) use super::ignored_state as scissors;
|
||||
pub(super) use super::ignored_state as stencil_ref;
|
||||
pub(super) use super::ignored_state as targets;
|
||||
pub(super) use super::ignored_state as topology;
|
||||
pub(super) use super::ignored_state as vertex_buffers;
|
||||
pub(super) use super::ignored_state as viewports;
|
||||
}
|
||||
|
||||
fn count_draw() {
|
||||
DRAWS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Draws of the kinds the host does not run yet (indirect, mesh), and
|
||||
/// dispatches, counted per frame for the log.
|
||||
/// shortcut: dropped until their shaders translate (decision 0007).
|
||||
extern "system" fn draw(_: This) {
|
||||
count_draw();
|
||||
}
|
||||
fn count_dispatch() {
|
||||
DISPATCHES.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
extern "system" fn dispatch(_: This) {
|
||||
count_dispatch();
|
||||
}
|
||||
static DRAWS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||
static DISPATCHES: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||
|
||||
/// Draws (any kind, mesh and indirect included) and compute dispatches
|
||||
/// recorded since the last call.
|
||||
pub(crate) fn take_counts() -> (u64, u64) {
|
||||
use std::sync::atomic::Ordering::Relaxed;
|
||||
(DRAWS.swap(0, Relaxed), DISPATCHES.swap(0, Relaxed))
|
||||
}
|
||||
|
||||
/// A GPU wait for a memory value `(address, comparison, reference, ...)`.
|
||||
/// Lists run one after another and to completion, so a value another queue
|
||||
/// or the CPU has to write first cannot be waited for; nothing to do.
|
||||
extern "system" fn wait_value(_: This, _address: u64, _comparison: u32, _reference: u64) {}
|
||||
|
||||
/// The enhanced barriers `(group count, groups)`: buffer, texture and
|
||||
/// global barriers with layouts instead of states. Every host use of a
|
||||
/// title texture (clears, copies) moves its host copy to the state it needs
|
||||
/// first, so only their ordering matters: one barrier on every shader
|
||||
/// write (the title's buffer barriers order compute passes).
|
||||
extern "system" fn barrier_groups(this: This, count: u32, _groups: *const u8) {
|
||||
#[cfg(windows)]
|
||||
if count > 0
|
||||
&& let Some(list) = host_list(this)
|
||||
{
|
||||
use windows::Win32::Graphics::Direct3D12::D3D12_RESOURCE_BARRIER;
|
||||
// SAFETY: the same layout; no resource named.
|
||||
let barrier = unsafe { std::mem::transmute::<Barrier, D3D12_RESOURCE_BARRIER>(UAV_BARRIER) };
|
||||
// SAFETY: an open list.
|
||||
unsafe { list.list.ResourceBarrier(&[barrier]) };
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
let _ = (this, count);
|
||||
}
|
||||
|
||||
/// The bottom-of-pipe value writes `(address, value, flush, flags)`, 32 and
|
||||
/// 64 bits: done when the list has run, as the GPU would. Flag 1 writes the
|
||||
/// GPU timestamp instead (64-bit form), flag 2 the system timestamp.
|
||||
extern "system" fn write32(this: This, address: u64, value: u32, _flush: u32, _flags: u32) {
|
||||
defer_write(this, address, Written::Value(u64::from(value)), 4);
|
||||
}
|
||||
extern "system" fn write64(this: This, address: u64, value: u64, _flush: u32, flags: u32) {
|
||||
const GPU_TIMESTAMP: u32 = 1;
|
||||
const SYSTEM_TIMESTAMP: u32 = 2;
|
||||
let what = match flags {
|
||||
GPU_TIMESTAMP => Written::GpuTimestamp,
|
||||
SYSTEM_TIMESTAMP => Written::SystemTimestamp,
|
||||
_ => Written::Value(value),
|
||||
};
|
||||
defer_write(this, address, what, 8);
|
||||
}
|
||||
|
||||
fn defer_write(this: This, address: u64, what: Written, bytes: usize) {
|
||||
if address == 0 {
|
||||
return;
|
||||
}
|
||||
#[cfg(windows)]
|
||||
if let Some(list) = host_list(this) {
|
||||
list.defer_write(address as *mut u8, what, bytes);
|
||||
return;
|
||||
}
|
||||
let _ = this;
|
||||
// Without a host GPU nothing runs later: write now.
|
||||
what.write(address as *mut u8, bytes);
|
||||
}
|
||||
|
||||
/// The list methods by their slot in older titles' lists (the 2020-era
|
||||
/// layout): IUnknown 3, object 4, device child 1, list 1, graphics list 96
|
||||
/// (59 as on PC, then console ones), then versions 1-6 (6 + 1 + 1 + 11 + 3
|
||||
/// + 13): 140 slots.
|
||||
const METHODS: [(usize, *const ()); 52] = [
|
||||
(0, list_query as *const ()),
|
||||
(2, list_release as *const ()),
|
||||
(7, object::parent_device as *const ()), // 0x38
|
||||
(8, list_type as *const ()), // 0x40
|
||||
(9, close as *const ()), // 0x48
|
||||
(10, reset as *const ()), // 0x50
|
||||
(12, state::draw as *const ()), // 0x60 instanced
|
||||
(13, state::draw_indexed as *const ()), // 0x68 indexed
|
||||
(14, state::dispatch as *const ()), // 0x70
|
||||
(15, copy_buffer_region as *const ()), // 0x78
|
||||
(16, copy_texture_region as *const ()), // 0x80
|
||||
(17, copy_resource as *const ()), // 0x88
|
||||
(19, resolve as *const ()), // 0x98
|
||||
(20, state::topology as *const ()), // 0xa0
|
||||
(21, state::viewports as *const ()), // 0xa8
|
||||
(22, state::scissors as *const ()), // 0xb0
|
||||
(23, state::blend_factor as *const ()), // 0xb8
|
||||
(24, state::stencil_ref as *const ()), // 0xc0
|
||||
(25, set_pipeline as *const ()), // 0xc8
|
||||
(26, barrier as *const ()), // 0xd0
|
||||
(32, state::heaps as *const ()), // 0x100
|
||||
(33, ignored_state as *const ()), // 0x108 compute root signature
|
||||
(34, ignored_state as *const ()), // 0x110 graphics root signature
|
||||
(35, state::compute_table as *const ()), // 0x118
|
||||
(36, state::graphics_table as *const ()), // 0x120
|
||||
(37, state::compute_constant as *const ()), // 0x128
|
||||
(38, state::graphics_constant as *const ()), // 0x130
|
||||
(39, state::compute_constants as *const ()), // 0x138
|
||||
(40, state::graphics_constants as *const ()), // 0x140
|
||||
(41, state::compute_view as *const ()), // 0x148 CBV
|
||||
(42, state::graphics_view as *const ()), // 0x150 CBV
|
||||
(43, state::compute_view as *const ()), // 0x158 SRV
|
||||
(44, state::graphics_view as *const ()), // 0x160 SRV
|
||||
(45, state::compute_view as *const ()), // 0x168 UAV
|
||||
(46, state::graphics_view as *const ()), // 0x170 UAV
|
||||
(47, state::index_buffer as *const ()), // 0x178
|
||||
(48, state::vertex_buffers as *const ()), // 0x180
|
||||
(50, state::targets as *const ()), // 0x190
|
||||
(51, clear_dsv as *const ()), // 0x198
|
||||
(52, clear_rtv as *const ()), // 0x1a0
|
||||
(59, draw as *const ()), // 0x1d8 indirect
|
||||
(60, copy_memory as *const ()), // 0x1e0
|
||||
(68, ignored_state as *const ()), // 0x220 depth bounds
|
||||
(69, write32 as *const ()), // 0x228
|
||||
(70, write64 as *const ()), // 0x230
|
||||
(71, wait_value as *const ()), // 0x238, 32 bits
|
||||
(72, wait_value as *const ()), // 0x240, 64 bits
|
||||
(73, ignored_state as *const ()), // 0x248 pixel shader depth order
|
||||
(83, copy_texture_region_x as *const ()), // 0x298
|
||||
(84, copy_resource_x as *const ()), // 0x2a0
|
||||
(124, ignored_state as *const ()), // 0x3e0 shading rate
|
||||
(127, state::dispatch_mesh as *const ()), // 0x3f8 mesh dispatch
|
||||
];
|
||||
/// The rest of [`METHODS`], kept apart only to stay readable.
|
||||
const MORE_METHODS: [(usize, *const ()); 9] = [
|
||||
(28, query_mark as *const ()), // 0xe0 BeginQuery
|
||||
(29, query_mark as *const ()), // 0xe8 EndQuery
|
||||
(30, resolve_queries as *const ()), // 0xf0
|
||||
(78, dispatch_x as *const ()), // 0x270
|
||||
(98, state::dispatch_mesh_x as *const ()), // 0x310
|
||||
(99, driver_hint as *const ()), // 0x318
|
||||
// Pipeline syncs at the top and bottom of the pipe, 0x408 and 0x410.
|
||||
(129, sync as *const ()),
|
||||
(130, sync as *const ()),
|
||||
(137, reset_x as *const ()), // 0x448
|
||||
];
|
||||
|
||||
/// Newer titles' lists have two more methods in the console part of the
|
||||
/// base list, after the clears (0x198/0x1a0 as before) and before
|
||||
/// ExecuteIndirect, which moved from 0x1d8 to 0x1e8: every slot from 0x1d8
|
||||
/// on is two later (taken here as starting exactly at 0x1d8). Inferred from
|
||||
/// Grand Theft Auto VI's call shapes: ExecuteIndirect 0x1e8, bottom-of-pipe
|
||||
/// writes 0x238/0x240, waits 0x248/0x250, depth bounds 0x230, shading rate
|
||||
/// 0x3f0/0x400, syncs 0x418/0x420, ResetX 0x458 (asserts on failure).
|
||||
const fn newer_slot(slot: usize) -> usize {
|
||||
if slot >= 59 { slot + 2 } else { slot }
|
||||
}
|
||||
|
||||
/// Methods only newer titles' lists have. 0x490: the enhanced barrier
|
||||
/// `(group count, groups)`, with 16-byte groups `(type, count, barriers)`
|
||||
/// and 40-byte buffer barriers (title+0x95e0 builds them). 0x470 `(u64)`,
|
||||
/// called from Grand Theft Auto VI's state flush with its result unused.
|
||||
/// shortcut: 0x470's purpose is unknown; ignored until a title shows it
|
||||
/// matters.
|
||||
const NEWER_METHODS: [(usize, *const ()); 3] = [
|
||||
(142, ignored_state as *const ()),
|
||||
(146, barrier_groups as *const ()),
|
||||
(148, allocate_upload as *const ()),
|
||||
];
|
||||
|
||||
const fn list_table(newer: bool) -> [*const (); 160] {
|
||||
let mut f = object::d3d12_object(object::missing_table::<LIST, 160>());
|
||||
let mut i = 0;
|
||||
while i < METHODS.len() + MORE_METHODS.len() {
|
||||
let (slot, method) = if i < METHODS.len() {
|
||||
METHODS[i]
|
||||
} else {
|
||||
MORE_METHODS[i - METHODS.len()]
|
||||
};
|
||||
f[if newer { newer_slot(slot) } else { slot }] = method;
|
||||
i += 1;
|
||||
}
|
||||
let mut i = 0;
|
||||
while newer && i < NEWER_METHODS.len() {
|
||||
f[NEWER_METHODS[i].0] = NEWER_METHODS[i].1;
|
||||
i += 1;
|
||||
}
|
||||
f
|
||||
}
|
||||
|
||||
/// Every slot up to the limit exists and logs, for the methods newer
|
||||
/// titles add.
|
||||
static LIST_FUNCTIONS: Table<160> = Table(list_table(false));
|
||||
static NEWER_LIST_FUNCTIONS: Table<160> = Table(list_table(true));
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
@@ -666,11 +1329,25 @@ mod tests {
|
||||
(at(0x18), at(0x28), at(0x30))
|
||||
};
|
||||
assert!(put >= draw_limit && put >= api_limit);
|
||||
// The console's ID3D12GraphicsCommandList6, as Grand Theft Auto VI asks.
|
||||
let mut same = null;
|
||||
assert_eq!(list_query(list, &LIST_IIDS[7], &mut same), S_OK);
|
||||
assert_eq!(same, list);
|
||||
assert_eq!(slot::<extern "system" fn(This) -> u32>(list, 0x10)(list), 1);
|
||||
assert_eq!(slot::<extern "system" fn(This) -> u32>(list, 0x40)(list), 0);
|
||||
assert_eq!(
|
||||
slot::<extern "system" fn(This) -> HRESULT>(list, 0x48)(list),
|
||||
S_OK
|
||||
);
|
||||
// List-owned upload memory: aligned, writable, gone at reset.
|
||||
let p = allocate_upload(list, 40, 0x100);
|
||||
assert!(!p.is_null() && (p as usize).is_multiple_of(0x100));
|
||||
// SAFETY: 40 bytes were handed out.
|
||||
unsafe { p.write_bytes(0xab, 40) };
|
||||
assert!(allocate_upload(list, 8, 0x30).is_null(), "not a power of two");
|
||||
assert_eq!(reset(list, allocator, null), S_OK);
|
||||
// SAFETY: the list is ours.
|
||||
assert!(unsafe { &(*list.cast::<List>()).uploads }.lock().unwrap().is_empty());
|
||||
let release = |o: This| slot::<extern "system" fn(This) -> u32>(o, 0x10)(o);
|
||||
assert_eq!(release(list), 0);
|
||||
assert_eq!(release(allocator), 0);
|
||||
|
||||
Reference in new issue
Block a user