Prevent unnecessary copies of DXBCFile*

* The DXBCFile* is new'd in the wrapped CreateShader function and passed
  to the wrapped shader instance, and ownership of the pointer lives
  with the ShaderEntry in WrappedShader::m_ShaderList.
* On destruction when a shader removes itself from that list, the
  DXBCFile* is deleted.
* The same lifespan applies to the ShaderReflection*
This commit is contained in:
baldurk
2015-05-02 16:45:09 +02:00
parent 26b9d7902b
commit 397ef85342
8 changed files with 63 additions and 101 deletions
+1 -1
View File
@@ -3359,7 +3359,7 @@ bool D3D11DebugManager::RenderTexture(TextureDisplay cfg, bool blendAlpha)
if(it != WrappedShader::m_ShaderList.end())
{
auto dxbc = it->second.m_DXBCFile;
auto dxbc = it->second->GetDXBC();
RDCASSERT(dxbc);
RDCASSERT(dxbc->m_Type == D3D11_SHVER_PIXEL_SHADER);
+14 -14
View File
@@ -1204,7 +1204,7 @@ bool WrappedID3D11Device::Serialise_CreateVertexShader(
}
else
{
ret = new WrappedID3D11Shader<ID3D11VertexShader>(ret, DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
ret = new WrappedID3D11Shader<ID3D11VertexShader>(ret, new DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
GetResourceManager()->AddLiveResource(pShader, ret);
}
@@ -1232,7 +1232,7 @@ HRESULT WrappedID3D11Device::CreateVertexShader(
{
SCOPED_LOCK(m_D3DLock);
wrapped = new WrappedID3D11Shader<ID3D11VertexShader>(real, DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
wrapped = new WrappedID3D11Shader<ID3D11VertexShader>(real, new DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
if(m_State >= WRITING)
{
@@ -1288,7 +1288,7 @@ bool WrappedID3D11Device::Serialise_CreateGeometryShader(
}
else
{
ret = new WrappedID3D11Shader<ID3D11GeometryShader>(ret, DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
ret = new WrappedID3D11Shader<ID3D11GeometryShader>(ret, new DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
GetResourceManager()->AddLiveResource(pShader, ret);
}
@@ -1316,7 +1316,7 @@ HRESULT WrappedID3D11Device::CreateGeometryShader(
{
SCOPED_LOCK(m_D3DLock);
wrapped = new WrappedID3D11Shader<ID3D11GeometryShader>(real, DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
wrapped = new WrappedID3D11Shader<ID3D11GeometryShader>(real, new DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
if(m_State >= WRITING)
{
@@ -1388,7 +1388,7 @@ bool WrappedID3D11Device::Serialise_CreateGeometryShaderWithStreamOutput(
}
else
{
ret = new WrappedID3D11Shader<ID3D11GeometryShader>(ret, DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
ret = new WrappedID3D11Shader<ID3D11GeometryShader>(ret, new DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
GetResourceManager()->AddLiveResource(pShader, ret);
}
@@ -1428,7 +1428,7 @@ HRESULT WrappedID3D11Device::CreateGeometryShaderWithStreamOutput(
{
SCOPED_LOCK(m_D3DLock);
wrapped = new WrappedID3D11Shader<ID3D11GeometryShader>(real, DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
wrapped = new WrappedID3D11Shader<ID3D11GeometryShader>(real, new DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
if(m_State >= WRITING)
{
@@ -1485,7 +1485,7 @@ bool WrappedID3D11Device::Serialise_CreatePixelShader(
}
else
{
ret = new WrappedID3D11Shader<ID3D11PixelShader>(ret, DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
ret = new WrappedID3D11Shader<ID3D11PixelShader>(ret, new DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
GetResourceManager()->AddLiveResource(pShader, ret);
}
@@ -1513,7 +1513,7 @@ HRESULT WrappedID3D11Device::CreatePixelShader(
{
SCOPED_LOCK(m_D3DLock);
wrapped = new WrappedID3D11Shader<ID3D11PixelShader>(real, DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
wrapped = new WrappedID3D11Shader<ID3D11PixelShader>(real, new DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
if(m_State >= WRITING)
{
@@ -1569,7 +1569,7 @@ bool WrappedID3D11Device::Serialise_CreateHullShader(
}
else
{
ret = new WrappedID3D11Shader<ID3D11HullShader>(ret, DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
ret = new WrappedID3D11Shader<ID3D11HullShader>(ret, new DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
GetResourceManager()->AddLiveResource(pShader, ret);
}
@@ -1597,7 +1597,7 @@ HRESULT WrappedID3D11Device::CreateHullShader(
{
SCOPED_LOCK(m_D3DLock);
wrapped = new WrappedID3D11Shader<ID3D11HullShader>(real, DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
wrapped = new WrappedID3D11Shader<ID3D11HullShader>(real, new DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
if(m_State >= WRITING)
{
@@ -1653,7 +1653,7 @@ bool WrappedID3D11Device::Serialise_CreateDomainShader(
}
else
{
ret = new WrappedID3D11Shader<ID3D11DomainShader>(ret, DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
ret = new WrappedID3D11Shader<ID3D11DomainShader>(ret, new DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
GetResourceManager()->AddLiveResource(pShader, ret);
}
@@ -1681,7 +1681,7 @@ HRESULT WrappedID3D11Device::CreateDomainShader(
{
SCOPED_LOCK(m_D3DLock);
wrapped = new WrappedID3D11Shader<ID3D11DomainShader>(real, DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
wrapped = new WrappedID3D11Shader<ID3D11DomainShader>(real, new DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
if(m_State >= WRITING)
{
@@ -1737,7 +1737,7 @@ bool WrappedID3D11Device::Serialise_CreateComputeShader(
}
else
{
ret = new WrappedID3D11Shader<ID3D11ComputeShader>(ret, DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
ret = new WrappedID3D11Shader<ID3D11ComputeShader>(ret, new DXBC::DXBCFile(ShaderBytecode, (size_t)BytecodeLen), this);
GetResourceManager()->AddLiveResource(pShader, ret);
}
@@ -1765,7 +1765,7 @@ HRESULT WrappedID3D11Device::CreateComputeShader(
{
SCOPED_LOCK(m_D3DLock);
wrapped = new WrappedID3D11Shader<ID3D11ComputeShader>(real, DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
wrapped = new WrappedID3D11Shader<ID3D11ComputeShader>(real, new DXBC::DXBCFile(pShaderBytecode, BytecodeLength), this);
if(m_State >= WRITING)
{
+5 -4
View File
@@ -296,9 +296,10 @@ ShaderReflection *D3D11Replay::GetShader(ResourceId id)
if(it == WrappedShader::m_ShaderList.end())
return NULL;
RDCASSERT(it->second.m_Details);
ShaderReflection *ret = it->second->GetDetails();
RDCASSERT(ret);
return it->second.m_Details;
return ret;
}
void D3D11Replay::FreeTargetResource(ResourceId id)
@@ -1344,9 +1345,9 @@ void D3D11Replay::FillCBufferVariables(ResourceId shader, uint32_t cbufSlot, vec
if(it == WrappedShader::m_ShaderList.end())
return;
RDCASSERT(it->second.m_DXBCFile);
DXBC::DXBCFile *dxbc = it->second->GetDXBC();
DXBC::DXBCFile *dxbc = it->second.m_DXBCFile;
RDCASSERT(dxbc);
if(cbufSlot < dxbc->m_CBuffers.size())
m_pDevice->GetDebugManager()->FillCBufferVariables(dxbc->m_CBuffers[cbufSlot].variables, outvars, false, data);
+1 -1
View File
@@ -62,7 +62,7 @@ map<ResourceId,WrappedID3D11Texture1D::TextureEntry> WrappedTexture<ID3D11Textur
map<ResourceId,WrappedID3D11Texture2D::TextureEntry> WrappedTexture<ID3D11Texture2D, D3D11_TEXTURE2D_DESC>::m_TextureList;
map<ResourceId,WrappedID3D11Texture3D::TextureEntry> WrappedTexture<ID3D11Texture3D, D3D11_TEXTURE3D_DESC>::m_TextureList;
map<ResourceId,WrappedID3D11Buffer::BufferEntry> WrappedID3D11Buffer::m_BufferList;
map<ResourceId,WrappedShader::ShaderEntry> WrappedShader::m_ShaderList;
map<ResourceId,WrappedShader::ShaderEntry*> WrappedShader::m_ShaderList;
UINT GetMipForSubresource(ID3D11Resource *res, int Subresource)
{
+32 -33
View File
@@ -1076,51 +1076,50 @@ public:
class WrappedShader
{
public:
struct ShaderEntry
class ShaderEntry
{
ShaderEntry() : m_DXBCFile(NULL), m_Details(NULL) {}
ShaderEntry(const DXBC::DXBCFile &file)
{
m_DXBCFile = new DXBC::DXBCFile(file);
m_Details = MakeShaderReflection(m_DXBCFile);
}
ShaderEntry(const ShaderEntry &e)
{
*this = e;
}
ShaderEntry &operator =(const ShaderEntry &e)
{
m_DXBCFile = NULL;
if(e.m_DXBCFile)
m_DXBCFile = new DXBC::DXBCFile(*e.m_DXBCFile);
m_Details = MakeShaderReflection(m_DXBCFile);
public:
ShaderEntry() : m_DXBCFile(NULL), m_Details(NULL) {}
ShaderEntry(DXBC::DXBCFile *file)
{
m_DXBCFile = file;
m_Details = MakeShaderReflection(m_DXBCFile);
}
~ShaderEntry()
{
SAFE_DELETE(m_DXBCFile);
SAFE_DELETE(m_Details);
}
return *this;
}
~ShaderEntry()
{
SAFE_DELETE(m_DXBCFile);
SAFE_DELETE(m_Details);
}
DXBC::DXBCFile *GetDXBC() { return m_DXBCFile; }
ShaderReflection *GetDetails() { return m_Details; }
private:
ShaderEntry(const ShaderEntry &e);
ShaderEntry &operator =(const ShaderEntry &e);
DXBC::DXBCFile *m_DXBCFile;
ShaderReflection *m_Details;
DXBC::DXBCFile *m_DXBCFile;
ShaderReflection *m_Details;
};
static map<ResourceId, ShaderEntry> m_ShaderList;
static map<ResourceId, ShaderEntry*> m_ShaderList;
WrappedShader(ResourceId id, const DXBC::DXBCFile &file) : m_ID(id)
WrappedShader(ResourceId id, DXBC::DXBCFile *file) : m_ID(id)
{
RDCASSERT(m_ShaderList.find(m_ID) == m_ShaderList.end());
m_ShaderList[m_ID] = ShaderEntry(file);
m_ShaderList[m_ID] = new ShaderEntry(file);
}
virtual ~WrappedShader()
{
if(m_ShaderList.find(m_ID) != m_ShaderList.end()) m_ShaderList.erase(m_ID);
auto it = m_ShaderList.find(m_ID);
if(it != m_ShaderList.end())
{
delete it->second;
m_ShaderList.erase(it);
}
}
DXBC::DXBCFile *GetDXBC() { return m_ShaderList[m_ID].m_DXBCFile; }
ShaderReflection *GetDetails() { return m_ShaderList[m_ID].m_Details; }
DXBC::DXBCFile *GetDXBC() { return m_ShaderList[m_ID]->GetDXBC(); }
ShaderReflection *GetDetails() { return m_ShaderList[m_ID]->GetDetails(); }
private:
ResourceId m_ID;
};
@@ -1133,7 +1132,7 @@ public:
static const int AllocPoolMaxByteSize = 3*1024*1024;
ALLOCATE_WITH_WRAPPED_POOL(WrappedID3D11Shader<RealShaderType>, AllocPoolCount, AllocPoolMaxByteSize);
WrappedID3D11Shader(RealShaderType* real, const DXBC::DXBCFile &file, WrappedID3D11Device* device)
WrappedID3D11Shader(RealShaderType* real, DXBC::DXBCFile *file, WrappedID3D11Device* device)
: WrappedDeviceChild<RealShaderType>(real, device), WrappedShader(GetResourceID(), file) {}
virtual ~WrappedID3D11Shader() { Shutdown(); }
};
+3 -42
View File
@@ -310,8 +310,6 @@ class DXBCDebugChunk
vector< pair<string, string> > Files; // <filename, source>
virtual void GetFileLine(size_t instruction, uintptr_t offset, int32_t &fileIdx, int32_t &lineNum) const = 0;
virtual DXBCDebugChunk *Clone() const = 0;
};
// declare one of these and pass in your shader bytecode, then inspect
@@ -322,46 +320,6 @@ class DXBCFile
DXBCFile(const void *ByteCode, size_t ByteCodeLength);
~DXBCFile() { SAFE_DELETE(m_DebugInfo); }
DXBCFile(const DXBCFile &o)
{
*this = o;
}
DXBCFile &operator =(const DXBCFile &o)
{
m_Type = o.m_Type;
m_Version = o.m_Version;
m_ShaderStats = o.m_ShaderStats;
m_DebugInfo = NULL;
if(o.m_DebugInfo)
m_DebugInfo = o.m_DebugInfo->Clone();
m_Resources = o.m_Resources;
m_CBuffers = o.m_CBuffers;
m_Interfaces = o.m_Interfaces;
m_Immediate = o.m_Immediate;
m_ResourceBinds = o.m_ResourceBinds;
m_InputSig = o.m_InputSig;
m_OutputSig = o.m_OutputSig;
m_PatchConstantSig = o.m_PatchConstantSig;
m_Declarations = o.m_Declarations;
m_Instructions = o.m_Instructions;
m_Disassembly = o.m_Disassembly;
m_HexDump = o.m_HexDump;
m_ShaderBlob = o.m_ShaderBlob;
return *this;
}
D3D11_SHADER_VERSION_TYPE m_Type;
struct { uint32_t Major, Minor; } m_Version;
@@ -392,6 +350,9 @@ class DXBCFile
size_t NumOperands(OpcodeType op);
private:
DXBCFile(const DXBCFile &o);
DXBCFile &operator =(const DXBCFile &o);
void DisassembleHexDump();
void MakeDisassembly();
void GuessResources();
+4 -4
View File
@@ -244,9 +244,11 @@ class SDBGChunk : public DXBCDebugChunk
uint32_t GetShaderCompileFlags() const { return m_ShaderFlags; }
void GetFileLine(size_t instruction, uintptr_t offset, int32_t &fileIdx, int32_t &lineNum) const;
DXBCDebugChunk *Clone() const { return new SDBGChunk(*this); }
private:
SDBGChunk();
SDBGChunk(const SDBGChunk &);
SDBGChunk &operator =(const SDBGChunk &o);
bool m_HasDebugInfo;
string GetSymbolName(int symbolID);
@@ -266,8 +268,6 @@ class SDBGChunk : public DXBCDebugChunk
string m_Entry;
string m_Profile;
SDBGChunk();
// these don't need to be exposed, a more processed and friendly
// version is exposed
SDBGHeader m_Header;
+3 -2
View File
@@ -290,9 +290,10 @@ class SPDBChunk : public DXBCDebugChunk
uint32_t GetShaderCompileFlags() const { return m_ShaderFlags; }
void GetFileLine(size_t instruction, uintptr_t offset, int32_t &fileIdx, int32_t &lineNum) const;
DXBCDebugChunk *Clone() const { return new SPDBChunk(*this); }
private:
SPDBChunk(const SPDBChunk &);
SPDBChunk &operator =(const SPDBChunk &o);
bool m_HasDebugInfo;
CompilandDetails m_CompilandDetails;