1use std::collections::BTreeMap;
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
11#[serde(rename_all = "camelCase")]
12pub struct WebGpuReport {
13 pub devices: Vec<WebGpuDevice>,
14 pub resources: Vec<WebGpuResource>,
15 pub errors: WebGpuErrors,
16 pub frames: Vec<WebGpuFrame>,
17}
18
19#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
20#[serde(rename_all = "camelCase")]
21pub struct WebGpuDevice {
22 pub handle: u64,
23 pub adapter_name: String,
24 pub backend: String,
25 pub label: String,
26 pub enabled_features: Vec<String>,
27 pub limits: BTreeMap<String, u64>,
29 pub lost: bool,
30 pub lost_reason: Option<String>,
31}
32
33#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
34#[serde(rename_all = "camelCase")]
35pub struct WebGpuResource {
36 pub device: u64,
37 pub handle: u64,
38 pub label: String,
39 pub details: WebGpuResourceDetails,
40}
41
42#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
43#[serde(
44 tag = "kind",
45 rename_all = "kebab-case",
46 rename_all_fields = "camelCase"
47)]
48pub enum WebGpuResourceDetails {
49 Buffer {
50 size: u64,
51 usage: u32,
52 },
53 Texture {
54 size: [u32; 3],
55 format: String,
56 mip_levels: u32,
57 sample_count: u32,
58 usage: u32,
59 },
60 Sampler,
61 ShaderModule {
62 entry_points: Vec<WebGpuEntryPoint>,
63 compilation_messages: Vec<WebGpuCompilationMessage>,
64 },
65 RenderPipeline {
66 vertex_entry_point: Option<String>,
67 fragment_entry_point: Option<String>,
68 color_targets: Vec<Option<String>>,
69 },
70 ComputePipeline {
71 compute_entry_point: Option<String>,
72 },
73 BindGroup,
74 BindGroupLayout,
75 PipelineLayout,
76}
77
78impl WebGpuResourceDetails {
79 pub fn kind_name(&self) -> &'static str {
80 match self {
81 Self::Buffer { .. } => "buffer",
82 Self::Texture { .. } => "texture",
83 Self::Sampler => "sampler",
84 Self::ShaderModule { .. } => "shader-module",
85 Self::RenderPipeline { .. } => "render-pipeline",
86 Self::ComputePipeline { .. } => "compute-pipeline",
87 Self::BindGroup => "bind-group",
88 Self::BindGroupLayout => "bind-group-layout",
89 Self::PipelineLayout => "pipeline-layout",
90 }
91 }
92}
93
94#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
95#[serde(rename_all = "camelCase")]
96pub struct WebGpuEntryPoint {
97 pub stage: String,
98 pub name: String,
99}
100
101#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
102#[serde(rename_all = "camelCase")]
103pub struct WebGpuCompilationMessage {
104 pub message: String,
105 #[serde(rename = "type")]
106 pub message_type: String,
107 pub line_num: u32,
108 pub line_pos: usize,
109 pub offset: usize,
110 pub length: usize,
111}
112
113#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
114#[serde(rename_all = "camelCase")]
115pub struct WebGpuErrors {
116 pub since_previous: Vec<WebGpuError>,
117 pub total: u64,
118 pub validation_total: u64,
119 pub uncaptured_total: u64,
120 pub dropped_since_previous: u64,
123}
124
125#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
126#[serde(rename_all = "camelCase")]
127pub struct WebGpuError {
128 pub device: u64,
129 #[serde(rename = "type")]
130 pub error_type: String,
131 pub message: String,
132 pub api_call: String,
133 pub object_label: String,
134 pub uncaptured: bool,
135}
136
137#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
138#[serde(rename_all = "camelCase")]
139pub struct WebGpuFrame {
140 pub sequence: u64,
141 pub device: u64,
142 pub submits: u64,
143 pub complete: bool,
146 pub passes: Vec<WebGpuPass>,
147}
148
149#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
150#[serde(rename_all = "camelCase")]
151pub struct WebGpuPass {
152 pub kind: String,
153 pub label: String,
154 pub color_targets: Vec<Option<WebGpuColorTarget>>,
155 pub depth_target: Option<WebGpuDepthTarget>,
156 pub draws: u64,
157 pub draw_indexed: u64,
158 pub draw_indirect: u64,
159 pub draw_indexed_indirect: u64,
160 pub dispatches: u64,
162 pub vertices: u64,
165 pub instances: u64,
167 pub pipelines: Vec<String>,
168 pub complete: bool,
169}
170
171impl WebGpuPass {
172 pub fn draw_count(&self) -> u64 {
173 self.draws
174 .saturating_add(self.draw_indexed)
175 .saturating_add(self.draw_indirect)
176 .saturating_add(self.draw_indexed_indirect)
177 }
178}
179
180#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
181#[serde(rename_all = "camelCase")]
182pub struct WebGpuColorTarget {
183 pub target: String,
185 pub resolve_target: Option<String>,
186 pub load_op: String,
187 pub store_op: String,
188}
189
190#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
191#[serde(rename_all = "camelCase")]
192pub struct WebGpuDepthTarget {
193 pub target: String,
194 pub depth_load_op: Option<String>,
195 pub depth_store_op: Option<String>,
196 pub stencil_load_op: Option<String>,
197 pub stencil_store_op: Option<String>,
198}
199
200#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
202#[serde(rename_all = "camelCase")]
203pub struct WebGpuBufferSnapshot {
204 pub label: String,
206 pub size: u64,
208 pub usage: u32,
210 pub offset: u64,
212 pub submit: u64,
215 pub written_by_write_buffer: bool,
218 pub data_base64: String,
220}