idk man...
This commit is contained in:
parent
7b7badd4d4
commit
d29b121aca
|
@ -16,6 +16,10 @@ struct WindowState {
|
||||||
egui_platform: egui_winit_platform::Platform,
|
egui_platform: egui_winit_platform::Platform,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct EguiRenderState {
|
||||||
|
textures: BTreeMap<u64, ()>,
|
||||||
|
}
|
||||||
|
|
||||||
struct WinitState {
|
struct WinitState {
|
||||||
last_resize_events: BTreeMap<WindowId, PhysicalSize<u32>>,
|
last_resize_events: BTreeMap<WindowId, PhysicalSize<u32>>,
|
||||||
window_attrs: WindowAttributes,
|
window_attrs: WindowAttributes,
|
||||||
|
@ -77,7 +81,11 @@ impl WinitState {
|
||||||
|
|
||||||
// rendering
|
// rendering
|
||||||
self.renderer
|
self.renderer
|
||||||
.debug_draw(&window_id, || window.window.pre_present_notify())
|
.debug_draw(
|
||||||
|
&window_id,
|
||||||
|
|| { // window.window.pre_present_notify()
|
||||||
|
},
|
||||||
|
)
|
||||||
.expect("drawing");
|
.expect("drawing");
|
||||||
window.window.request_redraw();
|
window.window.request_redraw();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,31 @@
|
||||||
use super::{Device, Queue, VkAllocator};
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use super::{Device, Queue};
|
||||||
use ash::{prelude::*, vk};
|
use ash::{prelude::*, vk};
|
||||||
use vk_mem::Alloc;
|
use vk_mem::Alloc;
|
||||||
|
|
||||||
pub struct Image2D {
|
pub struct Image2D {
|
||||||
alloc: VkAllocator,
|
device: Device,
|
||||||
image: vk::Image,
|
|
||||||
size: vk::Extent2D,
|
size: vk::Extent2D,
|
||||||
mip_levels: u32,
|
mip_levels: u32,
|
||||||
format: vk::Format,
|
format: vk::Format,
|
||||||
|
image: vk::Image,
|
||||||
allocation: vk_mem::Allocation,
|
allocation: vk_mem::Allocation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for Image2D {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
self.device
|
||||||
|
.alloc()
|
||||||
|
.destroy_image(self.image, &mut self.allocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Image2D {
|
impl Image2D {
|
||||||
pub fn new_exclusive(
|
pub fn new_exclusive(
|
||||||
alloc: VkAllocator,
|
device: &Device,
|
||||||
extent: vk::Extent2D,
|
extent: vk::Extent2D,
|
||||||
mip_levels: u32,
|
mip_levels: u32,
|
||||||
array_layers: u32,
|
array_layers: u32,
|
||||||
|
@ -22,7 +34,7 @@ impl Image2D {
|
||||||
usage: vk::ImageUsageFlags,
|
usage: vk::ImageUsageFlags,
|
||||||
memory_usage: vk_mem::MemoryUsage,
|
memory_usage: vk_mem::MemoryUsage,
|
||||||
alloc_flags: vk_mem::AllocationCreateFlags,
|
alloc_flags: vk_mem::AllocationCreateFlags,
|
||||||
) -> VkResult<Image2D> {
|
) -> VkResult<Arc<Self>> {
|
||||||
let create_info = vk::ImageCreateInfo::default()
|
let create_info = vk::ImageCreateInfo::default()
|
||||||
.array_layers(array_layers)
|
.array_layers(array_layers)
|
||||||
.mip_levels(mip_levels)
|
.mip_levels(mip_levels)
|
||||||
|
@ -46,25 +58,25 @@ impl Image2D {
|
||||||
};
|
};
|
||||||
|
|
||||||
let (image, allocation) =
|
let (image, allocation) =
|
||||||
unsafe { alloc.create_image(&create_info, &alloc_info)? };
|
unsafe { device.alloc().create_image(&create_info, &alloc_info)? };
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Arc::new(Self {
|
||||||
alloc,
|
|
||||||
image,
|
|
||||||
size: extent,
|
size: extent,
|
||||||
mip_levels,
|
mip_levels,
|
||||||
format,
|
format,
|
||||||
|
device: device.clone(),
|
||||||
|
image,
|
||||||
allocation,
|
allocation,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(
|
pub fn view(
|
||||||
&self,
|
self: &Arc<Self>,
|
||||||
device: &Device,
|
device: &Device,
|
||||||
aspect: vk::ImageAspectFlags,
|
aspect: vk::ImageAspectFlags,
|
||||||
) -> VkResult<vk::ImageView> {
|
) -> VkResult<Arc<ImageView2D>> {
|
||||||
let create_info = vk::ImageViewCreateInfo::default()
|
let create_info = vk::ImageViewCreateInfo::default()
|
||||||
.image(self.image)
|
.image(self.image())
|
||||||
.view_type(vk::ImageViewType::TYPE_2D)
|
.view_type(vk::ImageViewType::TYPE_2D)
|
||||||
.format(self.format)
|
.format(self.format)
|
||||||
.components(vk::ComponentMapping::default())
|
.components(vk::ComponentMapping::default())
|
||||||
|
@ -80,7 +92,11 @@ impl Image2D {
|
||||||
let view =
|
let view =
|
||||||
unsafe { device.dev().create_image_view(&create_info, None)? };
|
unsafe { device.dev().create_image_view(&create_info, None)? };
|
||||||
|
|
||||||
Ok(view)
|
Ok(Arc::new(ImageView2D {
|
||||||
|
view,
|
||||||
|
image: self.clone(),
|
||||||
|
aspect,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn image(&self) -> vk::Image {
|
pub fn image(&self) -> vk::Image {
|
||||||
|
@ -88,14 +104,22 @@ impl Image2D {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Image2D {
|
pub struct ImageView2D {
|
||||||
|
view: vk::ImageView,
|
||||||
|
aspect: vk::ImageAspectFlags,
|
||||||
|
image: Arc<Image2D>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for ImageView2D {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.alloc.destroy_image(self.image, &mut self.allocation);
|
self.image.device.dev().destroy_image_view(self.view, None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ImageView2D {}
|
||||||
|
|
||||||
pub struct QueueOwnership {
|
pub struct QueueOwnership {
|
||||||
src: u32,
|
src: u32,
|
||||||
dst: u32,
|
dst: u32,
|
||||||
|
|
|
@ -36,9 +36,8 @@ use tracing::info;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod images;
|
mod images;
|
||||||
mod render_graph;
|
mod render_graph;
|
||||||
mod sync;
|
|
||||||
|
|
||||||
type VkAllocator = Arc<vk_mem::Allocator>;
|
mod sync;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
@ -470,6 +469,7 @@ impl DeviceQueueFamilies {
|
||||||
struct DeviceInner {
|
struct DeviceInner {
|
||||||
instance: Arc<Instance>,
|
instance: Arc<Instance>,
|
||||||
physical: PhysicalDevice,
|
physical: PhysicalDevice,
|
||||||
|
alloc: vk_mem::Allocator,
|
||||||
device: ash::Device,
|
device: ash::Device,
|
||||||
swapchain: khr::swapchain::Device,
|
swapchain: khr::swapchain::Device,
|
||||||
debug_utils: ash::ext::debug_utils::Device,
|
debug_utils: ash::ext::debug_utils::Device,
|
||||||
|
@ -505,6 +505,9 @@ impl Device {
|
||||||
fn weak(&self) -> WeakDevice {
|
fn weak(&self) -> WeakDevice {
|
||||||
Arc::downgrade(&self.0)
|
Arc::downgrade(&self.0)
|
||||||
}
|
}
|
||||||
|
fn alloc(&self) -> &vk_mem::Allocator {
|
||||||
|
&self.0.alloc
|
||||||
|
}
|
||||||
fn dev(&self) -> &ash::Device {
|
fn dev(&self) -> &ash::Device {
|
||||||
&self.0.device
|
&self.0.device
|
||||||
}
|
}
|
||||||
|
@ -1194,7 +1197,6 @@ impl Drop for Surface {
|
||||||
pub struct Vulkan {
|
pub struct Vulkan {
|
||||||
instance: Arc<Instance>,
|
instance: Arc<Instance>,
|
||||||
device: Device,
|
device: Device,
|
||||||
alloc: VkAllocator,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Vulkan {
|
impl Drop for Vulkan {
|
||||||
|
@ -1393,19 +1395,7 @@ impl Vulkan {
|
||||||
let device =
|
let device =
|
||||||
Self::create_device(instance.clone(), pdev, &mut features)?;
|
Self::create_device(instance.clone(), pdev, &mut features)?;
|
||||||
|
|
||||||
let alloc_info = vk_mem::AllocatorCreateInfo::new(
|
Ok(Self { instance, device })
|
||||||
&instance.instance,
|
|
||||||
device.dev(),
|
|
||||||
device.phy(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let alloc = Arc::new(unsafe { vk_mem::Allocator::new(alloc_info)? });
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
instance,
|
|
||||||
device,
|
|
||||||
alloc,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn queue_family_supports_presentation(
|
fn queue_family_supports_presentation(
|
||||||
|
@ -1693,6 +1683,14 @@ impl Vulkan {
|
||||||
.map(get_queue)
|
.map(get_queue)
|
||||||
.unwrap_or(compute_queue.clone());
|
.unwrap_or(compute_queue.clone());
|
||||||
|
|
||||||
|
let alloc_info = vk_mem::AllocatorCreateInfo::new(
|
||||||
|
&instance.instance,
|
||||||
|
&device,
|
||||||
|
pdev.pdev,
|
||||||
|
);
|
||||||
|
|
||||||
|
let alloc = unsafe { vk_mem::Allocator::new(alloc_info)? };
|
||||||
|
|
||||||
Device::new(DeviceInner {
|
Device::new(DeviceInner {
|
||||||
device: device.clone(),
|
device: device.clone(),
|
||||||
physical: pdev,
|
physical: pdev,
|
||||||
|
@ -1705,6 +1703,7 @@ impl Vulkan {
|
||||||
&device,
|
&device,
|
||||||
),
|
),
|
||||||
instance,
|
instance,
|
||||||
|
alloc,
|
||||||
allocated_queues,
|
allocated_queues,
|
||||||
main_queue,
|
main_queue,
|
||||||
present_queue,
|
present_queue,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use ash::vk;
|
use ash::vk;
|
||||||
|
|
||||||
struct Rgba([f32;4]);
|
struct Rgba([f32; 4]);
|
||||||
|
|
||||||
enum LoadOp {
|
enum LoadOp {
|
||||||
Clear(Rgba),
|
Clear(Rgba),
|
||||||
|
@ -9,7 +9,8 @@ enum LoadOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum StoreOp {
|
enum StoreOp {
|
||||||
DontCare,Store,
|
DontCare,
|
||||||
|
Store,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AttachmentInfo {
|
struct AttachmentInfo {
|
||||||
|
@ -23,5 +24,4 @@ struct Texture {
|
||||||
texture: vk::Image,
|
texture: vk::Image,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RenderGraph {
|
pub struct RenderGraph {}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue