Correct alignment if a buffer is an acceleration structure scratch buffer (#8745)

This commit is contained in:
Vecvec authored and GitHub committed 2025-12-17 00:02:38 -05:00
1 parent 703c7d274d
commit f1b79b1c30
3 files changed
+28 -7

No files matched your search

+11 -6
View File
@@ -1892,6 +1892,14 @@ impl super::Instance {
);
}
let has_robust_buffer_access2 = phd_features
.robustness2
.as_ref()
.map(|r| r.robust_buffer_access2 == 1)
.unwrap_or_default();
let alignments = phd_capabilities.to_hal_alignments(has_robust_buffer_access2);
let private_caps = super::PrivateCapabilities {
image_view_usage: phd_capabilities.device_api_version >= vk::API_VERSION_1_1
|| phd_capabilities.supports_extension(khr::maintenance2::NAME),
@@ -1934,11 +1942,7 @@ impl super::Instance {
.image_robustness
.is_some_and(|ext| ext.robust_image_access != 0),
},
robust_buffer_access2: phd_features
.robustness2
.as_ref()
.map(|r| r.robust_buffer_access2 == 1)
.unwrap_or_default(),
robust_buffer_access2: has_robust_buffer_access2,
robust_image_access2: phd_features
.robustness2
.as_ref()
@@ -1963,10 +1967,11 @@ impl super::Instance {
.multiview
.map(|a| a.max_multiview_instance_index)
.unwrap_or(0),
scratch_buffer_alignment: alignments.ray_tracing_scratch_buffer_alignment,
};
let capabilities = crate::Capabilities {
limits: phd_capabilities.to_wgpu_limits(),
alignments: phd_capabilities.to_hal_alignments(private_caps.robust_buffer_access2),
alignments,
downlevel: wgt::DownlevelCapabilities {
flags: downlevel_flags,
limits: wgt::DownlevelLimits {},
+11 -1
View File
@@ -879,7 +879,7 @@ impl crate::Device for super::Device {
.map_err(super::map_host_device_oom_and_ioca_err)?
};
let requirements = unsafe { self.shared.raw.get_buffer_memory_requirements(raw) };
let mut requirements = unsafe { self.shared.raw.get_buffer_memory_requirements(raw) };
let is_cpu_read = desc.usage.contains(wgt::BufferUses::MAP_READ);
let is_cpu_write = desc.usage.contains(wgt::BufferUses::MAP_WRITE);
@@ -900,6 +900,16 @@ impl crate::Device for super::Device {
let name = desc.label.unwrap_or("Unlabeled buffer");
if desc
.usage
.contains(wgt::BufferUses::ACCELERATION_STRUCTURE_SCRATCH)
{
// There is no way to specify this usage to Vulkan so we must make sure the alignment requirement is large enough.
requirements.alignment = requirements
.alignment
.max(self.shared.private_caps.scratch_buffer_alignment as u64);
}
let allocation = self
.mem_allocator
.lock()
+6
View File
@@ -388,6 +388,12 @@ struct PrivateCapabilities {
/// if you are drawing more than 128 million instances. We still want to avoid
/// undefined behavior in this situation, so we panic if the limit is violated.
multiview_instance_index_limit: u32,
/// BufferUsages::ACCELERATION_STRUCTURE_SCRATCH allows usage as a scratch buffer.
/// Vulkan has no way to specify this as a usage, and it maps to other usages, but
/// these usages do not have as high of an alignment requirement using the buffer as
/// a scratch buffer when building acceleration structures.
scratch_buffer_alignment: u32,
}
bitflags::bitflags!(