-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This update significantly expands support for [`naga-oil`] modules. The language server now accepts a `preprocessor` key, with this interface: ```ts export interface Preprocessor { globalShaderDefs: Record<string, string>; shaderDefs: Record<string, Record<string, string>>; } ``` An example configuration looks like this: ```json { "wgsl.preprocessor.globalShaderDefs": { "AVAILABLE_STORAGE_BUFFER_BINDINGS": "8", "PER_OBJECT_BUFFER_BATCH_SIZE": "64", "MAX_CASCADES_PER_LIGHT": "8", "MAX_DIRECTIONAL_LIGHTS": "4", "MORPH_TARGETS": "", "SKINNED": "", "VERTEX_POSITIONS": "", "SLICE_COUNT": "3", "SAMPLES_PER_SLICE_SIDE": "3" }, "wgsl.preprocessor.shaderDefs": { "bevy_core_pipeline::tonemapping": { "TONEMAP_METHOD_AGX": "" } } } ``` When WGSL documents are processed, conditional directives like the following are parsed and evaluated using the provided configuration: ```wgsl #ifdef SKINNED // ... #else // ... #endif ``` ```wgsl #if AVAILABLE_STORAGE_BUFFER_BINDINGS >= 3 // ... #else // ... #endif ``` 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: ```wgsl #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 ``` ```wgsl @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: ```wgsl #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. [`naga-oil`]: https://github.com/bevyengine/naga_oil [`DiagnosticTag.Unnecessary`]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnosticTag
- Loading branch information
1 parent
ebbbe54
commit eeb31f0
Showing
89 changed files
with
7,653 additions
and
1,140 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.