From 583f60ce9f3bec7625393f94ee3693934ae5791b Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 24 Dec 2019 09:10:27 -0800 Subject: Reworked ClearRenderTarget and ClearDepthStencil methods to not take nullptr --- .../src/DeviceContextVkImpl.cpp | 58 +++++----------------- .../GraphicsEngineVulkan/src/SwapChainVkImpl.cpp | 7 ++- 2 files changed, 18 insertions(+), 47 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index a508b4e9..330fdcb9 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -609,28 +609,12 @@ void DeviceContextVkImpl::ClearDepthStencil(ITextureView* pView Uint8 Stencil, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) { - ITextureViewVk* pVkDSV = nullptr; - if (pView != nullptr) - { - pVkDSV = ValidatedCast(pView); -#ifdef DEVELOPMENT - const auto& ViewDesc = pVkDSV->GetDesc(); - if (ViewDesc.ViewType != TEXTURE_VIEW_DEPTH_STENCIL) - { - LOG_ERROR("The type (", GetTexViewTypeLiteralName(ViewDesc.ViewType), ") of texture view '", pView->GetDesc().Name, "' is incorrect for ClearDepthStencil operation. Depth-stencil view (TEXTURE_VIEW_DEPTH_STENCIL) must be provided."); - return; - } -#endif - } - else - { - if (m_pBoundDepthStencil == nullptr) - { - LOG_ERROR_MESSAGE("ClearDepthStencil(nullptr, ...) is invalid because no depth-stencil buffer is currently bound."); - return; - } - pVkDSV = m_pBoundDepthStencil; - } + if (!TDeviceContextBase::ClearDepthStencil(pView)) + return; + + VERIFY_EXPR(pView != nullptr); + + auto* pVkDSV = ValidatedCast(pView); EnsureVkCmdBuffer(); @@ -721,30 +705,12 @@ VkClearColorValue ClearValueToVkClearValue(const float* RGBA, TEXTURE_FORMAT Tex void DeviceContextVkImpl::ClearRenderTarget(ITextureView* pView, const float* RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) { - ITextureViewVk* pVkRTV = nullptr; - if (pView != nullptr) - { -#ifdef DEVELOPMENT - const auto& ViewDesc = pView->GetDesc(); - if (ViewDesc.ViewType != TEXTURE_VIEW_RENDER_TARGET) - { - LOG_ERROR("The type (", GetTexViewTypeLiteralName(ViewDesc.ViewType), ") of texture view '", pView->GetDesc().Name, "' is incorrect for ClearRenderTarget operation. Render target view (TEXTURE_VIEW_RENDER_TARGET) must be provided."); - return; - } -#endif - pVkRTV = ValidatedCast(pView); - } - else - { - if (m_NumBoundRenderTargets != 1) - { - 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]; - } + if (!TDeviceContextBase::ClearRenderTarget(pView)) + return; + + VERIFY_EXPR(pView != nullptr); + + auto* pVkRTV = ValidatedCast(pView); static constexpr float Zero[4] = {0.f, 0.f, 0.f, 0.f}; if (RGBA == nullptr) diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp index 98be4ccb..6dd304ac 100644 --- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp @@ -513,10 +513,15 @@ VkResult SwapChainVkImpl::AcquireNextImage(DeviceContextVkImpl* pDeviceCtxVk) if (!m_SwapChainImagesInitialized[m_BackBufferIndex]) { // Vulkan validation layers do not like uninitialized memory. - // Clear back buffer first time we acquire it. This will use vkCmdClearColorImage() + // Clear back buffer first time we acquire it. + + ITextureView* pRTV = GetCurrentBackBufferRTV(); + ITextureView* pDSV = GetDepthBufferDSV(); + pDeviceCtxVk->SetRenderTargets(1, &pRTV, pDSV, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); pDeviceCtxVk->ClearRenderTarget(GetCurrentBackBufferRTV(), nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); m_SwapChainImagesInitialized[m_BackBufferIndex] = true; } + pDeviceCtxVk->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_NONE); } return res; -- cgit v1.2.3