Clean up handling of internal resources

* This reduces code complexity and divergence between the backends, as well as
  prevents internal resources in captures from being included when 'Ref All
  Resources' is enabled.
This commit is contained in:
baldurk
2018-08-06 16:22:48 +01:00
parent 98e4a5b613
commit 8e2a2b13c1
30 changed files with 213 additions and 82 deletions
+16 -7
View File
@@ -97,7 +97,7 @@ struct ResourceRecord
DataOffset(0),
Length(0),
DataWritten(false),
SpecialResource(false)
InternalResource(false)
{
m_ChunkLock = NULL;
@@ -261,7 +261,16 @@ struct ResourceRecord
int UpdateCount;
bool DataInSerialiser;
bool SpecialResource; // like the swap chain back buffers
// anything internal that shouldn't be automatically pulled in by 'Ref All Resources' or have
// initial contents stored. This could either be a type of object that would break if its chunks
// were inserted into the initialisation phase (like an D3D11 DeviceContext which contains
// commands) or just debug objects created during capture as helpers which shouldn't be included.
//
// The implication is that they are handled specially for being inserted into the capture, or
// aren't inserted at all. Note that if a resource is frame-referenced, it will be included
// regardless but still without initial contents, capture drivers should be careful.
bool InternalResource;
bool DataWritten;
protected:
@@ -413,7 +422,6 @@ public:
protected:
friend InitialContentData;
// 'interface' to implement by derived classes
virtual bool SerialisableResource(ResourceId id, RecordType *record) = 0;
virtual ResourceId GetID(WrappedResourceType res) = 0;
virtual bool ResourceTypeRelease(WrappedResourceType res) = 0;
@@ -803,7 +811,8 @@ void ResourceManager<Configuration>::InsertReferencedChunks(WriteSerialiser &ser
RenderDoc::Inst().SetProgress(CaptureProgress::AddReferencedResources, idx / num);
idx += 1.0f;
if(!SerialisableResource(it->first, it->second))
if(m_FrameReferencedResources.find(it->first) == m_FrameReferencedResources.end() &&
it->second->InternalResource)
continue;
it->second->Insert(sortedChunks);
@@ -857,7 +866,7 @@ void ResourceManager<Configuration>::PrepareInitialContents()
RecordType *record = GetResourceRecord(id);
WrappedResourceType res = GetCurrentResource(id);
if(record == NULL || record->SpecialResource)
if(record == NULL || record->InternalResource)
continue;
prepared++;
@@ -942,7 +951,7 @@ void ResourceManager<Configuration>::InsertInitialContentsChunks(WriteSerialiser
continue;
}
if(record->SpecialResource)
if(record->InternalResource)
{
#if ENABLED(VERBOSE_DIRTY_RESOURCES)
RDCDEBUG("Resource %llu is special - skipping", id);
@@ -1045,7 +1054,7 @@ void ResourceManager<Configuration>::ApplyInitialContentsNonChunks(WriteSerialis
RecordType *record = GetResourceRecord(id);
if(!record || record->SpecialResource)
if(!record || record->InternalResource)
continue;
if(!Need_InitialStateChunk(res))
+1 -2
View File
@@ -139,11 +139,10 @@ WrappedID3D11DeviceContext::WrappedID3D11DeviceContext(WrappedID3D11Device *real
{
m_ContextRecord = m_pDevice->GetResourceManager()->AddResourceRecord(m_ResourceID);
m_ContextRecord->DataInSerialiser = false;
m_ContextRecord->SpecialResource = true;
m_ContextRecord->InternalResource = true;
m_ContextRecord->Length = 0;
m_ContextRecord->NumSubResources = 0;
m_ContextRecord->SubResources = NULL;
m_ContextRecord->ignoreSerialise = true;
}
m_ScratchSerialiser.SetUserData(GetResourceManager());
@@ -5231,7 +5231,7 @@ HRESULT WrappedID3D11DeviceContext::FinishCommandList(BOOL RestoreDeferredContex
D3D11ResourceRecord *record =
m_pDevice->GetResourceManager()->AddResourceRecord(wrapped->GetResourceID());
record->Length = 0;
record->ignoreSerialise = true;
record->InternalResource = true;
if(IsActiveCapturing(m_State))
{
+12
View File
@@ -131,6 +131,7 @@ ID3D11Buffer *D3D11DebugManager::MakeCBuffer(const void *data, size_t size)
void D3D11DebugManager::InitCommonResources()
{
D3D11ShaderCache *shaderCache = m_pDevice->GetShaderCache();
D3D11ResourceManager *rm = m_pDevice->GetResourceManager();
std::string multisamplehlsl = GetEmbeddedResource(multisample_hlsl);
@@ -153,6 +154,14 @@ void D3D11DebugManager::InitCommonResources()
shaderCache->MakePShader(multisamplehlsl.c_str(), "RENDERDOC_DepthCopyArrayToMS", "ps_5_0");
m_pDevice->InternalRef();
// mark created resources as internal during capture so they aren't included in capture files.
rm->SetInternalResource(CopyMSToArrayPS);
rm->SetInternalResource(CopyArrayToMSPS);
rm->SetInternalResource(FloatCopyMSToArrayPS);
rm->SetInternalResource(FloatCopyArrayToMSPS);
rm->SetInternalResource(DepthCopyMSToArrayPS);
rm->SetInternalResource(DepthCopyArrayToMSPS);
std::string displayhlsl = GetEmbeddedResource(debugcbuffers_h);
displayhlsl += GetEmbeddedResource(debugcommon_hlsl);
displayhlsl += GetEmbeddedResource(debugdisplay_hlsl);
@@ -160,10 +169,13 @@ void D3D11DebugManager::InitCommonResources()
MSArrayCopyVS = shaderCache->MakeVShader(displayhlsl.c_str(), "RENDERDOC_FullscreenVS", "vs_4_0");
m_pDevice->InternalRef();
rm->SetInternalResource(MSArrayCopyVS);
for(int i = 0; i < ARRAY_COUNT(PublicCBuffers); i++)
{
PublicCBuffers[i] = MakeCBuffer(sizeof(float) * 4 * 100);
m_pDevice->InternalRef();
rm->SetInternalResource(PublicCBuffers[i]);
}
publicCBufIdx = 0;
+1 -2
View File
@@ -140,7 +140,7 @@ WrappedID3D11Device::WrappedID3D11Device(ID3D11Device *realDevice, D3D11InitPara
{
m_DeviceRecord = GetResourceManager()->AddResourceRecord(m_ResourceID);
m_DeviceRecord->DataInSerialiser = false;
m_DeviceRecord->SpecialResource = true;
m_DeviceRecord->InternalResource = true;
m_DeviceRecord->Length = 0;
m_DeviceRecord->NumSubResources = 0;
m_DeviceRecord->SubResources = NULL;
@@ -1307,7 +1307,6 @@ IUnknown *WrappedID3D11Device::WrapSwapchainBuffer(WrappedIDXGISwapChain4 *swap,
{
D3D11ResourceRecord *record = GetResourceManager()->AddResourceRecord(id);
record->DataInSerialiser = false;
record->SpecialResource = true;
record->Length = 0;
record->NumSubResources = 0;
record->SubResources = NULL;
+5 -22
View File
@@ -49,31 +49,14 @@ ID3D11DeviceChild *D3D11ResourceManager::UnwrapResource(ID3D11DeviceChild *res)
return res;
}
bool D3D11ResourceManager::SerialisableResource(ResourceId id, D3D11ResourceRecord *record)
void D3D11ResourceManager::SetInternalResource(ID3D11DeviceChild *res)
{
if(id == m_Device->GetImmediateContext()->GetResourceID())
return false;
if(id == m_Device->GetResourceID())
return true;
if(record->ignoreSerialise)
return false;
bool skip = false;
for(size_t i = 0; i < m_Device->GetNumDeferredContexts(); i++)
if(!RenderDoc::Inst().IsReplayApp())
{
if(id == m_Device->GetDeferredContext(i)->GetResourceID())
{
skip = true;
break;
}
D3D11ResourceRecord *record = GetResourceRecord(GetIDForResource(res));
if(record)
record->InternalResource = true;
}
if(skip)
return false;
return true;
}
ResourceId D3D11ResourceManager::GetID(ID3D11DeviceChild *res)
+2 -4
View File
@@ -76,7 +76,6 @@ struct D3D11ResourceRecord : public ResourceRecord
{
RDCEraseEl(ShadowPtr);
RDCEraseEl(contexts);
ignoreSerialise = false;
}
~D3D11ResourceRecord()
@@ -184,8 +183,6 @@ struct D3D11ResourceRecord : public ResourceRecord
}
}
bool ignoreSerialise;
int NumSubResources;
D3D11ResourceRecord **SubResources;
@@ -252,8 +249,9 @@ public:
return (ID3D11Resource *)UnwrapResource((ID3D11DeviceChild *)res);
}
void SetInternalResource(ID3D11DeviceChild *res);
private:
bool SerialisableResource(ResourceId id, D3D11ResourceRecord *record);
ResourceId GetID(ID3D11DeviceChild *res);
bool ResourceTypeRelease(ID3D11DeviceChild *res);
@@ -27,6 +27,7 @@
#include "stb/stb_truetype.h"
#include "d3d11_context.h"
#include "d3d11_device.h"
#include "d3d11_resources.h"
#include "d3d11_shader_cache.h"
#include "data/hlsl/debugcbuffers.h"
@@ -39,6 +40,8 @@ D3D11TextRenderer::D3D11TextRenderer(WrappedID3D11Device *wrapper)
m_pDevice = wrapper;
m_pImmediateContext = m_pDevice->GetImmediateContext();
D3D11ResourceManager *rm = m_pDevice->GetResourceManager();
HRESULT hr = S_OK;
D3D11_BLEND_DESC blendDesc;
@@ -61,6 +64,7 @@ D3D11TextRenderer::D3D11TextRenderer(WrappedID3D11Device *wrapper)
RDCERR("Failed to create font blendstate HRESULT: %s", ToStr(hr).c_str());
m_pDevice->InternalRef();
rm->SetInternalResource(BlendState);
D3D11_SAMPLER_DESC sampDesc;
RDCEraseEl(sampDesc);
@@ -78,6 +82,7 @@ D3D11TextRenderer::D3D11TextRenderer(WrappedID3D11Device *wrapper)
RDCERR("Failed to create linear sampler state HRESULT: %s", ToStr(hr).c_str());
m_pDevice->InternalRef();
rm->SetInternalResource(LinearSampler);
D3D11_TEXTURE2D_DESC desc;
RDCEraseEl(desc);
@@ -135,6 +140,7 @@ D3D11TextRenderer::D3D11TextRenderer(WrappedID3D11Device *wrapper)
RDCERR("Failed to create debugTex HRESULT: %s", ToStr(hr).c_str());
m_pDevice->InternalRef();
rm->SetInternalResource(debugTex);
delete[] buf;
@@ -144,6 +150,7 @@ D3D11TextRenderer::D3D11TextRenderer(WrappedID3D11Device *wrapper)
RDCERR("Failed to create Tex HRESULT: %s", ToStr(hr).c_str());
m_pDevice->InternalRef();
rm->SetInternalResource(Tex);
SAFE_RELEASE(debugTex);
@@ -164,6 +171,7 @@ D3D11TextRenderer::D3D11TextRenderer(WrappedID3D11Device *wrapper)
RDCERR("Failed to create font GlyphData HRESULT: %s", ToStr(hr).c_str());
m_pDevice->InternalRef();
rm->SetInternalResource(GlyphData);
for(int i = 0; i < numChars; i++)
{
@@ -199,6 +207,7 @@ D3D11TextRenderer::D3D11TextRenderer(WrappedID3D11Device *wrapper)
RDCERR("Failed to create font CBuffer HRESULT: %s", ToStr(hr).c_str());
m_pDevice->InternalRef();
rm->SetInternalResource(CBuffer);
cbufDesc.ByteWidth = (2 + FONT_MAX_CHARS) * sizeof(uint32_t) * 4;
hr = m_pDevice->CreateBuffer(&cbufDesc, NULL, &CharBuffer);
@@ -207,6 +216,7 @@ D3D11TextRenderer::D3D11TextRenderer(WrappedID3D11Device *wrapper)
RDCERR("Failed to create font CharBuffer HRESULT: %s", ToStr(hr).c_str());
m_pDevice->InternalRef();
rm->SetInternalResource(CharBuffer);
std::string fullhlsl = "";
{
@@ -222,8 +232,11 @@ D3D11TextRenderer::D3D11TextRenderer(WrappedID3D11Device *wrapper)
VS = shaderCache->MakeVShader(fullhlsl.c_str(), "RENDERDOC_TextVS", "vs_4_0");
m_pDevice->InternalRef();
rm->SetInternalResource(VS);
PS = shaderCache->MakePShader(fullhlsl.c_str(), "RENDERDOC_TextPS", "ps_4_0");
m_pDevice->InternalRef();
rm->SetInternalResource(PS);
shaderCache->SetCaching(false);
}
@@ -388,7 +388,7 @@ HRESULT WrappedID3D12GraphicsCommandList2::Reset(ID3D12CommandAllocator *pAlloca
m_ListRecord->bakedCommands =
GetResourceManager()->AddResourceRecord(ResourceIDGen::GetNewUniqueID());
m_ListRecord->bakedCommands->type = Resource_GraphicsCommandList;
m_ListRecord->bakedCommands->SpecialResource = true;
m_ListRecord->bakedCommands->InternalResource = true;
m_ListRecord->bakedCommands->cmdInfo = new CmdListRecordingInfo();
{
+3 -3
View File
@@ -212,7 +212,7 @@ WrappedID3D12CommandQueue::WrappedID3D12CommandQueue(ID3D12CommandQueue *real,
m_QueueRecord = m_pDevice->GetResourceManager()->AddResourceRecord(m_ResourceID);
m_QueueRecord->type = Resource_CommandQueue;
m_QueueRecord->DataInSerialiser = false;
m_QueueRecord->SpecialResource = true;
m_QueueRecord->InternalResource = true;
m_QueueRecord->Length = 0;
}
@@ -792,7 +792,7 @@ WrappedID3D12GraphicsCommandList2::WrappedID3D12GraphicsCommandList2(ID3D12Graph
m_ListRecord = m_pDevice->GetResourceManager()->AddResourceRecord(m_ResourceID);
m_ListRecord->type = Resource_GraphicsCommandList;
m_ListRecord->DataInSerialiser = false;
m_ListRecord->SpecialResource = true;
m_ListRecord->InternalResource = true;
m_ListRecord->Length = 0;
m_ListRecord->cmdInfo = new CmdListRecordingInfo();
@@ -807,7 +807,7 @@ WrappedID3D12GraphicsCommandList2::WrappedID3D12GraphicsCommandList2(ID3D12Graph
m_CreationRecord =
m_pDevice->GetResourceManager()->AddResourceRecord(ResourceIDGen::GetNewUniqueID());
m_CreationRecord->type = Resource_GraphicsCommandList;
m_CreationRecord->SpecialResource = true;
m_CreationRecord->InternalResource = true;
m_ListRecord->AddParent(m_CreationRecord);
}
+9 -3
View File
@@ -228,12 +228,12 @@ WrappedID3D12Device::WrappedID3D12Device(ID3D12Device *realDevice, D3D12InitPara
m_DeviceRecord = GetResourceManager()->AddResourceRecord(m_ResourceID);
m_DeviceRecord->type = Resource_Device;
m_DeviceRecord->DataInSerialiser = false;
m_DeviceRecord->SpecialResource = true;
m_DeviceRecord->InternalResource = true;
m_DeviceRecord->Length = 0;
m_FrameCaptureRecord = GetResourceManager()->AddResourceRecord(ResourceIDGen::GetNewUniqueID());
m_FrameCaptureRecord->DataInSerialiser = false;
m_FrameCaptureRecord->SpecialResource = true;
m_FrameCaptureRecord->InternalResource = true;
m_FrameCaptureRecord->Length = 0;
RenderDoc::Inst().AddDeviceFrameCapturer((ID3D12Device *)this, this);
@@ -791,7 +791,6 @@ IUnknown *WrappedID3D12Device::WrapSwapchainBuffer(WrappedIDXGISwapChain4 *swap,
D3D12ResourceRecord *record = GetResourceManager()->AddResourceRecord(id);
record->type = Resource_Resource;
record->DataInSerialiser = false;
record->SpecialResource = true;
record->Length = 0;
WrappedID3D12Resource *wrapped = (WrappedID3D12Resource *)pRes;
@@ -2229,9 +2228,14 @@ void WrappedID3D12Device::CreateInternalResources()
CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), (void **)&m_GPUSyncFence);
m_GPUSyncHandle = ::CreateEvent(NULL, FALSE, FALSE, NULL);
GetResourceManager()->SetInternalResource(m_Alloc);
GetResourceManager()->SetInternalResource(m_GPUSyncFence);
CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, __uuidof(ID3D12CommandAllocator),
(void **)&m_DataUploadAlloc);
GetResourceManager()->SetInternalResource(m_DataUploadAlloc);
CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_DataUploadAlloc, NULL,
__uuidof(ID3D12GraphicsCommandList), (void **)&m_DataUploadList);
@@ -2243,6 +2247,8 @@ void WrappedID3D12Device::CreateInternalResources()
CreateDescriptorHeap(&desc, __uuidof(ID3D12DescriptorHeap), (void **)&m_RTVHeap);
GetResourceManager()->SetInternalResource(m_RTVHeap);
D3D12_CPU_DESCRIPTOR_HANDLE handle;
if(m_RTVHeap)
+1 -1
View File
@@ -163,7 +163,7 @@ bool WrappedID3D12Device::Serialise_CreateCommandAllocator(SerialiserType &ser,
GetResourceManager()->AddLiveResource(pCommandAllocator, ret);
AddResource(pCommandAllocator, ResourceType::Pool, "Command Queue");
AddResource(pCommandAllocator, ResourceType::Pool, "Command Allocator");
}
}
+7 -8
View File
@@ -694,15 +694,14 @@ template void D3D12ResourceManager::SerialiseResourceStates(
WriteSerialiser &ser, std::vector<D3D12_RESOURCE_BARRIER> &barriers,
std::map<ResourceId, SubresourceStateVector> &states);
bool D3D12ResourceManager::SerialisableResource(ResourceId id, D3D12ResourceRecord *record)
void D3D12ResourceManager::SetInternalResource(ID3D12DeviceChild *res)
{
if(record->type == Resource_GraphicsCommandList || record->type == Resource_CommandQueue)
return false;
if(m_Device->GetFrameCaptureResourceId() == id)
return false;
return true;
if(!RenderDoc::Inst().IsReplayApp())
{
D3D12ResourceRecord *record = GetResourceRecord(GetResID(res));
if(record)
record->InternalResource = true;
}
}
ResourceId D3D12ResourceManager::GetID(ID3D12DeviceChild *res)
+2 -1
View File
@@ -692,8 +692,9 @@ public:
template <typename SerialiserType>
bool Serialise_InitialState(SerialiserType &ser, ResourceId resid, ID3D12DeviceChild *res);
void SetInternalResource(ID3D12DeviceChild *res);
private:
bool SerialisableResource(ResourceId id, D3D12ResourceRecord *record);
ResourceId GetID(ID3D12DeviceChild *res);
bool ResourceTypeRelease(ID3D12DeviceChild *res);
@@ -34,6 +34,8 @@
D3D12TextRenderer::D3D12TextRenderer(WrappedID3D12Device *wrapper)
{
D3D12ResourceManager *rm = wrapper->GetResourceManager();
HRESULT hr = S_OK;
D3D12_DESCRIPTOR_HEAP_DESC desc;
@@ -49,6 +51,8 @@ D3D12TextRenderer::D3D12TextRenderer(WrappedID3D12Device *wrapper)
RDCERR("Couldn't create font descriptor heap! HRESULT: %s", ToStr(hr).c_str());
}
rm->SetInternalResource(descHeap);
D3D12_HEAP_PROPERTIES uploadHeap;
uploadHeap.Type = D3D12_HEAP_TYPE_UPLOAD;
uploadHeap.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
@@ -83,6 +87,8 @@ D3D12TextRenderer::D3D12TextRenderer(WrappedID3D12Device *wrapper)
if(FAILED(hr))
RDCERR("Failed to create uploadBuf HRESULT: %s", ToStr(hr).c_str());
rm->SetInternalResource(uploadBuf);
D3D12_RESOURCE_DESC texDesc;
texDesc.Alignment = 0;
texDesc.DepthOrArraySize = 1;
@@ -105,6 +111,8 @@ D3D12TextRenderer::D3D12TextRenderer(WrappedID3D12Device *wrapper)
if(FAILED(hr))
RDCERR("Failed to create FontTex HRESULT: %s", ToStr(hr).c_str());
rm->SetInternalResource(Tex);
std::string font = GetEmbeddedResource(sourcecodepro_ttf);
byte *ttfdata = (byte *)font.c_str();
@@ -218,6 +226,8 @@ D3D12TextRenderer::D3D12TextRenderer(WrappedID3D12Device *wrapper)
if(FAILED(hr))
RDCERR("Couldn't create GlyphData cbuffer! %s", ToStr(hr).c_str());
rm->SetInternalResource(GlyphData);
for(int i = 0; i < numChars; i++)
{
stbtt_bakedchar *b = chardata + i;
@@ -255,6 +265,11 @@ D3D12TextRenderer::D3D12TextRenderer(WrappedID3D12Device *wrapper)
D3D12_RESOURCE_STATE_GENERIC_READ, NULL,
__uuidof(ID3D12Resource), (void **)&Constants);
if(FAILED(hr))
RDCERR("Couldn't create Constants cbuffer! %s", ToStr(hr).c_str());
rm->SetInternalResource(Constants);
cbDesc.Width = FONT_BUFFER_CHARS * sizeof(uint32_t) * 4;
hr = wrapper->CreateCommittedResource(&heapProps, D3D12_HEAP_FLAG_NONE, &cbDesc,
D3D12_RESOURCE_STATE_GENERIC_READ, NULL,
@@ -263,6 +278,8 @@ D3D12TextRenderer::D3D12TextRenderer(WrappedID3D12Device *wrapper)
if(FAILED(hr))
RDCERR("Couldn't create CharBuffer cbuffer! %s", ToStr(hr).c_str());
rm->SetInternalResource(CharBuffer);
ConstRingIdx = 0;
std::vector<D3D12_ROOT_PARAMETER1> rootSig;
@@ -325,6 +342,11 @@ D3D12TextRenderer::D3D12TextRenderer(WrappedID3D12Device *wrapper)
hr = wrapper->CreateRootSignature(0, root->GetBufferPointer(), root->GetBufferSize(),
__uuidof(ID3D12RootSignature), (void **)&RootSig);
if(FAILED(hr))
RDCERR("Couldn't create RootSig! %s", ToStr(hr).c_str());
rm->SetInternalResource(RootSig);
SAFE_RELEASE(root);
std::string fullhlsl = "";
@@ -379,6 +401,8 @@ D3D12TextRenderer::D3D12TextRenderer(WrappedID3D12Device *wrapper)
if(FAILED(hr))
RDCERR("Couldn't create BGRA8 Pipe! HRESULT: %s", ToStr(hr).c_str());
rm->SetInternalResource(Pipe[BGRA8_BACKBUFFER]);
pipeDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
hr = wrapper->CreateGraphicsPipelineState(&pipeDesc, __uuidof(ID3D12PipelineState),
@@ -387,6 +411,8 @@ D3D12TextRenderer::D3D12TextRenderer(WrappedID3D12Device *wrapper)
if(FAILED(hr))
RDCERR("Couldn't create RGBA8 Pipe! HRESULT: %s", ToStr(hr).c_str());
rm->SetInternalResource(Pipe[RGBA8_BACKBUFFER]);
pipeDesc.RTVFormats[0] = DXGI_FORMAT_R16G16B16A16_FLOAT;
hr = wrapper->CreateGraphicsPipelineState(&pipeDesc, __uuidof(ID3D12PipelineState),
@@ -395,6 +421,8 @@ D3D12TextRenderer::D3D12TextRenderer(WrappedID3D12Device *wrapper)
if(FAILED(hr))
RDCERR("Couldn't create RGBA16 Pipe! HRESULT: %s", ToStr(hr).c_str());
rm->SetInternalResource(Pipe[RGBA16_BACKBUFFER]);
SAFE_RELEASE(TextVS);
SAFE_RELEASE(TextPS);
}
+1 -1
View File
@@ -27,7 +27,7 @@
#include "d3d8_manager.h"
#include "d3d8_resources.h"
bool D3D8ResourceManager::SerialisableResource(ResourceId id, D3D8ResourceRecord *record)
bool D3D8ResourceManager::AutoReferenceResource(ResourceId id, D3D8ResourceRecord *record)
{
return true;
}
+1 -1
View File
@@ -69,7 +69,7 @@ class D3D8ResourceManager : public ResourceManager<D3D8ResourceManagerConfigurat
public:
D3D8ResourceManager(WrappedD3DDevice8 *dev) : m_Device(dev) {}
private:
bool SerialisableResource(ResourceId id, D3D8ResourceRecord *record);
bool AutoReferenceResource(ResourceId id, D3D8ResourceRecord *record);
ResourceId GetID(IUnknown *res);
bool ResourceTypeRelease(IUnknown *res);
+15 -3
View File
@@ -564,12 +564,12 @@ WrappedOpenGL::WrappedOpenGL(GLPlatform &platform)
m_DeviceRecord = GetResourceManager()->AddResourceRecord(m_DeviceResourceID);
m_DeviceRecord->DataInSerialiser = false;
m_DeviceRecord->Length = 0;
m_DeviceRecord->SpecialResource = true;
m_DeviceRecord->InternalResource = true;
m_ContextRecord = GetResourceManager()->AddResourceRecord(m_ContextResourceID);
m_ContextRecord->DataInSerialiser = false;
m_ContextRecord->Length = 0;
m_ContextRecord->SpecialResource = true;
m_ContextRecord->InternalResource = true;
// we register an ID for the backbuffer, this will be tied to the fake-created backbuffer on
// replay, and every context's FBO 0 will be pointed to it with ReplaceResource
@@ -921,7 +921,7 @@ void WrappedOpenGL::ContextData::CreateResourceRecord(WrappedOpenGL *driver, voi
m_ContextDataRecord = driver->GetResourceManager()->AddResourceRecord(m_ContextDataResourceID);
m_ContextDataRecord->DataInSerialiser = false;
m_ContextDataRecord->Length = 0;
m_ContextDataRecord->SpecialResource = true;
m_ContextDataRecord->InternalResource = true;
}
}
@@ -1186,6 +1186,12 @@ void WrappedOpenGL::ActivateContext(GLWindowingData winData)
gl_CurChunk = GLChunk::glBufferData;
glBufferData(eGL_ARRAY_BUFFER, 64, NULL, eGL_DYNAMIC_DRAW);
// we mark these buffers as internal since initial contents are not needed - they're
// entirely handled internally and buffer data is uploaded immediately before draws - and
// we don't want them to be pulled in unless explicitly referenced.
GetResourceManager()->SetInternalResource(
BufferRes(GetCtx(), ctxdata.m_ClientMemoryVBOs[i]));
if(HasExt[KHR_debug])
{
gl_CurChunk = GLChunk::glObjectLabel;
@@ -1200,6 +1206,8 @@ void WrappedOpenGL::ActivateContext(GLWindowingData winData)
gl_CurChunk = GLChunk::glBindBuffer;
glBindBuffer(eGL_ELEMENT_ARRAY_BUFFER, ctxdata.m_ClientMemoryIBO);
GetResourceManager()->SetInternalResource(BufferRes(GetCtx(), ctxdata.m_ClientMemoryIBO));
gl_CurChunk = GLChunk::glBufferData;
glBufferData(eGL_ELEMENT_ARRAY_BUFFER, 64, NULL, eGL_DYNAMIC_DRAW);
@@ -1248,6 +1256,8 @@ void WrappedOpenGL::ActivateContext(GLWindowingData winData)
record->AddChunk(scope.Get());
}
GetResourceManager()->SetInternalResource(VertexArrayRes(GetCtx(), 0));
// we immediately mark it dirty since the vertex array tracking functions expect a proper
// VAO
GetResourceManager()->MarkDirtyResource(id);
@@ -1266,6 +1276,8 @@ void WrappedOpenGL::ActivateContext(GLWindowingData winData)
SCOPED_SERIALISE_CHUNK(GLChunk::glContextInit);
Serialise_ContextInit(ser);
GetResourceManager()->SetInternalResource(FramebufferRes(GetCtx(), 0));
m_DeviceRecord->AddChunk(scope.Get());
}
}
-2
View File
@@ -480,8 +480,6 @@ public:
uint64_t GetLogVersion() { return m_SectionVersion; }
static std::string GetChunkName(uint32_t idx);
GLResourceManager *GetResourceManager() { return m_ResourceManager; }
ResourceId GetDeviceResourceID() { return m_DeviceResourceID; }
ResourceId GetContextResourceID() { return m_ContextResourceID; }
CaptureState GetState() { return m_State; }
GLReplay *GetReplay() { return &m_Replay; }
WriteSerialiser &GetSerialiser() { return m_ScratchSerialiser; }
+7 -4
View File
@@ -113,11 +113,14 @@ void GLResourceManager::MarkFBOReferenced(GLResource res, FrameRefType ref)
}
}
bool GLResourceManager::SerialisableResource(ResourceId id, GLResourceRecord *record)
void GLResourceManager::SetInternalResource(GLResource res)
{
if(id == m_Driver->GetContextResourceID())
return false;
return true;
if(!RenderDoc::Inst().IsReplayApp())
{
GLResourceRecord *record = GetResourceRecord(res);
if(record)
record->InternalResource = true;
}
}
bool GLResourceManager::ResourceTypeRelease(GLResource res)
+2 -2
View File
@@ -244,9 +244,9 @@ public:
return Serialise_InitialState<WriteSerialiser>(ser, resid, res);
}
private:
bool SerialisableResource(ResourceId id, GLResourceRecord *record);
void SetInternalResource(GLResource res);
private:
bool ResourceTypeRelease(GLResource res);
bool Force_InitialState(GLResource res, bool prepare);
bool Need_InitialStateChunk(GLResource res);
+1 -1
View File
@@ -153,7 +153,7 @@ WrappedVulkan::WrappedVulkan() : m_RenderState(this, &m_CreationInfo)
m_FrameCaptureRecord = GetResourceManager()->AddResourceRecord(ResourceIDGen::GetNewUniqueID());
m_FrameCaptureRecord->DataInSerialiser = false;
m_FrameCaptureRecord->Length = 0;
m_FrameCaptureRecord->SpecialResource = true;
m_FrameCaptureRecord->InternalResource = true;
}
else
{
-1
View File
@@ -802,7 +802,6 @@ public:
APIProperties APIProps;
ResourceId GetContextResourceID() { return m_FrameCaptureRecord->GetResourceID(); }
static std::string GetChunkName(uint32_t idx);
VulkanResourceManager *GetResourceManager() { return m_ResourceManager; }
VulkanDebugManager *GetDebugManager() { return m_DebugManager; }
+21
View File
@@ -138,6 +138,8 @@ static void create(WrappedVulkan *driver, const char *objName, const int line,
VkResult vkr = driver->vkCreateRenderPass(driver->GetDev(), &rpinfo, NULL, renderPass);
if(vkr != VK_SUCCESS)
RDCERR("Failed creating object %s at line %i, vkr was %s", objName, line, ToStr(vkr).c_str());
driver->GetResourceManager()->SetInternalResource(GetResID(*renderPass));
}
// Create a compute pipeline with a shader module
@@ -401,6 +403,8 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver)
m_Device = m_pDriver->GetDev();
VkDevice dev = m_Device;
VulkanResourceManager *rm = driver->GetResourceManager();
VkResult vkr = VK_SUCCESS;
VulkanShaderCache *shaderCache = driver->GetShaderCache();
@@ -421,9 +425,13 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver)
CREATE_OBJECT(m_ArrayMSSampler, VK_FILTER_NEAREST);
rm->SetInternalResource(GetResID(m_ArrayMSSampler));
vkr = m_pDriver->vkCreateDescriptorPool(dev, &poolInfo, NULL, &m_ArrayMSDescriptorPool);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_ArrayMSDescriptorPool));
CREATE_OBJECT(m_ArrayMSDescSetLayout,
{
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_ALL, NULL},
@@ -431,8 +439,12 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver)
{2, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, VK_SHADER_STAGE_ALL, NULL},
});
rm->SetInternalResource(GetResID(m_ArrayMSDescSetLayout));
CREATE_OBJECT(m_ArrayMSPipeLayout, m_ArrayMSDescSetLayout, sizeof(Vec4u));
rm->SetInternalResource(GetResID(m_ArrayMSPipeLayout));
//////////////////////////////////////////////////////////////////
// Color MS to Array copy (via compute)
@@ -441,11 +453,16 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver)
CREATE_OBJECT(m_Array2MSPipe, m_ArrayMSPipeLayout,
shaderCache->GetBuiltinModule(BuiltinShader::Array2MSCS));
rm->SetInternalResource(GetResID(m_MS2ArrayPipe));
rm->SetInternalResource(GetResID(m_Array2MSPipe));
//////////////////////////////////////////////////////////////////
// Depth MS to Array copy (via graphics)
CREATE_OBJECT(m_ArrayMSDescSet, m_ArrayMSDescriptorPool, m_ArrayMSDescSetLayout);
rm->SetInternalResource(GetResID(m_ArrayMSDescSet));
VkFormat formats[] = {
VK_FORMAT_D16_UNORM, VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_X8_D24_UNORM_PACK32,
VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT,
@@ -499,6 +516,8 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver)
CREATE_OBJECT(m_DepthMS2ArrayPipe[f], depthPipeInfo);
rm->SetInternalResource(GetResID(m_DepthMS2ArrayPipe[f]));
m_pDriver->vkDestroyRenderPass(dev, depthMS2ArrayRP, NULL);
for(size_t s = 0; s < ARRAY_COUNT(sampleCounts); s++)
@@ -523,6 +542,8 @@ VulkanDebugManager::VulkanDebugManager(WrappedVulkan *driver)
CREATE_OBJECT(m_DepthArray2MSPipe[f][s], depthPipeInfo);
rm->SetInternalResource(GetResID(m_DepthArray2MSPipe[f][s]));
m_pDriver->vkDestroyRenderPass(dev, depthArray2MSRP, NULL);
}
}
+10 -7
View File
@@ -25,13 +25,6 @@
#include "vk_manager.h"
#include "vk_core.h"
bool VulkanResourceManager::SerialisableResource(ResourceId id, VkResourceRecord *record)
{
if(record->SpecialResource || id == m_Core->GetContextResourceID())
return false;
return true;
}
// debugging logging for barriers
#if 0
#define TRDBG(...) RDCLOG(__VA_ARGS__)
@@ -381,6 +374,16 @@ void VulkanResourceManager::MarkSparseMapReferenced(SparseMapping *sparse)
}
}
void VulkanResourceManager::SetInternalResource(ResourceId id)
{
if(!RenderDoc::Inst().IsReplayApp())
{
VkResourceRecord *record = GetResourceRecord(id);
if(record)
record->InternalResource = true;
}
}
void VulkanResourceManager::ApplyBarriers(uint32_t queueFamilyIndex,
vector<pair<ResourceId, ImageRegionState> > &states,
map<ResourceId, ImageLayouts> &layouts)
+2 -2
View File
@@ -406,9 +406,9 @@ public:
// helper for sparse mappings
void MarkSparseMapReferenced(SparseMapping *sparse);
private:
bool SerialisableResource(ResourceId id, VkResourceRecord *record);
void SetInternalResource(ResourceId id);
private:
bool ResourceTypeRelease(WrappedVkRes *res);
bool Force_InitialState(WrappedVkRes *res, bool prepare);
+42
View File
@@ -35,6 +35,8 @@ VulkanTextRenderer::VulkanTextRenderer(WrappedVulkan *driver)
m_pDriver = driver;
m_Device = driver->GetDev();
VulkanResourceManager *rm = driver->GetResourceManager();
VkDevice dev = m_Device;
VkResult vkr = VK_SUCCESS;
@@ -53,6 +55,8 @@ VulkanTextRenderer::VulkanTextRenderer(WrappedVulkan *driver)
vkr = m_pDriver->vkCreateSampler(dev, &sampInfo, NULL, &m_LinearSampler);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_LinearSampler));
// just need enough for text rendering
VkDescriptorPoolSize captureDescPoolTypes[] = {
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1},
@@ -73,6 +77,8 @@ VulkanTextRenderer::VulkanTextRenderer(WrappedVulkan *driver)
vkr = m_pDriver->vkCreateDescriptorPool(dev, &descpoolInfo, NULL, &m_DescriptorPool);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_DescriptorPool));
// declare some common creation info structs
VkPipelineLayoutCreateInfo pipeLayoutInfo = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
pipeLayoutInfo.setLayoutCount = 1;
@@ -110,15 +116,19 @@ VulkanTextRenderer::VulkanTextRenderer(WrappedVulkan *driver)
attDesc.format = VK_FORMAT_R8G8B8A8_SRGB;
m_pDriver->vkCreateRenderPass(dev, &rpinfo, NULL, &RGBA8sRGBRP);
rm->SetInternalResource(GetResID(RGBA8sRGBRP));
attDesc.format = VK_FORMAT_R8G8B8A8_UNORM;
m_pDriver->vkCreateRenderPass(dev, &rpinfo, NULL, &RGBA8LinearRP);
rm->SetInternalResource(GetResID(RGBA8LinearRP));
attDesc.format = VK_FORMAT_B8G8R8A8_SRGB;
m_pDriver->vkCreateRenderPass(dev, &rpinfo, NULL, &BGRA8sRGBRP);
rm->SetInternalResource(GetResID(BGRA8sRGBRP));
attDesc.format = VK_FORMAT_B8G8R8A8_UNORM;
m_pDriver->vkCreateRenderPass(dev, &rpinfo, NULL, &BGRA8LinearRP);
rm->SetInternalResource(GetResID(BGRA8LinearRP));
}
// declare the pipeline creation info and all of its sub-structures
@@ -229,24 +239,36 @@ VulkanTextRenderer::VulkanTextRenderer(WrappedVulkan *driver)
vkr = m_pDriver->vkCreateDescriptorSetLayout(dev, &descsetLayoutInfo, NULL, &m_TextDescSetLayout);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_TextDescSetLayout));
pipeLayoutInfo.pSetLayouts = &m_TextDescSetLayout;
vkr = m_pDriver->vkCreatePipelineLayout(dev, &pipeLayoutInfo, NULL, &m_TextPipeLayout);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_TextPipeLayout));
descSetAllocInfo.pSetLayouts = &m_TextDescSetLayout;
vkr = m_pDriver->vkAllocateDescriptorSets(dev, &descSetAllocInfo, &m_TextDescSet);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_TextDescSet));
// make the ring conservatively large to handle many lines of text * several frames
m_TextGeneralUBO.Create(driver, dev, 128, 100, 0);
RDCCOMPILE_ASSERT(sizeof(FontUBOData) <= 128, "font uniforms size");
rm->SetInternalResource(GetResID(m_TextGeneralUBO.buf));
rm->SetInternalResource(GetResID(m_TextGeneralUBO.mem));
// we only use a subset of the [MAX_SINGLE_LINE_LENGTH] array needed for each line, so this ring
// can be smaller
m_TextStringUBO.Create(driver, dev, 4096, 10, 0);
RDCCOMPILE_ASSERT(sizeof(StringUBOData) <= 4096, "font uniforms size");
rm->SetInternalResource(GetResID(m_TextStringUBO.buf));
rm->SetInternalResource(GetResID(m_TextStringUBO.mem));
pipeInfo.layout = m_TextPipeLayout;
pipeInfo.renderPass = RGBA8sRGBRP;
@@ -254,21 +276,29 @@ VulkanTextRenderer::VulkanTextRenderer(WrappedVulkan *driver)
&m_TextPipeline[0]);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_TextPipeline[0]));
pipeInfo.renderPass = RGBA8LinearRP;
vkr = m_pDriver->vkCreateGraphicsPipelines(dev, VK_NULL_HANDLE, 1, &pipeInfo, NULL,
&m_TextPipeline[1]);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_TextPipeline[1]));
pipeInfo.renderPass = BGRA8sRGBRP;
vkr = m_pDriver->vkCreateGraphicsPipelines(dev, VK_NULL_HANDLE, 1, &pipeInfo, NULL,
&m_TextPipeline[2]);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_TextPipeline[2]));
pipeInfo.renderPass = BGRA8LinearRP;
vkr = m_pDriver->vkCreateGraphicsPipelines(dev, VK_NULL_HANDLE, 1, &pipeInfo, NULL,
&m_TextPipeline[3]);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_TextPipeline[3]));
// create the actual font texture data and glyph data, for upload
{
const uint32_t width = FONT_TEX_WIDTH, height = FONT_TEX_HEIGHT;
@@ -323,6 +353,8 @@ VulkanTextRenderer::VulkanTextRenderer(WrappedVulkan *driver)
vkr = m_pDriver->vkCreateImage(dev, &imInfo, NULL, &m_TextAtlas);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_TextAtlas));
VkMemoryRequirements mrq = {0};
m_pDriver->vkGetImageMemoryRequirements(dev, m_TextAtlas, &mrq);
@@ -335,6 +367,8 @@ VulkanTextRenderer::VulkanTextRenderer(WrappedVulkan *driver)
vkr = m_pDriver->vkAllocateMemory(dev, &allocInfo, NULL, &m_TextAtlasMem);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_TextAtlasMem));
vkr = m_pDriver->vkBindImageMemory(dev, m_TextAtlas, m_TextAtlasMem, 0);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
@@ -353,11 +387,16 @@ VulkanTextRenderer::VulkanTextRenderer(WrappedVulkan *driver)
vkr = m_pDriver->vkCreateImageView(dev, &viewInfo, NULL, &m_TextAtlasView);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
rm->SetInternalResource(GetResID(m_TextAtlasView));
// create temporary memory and buffer to upload atlas
// doesn't need to be ring'd, as it's static
m_TextAtlasUpload.Create(driver, dev, 32768, 1, 0);
RDCCOMPILE_ASSERT(width * height <= 32768, "font uniform size");
rm->SetInternalResource(GetResID(m_TextAtlasUpload.buf));
rm->SetInternalResource(GetResID(m_TextAtlasUpload.mem));
byte *pData = (byte *)m_TextAtlasUpload.Map();
RDCASSERT(pData);
@@ -370,6 +409,9 @@ VulkanTextRenderer::VulkanTextRenderer(WrappedVulkan *driver)
m_TextGlyphUBO.Create(driver, dev, 4096, 1, 0);
RDCCOMPILE_ASSERT(sizeof(Vec4f) * 2 * (numChars + 1) < 4096, "font uniform size");
rm->SetInternalResource(GetResID(m_TextGlyphUBO.buf));
rm->SetInternalResource(GetResID(m_TextGlyphUBO.mem));
FontGlyphData *glyphData = (FontGlyphData *)m_TextGlyphUBO.Map();
glyphData[0].posdata = Vec4f();
@@ -187,6 +187,8 @@ VulkanShaderCache::VulkanShaderCache(WrappedVulkan *driver)
VkResult vkr =
driver->vkCreateShaderModule(m_Device, &modinfo, NULL, &m_BuiltinShaderModules[i]);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
driver->GetResourceManager()->SetInternalResource(GetResID(m_BuiltinShaderModules[i]));
}
}
@@ -526,9 +526,10 @@ VkResult WrappedVulkan::vkAllocateCommandBuffers(VkDevice device,
// might be partially recorded at the time of a submit of a previously baked list.
VkResourceRecord *allocRecord =
GetResourceManager()->AddResourceRecord(ResourceIDGen::GetNewUniqueID());
allocRecord->SpecialResource = true;
allocRecord->InternalResource = true;
allocRecord->AddChunk(chunk);
record->AddParent(allocRecord);
record->InternalResource = true;
record->bakedCommands = NULL;
@@ -840,7 +841,7 @@ VkResult WrappedVulkan::vkBeginCommandBuffer(VkCommandBuffer commandBuffer,
record->bakedCommands->Delete(GetResourceManager());
record->bakedCommands = GetResourceManager()->AddResourceRecord(ResourceIDGen::GetNewUniqueID());
record->bakedCommands->SpecialResource = true;
record->bakedCommands->InternalResource = true;
record->bakedCommands->Resource = (WrappedVkRes *)commandBuffer;
record->bakedCommands->cmdInfo = new CmdBufferRecordingInfo();
@@ -259,7 +259,7 @@ VkResult WrappedVulkan::vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR
VkResourceRecord *record = GetResourceManager()->AddResourceRecord(pSwapchainImages[i]);
VkResourceRecord *swaprecord = GetRecord(swapchain);
record->SpecialResource = true;
record->InternalResource = true;
record->AddParent(swaprecord);
@@ -498,6 +498,7 @@ void WrappedVulkan::WrapAndProcessCreatedSwapchain(VkDevice device,
RDCASSERTEQUAL(vkr, VK_SUCCESS);
GetResourceManager()->WrapResource(Unwrap(device), swapInfo.rp);
GetResourceManager()->SetInternalResource(GetResID(swapInfo.rp));
}
// serialise out the swap chain images
@@ -561,6 +562,7 @@ void WrappedVulkan::WrapAndProcessCreatedSwapchain(VkDevice device,
RDCASSERTEQUAL(vkr, VK_SUCCESS);
GetResourceManager()->WrapResource(Unwrap(device), swapImInfo.view);
GetResourceManager()->SetInternalResource(GetResID(swapImInfo.view));
VkFramebufferCreateInfo fbinfo = {
VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
@@ -578,6 +580,7 @@ void WrappedVulkan::WrapAndProcessCreatedSwapchain(VkDevice device,
RDCASSERTEQUAL(vkr, VK_SUCCESS);
GetResourceManager()->WrapResource(Unwrap(device), swapImInfo.fb);
GetResourceManager()->SetInternalResource(GetResID(swapImInfo.fb));
}
}