mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-29 13:20:54 +00:00
Fix refcounting of D3D12 shader objects
This commit is contained in:
@@ -221,6 +221,9 @@ public:
|
||||
else
|
||||
RDCWARN("No device pointer, is a deleted resource being Release()d?");
|
||||
|
||||
if(ret == 0)
|
||||
return ret;
|
||||
|
||||
if(ret >= m_InternalRefcount)
|
||||
ret -= m_InternalRefcount;
|
||||
|
||||
|
||||
@@ -437,7 +437,8 @@ bool WrappedID3D12Device::Serialise_CreateGraphicsPipelineState(
|
||||
}
|
||||
else
|
||||
{
|
||||
WrappedID3D12Shader *entry = WrappedID3D12Shader::AddShader(*shaders[i], this, wrapped);
|
||||
WrappedID3D12Shader *entry = WrappedID3D12Shader::AddShader(*shaders[i], this);
|
||||
entry->AddRef();
|
||||
|
||||
shaders[i]->pShaderBytecode = entry;
|
||||
|
||||
@@ -560,7 +561,9 @@ HRESULT WrappedID3D12Device::CreateGraphicsPipelineState(const D3D12_GRAPHICS_PI
|
||||
}
|
||||
else
|
||||
{
|
||||
shaders[i]->pShaderBytecode = WrappedID3D12Shader::AddShader(*shaders[i], this, NULL);
|
||||
WrappedID3D12Shader *sh = WrappedID3D12Shader::AddShader(*shaders[i], this);
|
||||
sh->AddRef();
|
||||
shaders[i]->pShaderBytecode = sh;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -643,8 +646,8 @@ bool WrappedID3D12Device::Serialise_CreateComputePipelineState(
|
||||
|
||||
wrapped->compute = new D3D12_EXPANDED_PIPELINE_STATE_STREAM_DESC(Descriptor);
|
||||
|
||||
WrappedID3D12Shader *entry =
|
||||
WrappedID3D12Shader::AddShader(wrapped->compute->CS, this, wrapped);
|
||||
WrappedID3D12Shader *entry = WrappedID3D12Shader::AddShader(wrapped->compute->CS, this);
|
||||
entry->AddRef();
|
||||
|
||||
AddResourceCurChunk(entry->GetResourceID());
|
||||
|
||||
@@ -710,8 +713,9 @@ HRESULT WrappedID3D12Device::CreateComputePipelineState(const D3D12_COMPUTE_PIPE
|
||||
|
||||
wrapped->compute = new D3D12_EXPANDED_PIPELINE_STATE_STREAM_DESC(*pDesc);
|
||||
|
||||
wrapped->compute->CS.pShaderBytecode =
|
||||
WrappedID3D12Shader::AddShader(wrapped->compute->CS, this, NULL);
|
||||
WrappedID3D12Shader *sh = WrappedID3D12Shader::AddShader(wrapped->compute->CS, this);
|
||||
sh->AddRef();
|
||||
wrapped->compute->CS.pShaderBytecode = sh;
|
||||
}
|
||||
|
||||
*ppPipelineState = (ID3D12PipelineState *)wrapped;
|
||||
|
||||
@@ -84,7 +84,8 @@ bool WrappedID3D12Device::Serialise_CreatePipelineState(SerialiserType &ser,
|
||||
}
|
||||
else
|
||||
{
|
||||
WrappedID3D12Shader *entry = WrappedID3D12Shader::AddShader(*shaders[i], this, wrapped);
|
||||
WrappedID3D12Shader *entry = WrappedID3D12Shader::AddShader(*shaders[i], this);
|
||||
entry->AddRef();
|
||||
|
||||
shaders[i]->pShaderBytecode = entry;
|
||||
|
||||
@@ -212,7 +213,9 @@ HRESULT WrappedID3D12Device::CreatePipelineState(const D3D12_PIPELINE_STATE_STRE
|
||||
}
|
||||
else
|
||||
{
|
||||
shaders[i]->pShaderBytecode = WrappedID3D12Shader::AddShader(*shaders[i], this, NULL);
|
||||
WrappedID3D12Shader *sh = WrappedID3D12Shader::AddShader(*shaders[i], this);
|
||||
sh->AddRef();
|
||||
shaders[i]->pShaderBytecode = sh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2848,7 +2848,9 @@ void D3D12Replay::BuildShader(ShaderEncoding sourceEncoding, const bytebuf &sour
|
||||
byteCode.BytecodeLength = dxbcLength;
|
||||
byteCode.pShaderBytecode = dxbcBytes;
|
||||
|
||||
WrappedID3D12Shader *sh = WrappedID3D12Shader::AddShader(byteCode, m_pDevice, NULL);
|
||||
WrappedID3D12Shader *sh = WrappedID3D12Shader::AddShader(byteCode, m_pDevice);
|
||||
|
||||
sh->AddRef();
|
||||
|
||||
id = sh->GetResourceID();
|
||||
}
|
||||
|
||||
@@ -65,14 +65,7 @@ TrackedResource12 *GetTracked(ID3D12Object *ptr)
|
||||
if(ptr == NULL)
|
||||
return NULL;
|
||||
|
||||
#undef D3D12_TYPE_MACRO
|
||||
#define D3D12_TYPE_MACRO(iface) \
|
||||
if(UnwrapHelper<iface>::IsAlloc(ptr)) \
|
||||
return (TrackedResource12 *)GetWrapped((iface *)ptr);
|
||||
|
||||
ALL_D3D12_TYPES;
|
||||
|
||||
return NULL;
|
||||
return (TrackedResource12 *)(WrappedDeviceChild12<ID3D12DeviceChild> *)ptr;
|
||||
}
|
||||
|
||||
template <>
|
||||
@@ -81,13 +74,6 @@ ID3D12Object *Unwrap(ID3D12Object *ptr)
|
||||
if(ptr == NULL)
|
||||
return NULL;
|
||||
|
||||
#undef D3D12_TYPE_MACRO
|
||||
#define D3D12_TYPE_MACRO(iface) \
|
||||
if(UnwrapHelper<iface>::IsAlloc(ptr)) \
|
||||
return (ID3D12Object *)GetWrapped((iface *)ptr)->GetReal();
|
||||
|
||||
ALL_D3D12_TYPES;
|
||||
|
||||
if(WrappedID3D12GraphicsCommandList::IsAlloc(ptr))
|
||||
return (ID3D12Object *)(((WrappedID3D12GraphicsCommandList *)ptr)->GetReal());
|
||||
if(WrappedID3D12CommandQueue::IsAlloc(ptr))
|
||||
@@ -104,21 +90,12 @@ ResourceId GetResID(ID3D12Object *ptr)
|
||||
if(ptr == NULL)
|
||||
return ResourceId();
|
||||
|
||||
TrackedResource12 *res = GetTracked(ptr);
|
||||
if(WrappedID3D12GraphicsCommandList::IsAlloc(ptr))
|
||||
return ((WrappedID3D12GraphicsCommandList *)ptr)->GetResourceID();
|
||||
if(WrappedID3D12CommandQueue::IsAlloc(ptr))
|
||||
return ((WrappedID3D12CommandQueue *)ptr)->GetResourceID();
|
||||
|
||||
if(res == NULL)
|
||||
{
|
||||
if(WrappedID3D12GraphicsCommandList::IsAlloc(ptr))
|
||||
return ((WrappedID3D12GraphicsCommandList *)ptr)->GetResourceID();
|
||||
if(WrappedID3D12CommandQueue::IsAlloc(ptr))
|
||||
return ((WrappedID3D12CommandQueue *)ptr)->GetResourceID();
|
||||
|
||||
RDCERR("Unknown type of ptr 0x%p", ptr);
|
||||
|
||||
return ResourceId();
|
||||
}
|
||||
|
||||
return res->GetResourceID();
|
||||
return GetTracked(ptr)->GetResourceID();
|
||||
}
|
||||
|
||||
template <>
|
||||
@@ -127,21 +104,12 @@ D3D12ResourceRecord *GetRecord(ID3D12Object *ptr)
|
||||
if(ptr == NULL)
|
||||
return NULL;
|
||||
|
||||
TrackedResource12 *res = GetTracked(ptr);
|
||||
if(WrappedID3D12GraphicsCommandList::IsAlloc(ptr))
|
||||
return ((WrappedID3D12GraphicsCommandList *)ptr)->GetResourceRecord();
|
||||
if(WrappedID3D12CommandQueue::IsAlloc(ptr))
|
||||
return ((WrappedID3D12CommandQueue *)ptr)->GetResourceRecord();
|
||||
|
||||
if(res == NULL)
|
||||
{
|
||||
if(WrappedID3D12GraphicsCommandList::IsAlloc(ptr))
|
||||
return ((WrappedID3D12GraphicsCommandList *)ptr)->GetResourceRecord();
|
||||
if(WrappedID3D12CommandQueue::IsAlloc(ptr))
|
||||
return ((WrappedID3D12CommandQueue *)ptr)->GetResourceRecord();
|
||||
|
||||
RDCERR("Unknown type of ptr 0x%p", ptr);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return res->GetResourceRecord();
|
||||
return GetTracked(ptr)->GetResourceRecord();
|
||||
}
|
||||
|
||||
template <>
|
||||
|
||||
@@ -695,16 +695,13 @@ public:
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
static ShaderEntry *AddShader(const D3D12_SHADER_BYTECODE &byteCode,
|
||||
WrappedID3D12Device *device, WrappedID3D12PipelineState *pipeline)
|
||||
static ShaderEntry *AddShader(const D3D12_SHADER_BYTECODE &byteCode, WrappedID3D12Device *device)
|
||||
{
|
||||
DXBCKey key(byteCode);
|
||||
ShaderEntry *shader = m_Shaders[key];
|
||||
|
||||
if(shader == NULL)
|
||||
shader = m_Shaders[key] = new ShaderEntry(byteCode, device);
|
||||
else
|
||||
shader->AddRef();
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user