Debugging Shaders
See:
- https://developer.apple.com/documentation/metal/shader_authoring/developing_and_debugging_metal_shaders
- https://www.khronos.org/opengl/wiki/Uniform_(GLSL)/Explicit_Uniform_Location
Troubleshooting
- Make sure that you enabled logging in your Rust project. The logs can be very useful for debugging.
- For
env_logger, you'll need it installed and set up and then you need tocargo runwith theRUST_LOG=infoenvironment variable set.
- For
- Pay attention to
location={value}issues. They get kind of interesting when you start sharing arrays. - Any
ShaderStagein yourRenderPipelineshould be enabled for the appropriate Shaders that you expect to use them. - Make sure all the data expected to come out of the Vertex shader should actually reach the defined output registers. Then make sure they translate into the match up with the input registers on the Fragment shader.
Setting up Rust with XCode Graphics Debugger
- Tested versions
- macOS Catalina version 10.15.7
- XCode version 12.0.1 (12A7300)
- Download and install XCode.
- Create a new Xcode project.
- Under the "Other" template category, select "External Build System".
- Set options for the new project:
- Use some sensible name for the "Product Name", e.g.,
rust-metal-graphics-debugger. - The build tool should be the path to your
rustc, which is usually/Users/{you}/.cargo/bin/rustc.
- Use some sensible name for the "Product Name", e.g.,
- After clicking "Finish", you'll need to select the folder in which to create the new project. Pick something sensible, e.g.,
/Users/{you}/Projects- You don't really need the Git repository, since you won't be doing any Rust development here.
- At the top left of the window, there is a button that will look like
rust-metal-graphics-debugger > My Mac, where clicking the left-side will give you a context menu forEdit Scheme,New Scheme, andManage Schemes. And clicking the right-side will give you a selection of platforms to target, i.e.,My MacorAny Mac.- Click on the left-side of this button and select
Edit Scheme.
- Click on the left-side of this button and select
- Configure the
Runscheme.Infotab- Build Configuration should be
Debug. - Executable should be your Rust binary. In your Cargo project (outside of Xcode), run
cargo build, then your binary can be found at/target/debug/or/target/debug/example/in your Cargo project. - Make sure
Debug executableis checked. - Make sure
Meis selected (instead ofroot) - Select Launch
automatically.
- Build Configuration should be
Argumentstab- You might want to set the following environment variables (Optional).
CXX=/usr/bin/clang++RUST_BACKTRACE=fullRUST_LOG=info
Optionstab- Make sure
GPU Frame Captureis set toAutomatically Enabled. - Click on
Use custom working directoryand set it to your Cargo project root.
- Make sure
Diagnosticstab- Deselect
API ValidationunderMetal. We're not writing any direct Metal Shader Language, only what is cross-compiled from SPIR-V, so we don't necessarily need to check this unless we come across a bug from upstream.
- Deselect
- Click the "Play" button at the top left. Your app should come up.
- In the software menu (top of screen), go to
Debug > Capture GPU Frame. - Use the link at the top of this page to Apple docs for how to debug Vertex and Fragment shaders.