vk: use ubo ring

This commit is contained in:
chyyran 2022-12-25 01:28:49 -05:00
parent 9dbe031ce8
commit 88db9220c4
4 changed files with 34 additions and 6 deletions

View file

@ -21,6 +21,7 @@ use std::error::Error;
use std::path::Path;
use crate::samplers::SamplerSet;
use crate::texture::VulkanImage;
use crate::ubo_ring::VkUboRing;
pub struct Vulkan {
// physical_device: vk::PhysicalDevice,
@ -253,12 +254,12 @@ impl FilterChainVulkan {
let reflection = reflect.reflect(index, semantics)?;
let spirv_words = reflect.compile(None)?;
let uniform_storage = UniformStorage::new(
reflection
let ubo_size = reflection
.ubo
.as_ref()
.map(|ubo| ubo.size as usize)
.unwrap_or(0),
.unwrap_or(0);
let uniform_storage = UniformStorage::new(ubo_size,
reflection
.push_constant
.as_ref()
@ -294,6 +295,7 @@ impl FilterChainVulkan {
images,
)?;
let ubo_ring = VkUboRing::new(&vulkan.device, &vulkan.memory_properties, images as usize, ubo_size)?;
// shader_vulkan: 2026
filters.push(FilterPass {
device: vulkan.device.clone(),
@ -304,6 +306,7 @@ impl FilterChainVulkan {
source,
config,
graphics_pipeline,
ubo_ring,
});
}

View file

@ -12,6 +12,7 @@ use crate::filter_chain::FilterCommon;
use crate::rendertarget::RenderTarget;
use crate::texture::Texture;
use crate::samplers::{SamplerSet, VulkanSampler};
use crate::ubo_ring::VkUboRing;
pub struct FilterPass {
pub device: ash::Device,
@ -22,6 +23,7 @@ pub struct FilterPass {
pub source: ShaderSource,
pub config: ShaderPassConfig,
pub graphics_pipeline: VulkanGraphicsPipeline,
pub ubo_ring: VkUboRing
}
@ -70,6 +72,7 @@ impl FilterPass {
if let Some(ubo) = &self.reflection.ubo {
// shader_vulkan: 2554 (ra uses uses one big buffer)
// itll be simpler for us if we just use a RingBuffer<vk::Buffer> tbh.
}
}

View file

@ -16,6 +16,7 @@ mod vulkan_state;
mod samplers;
mod texture;
mod rendertarget;
mod ubo_ring;
#[cfg(test)]
mod tests {

View file

@ -0,0 +1,21 @@
use ash::vk;
use librashader_runtime::ringbuffer::{BoxRingBuffer, InlineRingBuffer};
use crate::error;
use crate::vulkan_primitives::VulkanBuffer;
pub struct VkUboRing {
ring: BoxRingBuffer<VulkanBuffer>,
}
impl VkUboRing {
pub fn new(device: &ash::Device, mem_props: &vk::PhysicalDeviceMemoryProperties, ring_size: usize, buffer_size: usize) -> error::Result<Self> {
let mut ring = Vec::new();
for _ in 0..ring_size {
ring.push(VulkanBuffer::new(device, mem_props, vk::BufferUsageFlags::UNIFORM_BUFFER, buffer_size)?);
}
Ok(VkUboRing {
ring: BoxRingBuffer::from_vec(ring)
})
}
}