-
Notifications
You must be signed in to change notification settings - Fork 1.3k
implement debugPrintf in msl & spv #9389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
39ali
wants to merge
36
commits into
gfx-rs:trunk
Choose a base branch
from
39ali:printf-metal
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
cf330aa
added debugPrintf to msl
39ali e10066c
fix test
39ali e03d553
format readme
39ali b7db830
fix format
39ali 14f2e09
fix test
39ali 9b50c88
added debugPrintf support in vulkan
39ali 7b638b5
Update examples/features/src/debug_printf/mod.rs
39ali 122974e
Update naga/src/back/msl/writer.rs
39ali 8c06b04
Update naga/src/back/wgsl/writer.rs
39ali de26ded
Update naga/src/back/wgsl/writer.rs
39ali dae396d
Update naga/src/back/wgsl/writer.rs
39ali 19ce204
Update naga/src/ir/mod.rs
39ali be33c07
Update naga/src/front/wgsl/parse/lexer.rs
39ali a5a3699
Update naga/src/back/wgsl/writer.rs
39ali 87475bf
Update naga/src/front/wgsl/parse/directive/enable_extension.rs
39ali be76a33
removed InvalidExpression
39ali 4d9e223
Update naga/src/valid/mod.rs
39ali 7eb3160
refactor unsafe block
39ali 834db46
refactor
39ali 9d369d0
update changelog
39ali b2a97ff
increase validation_feature_list size to 4
39ali 20031bb
Update wgpu-hal/src/metal/adapter.rs
39ali 6cee5c1
Update wgpu-hal/src/metal/adapter.rs
39ali 9283e55
Update naga/src/ir/mod.rs
39ali 61ec6e2
Update naga/src/front/wgsl/error.rs
39ali e4560c7
Update naga/src/front/wgsl/lower/mod.rs
39ali b472f43
Update naga/src/front/wgsl/parse/directive/enable_extension.rs
39ali ba58433
Update CHANGELOG.md
39ali 1547e95
Update wgpu-types/src/features.rs
39ali 06d9582
Update naga/src/front/wgsl/lower/mod.rs
39ali 2b16010
Update CHANGELOG.md
39ali af53b07
Update CHANGELOG.md
39ali 5f463bf
fix typos
39ali ad082b6
added tests + refactor
39ali 11c128a
fix test
39ali 3fc174d
cleanup
39ali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # debugPrintf | ||
|
|
||
| This example shows how to printf in shaders | ||
|
|
||
| ## To Run | ||
|
|
||
| ``` | ||
| cargo run --bin wgpu-examples debug_printf | ||
| ``` |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| struct Example {} | ||
|
|
||
| impl crate::framework::Example for Example { | ||
| fn required_features() -> wgpu::Features { | ||
| wgpu::Features::DEBUG_PRINTF | ||
| } | ||
|
|
||
| fn required_downlevel_capabilities() -> wgpu::DownlevelCapabilities { | ||
| wgpu::DownlevelCapabilities { | ||
| flags: wgpu::DownlevelFlags::COMPUTE_SHADERS, | ||
| ..Default::default() | ||
| } | ||
| } | ||
|
|
||
| fn required_limits() -> wgpu::Limits { | ||
| wgpu::Limits::default() | ||
| } | ||
|
|
||
| fn init( | ||
| _config: &wgpu::SurfaceConfiguration, | ||
| _adapter: &wgpu::Adapter, | ||
| device: &wgpu::Device, | ||
| queue: &wgpu::Queue, | ||
| ) -> Self { | ||
| let shader_source = r#" | ||
| enable wgpu_debug_printf; | ||
|
|
||
| @compute @workgroup_size(8, 1, 1) | ||
| fn main(@builtin(local_invocation_index) idx: u32) { | ||
| // We use a specific ID to identify our print in the logs | ||
| debugPrintf("WGSL_METAL_LOG: Thread index is %u", idx); | ||
39ali marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| "#; | ||
39ali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { | ||
| label: Some("DebugPrintfShader"), | ||
| source: wgpu::ShaderSource::Wgsl(shader_source.into()), | ||
| }); | ||
|
|
||
| // Create a simple pipeline | ||
| let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { | ||
| label: Some("Debug Pipeline"), | ||
| layout: None, | ||
| module: &shader, | ||
| entry_point: Some("main"), | ||
| compilation_options: Default::default(), | ||
| cache: None, | ||
| }); | ||
|
|
||
| let mut encoder = | ||
| device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); | ||
| { | ||
| let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { | ||
| label: None, | ||
| timestamp_writes: None, | ||
| }); | ||
| cpass.set_pipeline(&pipeline); | ||
| cpass.dispatch_workgroups(1, 1, 1); | ||
| } | ||
|
|
||
| queue.submit(Some(encoder.finish())); | ||
|
|
||
| device.poll(wgpu::PollType::wait_indefinitely()).unwrap(); | ||
|
|
||
| Example {} | ||
| } | ||
|
|
||
| fn update(&mut self, _event: winit::event::WindowEvent) { | ||
| //empty | ||
| } | ||
|
|
||
| fn resize( | ||
| &mut self, | ||
| _config: &wgpu::SurfaceConfiguration, | ||
| _device: &wgpu::Device, | ||
| _queue: &wgpu::Queue, | ||
| ) { | ||
| } | ||
|
|
||
| fn render(&mut self, _view: &wgpu::TextureView, _device: &wgpu::Device, _queue: &wgpu::Queue) {} | ||
| } | ||
|
|
||
| pub fn main() { | ||
| crate::framework::run::<Example>("debug-printf"); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.