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:
@@ -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());
|
// 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");
|
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);
|
renderPost(commandBuffer, compositeSurface);
|
||||||
|
|
||||||
|
postCompositePass.end(commandBuffer);
|
||||||
|
|
||||||
|
|
||||||
GL_POP_GROUP_MARKER;
|
GL_POP_GROUP_MARKER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -629,6 +642,11 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
|||||||
// m_pContext->getTextureManager()->_setActiveTexture(0);
|
// m_pContext->getTextureManager()->_setActiveTexture(0);
|
||||||
// GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
// GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRCamera::renderDebug(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||||
|
{
|
||||||
const char* szText = settings.m_debug_text.c_str();
|
const char* szText = settings.m_debug_text.c_str();
|
||||||
|
|
||||||
std::string debug_text;
|
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");
|
KRTexture* fontTexture = m_pContext->getTextureManager()->getTexture("font");
|
||||||
fontTexture->resetPoolExpiry(0.0f, KRTexture::TEXTURE_USAGE_UI);
|
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->setImageBinding("fontTexture", fontTexture, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
|
||||||
fontShader->bind(commandBuffer, *this, m_viewport, Matrix4(), nullptr, nullptr, nullptr, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
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);
|
m_debug_text_vbo_data.bind(commandBuffer);
|
||||||
|
|
||||||
vkCmdDraw(commandBuffer, vertex_count, 1, 0, 0);
|
vkCmdDraw(commandBuffer, vertex_count, 1, 0, 0);
|
||||||
|
|
||||||
|
debugPass.end(commandBuffer);
|
||||||
|
|
||||||
m_debug_text_vertices.unlock();
|
m_debug_text_vertices.unlock();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ private:
|
|||||||
int volumetricLightAccumulationBuffer, volumetricLightAccumulationTexture;
|
int volumetricLightAccumulationBuffer, volumetricLightAccumulationTexture;
|
||||||
|
|
||||||
void renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface);
|
void renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface);
|
||||||
|
void renderDebug(VkCommandBuffer& commandBuffer, KRSurface& surface);
|
||||||
|
|
||||||
void destroyBuffers();
|
void destroyBuffers();
|
||||||
|
|
||||||
|
|||||||
@@ -162,6 +162,8 @@ void KRPresentationThread::renderFrame()
|
|||||||
float deltaTime = 0.005; // TODO - Replace dummy value
|
float deltaTime = 0.005; // TODO - Replace dummy value
|
||||||
if (scene) {
|
if (scene) {
|
||||||
scene->renderFrame(commandBuffer, surface, deltaTime);
|
scene->renderFrame(commandBuffer, surface, deltaTime);
|
||||||
|
} else {
|
||||||
|
surface.renderBlackFrame(commandBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) {
|
if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) {
|
||||||
|
|||||||
@@ -56,12 +56,16 @@ void KRRenderPass::create(KRDevice& device, VkFormat swapChainImageFormat, VkFor
|
|||||||
VkAttachmentDescription colorAttachment{};
|
VkAttachmentDescription colorAttachment{};
|
||||||
colorAttachment.format = swapChainImageFormat;
|
colorAttachment.format = swapChainImageFormat;
|
||||||
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
colorAttachment.loadOp = info.clearColor ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||||
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
colorAttachment.storeOp = info.keepColor ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
colorAttachment.initialLayout = info.clearColor ? VK_IMAGE_LAYOUT_UNDEFINED : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
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{};
|
VkAttachmentDescription depthAttachment{};
|
||||||
|
|||||||
@@ -44,8 +44,11 @@ public:
|
|||||||
|
|
||||||
struct RenderPassInfo
|
struct RenderPassInfo
|
||||||
{
|
{
|
||||||
|
bool clearColor;
|
||||||
|
bool keepColor;
|
||||||
bool clearDepth;
|
bool clearDepth;
|
||||||
bool keepDepth;
|
bool keepDepth;
|
||||||
|
bool finalPass;
|
||||||
};
|
};
|
||||||
|
|
||||||
void create(KRDevice& device, VkFormat swapChainImageFormat, VkFormat depthImageFormat, const RenderPassInfo& info);
|
void create(KRDevice& device, VkFormat swapChainImageFormat, VkFormat depthImageFormat, const RenderPassInfo& info);
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, void* platformH
|
|||||||
m_forwardOpaquePass = std::make_unique<KRRenderPass>(context);
|
m_forwardOpaquePass = std::make_unique<KRRenderPass>(context);
|
||||||
m_deferredGBufferPass = std::make_unique<KRRenderPass>(context);
|
m_deferredGBufferPass = std::make_unique<KRRenderPass>(context);
|
||||||
m_deferredOpaquePass = 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);
|
m_swapChain = std::make_unique<KRSwapchain>(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,6 +128,18 @@ void KRSurface::destroy()
|
|||||||
m_deferredOpaquePass->destroy(*device);
|
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++) {
|
for (int i=0; i < KRENGINE_MAX_FRAMES_IN_FLIGHT; i++) {
|
||||||
if (device && m_renderFinishedSemaphores[i] != VK_NULL_HANDLE) {
|
if (device && m_renderFinishedSemaphores[i] != VK_NULL_HANDLE) {
|
||||||
vkDestroySemaphore(device->m_logicalDevice, m_renderFinishedSemaphores[i], nullptr);
|
vkDestroySemaphore(device->m_logicalDevice, m_renderFinishedSemaphores[i], nullptr);
|
||||||
@@ -184,17 +199,47 @@ KrResult KRSurface::createSwapChain()
|
|||||||
|
|
||||||
|
|
||||||
KRRenderPass::RenderPassInfo info{};
|
KRRenderPass::RenderPassInfo info{};
|
||||||
|
info.clearColor = true;
|
||||||
|
info.keepColor = true;
|
||||||
info.clearDepth = true;
|
info.clearDepth = true;
|
||||||
info.keepDepth = false;
|
info.keepDepth = false;
|
||||||
|
info.finalPass = false;
|
||||||
m_forwardOpaquePass->create(*device, selectedSurfaceFormat.format, depthImageFormat, info);
|
m_forwardOpaquePass->create(*device, selectedSurfaceFormat.format, depthImageFormat, info);
|
||||||
|
|
||||||
|
info.clearColor = true;
|
||||||
|
info.keepColor = true;
|
||||||
info.clearDepth = true;
|
info.clearDepth = true;
|
||||||
info.keepDepth = true;
|
info.keepDepth = true;
|
||||||
|
info.finalPass = false;
|
||||||
m_deferredGBufferPass->create(*device, selectedSurfaceFormat.format, depthImageFormat, info);
|
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.clearDepth = false;
|
||||||
info.keepDepth = 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);
|
m_swapChain->create(*device, m_surface, selectedSurfaceFormat, depthImageFormat, swapExtent, imageCount, *m_forwardOpaquePass);
|
||||||
|
|
||||||
@@ -264,7 +309,29 @@ KRRenderPass& KRSurface::getDeferredOpaquePass()
|
|||||||
return *m_deferredOpaquePass;
|
return *m_deferredOpaquePass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KRRenderPass& KRSurface::getPostCompositePass()
|
||||||
|
{
|
||||||
|
return *m_postCompositePass;
|
||||||
|
}
|
||||||
|
|
||||||
|
KRRenderPass& KRSurface::getDebugPass()
|
||||||
|
{
|
||||||
|
return *m_debugPass;
|
||||||
|
}
|
||||||
|
|
||||||
|
KRRenderPass& KRSurface::getBlackFramePass()
|
||||||
|
{
|
||||||
|
return *m_blackFramePass;
|
||||||
|
}
|
||||||
|
|
||||||
void KRSurface::endFrame()
|
void KRSurface::endFrame()
|
||||||
{
|
{
|
||||||
m_frameIndex++;;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public:
|
|||||||
uint32_t getHeight() const;
|
uint32_t getHeight() const;
|
||||||
hydra::Vector2i getDimensions() const;
|
hydra::Vector2i getDimensions() const;
|
||||||
VkFormat getDepthFormat() const;
|
VkFormat getDepthFormat() const;
|
||||||
|
void renderBlackFrame(VkCommandBuffer &commandBuffer);
|
||||||
|
|
||||||
KRSurface(const KRSurface&) = delete;
|
KRSurface(const KRSurface&) = delete;
|
||||||
KRSurface& operator=(const KRSurface&) = delete;
|
KRSurface& operator=(const KRSurface&) = delete;
|
||||||
@@ -59,6 +60,9 @@ public:
|
|||||||
|
|
||||||
KRRenderPass& getDeferredGBufferPass();
|
KRRenderPass& getDeferredGBufferPass();
|
||||||
KRRenderPass& getDeferredOpaquePass();
|
KRRenderPass& getDeferredOpaquePass();
|
||||||
|
KRRenderPass& getPostCompositePass();
|
||||||
|
KRRenderPass& getDebugPass();
|
||||||
|
KRRenderPass& getBlackFramePass();
|
||||||
|
|
||||||
void endFrame();
|
void endFrame();
|
||||||
KrSurfaceHandle m_handle;
|
KrSurfaceHandle m_handle;
|
||||||
@@ -75,6 +79,10 @@ public:
|
|||||||
std::unique_ptr<KRRenderPass> m_forwardOpaquePass;
|
std::unique_ptr<KRRenderPass> m_forwardOpaquePass;
|
||||||
std::unique_ptr<KRRenderPass> m_deferredGBufferPass;
|
std::unique_ptr<KRRenderPass> m_deferredGBufferPass;
|
||||||
std::unique_ptr<KRRenderPass> m_deferredOpaquePass;
|
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
|
// TODO - This needs to be advanced per swap chain
|
||||||
uint64_t m_frameIndex;
|
uint64_t m_frameIndex;
|
||||||
|
|||||||
Reference in New Issue
Block a user