rt(vk): switch from an rwlock to a mutex for allocator
This commit is contained in:
parent
10ad2d927c
commit
752417f320
|
@ -4,7 +4,7 @@ use array_concat::concat_arrays;
|
|||
use ash::vk;
|
||||
use gpu_allocator::vulkan::Allocator;
|
||||
use librashader_runtime::quad::{QuadType, VertexInput};
|
||||
use parking_lot::RwLock;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
const OFFSCREEN_VBO_DATA: [VertexInput; 4] = [
|
||||
|
@ -54,7 +54,7 @@ pub struct DrawQuad {
|
|||
impl DrawQuad {
|
||||
pub fn new(
|
||||
device: &Arc<ash::Device>,
|
||||
allocator: &Arc<RwLock<Allocator>>,
|
||||
allocator: &Arc<Mutex<Allocator>>,
|
||||
) -> error::Result<DrawQuad> {
|
||||
let mut buffer = VulkanBuffer::new(
|
||||
device,
|
||||
|
|
|
@ -26,7 +26,7 @@ use librashader_runtime::binding::BindingUtil;
|
|||
use librashader_runtime::image::{Image, ImageError, UVDirection, BGRA8};
|
||||
use librashader_runtime::quad::QuadType;
|
||||
use librashader_runtime::uniforms::UniformStorage;
|
||||
use parking_lot::RwLock;
|
||||
use parking_lot::Mutex;
|
||||
use std::collections::VecDeque;
|
||||
use std::convert::Infallible;
|
||||
use std::path::Path;
|
||||
|
@ -43,7 +43,7 @@ use rayon::prelude::*;
|
|||
/// A Vulkan device and metadata that is required by the shader runtime.
|
||||
pub struct VulkanObjects {
|
||||
pub(crate) device: Arc<ash::Device>,
|
||||
pub(crate) alloc: Arc<RwLock<Allocator>>,
|
||||
pub(crate) alloc: Arc<Mutex<Allocator>>,
|
||||
queue: vk::Queue,
|
||||
// pub(crate) memory_properties: vk::PhysicalDeviceMemoryProperties,
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use ash::vk;
|
|||
use gpu_allocator::vulkan::{Allocation, AllocationCreateDesc, AllocationScheme, Allocator};
|
||||
use gpu_allocator::MemoryLocation;
|
||||
use librashader_runtime::uniforms::UniformStorageAccess;
|
||||
use parking_lot::RwLock;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use std::ffi::c_void;
|
||||
use std::mem::ManuallyDrop;
|
||||
|
@ -14,17 +14,17 @@ use std::sync::Arc;
|
|||
|
||||
pub struct VulkanImageMemory {
|
||||
allocation: Option<Allocation>,
|
||||
allocator: Arc<RwLock<Allocator>>,
|
||||
allocator: Arc<Mutex<Allocator>>,
|
||||
}
|
||||
|
||||
impl VulkanImageMemory {
|
||||
pub fn new(
|
||||
device: &Arc<ash::Device>,
|
||||
allocator: &Arc<RwLock<Allocator>>,
|
||||
allocator: &Arc<Mutex<Allocator>>,
|
||||
requirements: vk::MemoryRequirements,
|
||||
image: &vk::Image,
|
||||
) -> error::Result<VulkanImageMemory> {
|
||||
let allocation = allocator.write().allocate(&AllocationCreateDesc {
|
||||
let allocation = allocator.lock().allocate(&AllocationCreateDesc {
|
||||
name: "imagemem",
|
||||
requirements,
|
||||
location: MemoryLocation::GpuOnly,
|
||||
|
@ -46,7 +46,7 @@ impl Drop for VulkanImageMemory {
|
|||
fn drop(&mut self) {
|
||||
let allocation = self.allocation.take();
|
||||
if let Some(allocation) = allocation {
|
||||
if let Err(e) = self.allocator.write().free(allocation) {
|
||||
if let Err(e) = self.allocator.lock().free(allocation) {
|
||||
println!("librashader-runtime-vk: [warn] failed to deallocate image buffer {e}")
|
||||
}
|
||||
}
|
||||
|
@ -57,14 +57,14 @@ pub struct VulkanBuffer {
|
|||
pub handle: vk::Buffer,
|
||||
device: Arc<ash::Device>,
|
||||
memory: Option<Allocation>,
|
||||
allocator: Arc<RwLock<Allocator>>,
|
||||
allocator: Arc<Mutex<Allocator>>,
|
||||
size: vk::DeviceSize,
|
||||
}
|
||||
|
||||
impl VulkanBuffer {
|
||||
pub fn new(
|
||||
device: &Arc<ash::Device>,
|
||||
allocator: &Arc<RwLock<Allocator>>,
|
||||
allocator: &Arc<Mutex<Allocator>>,
|
||||
usage: vk::BufferUsageFlags,
|
||||
size: usize,
|
||||
) -> error::Result<VulkanBuffer> {
|
||||
|
@ -77,7 +77,7 @@ impl VulkanBuffer {
|
|||
|
||||
let memory_reqs = device.get_buffer_memory_requirements(buffer);
|
||||
|
||||
let alloc = allocator.write().allocate(&AllocationCreateDesc {
|
||||
let alloc = allocator.lock().allocate(&AllocationCreateDesc {
|
||||
name: "buffer",
|
||||
requirements: memory_reqs,
|
||||
location: MemoryLocation::CpuToGpu,
|
||||
|
@ -113,7 +113,7 @@ impl Drop for VulkanBuffer {
|
|||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
if let Some(allocation) = self.memory.take() {
|
||||
if let Err(e) = self.allocator.write().free(allocation) {
|
||||
if let Err(e) = self.allocator.lock().free(allocation) {
|
||||
println!(
|
||||
"librashader-runtime-vk: [warn] failed to deallocate buffer memory {e}"
|
||||
)
|
||||
|
@ -141,7 +141,7 @@ pub struct RawVulkanBuffer {
|
|||
impl RawVulkanBuffer {
|
||||
pub fn new(
|
||||
device: &Arc<ash::Device>,
|
||||
allocator: &Arc<RwLock<Allocator>>,
|
||||
allocator: &Arc<Mutex<Allocator>>,
|
||||
usage: vk::BufferUsageFlags,
|
||||
size: usize,
|
||||
) -> error::Result<Self> {
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::memory::VulkanImageMemory;
|
|||
use crate::{error, util};
|
||||
use ash::vk;
|
||||
use gpu_allocator::vulkan::Allocator;
|
||||
use parking_lot::RwLock;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::error::FilterChainError;
|
||||
|
@ -13,7 +13,7 @@ use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer, ViewportSize};
|
|||
|
||||
pub struct OwnedImage {
|
||||
pub device: Arc<ash::Device>,
|
||||
pub allocator: Arc<RwLock<Allocator>>,
|
||||
pub allocator: Arc<Mutex<Allocator>>,
|
||||
pub image_view: vk::ImageView,
|
||||
pub image: VulkanImage,
|
||||
pub memory: VulkanImageMemory,
|
||||
|
@ -33,7 +33,7 @@ pub struct OwnedImageLayout {
|
|||
impl OwnedImage {
|
||||
fn new_internal(
|
||||
device: Arc<ash::Device>,
|
||||
alloc: &Arc<RwLock<Allocator>>,
|
||||
alloc: &Arc<Mutex<Allocator>>,
|
||||
size: Size<u32>,
|
||||
mut format: ImageFormat,
|
||||
max_miplevels: u32,
|
||||
|
|
|
@ -2,7 +2,7 @@ use ash::vk;
|
|||
use gpu_allocator::vulkan::{Allocator, AllocatorCreateDesc};
|
||||
|
||||
use gpu_allocator::AllocationSizes;
|
||||
use parking_lot::RwLock;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::error;
|
||||
|
@ -95,7 +95,7 @@ pub fn create_allocator(
|
|||
device: ash::Device,
|
||||
instance: ash::Instance,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
) -> error::Result<Arc<RwLock<Allocator>>> {
|
||||
) -> error::Result<Arc<Mutex<Allocator>>> {
|
||||
let alloc = Allocator::new(&AllocatorCreateDesc {
|
||||
instance,
|
||||
device,
|
||||
|
@ -104,5 +104,5 @@ pub fn create_allocator(
|
|||
buffer_device_address: false,
|
||||
allocation_sizes: AllocationSizes::default(),
|
||||
})?;
|
||||
Ok(Arc::new(RwLock::new(alloc)))
|
||||
Ok(Arc::new(Mutex::new(alloc)))
|
||||
}
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
use ash::vk;
|
||||
use gpu_allocator::vulkan::{Allocation, AllocationCreateDesc, AllocationScheme, Allocator};
|
||||
use gpu_allocator::MemoryLocation;
|
||||
use parking_lot::RwLock;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use ash::prelude::VkResult;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct VulkanImageMemory {
|
||||
allocation: Option<Allocation>,
|
||||
allocator: Arc<RwLock<Allocator>>,
|
||||
allocator: Arc<Mutex<Allocator>>,
|
||||
}
|
||||
|
||||
impl VulkanImageMemory {
|
||||
pub fn new(
|
||||
device: &Arc<ash::Device>,
|
||||
allocator: &Arc<RwLock<Allocator>>,
|
||||
allocator: &Arc<Mutex<Allocator>>,
|
||||
requirements: vk::MemoryRequirements,
|
||||
image: &vk::Image,
|
||||
) -> VkResult<VulkanImageMemory> {
|
||||
let allocation = allocator
|
||||
.write()
|
||||
.lock()
|
||||
.allocate(&AllocationCreateDesc {
|
||||
name: "imagemem",
|
||||
requirements,
|
||||
|
@ -43,7 +43,7 @@ impl Drop for VulkanImageMemory {
|
|||
fn drop(&mut self) {
|
||||
let allocation = self.allocation.take();
|
||||
if let Some(allocation) = allocation {
|
||||
if let Err(e) = self.allocator.write().free(allocation) {
|
||||
if let Err(e) = self.allocator.lock().free(allocation) {
|
||||
println!("librashader-runtime-vk: [warn] failed to deallocate image buffer {e}")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ use vulkan_base::VulkanBase;
|
|||
use librashader_common::Viewport;
|
||||
|
||||
use librashader_runtime_vk::options::FrameOptionsVulkan;
|
||||
use winit::event::{ElementState, Event, WindowEvent};
|
||||
use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder};
|
||||
use winit::event::{Event, WindowEvent};
|
||||
use winit::event_loop::{EventLoop, EventLoopBuilder};
|
||||
use winit::platform::windows::EventLoopBuilderExtWindows;
|
||||
|
||||
// Constants
|
||||
|
|
|
@ -2,7 +2,7 @@ use ash::vk;
|
|||
use gpu_allocator::vulkan::{Allocator, AllocatorCreateDesc};
|
||||
|
||||
use gpu_allocator::AllocationSizes;
|
||||
use parking_lot::RwLock;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -50,7 +50,7 @@ pub fn create_allocator(
|
|||
device: ash::Device,
|
||||
instance: ash::Instance,
|
||||
physical_device: vk::PhysicalDevice,
|
||||
) -> Arc<RwLock<Allocator>> {
|
||||
) -> Arc<Mutex<Allocator>> {
|
||||
let alloc = Allocator::new(&AllocatorCreateDesc {
|
||||
instance,
|
||||
device,
|
||||
|
@ -60,5 +60,5 @@ pub fn create_allocator(
|
|||
allocation_sizes: AllocationSizes::default(),
|
||||
})
|
||||
.unwrap();
|
||||
Arc::new(RwLock::new(alloc))
|
||||
Arc::new(Mutex::new(alloc))
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use ash::prelude::VkResult;
|
|||
use gpu_allocator::vulkan::Allocator;
|
||||
use librashader_runtime_vk::error::FilterChainError;
|
||||
use librashader_runtime_vk::VulkanObjects;
|
||||
use parking_lot::RwLock;
|
||||
use parking_lot::Mutex;
|
||||
use std::ffi::CStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -22,7 +22,7 @@ pub struct VulkanBase {
|
|||
// pub debug: VulkanDebug,
|
||||
pub physical_device: vk::PhysicalDevice,
|
||||
pub mem_props: vk::PhysicalDeviceMemoryProperties,
|
||||
pub allocator: Arc<RwLock<Allocator>>,
|
||||
pub allocator: Arc<Mutex<Allocator>>,
|
||||
}
|
||||
|
||||
impl VulkanBase {
|
||||
|
|
Loading…
Reference in a new issue