summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2019-12-24 05:24:13 +0000
committerassiduous <assiduous@diligentgraphics.com>2019-12-24 05:24:13 +0000
commit4fd74ca8444da6491d5ec5f5e2b569c09cba2b3a (patch)
tree34bc4400307614539e044c0582f33ee2ce4dd643 /Graphics/GraphicsEngineVulkan
parentOpenGL backend: fixed issue with copying default framebuffer (diff)
downloadDiligentCore-4fd74ca8444da6491d5ec5f5e2b569c09cba2b3a.tar.gz
DiligentCore-4fd74ca8444da6491d5ec5f5e2b569c09cba2b3a.zip
Disabled SetRenderTarget(0, nullptr, nullptr) usage (fixed https://github.com/DiligentGraphics/DiligentCore/issues/81)
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp26
-rw-r--r--Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp30
-rw-r--r--Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp32
3 files changed, 19 insertions, 69 deletions
diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
index 6122ffda..a508b4e9 100644
--- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
@@ -25,7 +25,6 @@
#include <sstream>
#include "RenderDeviceVkImpl.h"
#include "DeviceContextVkImpl.h"
-#include "SwapChainVk.h"
#include "PipelineStateVkImpl.h"
#include "TextureVkImpl.h"
#include "BufferVkImpl.h"
@@ -625,20 +624,12 @@ void DeviceContextVkImpl::ClearDepthStencil(ITextureView* pView
}
else
{
- if (m_pSwapChain)
+ if (m_pBoundDepthStencil == nullptr)
{
- pVkDSV = ValidatedCast<ITextureViewVk>(m_pSwapChain->GetDepthBufferDSV());
- if (pVkDSV == nullptr)
- {
- LOG_WARNING_MESSAGE("Depth buffer is not initialized in the swap chain. Clear operation will be ignored.");
- return;
- }
- }
- else
- {
- LOG_ERROR("Failed to clear default depth stencil buffer: swap chain is not initialized in the device context");
+ LOG_ERROR_MESSAGE("ClearDepthStencil(nullptr, ...) is invalid because no depth-stencil buffer is currently bound.");
return;
}
+ pVkDSV = m_pBoundDepthStencil;
}
EnsureVkCmdBuffer();
@@ -745,15 +736,14 @@ void DeviceContextVkImpl::ClearRenderTarget(ITextureView* pView, const float* RG
}
else
{
- if (m_pSwapChain)
- {
- pVkRTV = ValidatedCast<ITextureViewVk>(m_pSwapChain->GetCurrentBackBufferRTV());
- }
- else
+ if (m_NumBoundRenderTargets != 1)
{
- LOG_ERROR("Failed to clear default render target: swap chain is not initialized in the device context");
+ LOG_ERROR_MESSAGE("ClearRenderTarget(nullptr, ...) semantic is only allowed when single render target is bound to the context. ",
+ m_NumBoundRenderTargets, " render ",
+ (m_NumBoundRenderTargets != 1 ? "targets are" : "target is"), " currently bound");
return;
}
+ pVkRTV = m_pBoundRenderTargets[0];
}
static constexpr float Zero[4] = {0.f, 0.f, 0.f, 0.f};
diff --git a/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp b/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp
index 18be491e..54c387c7 100644
--- a/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp
@@ -337,38 +337,8 @@ void EngineFactoryVkImpl::CreateSwapChainVk(IRenderDevice* pDevice,
auto* pDeviceContextVk = ValidatedCast<DeviceContextVkImpl>(pImmediateContext);
auto& RawMemAllocator = GetRawAllocator();
- if (pDeviceContextVk->GetSwapChain() != nullptr && SCDesc.IsPrimary)
- {
- LOG_ERROR_AND_THROW("Another swap chain labeled as primary has already been created. "
- "There must only be one primary swap chain.");
- }
-
-
auto* pSwapChainVk = NEW_RC_OBJ(RawMemAllocator, "SwapChainVkImpl instance", SwapChainVkImpl)(SCDesc, pDeviceVk, pDeviceContextVk, pNativeWndHandle);
pSwapChainVk->QueryInterface(IID_SwapChain, reinterpret_cast<IObject**>(ppSwapChain));
-
- if (SCDesc.IsPrimary)
- {
- pDeviceContextVk->SetSwapChain(pSwapChainVk);
- // Bind default render target
- pDeviceContextVk->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
- // Set default viewport
- pDeviceContextVk->SetViewports(1, nullptr, 0, 0);
-
- auto NumDeferredCtx = pDeviceVk->GetNumDeferredContexts();
- for (size_t ctx = 0; ctx < NumDeferredCtx; ++ctx)
- {
- if (auto pDeferredCtx = pDeviceVk->GetDeferredContext(ctx))
- {
- auto* pDeferredCtxVk = pDeferredCtx.RawPtr<DeviceContextVkImpl>();
- pDeferredCtxVk->SetSwapChain(pSwapChainVk);
- // We cannot bind default render target here because
- // there is no guarantee that deferred context will be used
- // in this frame. It is an error to bind
- // RTV of an inactive buffer in the swap chain
- }
- }
- }
}
catch (const std::runtime_error&)
{
diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp
index 09905e5f..98be4ccb 100644
--- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp
@@ -547,8 +547,6 @@ void SwapChainVkImpl::Present(Uint32 SyncInterval)
}
pImmediateCtxVk->Flush();
- // If present fails, default FB will be undbound by RecreateVulkanSwapchain(), so we need to check it now
- bool IsDefaultFBBound = pImmediateCtxVk->IsDefaultFBBound();
if (!m_IsMinimized)
{
@@ -605,13 +603,6 @@ void SwapChainVkImpl::Present(Uint32 SyncInterval)
res = AcquireNextImage(pImmediateCtxVk);
}
DEV_CHECK_ERR(res == VK_SUCCESS, "Failed to acquire next swap chain image");
-
- if (m_SwapChainDesc.IsPrimary && IsDefaultFBBound)
- {
- // If default framebuffer is bound, we need to call SetRenderTargets()
- // to bind new back buffer RTV
- pImmediateCtxVk->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
- }
}
}
@@ -631,10 +622,17 @@ void SwapChainVkImpl::WaitForImageAcquiredFences()
void SwapChainVkImpl::RecreateVulkanSwapchain(DeviceContextVkImpl* pImmediateCtxVk)
{
- std::vector<ITextureView*> pBackBufferRTVs(m_pBackBufferRTV.size());
- for (size_t i = 0; i < m_pBackBufferRTV.size(); ++i)
- pBackBufferRTVs[i] = m_pBackBufferRTV[i];
- UnbindRenderTargets(pImmediateCtxVk, pBackBufferRTVs.data(), static_cast<Uint32>(m_pBackBufferRTV.size()), m_pDepthBufferDSV);
+ bool RenderTargetsReset = false;
+ for (Uint32 i = 0; i < m_pBackBufferRTV.size() && !RenderTargetsReset; ++i)
+ {
+ auto* pCurrentBackBuffer = ValidatedCast<TextureVkImpl>(m_pBackBufferRTV[i]->GetTexture());
+ RenderTargetsReset = pImmediateCtxVk->UnbindTextureFromFramebuffer(pCurrentBackBuffer, false);
+ }
+ if (RenderTargetsReset)
+ {
+ LOG_INFO_MESSAGE_ONCE("Resizing the swap chain requires back and depth-stencil buffers to be unbound from the device context. "
+ "An application should use SetRenderTargets() to restore them.");
+ }
RenderDeviceVkImpl* pDeviceVk = m_pRenderDevice.RawPtr<RenderDeviceVkImpl>();
@@ -678,19 +676,11 @@ void SwapChainVkImpl::Resize(Uint32 NewWidth, Uint32 NewHeight)
{
auto* pImmediateCtxVk = pDeviceContext.RawPtr<DeviceContextVkImpl>();
// RecreateVulkanSwapchain() unbinds default FB
- bool bIsDefaultFBBound = pImmediateCtxVk->IsDefaultFBBound();
RecreateVulkanSwapchain(pImmediateCtxVk);
auto res = AcquireNextImage(pImmediateCtxVk);
DEV_CHECK_ERR(res == VK_SUCCESS, "Failed to acquire next image for the just resized swap chain");
(void)res;
-
- if (m_SwapChainDesc.IsPrimary && bIsDefaultFBBound)
- {
- // Set default render target and viewport
- pDeviceContext->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
- pDeviceContext->SetViewports(1, nullptr, 0, 0);
- }
}
catch (const std::runtime_error&)
{