Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions crates/lib/kajiya-backend/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ impl PendingResourceReleases {

pub struct DeviceFrame {
//pub(crate) linear_allocator_pool: vk_mem::AllocatorPool,
pub swapchain_acquired_semaphore: Option<vk::Semaphore>,
pub rendering_complete_semaphore: Option<vk::Semaphore>,
pub swapchain_acquired_semaphore: vk::Semaphore,
pub main_command_buffer: CommandBuffer,
pub presentation_command_buffer: CommandBuffer,
pub pending_resource_releases: Mutex<PendingResourceReleases>,
Expand Down Expand Up @@ -125,8 +124,12 @@ impl DeviceFrame {
info
})
.expect("linear allocator"),*/
swapchain_acquired_semaphore: None,
rendering_complete_semaphore: None,
swapchain_acquired_semaphore:
unsafe {
device
.create_semaphore(&vk::SemaphoreCreateInfo::default(), None)
}
.unwrap(),
main_command_buffer: CommandBuffer::new(device, queue_family).unwrap(),
presentation_command_buffer: CommandBuffer::new(device, queue_family).unwrap(),
pending_resource_releases: Default::default(),
Expand Down
33 changes: 7 additions & 26 deletions crates/lib/kajiya-backend/src/vulkan/swapchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ pub struct Swapchain {
pub(crate) raw: vk::SwapchainKHR,
pub desc: SwapchainDesc,
pub images: Vec<Arc<crate::Image>>,
pub acquire_semaphores: Vec<vk::Semaphore>,

// TODO: move out of swapchain, make a single semaphore
pub rendering_finished_semaphores: Vec<vk::Semaphore>,
pub next_semaphore: usize,
pub ready_for_present_semaphores: Vec<vk::Semaphore>,

// Keep a reference in order not to drop after the device
#[allow(dead_code)]
Expand All @@ -36,7 +32,7 @@ pub struct SwapchainImage {
pub image: Arc<crate::Image>,
pub image_index: u32,
pub acquire_semaphore: vk::Semaphore,
pub rendering_finished_semaphore: vk::Semaphore,
pub ready_for_present_semaphore: vk::Semaphore,
}

pub enum SwapchainAcquireImageErr {
Expand Down Expand Up @@ -180,17 +176,6 @@ impl Swapchain {

assert_eq!(desired_image_count, images.len() as u32);

let acquire_semaphores = (0..images.len())
.map(|_| {
unsafe {
device
.raw
.create_semaphore(&vk::SemaphoreCreateInfo::default(), None)
}
.unwrap()
})
.collect();

let rendering_finished_semaphores = (0..images.len())
.map(|_| {
unsafe {
Expand All @@ -207,9 +192,7 @@ impl Swapchain {
raw: swapchain,
desc,
images,
acquire_semaphores,
rendering_finished_semaphores,
next_semaphore: 0,
ready_for_present_semaphores: rendering_finished_semaphores,
device: device.clone(),
surface: surface.clone(),
})
Expand All @@ -221,11 +204,10 @@ impl Swapchain {

pub fn acquire_next_image(
&mut self,
acquire_semaphore: vk::Semaphore,
) -> std::result::Result<SwapchainImage, SwapchainAcquireImageErr> {
puffin::profile_function!();

let acquire_semaphore = self.acquire_semaphores[self.next_semaphore];
let rendering_finished_semaphore = self.rendering_finished_semaphores[self.next_semaphore];

let present_index = unsafe {
self.fns.acquire_next_image(
Expand All @@ -239,14 +221,13 @@ impl Swapchain {

match present_index {
Ok(present_index) => {
assert_eq!(present_index, self.next_semaphore);
let rendering_finished_semaphore = self.ready_for_present_semaphores[present_index];

self.next_semaphore = (self.next_semaphore + 1) % self.images.len();
Ok(SwapchainImage {
image: self.images[present_index].clone(),
image_index: present_index as u32,
acquire_semaphore,
rendering_finished_semaphore,
ready_for_present_semaphore: rendering_finished_semaphore,
})
}
Err(err)
Expand All @@ -265,7 +246,7 @@ impl Swapchain {
puffin::profile_function!();

let present_info = vk::PresentInfoKHR::builder()
.wait_semaphores(std::slice::from_ref(&image.rendering_finished_semaphore))
.wait_semaphores(std::slice::from_ref(&image.ready_for_present_semaphore))
.swapchains(std::slice::from_ref(&self.raw))
.image_indices(std::slice::from_ref(&image.image_index));

Expand Down
4 changes: 2 additions & 2 deletions crates/lib/kajiya-rg/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl Renderer {
// This can block, so we're doing it as late as possible.

let swapchain_image = swapchain
.acquire_next_image()
.acquire_next_image(current_frame.swapchain_acquired_semaphore)
.ok()
.expect("swapchain image");

Expand Down Expand Up @@ -266,7 +266,7 @@ impl Renderer {
let submit_info = [vk::SubmitInfo::builder()
.wait_semaphores(std::slice::from_ref(&swapchain_image.acquire_semaphore))
.signal_semaphores(std::slice::from_ref(
&swapchain_image.rendering_finished_semaphore,
&swapchain_image.ready_for_present_semaphore,
))
.wait_dst_stage_mask(&[vk::PipelineStageFlags::COMPUTE_SHADER])
.command_buffers(std::slice::from_ref(&presentation_cb.raw))
Expand Down
4 changes: 2 additions & 2 deletions crates/lib/kajiya/src/renderers/ircache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rg::BindMutToSimpleRenderPass;
use rust_shaders_shared::frame_constants::{IrcacheCascadeConstants, IRCACHE_CASCADE_COUNT};
use vk::BufferUsageFlags;

use crate::renderers::prefix_scan::inclusive_prefix_scan_u32_1m;
use crate::renderers::prefix_scan::{self, inclusive_prefix_scan_u32_1m};

use super::wrc::WrcRenderState;

Expand Down Expand Up @@ -314,7 +314,7 @@ impl IrcacheRenderer {
};

let mut entry_occupancy_buf = rg.create(BufferDesc::new_gpu_only(
size_of::<u32>() * MAX_ENTRIES,
size_of::<u32>() * prefix_scan::MIN_BUFFER_ELEMENTS,
vk::BufferUsageFlags::empty(),
));

Expand Down
5 changes: 4 additions & 1 deletion crates/lib/kajiya/src/renderers/prefix_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ use kajiya_backend::{
};
use kajiya_rg::{self as rg, SimpleRenderPass};

// see `inclusive_prefix_scan.hlsl`
const SEGMENT_SIZE: usize = 1024;
pub const MIN_BUFFER_ELEMENTS: usize = SEGMENT_SIZE * SEGMENT_SIZE;

pub fn inclusive_prefix_scan_u32_1m(rg: &mut rg::RenderGraph, input_buf: &mut rg::Handle<Buffer>) {
const SEGMENT_SIZE: usize = 1024;

SimpleRenderPass::new_compute(
rg.add_pass("_prefix scan 1"),
Expand Down
Loading