mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Remove update after bind workaround (#3397)
This commit is contained in:
parent
2c3f9fabb7
commit
5f99940afd
@ -90,9 +90,6 @@ pub mod api {
|
||||
pub use super::vulkan::Api as Vulkan;
|
||||
}
|
||||
|
||||
#[cfg(feature = "vulkan")]
|
||||
pub use vulkan::UpdateAfterBindTypes;
|
||||
|
||||
use std::{
|
||||
borrow::{Borrow, Cow},
|
||||
fmt,
|
||||
|
@ -81,7 +81,6 @@ impl PhysicalDeviceFeatures {
|
||||
requested_features: wgt::Features,
|
||||
downlevel_flags: wgt::DownlevelFlags,
|
||||
private_caps: &super::PrivateCapabilities,
|
||||
uab_types: super::UpdateAfterBindTypes,
|
||||
) -> Self {
|
||||
let needs_sampled_image_non_uniform = requested_features.contains(
|
||||
wgt::Features::TEXTURE_BINDING_ARRAY
|
||||
@ -191,18 +190,6 @@ impl PhysicalDeviceFeatures {
|
||||
.shader_storage_buffer_array_non_uniform_indexing(
|
||||
needs_storage_buffer_non_uniform,
|
||||
)
|
||||
.descriptor_binding_sampled_image_update_after_bind(
|
||||
uab_types.contains(super::UpdateAfterBindTypes::SAMPLED_TEXTURE),
|
||||
)
|
||||
.descriptor_binding_storage_image_update_after_bind(
|
||||
uab_types.contains(super::UpdateAfterBindTypes::STORAGE_TEXTURE),
|
||||
)
|
||||
.descriptor_binding_uniform_buffer_update_after_bind(
|
||||
uab_types.contains(super::UpdateAfterBindTypes::UNIFORM_BUFFER),
|
||||
)
|
||||
.descriptor_binding_storage_buffer_update_after_bind(
|
||||
uab_types.contains(super::UpdateAfterBindTypes::STORAGE_BUFFER),
|
||||
)
|
||||
.descriptor_binding_partially_bound(needs_partially_bound)
|
||||
.build(),
|
||||
)
|
||||
@ -687,55 +674,9 @@ impl PhysicalDeviceCapabilities {
|
||||
extensions
|
||||
}
|
||||
|
||||
fn to_wgpu_limits(&self, features: &PhysicalDeviceFeatures) -> wgt::Limits {
|
||||
fn to_wgpu_limits(&self) -> wgt::Limits {
|
||||
let limits = &self.properties.limits;
|
||||
|
||||
let uab_types = super::UpdateAfterBindTypes::from_features(features);
|
||||
|
||||
let max_sampled_textures =
|
||||
if uab_types.contains(super::UpdateAfterBindTypes::SAMPLED_TEXTURE) {
|
||||
if let Some(di) = self.descriptor_indexing {
|
||||
di.max_per_stage_descriptor_update_after_bind_sampled_images
|
||||
} else {
|
||||
limits.max_per_stage_descriptor_sampled_images
|
||||
}
|
||||
} else {
|
||||
limits.max_per_stage_descriptor_sampled_images
|
||||
};
|
||||
|
||||
let max_storage_textures =
|
||||
if uab_types.contains(super::UpdateAfterBindTypes::STORAGE_TEXTURE) {
|
||||
if let Some(di) = self.descriptor_indexing {
|
||||
di.max_per_stage_descriptor_update_after_bind_storage_images
|
||||
} else {
|
||||
limits.max_per_stage_descriptor_storage_images
|
||||
}
|
||||
} else {
|
||||
limits.max_per_stage_descriptor_storage_images
|
||||
};
|
||||
|
||||
let max_uniform_buffers = if uab_types.contains(super::UpdateAfterBindTypes::UNIFORM_BUFFER)
|
||||
{
|
||||
if let Some(di) = self.descriptor_indexing {
|
||||
di.max_per_stage_descriptor_update_after_bind_uniform_buffers
|
||||
} else {
|
||||
limits.max_per_stage_descriptor_uniform_buffers
|
||||
}
|
||||
} else {
|
||||
limits.max_per_stage_descriptor_uniform_buffers
|
||||
};
|
||||
|
||||
let max_storage_buffers = if uab_types.contains(super::UpdateAfterBindTypes::STORAGE_BUFFER)
|
||||
{
|
||||
if let Some(di) = self.descriptor_indexing {
|
||||
di.max_per_stage_descriptor_update_after_bind_storage_buffers
|
||||
} else {
|
||||
limits.max_per_stage_descriptor_storage_buffers
|
||||
}
|
||||
} else {
|
||||
limits.max_per_stage_descriptor_storage_buffers
|
||||
};
|
||||
|
||||
let max_compute_workgroup_sizes = limits.max_compute_work_group_size;
|
||||
let max_compute_workgroups_per_dimension = limits.max_compute_work_group_count[0]
|
||||
.min(limits.max_compute_work_group_count[1])
|
||||
@ -763,11 +704,11 @@ impl PhysicalDeviceCapabilities {
|
||||
.max_descriptor_set_uniform_buffers_dynamic,
|
||||
max_dynamic_storage_buffers_per_pipeline_layout: limits
|
||||
.max_descriptor_set_storage_buffers_dynamic,
|
||||
max_sampled_textures_per_shader_stage: max_sampled_textures,
|
||||
max_sampled_textures_per_shader_stage: limits.max_per_stage_descriptor_sampled_images,
|
||||
max_samplers_per_shader_stage: limits.max_per_stage_descriptor_samplers,
|
||||
max_storage_buffers_per_shader_stage: max_storage_buffers,
|
||||
max_storage_textures_per_shader_stage: max_storage_textures,
|
||||
max_uniform_buffers_per_shader_stage: max_uniform_buffers,
|
||||
max_storage_buffers_per_shader_stage: limits.max_per_stage_descriptor_storage_buffers,
|
||||
max_storage_textures_per_shader_stage: limits.max_per_stage_descriptor_storage_images,
|
||||
max_uniform_buffers_per_shader_stage: limits.max_per_stage_descriptor_uniform_buffers,
|
||||
max_uniform_buffer_binding_size: limits
|
||||
.max_uniform_buffer_range
|
||||
.min(crate::auxil::MAX_I32_BINDING_SIZE),
|
||||
@ -1092,7 +1033,7 @@ impl super::Instance {
|
||||
},
|
||||
};
|
||||
let capabilities = crate::Capabilities {
|
||||
limits: phd_capabilities.to_wgpu_limits(&phd_features),
|
||||
limits: phd_capabilities.to_wgpu_limits(),
|
||||
alignments: phd_capabilities.to_hal_alignments(),
|
||||
downlevel: wgt::DownlevelCapabilities {
|
||||
flags: downlevel_flags,
|
||||
@ -1161,7 +1102,6 @@ impl super::Adapter {
|
||||
&self,
|
||||
enabled_extensions: &[&'static CStr],
|
||||
features: wgt::Features,
|
||||
uab_types: super::UpdateAfterBindTypes,
|
||||
) -> PhysicalDeviceFeatures {
|
||||
PhysicalDeviceFeatures::from_extensions_and_requested_features(
|
||||
self.phd_capabilities.effective_api_version,
|
||||
@ -1169,7 +1109,6 @@ impl super::Adapter {
|
||||
features,
|
||||
self.downlevel_flags,
|
||||
&self.private_caps,
|
||||
uab_types,
|
||||
)
|
||||
}
|
||||
|
||||
@ -1185,7 +1124,6 @@ impl super::Adapter {
|
||||
handle_is_owned: bool,
|
||||
enabled_extensions: &[&'static CStr],
|
||||
features: wgt::Features,
|
||||
uab_types: super::UpdateAfterBindTypes,
|
||||
family_index: u32,
|
||||
queue_index: u32,
|
||||
) -> Result<crate::OpenDevice<super::Api>, crate::DeviceError> {
|
||||
@ -1320,7 +1258,6 @@ impl super::Adapter {
|
||||
},
|
||||
vendor_id: self.phd_capabilities.properties.vendor_id,
|
||||
timestamp_period: self.phd_capabilities.properties.limits.timestamp_period,
|
||||
uab_types,
|
||||
downlevel_flags: self.downlevel_flags,
|
||||
private_caps: self.private_caps.clone(),
|
||||
workarounds: self.workarounds,
|
||||
@ -1397,14 +1334,10 @@ impl crate::Adapter<super::Api> for super::Adapter {
|
||||
unsafe fn open(
|
||||
&self,
|
||||
features: wgt::Features,
|
||||
limits: &wgt::Limits,
|
||||
_limits: &wgt::Limits,
|
||||
) -> Result<crate::OpenDevice<super::Api>, crate::DeviceError> {
|
||||
let phd_limits = &self.phd_capabilities.properties.limits;
|
||||
let uab_types = super::UpdateAfterBindTypes::from_limits(limits, phd_limits);
|
||||
|
||||
let enabled_extensions = self.required_device_extensions(features);
|
||||
let mut enabled_phd_features =
|
||||
self.physical_device_features(&enabled_extensions, features, uab_types);
|
||||
let mut enabled_phd_features = self.physical_device_features(&enabled_extensions, features);
|
||||
|
||||
let family_index = 0; //TODO
|
||||
let family_info = vk::DeviceQueueCreateInfo::builder()
|
||||
@ -1438,7 +1371,6 @@ impl crate::Adapter<super::Api> for super::Adapter {
|
||||
true,
|
||||
&enabled_extensions,
|
||||
features,
|
||||
uab_types,
|
||||
family_info.queue_family_index,
|
||||
0,
|
||||
)
|
||||
|
@ -1196,13 +1196,12 @@ impl crate::Device<super::Api> for super::Device {
|
||||
|
||||
let mut binding_flag_info;
|
||||
let binding_flag_vec;
|
||||
let mut requires_update_after_bind = false;
|
||||
|
||||
let partially_bound = desc
|
||||
.flags
|
||||
.contains(crate::BindGroupLayoutFlags::PARTIALLY_BOUND);
|
||||
|
||||
let vk_info = if !self.shared.uab_types.is_empty() || partially_bound {
|
||||
let vk_info = if partially_bound {
|
||||
binding_flag_vec = desc
|
||||
.entries
|
||||
.iter()
|
||||
@ -1213,29 +1212,6 @@ impl crate::Device<super::Api> for super::Device {
|
||||
flags |= vk::DescriptorBindingFlags::PARTIALLY_BOUND;
|
||||
}
|
||||
|
||||
let uab_type = match entry.ty {
|
||||
wgt::BindingType::Buffer {
|
||||
ty: wgt::BufferBindingType::Uniform,
|
||||
..
|
||||
} => super::UpdateAfterBindTypes::UNIFORM_BUFFER,
|
||||
wgt::BindingType::Buffer {
|
||||
ty: wgt::BufferBindingType::Storage { .. },
|
||||
..
|
||||
} => super::UpdateAfterBindTypes::STORAGE_BUFFER,
|
||||
wgt::BindingType::Texture { .. } => {
|
||||
super::UpdateAfterBindTypes::SAMPLED_TEXTURE
|
||||
}
|
||||
wgt::BindingType::StorageTexture { .. } => {
|
||||
super::UpdateAfterBindTypes::STORAGE_TEXTURE
|
||||
}
|
||||
_ => super::UpdateAfterBindTypes::empty(),
|
||||
};
|
||||
|
||||
if !uab_type.is_empty() && self.shared.uab_types.contains(uab_type) {
|
||||
flags |= vk::DescriptorBindingFlags::UPDATE_AFTER_BIND;
|
||||
requires_update_after_bind = true;
|
||||
}
|
||||
|
||||
flags
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@ -1248,14 +1224,6 @@ impl crate::Device<super::Api> for super::Device {
|
||||
vk_info
|
||||
};
|
||||
|
||||
let dsl_create_flags = if requires_update_after_bind {
|
||||
vk::DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND_POOL
|
||||
} else {
|
||||
vk::DescriptorSetLayoutCreateFlags::empty()
|
||||
};
|
||||
|
||||
let vk_info = vk_info.flags(dsl_create_flags);
|
||||
|
||||
let raw = unsafe {
|
||||
self.shared
|
||||
.raw
|
||||
@ -1274,7 +1242,6 @@ impl crate::Device<super::Api> for super::Device {
|
||||
desc_count,
|
||||
types: types.into_boxed_slice(),
|
||||
binding_arrays,
|
||||
requires_update_after_bind,
|
||||
})
|
||||
}
|
||||
unsafe fn destroy_bind_group_layout(&self, bg_layout: super::BindGroupLayout) {
|
||||
@ -1358,11 +1325,7 @@ impl crate::Device<super::Api> for super::Device {
|
||||
self.desc_allocator.lock().allocate(
|
||||
&*self.shared,
|
||||
&desc.layout.raw,
|
||||
if desc.layout.requires_update_after_bind {
|
||||
gpu_descriptor::DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND
|
||||
} else {
|
||||
gpu_descriptor::DescriptorSetLayoutCreateFlags::empty()
|
||||
},
|
||||
gpu_descriptor::DescriptorSetLayoutCreateFlags::empty(),
|
||||
&desc.layout.desc_count,
|
||||
1,
|
||||
)?
|
||||
|
@ -233,65 +233,6 @@ struct FramebufferKey {
|
||||
sample_count: u32,
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
pub struct UpdateAfterBindTypes: u8 {
|
||||
const UNIFORM_BUFFER = 0x1;
|
||||
const STORAGE_BUFFER = 0x2;
|
||||
const SAMPLED_TEXTURE = 0x4;
|
||||
const STORAGE_TEXTURE = 0x8;
|
||||
}
|
||||
}
|
||||
|
||||
impl UpdateAfterBindTypes {
|
||||
pub fn from_limits(limits: &wgt::Limits, phd_limits: &vk::PhysicalDeviceLimits) -> Self {
|
||||
let mut uab_types = UpdateAfterBindTypes::empty();
|
||||
uab_types.set(
|
||||
UpdateAfterBindTypes::UNIFORM_BUFFER,
|
||||
limits.max_uniform_buffers_per_shader_stage
|
||||
> phd_limits.max_per_stage_descriptor_uniform_buffers,
|
||||
);
|
||||
uab_types.set(
|
||||
UpdateAfterBindTypes::STORAGE_BUFFER,
|
||||
limits.max_storage_buffers_per_shader_stage
|
||||
> phd_limits.max_per_stage_descriptor_storage_buffers,
|
||||
);
|
||||
uab_types.set(
|
||||
UpdateAfterBindTypes::SAMPLED_TEXTURE,
|
||||
limits.max_sampled_textures_per_shader_stage
|
||||
> phd_limits.max_per_stage_descriptor_sampled_images,
|
||||
);
|
||||
uab_types.set(
|
||||
UpdateAfterBindTypes::STORAGE_TEXTURE,
|
||||
limits.max_storage_textures_per_shader_stage
|
||||
> phd_limits.max_per_stage_descriptor_storage_images,
|
||||
);
|
||||
uab_types
|
||||
}
|
||||
|
||||
fn from_features(features: &adapter::PhysicalDeviceFeatures) -> Self {
|
||||
let mut uab_types = UpdateAfterBindTypes::empty();
|
||||
if let Some(di) = features.descriptor_indexing {
|
||||
uab_types.set(
|
||||
UpdateAfterBindTypes::UNIFORM_BUFFER,
|
||||
di.descriptor_binding_uniform_buffer_update_after_bind != 0,
|
||||
);
|
||||
uab_types.set(
|
||||
UpdateAfterBindTypes::STORAGE_BUFFER,
|
||||
di.descriptor_binding_storage_buffer_update_after_bind != 0,
|
||||
);
|
||||
uab_types.set(
|
||||
UpdateAfterBindTypes::SAMPLED_TEXTURE,
|
||||
di.descriptor_binding_sampled_image_update_after_bind != 0,
|
||||
);
|
||||
uab_types.set(
|
||||
UpdateAfterBindTypes::STORAGE_TEXTURE,
|
||||
di.descriptor_binding_storage_image_update_after_bind != 0,
|
||||
);
|
||||
}
|
||||
uab_types
|
||||
}
|
||||
}
|
||||
|
||||
struct DeviceShared {
|
||||
raw: ash::Device,
|
||||
family_index: u32,
|
||||
@ -304,7 +245,6 @@ struct DeviceShared {
|
||||
extension_fns: DeviceExtensionFunctions,
|
||||
vendor_id: u32,
|
||||
timestamp_period: f32,
|
||||
uab_types: UpdateAfterBindTypes,
|
||||
downlevel_flags: wgt::DownlevelFlags,
|
||||
private_caps: PrivateCapabilities,
|
||||
workarounds: Workarounds,
|
||||
@ -389,7 +329,6 @@ pub struct BindGroupLayout {
|
||||
types: Box<[(vk::DescriptorType, u32)]>,
|
||||
/// Map of binding index to size,
|
||||
binding_arrays: Vec<(u32, NonZeroU32)>,
|
||||
requires_update_after_bind: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
Loading…
Reference in New Issue
Block a user