draw.rs 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. //! Draws on the host GPU (decision 0007, step 3). A list keeps the state
  2. //! the title sets for its draws (pipeline, descriptor heaps, root
  3. //! arguments, vertex and index buffers, targets); each draw then brings the
  4. //! host list up to date: the host pipeline and our root signature, the
  5. //! user data the translated shaders read, the host copies of the buffers
  6. //! and descriptors they read, and the states of the textures involved.
  7. //! State the host keeps across draws (viewports, scissors, blend factor,
  8. //! stencil reference, topology, targets) is set on the host list as the
  9. //! title sets it.
  10. use std::sync::atomic::{AtomicU64, Ordering};
  11. use victory_shader::{ResourceType, RootType, UsedResource};
  12. use crate::descriptor::View;
  13. use windows::Win32::Foundation::RECT;
  14. use windows::Win32::Graphics::Direct3D::D3D_PRIMITIVE_TOPOLOGY;
  15. use windows::Win32::Graphics::Direct3D12::*;
  16. use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT;
  17. use windows::core::Interface;
  18. use crate::host::HostList;
  19. use crate::object::This;
  20. use crate::pipeline::host::HostPipeline;
  21. /// A root argument as the title set it.
  22. #[derive(Debug, Clone, Default)]
  23. enum Root {
  24. #[default]
  25. None,
  26. /// A descriptor table's first descriptor (an address in a heap).
  27. Table(u64),
  28. Constants(Vec<u32>),
  29. /// A root view's GPU address.
  30. View(u64),
  31. }
  32. #[repr(C)]
  33. #[derive(Debug, Clone, Copy, Default)]
  34. pub(crate) struct VertexView {
  35. address: u64,
  36. size: u32,
  37. stride: u32,
  38. }
  39. #[repr(C)]
  40. #[derive(Debug, Clone, Copy, Default)]
  41. pub(crate) struct IndexView {
  42. address: u64,
  43. size: u32,
  44. format: u32,
  45. }
  46. /// What one title list has set, and what its host list was last given.
  47. #[derive(Default)]
  48. pub(crate) struct State {
  49. pipeline: usize,
  50. /// View heap, sampler heap.
  51. heaps: [usize; 2],
  52. graphics: Vec<Root>,
  53. compute: Vec<Root>,
  54. vertex: [VertexView; 32],
  55. index: IndexView,
  56. /// Bound render target and depth resources, for their host states.
  57. targets: Vec<usize>,
  58. depth: usize,
  59. /// The title's primitive topology (the host's may differ).
  60. topology: u32,
  61. /// What the host list has: pipeline, root signature, heaps.
  62. host_pipeline: usize,
  63. /// Graphics, compute.
  64. host_roots: [usize; 2],
  65. host_heaps: [usize; 2],
  66. /// Tables made afresh in this list: (table, what it holds) → first
  67. /// dynamic slot.
  68. fresh_tables: std::collections::HashMap<(u64, u64), u32>,
  69. /// The dynamic slots the list holds: title heap, first, count; given
  70. /// back when the list is reset or released.
  71. dynamic: Vec<(usize, u32, u32)>,
  72. }
  73. impl Drop for State {
  74. fn drop(&mut self) {
  75. for &(heap, first, n) in &self.dynamic {
  76. crate::descriptor::release_dynamic(heap, first, n);
  77. }
  78. }
  79. }
  80. /// Draws recorded on the host GPU since the last frame line.
  81. static DRAWN: AtomicU64 = AtomicU64::new(0);
  82. /// Draws run on the host so far.
  83. pub(crate) fn drawn() -> u64 {
  84. DRAWN.load(Ordering::Relaxed)
  85. }
  86. /// The draws traced since the last present (diagnostics builds, with
  87. /// debug logging for this module): logged when the frame comes out black.
  88. #[cfg(feature = "diagnostics")]
  89. static FRAME: std::sync::Mutex<Vec<String>> = std::sync::Mutex::new(Vec::new());
  90. /// The draws traced since the last call.
  91. #[cfg(feature = "diagnostics")]
  92. pub(crate) fn take_frame() -> Vec<String> {
  93. std::mem::take(&mut *FRAME.lock().unwrap_or_else(|e| e.into_inner()))
  94. }
  95. /// Draws, mesh dispatches and dispatches recorded but not run on the host
  96. /// (no host pipeline) since the last call.
  97. pub(crate) fn take_dropped() -> u64 {
  98. DROPPED.swap(0, Ordering::Relaxed)
  99. }
  100. static DROPPED: AtomicU64 = AtomicU64::new(0);
  101. /// Marks the last traced draw as not run on the host.
  102. #[cfg(feature = "diagnostics")]
  103. fn dropped(pipeline: usize) {
  104. crate::pipeline::note_drop(pipeline as This);
  105. if let Some(last) = FRAME.lock().unwrap_or_else(|e| e.into_inner()).last_mut() {
  106. last.push_str(" DROPPED");
  107. }
  108. }
  109. /// Dispatches run on the host so far.
  110. static DISPATCHED: AtomicU64 = AtomicU64::new(0);
  111. pub(crate) fn dispatched() -> u64 {
  112. DISPATCHED.load(Ordering::Relaxed)
  113. }
  114. /// The host address of a root view: its buffer's host copy, or for a
  115. /// constant buffer not 256-byte aligned there (the console needs 16) a
  116. /// copy in upload memory.
  117. /// shortcut: a root view has no size; constant buffers are taken as 64 KiB,
  118. /// other views as 1 MiB (both cut at their buffer's end).
  119. fn root_view(list: &HostList, address: u64, srv: bool) -> Option<u64> {
  120. let shadow = crate::shadow::find(address, 1)?;
  121. let len = shadow
  122. .left(address)
  123. .min(if srv { 1 << 20 } else { 1 << 16 });
  124. let gpu = shadow.gpu(address);
  125. if srv || gpu % 256 == 0 {
  126. shadow.refresh(list, address, len);
  127. return Some(gpu);
  128. }
  129. let (gpu, to) = list.scratch(len)?;
  130. list.defer_fill(to, address as *const u8, len as usize);
  131. Some(gpu)
  132. }
  133. macro_rules! once {
  134. ($($arg:tt)*) => {{
  135. static ONCE: std::sync::Once = std::sync::Once::new();
  136. ONCE.call_once(|| tracing::warn!($($arg)*));
  137. }};
  138. }
  139. fn set(roots: &mut Vec<Root>, slot: u32, root: Root) {
  140. let slot = slot as usize;
  141. if roots.len() <= slot {
  142. roots.resize(slot + 1, Root::None);
  143. }
  144. roots[slot] = root;
  145. }
  146. impl State {
  147. pub(crate) fn reset(&mut self, pipeline: This) {
  148. *self = State::default();
  149. self.pipeline = pipeline as usize;
  150. }
  151. /// The title's topology; console-only ones become host lists (see
  152. /// [`crate::primitive`]).
  153. pub(crate) fn set_topology(&mut self, list: &HostList, topology: u32) {
  154. self.topology = topology;
  155. let host = match topology {
  156. RECTANGLES => 4,
  157. TRIANGLE_FAN | LINE_LOOP | QUADS | QUAD_STRIP => {
  158. once!(topology, "console topology drawn as a triangle list");
  159. 4
  160. }
  161. t => t,
  162. };
  163. // SAFETY: an open list.
  164. unsafe {
  165. list.list
  166. .IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY(host as i32))
  167. };
  168. }
  169. pub(crate) fn set_pipeline(&mut self, pipeline: This) {
  170. self.pipeline = pipeline as usize;
  171. }
  172. pub(crate) fn set_heaps(&mut self, heaps: &[This]) {
  173. self.heaps = [0; 2];
  174. for &h in heaps {
  175. if !h.is_null() {
  176. let samplers = crate::descriptor::heap(h).samplers();
  177. self.heaps[usize::from(samplers)] = h as usize;
  178. }
  179. }
  180. }
  181. fn roots(&mut self, compute: bool) -> &mut Vec<Root> {
  182. if compute {
  183. &mut self.compute
  184. } else {
  185. &mut self.graphics
  186. }
  187. }
  188. pub(crate) fn set_table(&mut self, compute: bool, slot: u32, handle: u64) {
  189. set(self.roots(compute), slot, Root::Table(handle));
  190. }
  191. pub(crate) fn set_view(&mut self, compute: bool, slot: u32, address: u64) {
  192. set(self.roots(compute), slot, Root::View(address));
  193. }
  194. pub(crate) fn set_constants(&mut self, compute: bool, slot: u32, values: &[u32], offset: u32) {
  195. let roots = self.roots(compute);
  196. let s = slot as usize;
  197. if !matches!(roots.get(s), Some(Root::Constants(_))) {
  198. set(roots, slot, Root::Constants(Vec::new()));
  199. }
  200. if let Root::Constants(c) = &mut roots[s] {
  201. let end = offset as usize + values.len();
  202. if c.len() < end {
  203. c.resize(end, 0);
  204. }
  205. c[offset as usize..end].copy_from_slice(values);
  206. }
  207. }
  208. pub(crate) fn set_vertex_buffers(&mut self, start: u32, views: &[VertexView]) {
  209. for (i, v) in views.iter().enumerate() {
  210. if let Some(slot) = self.vertex.get_mut(start as usize + i) {
  211. *slot = *v;
  212. }
  213. }
  214. }
  215. pub(crate) fn set_index_buffer(&mut self, view: Option<&IndexView>) {
  216. self.index = view.copied().unwrap_or_default();
  217. }
  218. /// Render targets and depth, set on the host list at once.
  219. pub(crate) fn set_targets(&mut self, list: &HostList, handles: &[u64], depth: u64) {
  220. let Some(host) = crate::host::host() else {
  221. return;
  222. };
  223. self.targets.clear();
  224. let mut rtvs = Vec::new();
  225. for &h in handles {
  226. let Some(record) = crate::descriptor::rtv_record(h) else {
  227. once!(
  228. handle = format_args!("{h:#x}"),
  229. "render target without a recorded view"
  230. );
  231. continue;
  232. };
  233. let Some(texture) = crate::resource::host_resource(record.resource) else {
  234. continue;
  235. };
  236. self.targets.push(record.resource as usize);
  237. #[cfg(feature = "diagnostics")]
  238. crate::capture::note_target(record.resource);
  239. rtvs.push(host.rtv(texture, record.desc().as_ref()));
  240. }
  241. self.depth = 0;
  242. let dsv = crate::descriptor::dsv_record(depth).and_then(|record| {
  243. let texture = crate::resource::host_resource(record.resource)?;
  244. self.depth = record.resource as usize;
  245. #[cfg(feature = "diagnostics")]
  246. crate::capture::note_target(record.resource);
  247. Some(host.dsv(texture, record.depth_desc().as_ref()))
  248. });
  249. // SAFETY: an open list; the views were just made.
  250. unsafe {
  251. list.list.OMSetRenderTargets(
  252. rtvs.len() as u32,
  253. (!rtvs.is_empty()).then_some(rtvs.as_ptr()),
  254. false,
  255. dsv.as_ref().map(std::ptr::from_ref),
  256. )
  257. };
  258. }
  259. /// The user-data value of a root argument, as translated shaders read
  260. /// it: a table's byte offset in its heap, a constant's value.
  261. fn user_value(&self, compute: bool, slot: u8, root: RootType, dword: u32) -> u32 {
  262. match (self.roots_ref(compute).get(usize::from(slot)), root) {
  263. (Some(Root::Table(handle)), RootType::Table) => match self.heap_of(*handle) {
  264. Some(heap) => (handle - heap.start) as u32,
  265. None => {
  266. once!(
  267. handle = format_args!("{handle:#x}"),
  268. "descriptor table outside the bound heaps"
  269. );
  270. 0
  271. }
  272. },
  273. (Some(Root::Constants(c)), RootType::Constants) => {
  274. c.get(dword as usize).copied().unwrap_or(0)
  275. }
  276. _ => {
  277. once!(
  278. slot,
  279. ?root,
  280. "a shader reads a root argument the title did not set"
  281. );
  282. 0
  283. }
  284. }
  285. }
  286. /// The bound heap holding `handle`.
  287. fn heap_of(&self, handle: u64) -> Option<&'static crate::descriptor::Heap> {
  288. self.heaps
  289. .iter()
  290. .filter(|&&h| h != 0)
  291. .map(|&h| crate::descriptor::heap(h as This))
  292. .find(|h| h.index(handle).is_some())
  293. }
  294. /// Brings the host list up to date for a draw; false if the draw cannot
  295. /// run on the host.
  296. fn prepare(&mut self, list: &HostList, indexed: bool) -> bool {
  297. self.prepare_for(list, indexed, false)
  298. }
  299. /// As [`State::prepare`], for draws (`mesh` false) or mesh dispatches.
  300. fn prepare_for(&mut self, list: &HostList, indexed: bool, mesh: bool) -> bool {
  301. let Some(p) = crate::pipeline::host_pipeline(self.pipeline as This) else {
  302. return false;
  303. };
  304. if p.compute || p.mesh != mesh {
  305. once!(mesh, "a draw or mesh dispatch with another kind of pipeline");
  306. return false;
  307. }
  308. self.bind(list, p, false);
  309. let l = &list.list;
  310. // Vertex buffers the input layout reads.
  311. let mut views = [D3D12_VERTEX_BUFFER_VIEW::default(); 32];
  312. let mut count = 0;
  313. for (slot, (view, &v)) in views.iter_mut().zip(&self.vertex).enumerate() {
  314. if p.slots & 1 << slot == 0 {
  315. continue;
  316. }
  317. count = slot + 1;
  318. if v.address == 0 || v.size == 0 {
  319. continue;
  320. }
  321. let Some(shadow) = crate::shadow::find(v.address, u64::from(v.size)) else {
  322. continue;
  323. };
  324. shadow.refresh(list, v.address, u64::from(v.size));
  325. *view = D3D12_VERTEX_BUFFER_VIEW {
  326. BufferLocation: shadow.gpu(v.address),
  327. SizeInBytes: v.size,
  328. StrideInBytes: v.stride,
  329. };
  330. }
  331. // SAFETY: an open list; the views name live host buffers.
  332. unsafe {
  333. if count > 0 {
  334. l.IASetVertexBuffers(0, Some(&views[..count]));
  335. }
  336. }
  337. if indexed {
  338. let v = self.index;
  339. let Some(shadow) = crate::shadow::find(v.address, u64::from(v.size)) else {
  340. return false;
  341. };
  342. shadow.refresh(list, v.address, u64::from(v.size));
  343. let view = D3D12_INDEX_BUFFER_VIEW {
  344. BufferLocation: shadow.gpu(v.address),
  345. SizeInBytes: v.size,
  346. Format: DXGI_FORMAT(v.format as i32),
  347. };
  348. // SAFETY: an open list; the view names a live host buffer.
  349. unsafe { l.IASetIndexBuffer(Some(&view)) };
  350. }
  351. const RENDER_TARGET: u32 = 0x4;
  352. const DEPTH_WRITE: u32 = 0x10;
  353. for &t in &self.targets {
  354. crate::list::ensure_state(list, t as This, RENDER_TARGET);
  355. }
  356. if self.depth != 0 {
  357. crate::list::ensure_state(list, self.depth as This, DEPTH_WRITE);
  358. }
  359. true
  360. }
  361. /// A descriptor a shader reads through a table: its host slot made if
  362. /// it changed, constant data copied, textures made readable.
  363. /// What draws and dispatches share: heaps, our root signature, the
  364. /// pipeline, and per stage the user data, root views and the
  365. /// descriptors its tables hold.
  366. fn bind(&mut self, list: &HostList, p: &HostPipeline, compute: bool) {
  367. let l = &list.list;
  368. // Heaps first: a root signature with directly indexed heaps must be
  369. // set after them.
  370. if self.host_heaps != self.heaps {
  371. let heaps: Vec<Option<ID3D12DescriptorHeap>> = self
  372. .heaps
  373. .iter()
  374. .filter(|&&h| h != 0)
  375. .filter_map(|&h| crate::descriptor::heap(h as This).host())
  376. .map(|h| Some(h.heap.clone()))
  377. .collect();
  378. heaps.iter().flatten().for_each(|h| list.keep(h));
  379. // SAFETY: an open list and shader-visible heaps.
  380. unsafe { l.SetDescriptorHeaps(&heaps) };
  381. self.host_heaps = self.heaps;
  382. self.host_roots = [0; 2];
  383. }
  384. let root = p.root.as_raw() as usize;
  385. if self.host_roots[usize::from(compute)] != root {
  386. // SAFETY: an open list and a live root signature.
  387. unsafe {
  388. if compute {
  389. l.SetComputeRootSignature(&p.root);
  390. } else {
  391. l.SetGraphicsRootSignature(&p.root);
  392. }
  393. }
  394. self.host_roots[usize::from(compute)] = root;
  395. }
  396. // By host object: a title pipeline released and another made at its
  397. // address is another host pipeline (the list keeps the old one).
  398. if self.host_pipeline != p.pso.as_raw() as usize {
  399. // SAFETY: an open list and a live pipeline.
  400. unsafe { l.SetPipelineState(&p.pso) };
  401. self.host_pipeline = p.pso.as_raw() as usize;
  402. list.used_pipeline(&p.name);
  403. // The title may release the pipeline before it submits the list.
  404. list.keep(&p.pso);
  405. list.keep(&p.root);
  406. }
  407. for stage in &p.stages {
  408. let t = stage.translated();
  409. let made = self.tables(list, &t.used, compute);
  410. if let Some((param, dwords)) = stage.user_data {
  411. let mut values = vec![0u32; dwords as usize];
  412. for u in &t.host.user_data {
  413. let fresh = made
  414. .iter()
  415. .find(|m| m.0 == u.slot && u.root == RootType::Table);
  416. values[u.index as usize] = match fresh {
  417. Some(&(_, offset)) => offset,
  418. None => self.user_value(compute, u.slot, u.root, u.dword),
  419. };
  420. }
  421. // SAFETY: an open list; `values` covers the parameter.
  422. unsafe {
  423. if compute {
  424. l.SetComputeRoot32BitConstants(param, dwords, values.as_ptr().cast(), 0);
  425. } else {
  426. l.SetGraphicsRoot32BitConstants(param, dwords, values.as_ptr().cast(), 0);
  427. }
  428. }
  429. }
  430. for (views, srv) in [(&stage.root_cbvs, false), (&stage.root_srvs, true)] {
  431. for &(slot, param) in views {
  432. let Some(Root::View(address)) = self.roots_ref(compute).get(usize::from(slot))
  433. else {
  434. once!(slot, "a shader reads a root view the title did not set");
  435. continue;
  436. };
  437. let Some(gpu) = root_view(list, *address, srv) else {
  438. continue;
  439. };
  440. // SAFETY: an open list; the address is in live memory.
  441. unsafe {
  442. match (compute, srv) {
  443. (false, false) => l.SetGraphicsRootConstantBufferView(param, gpu),
  444. (false, true) => l.SetGraphicsRootShaderResourceView(param, gpu),
  445. (true, false) => l.SetComputeRootConstantBufferView(param, gpu),
  446. (true, true) => l.SetComputeRootShaderResourceView(param, gpu),
  447. }
  448. }
  449. }
  450. }
  451. }
  452. }
  453. /// Runs a dispatch on the host.
  454. pub(crate) fn dispatch(&mut self, list: &HostList, x: u32, y: u32, z: u32) {
  455. let Some(p) = crate::pipeline::host_pipeline(self.pipeline as This) else {
  456. once!(
  457. pipeline = format_args!("{:#x}", self.pipeline),
  458. "a dispatch without a host pipeline dropped"
  459. );
  460. DROPPED.fetch_add(1, Ordering::Relaxed);
  461. #[cfg(feature = "diagnostics")]
  462. crate::pipeline::note_drop(self.pipeline as This);
  463. return;
  464. };
  465. if !p.compute {
  466. once!("a dispatch with a graphics pipeline");
  467. return;
  468. }
  469. self.bind(list, p, true);
  470. #[cfg(feature = "diagnostics")]
  471. list.note_op(|| self.op_text(format!("dispatch {x}x{y}x{z}"), true));
  472. // SAFETY: an open list with everything set.
  473. unsafe { list.list.Dispatch(x, y, z) };
  474. DISPATCHED.fetch_add(1, Ordering::Relaxed);
  475. }
  476. /// What a draw or dispatch runs, for the device-removed report
  477. /// (diagnostics): the pipeline, then per stage the user data it gets
  478. /// (with the view at that heap index, if one is), the host addresses
  479. /// of its root views and the views its tables name.
  480. #[cfg(feature = "diagnostics")]
  481. fn op_text(&self, kind: String, compute: bool) -> String {
  482. use std::fmt::Write;
  483. let Some(p) = crate::pipeline::host_pipeline(self.pipeline as This) else {
  484. return kind;
  485. };
  486. let mut text = format!("{kind} {}", p.name);
  487. let views = (self.heaps[0] != 0)
  488. .then(|| crate::descriptor::heap(self.heaps[0] as This).host())
  489. .flatten();
  490. for stage in &p.stages {
  491. let t = stage.translated();
  492. let _ = write!(text, " | {}:", stage.shader.hash);
  493. for u in &t.host.user_data {
  494. let v = self.user_value(compute, u.slot, u.root, u.dword);
  495. let _ = write!(text, " u{}={v:#x}", u.index);
  496. let index = if u.root == RootType::Table { v / 32 } else { v };
  497. if let Some(slot) = views.and_then(|h| h.describe_slot(index)) {
  498. let _ = write!(text, " [heap {index}: {slot}]");
  499. }
  500. }
  501. for &(slot, _) in stage.root_cbvs.iter().chain(&stage.root_srvs) {
  502. if let Some(Root::View(address)) = self.roots_ref(compute).get(usize::from(slot)) {
  503. let host = crate::shadow::find(*address, 1)
  504. .map(|s| (s.gpu(*address), s.left(*address)));
  505. let _ = write!(text, " root{slot}={address:#x} host {host:#x?}");
  506. }
  507. }
  508. }
  509. let _ = write!(text, " tables {:?}", self.reads(compute));
  510. text
  511. }
  512. /// Runs a mesh dispatch of `x` groups on the host (the title's mesh
  513. /// programs are one-dimensional).
  514. pub(crate) fn dispatch_mesh(&mut self, list: &HostList, x: u32) {
  515. #[cfg(feature = "diagnostics")]
  516. self.trace("mesh", x, 0);
  517. let ran = self.prepare_for(list, false, true)
  518. && match list.list.cast::<ID3D12GraphicsCommandList6>() {
  519. Ok(l6) => {
  520. #[cfg(feature = "diagnostics")]
  521. list.note_op(|| self.op_text(format!("mesh {x}"), false));
  522. // SAFETY: an open list with everything set.
  523. unsafe { l6.DispatchMesh(x, 1, 1) };
  524. DRAWN.fetch_add(1, Ordering::Relaxed);
  525. true
  526. }
  527. Err(_) => false,
  528. };
  529. if !ran {
  530. DROPPED.fetch_add(1, Ordering::Relaxed);
  531. #[cfg(feature = "diagnostics")]
  532. dropped(self.pipeline);
  533. }
  534. }
  535. fn roots_ref(&self, compute: bool) -> &Vec<Root> {
  536. if compute {
  537. &self.compute
  538. } else {
  539. &self.graphics
  540. }
  541. }
  542. fn table_entry(&self, list: &HostList, u: &UsedResource, compute: bool) {
  543. let Some(Root::Table(table)) = self.roots_ref(compute).get(usize::from(u.slot)) else {
  544. return;
  545. };
  546. let handle = table + u64::from(u.table_offset_dwords) * 4;
  547. let Some(heap) = self.heap_of(handle) else {
  548. return;
  549. };
  550. let (Some(host), Some(index)) = (heap.host(), heap.index(handle)) else {
  551. return;
  552. };
  553. if let Some(view) = host.mirror(index, handle, true) {
  554. readable(list, u, &view);
  555. }
  556. }
  557. /// The descriptors a shader reads through tables. Tables holding a
  558. /// constant buffer are made afresh for the draw in dynamic slots, with
  559. /// the constant data copied to upload memory when the list is
  560. /// submitted: the host wants constant buffers 256-byte aligned, the
  561. /// console only 16. Returns those tables' new byte offsets by root
  562. /// parameter; the other tables' slots are made from the title's.
  563. ///
  564. /// Within a list, the same table holding the same descriptors is made
  565. /// once: its constant data is copied at submission either way, and the
  566. /// big tables the world binds would otherwise take hundreds of slots per
  567. /// draw, wrapping the dynamic slots onto lists not yet submitted.
  568. fn tables(&mut self, list: &HostList, used: &[UsedResource], compute: bool) -> Vec<(u8, u32)> {
  569. let tables = |u: &&UsedResource| u.root == RootType::Table;
  570. let mut fresh: Vec<u8> = used
  571. .iter()
  572. .filter(tables)
  573. .filter(|u| u.kind == ResourceType::Cbv)
  574. .map(|u| u.slot)
  575. .collect();
  576. // Tables reaching past a host heap smaller than the title's (the
  577. // host's limit, 1,000,000 views on NVIDIA) are made afresh too: the
  578. // title's slots there have no host slot of their own.
  579. for u in used.iter().filter(tables) {
  580. if fresh.contains(&u.slot) {
  581. continue;
  582. }
  583. let Some(&Root::Table(table)) = self.roots_ref(compute).get(usize::from(u.slot)) else {
  584. continue;
  585. };
  586. let end = table + u64::from(u.table_offset_dwords) * 4;
  587. let Some(heap) = self.heap_of(table) else {
  588. continue;
  589. };
  590. let (Some(host), Some(index)) = (heap.host(), heap.index(end)) else {
  591. continue;
  592. };
  593. if index >= host.count() {
  594. fresh.push(u.slot);
  595. }
  596. }
  597. fresh.sort_unstable();
  598. fresh.dedup();
  599. for u in used.iter().filter(tables) {
  600. if !fresh.contains(&u.slot) {
  601. self.table_entry(list, u, compute);
  602. }
  603. }
  604. let mut made = Vec::new();
  605. for slot in fresh {
  606. let Some(&Root::Table(table)) = self.roots_ref(compute).get(usize::from(slot)) else {
  607. continue;
  608. };
  609. let entries: Vec<&UsedResource> = used
  610. .iter()
  611. .filter(tables)
  612. .filter(|u| u.slot == slot)
  613. .collect();
  614. let Some(heap) = self.heap_of(table) else {
  615. continue;
  616. };
  617. let Some(host) = heap.host() else {
  618. continue;
  619. };
  620. let n = entries
  621. .iter()
  622. .map(|u| u.table_offset_dwords / 8 + 1)
  623. .max()
  624. .unwrap_or(1);
  625. // The table and what its entries hold (record words).
  626. let key = {
  627. use std::hash::{Hash, Hasher};
  628. let mut h = std::collections::hash_map::DefaultHasher::new();
  629. for k in 0..n {
  630. let at = table + u64::from(k) * 32;
  631. // SAFETY: a descriptor slot in title memory.
  632. unsafe { (at as *const [u32; 3]).read_unaligned() }.hash(&mut h);
  633. }
  634. (table, h.finish())
  635. };
  636. if let Some(&first) = self.fresh_tables.get(&key) {
  637. for u in entries.iter().filter(|u| u.kind != ResourceType::Cbv) {
  638. let handle = table + u64::from(u.table_offset_dwords) * 4;
  639. if let Some(view) = crate::descriptor::view(handle) {
  640. readable(list, u, &view);
  641. }
  642. }
  643. made.push((slot, first * 32));
  644. continue;
  645. }
  646. let Some(first) = host.dynamic(n) else {
  647. continue;
  648. };
  649. self.fresh_tables.insert(key, first);
  650. self.dynamic
  651. .push((std::ptr::from_ref(heap) as usize, first, n));
  652. // The whole range: a shader may index past the entries its
  653. // used-resource list names (descriptor arrays).
  654. for k in 0..n {
  655. let index = first + k;
  656. let used = entries.iter().find(|u| u.table_offset_dwords / 8 == k);
  657. match crate::descriptor::view(table + u64::from(k) * 32) {
  658. Some(View::Constant(address, size)) => {
  659. let Some((gpu, to)) = list.scratch(u64::from(size)) else {
  660. host.make_null(index);
  661. continue;
  662. };
  663. list.defer_fill(to, address as *const u8, size as usize);
  664. host.constant_at(index, gpu, size);
  665. }
  666. Some(view) => {
  667. host.make_at(index, &view);
  668. if let Some(u) = used {
  669. readable(list, u, &view);
  670. }
  671. }
  672. None => {
  673. host.make_null(index);
  674. if used.is_some() {
  675. once!(slot, "a table entry without a view");
  676. }
  677. }
  678. }
  679. }
  680. made.push((slot, first * 32));
  681. }
  682. made
  683. }
  684. /// The first draws, at debug level: what they bind and read
  685. /// (diagnostics builds).
  686. #[cfg(feature = "diagnostics")]
  687. fn trace(&self, kind: &str, count: u32, first: u32) {
  688. static TRACED: AtomicU64 = AtomicU64::new(0);
  689. if !tracing::enabled!(tracing::Level::DEBUG) {
  690. return;
  691. }
  692. let listed = crate::capture::listed(crate::queue::presented() + 1);
  693. let logged = listed || TRACED.fetch_add(1, Ordering::Relaxed) < 64;
  694. let targets: Vec<String> = self
  695. .targets
  696. .iter()
  697. .filter_map(|&t| crate::resource::host_resource(t as This))
  698. .map(|t| {
  699. // SAFETY: a live resource.
  700. let d = unsafe { t.GetDesc() };
  701. format!("{}x{} f{}", d.Width, d.Height, d.Format.0)
  702. })
  703. .collect();
  704. let v = self.vertex[0];
  705. let line = format!(
  706. "{kind} {count} from {first} topology {} pipeline {:#x} targets {targets:?} vb {:#x}+{} stride {} reads {:?}",
  707. self.topology,
  708. self.pipeline,
  709. v.address,
  710. v.size,
  711. v.stride,
  712. self.reads(false)
  713. );
  714. if logged {
  715. tracing::debug!("draw {line}");
  716. }
  717. let mut frame = FRAME.lock().unwrap_or_else(|e| e.into_inner());
  718. if frame.len() < 256 {
  719. frame.push(line);
  720. }
  721. }
  722. /// What a draw's shaders read, one line per used resource (diagnostics
  723. /// builds).
  724. #[cfg(feature = "diagnostics")]
  725. fn reads(&self, compute: bool) -> Vec<String> {
  726. let Some(p) = crate::pipeline::host_pipeline(self.pipeline as This) else {
  727. return vec!["no host pipeline".into()];
  728. };
  729. let mut out = Vec::new();
  730. for stage in &p.stages {
  731. let t = stage.translated();
  732. for u in &t.used {
  733. let what = match (u.root, self.roots_ref(compute).get(usize::from(u.slot))) {
  734. (RootType::Table, Some(Root::Table(table))) => {
  735. let handle = table + u64::from(u.table_offset_dwords) * 4;
  736. describe(crate::descriptor::view(handle).as_ref())
  737. }
  738. (root, _) => format!("{root:?}"),
  739. };
  740. out.push(format!(
  741. "{} {:?} s{}+{}: {what}",
  742. stage.shader.hash, u.kind, u.slot, u.table_offset_dwords
  743. ));
  744. }
  745. }
  746. out
  747. }
  748. pub(crate) fn draw(
  749. &mut self,
  750. list: &HostList,
  751. vertices: u32,
  752. instances: u32,
  753. first: u32,
  754. first_instance: u32,
  755. ) {
  756. #[cfg(feature = "diagnostics")]
  757. self.trace("draw", vertices, first);
  758. let rects = self.topology == RECTANGLES;
  759. let ran = self.prepare(list, false) && (!rects || self.rectangles(list, vertices, first));
  760. if ran {
  761. // Rectangles were expanded into their own vertex buffers.
  762. let (count, from) = if rects {
  763. (vertices / 3 * 6, 0)
  764. } else {
  765. (vertices, first)
  766. };
  767. #[cfg(feature = "diagnostics")]
  768. list.note_op(|| self.op_text(format!("draw {count}x{instances}"), false));
  769. // SAFETY: an open list with everything set.
  770. unsafe {
  771. list.list
  772. .DrawInstanced(count, instances, from, first_instance)
  773. };
  774. DRAWN.fetch_add(1, Ordering::Relaxed);
  775. }
  776. if !ran {
  777. DROPPED.fetch_add(1, Ordering::Relaxed);
  778. #[cfg(feature = "diagnostics")]
  779. dropped(self.pipeline);
  780. }
  781. }
  782. /// Binds vertex buffers holding the rectangles of vertices `first..first
  783. /// + count` as triangles, made when the list is submitted.
  784. fn rectangles(&self, list: &HostList, count: u32, first: u32) -> bool {
  785. let Some(p) = crate::pipeline::host_pipeline(self.pipeline as This) else {
  786. return false;
  787. };
  788. let rects = u64::from(count / 3);
  789. for slot in 0..32 {
  790. let elements: Vec<(u32, u32)> = p
  791. .inputs
  792. .iter()
  793. .filter(|e| e.slot == slot && !e.per_instance)
  794. .map(|e| (e.offset, e.format))
  795. .collect();
  796. if elements.is_empty() {
  797. continue;
  798. }
  799. let v = self.vertex[slot as usize];
  800. let stride = u64::from(v.stride);
  801. let from = v.address + u64::from(first) * stride;
  802. if v.address == 0
  803. || stride == 0
  804. || u64::from(first + count) * stride > u64::from(v.size)
  805. || crate::shadow::find(from, rects * 3 * stride).is_none()
  806. {
  807. once!(slot, "rectangle vertices outside their buffer");
  808. return false;
  809. }
  810. let Some((gpu, to)) = list.scratch(rects * 6 * stride) else {
  811. return false;
  812. };
  813. let (from, to, stride) = (from as usize, to as usize, stride as usize);
  814. let n = rects as usize;
  815. list.defer_host(move || {
  816. // SAFETY: the vertices lie in a title buffer (checked when
  817. // recorded) and the scratch memory is the list's.
  818. let (src, dst) = unsafe {
  819. (
  820. std::slice::from_raw_parts(from as *const u8, n * 3 * stride),
  821. std::slice::from_raw_parts_mut(to as *mut u8, n * 6 * stride),
  822. )
  823. };
  824. crate::primitive::expand_rects(src, dst, stride, &elements);
  825. });
  826. let view = D3D12_VERTEX_BUFFER_VIEW {
  827. BufferLocation: gpu,
  828. SizeInBytes: (rects * 6 * stride as u64) as u32,
  829. StrideInBytes: v.stride,
  830. };
  831. // SAFETY: an open list; the view names live scratch memory.
  832. unsafe { list.list.IASetVertexBuffers(slot, Some(&[view])) };
  833. }
  834. true
  835. }
  836. pub(crate) fn draw_indexed(
  837. &mut self,
  838. list: &HostList,
  839. indices: u32,
  840. instances: u32,
  841. first: u32,
  842. base: i32,
  843. first_instance: u32,
  844. ) {
  845. #[cfg(feature = "diagnostics")]
  846. self.trace("indexed", indices, first);
  847. if self.topology == RECTANGLES {
  848. once!("indexed rectangles not drawn");
  849. }
  850. let ran = self.topology != RECTANGLES && self.prepare(list, true);
  851. if ran {
  852. #[cfg(feature = "diagnostics")]
  853. list.note_op(|| self.op_text(format!("indexed {indices}x{instances}"), false));
  854. // SAFETY: an open list with everything set.
  855. unsafe {
  856. list.list
  857. .DrawIndexedInstanced(indices, instances, first, base, first_instance)
  858. };
  859. DRAWN.fetch_add(1, Ordering::Relaxed);
  860. }
  861. if !ran {
  862. DROPPED.fetch_add(1, Ordering::Relaxed);
  863. #[cfg(feature = "diagnostics")]
  864. dropped(self.pipeline);
  865. }
  866. }
  867. }
  868. impl State {
  869. /// Indirect execution of a one-argument signature of `kind` (PC
  870. /// numbering: 0 draw, 1 indexed draw, 2 dispatch, 10 mesh dispatch) with
  871. /// records `stride` bytes apart at title address `arguments`, and the
  872. /// record count at `count` if the title gives one: the GPU reads them
  873. /// from the buffer's host copy, where earlier dispatches may have
  874. /// written them. False if it cannot run on the host.
  875. pub(crate) fn execute_indirect(
  876. &mut self,
  877. list: &HostList,
  878. (kind, stride, max): (u32, u32, u32),
  879. arguments: u64,
  880. count: Option<u64>,
  881. ) -> bool {
  882. const DRAW: u32 = 0;
  883. const INDEXED: u32 = 1;
  884. const DISPATCH: u32 = 2;
  885. const MESH: u32 = 10;
  886. #[cfg(feature = "diagnostics")]
  887. let why = |what: &str| crate::pipeline::note_why(format!("indirect kind {kind}: {what}"));
  888. #[cfg(not(feature = "diagnostics"))]
  889. let why = |_: &str| {};
  890. let len = u64::from(stride) * u64::from(max.max(1));
  891. let Some(args) = crate::shadow::find(arguments, len) else {
  892. why("arguments outside title buffers");
  893. return false;
  894. };
  895. let counter = match count {
  896. Some(at) => match crate::shadow::find(at, 4) {
  897. Some(s) => Some((s, at)),
  898. None => {
  899. why("count outside title buffers");
  900. return false;
  901. }
  902. },
  903. None => None,
  904. };
  905. let Some(signature) = matches!(kind, DRAW | INDEXED | DISPATCH | MESH)
  906. .then(|| host_signature(kind, stride))
  907. .flatten()
  908. else {
  909. why("no host signature");
  910. return false;
  911. };
  912. args.refresh(list, arguments, len);
  913. if let Some((s, at)) = &counter {
  914. s.refresh(list, *at, 4);
  915. }
  916. // Bounded first: the clamp binds a compute pipeline of its own.
  917. if !crate::indirect::bound(list, &args.buffer, args.gpu(arguments), (kind, stride, max)) {
  918. why("not bounded (no clamp, or arguments not 4-byte aligned)");
  919. return false;
  920. }
  921. self.host_pipeline = 0;
  922. self.host_roots[1] = 0;
  923. let ran = match kind {
  924. DRAW | INDEXED => self.topology != RECTANGLES && self.prepare(list, kind == INDEXED),
  925. MESH => self.prepare_for(list, false, true),
  926. DISPATCH => match crate::pipeline::host_pipeline(self.pipeline as This) {
  927. Some(p) if p.compute => {
  928. self.bind(list, p, true);
  929. true
  930. }
  931. _ => false,
  932. },
  933. _ => false,
  934. };
  935. if !ran {
  936. crate::indirect::done(list, &args.buffer);
  937. #[cfg(feature = "diagnostics")]
  938. match crate::pipeline::host_pipeline(self.pipeline as This) {
  939. None => crate::pipeline::note_drop(self.pipeline as This),
  940. Some(p) => why(&format!("prepare failed (compute {}, mesh {})", p.compute, p.mesh)),
  941. }
  942. return false;
  943. }
  944. #[cfg(feature = "diagnostics")]
  945. list.note_op(|| {
  946. self.op_text(format!("indirect kind {kind} max {max} at {arguments:#x}"), kind == DISPATCH)
  947. });
  948. // SAFETY: an open list with everything set; the buffers are host
  949. // copies the list keeps alive (refresh), the signature is cached.
  950. unsafe {
  951. list.list.ExecuteIndirect(
  952. &signature,
  953. max,
  954. &args.buffer,
  955. args.offset(arguments),
  956. counter.as_ref().map(|(s, _)| &s.buffer),
  957. counter.as_ref().map_or(0, |(s, at)| s.offset(*at)),
  958. )
  959. };
  960. crate::indirect::done(list, &args.buffer);
  961. if kind == DISPATCH {
  962. DISPATCHED.fetch_add(1, Ordering::Relaxed);
  963. } else {
  964. DRAWN.fetch_add(1, Ordering::Relaxed);
  965. }
  966. true
  967. }
  968. }
  969. /// The host command signature for one argument of `kind` with records
  970. /// `stride` bytes apart (no root arguments, so no root signature), made
  971. /// once.
  972. fn host_signature(kind: u32, stride: u32) -> Option<ID3D12CommandSignature> {
  973. static MADE: std::sync::Mutex<Vec<((u32, u32), ID3D12CommandSignature)>> =
  974. std::sync::Mutex::new(Vec::new());
  975. let mut made = MADE.lock().unwrap_or_else(|e| e.into_inner());
  976. if let Some((_, s)) = made.iter().find(|(k, _)| *k == (kind, stride)) {
  977. return Some(s.clone());
  978. }
  979. let argument = D3D12_INDIRECT_ARGUMENT_DESC {
  980. Type: D3D12_INDIRECT_ARGUMENT_TYPE(kind as i32),
  981. ..Default::default()
  982. };
  983. let desc = D3D12_COMMAND_SIGNATURE_DESC {
  984. ByteStride: stride,
  985. NumArgumentDescs: 1,
  986. pArgumentDescs: &argument,
  987. NodeMask: 0,
  988. };
  989. let mut signature: Option<ID3D12CommandSignature> = None;
  990. // SAFETY: a description of one argument; no root arguments.
  991. let result = unsafe {
  992. crate::host::host()?.device.CreateCommandSignature(
  993. &desc,
  994. None::<&ID3D12RootSignature>,
  995. &mut signature,
  996. )
  997. };
  998. if let Err(e) = result {
  999. once!(error = %e, kind, stride, "host command signature refused");
  1000. return None;
  1001. }
  1002. let signature = signature?;
  1003. made.push(((kind, stride), signature.clone()));
  1004. Some(signature)
  1005. }
  1006. /// Gets what a shader reads or writes through a view ready: buffer data
  1007. /// copied, textures moved to the state they need.
  1008. fn readable(list: &HostList, u: &UsedResource, view: &View) {
  1009. const SHADER_RESOURCE: u32 = 0x40 | 0x80;
  1010. const UNORDERED_ACCESS: u32 = 0x8;
  1011. let placed = crate::descriptor::host::placed_texture(view);
  1012. let view = placed.as_ref().unwrap_or(view);
  1013. // Buffer views read title memory: their range is copied at submission;
  1014. // what shaders write through unordered access goes back to it after.
  1015. if let Some((address, len)) = crate::descriptor::host::buffer_range(view)
  1016. && len > 0
  1017. && let Some(shadow) = crate::shadow::find(address, len)
  1018. {
  1019. shadow.refresh(list, address, len);
  1020. if u.kind == ResourceType::Uav {
  1021. shadow.gpu_writes(list, address, len);
  1022. }
  1023. }
  1024. match (view, u.kind) {
  1025. (View::Shader(resource, _), ResourceType::Srv) => {
  1026. if let Some(t) = crate::resource::host_resource(*resource as This)
  1027. && crate::texture::title_written(t)
  1028. {
  1029. crate::texture::upload(list, *resource as This, t);
  1030. }
  1031. crate::list::ensure_state(list, *resource as This, SHADER_RESOURCE);
  1032. #[cfg(feature = "diagnostics")]
  1033. if let Some(t) = crate::resource::host_resource(*resource as This) {
  1034. // SAFETY: a live resource.
  1035. let d = unsafe { t.GetDesc() };
  1036. if d.Flags.0 & 7 == 0 {
  1037. tracing::debug!(
  1038. resource = format_args!("{resource:#x}"),
  1039. ?d,
  1040. "a shader reads a texture the title fills"
  1041. );
  1042. }
  1043. }
  1044. }
  1045. (View::Unordered(resource, _, _), ResourceType::Uav) => {
  1046. #[cfg(feature = "diagnostics")]
  1047. crate::capture::note_target(*resource as This);
  1048. crate::list::ensure_state(list, *resource as This, UNORDERED_ACCESS);
  1049. }
  1050. _ => {}
  1051. }
  1052. }
  1053. /// A view in a few words (diagnostics builds).
  1054. #[cfg(feature = "diagnostics")]
  1055. fn describe(view: Option<&View>) -> String {
  1056. let texture = |r: This| {
  1057. crate::resource::host_resource(r).map(|t| {
  1058. // SAFETY: a live resource.
  1059. let d = unsafe { t.GetDesc() };
  1060. format!("{}x{} f{} flags {:#x}", d.Width, d.Height, d.Format.0, d.Flags.0)
  1061. })
  1062. };
  1063. match view {
  1064. None => "no view".into(),
  1065. Some(v @ View::Shader(r, _)) => texture(*r as This)
  1066. .unwrap_or_else(|| format!("buffer {:?}", crate::descriptor::host::buffer_range(v))),
  1067. Some(View::Unordered(r, ..)) => format!("uav {:?}", texture(*r as This)),
  1068. Some(View::Placed(u, r, d)) => format!(
  1069. "placed uav={u} dim {} {}x{} f{} layout {:#x} at {:#x}",
  1070. r[0],
  1071. u64::from(r[4]) | u64::from(r[5]) << 32,
  1072. r[6],
  1073. r[8],
  1074. r[11],
  1075. u64::from(d[10]) | u64::from(d[11]) << 32
  1076. ),
  1077. // The first four values, as a colour rectangle's constants are.
  1078. Some(View::Constant(address, size))
  1079. if *size >= 16 && crate::texture::committed(*address as *const u8, 16) =>
  1080. {
  1081. // SAFETY: 16 committed bytes of title memory.
  1082. let v = unsafe { (*address as *const [f32; 4]).read_unaligned() };
  1083. format!("Constant({address:#x}, {size}) {v:?}")
  1084. }
  1085. Some(v) => format!("{v:?}").chars().take(60).collect(),
  1086. }
  1087. }
  1088. /// The console's own primitive topologies.
  1089. const TRIANGLE_FAN: u32 = 6;
  1090. const RECTANGLES: u32 = 17;
  1091. const LINE_LOOP: u32 = 18;
  1092. const QUADS: u32 = 19;
  1093. const QUAD_STRIP: u32 = 20;
  1094. /// Fixed-function state, straight onto the host list.
  1095. pub(crate) fn viewports(list: &HostList, viewports: &[D3D12_VIEWPORT]) {
  1096. // SAFETY: an open list.
  1097. unsafe { list.list.RSSetViewports(viewports) };
  1098. }
  1099. pub(crate) fn scissors(list: &HostList, rects: &[RECT]) {
  1100. // SAFETY: an open list.
  1101. unsafe { list.list.RSSetScissorRects(rects) };
  1102. }
  1103. pub(crate) fn blend_factor(list: &HostList, factor: Option<&[f32; 4]>) {
  1104. // SAFETY: an open list.
  1105. unsafe { list.list.OMSetBlendFactor(factor) };
  1106. }
  1107. pub(crate) fn stencil_ref(list: &HostList, reference: u32) {
  1108. // SAFETY: an open list.
  1109. unsafe { list.list.OMSetStencilRef(reference) };
  1110. }