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

Add a preserve_bindings opt to the builder and codegen opts #830

Merged
merged 4 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions crates/rustc_codegen_spirv/src/codegen_cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ pub struct CodegenArgs {
pub uniform_buffer_standard_layout: bool,
pub scalar_block_layout: bool,
pub skip_block_layout: bool,

// spirv-opt flags
pub preserve_bindings: bool,
}

impl CodegenArgs {
Expand Down Expand Up @@ -289,6 +292,13 @@ impl CodegenArgs {
opts.optflagopt("", "scalar-block-layout", "Enable VK_EXT_scalar_block_layout when checking standard uniform, storage buffer, and push constant layouts. Scalar layout rules are more permissive than relaxed block layout so in effect this will override the --relax-block-layout option.", "");
opts.optflagopt("", "skip-block-layout", "Skip checking standard uniform/storage buffer layout. Overrides any --relax-block-layout or --scalar-block-layout option.", "");

opts.optflagopt(
"",
"preserve-bindings",
"Preserve unused descriptor bindings. Useful for reflection.",
"",
);

let matches = opts.parse(args)?;
let module_output_type =
matches.opt_get_default("module-output", ModuleOutputType::Single)?;
Expand All @@ -306,6 +316,8 @@ impl CodegenArgs {
let scalar_block_layout = matches.opt_present("scalar-block-layout");
let skip_block_layout = matches.opt_present("skip-block-layout");

let preserve_bindings = matches.opt_present("preserve-bindings");

let relax_block_layout = if relax_block_layout { Some(true) } else { None };

let spirv_metadata = match spirv_metadata.as_deref() {
Expand Down Expand Up @@ -334,6 +346,8 @@ impl CodegenArgs {
uniform_buffer_standard_layout,
scalar_block_layout,
skip_block_layout,

preserve_bindings,
})
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn post_link_single_module(
let opt_options = spirv_tools::opt::Options {
validator_options: Some(val_options.clone()),
max_id_bound: None,
preserve_bindings: false,
preserve_bindings: cg_args.preserve_bindings,
preserve_spec_constants: false,
};

Expand Down
14 changes: 14 additions & 0 deletions crates/spirv-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ pub struct SpirvBuilder {
pub uniform_buffer_standard_layout: bool,
pub scalar_block_layout: bool,
pub skip_block_layout: bool,

// spirv-opt flags
pub preserve_bindings: bool,
}

impl SpirvBuilder {
Expand All @@ -187,6 +190,8 @@ impl SpirvBuilder {
uniform_buffer_standard_layout: false,
scalar_block_layout: false,
skip_block_layout: false,

preserve_bindings: false,
}
}

Expand Down Expand Up @@ -278,6 +283,12 @@ impl SpirvBuilder {
self
}

/// Preserve unused descriptor bindings. Useful for reflection.
pub fn preserve_bindings(mut self, v: bool) -> Self {
self.preserve_bindings = v;
self
}

/// Builds the module. If `print_metadata` is [`MetadataPrintout::Full`], you usually don't have to inspect the path
/// in the result, as the environment variable for the path to the module will already be set.
pub fn build(mut self) -> Result<CompileResult, SpirvBuilderError> {
Expand Down Expand Up @@ -424,6 +435,9 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
if builder.skip_block_layout {
llvm_args.push("--skip-block-layout");
}
if builder.preserve_bindings {
llvm_args.push("--preserve-bindings");
}
let llvm_args = join_checking_for_separators(llvm_args, " ");
if !llvm_args.is_empty() {
rustflags.push(["-Cllvm-args=", &llvm_args].concat());
Expand Down