framegraph bugfix

This commit is contained in:
ouczbs 2024-12-16 21:49:57 +08:00
parent 1d3961ec74
commit 5c695160d3
10 changed files with 37 additions and 10 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
build/
vsxmake*/
/tools
*.log

View File

@ -17,5 +17,6 @@ namespace api {
virtual void BindVertexBuffer(BufferDesc buffers) = 0;
virtual void BindVertexBuffers(uint32_t buffer_count, const BufferDesc* buffers, const uint32_t* offsets) = 0;
virtual void DrawIndexed(uint32_t index_count, uint32_t first_index, uint32_t first_vertex) = 0;
virtual void ExecuteSurfaceBarriers(const ResourceBarrierDesc& desc) = 0;
};
}

View File

@ -145,7 +145,7 @@ namespace api {
desc.type = RenderPassType::Present;
desc.textureBarriersCount = 1;
desc.pTextureBarriers = &barrier;
RenderAPI::Ptr()->ExecuteResourceBarriers(desc);
view.context->ExecuteSurfaceBarriers(desc);
}
void FrameGraph::ExecuteComputePass(RenderPassNode* node, FRenderView& view)
{

View File

@ -1,3 +1,4 @@
#pragma once
#include "type.h"
#include "render/renderapi.h"
namespace vkn {
@ -15,6 +16,7 @@ namespace vkn {
void BindVertexBuffer(BufferDesc desc) override;
void BindVertexBuffers(uint32_t buffer_count, const BufferDesc* descs, const uint32_t* offsets)override;
void DrawIndexed(uint32_t index_count, uint32_t first_index, uint32_t first_vertex) override;
void ExecuteSurfaceBarriers(const ResourceBarrierDesc& desc) override;
void BeginRecord(VkCommandBufferUsageFlags flag);
void EndRecord(VkQueue queue);

View File

@ -332,14 +332,12 @@ namespace vkn {
{
VulkanContext& ctx = *(VulkanContext*)&context;
window.Aquire(ctx);
ctx.BeginRecord(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
graph.mSurface = ctx.surface;
EventSystem::Ptr()->BeginRenderFrame.Invoke();
}
void VulkanAPI::EndFrame()
{
VulkanContext& ctx = *(VulkanContext*)&context;
ctx.EndRecord(Backend::RenderWorker->GetQueue().Ptr());
window.Present(ctx);
}
void VulkanAPI::ExecuteResourceBarriers(const ResourceBarrierDesc& desc) {
@ -456,11 +454,15 @@ namespace vkn {
submitInfo.pWaitSemaphores = waitSemaphores;
submitInfo.pWaitDstStageMask = waitDstStageMasks;
submitInfo.waitSemaphoreCount = semaphoreCount;
VkFence fence = nullptr;
if (node->IsLastOutput()) {
ctx.graphSemaphore = passInfo->semaphores[context.frame];
if (graph.mSurface.state == ResourceState::PRESENT) {
fence = ctx.surfaceFence;
}
}
//zlog::info("+++++sign {:#x}", (uintptr_t)passInfo->semaphores[context.frame]);
vkQueueSubmit(Backend::RenderWorker->GetQueue().Ptr(), 1, &submitInfo, nullptr);
vkQueueSubmit(Backend::RenderWorker->GetQueue().Ptr(), 1, &submitInfo, fence);
}
RenderPassInfo* VulkanAPI::GetRenderPassInfo(Name name, size_t hash) {
if (hash) {

View File

@ -1,5 +1,6 @@
#include "vkn/vulkan_context.h"
#include "vkn/backend.h"
#include "vkn/vulkan_api.h"
#include "vkn/thread/command_worker.h"
#include "zlog.h"
namespace vkn {
void VulkanContext::SetScissor(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
@ -49,6 +50,12 @@ namespace vkn {
{
vkCmdDrawIndexed(command, index_count, 1, first_index, first_vertex, 0);
}
void VulkanContext::ExecuteSurfaceBarriers(const ResourceBarrierDesc& desc)
{
BeginRecord(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
VulkanAPI::Ptr()->ExecuteResourceBarriers(desc);
EndRecord(Backend::RenderWorker->GetQueue().Ptr());
}
void VulkanContext::BeginRecord(VkCommandBufferUsageFlags flag)
{
VkCommandBufferBeginInfo beginInfo{
@ -79,6 +86,6 @@ namespace vkn {
//zlog::info("-----wait {:#x}", (uintptr_t)waitSemaphores[0]);
//zlog::info("+++++sign {:#x}", (uintptr_t)signalSemaphores[0]);
vkQueueSubmit(queue, 1, &submitInfo, surfaceFence);
graphSemaphore = nullptr;
graphSemaphore = presentSemaphore;
}
}

View File

@ -47,7 +47,7 @@ namespace vkn {
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
VkAttachmentReference colorAttachmentRef = {};
@ -64,7 +64,7 @@ namespace vkn {
dependency.dstSubpass = 0;
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependency.srcAccessMask = 0; // or VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
VkRenderPassCreateInfo info = {};
@ -140,7 +140,7 @@ namespace vkn {
ImGui::End();
ImGui::Render();
VulkanContext& ctx = *(VulkanContext*)&context.parent;
VulkanContext& ctx = *(VulkanContext*)context.parent;
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), ctx.command);
ImGuiIO& io = ImGui::GetIO();
// 更新并渲染平台窗口

View File

@ -109,7 +109,7 @@ namespace vkn {
//zlog::info("present+++++++++++:: {:#x}", (uintptr_t)ctx.presentSemaphore);
VkPresentInfoKHR presentInfo = {};
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
presentInfo.pWaitSemaphores = &ctx.presentSemaphore;
presentInfo.pWaitSemaphores = &ctx.graphSemaphore;
presentInfo.waitSemaphoreCount = 1;
presentInfo.pSwapchains = &mPtr;
presentInfo.swapchainCount = 1;

14
game/zworld/imgui.ini Normal file
View File

@ -0,0 +1,14 @@
[Window][Debug##Default]
ViewportPos=480,240
ViewportId=0x16723995
Size=400,400
Collapsed=0
[Window][Hello, ImGui!]
ViewportPos=480,240
ViewportId=0x41ACA57A
Size=191,71
Collapsed=0
[Docking][Data]