Now rendering black frames rather than empty frames when scene isn't loaded, preventing some Vulkan validation errors.

Added keepColor, clearColor, and finalLayout attributes to KRRenderPass::RenderPassInfo.
Now able to render debug text on macOS.
This commit is contained in:
2024-01-14 15:36:51 -08:00
parent 0c6b0854f2
commit e6706a4e1f
7 changed files with 170 additions and 61 deletions

View File

@@ -404,10 +404,23 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS
// fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i/%i Kbyte (active/total) Shader Handles: %i Visible Bounds: %i Max Texture LOD: %i\n", (int)m_pContext->getMeshManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getActiveMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024, (int)m_pContext->getPipelineManager()->getShaderHandlesUsed(), (int)m_visibleBounds.size(), m_pContext->getTextureManager()->getLODDimCap());
GL_PUSH_GROUP_MARKER("Debug Overlays");
renderDebug(commandBuffer, compositeSurface);
GL_POP_GROUP_MARKER;
GL_PUSH_GROUP_MARKER("Post Processing");
KRRenderPass& postCompositePass = compositeSurface.getPostCompositePass();
postCompositePass.begin(commandBuffer, compositeSurface, Vector4::Create(0.0f, 0.0f, 0.0f, 1.0f));
renderPost(commandBuffer, compositeSurface);
postCompositePass.end(commandBuffer);
GL_POP_GROUP_MARKER;
}
@@ -629,6 +642,11 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface)
// m_pContext->getTextureManager()->_setActiveTexture(0);
// GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
// }
}
void KRCamera::renderDebug(VkCommandBuffer& commandBuffer, KRSurface& surface)
{
const char* szText = settings.m_debug_text.c_str();
std::string debug_text;
@@ -756,6 +774,11 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface)
}
}
m_debug_text_vbo_data.load(commandBuffer);
KRRenderPass& debugPass = surface.getDebugPass();
debugPass.begin(commandBuffer, surface, Vector4::Create(0.0f, 0.0f, 0.0f, 1.0f));
KRTexture* fontTexture = m_pContext->getTextureManager()->getTexture("font");
fontTexture->resetPoolExpiry(0.0f, KRTexture::TEXTURE_USAGE_UI);
@@ -772,11 +795,12 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface)
fontShader->setImageBinding("fontTexture", fontTexture, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
fontShader->bind(commandBuffer, *this, m_viewport, Matrix4(), nullptr, nullptr, nullptr, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
m_debug_text_vbo_data.load(commandBuffer);
m_debug_text_vbo_data.bind(commandBuffer);
vkCmdDraw(commandBuffer, vertex_count, 1, 0, 0);
debugPass.end(commandBuffer);
m_debug_text_vertices.unlock();
} else {

View File

@@ -90,6 +90,7 @@ private:
int volumetricLightAccumulationBuffer, volumetricLightAccumulationTexture;
void renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface);
void renderDebug(VkCommandBuffer& commandBuffer, KRSurface& surface);
void destroyBuffers();

View File

@@ -162,6 +162,8 @@ void KRPresentationThread::renderFrame()
float deltaTime = 0.005; // TODO - Replace dummy value
if (scene) {
scene->renderFrame(commandBuffer, surface, deltaTime);
} else {
surface.renderBlackFrame(commandBuffer);
}
if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) {

View File

@@ -56,12 +56,16 @@ void KRRenderPass::create(KRDevice& device, VkFormat swapChainImageFormat, VkFor
VkAttachmentDescription colorAttachment{};
colorAttachment.format = swapChainImageFormat;
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colorAttachment.loadOp = info.clearColor ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
colorAttachment.storeOp = info.keepColor ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE;
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
colorAttachment.initialLayout = info.clearColor ? VK_IMAGE_LAYOUT_UNDEFINED : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
if (info.finalPass) {
colorAttachment.finalLayout = info.keepColor ? VK_IMAGE_LAYOUT_PRESENT_SRC_KHR : VK_IMAGE_LAYOUT_UNDEFINED;
} else {
colorAttachment.finalLayout = info.keepColor ? VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED;
}
VkAttachmentDescription depthAttachment{};

View File

@@ -44,8 +44,11 @@ public:
struct RenderPassInfo
{
bool clearColor;
bool keepColor;
bool clearDepth;
bool keepDepth;
bool finalPass;
};
void create(KRDevice& device, VkFormat swapChainImageFormat, VkFormat depthImageFormat, const RenderPassInfo& info);

View File

@@ -49,6 +49,9 @@ KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, void* platformH
m_forwardOpaquePass = std::make_unique<KRRenderPass>(context);
m_deferredGBufferPass = std::make_unique<KRRenderPass>(context);
m_deferredOpaquePass = std::make_unique<KRRenderPass>(context);
m_postCompositePass = std::make_unique<KRRenderPass>(context);
m_debugPass = std::make_unique<KRRenderPass>(context);
m_blackFramePass = std::make_unique<KRRenderPass>(context);
m_swapChain = std::make_unique<KRSwapchain>(context);
}
@@ -125,6 +128,18 @@ void KRSurface::destroy()
m_deferredOpaquePass->destroy(*device);
}
if (m_postCompositePass) {
m_postCompositePass->destroy(*device);
}
if (m_debugPass) {
m_debugPass->destroy(*device);
}
if (m_blackFramePass) {
m_blackFramePass->destroy(*device);
}
for (int i=0; i < KRENGINE_MAX_FRAMES_IN_FLIGHT; i++) {
if (device && m_renderFinishedSemaphores[i] != VK_NULL_HANDLE) {
vkDestroySemaphore(device->m_logicalDevice, m_renderFinishedSemaphores[i], nullptr);
@@ -184,17 +199,47 @@ KrResult KRSurface::createSwapChain()
KRRenderPass::RenderPassInfo info{};
info.clearColor = true;
info.keepColor = true;
info.clearDepth = true;
info.keepDepth = false;
info.finalPass = false;
m_forwardOpaquePass->create(*device, selectedSurfaceFormat.format, depthImageFormat, info);
info.clearColor = true;
info.keepColor = true;
info.clearDepth = true;
info.keepDepth = true;
info.finalPass = false;
m_deferredGBufferPass->create(*device, selectedSurfaceFormat.format, depthImageFormat, info);
info.clearColor = false;
info.keepColor = true;
info.clearDepth = false;
info.keepDepth = true;
info.finalPass = false;
m_deferredOpaquePass->create(*device, selectedSurfaceFormat.format, depthImageFormat, info);
info.clearColor = false;
info.keepColor = true;
info.clearDepth = false;
info.keepDepth = true;
info.finalPass = false;
m_debugPass->create(*device, selectedSurfaceFormat.format, depthImageFormat, info);
info.clearColor = false;
info.keepColor = true;
info.clearDepth = false;
info.keepDepth = false;
m_deferredOpaquePass->create(*device, selectedSurfaceFormat.format, depthImageFormat, info);
info.finalPass = true;
m_postCompositePass->create(*device, selectedSurfaceFormat.format, depthImageFormat, info);
info.clearColor = true;
info.keepColor = true;
info.clearDepth = false;
info.keepDepth = false;
info.finalPass = true;
m_blackFramePass->create(*device, selectedSurfaceFormat.format, depthImageFormat, info);
m_swapChain->create(*device, m_surface, selectedSurfaceFormat, depthImageFormat, swapExtent, imageCount, *m_forwardOpaquePass);
@@ -264,7 +309,29 @@ KRRenderPass& KRSurface::getDeferredOpaquePass()
return *m_deferredOpaquePass;
}
KRRenderPass& KRSurface::getPostCompositePass()
{
return *m_postCompositePass;
}
KRRenderPass& KRSurface::getDebugPass()
{
return *m_debugPass;
}
KRRenderPass& KRSurface::getBlackFramePass()
{
return *m_blackFramePass;
}
void KRSurface::endFrame()
{
m_frameIndex++;;
}
void KRSurface::renderBlackFrame(VkCommandBuffer &commandBuffer)
{
m_blackFramePass->begin(commandBuffer, *this, Vector4::Create(0.0f, 0.0f, 0.0f, 1.0f));
m_blackFramePass->end(commandBuffer);
}

View File

@@ -48,6 +48,7 @@ public:
uint32_t getHeight() const;
hydra::Vector2i getDimensions() const;
VkFormat getDepthFormat() const;
void renderBlackFrame(VkCommandBuffer &commandBuffer);
KRSurface(const KRSurface&) = delete;
KRSurface& operator=(const KRSurface&) = delete;
@@ -59,6 +60,9 @@ public:
KRRenderPass& getDeferredGBufferPass();
KRRenderPass& getDeferredOpaquePass();
KRRenderPass& getPostCompositePass();
KRRenderPass& getDebugPass();
KRRenderPass& getBlackFramePass();
void endFrame();
KrSurfaceHandle m_handle;
@@ -75,6 +79,10 @@ public:
std::unique_ptr<KRRenderPass> m_forwardOpaquePass;
std::unique_ptr<KRRenderPass> m_deferredGBufferPass;
std::unique_ptr<KRRenderPass> m_deferredOpaquePass;
std::unique_ptr<KRRenderPass> m_postCompositePass;
std::unique_ptr<KRRenderPass> m_debugPass;
std::unique_ptr<KRRenderPass> m_blackFramePass;
// TODO - This needs to be advanced per swap chain
uint64_t m_frameIndex;