2020#include " stdafx.h"
2121
2222#include " SampleRenderer.h"
23+ #include " base\\SaveTexture.h"
24+
2325
2426// --------------------------------------------------------------------------------------
2527//
@@ -33,7 +35,7 @@ void SampleRenderer::OnCreate(Device* pDevice, SwapChain *pSwapChain)
3335 // Initialize helpers
3436
3537 // Create all the heaps for the resources views
36- const uint32_t cbvDescriptorCount = 2000 ;
38+ const uint32_t cbvDescriptorCount = 4000 ;
3739 const uint32_t srvDescriptorCount = 8000 ;
3840 const uint32_t uavDescriptorCount = 10 ;
3941 const uint32_t dsvDescriptorCount = 10 ;
@@ -46,7 +48,7 @@ void SampleRenderer::OnCreate(Device* pDevice, SwapChain *pSwapChain)
4648 m_CommandListRing.OnCreate (pDevice, backBufferCount, commandListsPerBackBuffer, pDevice->GetGraphicsQueue ()->GetDesc ());
4749
4850 // Create a 'dynamic' constant buffer
49- const uint32_t constantBuffersMemSize = 20 * 1024 * 1024 ;
51+ const uint32_t constantBuffersMemSize = 200 * 1024 * 1024 ;
5052 m_ConstantBufferRing.OnCreate (pDevice, backBufferCount, constantBuffersMemSize, &m_resourceViewHeaps);
5153
5254 // Create a 'static' pool for vertices, indices and constant buffers
@@ -294,6 +296,9 @@ int SampleRenderer::LoadScene(GLTFCommon *pGLTFCommon, int stage)
294296 ImGui::EndPopup ();
295297 }
296298
299+ // use multithreading
300+ AsyncPool *pAsyncPool = &m_asyncPool;
301+
297302 // Loading stages
298303 //
299304 if (stage == 0 )
@@ -312,7 +317,7 @@ int SampleRenderer::LoadScene(GLTFCommon *pGLTFCommon, int stage)
312317
313318 // here we are loading onto the GPU all the textures and the inverse matrices
314319 // this data will be used to create the PBR and Depth passes
315- m_pGLTFTexturesAndBuffers->LoadTextures ();
320+ m_pGLTFTexturesAndBuffers->LoadTextures (pAsyncPool );
316321 }
317322 else if (stage == 7 )
318323 {
@@ -326,7 +331,8 @@ int SampleRenderer::LoadScene(GLTFCommon *pGLTFCommon, int stage)
326331 &m_resourceViewHeaps,
327332 &m_ConstantBufferRing,
328333 &m_VidMemBufferPool,
329- m_pGLTFTexturesAndBuffers
334+ m_pGLTFTexturesAndBuffers,
335+ pAsyncPool
330336 );
331337 }
332338 else if (stage == 8 )
@@ -342,7 +348,8 @@ int SampleRenderer::LoadScene(GLTFCommon *pGLTFCommon, int stage)
342348 &m_VidMemBufferPool,
343349 m_pGLTFTexturesAndBuffers,
344350 m_MotionVectors.GetFormat (),
345- m_NormalBuffer.GetFormat ()
351+ m_NormalBuffer.GetFormat (),
352+ pAsyncPool
346353 );
347354 }
348355 else if (stage == 9 )
@@ -359,13 +366,16 @@ int SampleRenderer::LoadScene(GLTFCommon *pGLTFCommon, int stage)
359366 &m_VidMemBufferPool,
360367 m_pGLTFTexturesAndBuffers,
361368 &m_skyDome,
369+ false , // use a SSAO mask
362370 USE_SHADOWMASK,
363371 m_HDRMSAA.GetFormat (), // forward pass channel
364372 DXGI_FORMAT_UNKNOWN, // specular-roughness channel
365373 DXGI_FORMAT_UNKNOWN, // diffuse channel
366374 DXGI_FORMAT_UNKNOWN, // normal channel
367- 4
375+ 4 ,
376+ pAsyncPool
368377 );
378+
369379 }
370380 else if (stage == 10 )
371381 {
@@ -466,6 +476,7 @@ void SampleRenderer::OnRender(State *pState, SwapChain *pSwapChain)
466476
467477 // Let our resource managers do some house keeping
468478 //
479+ m_CommandListRing.OnBeginFrame ();
469480 m_ConstantBufferRing.OnBeginFrame ();
470481 m_GPUTimer.OnBeginFrame (gpuTicksPerSecond, &m_TimeStamps);
471482
@@ -481,13 +492,15 @@ void SampleRenderer::OnRender(State *pState, SwapChain *pSwapChain)
481492 //
482493 per_frame *pPerFrame = NULL ;
483494 if (m_pGLTFTexturesAndBuffers)
484- {
495+ {
485496 // fill as much as possible using the GLTF (camera, lights, ...)
486497 pPerFrame = m_pGLTFTexturesAndBuffers->m_pGLTFCommon ->SetPerFrameData (pState->camera );
487498
488499 // Set some lighting factors
489500 pPerFrame->iblFactor = pState->iblFactor ;
490501 pPerFrame->emmisiveFactor = pState->emmisiveFactor ;
502+ pPerFrame->invScreenResolution [0 ] = 1 .0f / ((float )m_Width);
503+ pPerFrame->invScreenResolution [1 ] = 1 .0f / ((float )m_Height);
491504
492505 // Set shadowmaps bias and an index that indicates the rectangle of the atlas in which depth will be rendered
493506 uint32_t shadowMapIndex = 0 ;
@@ -562,6 +575,7 @@ void SampleRenderer::OnRender(State *pState, SwapChain *pSwapChain)
562575 shadowMapIndex++;
563576 }
564577 }
578+
565579 pCmdLst1->ResourceBarrier (1 , &CD3DX12_RESOURCE_BARRIER::Transition (m_shadowMap.GetResource (), D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));
566580
567581 // Motion vectors ---------------------------------------------------------------------------
@@ -781,7 +795,7 @@ void SampleRenderer::OnRender(State *pState, SwapChain *pSwapChain)
781795 pCmdLst1->ResourceBarrier (ARRAYSIZE (postSharpen), postSharpen);
782796 }
783797
784- // If using FreeSync2 we need to to the tonemapping in-place and then apply the GUI, later we'll apply the color conversion into the swapchain
798+ // If using FreeSync HDR we need to to the tonemapping in-place and then apply the GUI, later we'll apply the color conversion into the swapchain
785799 //
786800 if (pSwapChain->GetDisplayMode () != DISPLAYMODE_SDR)
787801 {
@@ -813,8 +827,7 @@ void SampleRenderer::OnRender(State *pState, SwapChain *pSwapChain)
813827 }
814828 }
815829
816- // submit command buffer
817-
830+ // submit command buffer #1
818831 ThrowIfFailed (pCmdLst1->Close ());
819832 ID3D12CommandList* CmdListList1[] = { pCmdLst1 };
820833 m_pDevice->GetGraphicsQueue ()->ExecuteCommandLists (1 , CmdListList1);
@@ -823,13 +836,11 @@ void SampleRenderer::OnRender(State *pState, SwapChain *pSwapChain)
823836 //
824837 pSwapChain->WaitForSwapChain ();
825838
826- m_CommandListRing.OnBeginFrame ();
827-
828839 ID3D12GraphicsCommandList* pCmdLst2 = m_CommandListRing.GetNewCommandList ();
829840
830841 if (pSwapChain->GetDisplayMode () != DISPLAYMODE_SDR)
831842 {
832- // FS2 mode! Apply color conversion now.
843+ // FS HDR mode! Apply color conversion now.
833844 //
834845 pCmdLst2->RSSetViewports (1 , &m_viewport);
835846 pCmdLst2->RSSetScissorRects (1 , &m_rectScissor);
@@ -842,7 +853,7 @@ void SampleRenderer::OnRender(State *pState, SwapChain *pSwapChain)
842853 }
843854 else
844855 {
845- // non FS2 mode, that is SDR, here we apply the tonemapping from the HDR into the swapchain and then we render the GUI
856+ // non FS HDR mode, that is SDR, here we apply the tonemapping from the HDR into the swapchain and then we render the GUI
846857 //
847858
848859 // Tonemapping ------------------------------------------------------------------------
@@ -871,6 +882,11 @@ void SampleRenderer::OnRender(State *pState, SwapChain *pSwapChain)
871882 }
872883 }
873884
885+ if (pState->m_pScreenShotName != NULL )
886+ {
887+ m_saveTexture.CopyRenderTargetIntoStagingTexture (m_pDevice->GetDevice (), pCmdLst2, pSwapChain->GetCurrentBackBufferResource (), D3D12_RESOURCE_STATE_RENDER_TARGET);
888+ }
889+
874890 // Transition swapchain into present mode
875891
876892 pCmdLst2->ResourceBarrier (1 , &CD3DX12_RESOURCE_BARRIER::Transition (pSwapChain->GetCurrentBackBufferResource (), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
@@ -879,13 +895,19 @@ void SampleRenderer::OnRender(State *pState, SwapChain *pSwapChain)
879895
880896 m_GPUTimer.CollectTimings (pCmdLst2);
881897
882- // Close & Submit the command list --- -------------------------------------------------
898+ // Close & Submit the command list #2 -------------------------------------------------
883899 //
884900 ThrowIfFailed (pCmdLst2->Close ());
885901
886902 ID3D12CommandList* CmdListList2[] = { pCmdLst2 };
887903 m_pDevice->GetGraphicsQueue ()->ExecuteCommandLists (1 , CmdListList2);
888904
905+ if (pState->m_pScreenShotName != NULL )
906+ {
907+ m_saveTexture.SaveStagingTextureAsJpeg (m_pDevice->GetDevice (), m_pDevice->GetGraphicsQueue (), pState->m_pScreenShotName ->c_str ());
908+ pState->m_pScreenShotName = NULL ;
909+ }
910+
889911 // Update previous camera matrices
890912 //
891913 pState->camera .UpdatePreviousMatrices ();
0 commit comments