diff options
| author | Miles Macklin <[email protected]> | 2017-07-05 12:59:25 +1200 |
|---|---|---|
| committer | Miles Macklin <[email protected]> | 2017-07-05 12:59:25 +1200 |
| commit | 7f669cec7c812a366eedaf0cdfe09d6a5bad84af (patch) | |
| tree | 5744216f9f88788c88f07a69ad11a43d232c95f9 /demo/d3d12 | |
| parent | 1.2.0.beta.1 (diff) | |
| download | flex-7f669cec7c812a366eedaf0cdfe09d6a5bad84af.tar.xz flex-7f669cec7c812a366eedaf0cdfe09d6a5bad84af.zip | |
Flex 1.2 (beta 2)
Diffstat (limited to 'demo/d3d12')
| -rw-r--r-- | demo/d3d12/appD3D12Ctx.cpp | 10 | ||||
| -rw-r--r-- | demo/d3d12/demoContextD3D12.cpp | 52 | ||||
| -rw-r--r-- | demo/d3d12/demoContextD3D12.h | 12 |
3 files changed, 53 insertions, 21 deletions
diff --git a/demo/d3d12/appD3D12Ctx.cpp b/demo/d3d12/appD3D12Ctx.cpp index 944453a..82aa56a 100644 --- a/demo/d3d12/appD3D12Ctx.cpp +++ b/demo/d3d12/appD3D12Ctx.cpp @@ -310,7 +310,7 @@ void AppGraphCtxInitRenderTargetD3D12(AppGraphCtx* contextIn, SDL_Window* window hr = pFactory->CreateSwapChain(context->m_commandQueue, &desc, (IDXGISwapChain**)&context->m_swapChain); - if(hr != S_OK) + if (hr != S_OK) { COMRelease(context->m_swapChain); context->m_fullscreen = false; @@ -378,7 +378,7 @@ void AppGraphCtxInitRenderTargetD3D12(AppGraphCtx* contextIn, SDL_Window* window D3D12_RESOURCE_DESC desc = backBuffer->GetDesc(); DXGI_FORMAT resourceFormat; - + if (desc.Format == DXGI_FORMAT_R32_FLOAT || desc.Format == DXGI_FORMAT_D32_FLOAT) { resourceFormat = DXGI_FORMAT_R32_TYPELESS; @@ -449,7 +449,7 @@ void AppGraphCtxInitRenderTargetD3D12(AppGraphCtx* contextIn, SDL_Window* window D3D12_RESOURCE_STATE_DEPTH_WRITE, &clearValue, IID_PPV_ARGS(&context->m_depthStencil) - )) + )) { return; } @@ -457,7 +457,7 @@ void AppGraphCtxInitRenderTargetD3D12(AppGraphCtx* contextIn, SDL_Window* window // create the depth stencil view D3D12_DEPTH_STENCIL_VIEW_DESC viewDesc = {}; viewDesc.Format = context->m_dsv_format; // DXGI_FORMAT_D32_FLOAT; - viewDesc.ViewDimension = (context->m_numMsaaSamples>1) ? D3D12_DSV_DIMENSION_TEXTURE2DMS : D3D12_DSV_DIMENSION_TEXTURE2D; + viewDesc.ViewDimension = (context->m_numMsaaSamples > 1) ? D3D12_DSV_DIMENSION_TEXTURE2DMS : D3D12_DSV_DIMENSION_TEXTURE2D; viewDesc.Flags = D3D12_DSV_FLAG_NONE; viewDesc.Texture2D.MipSlice = 0; @@ -621,8 +621,10 @@ void AppGraphCtxFramePresentD3D12(AppGraphCtx* contextIn, bool fullsync) auto context = cast_to_AppGraphCtxD3D12(contextIn); // check if now is good time to present +#if 0 // disable frame latency waitable object check because it will cause vsync to fail bool shouldPresent = context->m_fullscreen ? true : WaitForSingleObjectEx(context->m_swapChainWaitableObject, 0, TRUE) != WAIT_TIMEOUT; if (shouldPresent) +#endif { context->m_swapChain->Present(fullsync, 0); context->m_renderTargetID++; diff --git a/demo/d3d12/demoContextD3D12.cpp b/demo/d3d12/demoContextD3D12.cpp index 8a698f7..110aea1 100644 --- a/demo/d3d12/demoContextD3D12.cpp +++ b/demo/d3d12/demoContextD3D12.cpp @@ -74,11 +74,42 @@ DemoContextD3D12::DemoContextD3D12() // Allocate space for all debug vertices m_debugLineVertices.resize(MAX_DEBUG_LINE_SIZE); + + m_renderStateManager = new RenderStateManagerD3D12; +} + +template <class T> +void inline COMRelease(T& t) +{ + if (t) t->Release(); + t = nullptr; } DemoContextD3D12::~DemoContextD3D12() { imguiGraphDestroy(); + + AppGraphCtxRelease(m_appGraphCtx); + + delete m_renderStateManager; + + COMRelease(m_graphicsCompleteFence); + COMRelease(m_queryHeap); + COMRelease(m_queryResults); + + // Explicitly delete these, so we can call D3D memory leak checker at bottom of this destructor + m_meshPipeline.reset(); + m_pointPipeline.reset(); + m_fluidPointPipeline.reset(); + m_fluidSmoothPipeline.reset(); + m_fluidCompositePipeline.reset(); + m_diffusePointPipeline.reset(); + m_linePipeline.reset(); + m_fluidPointRenderTarget.reset(); + m_fluidSmoothRenderTarget.reset(); + m_fluidResolvedTarget.reset(); + m_screenQuadMesh.reset(); + m_shadowMap.reset(); } bool DemoContextD3D12::initialize(const RenderInitOptions& options) @@ -183,8 +214,8 @@ int DemoContextD3D12::_initRenderResources(const RenderInitOptions& options) { // Make enough space for largest _single_ dynamic buffer allocation - NV_RETURN_ON_FAIL(m_renderStateManager.initialize(renderContext, 16 * 1024 * 1024)); - m_renderState = m_renderStateManager.getState(); + NV_RETURN_ON_FAIL(m_renderStateManager->initialize(renderContext, 16 * 1024 * 1024)); + m_renderState = m_renderStateManager->getState(); } // Create the renderer @@ -465,7 +496,7 @@ void DemoContextD3D12::startFrame(FlexVec4 colorIn) AppGraphCtxD3D12* renderContext = getRenderContext(); // Work out what what can be recovered, as GPU no longer accessing - m_renderStateManager.updateCompleted(); + m_renderStateManager->updateCompleted(); AppGraphColor clearColor = { colorIn.x, colorIn.y, colorIn.z, colorIn.w }; AppGraphCtxFrameStart(cast_from_AppGraphCtxD3D12(renderContext), clearColor); @@ -529,11 +560,11 @@ void DemoContextD3D12::endFrame() renderContext->m_commandListOpenCount = 0; // Inform the manager that the work has been submitted - m_renderStateManager.onGpuWorkSubmitted(renderContext->m_commandQueue); + m_renderStateManager->onGpuWorkSubmitted(renderContext->m_commandQueue); HANDLE completeEvent = m_graphicsCompleteEvent; - renderContext->m_commandQueue->Signal(m_graphicsCompleteFence.Get(), m_graphicsCompleteFenceValue); + renderContext->m_commandQueue->Signal(m_graphicsCompleteFence, m_graphicsCompleteFenceValue); } void DemoContextD3D12::getRenderDevice(void** device, void** context) @@ -1060,15 +1091,15 @@ void DemoContextD3D12::graphicsTimerBegin() { ID3D12GraphicsCommandList* commandList = m_renderContext->m_commandList; - commandList->EndQuery(m_queryHeap.Get(), D3D12_QUERY_TYPE_TIMESTAMP, 0); + commandList->EndQuery(m_queryHeap, D3D12_QUERY_TYPE_TIMESTAMP, 0); } void DemoContextD3D12::graphicsTimerEnd() { ID3D12GraphicsCommandList* commandList = m_renderContext->m_commandList; - commandList->EndQuery(m_queryHeap.Get(), D3D12_QUERY_TYPE_TIMESTAMP, 1); - commandList->ResolveQueryData(m_queryHeap.Get(), D3D12_QUERY_TYPE_TIMESTAMP, 0, 2, m_queryResults.Get(), 0); + commandList->EndQuery(m_queryHeap, D3D12_QUERY_TYPE_TIMESTAMP, 1); + commandList->ResolveQueryData(m_queryHeap, D3D12_QUERY_TYPE_TIMESTAMP, 0, 2, m_queryResults, 0); } float DemoContextD3D12::rendererGetDeviceTimestamps(unsigned long long* begin, unsigned long long* end, unsigned long long* freq) @@ -1086,10 +1117,9 @@ float DemoContextD3D12::rendererGetDeviceTimestamps(unsigned long long* begin, u commandQueue->GetTimestampFrequency(&frequency); } - //Get render timestamps + // Get render timestamps uint64_t* times; - //m_queryResults->Map(0, nullptr, (void**)×); - D3D12_RANGE readRange = { 0, 1 }; + D3D12_RANGE readRange = { 0, 2 }; m_queryResults->Map(0, &readRange, (void**)×); uint64_t renderBegin = times[0]; uint64_t renderEnd = times[1]; diff --git a/demo/d3d12/demoContextD3D12.h b/demo/d3d12/demoContextD3D12.h index 5f43c31..894cb0d 100644 --- a/demo/d3d12/demoContextD3D12.h +++ b/demo/d3d12/demoContextD3D12.h @@ -232,7 +232,7 @@ public: std::wstring m_executablePath; std::wstring m_shadersPath; - RenderStateManagerD3D12 m_renderStateManager; + RenderStateManagerD3D12* m_renderStateManager; RenderStateD3D12 m_renderState; SDL_Window* m_window; @@ -241,11 +241,11 @@ public: int m_msaaSamples; // Synchronization and timing for async compute benchmarking - ComPtr<ID3D12Fence> m_graphicsCompleteFence; - HANDLE m_graphicsCompleteEvent; - UINT64 m_graphicsCompleteFenceValue; - ComPtr<ID3D12QueryHeap> m_queryHeap; - ComPtr<ID3D12Resource> m_queryResults; + ID3D12Fence* m_graphicsCompleteFence; + HANDLE m_graphicsCompleteEvent; + UINT64 m_graphicsCompleteFenceValue; + ID3D12QueryHeap* m_queryHeap; + ID3D12Resource* m_queryResults; bool m_inLineDraw; std::vector<LineData::Vertex> m_debugLineVertices; |