Remove static resource lists, make them members of the device

This commit is contained in:
baldurk
2019-09-06 22:19:28 +01:00
parent 1eecd56896
commit 9c6bfa6788
7 changed files with 38 additions and 44 deletions
+6 -11
View File
@@ -243,17 +243,14 @@ WrappedID3D12Device::WrappedID3D12Device(ID3D12Device *realDevice, D3D12InitPara
m_InitParams = params;
WrappedID3D12Resource1::m_List = NULL;
WrappedID3D12PipelineState::m_List = NULL;
if(RenderDoc::Inst().IsReplayApp())
{
m_State = CaptureState::LoadingReplaying;
if(realDevice)
{
WrappedID3D12Resource1::m_List = new std::map<ResourceId, WrappedID3D12Resource1 *>();
WrappedID3D12PipelineState::m_List = new std::vector<WrappedID3D12PipelineState *>();
m_ResourceList = new std::map<ResourceId, WrappedID3D12Resource1 *>();
m_PipelineList = new std::vector<WrappedID3D12PipelineState *>();
}
m_FrameCaptureRecord = NULL;
@@ -424,12 +421,6 @@ WrappedID3D12Device::~WrappedID3D12Device()
for(size_t i = 0; i < m_InternalCmds.freecmds.size(); i++)
SAFE_RELEASE(m_InternalCmds.freecmds[i]);
if(!IsStructuredExporting(m_State))
{
SAFE_DELETE(WrappedID3D12Resource1::m_List);
SAFE_DELETE(WrappedID3D12PipelineState::m_List);
}
for(size_t i = 0; i < m_QueueFences.size(); i++)
{
GPUSync(m_Queues[i], m_QueueFences[i]);
@@ -486,6 +477,9 @@ WrappedID3D12Device::~WrappedID3D12Device()
delete m_ThreadTempMem[i];
}
SAFE_DELETE(m_ResourceList);
SAFE_DELETE(m_PipelineList);
if(RenderDoc::Inst().GetCrashHandler())
RenderDoc::Inst().GetCrashHandler()->UnregisterMemoryRegion(this);
@@ -2946,6 +2940,7 @@ ReplayStatus WrappedID3D12Device::ReadLogInitialisation(RDCFile *rdc, bool store
if(IsStructuredExporting(m_State))
{
m_Queue = new WrappedID3D12CommandQueue(NULL, this, m_State);
m_Queues.push_back(m_Queue);
}
m_Queue->SetFrameReader(new StreamReader(reader, frameDataSize));
+8
View File
@@ -55,6 +55,7 @@ DECLARE_REFLECTION_STRUCT(D3D12InitParams);
class WrappedID3D12Device;
class WrappedID3D12Resource1;
class WrappedID3D12PipelineState;
class D3D12TextRenderer;
class D3D12ShaderCache;
@@ -421,6 +422,10 @@ private:
std::map<ResourceId, std::string> m_ResourceNames;
// only valid on replay
std::map<ResourceId, WrappedID3D12Resource1 *> *m_ResourceList = NULL;
std::vector<WrappedID3D12PipelineState *> *m_PipelineList = NULL;
struct SwapPresentInfo
{
D3D12_CPU_DESCRIPTOR_HANDLE rtvs[8];
@@ -464,6 +469,9 @@ public:
const D3D12_FEATURE_DATA_D3D12_OPTIONS3 &GetOpts3() { return m_D3D12Opts3; }
void RemoveQueue(WrappedID3D12CommandQueue *queue);
// only valid on replay
std::map<ResourceId, WrappedID3D12Resource1 *> &GetResourceList() { return *m_ResourceList; }
std::vector<WrappedID3D12PipelineState *> &GetPipelineList() { return *m_PipelineList; }
////////////////////////////////////////////////////////////////
// non wrapping interface
+1 -1
View File
@@ -271,7 +271,7 @@ ResourceId D3D12Replay::RenderOverlay(ResourceId texid, CompType typeHint, Float
DebugOverlay overlay, uint32_t eventId,
const std::vector<uint32_t> &passEvents)
{
ID3D12Resource *resource = WrappedID3D12Resource1::GetList()[texid];
ID3D12Resource *resource = m_pDevice->GetResourceList()[texid];
if(resource == NULL)
return ResourceId();
@@ -332,7 +332,7 @@ bool D3D12Replay::RenderTextureInternal(D3D12_CPU_DESCRIPTOR_HANDLE rtv, Texture
{
const bool blendAlpha = (flags & eTexDisplay_BlendAlpha) != 0;
ID3D12Resource *resource = WrappedID3D12Resource1::GetList()[cfg.resourceId];
ID3D12Resource *resource = m_pDevice->GetResourceList()[cfg.resourceId];
if(resource == NULL)
return false;
+13 -15
View File
@@ -310,8 +310,7 @@ std::vector<ResourceId> D3D12Replay::GetBuffers()
{
std::vector<ResourceId> ret;
for(auto it = WrappedID3D12Resource1::GetList().begin();
it != WrappedID3D12Resource1::GetList().end(); it++)
for(auto it = m_pDevice->GetResourceList().begin(); it != m_pDevice->GetResourceList().end(); it++)
if(it->second->GetDesc().Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
ret.push_back(it->first);
@@ -322,8 +321,7 @@ std::vector<ResourceId> D3D12Replay::GetTextures()
{
std::vector<ResourceId> ret;
for(auto it = WrappedID3D12Resource1::GetList().begin();
it != WrappedID3D12Resource1::GetList().end(); it++)
for(auto it = m_pDevice->GetResourceList().begin(); it != m_pDevice->GetResourceList().end(); it++)
{
if(it->second->GetDesc().Dimension != D3D12_RESOURCE_DIMENSION_BUFFER &&
m_pDevice->GetResourceManager()->GetOriginalID(it->first) != it->first)
@@ -338,9 +336,9 @@ BufferDescription D3D12Replay::GetBuffer(ResourceId id)
BufferDescription ret = {};
ret.resourceId = m_pDevice->GetResourceManager()->GetOriginalID(id);
auto it = WrappedID3D12Resource1::GetList().find(id);
auto it = m_pDevice->GetResourceList().find(id);
if(it == WrappedID3D12Resource1::GetList().end())
if(it == m_pDevice->GetResourceList().end())
return ret;
D3D12_RESOURCE_DESC desc = it->second->GetDesc();
@@ -379,9 +377,9 @@ TextureDescription D3D12Replay::GetTexture(ResourceId id)
TextureDescription ret = {};
ret.resourceId = m_pDevice->GetResourceManager()->GetOriginalID(id);
auto it = WrappedID3D12Resource1::GetList().find(id);
auto it = m_pDevice->GetResourceList().find(id);
if(it == WrappedID3D12Resource1::GetList().end())
if(it == m_pDevice->GetResourceList().end())
return ret;
D3D12_RESOURCE_DESC desc = it->second->GetDesc();
@@ -2252,7 +2250,7 @@ uint32_t D3D12Replay::PickVertex(uint32_t eventId, int32_t width, int32_t height
bool D3D12Replay::GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, uint32_t sample,
CompType typeHint, float *minval, float *maxval)
{
ID3D12Resource *resource = WrappedID3D12Resource1::GetList()[texid];
ID3D12Resource *resource = m_pDevice->GetResourceList()[texid];
if(resource == NULL)
return false;
@@ -2432,7 +2430,7 @@ bool D3D12Replay::GetHistogram(ResourceId texid, uint32_t sliceFace, uint32_t mi
if(minval >= maxval)
return false;
ID3D12Resource *resource = WrappedID3D12Resource1::GetList()[texid];
ID3D12Resource *resource = m_pDevice->GetResourceList()[texid];
if(resource == NULL)
return false;
@@ -2678,9 +2676,9 @@ bool D3D12Replay::NeedRemapForFetch(const ResourceFormat &format)
void D3D12Replay::GetBufferData(ResourceId buff, uint64_t offset, uint64_t length, bytebuf &retData)
{
auto it = WrappedID3D12Resource1::GetList().find(buff);
auto it = m_pDevice->GetResourceList().find(buff);
if(it == WrappedID3D12Resource1::GetList().end())
if(it == m_pDevice->GetResourceList().end())
{
RDCERR("Getting buffer data for unknown buffer %llu!", buff);
return;
@@ -2878,7 +2876,7 @@ void D3D12Replay::RefreshDerivedReplacements()
// we're iterating
std::vector<ID3D12PipelineState *> deletequeue;
for(WrappedID3D12PipelineState *pipe : WrappedID3D12PipelineState::GetList())
for(WrappedID3D12PipelineState *pipe : m_pDevice->GetPipelineList())
{
ResourceId pipesrcid = pipe->GetResourceID();
ResourceId origsrcid = rm->GetOriginalID(pipesrcid);
@@ -2985,7 +2983,7 @@ void D3D12Replay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip
bool wasms = false;
bool resolve = params.resolve;
ID3D12Resource *resource = WrappedID3D12Resource1::GetList()[tex];
ID3D12Resource *resource = m_pDevice->GetResourceList()[tex];
if(resource == NULL)
{
@@ -3505,7 +3503,7 @@ void D3D12Replay::BuildCustomShader(ShaderEncoding sourceEncoding, bytebuf sourc
ResourceId D3D12Replay::ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip,
uint32_t arrayIdx, uint32_t sampleIdx, CompType typeHint)
{
ID3D12Resource *resource = WrappedID3D12Resource1::GetList()[texid];
ID3D12Resource *resource = m_pDevice->GetResourceList()[texid];
if(resource == NULL)
return ResourceId();
+2 -4
View File
@@ -29,8 +29,6 @@
#include "d3d12_command_queue.h"
GPUAddressRangeTracker WrappedID3D12Resource1::m_Addresses;
std::map<ResourceId, WrappedID3D12Resource1 *> *WrappedID3D12Resource1::m_List = NULL;
std::vector<WrappedID3D12PipelineState *> *WrappedID3D12PipelineState::m_List = NULL;
std::map<WrappedID3D12PipelineState::DXBCKey, WrappedID3D12Shader *> WrappedID3D12Shader::m_Shaders;
bool WrappedID3D12Shader::m_InternalResources = false;
@@ -305,8 +303,8 @@ WrappedID3D12Resource1::~WrappedID3D12Resource1()
}
}
if(m_List)
(*m_List).erase(GetResourceID());
if(IsReplayMode(m_pDevice->GetState()))
m_pDevice->GetResourceList().erase(GetResourceID());
// assuming only valid for buffers
if(m_pReal->GetDesc().Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
+7 -12
View File
@@ -632,9 +632,6 @@ public:
}
}
static std::vector<WrappedID3D12PipelineState *> *m_List;
static std::vector<WrappedID3D12PipelineState *> &GetList() { return *m_List; }
bool IsGraphics() { return graphics != NULL; }
bool IsCompute() { return compute != NULL; }
struct DXBCKey
@@ -814,13 +811,14 @@ public:
WrappedID3D12PipelineState(ID3D12PipelineState *real, WrappedID3D12Device *device)
: WrappedDeviceChild12(real, device)
{
if(m_List)
m_List->push_back(this);
if(IsReplayMode(m_pDevice->GetState()))
m_pDevice->GetPipelineList().push_back(this);
}
virtual ~WrappedID3D12PipelineState()
{
if(m_List)
m_List->erase(std::find(m_List->begin(), m_List->end(), this));
if(IsReplayMode(m_pDevice->GetState()))
m_pDevice->GetPipelineList().erase(std::find(m_pDevice->GetPipelineList().begin(),
m_pDevice->GetPipelineList().end(), this));
Shutdown();
@@ -890,9 +888,6 @@ public:
static const int AllocMaxByteSize = 1536 * 1024;
ALLOCATE_WITH_WRAPPED_POOL(WrappedID3D12Resource1, AllocPoolCount, AllocMaxByteSize, false);
static std::map<ResourceId, WrappedID3D12Resource1 *> *m_List;
static std::map<ResourceId, WrappedID3D12Resource1 *> &GetList() { return *m_List; }
static void RefBuffers(D3D12ResourceManager *rm);
static void GetResIDFromAddr(D3D12_GPU_VIRTUAL_ADDRESS addr, ResourceId &id, UINT64 &offs)
@@ -919,8 +914,8 @@ public:
WrappedID3D12Resource1(ID3D12Resource *real, WrappedID3D12Device *device)
: WrappedDeviceChild12(real, device)
{
if(m_List)
(*m_List)[GetResourceID()] = this;
if(IsReplayMode(device->GetState()))
device->GetResourceList()[GetResourceID()] = this;
real->QueryInterface(__uuidof(ID3D12Resource1), (void **)&m_pReal1);