Skip to content

Commit

Permalink
Validate use of alternate blend source in shader validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederik Vestre committed Aug 13, 2023
1 parent 336d475 commit 419db63
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ pub enum EntryPointError {
InvalidIntegerInterpolation { location: u32 },
#[error(transparent)]
Function(#[from] FunctionError),
#[error(
"Invalid locations {location_mask:?} are set for blend_src_1. Only the first location may be set."
)]
InvalidLocationMaskForAlternateBlendSource { location_mask: BitSet },
}

#[cfg(feature = "validate")]
Expand All @@ -115,6 +119,7 @@ fn storage_usage(access: crate::StorageAccess) -> GlobalUse {
struct VaryingContext<'a> {
stage: crate::ShaderStage,
output: bool,
alternate_blend_source: bool,
types: &'a UniqueArena<crate::Type>,
type_info: &'a Vec<super::r#type::TypeInfo>,
location_mask: &'a mut BitSet,
Expand Down Expand Up @@ -319,6 +324,7 @@ impl VaryingContext<'_> {
}
}
}
self.alternate_blend_source = alternate_blend_source;

let needs_interpolation = match self.stage {
crate::ShaderStage::Vertex => self.output,
Expand Down Expand Up @@ -628,6 +634,7 @@ impl super::Validator {
let mut ctx = VaryingContext {
stage: ep.stage,
output: false,
alternate_blend_source: false,
types: &module.types,
type_info: &self.types,
location_mask: &mut self.location_mask,
Expand All @@ -647,6 +654,7 @@ impl super::Validator {
let mut ctx = VaryingContext {
stage: ep.stage,
output: true,
alternate_blend_source: false,
types: &module.types,
type_info: &self.types,
location_mask: &mut self.location_mask,
Expand All @@ -658,6 +666,27 @@ impl super::Validator {
};
ctx.validate(fr.ty, fr.binding.as_ref())
.map_err_inner(|e| EntryPointError::Result(e).with_span())?;
#[cfg(feature = "validate")]
if ctx.alternate_blend_source {
/* Check if only the first bit in the location mask is set */
if !self
.location_mask
.get_ref()
.iter()
.enumerate()
.all(|(idx, val)| match idx {
0 => val,
_ => !val,
})
{
return Err(
EntryPointError::InvalidLocationMaskForAlternateBlendSource {
location_mask: self.location_mask.clone(),
}
.with_span(),
);
}
}

#[cfg(feature = "validate")]
if ep.stage == crate::ShaderStage::Vertex
Expand Down

0 comments on commit 419db63

Please sign in to comment.