Conditional branches that evaluate to false are marked inactive (with DiagnosticTag.Unnecessary) and removed from the input that's passed to the WGSL parser, along with all lines containing conditional directives.
Additionally, shader-def interpolations like the following are replaced with their configured values, with a helpful diagnostic if the server couldn't find a definition for the identifier:
#ifdef PER_OBJECT_BUFFER_BATCH_SIZE
// The WGSL parser will read this type as `array<Mesh, 64u>`
@group(1) @binding(0) var<uniform> mesh: array<Mesh, #{PER_OBJECT_BUFFER_BATCH_SIZE}u>;
#else
@group(1) @binding(0) var<storage> mesh: array<Mesh>;
#endif // PER_OBJECT_BUFFER_BATCH_SIZE
@compute
@workgroup_size(8, 8, 1)
fn gtao(@builtin(global_invocation_id) global_id: vec3<u32>) {
// The parser will read this value as `f32(3)`
let slice_count = f32(#SLICE_COUNT);
// ...
}
Hovering over the #{PER_OBJECT_BUFFER_BATCH_SIZE} range in the editor displays a tooltip like the following, reflecting the value provided in the LSP configuration:
#define PER_OBJECT_BUFFER_BATCH_SIZE 64
Additionally, in-source #define statements like the example above are handled by the pre-parser in the same way.
Remaining Work
This update does not make any changes to the handling of module imports — while the server still provides features like hover tooltips, go-to-definition and reference lookups for imported/exported symbols, these elements are not yet expanded to valid WGSL source code before passing to the Naga validator, so Naga will still emit a parse error and exit early in any modules that include a #define_import_path or #import statement.
This update significantly expands support for
naga-oil
modules.The language server now accepts a
preprocessor
key, with this interface:An example configuration looks like this:
When WGSL documents are processed, conditional directives like the following are parsed and evaluated using the provided configuration:
Conditional branches that evaluate to
false
are marked inactive (withDiagnosticTag.Unnecessary
) and removed from the input that's passed to the WGSL parser, along with all lines containing conditional directives.Additionally, shader-def interpolations like the following are replaced with their configured values, with a helpful diagnostic if the server couldn't find a definition for the identifier:
Hovering over the
#{PER_OBJECT_BUFFER_BATCH_SIZE}
range in the editor displays a tooltip like the following, reflecting the value provided in the LSP configuration:Additionally, in-source
#define
statements like the example above are handled by the pre-parser in the same way.Remaining Work
This update does not make any changes to the handling of module imports — while the server still provides features like hover tooltips, go-to-definition and reference lookups for imported/exported symbols, these elements are not yet expanded to valid WGSL source code before passing to the Naga validator, so Naga will still emit a parse error and exit early in any modules that include a
#define_import_path
or#import
statement.