Skip to content

Commit e055500

Browse files
author
Wilkinson, David
committed
Merge for GLTFSample v1.2 update
2 parents 3a29fca + 512e664 commit e055500

File tree

12 files changed

+110
-60
lines changed

12 files changed

+110
-60
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "libs/cauldron"]
22
path = libs/cauldron
3-
url = ../../GPUOpen-LibrariesAndSDKs/Cauldron.git
3+
url = ../Cauldron.git
44
[submodule "media/Cauldron-Media"]
55
path = media/Cauldron-Media
66
url = ../../GPUOpen-LibrariesAndSDKs/Cauldron-Media

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ add_subdirectory(libs/cauldron)
1515

1616
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
1717

18-
if(GFX_API STREQUAL DX12)
19-
add_subdirectory(src/DX12)
18+
if(GFX_API STREQUAL DX12)
19+
add_subdirectory(src/DX12)
2020
elseif(GFX_API STREQUAL VK)
2121
find_package(Vulkan REQUIRED)
2222
add_subdirectory(src/VK)

libs/cauldron

src/Common/GLTFSample.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@
3939
{
4040
"time": 0,
4141
"from": [ 5.13694048, 1.89175785, -1.40289795 ],
42-
"to": [ 0.703276634, 1.02280307, 0.218072295 ]
42+
"to": [ 0.703276634, 1.02280307, 0.218072295 ],
43+
"screenShotName": "camera1.jpg"
4344
},
4445
{
4546
"time": 1000,
4647
"from": [ -5.13694048, 1.89175785, -1.40289795 ],
47-
"to": [ 0.703276634, 1.02280307, 0.218072295 ]
48+
"to": [ 0.703276634, 1.02280307, 0.218072295 ],
49+
"screenShotName": "camera2.jpg"
4850
}
4951
]
5052
}

src/DX12/GLTFSample.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ void GLTFSample::OnCreate(HWND hWnd)
122122
m_device.CreatePipelineCache();
123123

124124
// set stable power state
125-
m_device.GetDevice()->SetStablePowerState(m_stablePowerState);
125+
if (m_stablePowerState)
126+
m_device.GetDevice()->SetStablePowerState(TRUE);
126127

127128
//init the shader compiler
129+
InitDirectXCompiler();
128130
CreateShaderCache();
129131

130132
// Create Swapchain
@@ -312,7 +314,6 @@ void GLTFSample::LoadScene(int sceneIndex)
312314
{
313315
tfNode n;
314316
n.m_tranform.LookAt(PolarToVector(XM_PI / 2.0f, 0.58f)*3.5f, XMVectorSet(0, 0, 0, 0));
315-
int sourceIdx = m_pGltfLoader->AddNode(n);
316317

317318
tfLight l;
318319
l.m_type = tfLight::LIGHT_SPOTLIGHT;
@@ -321,9 +322,8 @@ void GLTFSample::LoadScene(int sceneIndex)
321322
l.m_range = 15;
322323
l.m_outerConeAngle = XM_PI / 4.0f;
323324
l.m_innerConeAngle = (XM_PI / 4.0f) * 0.9f;
324-
l.m_nodeIndex = sourceIdx;
325325

326-
m_pGltfLoader->AddLight(l);
326+
m_pGltfLoader->AddLight(n, l);
327327
}
328328

329329
// set default camera
@@ -341,7 +341,10 @@ void GLTFSample::LoadScene(int sceneIndex)
341341
//
342342
if (m_state.m_isBenchmarking)
343343
{
344-
BenchmarkConfig(scene["BenchmarkSettings"], m_activeCamera, m_pGltfLoader);
344+
std::string deviceName;
345+
std::string driverVersion;
346+
m_device.GetDeviceInfo(&deviceName, &driverVersion);
347+
BenchmarkConfig(scene["BenchmarkSettings"], m_activeCamera, m_pGltfLoader, deviceName, driverVersion);
345348
}
346349

347350
// indicate the mainloop we started loading a GLTF and it needs to load the rest (textures and geometry)
@@ -416,33 +419,33 @@ void GLTFSample::BuildUI()
416419

417420
if (ImGui::Button("Set spotlight 0"))
418421
{
419-
int idx = m_pGltfLoader->m_lights[0].m_nodeIndex;
422+
int idx = m_pGltfLoader->m_lightInstances[0].m_nodeIndex;
420423
m_pGltfLoader->m_nodes[idx].m_tranform.LookAt(m_state.camera.GetPosition(), m_state.camera.GetPosition() - m_state.camera.GetDirection());
421424
m_pGltfLoader->m_animatedMats[idx] = m_pGltfLoader->m_nodes[idx].m_tranform.GetWorldMat();
422425
}
423426

424-
// FreeSync2 display mode selector
427+
// FreeSync HDR display mode selector
425428
//
426-
if (ImGui::Button("FreeSync2"))
429+
if (ImGui::Button("FreeSync HDR"))
427430
{
428-
ImGui::OpenPopup("FreeSync2");
431+
ImGui::OpenPopup("FreeSync HDR");
429432
m_swapChain.EnumerateDisplayModes(&m_displayModesAvailable, &m_displayModesNamesAvailable);
430433
}
431434

432-
if (ImGui::BeginPopupModal("FreeSync2", NULL, ImGuiWindowFlags_AlwaysAutoResize))
435+
if (ImGui::BeginPopupModal("FreeSync HDR", NULL, ImGuiWindowFlags_AlwaysAutoResize))
433436
{
434437
if (m_displayModesAvailable.size() == 1)
435438
{
436-
ImGui::Text("\nOpps! This window is not on a FreeSync2 monitor so the only available mode is SDR.\n\n");
437-
ImGui::Text("If you have a FreeSync2 monitor move this window to that monitor and try again\n\n");
439+
ImGui::Text("\nOpps! This window is not on a FreeSync HDR monitor so the only available mode is SDR.\n\n");
440+
ImGui::Text("If you have a FreeSync HDR monitor move this window to that monitor and try again\n\n");
438441
if (ImGui::Button("Cancel", ImVec2(120, 0))) { ImGui::CloseCurrentPopup(); }
439442
ImGui::EndPopup();
440443
}
441444
else
442445
{
443446
if (m_swapChain.IsFullScreen() == false)
444447
{
445-
ImGui::Text("\nFreeSync2 modes are only available in in fullscreen mode, please press ALT + ENTER for fun!\n\n");
448+
ImGui::Text("\nFreeSync HDR modes are only available in in fullscreen mode, please press ALT + ENTER for fun!\n\n");
446449
if (ImGui::Button("Cancel", ImVec2(120, 0))) { ImGui::CloseCurrentPopup(); }
447450
ImGui::EndPopup();
448451
}
@@ -570,7 +573,7 @@ void GLTFSample::OnRender()
570573
// benchmarking takes control of the time, and exits the app when the animation is done
571574
std::vector<TimeStamp> timeStamps = m_Node->GetTimingValues();
572575

573-
m_time = BenchmarkLoop(timeStamps, &m_state.camera);
576+
m_time = BenchmarkLoop(timeStamps, &m_state.camera, &m_state.m_pScreenShotName);
574577
}
575578
else
576579
{

src/DX12/SampleRenderer.cpp

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
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();

src/DX12/SampleRenderer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class SampleRenderer
5757
bool m_isBenchmarking;
5858

5959
bool bDrawLightFrustum;
60+
61+
const std::string *m_pScreenShotName = NULL;
6062
};
6163

6264
void OnCreate(Device* pDevice, SwapChain *pSwapChain);
@@ -169,4 +171,7 @@ class SampleRenderer
169171
WireframeBox m_wireframeBox;
170172

171173
std::vector<TimeStamp> m_TimeStamps;
174+
175+
SaveTexture m_saveTexture;
176+
AsyncPool m_asyncPool;
172177
};

src/DX12/stdafx.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ using namespace DirectX;
2929
#include "Base/Helper.h"
3030
#include "Base/Device.h"
3131
#include "Base/Texture.h"
32-
#include "Base/FreeSync2.h"
32+
#include "Base/FreeSyncHDR.h"
3333
#include "Base/SwapChain.h"
3434
#include "Base/UploadHeap.h"
35+
#include "Base/SaveTexture.h"
3536
#include "Base/UserMarkers.h"
3637
#include "Base/GPUTimestamps.h"
3738
#include "Base/CommandListRing.h"
3839
#include "Base/StaticBufferPool.h"
3940
#include "Base/DynamicBufferRing.h"
4041
#include "Base/ResourceViewHeaps.h"
42+
#include "Base/ShaderCompilerCache.h"
4143
#include "Base/ShaderCompilerHelper.h"
4244
#include "Base/StaticConstantBufferPool.h"
4345

0 commit comments

Comments
 (0)