fix build

This commit is contained in:
zack 2024-12-28 19:08:21 -05:00
parent 15a4041785
commit ab8e78e1b1
No known key found for this signature in database
GPG key ID: 5F873416BCF59F35
4 changed files with 5 additions and 100 deletions

View file

@ -1,101 +1,2 @@
use std::{
sync::{Arc, Mutex, MutexGuard},
thread::Result,
};
use ash::{vk, Device};
use gpu_allocator::{
vulkan::{Allocation, AllocationCreateDesc, Allocator},
MemoryLocation,
};
#[derive(Debug)]
pub enum RtError {
VulkanError(vk::Result),
AllocationError(gpu_allocator::AllocationError),
}
pub struct AccelerationStructure {
accel: vk::AccelerationStructureKHR,
buffer: vk::Buffer,
allocation: Option<Allocation>,
}
impl AccelerationStructure {
fn destroy(&mut self, device: &Device, allocator: &mut Allocator) {
unsafe { device.destroy_buffer(self.buffer, None) };
if let Some(allocation) = self.allocation.take() {
allocator.free(allocation).unwrap();
}
}
}
pub struct Buffer {
buffer: vk::Buffer,
allocation: Option<Allocation>,
size: vk::DeviceSize,
}
impl Buffer {
pub fn new(
device: &Device,
allocator: &mut Allocator,
size: vk::DeviceSize,
usage: vk::BufferUsageFlags,
location: MemoryLocation,
) -> color_eyre::Result<Self> {
let buffer_info = vk::BufferCreateInfo::builder()
.size(size)
.usage(usage)
.sharing_mode(vk::SharingMode::EXCLUSIVE)
.build();
let buffer = unsafe { device.create_buffer(&buffer_info, None) }?;
let requirements = unsafe { device.get_buffer_memory_requirements(buffer) };
let allocation = allocator.allocate(&AllocationCreateDesc {
name: "rt_buffer",
requirements,
location,
linear: true,
allocation_scheme: gpu_allocator::vulkan::AllocationScheme::GpuAllocatorManaged,
})?;
unsafe { device.bind_buffer_memory(buffer, allocation.memory(), allocation.offset()) }?;
Ok(Self {
buffer,
allocation: Some(allocation),
size,
})
}
pub fn destroy(&mut self, device: &Device, allocator: &mut Allocator) {
unsafe { device.destroy_buffer(self.buffer, None) };
if let Some(allocation) = self.allocation.take() {
allocator.free(allocation).unwrap();
}
}
}
pub struct RaytracingBuilderKHR {
device: Arc<Device>,
queue_index: u32,
allocator: Arc<Mutex<Allocator>>,
blas: Vec<AccelerationStructure>,
tlas: AccelerationStructure,
command_pool: vk::CommandPool,
}
impl RaytracingBuilderKHR {
pub fn new() -> Self {
Self {
device: None,
queue_index: 0,
allocator: None,
blas: Vec::new(),
tlas: AccelerationStructure::de,
}
}
}

View file

@ -607,7 +607,7 @@ impl RendererInner {
let mut allocator = allocator.lock().unwrap();
let vertices = {
let model_obj = tobj::load_obj(
"/home/zoey/dev/vk-rs/crates/vk-rs/assets/suzanne.obj",
"./crates/vk-rs/assets/suzanne.obj",
&tobj::LoadOptions {
single_index: true,
triangulate: true,