diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index 22bd3e5..18c18a1 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -26,11 +26,12 @@ use librashader_runtime::uniforms::UniformStorage; use rustc_hash::FxHashMap; use std::collections::VecDeque; use std::path::Path; +use std::sync::Arc; use crate::options::{FilterChainOptionsVulkan, FrameOptionsVulkan}; /// A Vulkan device and metadata that is required by the shader runtime. pub struct VulkanObjects { - pub(crate) device: ash::Device, + pub(crate) device: Arc, pub(crate) memory_properties: vk::PhysicalDeviceMemoryProperties, queue: vk::Queue, pipeline_cache: vk::PipelineCache, @@ -77,7 +78,7 @@ impl TryFrom for VulkanObjects { instance.get_physical_device_memory_properties(vulkan.physical_device); Ok(VulkanObjects { - device, + device: Arc::new(device), queue, pipeline_cache, memory_properties, @@ -87,10 +88,10 @@ impl TryFrom for VulkanObjects { } } -impl TryFrom<(vk::PhysicalDevice, ash::Instance, ash::Device)> for VulkanObjects { +impl TryFrom<(vk::PhysicalDevice, ash::Instance, Arc)> for VulkanObjects { type Error = FilterChainError; - fn try_from(value: (vk::PhysicalDevice, ash::Instance, ash::Device)) -> error::Result { + fn try_from(value: (vk::PhysicalDevice, ash::Instance, Arc)) -> error::Result { unsafe { let device = value.2; @@ -136,7 +137,7 @@ pub(crate) struct FilterCommon { pub feedback_inputs: Box<[Option]>, pub history_textures: Box<[Option]>, pub config: FilterMutable, - pub device: ash::Device, + pub device: Arc, } /// Contains residual intermediate `VkImageView` and `VkImage` objects created diff --git a/librashader-runtime-vk/src/filter_pass.rs b/librashader-runtime-vk/src/filter_pass.rs index 30b77c7..ec15597 100644 --- a/librashader-runtime-vk/src/filter_pass.rs +++ b/librashader-runtime-vk/src/filter_pass.rs @@ -1,3 +1,4 @@ +use std::sync::Arc; use crate::{error, VulkanImage}; use crate::filter_chain::FilterCommon; use crate::render_target::RenderTarget; @@ -17,7 +18,7 @@ use librashader_runtime::uniforms::{UniformStorage, UniformStorageAccess}; use rustc_hash::FxHashMap; pub struct FilterPass { - pub device: ash::Device, + pub device: Arc, pub reflection: ShaderReflection, // pub(crate) compiled: ShaderCompilerOutput>, pub(crate) uniform_storage: UniformStorage, diff --git a/librashader-runtime-vk/src/framebuffer.rs b/librashader-runtime-vk/src/framebuffer.rs index 8da3dc6..572263c 100644 --- a/librashader-runtime-vk/src/framebuffer.rs +++ b/librashader-runtime-vk/src/framebuffer.rs @@ -1,3 +1,4 @@ +use std::sync::Arc; use crate::filter_chain::VulkanObjects; use crate::texture::VulkanImage; use crate::{error, util}; @@ -8,7 +9,7 @@ use librashader_common::Size; pub(crate) struct OutputImage { pub size: Size, pub image_view: vk::ImageView, - device: ash::Device, + device: Arc, image: vk::Image, } diff --git a/librashader-runtime-vk/src/hello_triangle/command.rs b/librashader-runtime-vk/src/hello_triangle/command.rs index 2677c8f..5abd052 100644 --- a/librashader-runtime-vk/src/hello_triangle/command.rs +++ b/librashader-runtime-vk/src/hello_triangle/command.rs @@ -1,3 +1,4 @@ +use std::sync::Arc; use crate::hello_triangle::physicaldevice::find_queue_family; use crate::hello_triangle::vulkan_base::VulkanBase; use ash::prelude::VkResult; @@ -5,7 +6,7 @@ use ash::vk; pub struct VulkanCommandPool { pool: vk::CommandPool, - device: ash::Device, + device: Arc, pub buffers: Vec, } diff --git a/librashader-runtime-vk/src/hello_triangle/swapchain.rs b/librashader-runtime-vk/src/hello_triangle/swapchain.rs index d816a62..a7d6237 100644 --- a/librashader-runtime-vk/src/hello_triangle/swapchain.rs +++ b/librashader-runtime-vk/src/hello_triangle/swapchain.rs @@ -6,6 +6,7 @@ use ash::prelude::VkResult; use ash::vk; use ash::vk::{Extent3D, Handle}; use std::ffi::CStr; +use std::sync::Arc; pub struct VulkanSwapchain { pub swapchain: vk::SwapchainKHR, @@ -18,7 +19,7 @@ pub struct VulkanSwapchain { pub render_images: Vec<(vk::Image, VulkanImageMemory)>, pub render_image_views: Vec, - device: ash::Device, + device: Arc, } impl VulkanSwapchain { @@ -112,7 +113,7 @@ impl VulkanSwapchain { &base.mem_props, mem_reqs.memory_type_bits, vk::MemoryPropertyFlags::DEVICE_LOCAL, - )) + ).unwrap()) .build(); // todo: optimize by reusing existing memory. diff --git a/librashader-runtime-vk/src/hello_triangle/vulkan_base.rs b/librashader-runtime-vk/src/hello_triangle/vulkan_base.rs index 62f7b2b..6a35e21 100644 --- a/librashader-runtime-vk/src/hello_triangle/vulkan_base.rs +++ b/librashader-runtime-vk/src/hello_triangle/vulkan_base.rs @@ -9,6 +9,7 @@ use crate::hello_triangle::physicaldevice::{find_queue_family, pick_physical_dev use crate::hello_triangle::surface::VulkanSurface; use ash::prelude::VkResult; use std::ffi::{CStr, CString}; +use std::sync::Arc; const WINDOW_TITLE: &'static [u8] = b"librashader Vulkan\0"; const KHRONOS_VALIDATION: &'static [u8] = b"VK_LAYER_KHRONOS_validation\0"; @@ -16,7 +17,7 @@ const KHRONOS_VALIDATION: &'static [u8] = b"VK_LAYER_KHRONOS_validation\0"; pub struct VulkanBase { pub entry: ash::Entry, pub instance: ash::Instance, - pub device: ash::Device, + pub device: Arc, pub graphics_queue: vk::Queue, pub debug: VulkanDebug, pub physical_device: vk::PhysicalDevice, @@ -65,7 +66,7 @@ impl VulkanBase { Ok(VulkanBase { entry, instance, - device, + device: Arc::new(device), graphics_queue: queue, physical_device, mem_props, diff --git a/librashader-runtime-vk/src/samplers.rs b/librashader-runtime-vk/src/samplers.rs index 3fc862c..b2f0b52 100644 --- a/librashader-runtime-vk/src/samplers.rs +++ b/librashader-runtime-vk/src/samplers.rs @@ -1,3 +1,4 @@ +use std::sync::Arc; use crate::error; use ash::vk; use librashader_common::{FilterMode, WrapMode}; @@ -5,12 +6,12 @@ use rustc_hash::FxHashMap; pub struct VulkanSampler { pub handle: vk::Sampler, - device: ash::Device, + device: Arc, } impl VulkanSampler { pub fn new( - device: &ash::Device, + device: &Arc, wrap: WrapMode, filter: FilterMode, mipmap: FilterMode, @@ -61,7 +62,7 @@ impl SamplerSet { self.samplers.get(&(wrap, filter, mipmap)).unwrap() } - pub fn new(device: &ash::Device) -> error::Result { + pub fn new(device: &Arc) -> error::Result { let mut samplers = FxHashMap::default(); let wrap_modes = &[ WrapMode::ClampToBorder, diff --git a/librashader-runtime-vk/src/texture.rs b/librashader-runtime-vk/src/texture.rs index f723e71..8bd3de1 100644 --- a/librashader-runtime-vk/src/texture.rs +++ b/librashader-runtime-vk/src/texture.rs @@ -1,3 +1,4 @@ +use std::sync::Arc; use crate::filter_chain::VulkanObjects; use crate::util::find_vulkan_memory_type; use crate::vulkan_primitives::VulkanImageMemory; @@ -9,7 +10,7 @@ use librashader_presets::Scale2D; use librashader_runtime::scaling::{MipmapSize, ViewportSize}; pub struct OwnedImage { - pub device: ash::Device, + pub device: Arc, pub mem_props: vk::PhysicalDeviceMemoryProperties, pub image_view: vk::ImageView, pub image: VulkanImage, @@ -28,7 +29,7 @@ pub struct OwnedImageLayout { impl OwnedImage { fn new_internal( - device: ash::Device, + device: Arc, mem_props: vk::PhysicalDeviceMemoryProperties, size: Size, mut format: ImageFormat, diff --git a/librashader-runtime-vk/src/ubo_ring.rs b/librashader-runtime-vk/src/ubo_ring.rs index 4821fff..91ccbd1 100644 --- a/librashader-runtime-vk/src/ubo_ring.rs +++ b/librashader-runtime-vk/src/ubo_ring.rs @@ -1,3 +1,4 @@ +use std::sync::Arc; use crate::error; use crate::vulkan_primitives::VulkanBuffer; use ash::vk; @@ -6,12 +7,12 @@ use librashader_runtime::uniforms::UniformStorageAccess; pub struct VkUboRing { ring: BoxRingBuffer, - device: ash::Device, + device: Arc, } impl VkUboRing { pub fn new( - device: &ash::Device, + device: &Arc, mem_props: &vk::PhysicalDeviceMemoryProperties, ring_size: usize, buffer_size: usize, diff --git a/librashader-runtime-vk/src/vulkan_primitives.rs b/librashader-runtime-vk/src/vulkan_primitives.rs index bbe9f70..70458ce 100644 --- a/librashader-runtime-vk/src/vulkan_primitives.rs +++ b/librashader-runtime-vk/src/vulkan_primitives.rs @@ -1,15 +1,16 @@ use crate::{error, util}; use ash::vk; use std::ffi::c_void; +use std::sync::Arc; pub struct VulkanImageMemory { pub handle: vk::DeviceMemory, - device: ash::Device, + device: Arc, } impl VulkanImageMemory { pub fn new( - device: &ash::Device, + device: &Arc, alloc: &vk::MemoryAllocateInfo, ) -> error::Result { unsafe {