Compare commits

..

No commits in common. "3438dfde842c98716c35b4ebd6eeceee7600bcf2" and "4f95f3a928825b2caaee87216aba69c6b729ec16" have entirely different histories.

7 changed files with 10 additions and 216 deletions

View file

@ -670,10 +670,10 @@ impl SamplerCache {
pub fn get_sampler(&mut self, desc: pipeline::SamplerDesc) -> VkResult<vk::Sampler> { pub fn get_sampler(&mut self, desc: pipeline::SamplerDesc) -> VkResult<vk::Sampler> {
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
let entry = match self.samplers.entry(desc) { let entry = match self.samplers.entry(desc) {
Entry::Occupied(entry) => entry.get().raw(), Entry::Occupied(entry) => entry.get().handle(),
Entry::Vacant(entry) => { Entry::Vacant(entry) => {
let sampler = pipeline::Sampler::new(self.device.clone(), entry.key())?; let sampler = pipeline::Sampler::new(self.device.clone(), entry.key())?;
entry.insert(sampler).raw() entry.insert(sampler).handle()
} }
}; };

View file

@ -4,6 +4,7 @@ use ash::{ext, prelude::*, vk};
use parking_lot::Mutex; use parking_lot::Mutex;
use crate::{ use crate::{
define_device_owned_handle,
device::{ device::{
Device, DeviceHandle, DeviceInner, DeviceObject, asdf::traits::ExternallyManagedObject, Device, DeviceHandle, DeviceInner, DeviceObject, asdf::traits::ExternallyManagedObject,
}, },
@ -350,6 +351,8 @@ impl DescriptorSetLayout {
} }
} }
use crate::device::DeviceOwned;
impl<T: AsRef<DeviceInner>> ExternallyManagedObject<T> for vk::PipelineLayout { impl<T: AsRef<DeviceInner>> ExternallyManagedObject<T> for vk::PipelineLayout {
unsafe fn destroy(self, device: &T) { unsafe fn destroy(self, device: &T) {
unsafe { unsafe {
@ -447,20 +450,11 @@ impl std::hash::Hash for SamplerDesc {
} }
} }
impl<T> ExternallyManagedObject<T> for vk::Sampler define_device_owned_handle! {
where #[derive(Debug)]
T: AsRef<DeviceInner>, pub Sampler(vk::Sampler) {} => |this| unsafe {
{ this.device().dev().destroy_sampler(this.handle(), None);
unsafe fn destroy(self, device: &T) {
unsafe {
device.as_ref().raw.destroy_sampler(self, None);
} }
}
}
#[derive(Debug)]
pub struct Sampler {
sampler: DeviceObject<vk::Sampler>,
} }
impl Sampler { impl Sampler {
@ -485,13 +479,7 @@ impl Sampler {
let handle = unsafe { device.dev().create_sampler(info, None)? }; let handle = unsafe { device.dev().create_sampler(info, None)? };
Ok(Self { Self::construct(device, handle, None)
sampler: DeviceObject::new(device, handle),
})
}
pub fn raw(&self) -> vk::Sampler {
*self.sampler
} }
} }

View file

@ -1,152 +0,0 @@
#![allow(dead_code)]
use super::resources::*;
pub struct CopyBuffers {
pub src: Read<BufferSlice>,
pub dst: Write<BufferSlice>,
}
pub struct CopyTextures {
pub src: Read<TextureRegion>,
pub dst: Write<TextureRegion>,
}
pub struct ClearTexture {
pub dst: Write<TextureRegion>,
pub clear_value: [f32; 4],
}
pub struct CopyBufferToTexture {
pub src: Read<BufferSlice>,
pub dst: Write<TextureRegion>,
}
pub struct CopyTextureToBuffer {
pub src: Read<TextureRegion>,
pub dst: Write<BufferSlice>,
}
pub struct Copy<T: Resource, U: Resource> {
pub src: Read<T>,
pub dst: Write<U>,
}
pub struct UpdateBuffer {
pub dst: Write<BufferSlice>,
pub data: Vec<u8>,
}
pub struct UpdateTexture {
pub dst: Write<TextureRegion>,
pub data: Vec<u8>,
}
pub struct Update<T: Resource> {
pub dst: Write<T>,
pub data: Vec<u8>,
}
pub struct RenderPass {
pub color_attachments: Vec<Write<TextureRegion>>,
pub depth_attachment: Option<Write<TextureRegion>>,
pub stencil_attachment: Option<Write<TextureRegion>>,
pub area: (u32, u32),
pub layers: u32,
}
pub struct BindPipeline(pub Pipeline);
pub struct BindVertexBuffers {
pub buffers: Vec<Read<BufferSlice>>,
}
pub struct BindIndexBuffer(pub Read<BufferSlice>, pub IndexFormat);
pub struct BindDescriptorSets {
pub sets: Vec<DescriptorSet>,
}
pub struct SetViewport {
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub min_depth: f32,
pub max_depth: f32,
}
pub struct SetScissor {
pub x: u32,
pub y: u32,
pub width: u32,
pub height: u32,
}
pub struct PushConstants {
pub data: Box<[u8]>,
}
pub struct DrawData {
pub vertex_count: u32,
pub instance_count: u32,
pub first_vertex: u32,
pub first_instance: u32,
}
pub struct DrawIndexedData {
pub index_count: u32,
pub instance_count: u32,
pub first_index: u32,
pub vertex_offset: i32,
pub first_instance: u32,
}
pub struct DrawIndirectData {
pub indirect_buffer: Read<BufferSlice>,
}
pub struct DrawIndexedIndirectData {
pub indirect_buffer: Read<BufferSlice>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum IndexFormat {
Uint8,
Uint16,
Uint32,
}
pub struct Draw<T: IsDrawData> {
pub data: T,
pub vertex_buffers: Vec<Read<BufferSlice>>,
pub index_buffer: Option<(Read<BufferSlice>, IndexFormat)>,
pub count_buffer: Option<Read<BufferSlice>>,
}
pub struct Dispatch;
mod sealed {
pub trait IsDrawData {}
pub trait InsideRenderPass {}
pub trait OutsideRenderPass {}
}
use sealed::*;
impl IsDrawData for DrawData {}
impl IsDrawData for DrawIndexedData {}
impl IsDrawData for DrawIndirectData {}
impl IsDrawData for DrawIndexedIndirectData {}
impl InsideRenderPass for BindPipeline {}
impl OutsideRenderPass for BindPipeline {}
impl InsideRenderPass for BindVertexBuffers {}
impl OutsideRenderPass for BindVertexBuffers {}
impl InsideRenderPass for BindIndexBuffer {}
impl OutsideRenderPass for BindIndexBuffer {}
impl InsideRenderPass for BindDescriptorSets {}
impl OutsideRenderPass for BindDescriptorSets {}
impl OutsideRenderPass for PushConstants {}
impl InsideRenderPass for SetViewport {}
impl InsideRenderPass for SetScissor {}
impl InsideRenderPass for PushConstants {}
impl<T: IsDrawData> InsideRenderPass for Draw<T> {}
impl<T: IsDrawData> InsideRenderPass for T {}

View file

@ -1,6 +0,0 @@
mod legacy;
pub use legacy::*;
mod commands;
mod recorder;
mod resources;

View file

@ -1,2 +0,0 @@
struct CommandRecorder;
struct RenderPassRecorder;

View file

@ -1,34 +0,0 @@
use crate::images::MipRange;
pub trait Resource: Sized {}
mod impls {
use super::*;
impl Resource for Buffer {}
impl Resource for Texture {}
impl Resource for BufferSlice {}
impl Resource for TextureRegion {}
}
pub struct Pipeline;
pub struct DescriptorSet;
pub struct Buffer;
pub struct Texture;
pub struct BufferSlice {
pub buffer: Buffer,
pub offset: u64,
pub size: u64,
}
pub struct TextureRegion {
pub texture: Texture,
pub mip_levels: MipRange,
pub array_layers: MipRange,
pub origin: (u32, u32, u32),
pub extent: (u32, u32, u32),
}
pub struct Read<T>(pub T);
pub struct Write<T>(pub T);
pub struct ReadWrite<T>(pub T);