@@ -678,9 +678,9 @@ WrappedID3D12Device::WrappedID3D12Device(ID3D12Device *realDevice, D3D12InitPara
678
678
m_HeaderChunk = NULL ;
679
679
680
680
m_Alloc = m_DataUploadAlloc = NULL ;
681
- m_GPUSyncFence = NULL ;
682
- m_GPUSyncHandle = NULL ;
683
- m_GPUSyncCounter = 0 ;
681
+ m_WFIFence = NULL ;
682
+ m_WFIHandle = NULL ;
683
+ m_WFICounter = 0 ;
684
684
m_OverlaySyncHandle = NULL ;
685
685
686
686
initStateCurBatch = 0 ;
@@ -900,12 +900,9 @@ WrappedID3D12Device::~WrappedID3D12Device()
900
900
for (size_t i = 0 ; i < m_InternalCmds.freecmds .size (); i++)
901
901
SAFE_RELEASE (m_InternalCmds.freecmds [i]);
902
902
903
+ DeviceWaitForIdle ();
903
904
for (size_t i = 0 ; i < m_QueueFences.size (); i++)
904
- {
905
- GPUSync (m_Queues[i], m_QueueFences[i]);
906
-
907
905
SAFE_RELEASE (m_QueueFences[i]);
908
- }
909
906
910
907
for (auto it = m_UploadBuffers.begin (); it != m_UploadBuffers.end (); ++it)
911
908
{
@@ -2180,7 +2177,7 @@ bool WrappedID3D12Device::Serialise_MapDataWrite(SerialiserType &ser, ID3D12Reso
2180
2177
m_CurDataUpload++;
2181
2178
if (m_CurDataUpload == ARRAY_COUNT (m_DataUploadList))
2182
2179
{
2183
- GPUSync ();
2180
+ InternalQueueWaitForIdle ();
2184
2181
m_CurDataUpload = 0 ;
2185
2182
}
2186
2183
}
@@ -2331,7 +2328,7 @@ bool WrappedID3D12Device::Serialise_WriteToSubresource(SerialiserType &ser, ID3D
2331
2328
m_CurDataUpload++;
2332
2329
if (m_CurDataUpload == ARRAY_COUNT (m_DataUploadList))
2333
2330
{
2334
- GPUSync ();
2331
+ InternalQueueWaitForIdle ();
2335
2332
m_CurDataUpload = 0 ;
2336
2333
}
2337
2334
}
@@ -2728,7 +2725,7 @@ void WrappedID3D12Device::StartFrameCapture(DeviceOwnedWindow devWnd)
2728
2725
initStateCurBatch = 0 ;
2729
2726
initStateCurList = NULL ;
2730
2727
2731
- GPUSyncAllQueues ();
2728
+ DeviceWaitForIdle ();
2732
2729
2733
2730
// wait until we've synced all queues to check for these
2734
2731
GetResourceManager ()->GetRTManager ()->TickASManagement ();
@@ -2863,7 +2860,7 @@ bool WrappedID3D12Device::EndFrameCapture(DeviceOwnedWindow devWnd)
2863
2860
2864
2861
m_State = CaptureState::BackgroundCapturing;
2865
2862
2866
- GPUSync ();
2863
+ DeviceWaitForIdle ();
2867
2864
}
2868
2865
2869
2866
rdcarray<MapState> maps = GetMaps ();
@@ -3217,7 +3214,7 @@ bool WrappedID3D12Device::DiscardFrameCapture(DeviceOwnedWindow devWnd)
3217
3214
3218
3215
m_State = CaptureState::BackgroundCapturing;
3219
3216
3220
- GPUSync ();
3217
+ DeviceWaitForIdle ();
3221
3218
3222
3219
queues = m_Queues;
3223
3220
}
@@ -4468,10 +4465,10 @@ void WrappedID3D12Device::CreateInternalResources()
4468
4465
CreateCommandAllocator (D3D12_COMMAND_LIST_TYPE_DIRECT, __uuidof (ID3D12CommandAllocator),
4469
4466
(void **)&m_Alloc);
4470
4467
InternalRef ();
4471
- CreateFence (0 , D3D12_FENCE_FLAG_NONE, __uuidof (ID3D12Fence), (void **)&m_GPUSyncFence );
4472
- m_GPUSyncFence ->SetName (L" m_GPUSyncFence " );
4468
+ CreateFence (0 , D3D12_FENCE_FLAG_NONE, __uuidof (ID3D12Fence), (void **)&m_WFIFence );
4469
+ m_WFIFence ->SetName (L" m_WFIFence " );
4473
4470
InternalRef ();
4474
- m_GPUSyncHandle = ::CreateEvent (NULL , FALSE , FALSE , NULL );
4471
+ m_WFIHandle = ::CreateEvent (NULL , FALSE , FALSE , NULL );
4475
4472
4476
4473
CreateFence (0 , D3D12_FENCE_FLAG_NONE, __uuidof (ID3D12Fence), (void **)&m_OverlayFence);
4477
4474
m_OverlayFence->SetName (L" m_OverlayFence" );
@@ -4493,7 +4490,7 @@ void WrappedID3D12Device::CreateInternalResources()
4493
4490
}
4494
4491
4495
4492
GetResourceManager ()->SetInternalResource (m_Alloc);
4496
- GetResourceManager ()->SetInternalResource (m_GPUSyncFence );
4493
+ GetResourceManager ()->SetInternalResource (m_WFIFence );
4497
4494
4498
4495
CreateCommandAllocator (D3D12_COMMAND_LIST_TYPE_DIRECT, __uuidof (ID3D12CommandAllocator),
4499
4496
(void **)&m_DataUploadAlloc);
@@ -4542,7 +4539,7 @@ void WrappedID3D12Device::CreateInternalResources()
4542
4539
RDCERR (" Failed to create RTV heap" );
4543
4540
}
4544
4541
4545
- m_GPUSyncCounter = 0 ;
4542
+ m_WFICounter = 0 ;
4546
4543
4547
4544
if (m_TextRenderer == NULL )
4548
4545
m_TextRenderer = new D3D12TextRenderer (this );
@@ -4555,7 +4552,7 @@ void WrappedID3D12Device::CreateInternalResources()
4555
4552
4556
4553
void WrappedID3D12Device::DestroyInternalResources ()
4557
4554
{
4558
- if (m_GPUSyncHandle == NULL )
4555
+ if (m_WFIHandle == NULL )
4559
4556
return ;
4560
4557
4561
4558
SAFE_RELEASE (m_pAMDExtObject);
@@ -4585,67 +4582,71 @@ void WrappedID3D12Device::DestroyInternalResources()
4585
4582
}
4586
4583
4587
4584
SAFE_RELEASE (m_Alloc);
4588
- SAFE_RELEASE (m_GPUSyncFence );
4585
+ SAFE_RELEASE (m_WFIFence );
4589
4586
SAFE_RELEASE (m_OverlayFence);
4590
- CloseHandle (m_GPUSyncHandle );
4587
+ CloseHandle (m_WFIHandle );
4591
4588
CloseHandle (m_OverlaySyncHandle);
4592
4589
}
4593
4590
4594
4591
void WrappedID3D12Device::DataUploadSync ()
4595
4592
{
4596
4593
if (m_CurDataUpload >= 0 )
4597
4594
{
4598
- GPUSync ();
4595
+ InternalQueueWaitForIdle ();
4599
4596
m_CurDataUpload = 0 ;
4600
4597
}
4601
4598
}
4602
4599
4603
- void WrappedID3D12Device::GPUSync (ID3D12CommandQueue *queue, ID3D12Fence *fence)
4600
+ void WrappedID3D12Device::InternalQueueWaitForIdle ()
4601
+ {
4602
+ QueueWaitForIdle (GetQueue (), m_WFIFence);
4603
+ }
4604
+
4605
+ void WrappedID3D12Device::QueueWaitForIdle (ID3D12CommandQueue *queue, ID3D12Fence *fence)
4604
4606
{
4605
- m_GPUSyncCounter ++;
4607
+ m_WFICounter ++;
4606
4608
4607
4609
if (HasFatalError ())
4608
4610
return ;
4609
4611
4610
- if (queue == NULL )
4611
- queue = GetQueue ();
4612
-
4613
- if (fence == NULL )
4614
- fence = m_GPUSyncFence;
4615
-
4616
- HRESULT hr = queue->Signal (fence, m_GPUSyncCounter);
4612
+ HRESULT hr = queue->Signal (fence, m_WFICounter);
4617
4613
CHECK_HR (this , hr);
4618
4614
RDCASSERTEQUAL (hr, S_OK);
4619
4615
4620
- fence->SetEventOnCompletion (m_GPUSyncCounter, m_GPUSyncHandle );
4616
+ fence->SetEventOnCompletion (m_WFICounter, m_WFIHandle );
4621
4617
4622
4618
// wait 10s for hardware GPUs, 100s for CPU
4623
4619
if (m_Replay && m_Replay->GetDriverInfo ().vendor == GPUVendor::Software)
4624
- WaitForSingleObject (m_GPUSyncHandle , 100000 );
4620
+ WaitForSingleObject (m_WFIHandle , 100000 );
4625
4621
else
4626
- WaitForSingleObject (m_GPUSyncHandle , 10000 );
4622
+ WaitForSingleObject (m_WFIHandle , 10000 );
4627
4623
4628
4624
hr = m_pDevice->GetDeviceRemovedReason ();
4629
4625
CHECK_HR (this , hr);
4630
4626
RDCASSERTEQUAL (hr, S_OK);
4631
4627
}
4632
4628
4633
- void WrappedID3D12Device::GPUSyncAllQueues ()
4629
+ void WrappedID3D12Device::ReplayWorkWaitForIdle ()
4634
4630
{
4635
- if (m_GPUSynced )
4631
+ if (m_WaitedForIdleAfterReplay )
4636
4632
return ;
4637
4633
4638
- for (size_t i = 0 ; i < m_QueueFences.size (); i++)
4639
- GPUSync (m_Queues[i], m_QueueFences[i]);
4634
+ DeviceWaitForIdle ();
4640
4635
4641
- m_GPUSynced = true ;
4636
+ m_WaitedForIdleAfterReplay = true ;
4637
+ }
4638
+
4639
+ void WrappedID3D12Device::DeviceWaitForIdle ()
4640
+ {
4641
+ for (size_t i = 0 ; i < m_QueueFences.size (); i++)
4642
+ QueueWaitForIdle (m_Queues[i], m_QueueFences[i]);
4642
4643
}
4643
4644
4644
4645
ID3D12GraphicsCommandListX *WrappedID3D12Device::GetNewList ()
4645
4646
{
4646
4647
ID3D12GraphicsCommandListX *ret = NULL ;
4647
4648
4648
- m_GPUSynced = false ;
4649
+ m_WaitedForIdleAfterReplay = false ;
4649
4650
4650
4651
if (!m_InternalCmds.freecmds .empty ())
4651
4652
{
@@ -4783,7 +4784,7 @@ void WrappedID3D12Device::FlushLists(bool forceSync, ID3D12CommandQueue *queue)
4783
4784
4784
4785
if (!m_InternalCmds.submittedcmds .empty () || forceSync)
4785
4786
{
4786
- GPUSync (queue);
4787
+ QueueWaitForIdle (queue, m_WFIFence );
4787
4788
4788
4789
if (!m_InternalCmds.submittedcmds .empty ())
4789
4790
m_InternalCmds.freecmds .append (m_InternalCmds.submittedcmds );
@@ -5382,22 +5383,22 @@ void WrappedID3D12Device::ReplayLog(uint32_t startEventID, uint32_t endEventID,
5382
5383
{
5383
5384
bool partial = true ;
5384
5385
5385
- m_GPUSynced = false ;
5386
+ m_WaitedForIdleAfterReplay = false ;
5386
5387
5387
5388
if (startEventID == 0 && (replayType == eReplay_WithoutDraw || replayType == eReplay_Full))
5388
5389
{
5389
5390
startEventID = 1 ;
5390
5391
partial = false ;
5391
5392
5392
- m_GPUSyncCounter ++;
5393
+ m_WFICounter ++;
5393
5394
5394
- GPUSyncAllQueues ();
5395
+ DeviceWaitForIdle ();
5395
5396
5396
5397
// I'm not sure the reason for this, but the debug layer warns about being unable to resubmit
5397
5398
// command lists due to the 'previous queue fence' not being ready yet, even if no fences are
5398
5399
// signalled or waited. So instead we just signal a dummy fence each new 'frame'
5399
5400
for (size_t i = 0 ; i < m_Queues.size (); i++)
5400
- CHECK_HR (this , m_Queues[i]->Signal (m_QueueFences[i], m_GPUSyncCounter ));
5401
+ CHECK_HR (this , m_Queues[i]->Signal (m_QueueFences[i], m_WFICounter ));
5401
5402
5402
5403
FlushLists (true );
5403
5404
m_CurDataUpload = 0 ;
@@ -5423,7 +5424,7 @@ void WrappedID3D12Device::ReplayLog(uint32_t startEventID, uint32_t endEventID,
5423
5424
ExecuteLists ();
5424
5425
FlushLists (true );
5425
5426
5426
- GPUSyncAllQueues ();
5427
+ DeviceWaitForIdle ();
5427
5428
5428
5429
// clear any previous ray dispatch references
5429
5430
D3D12CommandData &cmd = *m_Queue->GetCommandData ();
0 commit comments