Skip to content

Commit

Permalink
Fix: fixed bug in synchronization of TLAS and Scene Objects
Browse files Browse the repository at this point in the history
  • Loading branch information
AEspinosaDev committed Nov 20, 2024
1 parent 7390430 commit b2837ed
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ The main feautures of the library are:
- Forward and Deferred pipelines support.
- PBR, Phong and other types of materials abstractions.
- Scene and scene objects abstractions.
- Texture loading with mipmapping.
- On the fly shader compiling.
- Raytracing Support (Shadows, AO).
- Texture loading with mipmapping.
- Dynamic renderer states for some graphic features.
- Multipass (depth pass for shadows, SSAO and post-processing).
- Vulkan object and functionality abstraction.
Expand Down Expand Up @@ -163,7 +164,7 @@ int main()
// Create the renderer, you can play with the settings here
Systems::RendererSettings settings{};
settings.samplesMSAA = MSAASamples::MSAA_x4;
settings.samplesMSAA = MSAASamples::x4;
settings.clearColor = Vec4(0.0, 0.0, 0.0, 1.0);
Systems::BaseRenderer *renderer = new Systems::ForwardRenderer(window, settings, {});
Expand Down
8 changes: 6 additions & 2 deletions include/engine/graphics/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ class Device
DRAWING
-----------------------------------------------
*/
/*Setups frame for new rendering cicle, waits for the last one to finish and starts the command buffer*/
RenderResult prepare_frame(Frame& frame, uint32_t& imageIndex);
/*Waits for the frame to finish rendering*/
RenderResult wait_frame(Frame& frame, uint32_t& imageIndex);
/*Resets conmmand and control objects and starts command buffer for new render cicle*/
void start_frame(Frame& frame);
/*Submits the frame to the graphic queue for presenting into the swapchain*/
RenderResult submit_frame(Frame& frame, uint32_t imageIndex);


RenderResult aquire_present_image(Semaphore& waitSemahpore, uint32_t& imageIndex);
RenderResult present_image(Semaphore& signalSemaphore, uint32_t imageIndex);
/*
Expand Down
1 change: 1 addition & 0 deletions src/core/resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ void ResourceManager::update_object_data(Graphics::Device* const device,
//Update Acceleration Structure if change in objects
if (accel->instances < BLASInstances.size())
{
device->wait();
accel->cleanup();
device->upload_TLAS(*accel, BLASInstances);
}
Expand Down
7 changes: 5 additions & 2 deletions src/graphics/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,17 @@ Frame Device::create_frame(uint16_t id) {

return frame;
}
RenderResult Device::prepare_frame(Frame& frame, uint32_t& imageIndex) {
RenderResult Device::wait_frame(Frame& frame, uint32_t& imageIndex) {

frame.renderFence.wait();
RenderResult imageResult = aquire_present_image(frame.presentSemaphore, imageIndex);

return imageResult;
}
void Device::start_frame(Frame& frame) {
frame.renderFence.reset();
frame.commandBuffer.reset();
frame.commandBuffer.begin();
return imageResult;
}
RenderResult Device::submit_frame(Frame& frame, uint32_t imageIndex) {

Expand Down
9 changes: 6 additions & 3 deletions src/systems/renderers/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,20 @@ void BaseRenderer::render(Core::Scene* const scene) {
if (!m_initialized)
init();

on_before_render(scene);

uint32_t imageIndex;
RenderResult result = m_device.prepare_frame(m_frames[m_currentFrame], imageIndex);
RenderResult result = m_device.wait_frame(m_frames[m_currentFrame], imageIndex);

if (result == RenderResult::ERROR_OUT_OF_DATE_KHR)
{
update_renderpasses();
return;
} else if (result != RenderResult::SUCCESS && result != RenderResult::SUBOPTIMAL_KHR)
{ throw VKFW_Exception("failed to acquire swap chain image!"); }

on_before_render(scene);

m_device.start_frame(m_frames[m_currentFrame]);

if (scene->get_skybox())
Core::ResourceManager::generate_skybox_maps(&m_frames[m_currentFrame], scene);

Expand Down

0 comments on commit b2837ed

Please sign in to comment.