-
Notifications
You must be signed in to change notification settings - Fork 60
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
Simplify extensions. Add Debug PrintF #216
Draft
Matthias-Fauconneau
wants to merge
1
commit into
gfx-rs:master
Choose a base branch
from
Matthias-Fauconneau:ext
base: master
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.
Draft
Changes from all commits
Commits
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
There are no files selected for viewing
This file contains 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 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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,8 +9,9 @@ mod table; | |||||||||||||
mod utils; | ||||||||||||||
|
||||||||||||||
use std::{ | ||||||||||||||
env, fs, | ||||||||||||||
io::{Read, Write}, | ||||||||||||||
env, | ||||||||||||||
fs, | ||||||||||||||
io::Write, | ||||||||||||||
path::{Path, PathBuf}, | ||||||||||||||
process, | ||||||||||||||
}; | ||||||||||||||
|
@@ -61,65 +62,82 @@ fn main() { | |||||||||||||
panic!("SPIRV-Headers missing - please checkout using git submodule"); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
let mut contents = String::new(); | ||||||||||||||
|
||||||||||||||
{ | ||||||||||||||
let path = autogen_src_dir | ||||||||||||||
.join("external/SPIRV-Headers/include/spirv/unified1/spirv.core.grammar.json"); | ||||||||||||||
let mut file = fs::File::open(path).unwrap(); | ||||||||||||||
file.read_to_string(&mut contents).unwrap(); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
let grammar: structs::Grammar = { | ||||||||||||||
let mut original = serde_json::from_str(&contents).unwrap(); | ||||||||||||||
let mut original = | ||||||||||||||
serde_json::from_str( | ||||||||||||||
&std::str::from_utf8( | ||||||||||||||
&fs::read(autogen_src_dir.join( | ||||||||||||||
"external/SPIRV-Headers/include/spirv/unified1/spirv.core.grammar.json", | ||||||||||||||
)) | ||||||||||||||
.unwrap(), | ||||||||||||||
) | ||||||||||||||
.unwrap(), | ||||||||||||||
) | ||||||||||||||
.unwrap(); | ||||||||||||||
map_reserved_instructions(&mut original); | ||||||||||||||
original | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
// For GLSLstd450 extended instruction set. | ||||||||||||||
{ | ||||||||||||||
let path = autogen_src_dir.join( | ||||||||||||||
"external/SPIRV-Headers/include/spirv/unified1/extinst.glsl.std.450.grammar.json", | ||||||||||||||
); | ||||||||||||||
let mut file = fs::File::open(path).unwrap(); | ||||||||||||||
contents.clear(); | ||||||||||||||
file.read_to_string(&mut contents).unwrap(); | ||||||||||||||
} | ||||||||||||||
let gl_grammar: structs::ExtInstSetGrammar = serde_json::from_str(&contents).unwrap(); | ||||||||||||||
|
||||||||||||||
// For OpenCL extended instruction set. | ||||||||||||||
{ | ||||||||||||||
let path = autogen_src_dir.join( | ||||||||||||||
"external/SPIRV-Headers/include/spirv/unified1/extinst.opencl.std.100.grammar.json", | ||||||||||||||
); | ||||||||||||||
let mut file = fs::File::open(path).unwrap(); | ||||||||||||||
contents.clear(); | ||||||||||||||
file.read_to_string(&mut contents).unwrap(); | ||||||||||||||
} | ||||||||||||||
let cl_grammar: structs::ExtInstSetGrammar = serde_json::from_str(&contents).unwrap(); | ||||||||||||||
let extended_instruction_sets = [ | ||||||||||||||
("GLSL.std.450", "GLOp", "https://www.khronos.org/registry/spir-v/specs/unified1/GLSL.std.450.html"), | ||||||||||||||
("OpenCL.std.100", "CLOp", "https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.ExtendedInstructionSet.100.html"), | ||||||||||||||
("NonSemantic.DebugPrintF", "DebugPrintFOp", "https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/master/docs/debug_printf.md"), | ||||||||||||||
Comment on lines
+82
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use spaces to indent this. The autoformatter refuses to do so because the lines are too long.
Suggested change
|
||||||||||||||
]; | ||||||||||||||
let extended_instruction_sets = extended_instruction_sets.map(|(ext, op, url)| { | ||||||||||||||
let grammar: structs::ExtInstSetGrammar = serde_json::from_str( | ||||||||||||||
&std::str::from_utf8( | ||||||||||||||
&fs::read(autogen_src_dir.join(format!( | ||||||||||||||
"external/SPIRV-Headers/include/spirv/unified1/extinst.{}.grammar.json", | ||||||||||||||
ext.to_lowercase() | ||||||||||||||
))) | ||||||||||||||
.unwrap(), | ||||||||||||||
) | ||||||||||||||
.unwrap(), | ||||||||||||||
) | ||||||||||||||
.unwrap(); | ||||||||||||||
(ext, op, url, grammar) | ||||||||||||||
}); | ||||||||||||||
|
||||||||||||||
// Path to the generated SPIR-V header file. | ||||||||||||||
// SPIR-V header | ||||||||||||||
write_formatted(&autogen_src_dir.join("../spirv/autogen_spirv.rs"), { | ||||||||||||||
let core = header::gen_spirv_header(&grammar); | ||||||||||||||
let gl = header::gen_glsl_std_450_opcodes(&gl_grammar); | ||||||||||||||
let cl = header::gen_opencl_std_opcodes(&cl_grammar); | ||||||||||||||
format!("{}\n{}\n{}", core, gl, cl) | ||||||||||||||
let extended_instruction_sets = | ||||||||||||||
extended_instruction_sets | ||||||||||||||
.iter() | ||||||||||||||
.map(|(ext, op, url, grammar)| { | ||||||||||||||
header::gen_opcodes( | ||||||||||||||
op, | ||||||||||||||
&grammar, | ||||||||||||||
&format!("[{}]({}) extended instruction opcode", ext, url), | ||||||||||||||
) | ||||||||||||||
.to_string() | ||||||||||||||
}); | ||||||||||||||
format!( | ||||||||||||||
"{}\n{}", | ||||||||||||||
core, | ||||||||||||||
extended_instruction_sets.collect::<Box<_>>().join("\n") | ||||||||||||||
) | ||||||||||||||
}); | ||||||||||||||
|
||||||||||||||
// Path to the generated instruction table. | ||||||||||||||
// Instruction table | ||||||||||||||
write_formatted( | ||||||||||||||
&autogen_src_dir.join("../rspirv/grammar/autogen_table.rs"), | ||||||||||||||
table::gen_grammar_inst_table_operand_kinds(&grammar), | ||||||||||||||
); | ||||||||||||||
// Path to the generated GLSLstd450 extended instruction set header. | ||||||||||||||
write_formatted( | ||||||||||||||
&autogen_src_dir.join("../rspirv/grammar/autogen_glsl_std_450.rs"), | ||||||||||||||
table::gen_glsl_std_450_inst_table(&gl_grammar), | ||||||||||||||
); | ||||||||||||||
write_formatted( | ||||||||||||||
&autogen_src_dir.join("../rspirv/grammar/autogen_opencl_std_100.rs"), | ||||||||||||||
table::gen_opencl_std_100_inst_table(&cl_grammar), | ||||||||||||||
); | ||||||||||||||
// Extended instruction sets | ||||||||||||||
for (ext, _, _, grammar) in extended_instruction_sets { | ||||||||||||||
write_formatted( | ||||||||||||||
&autogen_src_dir.join(format!( | ||||||||||||||
"../rspirv/grammar/autogen_{}.rs", | ||||||||||||||
ext.replace(".", "_").to_lowercase() | ||||||||||||||
)), | ||||||||||||||
table::gen_instruction_table( | ||||||||||||||
&grammar.instructions, | ||||||||||||||
&format!("{}_INSTRUCTION_TABLE", ext.replace(".", "_").to_uppercase()), | ||||||||||||||
true, | ||||||||||||||
), | ||||||||||||||
); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Path to the generated operands kind in data representation. | ||||||||||||||
write_formatted( | ||||||||||||||
|
This file contains 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 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 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,11 @@ | ||
// AUTOMATICALLY GENERATED from the SPIR-V JSON grammar: | ||
// external/spirv.core.grammar.json. | ||
// DO NOT MODIFY! | ||
|
||
static NONSEMANTIC_DEBUGPRINTF_INSTRUCTION_TABLE: &[ExtendedInstruction<'static>] = &[ext_inst!( | ||
DebugPrintf, | ||
1u32, | ||
[], | ||
[], | ||
[(IdRef, One), (IdRef, ZeroOrMore)] | ||
)]; |
This file contains 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use rspirv::{ | ||
binary::{Assemble as _, Disassemble as _}, | ||
dr, lift, | ||
dr, | ||
lift, | ||
}; | ||
|
||
use std::path::PathBuf; | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe keep this simple with
read_to_string
? Same below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I didn't know about it ><.
There really should be a note in std:fs::read about read_to_string existence. It's not the first time this annoys me ^^