Use impl_reprc macro
This commit is contained in:
parent
60903547e7
commit
7901c3d9f0
10 changed files with 79 additions and 42 deletions
|
@ -10,5 +10,4 @@ vulkan-sys = { path = "../vulkan-sys" }
|
||||||
vma-rs = { path = "../vma-rs" }
|
vma-rs = { path = "../vma-rs" }
|
||||||
anyhow = { version = "1.0.68", features = ["backtrace"] }
|
anyhow = { version = "1.0.68", features = ["backtrace"] }
|
||||||
assetpath = { path = "../assetpath" }
|
assetpath = { path = "../assetpath" }
|
||||||
safer-ffi = { version = "0.0.10", features = ["proc_macros"] }
|
|
||||||
utilities = { git = "https://gavania.de/hodasemi/utilities.git" }
|
utilities = { git = "https://gavania.de/hodasemi/utilities.git" }
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::prelude::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use cgmath::{Matrix, Matrix4, One};
|
use cgmath::{Matrix, Matrix4, One};
|
||||||
|
use utilities::impl_reprc;
|
||||||
|
|
||||||
use core::slice;
|
use core::slice;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -10,6 +11,19 @@ use std::{
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
impl_reprc!(
|
||||||
|
pub struct Transform {
|
||||||
|
#[assume_reprc]
|
||||||
|
m: Matrix4<f32>,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl From<Matrix4<f32>> for Transform {
|
||||||
|
fn from(m: Matrix4<f32>) -> Self {
|
||||||
|
Self { m }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum AccelerationStructureBuilderData {
|
enum AccelerationStructureBuilderData {
|
||||||
TopLevel(Vec<VkAccelerationStructureInstanceKHR>),
|
TopLevel(Vec<VkAccelerationStructureInstanceKHR>),
|
||||||
BottomLevel(Vec<VkAccelerationStructureGeometryKHR>, Vec<u32>),
|
BottomLevel(Vec<VkAccelerationStructureGeometryKHR>, Vec<u32>),
|
||||||
|
@ -59,7 +73,7 @@ impl AccelerationStructureBuilder {
|
||||||
pub fn add_vertices<T: ReprC + Send + Sync + 'static>(
|
pub fn add_vertices<T: ReprC + Send + Sync + 'static>(
|
||||||
mut self,
|
mut self,
|
||||||
vertex_buffer: &Arc<Buffer<T>>,
|
vertex_buffer: &Arc<Buffer<T>>,
|
||||||
transform: Option<Arc<Buffer<Matrix4<f32>>>>,
|
transform: Option<Arc<Buffer<Transform>>>,
|
||||||
flags: impl Into<VkGeometryFlagBitsKHR>,
|
flags: impl Into<VkGeometryFlagBitsKHR>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
match &mut self.data {
|
match &mut self.data {
|
||||||
|
@ -261,8 +275,8 @@ pub struct AccelerationStructure {
|
||||||
|
|
||||||
acceleration_structure: VkAccelerationStructureKHR,
|
acceleration_structure: VkAccelerationStructureKHR,
|
||||||
|
|
||||||
result_buffer: Arc<Buffer<u8>>,
|
result_buffer: Arc<Buffer<RawBuffer>>,
|
||||||
scratch_buffer: Mutex<Arc<Buffer<u8>>>,
|
scratch_buffer: Mutex<Arc<Buffer<RawBuffer>>>,
|
||||||
|
|
||||||
update_scratch_buffer_size: VkDeviceSize,
|
update_scratch_buffer_size: VkDeviceSize,
|
||||||
|
|
||||||
|
@ -289,7 +303,7 @@ impl AccelerationStructure {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn result_buffer(&self) -> &Arc<Buffer<u8>> {
|
pub fn result_buffer(&self) -> &Arc<Buffer<RawBuffer>> {
|
||||||
&self.result_buffer
|
&self.result_buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +393,7 @@ impl AccelerationStructure {
|
||||||
device: &Arc<Device>,
|
device: &Arc<Device>,
|
||||||
size: VkDeviceSize,
|
size: VkDeviceSize,
|
||||||
alignment: VkDeviceSize,
|
alignment: VkDeviceSize,
|
||||||
) -> Result<Arc<Buffer<u8>>> {
|
) -> Result<Arc<Buffer<RawBuffer>>> {
|
||||||
Buffer::builder()
|
Buffer::builder()
|
||||||
.set_usage(
|
.set_usage(
|
||||||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
|
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
|
||||||
|
|
|
@ -143,12 +143,12 @@ impl ImageBuilder {
|
||||||
|
|
||||||
Ok(image)
|
Ok(image)
|
||||||
}
|
}
|
||||||
ImageBuilderInternalType::NewImage(ref info) => match info.source_type {
|
ImageBuilderInternalType::NewImage(info) => match info.source_type {
|
||||||
ImageSourceType::Array(ref array) => {
|
ImageSourceType::Array(ref array) => {
|
||||||
let arc_image = Self::create_from_source(
|
let arc_image = Self::create_from_source(
|
||||||
device,
|
device,
|
||||||
queue,
|
queue,
|
||||||
info,
|
&info,
|
||||||
self.sampler,
|
self.sampler,
|
||||||
image_view_ci,
|
image_view_ci,
|
||||||
self.file_name,
|
self.file_name,
|
||||||
|
@ -162,13 +162,20 @@ impl ImageBuilder {
|
||||||
let arc_image = Self::create_from_source(
|
let arc_image = Self::create_from_source(
|
||||||
device,
|
device,
|
||||||
queue,
|
queue,
|
||||||
info,
|
&info,
|
||||||
self.sampler,
|
self.sampler,
|
||||||
image_view_ci,
|
image_view_ci,
|
||||||
self.file_name,
|
self.file_name,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Self::optimize_fill(device, queue, raw, &arc_image)?;
|
Self::optimize_fill(
|
||||||
|
device,
|
||||||
|
queue,
|
||||||
|
&raw.into_iter()
|
||||||
|
.map(|&d| RawBuffer { d })
|
||||||
|
.collect::<Vec<RawBuffer>>(),
|
||||||
|
&arc_image,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(arc_image)
|
Ok(arc_image)
|
||||||
}
|
}
|
||||||
|
@ -176,7 +183,7 @@ impl ImageBuilder {
|
||||||
let arc_image = Self::create_from_source(
|
let arc_image = Self::create_from_source(
|
||||||
device,
|
device,
|
||||||
queue,
|
queue,
|
||||||
info,
|
&info,
|
||||||
self.sampler,
|
self.sampler,
|
||||||
image_view_ci,
|
image_view_ci,
|
||||||
self.file_name,
|
self.file_name,
|
||||||
|
@ -421,7 +428,7 @@ impl ImageBuilder {
|
||||||
fn create_texture(
|
fn create_texture(
|
||||||
device: &Arc<Device>,
|
device: &Arc<Device>,
|
||||||
image_ci: &VkImageCreateInfo,
|
image_ci: &VkImageCreateInfo,
|
||||||
) -> Result<(VkImage, Arc<Memory<u8>>)> {
|
) -> Result<(VkImage, Arc<Memory<RawBuffer>>)> {
|
||||||
let image = Self::create_image(device, image_ci)?;
|
let image = Self::create_image(device, image_ci)?;
|
||||||
let memory = Memory::image_memory(
|
let memory = Memory::image_memory(
|
||||||
device,
|
device,
|
||||||
|
@ -439,7 +446,7 @@ impl ImageBuilder {
|
||||||
fn optimize_fill(
|
fn optimize_fill(
|
||||||
device: &Arc<Device>,
|
device: &Arc<Device>,
|
||||||
queue: &Arc<Mutex<Queue>>,
|
queue: &Arc<Mutex<Queue>>,
|
||||||
data: &[u8],
|
data: &[RawBuffer],
|
||||||
image: &Arc<Image>,
|
image: &Arc<Image>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let staging_buffer = Buffer::builder()
|
let staging_buffer = Buffer::builder()
|
||||||
|
@ -476,7 +483,7 @@ pub struct Image {
|
||||||
image_view: VkImageView,
|
image_view: VkImageView,
|
||||||
|
|
||||||
// optional handles
|
// optional handles
|
||||||
_memory: Option<Arc<Memory<u8>>>,
|
_memory: Option<Arc<Memory<RawBuffer>>>,
|
||||||
sampler: Option<Arc<Sampler>>,
|
sampler: Option<Arc<Sampler>>,
|
||||||
|
|
||||||
// image information
|
// image information
|
||||||
|
@ -792,7 +799,7 @@ impl Image {
|
||||||
let image = image::RgbaImage::from_raw(
|
let image = image::RgbaImage::from_raw(
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
memory.iter().map(|&v| v).collect(),
|
memory.iter().map(|&v| v.d).collect(),
|
||||||
)
|
)
|
||||||
.ok_or(anyhow::anyhow!(
|
.ok_or(anyhow::anyhow!(
|
||||||
"failed to create image from raw while saving to file: {:?}",
|
"failed to create image from raw while saving to file: {:?}",
|
||||||
|
@ -804,7 +811,7 @@ impl Image {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_image_to_buffer(self: &Arc<Image>) -> Result<Arc<Buffer<u8>>> {
|
fn copy_image_to_buffer(self: &Arc<Image>) -> Result<Arc<Buffer<RawBuffer>>> {
|
||||||
let buffer = Buffer::builder()
|
let buffer = Buffer::builder()
|
||||||
.set_usage(VK_BUFFER_USAGE_TRANSFER_DST_BIT)
|
.set_usage(VK_BUFFER_USAGE_TRANSFER_DST_BIT)
|
||||||
.set_memory_usage(MemoryUsage::GpuToCpu)
|
.set_memory_usage(MemoryUsage::GpuToCpu)
|
||||||
|
|
|
@ -2,11 +2,20 @@ use crate::prelude::*;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
|
use utilities::impl_reprc;
|
||||||
use vma_rs::prelude::*;
|
use vma_rs::prelude::*;
|
||||||
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
impl_reprc!(
|
||||||
|
#[derive(Debug, Copy)]
|
||||||
|
pub struct RawBuffer {
|
||||||
|
#[assume_reprc]
|
||||||
|
d: u8,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Hash, Eq)]
|
#[derive(Debug, Clone, PartialEq, Hash, Eq)]
|
||||||
pub enum MemoryUsage {
|
pub enum MemoryUsage {
|
||||||
GpuOnly,
|
GpuOnly,
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub(crate) struct ShaderBindingTableBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ShaderBindingTable {
|
pub struct ShaderBindingTable {
|
||||||
_sbt_buffer: Arc<Buffer<u8>>,
|
_sbt_buffer: Arc<Buffer<RawBuffer>>,
|
||||||
|
|
||||||
raygen_shader_binding_table: VkStridedDeviceAddressRegionKHR,
|
raygen_shader_binding_table: VkStridedDeviceAddressRegionKHR,
|
||||||
miss_shader_binding_table: VkStridedDeviceAddressRegionKHR,
|
miss_shader_binding_table: VkStridedDeviceAddressRegionKHR,
|
||||||
|
@ -41,7 +41,7 @@ impl ShaderBindingTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create(
|
fn create(
|
||||||
sbt_buffer: Arc<Buffer<u8>>,
|
sbt_buffer: Arc<Buffer<RawBuffer>>,
|
||||||
ray_gen_entry_size: VkDeviceSize,
|
ray_gen_entry_size: VkDeviceSize,
|
||||||
ray_gen_entry_count: VkDeviceSize,
|
ray_gen_entry_count: VkDeviceSize,
|
||||||
miss_offset: VkDeviceSize,
|
miss_offset: VkDeviceSize,
|
||||||
|
@ -201,7 +201,13 @@ impl ShaderBindingTableBuilder {
|
||||||
| VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
|
| VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
|
||||||
)
|
)
|
||||||
.set_memory_usage(MemoryUsage::CpuToGpu)
|
.set_memory_usage(MemoryUsage::CpuToGpu)
|
||||||
.set_data(&sbt_data)
|
.set_data(
|
||||||
|
sbt_data
|
||||||
|
.into_iter()
|
||||||
|
.map(|u| RawBuffer { d: u })
|
||||||
|
.collect::<Vec<RawBuffer>>()
|
||||||
|
.as_slice(),
|
||||||
|
)
|
||||||
.build(device.clone())?;
|
.build(device.clone())?;
|
||||||
|
|
||||||
Ok(ShaderBindingTable::create(
|
Ok(ShaderBindingTable::create(
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub use super::fence::Fence;
|
||||||
pub use super::framebuffer::{Framebuffer, FramebufferBuilder};
|
pub use super::framebuffer::{Framebuffer, FramebufferBuilder};
|
||||||
pub use super::image::*;
|
pub use super::image::*;
|
||||||
pub use super::instance::*;
|
pub use super::instance::*;
|
||||||
pub use super::memory::{Memory, MemoryUsage};
|
pub use super::memory::{Memory, MemoryUsage, RawBuffer};
|
||||||
pub use super::physicaldevice::PhysicalDevice;
|
pub use super::physicaldevice::PhysicalDevice;
|
||||||
pub use super::pipeline::Pipeline;
|
pub use super::pipeline::Pipeline;
|
||||||
pub use super::pipelinecache::PipelineCache;
|
pub use super::pipelinecache::PipelineCache;
|
||||||
|
@ -46,10 +46,9 @@ pub use super::{OutOfDate, VkHandle, VulkanDevice};
|
||||||
pub use image;
|
pub use image;
|
||||||
pub use utilities::prelude::cgmath;
|
pub use utilities::prelude::cgmath;
|
||||||
pub use utilities::prelude::cgmath::prelude::*;
|
pub use utilities::prelude::cgmath::prelude::*;
|
||||||
|
pub use utilities::prelude::*;
|
||||||
pub use vulkan_sys::prelude::*;
|
pub use vulkan_sys::prelude::*;
|
||||||
|
|
||||||
pub use super::render_target::{sub_pass::*, *};
|
pub use super::render_target::{sub_pass::*, *};
|
||||||
|
|
||||||
pub use super::single_submit::SingleSubmit;
|
pub use super::single_submit::SingleSubmit;
|
||||||
|
|
||||||
pub use safer_ffi::prelude::*;
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl Default for ShaderType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait VertexInputDescription: ReprC {
|
pub trait VertexInputDescription: ReprC + Sized {
|
||||||
fn bindings() -> Vec<VkVertexInputBindingDescription> {
|
fn bindings() -> Vec<VkVertexInputBindingDescription> {
|
||||||
vec![VkVertexInputBindingDescription {
|
vec![VkVertexInputBindingDescription {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
|
|
|
@ -9,4 +9,4 @@ library_loader = { path = "../library_loader" }
|
||||||
paste = "1.0.11"
|
paste = "1.0.11"
|
||||||
shared_library = "0.1.9"
|
shared_library = "0.1.9"
|
||||||
anyhow = { version = "1.0.68", features = ["backtrace"] }
|
anyhow = { version = "1.0.68", features = ["backtrace"] }
|
||||||
safer-ffi = { version = "0.0.10", features = ["proc_macros"] }
|
utilities = { git = "https://gavania.de/hodasemi/utilities.git" }
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use safer_ffi::prelude::*;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use utilities::{impl_reprc, prelude::*};
|
||||||
|
|
||||||
#[derive_ReprC]
|
impl_reprc!(
|
||||||
#[repr(C)]
|
#[derive(Copy, PartialEq)]
|
||||||
#[derive(Copy, Clone, PartialEq)]
|
|
||||||
pub struct VkAccelerationStructureInstanceKHR {
|
pub struct VkAccelerationStructureInstanceKHR {
|
||||||
pub transform: VkTransformMatrixKHR,
|
transform: VkTransformMatrixKHR,
|
||||||
|
#[assume_reprc]
|
||||||
instance_id_mask: u32,
|
instance_id_mask: u32,
|
||||||
|
#[assume_reprc]
|
||||||
instance_offset_flags: u32,
|
instance_offset_flags: u32,
|
||||||
pub accelerationStructureReference: u64,
|
#[assume_reprc]
|
||||||
|
accelerationStructureReference: u64,
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
impl VkAccelerationStructureInstanceKHR {
|
impl VkAccelerationStructureInstanceKHR {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use safer_ffi::prelude::*;
|
use utilities::{impl_reprc, prelude::*};
|
||||||
|
|
||||||
|
impl_reprc!(
|
||||||
#[derive_ReprC]
|
#[derive(Debug, Copy, PartialEq)]
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
|
||||||
pub struct VkTransformMatrixKHR {
|
pub struct VkTransformMatrixKHR {
|
||||||
|
#[assume_reprc]
|
||||||
matrix: [[f32; 4]; 3],
|
matrix: [[f32; 4]; 3],
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
impl From<[[f32; 4]; 4]> for VkTransformMatrixKHR {
|
impl From<[[f32; 4]; 4]> for VkTransformMatrixKHR {
|
||||||
fn from(matrix: [[f32; 4]; 4]) -> Self {
|
fn from(matrix: [[f32; 4]; 4]) -> Self {
|
||||||
|
|
Loading…
Reference in a new issue