nvidia_dlss/stub.rs
1#[cfg(feature = "vk-graph")]
2use vk_graph::driver::{device::Device, instance::Instance};
3use {
4 crate::{
5 DlssRrConfig, DlssRrFrameConstants, DlssRrQuality, DlssRrResources, InitInfo,
6 VulkanInitInfo,
7 },
8 ash::vk,
9 std::{ffi::CString, path::Path},
10};
11
12#[derive(Clone)]
13pub struct Evaluator;
14
15impl Evaluator {
16 #[must_use]
17 pub fn is_active(&self) -> bool {
18 false
19 }
20
21 /// # Errors
22 /// Always returns an error because the native backend is unavailable.
23 pub fn optimal_render_extent(
24 &self,
25 _output_extent: [u32; 2],
26 _quality: DlssRrQuality,
27 ) -> anyhow::Result<[u32; 2]> {
28 anyhow::bail!("ngx is available only on x86_64-unknown-linux-gnu")
29 }
30
31 /// # Safety
32 ///
33 /// This evaluator and its owning NGX context must remain valid until execution completes. The
34 /// command buffer must be recording on the context's device; every image and view must belong
35 /// to that device, and each declared layout must match its actual state. Image ranges,
36 /// formats, and extents must describe their views accurately. Before evaluation,
37 /// transition all inputs (including depth and the reflection guide) to
38 /// `SHADER_READ_ONLY_OPTIMAL` and the output to `GENERAL`. Evaluation leaves these
39 /// layouts unchanged; this wrapper does not record layout transitions. All handles must
40 /// remain valid until GPU execution completes. If dimensions or quality change, prior
41 /// evaluations must have completed first.
42 ///
43 /// # Errors
44 /// Always returns an error because the native backend is unavailable.
45 pub unsafe fn evaluate(
46 &self,
47 _command_buffer: vk::CommandBuffer,
48 _frame: &DlssRrFrameConstants,
49 _resources: &DlssRrResources,
50 _quality: DlssRrQuality,
51 ) -> anyhow::Result<()> {
52 anyhow::bail!("ngx is available only on x86_64-unknown-linux-gnu")
53 }
54
55 /// # Safety
56 ///
57 /// All NGX GPU work must have completed before shutdown.
58 ///
59 /// # Errors
60 /// This stub always succeeds; the native backend can report shutdown failures.
61 pub unsafe fn shutdown(&self) -> anyhow::Result<()> {
62 Ok(())
63 }
64}
65
66pub struct Ngx;
67
68impl Ngx {
69 /// Returns whether this build includes the native NGX backend.
70 #[must_use]
71 pub const fn native_backend_available() -> bool {
72 false
73 }
74
75 /// Returns the build-staged runtime directory, or `None` without the native backend.
76 #[must_use]
77 pub fn staged_runtime_dir() -> Option<&'static Path> {
78 None
79 }
80
81 /// # Errors
82 /// Always returns an error because the native backend is unavailable.
83 pub fn new(_info: InitInfo) -> anyhow::Result<Self> {
84 anyhow::bail!("ngx is available only on x86_64-unknown-linux-gnu")
85 }
86
87 #[must_use]
88 pub fn instance_extensions(&self) -> &[CString] {
89 &[]
90 }
91
92 /// Queries NGX device extension requirements.
93 ///
94 /// # Safety
95 ///
96 /// `physical_device` must be a valid physical device enumerated from `instance`.
97 /// The instance, physical device, and Vulkan loader that created them must remain
98 /// valid throughout the call and must not be destroyed concurrently.
99 ///
100 /// # Errors
101 /// Always returns an error because the native backend is unavailable.
102 #[cfg(feature = "vk-graph")]
103 pub unsafe fn device_extensions(
104 &self,
105 _instance: &Instance,
106 _physical_device: vk::PhysicalDevice,
107 ) -> anyhow::Result<Vec<CString>> {
108 anyhow::bail!("ngx is available only on x86_64-unknown-linux-gnu")
109 }
110
111 /// # Safety
112 ///
113 /// `instance` must be a valid Vulkan instance, and `physical_device` must be a valid
114 /// physical device enumerated from it. The instance, physical device, and Vulkan loader
115 /// that created them must remain valid throughout the call and must not be destroyed
116 /// concurrently.
117 ///
118 /// # Errors
119 /// Always returns an error because the native backend is unavailable.
120 pub unsafe fn device_extensions_raw(
121 &self,
122 _instance: vk::Instance,
123 _physical_device: vk::PhysicalDevice,
124 ) -> anyhow::Result<Vec<CString>> {
125 anyhow::bail!("ngx is available only on x86_64-unknown-linux-gnu")
126 }
127
128 /// Initializes NGX while retaining ownership of the graph device.
129 ///
130 /// # Safety
131 ///
132 /// The instance and device must enable the extensions returned by NGX. Complete all
133 /// NGX GPU work before explicit shutdown through `Ngx` or any evaluator. Dropping
134 /// these wrappers does not shut down NGX.
135 ///
136 /// # Errors
137 /// Always returns an error because the native backend is unavailable.
138 #[cfg(feature = "vk-graph")]
139 pub unsafe fn initialize(
140 &mut self,
141 _device: &Device,
142 _config: DlssRrConfig,
143 ) -> anyhow::Result<Evaluator> {
144 anyhow::bail!("ngx is available only on x86_64-unknown-linux-gnu")
145 }
146
147 /// Initializes NGX without retaining ownership of the Vulkan device.
148 ///
149 /// # Safety
150 ///
151 /// Handles must be valid and belong to the same Vulkan instance and physical device.
152 /// The instance and device must enable the extensions returned by NGX. The entrypoints
153 /// must belong to the loader that created these handles. Keep the loader, instance, and device alive
154 /// until explicit shutdown through `Ngx` or any evaluator completes, and complete all
155 /// NGX GPU work before shutdown. Dropping these wrappers does not shut down NGX.
156 ///
157 /// # Errors
158 /// Always returns an error because the native backend is unavailable.
159 pub unsafe fn initialize_raw(
160 &mut self,
161 _info: VulkanInitInfo,
162 _config: DlssRrConfig,
163 ) -> anyhow::Result<Evaluator> {
164 anyhow::bail!("ngx is available only on x86_64-unknown-linux-gnu")
165 }
166
167 #[must_use]
168 pub fn evaluator(&self) -> Option<Evaluator> {
169 None
170 }
171
172 /// # Safety
173 ///
174 /// All NGX GPU work must have completed before shutdown.
175 ///
176 /// # Errors
177 /// This stub always succeeds; the native backend can report shutdown failures.
178 pub unsafe fn shutdown(&mut self) -> anyhow::Result<()> {
179 Ok(())
180 }
181}