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

Properly validate shader interfaces between stages #2418

Merged
merged 2 commits into from
Dec 1, 2023
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
69 changes: 45 additions & 24 deletions vulkano/src/pipeline/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ use self::{
viewport::ViewportState,
};
use super::{
cache::PipelineCache, DynamicState, Pipeline, PipelineBindPoint, PipelineCreateFlags,
PipelineLayout, PipelineShaderStageCreateInfo,
cache::PipelineCache, shader::validate_interfaces_compatible, DynamicState, Pipeline,
PipelineBindPoint, PipelineCreateFlags, PipelineLayout, PipelineShaderStageCreateInfo,
};
use crate::{
device::{Device, DeviceOwned, DeviceOwnedDebugWrapper},
Expand Down Expand Up @@ -1953,29 +1953,50 @@ impl GraphicsPipelineCreateInfo {
.flatten()
.collect();

// TODO: this check is too strict; the output only has to be a superset, any variables
// not used in the input of the next shader are just ignored.
for (output, input) in ordered_stages.iter().zip(ordered_stages.iter().skip(1)) {
if let Err(err) = (input.entry_point.info().input_interface)
.matches(&output.entry_point.info().output_interface)
{
return Err(Box::new(ValidationError {
context: "stages".into(),
problem: format!(
"the output interface of the `ShaderStage::{:?}` stage does not \
match the input interface of the `ShaderStage::{:?}` stage: {}",
ShaderStage::from(output.entry_point.info().execution_model),
ShaderStage::from(input.entry_point.info().execution_model),
err
)
.into(),
vuids: &[
"VUID-VkGraphicsPipelineCreateInfo-pStages-00742",
"VUID-VkGraphicsPipelineCreateInfo-None-04889",
],
..Default::default()
}));
}
let out_spirv = output.entry_point.module().spirv();
let (out_execution_model, out_interface) =
match out_spirv.function(output.entry_point.id()).entry_point() {
Some(&Instruction::EntryPoint {
execution_model,
ref interface,
..
}) => (execution_model, interface),
_ => unreachable!(),
};

let in_spirv = input.entry_point.module().spirv();
let (in_execution_model, in_interface) =
match in_spirv.function(input.entry_point.id()).entry_point() {
Some(&Instruction::EntryPoint {
execution_model,
ref interface,
..
}) => (execution_model, interface),
_ => unreachable!(),
};

validate_interfaces_compatible(
out_spirv,
out_execution_model,
out_interface,
in_spirv,
in_execution_model,
in_interface,
device.enabled_features().maintenance4,
)
.map_err(|mut err| {
err.context = "stages".into();
err.problem = format!(
"the output interface of the `{:?}` stage is not compatible with \
the input interface of the `{:?}` stage: {}",
ShaderStage::from(out_execution_model),
ShaderStage::from(in_execution_model),
err.problem
)
.into();
err
})?;
}

// VUID-VkGraphicsPipelineCreateInfo-layout-01688
Expand Down
Loading