From 7dfdbb54a778d4d9184037fdc74c85debd68011b Mon Sep 17 00:00:00 2001 From: Louis Bavoil Date: Fri, 30 Mar 2018 21:31:25 +0200 Subject: HBAO+ 4.0.0.23827312 --- include/GFSDK_SSAO.h | 10 ++-- lib/GFSDK_SSAO_D3D11.win32.dll | Bin 1039360 -> 1039360 bytes lib/GFSDK_SSAO_D3D11.win32.lib | Bin 2328 -> 2328 bytes lib/GFSDK_SSAO_D3D11.win64.dll | Bin 1181696 -> 1181696 bytes lib/GFSDK_SSAO_D3D11.win64.lib | Bin 2326 -> 2326 bytes lib/GFSDK_SSAO_D3D12.win32.dll | Bin 959488 -> 960000 bytes lib/GFSDK_SSAO_D3D12.win32.lib | Bin 2328 -> 2328 bytes lib/GFSDK_SSAO_D3D12.win64.dll | Bin 1065984 -> 1066496 bytes lib/GFSDK_SSAO_D3D12.win64.lib | Bin 2326 -> 2326 bytes samples/dual_layer/D3D12/src/DeviceManager12.cpp | 28 +++++----- samples/dual_layer/D3D12/src/DeviceManager12.h | 55 ++++++++++--------- samples/dual_layer/D3D12/src/HBAOSampleD3D12.cpp | 3 +- src/Common.h | 2 - src/Common_DX12.h | 2 +- src/Renderer_DX12.cpp | 64 +++++++++++++++++------ src/Renderer_DX12.h | 2 + 16 files changed, 101 insertions(+), 65 deletions(-) diff --git a/include/GFSDK_SSAO.h b/include/GFSDK_SSAO.h index 63a86f1..e228670 100644 --- a/include/GFSDK_SSAO.h +++ b/include/GFSDK_SSAO.h @@ -197,7 +197,7 @@ struct GFSDK_SSAO_Version : Major(4) , Minor(0) , Branch(0) - , Revision(23740451) + , Revision(23827312) { } @@ -231,7 +231,7 @@ enum GFSDK_SSAO_Status GFSDK_SSAO_D3D_RESOURCE_CREATION_FAILED, // A resource-creation call has failed (running out of memory?) GFSDK_SSAO_D3D12_UNSUPPORTED_DEPTH_CLAMP_MODE, // CLAMP_TO_BORDER is used (implemented on D3D11 & GL, but not on D3D12) GFSDK_SSAO_D3D12_INVALID_HEAP_TYPE, // One of the heaps provided to GFSDK_SSAO_CreateContext_D3D12 has an unexpected type - GFSDK_SSAO_D3D12_INSUFFICIENT_DESCRIPTORS, // One of the heaps provided to GFSDK_SSAO_CreateContext_D3D12 has insufficient descriptors + GFSDK_SSAO_D3D12_INSUFFICIENT_DESCRIPTORS, // One of the heaps provided to GFSDK_SSAO_CreateContext_D3D12 has an insufficient number of descriptors GFSDK_SSAO_D3D12_INVALID_NODE_MASK, // NodeMask has more than one bit set. HBAO+ only supports operation on one D3D12 device node. GFSDK_SSAO_NO_SECOND_LAYER_PROVIDED // FullResDepthTexture2ndLayerSRV is not set, but DualLayerAO is enabled. }; @@ -911,6 +911,8 @@ public: // Remarks: // * Allocates internal D3D render targets on first use, and re-allocates them when the viewport dimensions change. // * Setting RenderMask = GFSDK_SSAO_RENDER_DEBUG_NORMAL_Z can be useful to visualize the normals used for the AO rendering. + // * The input depth & normal textures are assumed to have state D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE. + // * The output AO render target is assumed to have state D3D12_RESOURCE_STATE_RENDER_TARGET. // // Returns: // GFSDK_SSAO_NULL_ARGUMENT - One of the required argument pointers is NULL @@ -986,12 +988,10 @@ struct GFSDK_SSAO_DescriptorHeapRange_D3D12 { ID3D12DescriptorHeap* pDescHeap; // Pointer to the descriptor heap GFSDK_SSAO_UINT BaseIndex; // The base index that can be used as a start index of the pDescHeap - GFSDK_SSAO_UINT NumDescriptors; // The maximum number of descriptors that are allowed to be used in the library GFSDK_SSAO_DescriptorHeapRange_D3D12() : pDescHeap(NULL) , BaseIndex(0) - , NumDescriptors(0) { } }; @@ -1016,7 +1016,7 @@ struct GFSDK_SSAO_DescriptorHeaps_D3D12 // GFSDK_SSAO_D3D_FEATURE_LEVEL_NOT_SUPPORTED - The D3D feature level of pD3DDevice is lower than 11_0 // GFSDK_SSAO_D3D_RESOURCE_CREATION_FAILED - A resource-creation call has failed (running out of memory?) // GFSDK_SSAO_D3D12_INVALID_HEAP_TYPE - One of the heaps provided to GFSDK_SSAO_CreateContext_D3D12 has an unexpected type -// GFSDK_SSAO_D3D12_INSUFFICIENT_DESCRIPTORS - One of the heaps described in pHeapInfo has insufficient descriptors +// GFSDK_SSAO_D3D12_INSUFFICIENT_DESCRIPTORS - One of the heaps described in pHeapInfo has an insufficient number of descriptors // GFSDK_SSAO_D3D12_INVALID_NODE_MASK - NodeMask has more than one bit set, or is zero // GFSDK_SSAO_OK - Success //--------------------------------------------------------------------------------------------------- diff --git a/lib/GFSDK_SSAO_D3D11.win32.dll b/lib/GFSDK_SSAO_D3D11.win32.dll index 940dde2..297cba4 100644 Binary files a/lib/GFSDK_SSAO_D3D11.win32.dll and b/lib/GFSDK_SSAO_D3D11.win32.dll differ diff --git a/lib/GFSDK_SSAO_D3D11.win32.lib b/lib/GFSDK_SSAO_D3D11.win32.lib index 9a65205..18c0217 100644 Binary files a/lib/GFSDK_SSAO_D3D11.win32.lib and b/lib/GFSDK_SSAO_D3D11.win32.lib differ diff --git a/lib/GFSDK_SSAO_D3D11.win64.dll b/lib/GFSDK_SSAO_D3D11.win64.dll index f62678b..d2b6e1f 100644 Binary files a/lib/GFSDK_SSAO_D3D11.win64.dll and b/lib/GFSDK_SSAO_D3D11.win64.dll differ diff --git a/lib/GFSDK_SSAO_D3D11.win64.lib b/lib/GFSDK_SSAO_D3D11.win64.lib index 2d5ff5d..e4c5b0c 100644 Binary files a/lib/GFSDK_SSAO_D3D11.win64.lib and b/lib/GFSDK_SSAO_D3D11.win64.lib differ diff --git a/lib/GFSDK_SSAO_D3D12.win32.dll b/lib/GFSDK_SSAO_D3D12.win32.dll index af6bea6..9546dda 100644 Binary files a/lib/GFSDK_SSAO_D3D12.win32.dll and b/lib/GFSDK_SSAO_D3D12.win32.dll differ diff --git a/lib/GFSDK_SSAO_D3D12.win32.lib b/lib/GFSDK_SSAO_D3D12.win32.lib index 0756f0f..df020bd 100644 Binary files a/lib/GFSDK_SSAO_D3D12.win32.lib and b/lib/GFSDK_SSAO_D3D12.win32.lib differ diff --git a/lib/GFSDK_SSAO_D3D12.win64.dll b/lib/GFSDK_SSAO_D3D12.win64.dll index c524465..aeaf14e 100644 Binary files a/lib/GFSDK_SSAO_D3D12.win64.dll and b/lib/GFSDK_SSAO_D3D12.win64.dll differ diff --git a/lib/GFSDK_SSAO_D3D12.win64.lib b/lib/GFSDK_SSAO_D3D12.win64.lib index c0429a5..bfbbd87 100644 Binary files a/lib/GFSDK_SSAO_D3D12.win64.lib and b/lib/GFSDK_SSAO_D3D12.win64.lib differ diff --git a/samples/dual_layer/D3D12/src/DeviceManager12.cpp b/samples/dual_layer/D3D12/src/DeviceManager12.cpp index 85c99ff..7e847a9 100644 --- a/samples/dual_layer/D3D12/src/DeviceManager12.cpp +++ b/samples/dual_layer/D3D12/src/DeviceManager12.cpp @@ -216,6 +216,11 @@ DeviceManager::CreateWindowDeviceAndSwapChain(const DeviceCreationParameters& pa for(UINT bufferIndex = 0; bufferIndex < m_SwapChainDesc.BufferCount; bufferIndex++) { m_FrameFenceEvents.push_back( CreateEvent(NULL, false, true, NULL) ); + + ID3D12CommandAllocator* commandAllocator = nullptr; + m_Device12->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&commandAllocator)); + + m_CommandAllocators.push_back(commandAllocator); } DeviceCreated(); @@ -245,7 +250,9 @@ DeviceManager::Shutdown() SAFE_RELEASE(m_FrameFence); - SAFE_RELEASE(m_DefaultCommandAllocator); + for (auto& commandAllocator : m_CommandAllocators) + SAFE_RELEASE(commandAllocator); + SAFE_RELEASE(m_PreRenderCommandList); SAFE_RELEASE(m_PostRenderCommandList); @@ -288,19 +295,20 @@ HRESULT DeviceManager::CreatePrePostRenderCommandLists() { HRESULT hr; - if (!m_DefaultCommandAllocator) + ID3D12CommandAllocator* commandAllocator = m_CommandAllocators[m_BufferIndex]; + + if (commandAllocator) { - hr = m_Device12->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_DefaultCommandAllocator)); - HR_RETURN(hr); + commandAllocator->Reset(); } if (!m_PreRenderCommandList) { - hr = m_Device12->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_DefaultCommandAllocator, NULL, IID_PPV_ARGS(&m_PreRenderCommandList)); + hr = m_Device12->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, commandAllocator, NULL, IID_PPV_ARGS(&m_PreRenderCommandList)); HR_RETURN(hr); } else - m_PreRenderCommandList->Reset(m_DefaultCommandAllocator, nullptr); + m_PreRenderCommandList->Reset(commandAllocator, nullptr); SetResourceBarrier(m_PreRenderCommandList, m_SwapChainBuffers[m_BufferIndex], D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET); if(m_EnableRenderTargetClear) @@ -312,11 +320,11 @@ HRESULT DeviceManager::CreatePrePostRenderCommandLists() if (!m_PostRenderCommandList) { - hr = m_Device12->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_DefaultCommandAllocator, NULL, IID_PPV_ARGS(&m_PostRenderCommandList)); + hr = m_Device12->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, commandAllocator, NULL, IID_PPV_ARGS(&m_PostRenderCommandList)); HR_RETURN(hr); } else - m_PostRenderCommandList->Reset(m_DefaultCommandAllocator, nullptr); + m_PostRenderCommandList->Reset(commandAllocator, nullptr); SetResourceBarrier(m_PostRenderCommandList, m_SwapChainBuffers[m_BufferIndex], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT); m_PostRenderCommandList->Close(); @@ -425,10 +433,6 @@ DeviceManager::MessageLoop() { m_AverageFrameTime = timeSum / (double)m_vFrameTimes.size(); m_vFrameTimes.clear(); - - //char buf[256]; - //sprintf_s(buf, "Average FPS: %.2f\n", 1.f / m_AverageFrameTime); - //OutputDebugStringA(buf); } } diff --git a/samples/dual_layer/D3D12/src/DeviceManager12.h b/samples/dual_layer/D3D12/src/DeviceManager12.h index 595e60d..e4b1e37 100644 --- a/samples/dual_layer/D3D12/src/DeviceManager12.h +++ b/samples/dual_layer/D3D12/src/DeviceManager12.h @@ -99,34 +99,34 @@ public: }; protected: - ID3D12Device* m_Device12; - ID3D12CommandQueue* m_DefaultQueue; - IDXGISwapChain3* m_SwapChain; - DXGI_SWAP_CHAIN_DESC1 m_SwapChainDesc; - DXGI_SWAP_CHAIN_FULLSCREEN_DESC m_FullScreenDesc; - ID3D12CommandAllocator* m_DefaultCommandAllocator; - ID3D12GraphicsCommandList* m_PreRenderCommandList; - ID3D12GraphicsCommandList* m_PostRenderCommandList; - ID3D12DescriptorHeap* m_DescHeapRTV; - IDXGIAdapter* m_DxgiAdapter; - HWND m_hWnd; - std::list m_vControllers; - std::wstring m_WindowTitle; - double m_FixedFrameInterval; - UINT m_SyncInterval; - std::list m_vFrameTimes; - double m_AverageFrameTime; - double m_AverageTimeUpdateInterval; - bool m_InSizingModalLoop; - SIZE m_NewWindowSize; - std::vector m_SwapChainBuffers; + ID3D12Device* m_Device12; + ID3D12CommandQueue* m_DefaultQueue; + IDXGISwapChain3* m_SwapChain; + DXGI_SWAP_CHAIN_DESC1 m_SwapChainDesc; + DXGI_SWAP_CHAIN_FULLSCREEN_DESC m_FullScreenDesc; + std::vector m_CommandAllocators; + ID3D12GraphicsCommandList* m_PreRenderCommandList; + ID3D12GraphicsCommandList* m_PostRenderCommandList; + ID3D12DescriptorHeap* m_DescHeapRTV; + IDXGIAdapter* m_DxgiAdapter; + HWND m_hWnd; + std::list m_vControllers; + std::wstring m_WindowTitle; + double m_FixedFrameInterval; + UINT m_SyncInterval; + std::list m_vFrameTimes; + double m_AverageFrameTime; + double m_AverageTimeUpdateInterval; + bool m_InSizingModalLoop; + SIZE m_NewWindowSize; + std::vector m_SwapChainBuffers; std::vector m_SwapChainRTVs; - ID3D12Fence* m_FrameFence; - std::vector m_FrameFenceEvents; - int m_BufferIndex; - UINT64 m_FrameCount; - bool m_EnableRenderTargetClear; - float m_RenderTargetClearColor[4]; + ID3D12Fence* m_FrameFence; + std::vector m_FrameFenceEvents; + int m_BufferIndex; + UINT64 m_FrameCount; + bool m_EnableRenderTargetClear; + float m_RenderTargetClearColor[4]; private: HRESULT CreateRenderTargets(); HRESULT CreatePrePostRenderCommandLists(); @@ -146,7 +146,6 @@ public: , m_SyncInterval(0) , m_AverageFrameTime(0) , m_AverageTimeUpdateInterval(0.5) - , m_DefaultCommandAllocator(NULL) , m_PreRenderCommandList(NULL) , m_PostRenderCommandList(NULL) , m_DescHeapRTV(NULL) diff --git a/samples/dual_layer/D3D12/src/HBAOSampleD3D12.cpp b/samples/dual_layer/D3D12/src/HBAOSampleD3D12.cpp index cf10894..d5ce0d1 100644 --- a/samples/dual_layer/D3D12/src/HBAOSampleD3D12.cpp +++ b/samples/dual_layer/D3D12/src/HBAOSampleD3D12.cpp @@ -43,6 +43,7 @@ void HBAOSampleD3D12::Initialize() deviceParams.windowPosY = 0; mDeviceManager.CreateWindowDeviceAndSwapChain(deviceParams, L"HBAO+ D3D12 Sample"); + mDeviceManager.SetPrimaryRenderTargetClearColor(false, nullptr); mDeviceManager.AddControllerToBack(this); @@ -210,11 +211,9 @@ bool HBAOSampleD3D12::InitializeHBAOPlus() DescriptorHeaps.CBV_SRV_UAV.pDescHeap = mSSAODescriptorHeapCBVSRVUAV.Get(); DescriptorHeaps.CBV_SRV_UAV.BaseIndex = kNumTotalAppDescriptors; - DescriptorHeaps.CBV_SRV_UAV.NumDescriptors = GFSDK_SSAO_NUM_DESCRIPTORS_CBV_SRV_UAV_HEAP_D3D12; DescriptorHeaps.RTV.pDescHeap = mSSAODescriptorHeapRTV.Get(); DescriptorHeaps.RTV.BaseIndex = 0; - DescriptorHeaps.RTV.NumDescriptors = GFSDK_SSAO_NUM_DESCRIPTORS_RTV_HEAP_D3D12; GFSDK_SSAO_Status status = GFSDK_SSAO_CreateContext_D3D12(mDevice, NodeMask, DescriptorHeaps, &mSSAOContext, &CustomHeap); assert(status == GFSDK_SSAO_OK); diff --git a/src/Common.h b/src/Common.h index 30be88d..59030a8 100644 --- a/src/Common.h +++ b/src/Common.h @@ -23,10 +23,8 @@ #if _DEBUG #define ASSERT(exp) assert(exp) -#define ASSERT_GL_ERROR(GL) assert(!GL.glGetError()) #else #define ASSERT(exp) ((void)0) -#define ASSERT_GL_ERROR(GL) #endif #ifndef ANDROID diff --git a/src/Common_DX12.h b/src/Common_DX12.h index 17dbe83..945d3ce 100644 --- a/src/Common_DX12.h +++ b/src/Common_DX12.h @@ -68,7 +68,7 @@ struct GFSDK_D3D12_DescriptorHeap void InitDescriptorHeap(ID3D12Device* pDevice, D3D12_DESCRIPTOR_HEAP_TYPE HeapType, const GFSDK_SSAO_DescriptorHeapRange_D3D12* pHeapInfo, bool bShaderVisible) { - NumDescriptors = pHeapInfo->NumDescriptors; + NumDescriptors = pHeapInfo->pDescHeap->GetDesc().NumDescriptors; pDescHeap = pHeapInfo->pDescHeap; BaseIndex = pHeapInfo->BaseIndex; diff --git a/src/Renderer_DX12.cpp b/src/Renderer_DX12.cpp index 5fb4ea5..573350e 100644 --- a/src/Renderer_DX12.cpp +++ b/src/Renderer_DX12.cpp @@ -78,6 +78,52 @@ void GFSDK::SSAO::D3D12::Renderer::ReleaseResources() m_RTs.Release(); } +//-------------------------------------------------------------------------------- +GFSDK_SSAO_Status GFSDK::SSAO::D3D12::Renderer::ValidateDescriptorHeap( + const GFSDK_SSAO_DescriptorHeapRange_D3D12& DescHeapRange, + D3D12_DESCRIPTOR_HEAP_TYPE RequiredHeapType, + UINT RequiredNumDescriptors) +{ + if (!DescHeapRange.pDescHeap) + { + return GFSDK_SSAO_NULL_ARGUMENT; + } + + D3D12_DESCRIPTOR_HEAP_DESC HeapDesc = DescHeapRange.pDescHeap->GetDesc(); + + if (HeapDesc.Type != RequiredHeapType) + { + return GFSDK_SSAO_D3D12_INVALID_HEAP_TYPE; + } + + if (HeapDesc.NumDescriptors < DescHeapRange.BaseIndex + RequiredNumDescriptors) + { + return GFSDK_SSAO_D3D12_INSUFFICIENT_DESCRIPTORS; + } + + return GFSDK_SSAO_OK; +} + +//-------------------------------------------------------------------------------- +GFSDK_SSAO_Status GFSDK::SSAO::D3D12::Renderer::ValidateDescriptorHeaps(const GFSDK_SSAO_DescriptorHeaps_D3D12& DescriptorHeaps) +{ + GFSDK_SSAO_Status Status; + + Status = ValidateDescriptorHeap(DescriptorHeaps.CBV_SRV_UAV, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, CBVSRVUAVLayoutBase::eCBVSRVUAVLayoutBaseMax); + if (Status != GFSDK_SSAO_OK) + { + return Status; + } + + Status = ValidateDescriptorHeap(DescriptorHeaps.RTV, D3D12_DESCRIPTOR_HEAP_TYPE_RTV, RTVLayoutBase::eRTVLayoutBaseMax); + if (Status != GFSDK_SSAO_OK) + { + return Status; + } + + return GFSDK_SSAO_OK; +} + //-------------------------------------------------------------------------------- GFSDK_SSAO_Status GFSDK::SSAO::D3D12::Renderer::Create( ID3D12Device* pDevice, @@ -107,22 +153,10 @@ GFSDK_SSAO_Status GFSDK::SSAO::D3D12::Renderer::Create( return GFSDK_SSAO_D3D12_INVALID_NODE_MASK; } - if (!DescriptorHeaps.CBV_SRV_UAV.pDescHeap || - !DescriptorHeaps.RTV.pDescHeap) - { - return GFSDK_SSAO_NULL_ARGUMENT; - } - - if (DescriptorHeaps.CBV_SRV_UAV.pDescHeap->GetDesc().Type != D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV || - DescriptorHeaps.RTV.pDescHeap->GetDesc().Type != D3D12_DESCRIPTOR_HEAP_TYPE_RTV) - { - return GFSDK_SSAO_D3D12_INVALID_HEAP_TYPE; - } - - if (DescriptorHeaps.CBV_SRV_UAV.NumDescriptors < GFSDK_SSAO_NUM_DESCRIPTORS_CBV_SRV_UAV_HEAP_D3D12 || - DescriptorHeaps.RTV.NumDescriptors < GFSDK_SSAO_NUM_DESCRIPTORS_RTV_HEAP_D3D12) + GFSDK_SSAO_Status Status = ValidateDescriptorHeaps(DescriptorHeaps); + if (Status != GFSDK_SSAO_OK) { - return GFSDK_SSAO_D3D12_INSUFFICIENT_DESCRIPTORS; + return Status; } m_GraphicsContext.Init(pDevice, DescriptorHeaps, NodeMask); diff --git a/src/Renderer_DX12.h b/src/Renderer_DX12.h index fa2100d..88d8e41 100644 --- a/src/Renderer_DX12.h +++ b/src/Renderer_DX12.h @@ -144,6 +144,8 @@ private: GFSDK_SSAO_Status SetAOParameters(const GFSDK_SSAO_Parameters& Parameters); GFSDK_SSAO_Status SetOutput(const GFSDK_SSAO_Output_D3D12& Output); GFSDK_SSAO_Status ValidateDataFlow(); + GFSDK_SSAO_Status ValidateDescriptorHeap(const GFSDK_SSAO_DescriptorHeapRange_D3D12& DescHeapRange, D3D12_DESCRIPTOR_HEAP_TYPE RequiredHeapType, UINT RequiredNumDescriptors); + GFSDK_SSAO_Status ValidateDescriptorHeaps(const GFSDK_SSAO_DescriptorHeaps_D3D12& DescriptorHeaps); void DrawLinearDepthPS(GFSDK_D3D12_GraphicsContext* pGraphicsContext); void DrawDeinterleavedDepthPS(GFSDK_D3D12_GraphicsContext* pGraphicsContext); -- cgit v1.2.3