summaryrefslogtreecommitdiffstats
path: root/unityplugin/UnityEmulator
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-10-07 02:19:50 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-10-07 02:19:50 +0000
commitef733fdbac35b6180964766b107f219eb41b1d75 (patch)
treeecd061c4bd7c25648496d5dce96894794530c851 /unityplugin/UnityEmulator
parentFixed compiler warnings (diff)
downloadDiligentEngine-ef733fdbac35b6180964766b107f219eb41b1d75.tar.gz
DiligentEngine-ef733fdbac35b6180964766b107f219eb41b1d75.zip
Updated submodules (main change: refactored release queues in D3D12 and Vulkan backends)
Diffstat (limited to 'unityplugin/UnityEmulator')
-rw-r--r--unityplugin/UnityEmulator/src/DiligentGraphicsAdapterD3D12.cpp24
-rw-r--r--unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp10
-rw-r--r--unityplugin/UnityEmulator/src/UnityGraphicsD3D12Impl.h2
3 files changed, 22 insertions, 14 deletions
diff --git a/unityplugin/UnityEmulator/src/DiligentGraphicsAdapterD3D12.cpp b/unityplugin/UnityEmulator/src/DiligentGraphicsAdapterD3D12.cpp
index 5cae5fa..1ef8671 100644
--- a/unityplugin/UnityEmulator/src/DiligentGraphicsAdapterD3D12.cpp
+++ b/unityplugin/UnityEmulator/src/DiligentGraphicsAdapterD3D12.cpp
@@ -1,4 +1,6 @@
+#include <array>
+
#define NOMINMAX
#include <D3D12.h>
#include <dxgi1_4.h>
@@ -38,13 +40,13 @@ public:
IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_CommandQueueD3D12, TBase )
// Returns the fence value that will be signaled next time
- virtual UINT64 GetNextFenceValue()override final
+ virtual Uint64 GetNextFenceValue()override final
{
return m_GraphicsD3D12Impl.GetNextFenceValue();
}
// Executes a given command list
- virtual UINT64 ExecuteCommandList(ID3D12GraphicsCommandList* commandList)override final
+ virtual Uint64 Submit(ID3D12GraphicsCommandList* commandList)override final
{
return m_GraphicsD3D12Impl.ExecuteCommandList(commandList);
}
@@ -56,18 +58,18 @@ public:
}
/// Returns value of the last completed fence
- virtual Uint64 GetCompletedFenceValue()
+ virtual Uint64 GetCompletedFenceValue()override final
{
return m_GraphicsD3D12Impl.GetCompletedFenceValue();
}
/// Blocks execution until all pending GPU commands are complete
- virtual void IdleGPU()
+ virtual Uint64 WaitForIdle()override final
{
- m_GraphicsD3D12Impl.IdleGPU();
+ return m_GraphicsD3D12Impl.IdleGPU();
}
- virtual void SignalFence(ID3D12Fence* pFence, Uint64 Value)
+ virtual void SignalFence(ID3D12Fence* pFence, Uint64 Value)override final
{
m_GraphicsD3D12Impl.GetCommandQueue()->Signal(pFence, Value);
}
@@ -203,7 +205,8 @@ DiligentGraphicsAdapterD3D12::DiligentGraphicsAdapterD3D12(UnityGraphicsD3D12Emu
auto *pFactoryD3D12 = GetEngineFactoryD3D12();
EngineD3D12Attribs Attribs;
- pFactoryD3D12->AttachToD3D12Device(d3d12Device, CmdQueue, Attribs, &m_pDevice, &m_pDeviceCtx, 0);
+ std::array<ICommandQueueD3D12*, 1> CmdQueues = {CmdQueue};
+ pFactoryD3D12->AttachToD3D12Device(d3d12Device, CmdQueues.size(), CmdQueues.data(), Attribs, &m_pDevice, &m_pDeviceCtx, 0);
}
void DiligentGraphicsAdapterD3D12::InitProxySwapChain()
@@ -223,11 +226,11 @@ void DiligentGraphicsAdapterD3D12::PreSwapChainResize()
auto *pDeviceD3D12 = m_pDevice.RawPtr<IRenderDeviceD3D12>();
pProxySwapChainD3D12->ReleaseBuffers();
auto *GraphicsImpl = m_UnityGraphicsD3D12.GetGraphicsImpl();
- pDeviceD3D12->FinishFrame();
+ pDeviceD3D12->ReleaseStaleResources();
// We must idle GPU
GraphicsImpl->IdleGPU();
// And call FinishFrame() to release references to swap chain resources
- pDeviceD3D12->FinishFrame();
+ pDeviceD3D12->ReleaseStaleResources();
}
void DiligentGraphicsAdapterD3D12::PostSwapChainResize()
@@ -259,8 +262,9 @@ void DiligentGraphicsAdapterD3D12::EndFrame()
pCtxD3D12->TransitionTextureState(pCurrentBackBuffer, D3D12_RESOURCE_STATE_RENDER_TARGET);
pCtxD3D12->TransitionTextureState(pDepthBuffer, D3D12_RESOURCE_STATE_DEPTH_WRITE);
m_pDeviceCtx->Flush();
+ m_pDeviceCtx->FinishFrame();
m_pDeviceCtx->InvalidateState();
- m_pDevice.RawPtr<IRenderDeviceD3D12>()->FinishFrame();
+ m_pDevice.RawPtr<IRenderDeviceD3D12>()->ReleaseStaleResources();
}
bool DiligentGraphicsAdapterD3D12::UsesReverseZ()
diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp b/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp
index 8d102d9..1bf35d6 100644
--- a/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp
+++ b/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp
@@ -383,7 +383,7 @@ bool UnityGraphicsD3D12Impl::IsFenceCompleted(UINT64 FenceValue)
return FenceValue <= m_CompletedFenceValue;
}
-void UnityGraphicsD3D12Impl::IdleGPU()
+UINT64 UnityGraphicsD3D12Impl::IdleGPU()
{
auto SignaledValue = m_NextFenceValue;
m_D3D12CmdQueue->Signal(m_D3D12FrameFence, SignaledValue);
@@ -395,12 +395,16 @@ void UnityGraphicsD3D12Impl::IdleGPU()
m_D3D12FrameFence->SetEventOnCompletion(SignaledValue, m_WaitForGPUEventHandle);
WaitForSingleObject(m_WaitForGPUEventHandle, INFINITE);
}
+ return SignaledValue;
}
UINT64 UnityGraphicsD3D12Impl::ExecuteCommandList(ID3D12CommandList *pCmdList)
{
- ID3D12CommandList *CmdLists[] = { pCmdList };
- m_D3D12CmdQueue->ExecuteCommandLists(1, CmdLists);
+ if (pCmdList != nullptr)
+ {
+ ID3D12CommandList *CmdLists[] = { pCmdList };
+ m_D3D12CmdQueue->ExecuteCommandLists(1, CmdLists);
+ }
auto FenceValue = m_NextFenceValue;
m_D3D12CmdQueue->Signal(m_D3D12FrameFence, m_NextFenceValue++);
return FenceValue;
diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Impl.h b/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Impl.h
index c969f0d..a5ad50b 100644
--- a/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Impl.h
+++ b/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Impl.h
@@ -33,7 +33,7 @@ public:
bool IsFenceCompleted(UINT64 FenceValue);
- void IdleGPU();
+ UINT64 IdleGPU();
IDXGISwapChain3* GetDXGISwapChain() { return m_SwapChain; }
ID3D12Resource* GetDepthBuffer() { return m_DepthStencilBuffer; }