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

Improve binding error #6553

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
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
75 changes: 68 additions & 7 deletions wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,37 @@ enum ResourceType {
AccelerationStructure,
}

#[derive(Clone, Debug)]
pub enum BindingTypeName {
Buffer,
Texture,
Sampler,
AccelerationStructure,
}

impl From<&ResourceType> for BindingTypeName {
fn from(ty: &ResourceType) -> BindingTypeName {
match ty {
ResourceType::Buffer { .. } => BindingTypeName::Buffer,
ResourceType::Texture { .. } => BindingTypeName::Texture,
ResourceType::Sampler { .. } => BindingTypeName::Sampler,
ResourceType::AccelerationStructure { .. } => BindingTypeName::AccelerationStructure,
}
}
}

impl From<&BindingType> for BindingTypeName {
fn from(ty: &BindingType) -> BindingTypeName {
match ty {
BindingType::Buffer { .. } => BindingTypeName::Buffer,
BindingType::Texture { .. } => BindingTypeName::Texture,
BindingType::StorageTexture { .. } => BindingTypeName::Texture,
BindingType::Sampler { .. } => BindingTypeName::Sampler,
BindingType::AccelerationStructure { .. } => BindingTypeName::AccelerationStructure,
}
}
}

#[derive(Debug)]
struct Resource {
#[allow(unused)]
Expand Down Expand Up @@ -140,13 +171,20 @@ pub enum BindingError {
Missing,
#[error("Visibility flags don't include the shader stage")]
Invisible,
#[error("Type on the shader side does not match the pipeline binding")]
WrongType,
#[error(
"Type on the shader side ({shader:?}) does not match the pipeline binding ({binding:?})"
)]
WrongType {
binding: BindingTypeName,
shader: BindingTypeName,
},
#[error("Storage class {binding:?} doesn't match the shader {shader:?}")]
WrongAddressSpace {
binding: naga::AddressSpace,
shader: naga::AddressSpace,
},
#[error("Address space {space:?} is not a valid Buffer address space")]
WrongBufferAddressSpace { space: naga::AddressSpace },
#[error("Buffer structure size {buffer_size}, added to one element of an unbound array, if it's the last field, ended up greater than the given `min_binding_size`, which is {min_binding_size}")]
WrongBufferSize {
buffer_size: wgt::BufferSize,
Expand Down Expand Up @@ -378,7 +416,12 @@ impl Resource {
}
min_binding_size
}
_ => return Err(BindingError::WrongType),
_ => {
return Err(BindingError::WrongType {
binding: (&entry.ty).into(),
shader: (&self.ty).into(),
})
}
};
match min_size {
Some(non_zero) if non_zero < size => {
Expand All @@ -396,7 +439,12 @@ impl Resource {
return Err(BindingError::WrongSamplerComparison);
}
}
_ => return Err(BindingError::WrongType),
_ => {
return Err(BindingError::WrongType {
binding: (&entry.ty).into(),
shader: (&self.ty).into(),
})
}
},
ResourceType::Texture {
dim,
Expand Down Expand Up @@ -478,7 +526,12 @@ impl Resource {
access: naga_access,
}
}
_ => return Err(BindingError::WrongType),
_ => {
return Err(BindingError::WrongType {
binding: (&entry.ty).into(),
shader: (&self.ty).into(),
})
}
};
if class != expected_class {
return Err(BindingError::WrongTextureClass {
Expand All @@ -487,7 +540,15 @@ impl Resource {
});
}
}
ResourceType::AccelerationStructure => (),
ResourceType::AccelerationStructure => match entry.ty {
BindingType::AccelerationStructure => (),
_ => {
return Err(BindingError::WrongType {
binding: (&entry.ty).into(),
shader: (&self.ty).into(),
})
}
},
};

Ok(())
Expand All @@ -504,7 +565,7 @@ impl Resource {
naga::AddressSpace::Storage { access } => wgt::BufferBindingType::Storage {
read_only: access == naga::StorageAccess::LOAD,
},
_ => return Err(BindingError::WrongType),
_ => return Err(BindingError::WrongBufferAddressSpace { space: self.class }),
},
has_dynamic_offset: false,
min_binding_size: Some(size),
Expand Down