Skip to content

Commit fb305b8

Browse files
docs: add warning about stack size for WGSL compilation
1 parent b21a326 commit fb305b8

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Bottom level categories:
155155
- 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).
156156
- GLSL 410 does not support layout(binding = ...), enable only for GLSL 420. By @bes in [#5357](https://github.com/gfx-rs/wgpu/pull/5357)
157157
- In spv-out, check for acceleration and ray-query types when enabling ray-query extension to prevent validation error. By @Vecvec in [#5463](https://github.com/gfx-rs/wgpu/pull/5463)
158-
- Add a limit for curly brace nesting in WGSL parsing. By @ErichDonGubler in [#5447](https://github.com/gfx-rs/wgpu/pull/5447).
158+
- 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).
159159

160160
#### Tests
161161

naga/src/front/wgsl/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ impl Frontend {
4444
}
4545
}
4646

47+
/// <div class="warning">
48+
// NOTE: Keep this in sync with `wgpu::Device::create_shader_module`!
49+
// NOTE: Keep this in sync with `wgpu_core::Global::device_create_shader_module`!
50+
///
51+
/// This function may consume a lot of stack space. Compiler-enforced limits for parsing recursion
52+
/// exist; if shader compilation runs into them, it will return an error gracefully. However, on
53+
/// some build profiles and platforms, the default stack size for a thread may be exceeded before
54+
/// this limit is reached during parsing. Callers should ensure that there is enough stack space
55+
/// for this, particularly if calls to this method are exposed to user input.
56+
///
57+
/// </div>
4758
pub fn parse_str(source: &str) -> Result<crate::Module, ParseError> {
4859
Frontend::new().parse(source)
4960
}

wgpu-core/src/device/global.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,20 @@ impl Global {
11701170
}
11711171
}
11721172

1173+
/// Create a shader module with the given `source`.
1174+
///
1175+
/// <div class="warning">
1176+
// NOTE: Keep this in sync with `naga::front::wgsl::parse_str`!
1177+
// NOTE: Keep this in sync with `wgpu::Device::create_shader_module`!
1178+
///
1179+
/// This function may consume a lot of stack space. Compiler-enforced limits for parsing
1180+
/// recursion exist; if shader compilation runs into them, it will return an error gracefully.
1181+
/// However, on some build profiles and platforms, the default stack size for a thread may be
1182+
/// exceeded before this limit is reached during parsing. Callers should ensure that there is
1183+
/// enough stack space for this, particularly if calls to this method are exposed to user
1184+
/// input.
1185+
///
1186+
/// </div>
11731187
pub fn device_create_shader_module<A: HalApi>(
11741188
&self,
11751189
device_id: DeviceId,

wgpu/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,19 @@ impl Device {
22962296
}
22972297

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

0 commit comments

Comments
 (0)