wgpu_types/compilation_info.rs
1use alloc::string::String;
2use alloc::vec::Vec;
3
4/// Compilation information for a shader module.
5///
6/// Corresponds to [WebGPU `GPUCompilationInfo`](https://gpuweb.github.io/gpuweb/#gpucompilationinfo).
7/// The source locations use bytes, and index a UTF-8 encoded string.
8#[derive(Debug, Clone, Default)]
9pub struct CompilationInfo {
10 /// The messages from the shader compilation process.
11 pub messages: Vec<CompilationMessage>,
12}
13
14/// A single message from the shader compilation process.
15///
16/// Roughly corresponds to [`GPUCompilationMessage`](https://www.w3.org/TR/webgpu/#gpucompilationmessage),
17/// except that the location uses UTF-8 for all positions.
18#[derive(Debug, Clone)]
19pub struct CompilationMessage {
20 /// The text of the message.
21 pub message: String,
22 /// The type of the message.
23 pub message_type: CompilationMessageType,
24 /// Where in the source code the message points at.
25 pub location: Option<SourceLocation>,
26}
27
28/// The type of a compilation message.
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum CompilationMessageType {
31 /// An error message.
32 Error,
33 /// A warning message.
34 Warning,
35 /// An informational message.
36 Info,
37}
38
39/// A human-readable representation for a span, tailored for text source.
40///
41/// Roughly corresponds to the positional members of [`GPUCompilationMessage`][gcm] from
42/// the WebGPU specification, except
43/// - `offset` and `length` are in bytes (UTF-8 code units), instead of UTF-16 code units.
44/// - `line_position` is in bytes (UTF-8 code units), and is usually not directly intended for humans.
45///
46/// [gcm]: https://www.w3.org/TR/webgpu/#gpucompilationmessage
47#[derive(Copy, Clone, Debug, PartialEq, Eq)]
48pub struct SourceLocation {
49 /// 1-based line number.
50 pub line_number: u32,
51 /// 1-based column in code units (in bytes) of the start of the span.
52 /// Remember to convert accordingly when displaying to the user.
53 pub line_position: u32,
54 /// 0-based Offset in code units (in bytes) of the start of the span.
55 pub offset: u32,
56 /// Length in code units (in bytes) of the span.
57 pub length: u32,
58}