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,645 @@
|
||||
//! A DXIL vertex, pixel, compute or mesh shader under construction: the module,
|
||||
//! the `dx.op` declarations it calls, its signatures and bound resources,
|
||||
//! and the metadata and container that wrap it up (SM 6.6, validator 1.6).
|
||||
|
||||
use super::bitcode::{Attr, Md, Module, Ty, V};
|
||||
use super::container::{self, Binding, Psv, SigElement};
|
||||
|
||||
/// Where the shader reads its user data: `b0` in this space.
|
||||
pub const USER_DATA_SPACE: u32 = 0;
|
||||
/// Where immediate samplers are bound: `s<n>` in this space.
|
||||
pub const SAMPLER_SPACE: u32 = 0;
|
||||
/// Where root CBVs and SRVs are bound: `b<root parameter index>` and
|
||||
/// `t<root parameter index>` in this space.
|
||||
pub const ROOT_CBV_SPACE: u32 = 1;
|
||||
|
||||
/// `ShaderFlags` bits (metadata) and their `SFI0` feature bits.
|
||||
pub(crate) mod flags {
|
||||
pub const RAW_BUFFERS: u64 = 1 << 4;
|
||||
pub const TYPED_UAV_LOADS: u64 = 1 << 13;
|
||||
pub const WAVE_OPS: u64 = 1 << 19;
|
||||
pub const INT64: u64 = 1 << 20;
|
||||
pub const RESOURCE_HEAP: u64 = 1 << 30;
|
||||
pub const SAMPLER_HEAP: u64 = 1 << 31;
|
||||
}
|
||||
|
||||
pub(crate) struct Types {
|
||||
pub void: Ty,
|
||||
pub i1: Ty,
|
||||
pub i32: Ty,
|
||||
pub f32: Ty,
|
||||
pub handle: Ty,
|
||||
pub props: Ty,
|
||||
pub bind: Ty,
|
||||
pub cbuf_ret: Ty,
|
||||
pub res_ret: Ty,
|
||||
}
|
||||
|
||||
/// What a mesh shader declares beyond its thread-group size.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub(crate) struct Mesh {
|
||||
pub max_vertices: u32,
|
||||
pub max_primitives: u32,
|
||||
/// 1 lines, 2 triangles.
|
||||
pub topology: u8,
|
||||
}
|
||||
|
||||
pub(crate) struct Shader {
|
||||
pub m: Module,
|
||||
pub t: Types,
|
||||
pub pixel: bool,
|
||||
pub inputs: Vec<SigElement>,
|
||||
pub outputs: Vec<SigElement>,
|
||||
/// A mesh shader's per-primitive outputs.
|
||||
pub prims: Vec<SigElement>,
|
||||
/// A mesh shader (`threads` is its thread-group size).
|
||||
pub mesh: Option<Mesh>,
|
||||
/// Dwords of user data the shader reads (0: no user-data buffer).
|
||||
pub user_data: u32,
|
||||
/// Immediate samplers, bound as `s0..` in [`SAMPLER_SPACE`].
|
||||
pub samplers: u32,
|
||||
/// Bit n: immediate sampler n is a comparison sampler.
|
||||
pub cmp_samplers: u64,
|
||||
/// Root CBVs read, by root parameter index, with their handles.
|
||||
pub root_cbvs: Vec<(u8, V)>,
|
||||
/// Root SRVs (raw buffers) read, likewise.
|
||||
pub root_srvs: Vec<(u8, V)>,
|
||||
pub flags: u64,
|
||||
/// A compute shader with this thread-group size.
|
||||
pub threads: Option<[u32; 3]>,
|
||||
/// The wave size a compute shader requires (`WaveSize`).
|
||||
pub wave_size: Option<u32>,
|
||||
/// Thread-group shared memory, in dwords.
|
||||
pub lds_dwords: u32,
|
||||
lds: Option<V>,
|
||||
main: V,
|
||||
pub entry: usize,
|
||||
}
|
||||
|
||||
impl Shader {
|
||||
pub fn new(pixel: bool) -> Self {
|
||||
let mut m = Module::default();
|
||||
let void = m.void();
|
||||
let i1 = m.int(1);
|
||||
let i8 = m.int(8);
|
||||
let i32 = m.int(32);
|
||||
let f32 = m.float();
|
||||
let i8p = m.ptr(i8);
|
||||
let handle = m.named_struct("dx.types.Handle", vec![i8p]);
|
||||
let props = m.named_struct("dx.types.ResourceProperties", vec![i32, i32]);
|
||||
let bind = m.named_struct("dx.types.ResBind", vec![i32, i32, i32, i8]);
|
||||
let cbuf_ret = m.named_struct("dx.types.CBufRet.i32", vec![i32, i32, i32, i32]);
|
||||
let res_ret = m.named_struct("dx.types.ResRet.f32", vec![f32, f32, f32, f32, i32]);
|
||||
let main_ty = m.func_ty(void, vec![]);
|
||||
m.ptr(main_ty);
|
||||
let main = m.function("main", main_ty, None, true);
|
||||
let entry = m.new_block();
|
||||
Shader {
|
||||
m,
|
||||
t: Types {
|
||||
void,
|
||||
i1,
|
||||
i32,
|
||||
f32,
|
||||
handle,
|
||||
props,
|
||||
bind,
|
||||
cbuf_ret,
|
||||
res_ret,
|
||||
},
|
||||
pixel,
|
||||
inputs: Vec::new(),
|
||||
outputs: Vec::new(),
|
||||
prims: Vec::new(),
|
||||
mesh: None,
|
||||
user_data: 0,
|
||||
samplers: 0,
|
||||
cmp_samplers: 0,
|
||||
root_cbvs: Vec::new(),
|
||||
root_srvs: Vec::new(),
|
||||
flags: 0,
|
||||
threads: None,
|
||||
wave_size: None,
|
||||
lds_dwords: 0,
|
||||
lds: None,
|
||||
main,
|
||||
entry,
|
||||
}
|
||||
}
|
||||
|
||||
/// The thread-group shared memory: `[lds_dwords x i32]` in address
|
||||
/// space 3.
|
||||
pub fn lds(&mut self) -> V {
|
||||
if let Some(g) = self.lds {
|
||||
return g;
|
||||
}
|
||||
let arr = self.m.array(self.lds_dwords, self.t.i32);
|
||||
let g = self.m.global("lds", arr, 3);
|
||||
self.lds = Some(g);
|
||||
g
|
||||
}
|
||||
|
||||
/// Calls `dx.op.<name>` (class and overload) with `opcode` and `args`.
|
||||
pub fn op(
|
||||
&mut self,
|
||||
block: usize,
|
||||
name: &str,
|
||||
attr: Attr,
|
||||
ret: Ty,
|
||||
opcode: u32,
|
||||
args: &[V],
|
||||
) -> V {
|
||||
let mut params = vec![self.t.i32];
|
||||
params.extend(args.iter().map(|&a| self.m.type_of(a)));
|
||||
let fty = self.m.func_ty(ret, params);
|
||||
self.m.ptr(fty);
|
||||
let f = self
|
||||
.m
|
||||
.function(&format!("dx.op.{name}"), fty, Some(attr), false);
|
||||
let mut all = vec![self.m.i32(opcode)];
|
||||
all.extend(args);
|
||||
self.m.call(block, f, all)
|
||||
}
|
||||
|
||||
/// The handle of the user-data constant buffer, made in the entry block.
|
||||
pub fn user_data_handle(&mut self) -> V {
|
||||
let bind = [
|
||||
self.m.i32(0),
|
||||
self.m.i32(0),
|
||||
self.m.i32(USER_DATA_SPACE),
|
||||
self.m.i8(2), // CBV
|
||||
];
|
||||
let bind = self.m.aggregate(self.t.bind, &bind);
|
||||
let block = self.entry;
|
||||
let (i, f) = (self.m.i32(0), self.m.bool(false));
|
||||
let h = self.op(
|
||||
block,
|
||||
"createHandleFromBinding",
|
||||
Attr::ReadNone,
|
||||
self.t.handle,
|
||||
217,
|
||||
&[bind, i, f],
|
||||
);
|
||||
// The size is known in `finish`, which fixes this placeholder.
|
||||
self.annotate(block, h, 13, u32::MAX)
|
||||
}
|
||||
|
||||
/// The handle of the root CBV of root parameter `slot`, made in the
|
||||
/// entry block.
|
||||
pub fn root_cbv_handle(&mut self, slot: u8) -> V {
|
||||
if let Some(&(_, h)) = self.root_cbvs.iter().find(|r| r.0 == slot) {
|
||||
return h;
|
||||
}
|
||||
let r = self.m.i32(u32::from(slot));
|
||||
let bind = [r, r, self.m.i32(ROOT_CBV_SPACE), self.m.i8(2)];
|
||||
let bind = self.m.aggregate(self.t.bind, &bind);
|
||||
let f = self.m.bool(false);
|
||||
let block = self.entry;
|
||||
let h = self.op(
|
||||
block,
|
||||
"createHandleFromBinding",
|
||||
Attr::ReadNone,
|
||||
self.t.handle,
|
||||
217,
|
||||
&[bind, r, f],
|
||||
);
|
||||
let h = self.annotate(block, h, 13, 65536);
|
||||
self.root_cbvs.push((slot, h));
|
||||
h
|
||||
}
|
||||
|
||||
/// The handle of the root SRV (a raw buffer) of root parameter `slot`.
|
||||
pub fn root_srv_handle(&mut self, slot: u8) -> V {
|
||||
if let Some(&(_, h)) = self.root_srvs.iter().find(|r| r.0 == slot) {
|
||||
return h;
|
||||
}
|
||||
let r = self.m.i32(u32::from(slot));
|
||||
let bind = [r, r, self.m.i32(ROOT_CBV_SPACE), self.m.i8(0)];
|
||||
let bind = self.m.aggregate(self.t.bind, &bind);
|
||||
let f = self.m.bool(false);
|
||||
let block = self.entry;
|
||||
let h = self.op(
|
||||
block,
|
||||
"createHandleFromBinding",
|
||||
Attr::ReadNone,
|
||||
self.t.handle,
|
||||
217,
|
||||
&[bind, r, f],
|
||||
);
|
||||
let h = self.annotate(block, h, 11, 0);
|
||||
self.flags |= flags::RAW_BUFFERS;
|
||||
self.root_srvs.push((slot, h));
|
||||
h
|
||||
}
|
||||
|
||||
/// The handle of immediate sampler `n` (a comparison sampler when its
|
||||
/// bit in `cmp_samplers` is set).
|
||||
pub fn sampler_handle(&mut self, block: usize, n: u32) -> V {
|
||||
let bind = [
|
||||
self.m.i32(n),
|
||||
self.m.i32(n),
|
||||
self.m.i32(SAMPLER_SPACE),
|
||||
self.m.i8(3), // sampler
|
||||
];
|
||||
let bind = self.m.aggregate(self.t.bind, &bind);
|
||||
let (i, f) = (self.m.i32(n), self.m.bool(false));
|
||||
let h = self.op(
|
||||
block,
|
||||
"createHandleFromBinding",
|
||||
Attr::ReadNone,
|
||||
self.t.handle,
|
||||
217,
|
||||
&[bind, i, f],
|
||||
);
|
||||
let cmp = if self.cmp_samplers >> n & 1 != 0 {
|
||||
0x8000
|
||||
} else {
|
||||
0
|
||||
};
|
||||
self.annotate(block, h, 14 | cmp, 0)
|
||||
}
|
||||
|
||||
pub fn annotate(&mut self, block: usize, h: V, props0: u32, props1: u32) -> V {
|
||||
let p = [self.m.i32(props0), self.m.i32(props1)];
|
||||
let p = self.m.aggregate(self.t.props, &p);
|
||||
self.op(
|
||||
block,
|
||||
"annotateHandle",
|
||||
Attr::ReadNone,
|
||||
self.t.handle,
|
||||
216,
|
||||
&[h, p],
|
||||
)
|
||||
}
|
||||
|
||||
/// A descriptor heap handle, annotated with `props`.
|
||||
pub fn heap_handle(&mut self, block: usize, index: V, sampler: bool, props: (u32, u32)) -> V {
|
||||
self.flags |= if sampler {
|
||||
flags::SAMPLER_HEAP
|
||||
} else {
|
||||
flags::RESOURCE_HEAP
|
||||
};
|
||||
let (s, n) = (self.m.bool(sampler), self.m.bool(false));
|
||||
let h = self.op(
|
||||
block,
|
||||
"createHandleFromHeap",
|
||||
Attr::ReadNone,
|
||||
self.t.handle,
|
||||
218,
|
||||
&[index, s, n],
|
||||
);
|
||||
self.annotate(block, h, props.0, props.1)
|
||||
}
|
||||
|
||||
/// The finished container.
|
||||
pub fn finish(mut self) -> Vec<u8> {
|
||||
let ud_size = (self.user_data * 4).next_multiple_of(16);
|
||||
self.fix_user_data_size(ud_size);
|
||||
let mut resources = None;
|
||||
let mut bindings = Vec::new();
|
||||
let i32c = |s: &mut Self, v: u32| {
|
||||
let c = s.m.i32(v);
|
||||
s.m.md_value(c)
|
||||
};
|
||||
if self.user_data > 0
|
||||
|| self.samplers > 0
|
||||
|| !self.root_cbvs.is_empty()
|
||||
|| !self.root_srvs.is_empty()
|
||||
{
|
||||
let empty = self.m.md_str("");
|
||||
let mut cbvs = None;
|
||||
let mut cbv_list = Vec::new();
|
||||
if self.user_data > 0 {
|
||||
let arr = self.m.array(self.user_data.next_multiple_of(4), self.t.i32);
|
||||
let ty = self.m.named_struct("UserData", vec![arr]);
|
||||
let p = self.m.ptr(ty);
|
||||
let u = self.m.undef(p);
|
||||
let ops = vec![
|
||||
Some(i32c(&mut self, 0)),
|
||||
Some(self.m.md_value(u)),
|
||||
Some(empty),
|
||||
Some(i32c(&mut self, USER_DATA_SPACE)),
|
||||
Some(i32c(&mut self, 0)),
|
||||
Some(i32c(&mut self, 1)),
|
||||
Some(i32c(&mut self, ud_size)),
|
||||
None,
|
||||
];
|
||||
cbv_list.push(Some(self.m.md_node(ops)));
|
||||
bindings.push(Binding {
|
||||
kind: 2,
|
||||
space: USER_DATA_SPACE,
|
||||
register: 0,
|
||||
dxil_kind: 13,
|
||||
});
|
||||
}
|
||||
let blob = self.m.array(16384, self.t.i32);
|
||||
let ty = self.m.named_struct("RootCbv", vec![blob]);
|
||||
let p = self.m.ptr(ty);
|
||||
let u = self.m.undef(p);
|
||||
for (slot, _) in self.root_cbvs.clone() {
|
||||
let ops = vec![
|
||||
Some(i32c(&mut self, cbv_list.len() as u32)),
|
||||
Some(self.m.md_value(u)),
|
||||
Some(empty),
|
||||
Some(i32c(&mut self, ROOT_CBV_SPACE)),
|
||||
Some(i32c(&mut self, u32::from(slot))),
|
||||
Some(i32c(&mut self, 1)),
|
||||
Some(i32c(&mut self, 65536)),
|
||||
None,
|
||||
];
|
||||
cbv_list.push(Some(self.m.md_node(ops)));
|
||||
bindings.push(Binding {
|
||||
kind: 2,
|
||||
space: ROOT_CBV_SPACE,
|
||||
register: u32::from(slot),
|
||||
dxil_kind: 13,
|
||||
});
|
||||
}
|
||||
if !cbv_list.is_empty() {
|
||||
cbvs = Some(self.m.md_node(cbv_list));
|
||||
}
|
||||
let mut srvs = None;
|
||||
if !self.root_srvs.is_empty() {
|
||||
let ty = self
|
||||
.m
|
||||
.named_struct("struct.ByteAddressBuffer", vec![self.t.i32]);
|
||||
let p = self.m.ptr(ty);
|
||||
let u = self.m.undef(p);
|
||||
let mut list = Vec::new();
|
||||
for (n, (slot, _)) in self.root_srvs.clone().into_iter().enumerate() {
|
||||
let ops = vec![
|
||||
Some(i32c(&mut self, n as u32)),
|
||||
Some(self.m.md_value(u)),
|
||||
Some(empty),
|
||||
Some(i32c(&mut self, ROOT_CBV_SPACE)),
|
||||
Some(i32c(&mut self, u32::from(slot))),
|
||||
Some(i32c(&mut self, 1)),
|
||||
Some(i32c(&mut self, 11)),
|
||||
Some(i32c(&mut self, 0)),
|
||||
None,
|
||||
];
|
||||
list.push(Some(self.m.md_node(ops)));
|
||||
bindings.push(Binding {
|
||||
kind: 4,
|
||||
space: ROOT_CBV_SPACE,
|
||||
register: u32::from(slot),
|
||||
dxil_kind: 11,
|
||||
});
|
||||
}
|
||||
srvs = Some(self.m.md_node(list));
|
||||
}
|
||||
let mut samplers = None;
|
||||
if self.samplers > 0 {
|
||||
let ty = self.m.named_struct("struct.SamplerState", vec![self.t.i32]);
|
||||
let p = self.m.ptr(ty);
|
||||
let u = self.m.undef(p);
|
||||
let mut list = Vec::new();
|
||||
for n in 0..self.samplers {
|
||||
let kind = (self.cmp_samplers >> n & 1) as u32;
|
||||
let ops = vec![
|
||||
Some(i32c(&mut self, n)),
|
||||
Some(self.m.md_value(u)),
|
||||
Some(empty),
|
||||
Some(i32c(&mut self, SAMPLER_SPACE)),
|
||||
Some(i32c(&mut self, n)),
|
||||
Some(i32c(&mut self, 1)),
|
||||
// Sampler kind: 1 comparison.
|
||||
Some(i32c(&mut self, kind)),
|
||||
None,
|
||||
];
|
||||
list.push(Some(self.m.md_node(ops)));
|
||||
bindings.push(Binding {
|
||||
kind: 1,
|
||||
space: SAMPLER_SPACE,
|
||||
register: n,
|
||||
dxil_kind: 14,
|
||||
});
|
||||
}
|
||||
samplers = Some(self.m.md_node(list));
|
||||
}
|
||||
resources = Some(self.m.md_node(vec![srvs, None, cbvs, samplers]));
|
||||
// PSV0 lists them as the module does: CBVs, samplers, SRVs.
|
||||
bindings.sort_by_key(|b| match b.kind {
|
||||
2 => 0,
|
||||
1 => 1,
|
||||
_ => 2,
|
||||
});
|
||||
}
|
||||
if let Some(r) = resources {
|
||||
self.m.named_md("dx.resources", vec![r]);
|
||||
}
|
||||
|
||||
let graphics = self.threads.is_none() || self.mesh.is_some();
|
||||
if graphics {
|
||||
// shortcut: every output is declared to depend on every input; the
|
||||
// exact sets need a dependence pass. Drivers read this state.
|
||||
let scalars = |els: &[SigElement]| {
|
||||
els.iter()
|
||||
.filter_map(|e| e.row.map(|r| r * 4 + u32::from(e.col + e.cols)))
|
||||
.max()
|
||||
.unwrap_or(0)
|
||||
};
|
||||
let (ni, no) = (scalars(&self.inputs), scalars(&self.outputs));
|
||||
let mut view = vec![ni, no];
|
||||
// Mesh shaders have no inputs: then the primitive outputs' count.
|
||||
if self.mesh.is_some() {
|
||||
view.push(scalars(&self.prims));
|
||||
}
|
||||
for _ in 0..ni {
|
||||
for k in 0..no.div_ceil(32) {
|
||||
let bits = (no - 32 * k).min(32);
|
||||
view.push(if bits == 32 {
|
||||
u32::MAX
|
||||
} else {
|
||||
(1 << bits) - 1
|
||||
});
|
||||
}
|
||||
}
|
||||
let arr = self.m.array(view.len() as u32, self.t.i32);
|
||||
let elems: Vec<V> = view.iter().map(|&v| self.m.i32(v)).collect();
|
||||
let arr = self.m.aggregate(arr, &elems);
|
||||
let arr = self.m.md_value(arr);
|
||||
let view_node = self.m.md_node(vec![Some(arr)]);
|
||||
self.m.named_md("dx.viewIdState", vec![view_node]);
|
||||
}
|
||||
|
||||
let sigs = if graphics {
|
||||
let ins = self.signature_md(self.inputs.clone());
|
||||
let outs = self.signature_md(self.outputs.clone());
|
||||
let prims = self.signature_md(self.prims.clone());
|
||||
Some(self.m.md_node(vec![ins, outs, prims]))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
// Entry properties: shader flags (tag 0), thread-group size (4),
|
||||
// wave size (11).
|
||||
let mut props = Vec::new();
|
||||
if self.flags != 0 {
|
||||
props.push(i32c(&mut self, 0));
|
||||
let i64t = self.m.int(64);
|
||||
let f = self.m.int_const(i64t, self.flags as i64);
|
||||
props.push(self.m.md_value(f));
|
||||
}
|
||||
if let Some(threads) = self.threads {
|
||||
let t = threads.map(|n| Some(i32c(&mut self, n)));
|
||||
let t = self.m.md_node(t.to_vec());
|
||||
match self.mesh {
|
||||
// Mesh state (tag 9): threads, maximum vertices and
|
||||
// primitives, topology, payload bytes.
|
||||
Some(mesh) => {
|
||||
props.push(i32c(&mut self, 9));
|
||||
let state = [
|
||||
mesh.max_vertices,
|
||||
mesh.max_primitives,
|
||||
mesh.topology.into(),
|
||||
0,
|
||||
]
|
||||
.map(|n| Some(i32c(&mut self, n)));
|
||||
let mut node = vec![Some(t)];
|
||||
node.extend(state);
|
||||
props.push(self.m.md_node(node));
|
||||
}
|
||||
None => {
|
||||
props.push(i32c(&mut self, 4));
|
||||
props.push(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(n) = self.wave_size {
|
||||
props.push(i32c(&mut self, 11));
|
||||
let n = Some(i32c(&mut self, n));
|
||||
props.push(self.m.md_node(vec![n]));
|
||||
}
|
||||
let props =
|
||||
(!props.is_empty()).then(|| self.m.md_node(props.into_iter().map(Some).collect()));
|
||||
let main = self.m.md_value(self.main);
|
||||
let name = self.m.md_str("main");
|
||||
let entry = self
|
||||
.m
|
||||
.md_node(vec![Some(main), Some(name), sigs, resources, props]);
|
||||
|
||||
let ident = self.m.md_str("victory");
|
||||
let ident = self.m.md_node(vec![Some(ident)]);
|
||||
self.m.named_md("llvm.ident", vec![ident]);
|
||||
let one = i32c(&mut self, 1);
|
||||
let six = i32c(&mut self, 6);
|
||||
let version = self.m.md_node(vec![Some(one), Some(six)]);
|
||||
self.m.named_md("dx.version", vec![version]);
|
||||
self.m.named_md("dx.valver", vec![version]);
|
||||
// Program kinds: 0 pixel, 1 vertex, 5 compute, 13 mesh.
|
||||
let (name, kind) = match (self.threads, self.pixel) {
|
||||
_ if self.mesh.is_some() => ("ms", 13u32),
|
||||
(Some(_), _) => ("cs", 5u32),
|
||||
(None, true) => ("ps", 0),
|
||||
(None, false) => ("vs", 1),
|
||||
};
|
||||
let name = self.m.md_str(name);
|
||||
let sm = self.m.md_node(vec![Some(name), Some(six), Some(six)]);
|
||||
self.m.named_md("dx.shaderModel", vec![sm]);
|
||||
self.m.named_md("dx.entryPoints", vec![entry]);
|
||||
|
||||
let bitcode = self.m.write();
|
||||
let mut dxil = Vec::with_capacity(24 + bitcode.len());
|
||||
dxil.extend((kind << 16 | 0x66).to_le_bytes());
|
||||
dxil.extend((((24 + bitcode.len()) / 4) as u32).to_le_bytes());
|
||||
dxil.extend(b"DXIL");
|
||||
dxil.extend(0x106u32.to_le_bytes());
|
||||
dxil.extend(16u32.to_le_bytes());
|
||||
dxil.extend((bitcode.len() as u32).to_le_bytes());
|
||||
dxil.extend(&bitcode);
|
||||
|
||||
let mut features = 0u64;
|
||||
if self.flags & flags::TYPED_UAV_LOADS != 0 {
|
||||
features |= 0x800;
|
||||
}
|
||||
if self.flags & flags::WAVE_OPS != 0 {
|
||||
features |= 0x4000;
|
||||
}
|
||||
if self.flags & flags::INT64 != 0 {
|
||||
features |= 0x8000;
|
||||
}
|
||||
if self.flags & flags::RESOURCE_HEAP != 0 {
|
||||
features |= 0x200_0000;
|
||||
}
|
||||
if self.flags & flags::SAMPLER_HEAP != 0 {
|
||||
features |= 0x400_0000;
|
||||
}
|
||||
let sfi0 = features.to_le_bytes();
|
||||
let isg1 = container::signature(&self.inputs, true);
|
||||
let osg1 = container::signature(&self.outputs, false);
|
||||
let flag = if self.pixel {
|
||||
self.outputs.iter().any(|o| (17..=19).contains(&o.kind))
|
||||
} else {
|
||||
self.outputs.iter().any(|o| o.kind == 3)
|
||||
};
|
||||
let psv0 = container::psv(&Psv {
|
||||
stage: kind as u8,
|
||||
flag: flag && self.threads.is_none(),
|
||||
inputs: &self.inputs,
|
||||
outputs: &self.outputs,
|
||||
prims: &self.prims,
|
||||
mesh: self.mesh.map(|m| (m, self.lds_dwords * 4)),
|
||||
bindings: &bindings,
|
||||
threads: self.threads.unwrap_or_default(),
|
||||
wave_size: self.wave_size,
|
||||
});
|
||||
let hash = [0u8; 20];
|
||||
let psg1 = container::signature(&self.prims, false);
|
||||
let mut parts: Vec<(&[u8; 4], &[u8])> =
|
||||
vec![(b"SFI0", &sfi0), (b"ISG1", &isg1), (b"OSG1", &osg1)];
|
||||
if self.mesh.is_some() {
|
||||
parts.push((b"PSG1", &psg1));
|
||||
}
|
||||
parts.extend([(b"PSV0", &psv0[..]), (b"HASH", &hash), (b"DXIL", &dxil)]);
|
||||
container::build(&parts)
|
||||
}
|
||||
|
||||
/// The user-data buffer's annotation carries its size, known only now.
|
||||
fn fix_user_data_size(&mut self, size: u32) {
|
||||
let old = [self.m.i32(13), self.m.i32(u32::MAX)];
|
||||
let old = self.m.aggregate(self.t.props, &old);
|
||||
let new = [self.m.i32(13), self.m.i32(size)];
|
||||
let new = self.m.aggregate(self.t.props, &new);
|
||||
self.m.replace_const(old, new);
|
||||
}
|
||||
|
||||
fn signature_md(&mut self, elements: Vec<SigElement>) -> Option<Md> {
|
||||
if elements.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let mut list = Vec::new();
|
||||
for (id, e) in elements.iter().enumerate() {
|
||||
let c32 = |s: &mut Self, v: u32| {
|
||||
let c = s.m.i32(v);
|
||||
Some(s.m.md_value(c))
|
||||
};
|
||||
let c8 = |s: &mut Self, v: u8| {
|
||||
let c = s.m.i8(v);
|
||||
Some(s.m.md_value(c))
|
||||
};
|
||||
let idx = c32(self, e.index);
|
||||
let indices = Some(self.m.md_node(vec![idx]));
|
||||
let usage = if e.usage != 0 {
|
||||
let (tag, mask) = (c32(self, 3), c32(self, u32::from(e.usage)));
|
||||
Some(self.m.md_node(vec![tag, mask]))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let ops = vec![
|
||||
c32(self, id as u32),
|
||||
Some(self.m.md_str(&e.name)),
|
||||
c8(self, e.comp),
|
||||
c8(self, e.kind),
|
||||
indices,
|
||||
c8(self, e.interp),
|
||||
c32(self, 1),
|
||||
c8(self, e.cols),
|
||||
c32(self, e.row.unwrap_or(u32::MAX)),
|
||||
c8(self, if e.row.is_some() { e.col } else { u8::MAX }),
|
||||
usage,
|
||||
];
|
||||
list.push(Some(self.m.md_node(ops)));
|
||||
}
|
||||
Some(self.m.md_node(list))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user