diff --git a/examples/VulkanAnimation/main.cpp b/examples/VulkanAnimation/main.cpp index e9e71d0..f9d67ed 100644 --- a/examples/VulkanAnimation/main.cpp +++ b/examples/VulkanAnimation/main.cpp @@ -88,9 +88,22 @@ int main() { */ window.FinishInit(); - EventListener updateListener(&window.onRender, [&](VkCommandBuffer cmd){ - std::cout << window.currentBuffer << std::endl; - RenderingElement3DVulkan::BuildTLAS(cmd, window.currentBuffer); + Animation> anim({ + {std::chrono::seconds(3), -600, 600}, + }); + + anim.Start(std::chrono::high_resolution_clock::now()); + + EventListener updateListener(&window.onRender, [&](){ + float value = std::get<0>(anim.Play(window.currentFrameTime.now)); + + if(anim.currentFrame == anim.keyframes.size()) { + anim.Start(window.currentFrameTime.now); + } + + MatrixRowMajor transform = MatrixRowMajor::Translation(value, 0, 0); + std::memcpy(el.instance.transform.matrix, transform.m, sizeof(transform.m)); + RenderingElement3DVulkan::BuildTLAS(window.drawCmdBuffers[window.currentBuffer], window.currentBuffer); VkDescriptorImageInfo imageInfo = { .imageView = window.imageViews[window.currentBuffer], .imageLayout = VK_IMAGE_LAYOUT_GENERAL @@ -123,7 +136,6 @@ int main() { } }; vkUpdateDescriptorSets(VulkanDevice::device, 2, write, 0, nullptr); - window.descriptorsRt[0] = pool.sets[window.currentBuffer]; }); diff --git a/implementations/Crafter.Graphics-RenderingElement3DVulkan.cpp b/implementations/Crafter.Graphics-RenderingElement3DVulkan.cpp index eedfac5..43d3b4f 100644 --- a/implementations/Crafter.Graphics-RenderingElement3DVulkan.cpp +++ b/implementations/Crafter.Graphics-RenderingElement3DVulkan.cpp @@ -116,4 +116,14 @@ void RenderingElement3DVulkan::BuildTLAS(VkCommandBuffer cmd, std::uint32_t inde VkAccelerationStructureBuildRangeInfoKHR* tlasRangeInfoPP = &tlasRangeInfo; VulkanDevice::vkCmdBuildAccelerationStructuresKHR(cmd, 1, &tlasBuildGeometryInfo, &tlasRangeInfoPP); + + vkCmdPipelineBarrier( + cmd, + VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR, + VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR, + 0, + 0, nullptr, + 0, nullptr, + 0, nullptr + ); } \ No newline at end of file diff --git a/implementations/Crafter.Graphics-Window_vulkan.cpp b/implementations/Crafter.Graphics-Window_vulkan.cpp index a2a0ace..327a81e 100644 --- a/implementations/Crafter.Graphics-Window_vulkan.cpp +++ b/implementations/Crafter.Graphics-Window_vulkan.cpp @@ -368,7 +368,7 @@ void WindowVulkan::Render() { range ); - onRender.Invoke(drawCmdBuffers[currentBuffer]); + onRender.Invoke(); vkCmdBindPipeline(drawCmdBuffers[currentBuffer], VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, rtPipeline); VkBindDescriptorSetsInfo bindDescriptorSetsInfo{ @@ -474,6 +474,7 @@ void WindowVulkan::wl_surface_frame_done(void* data, struct wl_callback *cb, uin if(window->updating) { cb = wl_surface_frame(window->surface); wl_callback_add_listener(cb, &WindowVulkan::wl_callback_listener, window); + window->currentFrameTime = {start, start-window->lastFrameBegin}; window->onUpdate.Invoke({start, start-window->lastFrameBegin}); #ifdef CRAFTER_TIMING window->totalUpdate = std::chrono::nanoseconds(0); diff --git a/interfaces/Crafter.Graphics-Window.cppm b/interfaces/Crafter.Graphics-Window.cppm index f580805..5ae72dd 100644 --- a/interfaces/Crafter.Graphics-Window.cppm +++ b/interfaces/Crafter.Graphics-Window.cppm @@ -76,6 +76,7 @@ export namespace Crafter { class MouseElement; class Window { public: + FrameTime currentFrameTime; std::int32_t width; std::int32_t height; std::chrono::time_point lastFrameBegin; @@ -300,7 +301,7 @@ export namespace Crafter { xkb_keymap* xkb_keymap; xkb_context* xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); xkb_state* xkb_state; - Event onRender; + Event onRender; std::vector descriptorsRt; void Render(); void QueueRender();