Merge pull request #392 from mahkoh/jorth/descriptor-buffer-alignment
vulkan: align descriptor buffers to 4KB
This commit is contained in:
commit
7d1acf2ad5
3 changed files with 32 additions and 19 deletions
|
|
@ -73,7 +73,7 @@ impl VulkanBufferCache {
|
|||
align: DeviceSize,
|
||||
) -> Result<VulkanBuffer, VulkanError> {
|
||||
const MIN_ALLOCATION: DeviceSize = 1024;
|
||||
let capacity = capacity.max(MIN_ALLOCATION);
|
||||
let capacity = (capacity.max(MIN_ALLOCATION) + align - 1) & !(align - 1);
|
||||
let mut smallest = None;
|
||||
let mut smallest_size = DeviceSize::MAX;
|
||||
let mut fitting = None;
|
||||
|
|
|
|||
|
|
@ -28,15 +28,16 @@ use {
|
|||
push_descriptor,
|
||||
},
|
||||
vk::{
|
||||
DeviceCreateInfo, DeviceQueueCreateInfo, DeviceSize, ExternalSemaphoreFeatureFlags,
|
||||
ExternalSemaphoreHandleTypeFlags, ExternalSemaphoreProperties, MAX_MEMORY_TYPES,
|
||||
MemoryPropertyFlags, MemoryType, PhysicalDevice,
|
||||
PhysicalDeviceBufferDeviceAddressFeatures, PhysicalDeviceDescriptorBufferFeaturesEXT,
|
||||
PhysicalDeviceDescriptorBufferPropertiesEXT, PhysicalDeviceDriverProperties,
|
||||
PhysicalDeviceDriverPropertiesKHR, PhysicalDeviceDrmPropertiesEXT,
|
||||
PhysicalDeviceDynamicRenderingFeatures, PhysicalDeviceExternalSemaphoreInfo,
|
||||
PhysicalDeviceProperties, PhysicalDeviceProperties2,
|
||||
PhysicalDeviceSynchronization2Features, PhysicalDeviceTimelineSemaphoreFeatures, Queue,
|
||||
DeviceCreateInfo, DeviceQueueCreateInfo, DeviceSize, DriverId,
|
||||
ExternalSemaphoreFeatureFlags, ExternalSemaphoreHandleTypeFlags,
|
||||
ExternalSemaphoreProperties, MAX_MEMORY_TYPES, MemoryPropertyFlags, MemoryType,
|
||||
PhysicalDevice, PhysicalDeviceBufferDeviceAddressFeatures,
|
||||
PhysicalDeviceDescriptorBufferFeaturesEXT, PhysicalDeviceDescriptorBufferPropertiesEXT,
|
||||
PhysicalDeviceDriverProperties, PhysicalDeviceDriverPropertiesKHR,
|
||||
PhysicalDeviceDrmPropertiesEXT, PhysicalDeviceDynamicRenderingFeatures,
|
||||
PhysicalDeviceExternalSemaphoreInfo, PhysicalDeviceProperties,
|
||||
PhysicalDeviceProperties2, PhysicalDeviceSynchronization2Features,
|
||||
PhysicalDeviceTimelineSemaphoreFeatures, PhysicalDeviceVulkan12Properties, Queue,
|
||||
QueueFlags,
|
||||
},
|
||||
},
|
||||
|
|
@ -73,6 +74,7 @@ pub struct VulkanDevice {
|
|||
pub(super) descriptor_buffer_offset_mask: DeviceSize,
|
||||
pub(super) sampler_descriptor_size: usize,
|
||||
pub(super) sampled_image_descriptor_size: usize,
|
||||
pub(super) is_anv: bool,
|
||||
}
|
||||
|
||||
impl Drop for VulkanDevice {
|
||||
|
|
@ -365,18 +367,22 @@ impl VulkanInstance {
|
|||
image_drm_format_modifier::Device::new(&self.instance, &device);
|
||||
let descriptor_buffer = supports_descriptor_buffer
|
||||
.then(|| descriptor_buffer::Device::new(&self.instance, &device));
|
||||
let mut descriptor_buffer_props = PhysicalDeviceDescriptorBufferPropertiesEXT::default();
|
||||
let mut physical_device_vulkan12_properties = PhysicalDeviceVulkan12Properties::default();
|
||||
let mut physical_device_properties2 = PhysicalDeviceProperties2::default()
|
||||
.push_next(&mut physical_device_vulkan12_properties);
|
||||
if supports_descriptor_buffer {
|
||||
physical_device_properties2 =
|
||||
physical_device_properties2.push_next(&mut descriptor_buffer_props);
|
||||
}
|
||||
unsafe {
|
||||
self.instance
|
||||
.get_physical_device_properties2(phy_dev, &mut physical_device_properties2);
|
||||
}
|
||||
let mut descriptor_buffer_offset_mask = 0;
|
||||
let mut sampler_descriptor_size = 0;
|
||||
let mut sampled_image_descriptor_size = 0;
|
||||
if supports_descriptor_buffer {
|
||||
let mut descriptor_buffer_props =
|
||||
PhysicalDeviceDescriptorBufferPropertiesEXT::default();
|
||||
let mut props =
|
||||
PhysicalDeviceProperties2::default().push_next(&mut descriptor_buffer_props);
|
||||
unsafe {
|
||||
self.instance
|
||||
.get_physical_device_properties2(phy_dev, &mut props);
|
||||
}
|
||||
descriptor_buffer_offset_mask = descriptor_buffer_props
|
||||
.descriptor_buffer_offset_alignment
|
||||
.checked_next_power_of_two()
|
||||
|
|
@ -424,6 +430,8 @@ impl VulkanInstance {
|
|||
sampler_descriptor_size,
|
||||
sampled_image_descriptor_size,
|
||||
blend_limits,
|
||||
is_anv: physical_device_vulkan12_properties.driver_id
|
||||
== DriverId::INTEL_OPEN_SOURCE_MESA,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -489,7 +489,12 @@ impl VulkanRenderer {
|
|||
(&sampler_writer, &self.sampler_descriptor_buffer_cache),
|
||||
(&resource_writer, &self.resource_descriptor_buffer_cache),
|
||||
] {
|
||||
let buffer = cache.allocate(writer.len() as DeviceSize, 1)?;
|
||||
let mut min_alignment = 1;
|
||||
if self.device.is_anv {
|
||||
// https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33903
|
||||
min_alignment = 4096;
|
||||
}
|
||||
let buffer = cache.allocate(writer.len() as DeviceSize, min_alignment)?;
|
||||
buffer.buffer.allocation.upload(|ptr, _| unsafe {
|
||||
ptr::copy_nonoverlapping(writer.as_ptr(), ptr, writer.len())
|
||||
})?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue