|
| 1 | +#[cfg(feature = "trace")] |
| 2 | +mod record; |
| 3 | + |
1 | 4 | use core::{convert::Infallible, ops::Range};
|
2 | 5 |
|
3 | 6 | use alloc::{string::String, vec::Vec};
|
4 | 7 | use macro_rules_attribute::apply;
|
5 | 8 |
|
6 |
| -#[cfg(feature = "trace")] |
7 |
| -use {alloc::borrow::Cow, std::io::Write as _}; |
8 |
| - |
9 |
| -#[cfg(feature = "trace")] |
10 |
| -use crate::command::IdReferences; |
11 | 9 | use crate::{
|
12 | 10 | command::{serde_object_reference_struct, BasePass, Command, ReferenceType, RenderCommand},
|
13 | 11 | id,
|
14 | 12 | };
|
15 | 13 |
|
| 14 | +#[cfg(feature = "trace")] |
| 15 | +pub use record::*; |
| 16 | + |
16 | 17 | type FileName = String;
|
17 | 18 |
|
18 | 19 | pub const FILE_NAME: &str = "trace.ron";
|
19 | 20 |
|
20 |
| -#[cfg(feature = "trace")] |
21 |
| -pub(crate) fn new_render_bundle_encoder_descriptor<'a>( |
22 |
| - label: crate::Label<'a>, |
23 |
| - context: &'a super::RenderPassContext, |
24 |
| - depth_read_only: bool, |
25 |
| - stencil_read_only: bool, |
26 |
| -) -> crate::command::RenderBundleEncoderDescriptor<'a> { |
27 |
| - crate::command::RenderBundleEncoderDescriptor { |
28 |
| - label, |
29 |
| - color_formats: Cow::Borrowed(&context.attachments.colors), |
30 |
| - depth_stencil: context.attachments.depth_stencil.map(|format| { |
31 |
| - wgt::RenderBundleDepthStencil { |
32 |
| - format, |
33 |
| - depth_read_only, |
34 |
| - stencil_read_only, |
35 |
| - } |
36 |
| - }), |
37 |
| - sample_count: context.sample_count, |
38 |
| - multiview: context.multiview, |
39 |
| - } |
40 |
| -} |
41 |
| - |
42 | 21 | #[allow(clippy::large_enum_variant)]
|
43 | 22 | #[derive(Debug)]
|
44 | 23 | #[apply(serde_object_reference_struct)]
|
@@ -163,55 +142,3 @@ pub enum Action<'a, R: ReferenceType> {
|
163 | 142 | },
|
164 | 143 | DestroyTlas(id::TlasId),
|
165 | 144 | }
|
166 |
| - |
167 |
| -#[cfg(feature = "trace")] |
168 |
| -#[derive(Debug)] |
169 |
| -pub struct Trace { |
170 |
| - path: std::path::PathBuf, |
171 |
| - file: std::fs::File, |
172 |
| - config: ron::ser::PrettyConfig, |
173 |
| - binary_id: usize, |
174 |
| -} |
175 |
| - |
176 |
| -#[cfg(feature = "trace")] |
177 |
| -impl Trace { |
178 |
| - pub fn new(path: std::path::PathBuf) -> Result<Self, std::io::Error> { |
179 |
| - log::info!("Tracing into '{path:?}'"); |
180 |
| - let mut file = std::fs::File::create(path.join(FILE_NAME))?; |
181 |
| - file.write_all(b"[\n")?; |
182 |
| - Ok(Self { |
183 |
| - path, |
184 |
| - file, |
185 |
| - config: ron::ser::PrettyConfig::default(), |
186 |
| - binary_id: 0, |
187 |
| - }) |
188 |
| - } |
189 |
| - |
190 |
| - pub fn make_binary(&mut self, kind: &str, data: &[u8]) -> String { |
191 |
| - self.binary_id += 1; |
192 |
| - let name = std::format!("data{}.{}", self.binary_id, kind); |
193 |
| - let _ = std::fs::write(self.path.join(&name), data); |
194 |
| - name |
195 |
| - } |
196 |
| - |
197 |
| - pub(crate) fn add(&mut self, action: Action<'_, IdReferences>) |
198 |
| - where |
199 |
| - for<'a> Action<'a, IdReferences>: serde::Serialize, |
200 |
| - { |
201 |
| - match ron::ser::to_string_pretty(&action, self.config.clone()) { |
202 |
| - Ok(string) => { |
203 |
| - let _ = writeln!(self.file, "{string},"); |
204 |
| - } |
205 |
| - Err(e) => { |
206 |
| - log::warn!("RON serialization failure: {e:?}"); |
207 |
| - } |
208 |
| - } |
209 |
| - } |
210 |
| -} |
211 |
| - |
212 |
| -#[cfg(feature = "trace")] |
213 |
| -impl Drop for Trace { |
214 |
| - fn drop(&mut self) { |
215 |
| - let _ = self.file.write_all(b"]"); |
216 |
| - } |
217 |
| -} |
0 commit comments