From 632071a04ecb93ce1bf42579693c911b7bef0c70 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 7 Jul 2018 17:49:54 -0700 Subject: Removed unused CommandContext.cpp/h from Vulkan lib --- Graphics/GraphicsEngineVulkan/CMakeLists.txt | 2 - .../GraphicsEngineVulkan/include/CommandContext.h | 373 --------------------- .../include/RenderDeviceVkImpl.h | 1 - .../GraphicsEngineVulkan/src/CommandContext.cpp | 322 ------------------ .../src/DeviceContextVkImpl.cpp | 1 - .../src/PipelineStateVkImpl.cpp | 1 - 6 files changed, 700 deletions(-) delete mode 100644 Graphics/GraphicsEngineVulkan/include/CommandContext.h delete mode 100644 Graphics/GraphicsEngineVulkan/src/CommandContext.cpp (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index 0c675546..fc4d36c5 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -5,7 +5,6 @@ project(GraphicsEngineVk CXX) set(INCLUDE include/BufferVkImpl.h include/BufferViewVkImpl.h - include/CommandContext.h include/CommandListVkImpl.h include/CommandPoolManager.h include/CommandQueueVkImpl.h @@ -67,7 +66,6 @@ set(INTERFACE set(SRC src/BufferVkImpl.cpp src/BufferViewVkImpl.cpp - src/CommandContext.cpp src/CommandPoolManager.cpp src/CommandQueueVkImpl.cpp src/DescriptorPoolManager.cpp diff --git a/Graphics/GraphicsEngineVulkan/include/CommandContext.h b/Graphics/GraphicsEngineVulkan/include/CommandContext.h deleted file mode 100644 index 640bb828..00000000 --- a/Graphics/GraphicsEngineVulkan/include/CommandContext.h +++ /dev/null @@ -1,373 +0,0 @@ -/* Copyright 2015-2018 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - - -#pragma once - -#include - -#if 0 -//#include "D3D12ResourceBase.h" -#include "TextureViewVk.h" -#include "TextureVk.h" -#include "BufferVk.h" - -namespace Diligent -{ -// -// -//struct DWParam -//{ -// DWParam( FLOAT f ) : Float(f) {} -// DWParam( UINT u ) : Uint(u) {} -// DWParam( INT i ) : Int(i) {} -// -// void operator= ( FLOAT f ) { Float = f; } -// void operator= ( UINT u ) { Uint = u; } -// void operator= ( INT i ) { Int = i; } -// -// union -// { -// FLOAT Float; -// UINT Uint; -// INT Int; -// }; -//}; - - -class CommandContext -{ -public: - /* - CommandContext( IMemoryAllocator &MemAllocator, - class CommandListManager& CmdListManager, - GPUDescriptorHeap GPUDescriptorHeaps[], - const Uint32 DynamicDescriptorAllocationChunkSize[]); - - ~CommandContext(void); - - // Submit the command buffer and reset it. This is encouraged to keep the GPU busy and reduce latency. - // Taking too long to build command lists and submit them can idle the GPU. - ID3D12GraphicsCommandList* Close(ID3D12CommandAllocator **ppAllocator); - void Reset( CommandListManager& CmdListManager ); - - class GraphicsContext& AsGraphicsContext(); - class ComputeContext& AsComputeContext(); - - void ClearUAVFloat( ITextureViewD3D12 *pTexView, const float* Color ); - void ClearUAVUint( ITextureViewD3D12 *pTexView, const UINT *Color ); - - void CopyResource(ID3D12Resource *pDstRes, ID3D12Resource *pSrcRes) - { - m_pCommandList->CopyResource(pDstRes, pSrcRes); - } - - void TransitionResource(ITextureD3D12 *pTexture, D3D12_RESOURCE_STATES NewState, bool FlushImmediate = false); - void TransitionResource(IBufferD3D12 *pBuffer, D3D12_RESOURCE_STATES NewState, bool FlushImmediate = false); - //void BeginResourceTransition(GpuResource& Resource, D3D12_RESOURCE_STATES NewState, bool FlushImmediate = false); - void FlushResourceBarriers(); - - struct ShaderDescriptorHeaps - { - ID3D12DescriptorHeap* pSrvCbvUavHeap; - ID3D12DescriptorHeap* pSamplerHeap; - ShaderDescriptorHeaps(ID3D12DescriptorHeap* _pSrvCbvUavHeap = nullptr, ID3D12DescriptorHeap* _pSamplerHeap = nullptr) : - pSrvCbvUavHeap(_pSrvCbvUavHeap), - pSamplerHeap(_pSamplerHeap) - {} - bool operator == (const ShaderDescriptorHeaps& rhs)const - { - return pSrvCbvUavHeap == rhs.pSrvCbvUavHeap && pSamplerHeap == rhs.pSamplerHeap; - } - operator bool()const - { - return pSrvCbvUavHeap != nullptr || pSamplerHeap != nullptr; - } - }; - void SetDescriptorHeaps( ShaderDescriptorHeaps& Heaps ); - - void ExecuteIndirect(ID3D12CommandSignature *pCmdSignature, ID3D12Resource *pBuff, Uint64 ArgsOffset) - { - FlushResourceBarriers(); - m_pCommandList->ExecuteIndirect(pCmdSignature, 1, pBuff, ArgsOffset, nullptr, 0); - } - - void SetID(const Char* ID) { m_ID = ID; } - ID3D12GraphicsCommandList *GetCommandList(){return m_pCommandList;} - - void DiscardDynamicDescriptors(Uint64 FenceValue); - DescriptorHeapAllocation AllocateDynamicGPUVisibleDescriptor( D3D12_DESCRIPTOR_HEAP_TYPE Type, UINT Count = 1 ); - - void InsertUAVBarrier(D3D12ResourceBase& Resource, IDeviceObject &Object, bool FlushImmediate = false); - - void SetPipelineState( ID3D12PipelineState* pPSO ) - { - if (pPSO != m_pCurPipelineState) - { - m_pCommandList->SetPipelineState(m_pCurPipelineState = pPSO); - } - } - -protected: - void TransitionResource(D3D12ResourceBase& Resource, IDeviceObject &Object, D3D12_RESOURCE_STATES NewState, bool FlushImmediate); - void InsertAliasBarrier(D3D12ResourceBase& Before, D3D12ResourceBase& After, IDeviceObject &BeforeObj, IDeviceObject &AfterObj, bool FlushImmediate = false); - - CComPtr m_pCommandList; - CComPtr m_pCurrentAllocator; - - ID3D12PipelineState* m_pCurPipelineState = nullptr; - ID3D12RootSignature* m_pCurGraphicsRootSignature = nullptr; - ID3D12RootSignature* m_pCurComputeRootSignature = nullptr; - - static constexpr int MaxPendingBarriers = 16; - std::vector > m_PendingResourceBarriers; - // We must make sure that all referenced objects are alive until barriers are executed - // Keeping reference to ID3D12Resource is not sufficient! - // TextureD3D12Impl::~TextureD3D12Impl() and BufferD3D12Impl::~BufferD3D12Impl() - // are responsible for putting the D3D12 resource in the release queue - std::vector< RefCntAutoPtr, STDAllocatorRawMem> > m_PendingBarrierObjects; - - ShaderDescriptorHeaps m_BoundDescriptorHeaps; - - // Every context must use its own allocator that maintains individual list of retired descriptor heaps to - // avoid interference with other command contexts - // The heaps can only be discarded after the command list is submitted for execution - DynamicSuballocationsManager m_DynamicGPUDescriptorAllocator[2]; - - String m_ID; - - D3D12_PRIMITIVE_TOPOLOGY m_PrimitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; - */ -}; - - -class GraphicsContext : public CommandContext -{ -public: - /* - void ClearRenderTarget( ITextureViewD3D12 *pRTV, const float *Color ); - void ClearDepthStencil( ITextureViewD3D12 *pDSV, D3D12_CLEAR_FLAGS ClearFlags, float Depth, UINT8 Stencil ); - - void SetRootSignature( ID3D12RootSignature *pRootSig ) - { - if (pRootSig != m_pCurGraphicsRootSignature) - { - m_pCommandList->SetGraphicsRootSignature(m_pCurGraphicsRootSignature = pRootSig); - } - } - - void SetRenderTargets( UINT NumRTVs, ITextureViewD3D12** ppRTVs, ITextureViewD3D12* pDSV ); - - void SetViewports( UINT NumVPs, const D3D12_VIEWPORT* pVPs ) - { - m_pCommandList->RSSetViewports(NumVPs, pVPs); - } - - void SetScissorRects( UINT NumRects, const D3D12_RECT* pRects ) - { - m_pCommandList->RSSetScissorRects(NumRects, pRects); - } - - void SetStencilRef( UINT StencilRef ) - { - m_pCommandList->OMSetStencilRef( StencilRef ); - } - - void SetBlendFactor( const float* BlendFactor ) - { - m_pCommandList->OMSetBlendFactor( BlendFactor ); - } - - void SetPrimitiveTopology( D3D12_PRIMITIVE_TOPOLOGY Topology ) - { - if(m_PrimitiveTopology != Topology) - { - m_PrimitiveTopology = Topology; - m_pCommandList->IASetPrimitiveTopology(Topology); - } - } - - void SetConstants( UINT RootIndex, UINT NumConstants, const void* pConstants ) - { - m_pCommandList->SetGraphicsRoot32BitConstants( RootIndex, NumConstants, pConstants, 0 ); - } - - void SetConstants( UINT RootIndex, DWParam X ) - { - m_pCommandList->SetGraphicsRoot32BitConstant( RootIndex, X.Uint, 0 ); - } - - void SetConstants( UINT RootIndex, DWParam X, DWParam Y ) - { - m_pCommandList->SetGraphicsRoot32BitConstant( RootIndex, X.Uint, 0 ); - m_pCommandList->SetGraphicsRoot32BitConstant( RootIndex, Y.Uint, 1 ); - } - - void SetConstants( UINT RootIndex, DWParam X, DWParam Y, DWParam Z ) - { - m_pCommandList->SetGraphicsRoot32BitConstant( RootIndex, X.Uint, 0 ); - m_pCommandList->SetGraphicsRoot32BitConstant( RootIndex, Y.Uint, 1 ); - m_pCommandList->SetGraphicsRoot32BitConstant( RootIndex, Z.Uint, 2 ); - } - - void SetConstants( UINT RootIndex, DWParam X, DWParam Y, DWParam Z, DWParam W ) - { - m_pCommandList->SetGraphicsRoot32BitConstant( RootIndex, X.Uint, 0 ); - m_pCommandList->SetGraphicsRoot32BitConstant( RootIndex, Y.Uint, 1 ); - m_pCommandList->SetGraphicsRoot32BitConstant( RootIndex, Z.Uint, 2 ); - m_pCommandList->SetGraphicsRoot32BitConstant( RootIndex, W.Uint, 3 ); - } - - void SetConstantBuffer( UINT RootIndex, D3D12_GPU_VIRTUAL_ADDRESS CBV ) - { - m_pCommandList->SetGraphicsRootConstantBufferView(RootIndex, CBV); - } - - void SetDescriptorTable( UINT RootIndex, D3D12_GPU_DESCRIPTOR_HANDLE FirstHandle ) - { - m_pCommandList->SetGraphicsRootDescriptorTable( RootIndex, FirstHandle ); - } - - void SetIndexBuffer( const D3D12_INDEX_BUFFER_VIEW& IBView ) - { - m_pCommandList->IASetIndexBuffer(&IBView); - } - - void SetVertexBuffers( UINT StartSlot, UINT Count, const D3D12_VERTEX_BUFFER_VIEW VBViews[] ) - { - m_pCommandList->IASetVertexBuffers(StartSlot, Count, VBViews); - } - - void Draw(UINT VertexCountPerInstance, UINT InstanceCount, - UINT StartVertexLocation, UINT StartInstanceLocation) - { - FlushResourceBarriers(); - m_pCommandList->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation, StartInstanceLocation); - } - - void DrawIndexed(UINT IndexCountPerInstance, UINT InstanceCount, UINT StartIndexLocation, - INT BaseVertexLocation, UINT StartInstanceLocation) - { - FlushResourceBarriers(); - m_pCommandList->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, BaseVertexLocation, StartInstanceLocation); - } - */ -}; - -class ComputeContext : public CommandContext -{ -/* -public: - - void SetRootSignature( ID3D12RootSignature *pRootSig ) - { - if (pRootSig != m_pCurComputeRootSignature) - { - m_pCommandList->SetComputeRootSignature(m_pCurComputeRootSignature = pRootSig); - } - } - - void SetConstants( UINT RootIndex, UINT NumConstants, const void* pConstants ) - { - m_pCommandList->SetComputeRoot32BitConstants( RootIndex, NumConstants, pConstants, 0 ); - } - - void SetConstants( UINT RootIndex, DWParam X ) - { - m_pCommandList->SetComputeRoot32BitConstant( RootIndex, X.Uint, 0 ); - } - - void SetConstants( UINT RootIndex, DWParam X, DWParam Y ) - { - m_pCommandList->SetComputeRoot32BitConstant( RootIndex, X.Uint, 0 ); - m_pCommandList->SetComputeRoot32BitConstant( RootIndex, Y.Uint, 1 ); - } - - void SetConstants( UINT RootIndex, DWParam X, DWParam Y, DWParam Z ) - { - m_pCommandList->SetComputeRoot32BitConstant( RootIndex, X.Uint, 0 ); - m_pCommandList->SetComputeRoot32BitConstant( RootIndex, Y.Uint, 1 ); - m_pCommandList->SetComputeRoot32BitConstant( RootIndex, Z.Uint, 2 ); - } - - void SetConstants( UINT RootIndex, DWParam X, DWParam Y, DWParam Z, DWParam W ) - { - m_pCommandList->SetComputeRoot32BitConstant( RootIndex, X.Uint, 0 ); - m_pCommandList->SetComputeRoot32BitConstant( RootIndex, Y.Uint, 1 ); - m_pCommandList->SetComputeRoot32BitConstant( RootIndex, Z.Uint, 2 ); - m_pCommandList->SetComputeRoot32BitConstant( RootIndex, W.Uint, 3 ); - } - - - void SetConstantBuffer( UINT RootIndex, D3D12_GPU_VIRTUAL_ADDRESS CBV ) - { - m_pCommandList->SetComputeRootConstantBufferView(RootIndex, CBV); - } - - void SetDescriptorTable( UINT RootIndex, D3D12_GPU_DESCRIPTOR_HANDLE FirstHandle ) - { - m_pCommandList->SetComputeRootDescriptorTable( RootIndex, FirstHandle ); - } - - void Dispatch( size_t GroupCountX = 1, size_t GroupCountY = 1, size_t GroupCountZ = 1 ) - { - FlushResourceBarriers(); - m_pCommandList->Dispatch((UINT)GroupCountX, (UINT)GroupCountY, (UINT)GroupCountZ); - } - */ -}; - -/* -inline GraphicsContext& CommandContext::AsGraphicsContext() -{ - return static_cast(*this); -} - -inline ComputeContext& CommandContext::AsComputeContext() -{ - return static_cast(*this); -} - -inline void CommandContext::SetDescriptorHeaps( ShaderDescriptorHeaps& Heaps ) -{ -#ifdef _DEBUG - VERIFY(Heaps.pSrvCbvUavHeap != nullptr || Heaps.pSamplerHeap != nullptr, "At least one heap is expected to be set"); - VERIFY(Heaps.pSrvCbvUavHeap == nullptr || Heaps.pSrvCbvUavHeap->GetDesc().Type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, "Invalid heap type provided in pSrvCbvUavHeap"); - VERIFY(Heaps.pSamplerHeap == nullptr || Heaps.pSamplerHeap->GetDesc().Type == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, "Invalid heap type provided in pSamplerHeap"); -#endif - - if (!(Heaps == m_BoundDescriptorHeaps)) - { - m_BoundDescriptorHeaps = Heaps; - - ID3D12DescriptorHeap **ppHeaps = reinterpret_cast(&Heaps); - UINT NumHeaps = (ppHeaps[0] != nullptr ? 1 : 0) + (ppHeaps[1] != nullptr ? 1 : 0); - if(ppHeaps[0] == nullptr) - ++ppHeaps; - - m_pCommandList->SetDescriptorHeaps(NumHeaps, ppHeaps); - } -} -*/ -} -#endif \ No newline at end of file diff --git a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h index b80a255c..1f40ed6a 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h @@ -30,7 +30,6 @@ #include "RenderDeviceVk.h" #include "RenderDeviceBase.h" #include "DescriptorPoolManager.h" -#include "CommandContext.h" #include "VulkanDynamicHeap.h" #include "Atomics.h" #include "CommandQueueVk.h" diff --git a/Graphics/GraphicsEngineVulkan/src/CommandContext.cpp b/Graphics/GraphicsEngineVulkan/src/CommandContext.cpp deleted file mode 100644 index 46deb474..00000000 --- a/Graphics/GraphicsEngineVulkan/src/CommandContext.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/* Copyright 2015-2018 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#include "pch.h" -#include "CommandContext.h" -#include "TextureVkImpl.h" -#include "BufferVkImpl.h" - -#if 0 -namespace Diligent -{ - -CommandContext::CommandContext( IMemoryAllocator &MemAllocator, - CommandListManager &CmdListManager, - GPUDescriptorHeap GPUDescriptorHeaps[], - const Uint32 DynamicDescriptorAllocationChunkSize[])/* : - m_pCurGraphicsRootSignature( nullptr), - m_pCurPipelineState( nullptr), - m_pCurComputeRootSignature( nullptr), - m_DynamicGPUDescriptorAllocator - { - {MemAllocator, GPUDescriptorHeaps[0], DynamicDescriptorAllocationChunkSize[0]}, - {MemAllocator, GPUDescriptorHeaps[1], DynamicDescriptorAllocationChunkSize[1]} - }, - m_PendingResourceBarriers( STD_ALLOCATOR_RAW_MEM(Vk_RESOURCE_BARRIER, GetRawAllocator(), "Allocator for vector") ), - m_PendingBarrierObjects( STD_ALLOCATOR_RAW_MEM(RefCntAutoPtr, GetRawAllocator(), "Allocator for vector>") ) - */ -{ -#if 0 - m_PendingResourceBarriers.reserve(MaxPendingBarriers); - m_PendingBarrierObjects.reserve(MaxPendingBarriers); - - CmdListManager.CreateNewCommandList(&m_pCommandList, &m_pCurrentAllocator); -#endif -} - -CommandContext::~CommandContext( void ) -{ -} - - -#if 0 -void CommandContext::Reset( CommandListManager& CmdListManager ) -{ - - // We only call Reset() on previously freed contexts. The command list persists, but we need to - // request a new allocator if there is none - // The allocator may not be null if the command context was previously disposed without being executed - VERIFY_EXPR(m_pCommandList != nullptr); - if( !m_pCurrentAllocator ) - { - CmdListManager.RequestAllocator(&m_pCurrentAllocator); - m_pCommandList->Reset(m_pCurrentAllocator, nullptr); - } - - m_pCurPipelineState = nullptr; - m_pCurGraphicsRootSignature = nullptr; - m_pCurComputeRootSignature = nullptr; - m_PendingResourceBarriers.clear(); - m_PendingBarrierObjects.clear(); - m_BoundDescriptorHeaps = ShaderDescriptorHeaps(); - - m_PrimitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; -#if 0 - BindDescriptorHeaps(); -#endif -} - - -IVkGraphicsCommandList* CommandContext::Close(IVkCommandAllocator **ppAllocator) -{ - - FlushResourceBarriers(); - - //if (m_ID.length() > 0) - // EngineProfiling::EndBlock(this); - - VERIFY_EXPR(m_pCurrentAllocator != nullptr); - auto hr = m_pCommandList->Close(); - VERIFY(SUCCEEDED(hr), "Failed to close the command list"); - - if( ppAllocator != nullptr ) - *ppAllocator = m_pCurrentAllocator.Detach(); - return m_pCommandList; -} - - - -void GraphicsContext::SetRenderTargets( UINT NumRTVs, ITextureViewVk** ppRTVs, ITextureViewVk* pDSV ) -{ - Vk_CPU_DESCRIPTOR_HANDLE RTVHandles[8]; // Do not waste time initializing array to zero - - for (UINT i = 0; i < NumRTVs; ++i) - { - auto *pRTV = ppRTVs[i]; - if( pRTV ) - { - auto *pTexture = ValidatedCast( pRTV->GetTexture() ); - TransitionResource(pTexture, Vk_RESOURCE_STATE_RENDER_TARGET); - RTVHandles[i] = pRTV->GetCPUDescriptorHandle(); - VERIFY_EXPR(RTVHandles[i].ptr != 0); - } - } - - if (pDSV) - { - auto *pTexture = ValidatedCast( pDSV->GetTexture() ); - //if (bReadOnlyDepth) - //{ - // TransitionResource(*pTexture, Vk_RESOURCE_STATE_DEPTH_READ); - // m_pCommandList->OMSetRenderTargets( NumRTVs, RTVHandles, FALSE, &DSV->GetDSV_DepthReadOnly() ); - //} - //else - { - TransitionResource(pTexture, Vk_RESOURCE_STATE_DEPTH_WRITE); - auto DSVHandle = pDSV->GetCPUDescriptorHandle(); - VERIFY_EXPR(DSVHandle.ptr != 0); - m_pCommandList->OMSetRenderTargets( NumRTVs, RTVHandles, FALSE, &DSVHandle ); - } - } - else if(NumRTVs > 0) - { - m_pCommandList->OMSetRenderTargets( NumRTVs, RTVHandles, FALSE, nullptr ); - } -} - -void CommandContext::ClearUAVFloat( ITextureViewVk *pTexView, const float* Color ) -{ - auto *pTexture = ValidatedCast( pTexView->GetTexture() ); - TransitionResource(pTexture, Vk_RESOURCE_STATE_UNORDERED_ACCESS, true); - - // After binding a UAV, we can get a GPU handle that is required to clear it as a UAV (because it essentially runs - // a shader to set all of the values). - UNSUPPORTED("Not yet implemented"); - Vk_GPU_DESCRIPTOR_HANDLE GpuVisibleHandle = {};//m_DynamicDescriptorHeap.UploadDirect(Target.GetUAV()); - m_pCommandList->ClearUnorderedAccessViewFloat(GpuVisibleHandle, pTexView->GetCPUDescriptorHandle(), pTexture->GetVkResource(), Color, 0, nullptr); -} - -void CommandContext::ClearUAVUint( ITextureViewVk *pTexView, const UINT *Color ) -{ - auto *pTexture = ValidatedCast( pTexView->GetTexture() ); - TransitionResource(pTexture, Vk_RESOURCE_STATE_UNORDERED_ACCESS, true); - - // After binding a UAV, we can get a GPU handle that is required to clear it as a UAV (because it essentially runs - // a shader to set all of the values). - UNSUPPORTED("Not yet implemented"); - Vk_GPU_DESCRIPTOR_HANDLE GpuVisibleHandle = {};//m_DynamicDescriptorHeap.UploadDirect(Target.GetUAV()); - //CD3DX12_RECT ClearRect(0, 0, (LONG)Target.GetWidth(), (LONG)Target.GetHeight()); - - //TODO: My Nvidia card is not clearing UAVs with either Float or Uint variants. - m_pCommandList->ClearUnorderedAccessViewUint(GpuVisibleHandle, pTexView->GetCPUDescriptorHandle(), pTexture->GetVkResource(), Color, 0, nullptr/*1, &ClearRect*/); -} - - -void GraphicsContext::ClearRenderTarget( ITextureViewVk *pRTV, const float *Color ) -{ - auto *pTexture = ValidatedCast( pRTV->GetTexture() ); - TransitionResource(pTexture, Vk_RESOURCE_STATE_RENDER_TARGET, true); - m_pCommandList->ClearRenderTargetView(pRTV->GetCPUDescriptorHandle(), Color, 0, nullptr); -} - -void GraphicsContext::ClearDepthStencil( ITextureViewVk *pDSV, Vk_CLEAR_FLAGS ClearFlags, float Depth, UINT8 Stencil ) -{ - auto *pTexture = ValidatedCast( pDSV->GetTexture() ); - TransitionResource( pTexture, Vk_RESOURCE_STATE_DEPTH_WRITE, true); - m_pCommandList->ClearDepthStencilView(pDSV->GetCPUDescriptorHandle(), ClearFlags, Depth, Stencil, 0, nullptr); -} - - -void CommandContext::TransitionResource(ITextureVk *pTexture, Vk_RESOURCE_STATES NewState, bool FlushImmediate) -{ - VERIFY_EXPR( pTexture != nullptr ); - auto *pTexVk = ValidatedCast(pTexture); - TransitionResource(*pTexVk, *pTexVk, NewState, FlushImmediate); -} - -void CommandContext::TransitionResource(IBufferVk *pBuffer, Vk_RESOURCE_STATES NewState, bool FlushImmediate) -{ - VERIFY_EXPR( pBuffer != nullptr ); - auto *pBuffVk = ValidatedCast(pBuffer); - -#ifdef _DEBUG - // Dynamic buffers wtih no SRV/UAV bind flags are suballocated in - // the upload heap when Map() is called and must always be in - // Vk_RESOURCE_STATE_GENERIC_READ state - if(pBuffVk->GetDesc().Usage == USAGE_DYNAMIC && (pBuffVk->GetDesc().BindFlags & (BIND_SHADER_RESOURCE|BIND_UNORDERED_ACCESS)) == 0) - { - VERIFY(pBuffVk->GetState() == Vk_RESOURCE_STATE_GENERIC_READ, "Dynamic buffers that cannot be bound as SRV or UAV are expected to always be in Vk_RESOURCE_STATE_GENERIC_READ state"); - VERIFY( (NewState & Vk_RESOURCE_STATE_GENERIC_READ) == NewState, "Dynamic buffers can only transition to one of Vk_RESOURCE_STATE_GENERIC_READ states"); - } -#endif - - TransitionResource(*pBuffVk, *pBuffVk, NewState, FlushImmediate); - -#ifdef _DEBUG - if(pBuffVk->GetDesc().Usage == USAGE_DYNAMIC && (pBuffVk->GetDesc().BindFlags & (BIND_SHADER_RESOURCE|BIND_UNORDERED_ACCESS)) == 0) - VERIFY(pBuffVk->GetState() == Vk_RESOURCE_STATE_GENERIC_READ, "Dynamic buffers without SRV/UAV bind flag are expected to never transition from Vk_RESOURCE_STATE_GENERIC_READ state"); -#endif -} - -void CommandContext::TransitionResource(VkResourceBase& Resource, IDeviceObject &Object, Vk_RESOURCE_STATES NewState, bool FlushImmediate) -{ - Vk_RESOURCE_STATES OldState = Resource.GetState(); - - // Check if required state is already set - if ( (OldState & NewState) != NewState || NewState == 0 && OldState != 0 ) - { - // If both old state and new state are read-only states, combine the two - if( (OldState & Vk_RESOURCE_STATE_GENERIC_READ) == OldState && - (NewState & Vk_RESOURCE_STATE_GENERIC_READ) == NewState ) - NewState |= OldState; - - m_PendingResourceBarriers.emplace_back(); - m_PendingBarrierObjects.emplace_back(&Object); - Vk_RESOURCE_BARRIER& BarrierDesc = m_PendingResourceBarriers.back(); - - BarrierDesc.Type = Vk_RESOURCE_BARRIER_TYPE_TRANSITION; - BarrierDesc.Transition.pResource = Resource.GetVkResource(); - BarrierDesc.Transition.Subresource = Vk_RESOURCE_BARRIER_ALL_SUBRESOURCES; - BarrierDesc.Transition.StateBefore = OldState; - BarrierDesc.Transition.StateAfter = NewState; - - // Check to see if we already started the transition -#if 0 - if (NewState == Resource.m_TransitioningState) - { - BarrierDesc.Flags = Vk_RESOURCE_BARRIER_FLAG_END_ONLY; - Resource.m_TransitioningState = (Vk_RESOURCE_STATES)-1; - } - else -#endif - BarrierDesc.Flags = Vk_RESOURCE_BARRIER_FLAG_NONE; - - Resource.SetState( NewState ); - } - else if (NewState == Vk_RESOURCE_STATE_UNORDERED_ACCESS) - InsertUAVBarrier(Resource, Object, FlushImmediate); - - if (FlushImmediate || m_PendingResourceBarriers.size() >= MaxPendingBarriers) - FlushResourceBarriers(); -} - -void CommandContext::FlushResourceBarriers() -{ - if (m_PendingResourceBarriers.empty()) - { - VERIFY_EXPR(m_PendingBarrierObjects.empty()); - return; - } - - m_pCommandList->ResourceBarrier(static_cast(m_PendingResourceBarriers.size()), m_PendingResourceBarriers.data()); - m_PendingResourceBarriers.clear(); - m_PendingBarrierObjects.clear(); -} - - -void CommandContext::InsertUAVBarrier(VkResourceBase& Resource, IDeviceObject &Object, bool FlushImmediate) -{ - m_PendingResourceBarriers.emplace_back(); - m_PendingBarrierObjects.emplace_back(&Object); - Vk_RESOURCE_BARRIER& BarrierDesc = m_PendingResourceBarriers.back(); - - BarrierDesc.Type = Vk_RESOURCE_BARRIER_TYPE_UAV; - BarrierDesc.Flags = Vk_RESOURCE_BARRIER_FLAG_NONE; - BarrierDesc.UAV.pResource = Resource.GetVkResource(); - - if (FlushImmediate) - FlushResourceBarriers(); -} - -void CommandContext::InsertAliasBarrier(VkResourceBase& Before, VkResourceBase& After, IDeviceObject &BeforeObj, IDeviceObject &AfterObj, bool FlushImmediate) -{ - m_PendingResourceBarriers.emplace_back(); - m_PendingBarrierObjects.emplace_back(&BeforeObj); - m_PendingBarrierObjects.emplace_back(&AfterObj); - Vk_RESOURCE_BARRIER& BarrierDesc = m_PendingResourceBarriers.back(); - - BarrierDesc.Type = Vk_RESOURCE_BARRIER_TYPE_ALIASING; - BarrierDesc.Flags = Vk_RESOURCE_BARRIER_FLAG_NONE; - BarrierDesc.Aliasing.pResourceBefore = Before.GetVkResource(); - BarrierDesc.Aliasing.pResourceAfter = After.GetVkResource(); - - if (FlushImmediate) - FlushResourceBarriers(); -} - -void CommandContext::DiscardDynamicDescriptors(Uint64 FenceValue) -{ - for(size_t HeapType = 0; HeapType < _countof(m_DynamicGPUDescriptorAllocator); ++HeapType) - m_DynamicGPUDescriptorAllocator[HeapType].DiscardAllocations(FenceValue); -} - -DescriptorHeapAllocation CommandContext::AllocateDynamicGPUVisibleDescriptor( Vk_DESCRIPTOR_HEAP_TYPE Type, UINT Count ) -{ - VERIFY(Type >= Vk_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV && Type <= Vk_DESCRIPTOR_HEAP_TYPE_SAMPLER, "Invalid heap type"); - return m_DynamicGPUDescriptorAllocator[Type].Allocate(Count); -} - -#endif - -} -#endif \ No newline at end of file diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 9ff94d20..c4bc0753 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -27,7 +27,6 @@ #include "DeviceContextVkImpl.h" #include "SwapChainVk.h" #include "PipelineStateVkImpl.h" -#include "CommandContext.h" #include "TextureVkImpl.h" #include "BufferVkImpl.h" #include "VulkanTypeConversions.h" diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index a202c59c..16506cf8 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -29,7 +29,6 @@ #include "RenderDeviceVkImpl.h" #include "DeviceContextVkImpl.h" #include "ShaderResourceBindingVkImpl.h" -#include "CommandContext.h" #include "EngineMemory.h" #include "StringTools.h" -- cgit v1.2.3