Skip to content
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

shader struct name replacing #2484

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions vulkano-shaders/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,15 @@ impl TypeStruct {
.iter()
.find_map(|instruction| match instruction {
Instruction::Name { name, .. } => {
// rust-gpu uses fully qualified rust paths as names which contain `:`.
// I sady don't know how to check against all kinds of invalid ident chars.
let name = name.replace(':', "_");
// Replace chars that could potentially cause the ident to be invalid with "_".
// For example, Rust-GPU names structs by their fully qualified rust name (e.g.
// "foo::bar::MyStruct") in which the ":" is an invalid character for idents.
let mut name =
name.replace(|c: char| !(c.is_ascii_alphanumeric() || c == '_'), "_");
if name.starts_with(|c: char| !c.is_ascii_alphabetic()) {
name.insert(0, '_');
}

// Worst case: invalid idents will get the UnnamedX name below
syn::parse_str(&name).ok()
}
Expand Down
Loading