Skip to content

Commit

Permalink
docs: add warning about stack size for WGSL compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Apr 2, 2024
1 parent ab746f6 commit 22c80fb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Bottom level categories:
#### Naga
- In spv-in, remove unnecessary "gl_PerVertex" name check so unused builtins will always be skipped. By @Imberflur in [#5227](https://github.com/gfx-rs/wgpu/pull/5227).
- GLSL 410 does not support layout(binding = ...), enable only for GLSL 420. By @bes in [#5357](https://github.com/gfx-rs/wgpu/pull/5357)
- Add a limit for curly brace nesting in WGSL parsing. By @ErichDonGubler in [#5447](https://github.com/gfx-rs/wgpu/pull/5447).
- Add a limit for curly brace nesting in WGSL parsing, plus a note about stack size requirements. By @ErichDonGubler in [#5447](https://github.com/gfx-rs/wgpu/pull/5447).

#### Tests

Expand Down
11 changes: 11 additions & 0 deletions naga/src/front/wgsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ impl Frontend {
}
}

/// <div class="warning">
// NOTE: Keep this in sync with `wgpu::Device::create_shader_module`!
// NOTE: Keep this in sync with `wgpu_core::Global::device_create_shader_module`!
///
/// Compiler-enforced limits for WGSL parsing recursion exist; if shader compilation runs into
/// them, it will return an error gracefully. However, on some build profiles and platforms, the
/// default stack size for a thread may be exceeded before this limit is reached during parsing.
/// Callers should ensure that there is enough stack space for this, particularly if calls to this
/// method are exposed to user input.
///
/// </div>
pub fn parse_str(source: &str) -> Result<crate::Module, ParseError> {
Frontend::new().parse(source)
}
13 changes: 13 additions & 0 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,19 @@ impl Global {
}
}

/// Create a shader module with the given `source`.
///
/// <div class="warning">
// NOTE: Keep this in sync with `naga::front::wgsl::parse_str`!
// NOTE: Keep this in sync with `wgpu::Device::create_shader_module`!
///
/// Compiler-enforced limits for parsing recursion exist; if shader compilation runs into them,
/// it will return an error gracefully. However, on some build profiles and platforms, the
/// default stack size for a thread may be exceeded before this limit is reached during
/// parsing. Callers should ensure that there is enough stack space for this, particularly if
/// calls to this method are exposed to user input.
///
/// </div>
pub fn device_create_shader_module<A: HalApi>(
&self,
device_id: DeviceId,
Expand Down
12 changes: 12 additions & 0 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,18 @@ impl Device {
}

/// Creates a shader module from either SPIR-V or WGSL source code.
///
/// <div class="warning">
// NOTE: Keep this in sync with `naga::front::wgsl::parse_str`!
// NOTE: Keep this in sync with `wgpu_core::Global::device_create_shader_module`!
///
/// Compiler-enforced limits for WGSL parsing recursion exist; if shader compilation runs into
/// them, it will return an error gracefully. However, on some build profiles and platforms for
/// native targets, the default stack size for a thread may be exceeded before this limit is
/// reached during parsing. Callers should ensure that there is enough stack space for this,
/// particularly if calls to this method are exposed to user input.
///
/// </div>
pub fn create_shader_module(&self, desc: ShaderModuleDescriptor<'_>) -> ShaderModule {
let (id, data) = DynContext::device_create_shader_module(
&*self.context,
Expand Down

0 comments on commit 22c80fb

Please sign in to comment.