mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 14:55:05 +00:00
Code review:
Remove .size field from BindGroupEntry, since this information can be obtained from the layout.
This commit is contained in:
parent
7e6d6a33ed
commit
a82062595a
@ -1216,7 +1216,7 @@ impl<A: HalApi> Device<A> {
|
||||
.entries
|
||||
.get(&binding)
|
||||
.ok_or(Error::MissingBindingDeclaration(binding))?;
|
||||
let (res_index, size) = match entry.resource {
|
||||
let res_index = match entry.resource {
|
||||
Br::Buffer(ref bb) => {
|
||||
let bb = Self::create_buffer_binding(
|
||||
&bb,
|
||||
@ -1231,7 +1231,7 @@ impl<A: HalApi> Device<A> {
|
||||
|
||||
let res_index = hal_buffers.len();
|
||||
hal_buffers.push(bb);
|
||||
(res_index, 1)
|
||||
res_index
|
||||
}
|
||||
Br::BufferArray(ref bindings_array) => {
|
||||
if let Some(count) = decl.count {
|
||||
@ -1261,7 +1261,7 @@ impl<A: HalApi> Device<A> {
|
||||
)?;
|
||||
hal_buffers.push(bb);
|
||||
}
|
||||
(res_index, bindings_array.len())
|
||||
res_index
|
||||
}
|
||||
Br::Sampler(id) => {
|
||||
match decl.ty {
|
||||
@ -1293,7 +1293,7 @@ impl<A: HalApi> Device<A> {
|
||||
|
||||
let res_index = hal_samplers.len();
|
||||
hal_samplers.push(&sampler.raw);
|
||||
(res_index, 1)
|
||||
res_index
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::WrongBindingType {
|
||||
@ -1341,7 +1341,7 @@ impl<A: HalApi> Device<A> {
|
||||
view: &view.raw,
|
||||
usage: internal_use,
|
||||
});
|
||||
(res_index, 1)
|
||||
res_index
|
||||
}
|
||||
Br::TextureViewArray(ref bindings_array) => {
|
||||
if let Some(count) = decl.count {
|
||||
@ -1394,14 +1394,13 @@ impl<A: HalApi> Device<A> {
|
||||
});
|
||||
}
|
||||
|
||||
(res_index, bindings_array.len())
|
||||
res_index
|
||||
}
|
||||
};
|
||||
|
||||
hal_entries.push(hal::BindGroupEntry {
|
||||
binding,
|
||||
resource_index: res_index as u32,
|
||||
size: size as u32,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -396,17 +396,14 @@ impl<A: hal::Api> Example<A> {
|
||||
hal::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource_index: 0,
|
||||
size: 1,
|
||||
},
|
||||
hal::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource_index: 0,
|
||||
size: 1,
|
||||
},
|
||||
hal::BindGroupEntry {
|
||||
binding: 2,
|
||||
resource_index: 0,
|
||||
size: 1,
|
||||
},
|
||||
],
|
||||
};
|
||||
@ -428,7 +425,6 @@ impl<A: hal::Api> Example<A> {
|
||||
entries: &[hal::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource_index: 0,
|
||||
size: 1,
|
||||
}],
|
||||
};
|
||||
unsafe { device.create_bind_group(&local_group_desc).unwrap() }
|
||||
|
@ -803,7 +803,6 @@ impl<A: Api> Clone for TextureBinding<'_, A> {
|
||||
pub struct BindGroupEntry {
|
||||
pub binding: u32,
|
||||
pub resource_index: u32,
|
||||
pub size: u32,
|
||||
}
|
||||
|
||||
/// BindGroup descriptor.
|
||||
|
@ -570,6 +570,7 @@ impl crate::Device<super::Api> for super::Device {
|
||||
let stage_bit = map_naga_stage(stage);
|
||||
let mut dynamic_offsets_count = 0u32;
|
||||
for (entry, layout) in desc.entries.iter().zip(desc.layout.entries.iter()) {
|
||||
let size = layout.count.map_or(1, |c| c.get());
|
||||
if let wgt::BindingType::Buffer {
|
||||
has_dynamic_offset: true,
|
||||
..
|
||||
@ -586,7 +587,7 @@ impl crate::Device<super::Api> for super::Device {
|
||||
has_dynamic_offset,
|
||||
..
|
||||
} => {
|
||||
debug_assert_eq!(entry.size, 1);
|
||||
debug_assert_eq!(size, 1);
|
||||
let source = &desc.buffers[entry.resource_index as usize];
|
||||
let remaining_size =
|
||||
wgt::BufferSize::new(source.buffer.size - source.offset);
|
||||
@ -616,13 +617,13 @@ impl crate::Device<super::Api> for super::Device {
|
||||
}
|
||||
wgt::BindingType::Texture { .. } | wgt::BindingType::StorageTexture { .. } => {
|
||||
let start = entry.resource_index;
|
||||
let end = entry.resource_index + entry.size;
|
||||
let end = start + size;
|
||||
bg.textures.extend(
|
||||
desc.textures[start as usize..end as usize]
|
||||
.iter()
|
||||
.map(|tex| tex.view.as_raw()),
|
||||
);
|
||||
counter.textures += entry.size;
|
||||
counter.textures += size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -866,10 +866,13 @@ impl crate::Device<super::Api> for super::Device {
|
||||
if entry.binding as usize >= types.len() {
|
||||
types.resize(
|
||||
entry.binding as usize + 1,
|
||||
vk::DescriptorType::INPUT_ATTACHMENT,
|
||||
(vk::DescriptorType::INPUT_ATTACHMENT, 0),
|
||||
);
|
||||
}
|
||||
types[entry.binding as usize] = conv::map_binding_type(entry.ty);
|
||||
types[entry.binding as usize] = (
|
||||
conv::map_binding_type(entry.ty),
|
||||
entry.count.map_or(1, |c| c.get()),
|
||||
);
|
||||
|
||||
match entry.ty {
|
||||
wgt::BindingType::Buffer {
|
||||
@ -910,8 +913,8 @@ impl crate::Device<super::Api> for super::Device {
|
||||
.iter()
|
||||
.map(|entry| vk::DescriptorSetLayoutBinding {
|
||||
binding: entry.binding,
|
||||
descriptor_type: types[entry.binding as usize],
|
||||
descriptor_count: entry.count.map_or(1, |c| c.get()),
|
||||
descriptor_type: types[entry.binding as usize].0,
|
||||
descriptor_count: types[entry.binding as usize].1,
|
||||
stage_flags: conv::map_shader_stage(entry.visibility),
|
||||
p_immutable_samplers: ptr::null(),
|
||||
})
|
||||
@ -1006,7 +1009,10 @@ impl crate::Device<super::Api> for super::Device {
|
||||
let mut sampler_infos = Vec::with_capacity(desc.samplers.len());
|
||||
let mut image_infos = Vec::with_capacity(desc.textures.len());
|
||||
for entry in desc.entries {
|
||||
let ty = desc.layout.types[entry.binding as usize];
|
||||
let (ty, size) = desc.layout.types[entry.binding as usize];
|
||||
if size == 0 {
|
||||
continue; // empty slot
|
||||
}
|
||||
let mut write = vk::WriteDescriptorSet::builder()
|
||||
.dst_set(*set.raw())
|
||||
.dst_binding(entry.binding)
|
||||
@ -1024,7 +1030,7 @@ impl crate::Device<super::Api> for super::Device {
|
||||
vk::DescriptorType::SAMPLED_IMAGE | vk::DescriptorType::STORAGE_IMAGE => {
|
||||
let index = image_infos.len();
|
||||
let start = entry.resource_index;
|
||||
let end = entry.resource_index + entry.size;
|
||||
let end = start + size;
|
||||
image_infos.extend(desc.textures[start as usize..end as usize].iter().map(
|
||||
|binding| {
|
||||
let layout =
|
||||
@ -1043,7 +1049,7 @@ impl crate::Device<super::Api> for super::Device {
|
||||
| vk::DescriptorType::STORAGE_BUFFER_DYNAMIC => {
|
||||
let index = buffer_infos.len();
|
||||
let start = entry.resource_index;
|
||||
let end = entry.resource_index + entry.size;
|
||||
let end = start + size;
|
||||
buffer_infos.extend(desc.buffers[start as usize..end as usize].iter().map(
|
||||
|binding| {
|
||||
vk::DescriptorBufferInfo::builder()
|
||||
|
@ -271,7 +271,7 @@ pub struct Sampler {
|
||||
pub struct BindGroupLayout {
|
||||
raw: vk::DescriptorSetLayout,
|
||||
desc_count: gpu_descriptor::DescriptorTotalCount,
|
||||
types: Vec<vk::DescriptorType>,
|
||||
types: Vec<(vk::DescriptorType, u32)>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
Loading…
Reference in New Issue
Block a user