Skip to content
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
20 changes: 10 additions & 10 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4284,7 +4284,7 @@ impl Device {
Some(pipeline_layout) => validation::BindingLayoutSource::Provided(pipeline_layout),
None => validation::BindingLayoutSource::new_derived(&self.limits),
};
let mut shader_binding_sizes = FastHashMap::default();
let mut minimum_binding_sizes = FastHashMap::default();
let mut io = validation::StageIo::default();

let final_entry_point_name;
Expand All @@ -4300,7 +4300,7 @@ impl Device {
if let Some(interface) = shader_module_state.interface.interface() {
io = interface.check_stage(
&mut binding_layout_source,
&mut shader_binding_sizes,
&mut minimum_binding_sizes,
&final_entry_point_name,
stage,
io,
Expand All @@ -4325,7 +4325,7 @@ impl Device {
};

let late_sized_buffer_groups =
Device::make_late_sized_buffer_groups(&shader_binding_sizes, &pipeline_layout);
Device::make_late_sized_buffer_groups(&minimum_binding_sizes, &pipeline_layout);

let cache = match desc.cache {
Some(cache) => {
Expand Down Expand Up @@ -4436,7 +4436,7 @@ impl Device {

self.check_is_valid()?;

let mut shader_binding_sizes = FastHashMap::default();
let mut minimum_binding_sizes = FastHashMap::default();

let color_targets = desc
.fragment
Expand Down Expand Up @@ -4897,7 +4897,7 @@ impl Device {
io = interface
.check_stage(
&mut binding_layout_source,
&mut shader_binding_sizes,
&mut minimum_binding_sizes,
&_vertex_entry_point_name,
stage,
io,
Expand Down Expand Up @@ -4949,7 +4949,7 @@ impl Device {
io = interface
.check_stage(
&mut binding_layout_source,
&mut shader_binding_sizes,
&mut minimum_binding_sizes,
&_task_entry_point_name,
stage,
io,
Expand Down Expand Up @@ -4999,7 +4999,7 @@ impl Device {
io = interface
.check_stage(
&mut binding_layout_source,
&mut shader_binding_sizes,
&mut minimum_binding_sizes,
&_mesh_entry_point_name,
stage,
io,
Expand Down Expand Up @@ -5058,7 +5058,7 @@ impl Device {
io = interface
.check_stage(
&mut binding_layout_source,
&mut shader_binding_sizes,
&mut minimum_binding_sizes,
&fragment_entry_point_name,
stage,
io,
Expand Down Expand Up @@ -5188,7 +5188,7 @@ impl Device {
.flags
.contains(wgt::DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED)
{
for (binding, size) in shader_binding_sizes.iter() {
for (binding, size) in minimum_binding_sizes.iter() {
if size.get() % 16 != 0 {
return Err(pipeline::CreateRenderPipelineError::UnalignedShader {
binding: binding.binding,
Expand All @@ -5200,7 +5200,7 @@ impl Device {
}

let late_sized_buffer_groups =
Device::make_late_sized_buffer_groups(&shader_binding_sizes, &pipeline_layout);
Device::make_late_sized_buffer_groups(&minimum_binding_sizes, &pipeline_layout);

let cache = match desc.cache {
Some(cache) => {
Expand Down
32 changes: 20 additions & 12 deletions wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod shader_io_deductions;
#[derive(Debug)]
enum ResourceType {
Buffer {
size: wgt::BufferSize,
minimum_binding_size: wgt::BufferSize,
},
Texture {
dim: naga::ImageDimension,
Expand Down Expand Up @@ -594,7 +594,9 @@ pub use wgpu_naga_bridge::map_storage_format_to_naga;
impl Resource {
fn check_binding_use(&self, entry: &BindGroupLayoutEntry) -> Result<(), BindingError> {
match self.ty {
ResourceType::Buffer { size } => {
ResourceType::Buffer {
minimum_binding_size,
} => {
let min_size = match entry.ty {
BindingType::Buffer {
ty,
Expand Down Expand Up @@ -627,9 +629,9 @@ impl Resource {
}
};
match min_size {
Some(non_zero) if non_zero < size => {
Some(non_zero) if non_zero < minimum_binding_size => {
return Err(BindingError::WrongBufferSize {
buffer_size: size,
buffer_size: minimum_binding_size,
min_binding_size: non_zero,
})
}
Expand Down Expand Up @@ -797,7 +799,9 @@ impl Resource {
is_reffed_by_sampler_in_entrypoint: bool,
) -> Result<BindingType, BindingError> {
Ok(match self.ty {
ResourceType::Buffer { size } => BindingType::Buffer {
ResourceType::Buffer {
minimum_binding_size,
} => BindingType::Buffer {
ty: match self.class {
naga::AddressSpace::Uniform => wgt::BufferBindingType::Uniform,
naga::AddressSpace::Storage { access } => wgt::BufferBindingType::Storage {
Expand All @@ -806,7 +810,7 @@ impl Resource {
_ => return Err(BindingError::WrongBufferAddressSpace { space: self.class }),
},
has_dynamic_offset: false,
min_binding_size: Some(size),
min_binding_size: Some(minimum_binding_size),
},
ResourceType::Sampler { comparison } => BindingType::Sampler(if comparison {
wgt::SamplerBindingType::Comparison
Expand Down Expand Up @@ -1275,7 +1279,8 @@ impl Interface {
ResourceType::AccelerationStructure { vertex_return }
}
ref other => ResourceType::Buffer {
size: wgt::BufferSize::new(other.size(module.to_ctx()) as u64).unwrap(),
minimum_binding_size: wgt::BufferSize::new(other.size(module.to_ctx()) as u64)
.unwrap(),
},
};
let handle = resources.append(
Expand Down Expand Up @@ -1424,7 +1429,7 @@ impl Interface {
pub fn check_stage(
&self,
layouts: &mut BindingLayoutSource,
shader_binding_sizes: &mut FastHashMap<naga::ResourceBinding, wgt::BufferSize>,
minimum_binding_sizes: &mut FastHashMap<naga::ResourceBinding, wgt::BufferSize>,
entry_point_name: &str,
shader_stage: ShaderStageForValidation,
inputs: StageIo,
Expand All @@ -1448,13 +1453,16 @@ impl Interface {
match layouts {
BindingLayoutSource::Provided(pipeline_layout) => {
// update the required binding size for this buffer
if let ResourceType::Buffer { size } = res.ty {
match shader_binding_sizes.entry(res.bind) {
if let ResourceType::Buffer {
minimum_binding_size,
} = res.ty
{
match minimum_binding_sizes.entry(res.bind) {
Entry::Occupied(e) => {
*e.into_mut() = size.max(*e.get());
*e.into_mut() = minimum_binding_size.max(*e.get());
}
Entry::Vacant(e) => {
e.insert(size);
e.insert(minimum_binding_size);
}
}
}
Expand Down