Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions trinity/Tr2IndirectDrawBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "Tr2IndirectDrawBuffer.h"
#include "Tr2Renderer.h"
#include "../trinityal/metal/Tr2ShaderProgramALMetal.h"
#if TRINITY_PLATFORM == TRINITY_DIRECTX12
#include "../trinityal/dx12/Utilities.h"
Comment thread
JohnGreenFC marked this conversation as resolved.
#endif


CCP_STATS_DECLARE( sceneExecuteIndirectCount, "Trinity/AL/sceneExecuteIndirectCount", true, CST_COUNTER_LOW, "Number of ExecuteIndirect calls." );
Expand Down Expand Up @@ -328,7 +331,7 @@ void Tr2IndirectDrawBuffer::CopyArguments()
transition
};

renderContext.m_commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( renderContext.m_commandList, 1, &barrier );
}

for( int i = 0; i <= copyIndex; i++ )
Expand All @@ -352,7 +355,7 @@ void Tr2IndirectDrawBuffer::CopyArguments()
transition
};

renderContext.m_commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( renderContext.m_commandList, 1, &barrier );
}
#endif
}
Expand Down
53 changes: 37 additions & 16 deletions trinity/TriDevice12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,23 @@ void TriDevice::HandleRenderTick( Be::Time realTime, Be::Time simTime )

CCP_LOGERR( "[DRED] Last tracked GPU operations:" );
std::map<UINT, std::wstring> contextStrings;
D3D12_AUTO_BREADCRUMB_NODE1 const* pNode = dredAutoBreadcrumbsOutput.pHeadAutoBreadcrumbNode;
while( pNode && pNode->pLastBreadcrumbValue )
for( D3D12_AUTO_BREADCRUMB_NODE1 const* pNode = dredAutoBreadcrumbsOutput.pHeadAutoBreadcrumbNode; pNode; pNode = pNode->pNext )
{
if( !pNode->pLastBreadcrumbValue )
{
continue;
}
UINT lastCompletedOp = *pNode->pLastBreadcrumbValue;
if( lastCompletedOp != (int)pNode->BreadcrumbCount && lastCompletedOp != 0 )
// Only lists in flight at removal time; 0 = never started, BreadcrumbCount = fully retired
if( lastCompletedOp != pNode->BreadcrumbCount && lastCompletedOp != 0 )
{
CCP_LOGERR( "[DRED] Commandlist completed %d of %d commands", lastCompletedOp, pNode->BreadcrumbCount );
CCP_LOGERR( "[DRED] Commandlist '%s' (%p) on queue '%s' completed %d of %d commands (%d contexts)",
pNode->pCommandListDebugNameA ? pNode->pCommandListDebugNameA : "<unnamed>",
pNode->pCommandList,
pNode->pCommandQueueDebugNameA ? pNode->pCommandQueueDebugNameA : "<unnamed>",
lastCompletedOp,
pNode->BreadcrumbCount,
pNode->BreadcrumbContextsCount );

UINT firstOp = lastCompletedOp > 100 ? lastCompletedOp - 100 : 0;
UINT lastOp = std::min<UINT>( lastCompletedOp + 20, UINT( pNode->BreadcrumbCount ) - 1 );
Expand All @@ -227,7 +237,10 @@ void TriDevice::HandleRenderTick( Be::Time realTime, Be::Time simTime )
for( UINT breadcrumbContext = 0; breadcrumbContext < pNode->BreadcrumbContextsCount; ++breadcrumbContext )
{
const D3D12_DRED_BREADCRUMB_CONTEXT& context = pNode->pBreadcrumbContexts[breadcrumbContext];
contextStrings[context.BreadcrumbIndex] = context.pContextString;
if( context.BreadcrumbIndex >= firstOp && context.BreadcrumbIndex <= lastOp )
{
contextStrings[context.BreadcrumbIndex] = context.pContextString;
}
}

for( UINT op = firstOp; op <= lastOp; ++op )
Expand All @@ -241,28 +254,36 @@ void TriDevice::HandleRenderTick( Be::Time realTime, Be::Time simTime )
contextString = it->second;
}

char const* opName = DredBreadcrumbOpName( breadcrumbOp );
CCP_LOGERR( "\tOp: %d, %s%ls%s", op, opName, contextString.c_str(), ( op + 1 == lastCompletedOp ) ? " - Last completed" : "" );
// Markers with a context string are our own annotations, not GPU work
char const* opName = breadcrumbOp == D3D12_AUTO_BREADCRUMB_OP_SETMARKER && !contextString.empty() ? "[Trinity]" : DredBreadcrumbOpName( breadcrumbOp );
char const* status = op == lastCompletedOp ? " - IN FLIGHT" : ( op + 1 == lastCompletedOp ) ? " - Last completed" :
"";
CCP_LOGERR( "\tOp: %d, %s %ls%s", op, opName, contextString.c_str(), status );
}
}
pNode = pNode->pNext;
}
}
if( SUCCEEDED( pDred->GetPageFaultAllocationOutput1( &dredPageFaultOutput ) ) )
{
for( auto node = dredPageFaultOutput.pHeadExistingAllocationNode; node != nullptr; node = node->pNext )
{
if( node->ObjectNameW )
CCP_LOGERR( "[DRED] Page fault VA: 0x%016llX", dredPageFaultOutput.PageFaultVA );
// Engine names are ANSI (WKPDID_D3DDebugObjectName), so DRED fills ObjectNameA; ObjectNameW only holds names set via SetName
auto logAllocationNode = []( const char* prefix, const D3D12_DRED_ALLOCATION_NODE1* node ) {
Comment thread
JohnGreenFC marked this conversation as resolved.
if( node->ObjectNameA )
{
CCP_LOGERR( "Page Fault Allocation on: %ls", node->ObjectNameW );
CCP_LOGERR( "%s: %s (type %d)", prefix, node->ObjectNameA, node->AllocationType );
}
else
{
CCP_LOGERR( "%s: %ls (type %d)", prefix, node->ObjectNameW ? node->ObjectNameW : L"<unnamed>", node->AllocationType );
}
};
for( auto node = dredPageFaultOutput.pHeadExistingAllocationNode; node != nullptr; node = node->pNext )
{
logAllocationNode( "Page Fault Allocation on", node );
}
for( auto node = dredPageFaultOutput.pHeadRecentFreedAllocationNode; node != nullptr; node = node->pNext )
{
if( node->ObjectNameW )
{
CCP_LOGERR( "Page Fault Free on: %ls", node->ObjectNameW );
}
logAllocationNode( "Page Fault Free on", node );
}
}
}
Expand Down
1 change: 1 addition & 0 deletions trinityal/Tr2RenderContextEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ALLog.h"

bool g_requestDebugMarkers = false;
bool g_dredBreadcrumbsEnabled = false;
bool g_skipNvidiaStreamline = false;
bool g_brokenMacOSNvidiaDrivers = false;

Expand Down
5 changes: 5 additions & 0 deletions trinityal/dx12/Tr2PrimaryRenderContextDx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
extern bool g_requestDeviceDebugLayer;
extern bool g_requestDebugMarkers;
extern bool g_requestDred;
extern bool g_dredBreadcrumbsEnabled;
bool g_gatherPipelineStatistics = false;
extern ICrashReporter* TrinityALCrashes;

Expand Down Expand Up @@ -45,6 +46,9 @@ bool EnableDred()
// Turn on auto-breadcrumbs and page fault reporting.
pDredSettings->SetAutoBreadcrumbsEnablement( D3D12_DRED_ENABLEMENT_FORCED_ON );
pDredSettings->SetPageFaultEnablement( D3D12_DRED_ENABLEMENT_FORCED_ON );
// Capture SetMarker/BeginEvent strings alongside the breadcrumb ops
pDredSettings->SetBreadcrumbContextEnablement( D3D12_DRED_ENABLEMENT_FORCED_ON );
g_dredBreadcrumbsEnabled = true;
return true;
}
return false;
Expand Down Expand Up @@ -410,6 +414,7 @@ ALResult Tr2PrimaryRenderContextAL::CreateDevice(
desc.NodeMask = 0;

CR_RETURN_HR( CreateCommandQueue( device, &desc, commandQueue ) );
TrinityALImpl::SetDebugName( commandQueue, "PrimaryDirectQueue" );

const bool isWindowless = ( focusWindow == 0 ) && presentationParameters.software;

Expand Down
12 changes: 9 additions & 3 deletions trinityal/dx12/Tr2RenderContextDx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "util/AmdExtDevice.h"

extern bool g_requestDebugMarkers;
extern bool g_dredBreadcrumbsEnabled;

CCP_STATS_DECLARE( primitiveCount, "Trinity/AL/primitiveCount", true, CST_COUNTER_HIGH, "Primitive count in DrawPrimitive calls." );
CCP_STATS_DECLARE( vertexCount, "Trinity/AL/vertexCount", true, CST_COUNTER_HIGH, "Vertex count in DrawPrimitive calls." );
Expand Down Expand Up @@ -139,6 +140,7 @@ ALResult Tr2RenderContextAL::CreateDx12( ID3D12CommandAllocator* commandAllocato
commandAllocator,
nullptr,
IID_PPV_ARGS( &m_commandList ) ) );
TrinityALImpl::SetDebugName( m_commandList, "Tr2RenderContext CommandList" );
CR_RETURN_HR( m_commandList->Close() );
m_commandList.QueryInterface( &m_commandList2 );

Expand Down Expand Up @@ -1576,6 +1578,10 @@ void Tr2RenderContextAL::AddGpuMarker( const char* marker )
{
crashTracker->PutMarker( m_commandList2, marker );
}
if( g_dredBreadcrumbsEnabled )
{
TrinityALImpl::SetDredMarker( m_commandList, marker );
}
}

void Tr2RenderContextAL::PushGpuMarker( const char* marker )
Expand Down Expand Up @@ -1724,7 +1730,7 @@ void Tr2RenderContextAL::FlushBarriersDx12()
{
if( !m_barriers.empty() )
{
m_commandList->ResourceBarrier( UINT( m_barriers.size() ), m_barriers.data() );
TrinityALImpl::ResourceBarrier( m_commandList, UINT( m_barriers.size() ), m_barriers.data() );
m_barriers.clear();
}
}
Expand Down Expand Up @@ -1771,7 +1777,7 @@ void Tr2RenderContextAL::FlushBarriersDx12( size_t count, ID3D12Resource** resou
}
if( barrierCount )
{
m_commandList->ResourceBarrier( UINT( barrierCount ), barriers );
TrinityALImpl::ResourceBarrier( m_commandList, UINT( barrierCount ), barriers );
}
}
else
Expand All @@ -1797,7 +1803,7 @@ void Tr2RenderContextAL::FlushBarriersDx12( size_t count, ID3D12Resource** resou
}
if( !barriers.empty() )
{
m_commandList->ResourceBarrier( UINT( barriers.size() ), barriers.data() );
TrinityALImpl::ResourceBarrier( m_commandList, UINT( barriers.size() ), barriers.data() );
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions trinityal/dx12/Tr2RtTopLevelAccelerationStructureALDx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ALResult Tr2RtTopLevelAccelerationStructureAL::Create( const size_t count, const
uavBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
uavBarrier.UAV.pResource = nullptr;
uavBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
renderContext.m_commandList->ResourceBarrier( 1, &uavBarrier );
TrinityALImpl::ResourceBarrier( renderContext.m_commandList, 1, &uavBarrier );

size_t capacity = Align( count, 128 );

Expand Down Expand Up @@ -165,7 +165,7 @@ ALResult Tr2RtTopLevelAccelerationStructureAL::Create( const size_t count, const
topLevelUavBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
topLevelUavBarrier.UAV.pResource = buffer.TrinityALImpl_GetObject()->GetGpuResource();
topLevelUavBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
renderContext.m_commandList->ResourceBarrier( 1, &topLevelUavBarrier );
TrinityALImpl::ResourceBarrier( renderContext.m_commandList, 1, &topLevelUavBarrier );

return S_OK;
}
Expand Down Expand Up @@ -195,7 +195,7 @@ ALResult Tr2RtTopLevelAccelerationStructureAL::Update( const size_t count, const
uavBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
uavBarrier.UAV.pResource = nullptr;
uavBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
renderContext.m_commandList->ResourceBarrier( 1, &uavBarrier );
TrinityALImpl::ResourceBarrier( renderContext.m_commandList, 1, &uavBarrier );

CComPtr<ID3D12Resource> uploadBuffer;
auto completed = m_owner->GetRenderedFrameNumber();
Expand Down Expand Up @@ -256,7 +256,7 @@ ALResult Tr2RtTopLevelAccelerationStructureAL::Update( const size_t count, const
topLevelUavBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
topLevelUavBarrier.UAV.pResource = m_buffer.TrinityALImpl_GetObject()->GetGpuResource();
topLevelUavBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
renderContext.m_commandList->ResourceBarrier( 1, &topLevelUavBarrier );
TrinityALImpl::ResourceBarrier( renderContext.m_commandList, 1, &topLevelUavBarrier );

return S_OK;
}
Expand Down
50 changes: 25 additions & 25 deletions trinityal/dx12/Tr2TextureALDx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,17 @@ struct Tr2TextureAL::MipMapGenerator
else
{
auto restore = TrinityALImpl::Transition( m_staging, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST );
commandList->ResourceBarrier( 1, &restore );
TrinityALImpl::ResourceBarrier( commandList, 1, &restore );
}

staging = m_staging;

// Copy the resource to staging
auto from = TrinityALImpl::Transition( resource, resourceState, D3D12_RESOURCE_STATE_COPY_SOURCE );
commandList->ResourceBarrier( 1, &from );
TrinityALImpl::ResourceBarrier( commandList, 1, &from );
commandList->CopyResource( staging, resource );
auto to = TrinityALImpl::Transition( staging, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE );
commandList->ResourceBarrier( 1, &to );
TrinityALImpl::ResourceBarrier( commandList, 1, &to );
}
else
{
Expand All @@ -279,7 +279,7 @@ struct Tr2TextureAL::MipMapGenerator
if( ( resourceState & D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE ) == 0 )
{
auto barrier = TrinityALImpl::Transition( staging, resourceState, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
}
else
{
Expand Down Expand Up @@ -390,7 +390,7 @@ struct Tr2TextureAL::MipMapGenerator
srv2uavDescs[i].Transition.Subresource = mip + ( i * desc.MipLevels );
uav2srvDescs[i].Transition.Subresource = mip + ( i * desc.MipLevels );
}
commandList->ResourceBarrier( desc.DepthOrArraySize, srv2uavDescs.data() );
TrinityALImpl::ResourceBarrier( commandList, desc.DepthOrArraySize, srv2uavDescs.data() );

// Bind the mip subresources
commandList->SetComputeRootDescriptorTable( TrinityALImpl::GenerateMipsResources::TargetTexture, uavH );
Expand All @@ -412,10 +412,10 @@ struct Tr2TextureAL::MipMapGenerator
( mipHeight + TrinityALImpl::GenerateMipsResources::ThreadGroupSize - 1 ) / TrinityALImpl::GenerateMipsResources::ThreadGroupSize,
desc.DepthOrArraySize );

commandList->ResourceBarrier( 1, &barrierUAV );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrierUAV );

// Transition the mip to an SRV
commandList->ResourceBarrier( desc.DepthOrArraySize, uav2srvDescs.data() );
TrinityALImpl::ResourceBarrier( commandList, desc.DepthOrArraySize, uav2srvDescs.data() );

// Offset the descriptor heap handles
uavH.ptr += descriptorSize;
Expand All @@ -430,18 +430,18 @@ struct Tr2TextureAL::MipMapGenerator
TrinityALImpl::Transition( resource, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST )
};

commandList->ResourceBarrier( 2, barriers );
TrinityALImpl::ResourceBarrier( commandList, 2, barriers );
// Copy the entire resource back
commandList->CopyResource( resource, staging );

// Transition the target resource back to pixel shader resource
auto barrier = TrinityALImpl::Transition( resource, D3D12_RESOURCE_STATE_COPY_DEST, resourceState );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
}
else if( ( resourceState & D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE ) == 0 )
{
auto barrier = TrinityALImpl::Transition( resource, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, resourceState );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
}

m_device.DirtyDescriptorCache();
Expand Down Expand Up @@ -477,27 +477,27 @@ struct Tr2TextureAL::MipMapGenerator
else
{
auto restore = TrinityALImpl::Transition( m_resourceCopy, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST );
commandList->ResourceBarrier( 1, &restore );
TrinityALImpl::ResourceBarrier( commandList, 1, &restore );
}

// Copy the resource data
auto barrier = TrinityALImpl::Transition( resource, resourceState, D3D12_RESOURCE_STATE_COPY_SOURCE );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
commandList->CopyResource( m_resourceCopy, resource );
barrier = TrinityALImpl::Transition( m_resourceCopy, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );

// Generate the mips
GenerateMips_UnorderedAccessPath( m_resourceCopy, DXGI_FORMAT_R8G8B8A8_UNORM, commandList, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE );

// Direct copy back
barrier = TrinityALImpl::Transition( m_resourceCopy, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_COPY_SOURCE );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
barrier = TrinityALImpl::Transition( resource, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
commandList->CopyResource( resource, m_resourceCopy );
barrier = TrinityALImpl::Transition( resource, D3D12_RESOURCE_STATE_COPY_DEST, resourceState );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
return S_OK;
}

Expand Down Expand Up @@ -550,33 +550,33 @@ struct Tr2TextureAL::MipMapGenerator
else
{
auto restore = TrinityALImpl::Transition( m_bgrAliasCopy, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST );
commandList->ResourceBarrier( 1, &restore );
TrinityALImpl::ResourceBarrier( commandList, 1, &restore );
}

// Copy the resource data
auto barrier = TrinityALImpl::AliasBarrier( nullptr, m_bgrAliasCopy );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
barrier = TrinityALImpl::Transition( resource, resourceState, D3D12_RESOURCE_STATE_COPY_SOURCE );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
commandList->CopyResource( m_bgrAliasCopy, resource );

// Generate the mips
barrier = TrinityALImpl::AliasBarrier( m_bgrAliasCopy, m_bgrResourceCopy );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
barrier = TrinityALImpl::Transition( m_bgrResourceCopy, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
FORWARD_HR( GenerateMips_UnorderedAccessPath( m_bgrResourceCopy, DXGI_FORMAT_R8G8B8A8_UNORM, commandList, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE ) );

// Direct copy back
barrier = TrinityALImpl::AliasBarrier( m_bgrResourceCopy, m_bgrAliasCopy );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
barrier = TrinityALImpl::Transition( m_bgrAliasCopy, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
barrier = TrinityALImpl::Transition( resource, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
commandList->CopyResource( resource, m_bgrAliasCopy );
barrier = TrinityALImpl::Transition( resource, D3D12_RESOURCE_STATE_COPY_DEST, resourceState );
commandList->ResourceBarrier( 1, &barrier );
TrinityALImpl::ResourceBarrier( commandList, 1, &barrier );
return S_OK;
}

Expand Down
Loading