Add protection on D3D12 for bad internal API calls from python

This commit is contained in:
baldurk
2023-03-09 13:23:19 +00:00
parent e81e00beb3
commit 2c2bafa1a6
10 changed files with 85 additions and 13 deletions
+3 -1
View File
@@ -803,7 +803,9 @@ public:
void RemoveQueue(WrappedID3D12CommandQueue *queue);
// only valid on replay
std::map<ResourceId, WrappedID3D12Resource *> &GetResourceList() { return *m_ResourceList; }
const std::map<ResourceId, WrappedID3D12Resource *> &GetResourceList() { return *m_ResourceList; }
void AddReplayResource(ResourceId id, WrappedID3D12Resource *res) { (*m_ResourceList)[id] = res; }
void RemoveReplayResource(ResourceId id) { (*m_ResourceList).erase(id); }
rdcarray<WrappedID3D12PipelineState *> &GetPipelineList() { return *m_PipelineList; }
////////////////////////////////////////////////////////////////
// non wrapping interface
+7 -1
View File
@@ -965,7 +965,13 @@ RenderOutputSubresource D3D12Replay::GetRenderOutputSubresource(ResourceId id)
ResourceId D3D12Replay::RenderOverlay(ResourceId texid, FloatVector clearCol, DebugOverlay overlay,
uint32_t eventId, const rdcarray<uint32_t> &passEvents)
{
ID3D12Resource *resource = m_pDevice->GetResourceList()[texid];
ID3D12Resource *resource = NULL;
{
auto it = m_pDevice->GetResourceList().find(texid);
if(it != m_pDevice->GetResourceList().end())
resource = it->second;
}
if(resource == NULL)
return ResourceId();
@@ -341,7 +341,13 @@ bool D3D12Replay::RenderTextureInternal(D3D12_CPU_DESCRIPTOR_HANDLE rtv, Texture
{
const bool blendAlpha = (flags & eTexDisplay_BlendAlpha) != 0;
ID3D12Resource *resource = m_pDevice->GetResourceList()[cfg.resourceId];
ID3D12Resource *resource = NULL;
{
auto it = m_pDevice->GetResourceList().find(cfg.resourceId);
if(it != m_pDevice->GetResourceList().end())
resource = it->second;
}
if(resource == NULL)
return false;
+38 -8
View File
@@ -360,7 +360,7 @@ BufferDescription D3D12Replay::GetBuffer(ResourceId id)
auto it = m_pDevice->GetResourceList().find(id);
if(it == m_pDevice->GetResourceList().end())
if(it == m_pDevice->GetResourceList().end() || it->second == NULL)
return ret;
D3D12_RESOURCE_DESC desc = it->second->GetDesc();
@@ -401,7 +401,7 @@ TextureDescription D3D12Replay::GetTexture(ResourceId id)
auto it = m_pDevice->GetResourceList().find(id);
if(it == m_pDevice->GetResourceList().end())
if(it == m_pDevice->GetResourceList().end() || it->second == NULL)
return ret;
D3D12_RESOURCE_DESC desc = it->second->GetDesc();
@@ -2647,7 +2647,13 @@ void D3D12Replay::PickPixel(ResourceId texture, uint32_t x, uint32_t y, const Su
texDisplay.typeCast = typeCast;
texDisplay.rawOutput = true;
ID3D12Resource *resource = m_pDevice->GetResourceList()[texture];
ID3D12Resource *resource = NULL;
{
auto it = m_pDevice->GetResourceList().find(texture);
if(it != m_pDevice->GetResourceList().end())
resource = it->second;
}
if(resource)
{
@@ -2735,7 +2741,13 @@ void D3D12Replay::PickPixel(ResourceId texture, uint32_t x, uint32_t y, const Su
bool D3D12Replay::GetMinMax(ResourceId texid, const Subresource &sub, CompType typeCast,
float *minval, float *maxval)
{
ID3D12Resource *resource = m_pDevice->GetResourceList()[texid];
ID3D12Resource *resource = NULL;
{
auto it = m_pDevice->GetResourceList().find(texid);
if(it != m_pDevice->GetResourceList().end())
resource = it->second;
}
if(resource == NULL)
return false;
@@ -2920,7 +2932,13 @@ bool D3D12Replay::GetHistogram(ResourceId texid, const Subresource &sub, CompTyp
if(minval >= maxval)
return false;
ID3D12Resource *resource = m_pDevice->GetResourceList()[texid];
ID3D12Resource *resource = NULL;
{
auto it = m_pDevice->GetResourceList().find(texid);
if(it != m_pDevice->GetResourceList().end())
resource = it->second;
}
if(resource == NULL)
return false;
@@ -3155,7 +3173,7 @@ void D3D12Replay::GetBufferData(ResourceId buff, uint64_t offset, uint64_t lengt
{
auto it = m_pDevice->GetResourceList().find(buff);
if(it == m_pDevice->GetResourceList().end())
if(it == m_pDevice->GetResourceList().end() || it->second == NULL)
{
RDCERR("Getting buffer data for unknown buffer %s!",
ToStr(m_pDevice->GetResourceManager()->GetLiveID(buff)).c_str());
@@ -3497,7 +3515,13 @@ void D3D12Replay::GetTextureData(ResourceId tex, const Subresource &sub,
bool wasms = false;
bool resolve = params.resolve;
ID3D12Resource *resource = m_pDevice->GetResourceList()[tex];
ID3D12Resource *resource = NULL;
{
auto it = m_pDevice->GetResourceList().find(tex);
if(it != m_pDevice->GetResourceList().end())
resource = it->second;
}
if(resource == NULL)
{
@@ -4149,7 +4173,13 @@ void D3D12Replay::BuildCustomShader(ShaderEncoding sourceEncoding, const bytebuf
ResourceId D3D12Replay::ApplyCustomShader(TextureDisplay &display)
{
ID3D12Resource *resource = m_pDevice->GetResourceList()[display.resourceId];
ID3D12Resource *resource = NULL;
{
auto it = m_pDevice->GetResourceList().find(display.resourceId);
if(it != m_pDevice->GetResourceList().end())
resource = it->second;
}
if(resource == NULL)
return ResourceId();
+1 -1
View File
@@ -159,7 +159,7 @@ WrappedID3D12Resource::~WrappedID3D12Resource()
}
if(IsReplayMode(m_pDevice->GetState()))
m_pDevice->GetResourceList().erase(GetResourceID());
m_pDevice->RemoveReplayResource(GetResourceID());
// assuming only valid for buffers
if(m_pReal->GetDesc().Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
+1 -1
View File
@@ -980,7 +980,7 @@ public:
: WrappedDeviceChild12(real, device)
{
if(IsReplayMode(device->GetState()))
device->GetResourceList()[GetResourceID()] = this;
device->AddReplayResource(GetResourceID(), this);
// assuming only valid for buffers
if(m_pReal->GetDesc().Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
@@ -46,11 +46,18 @@ class D3D11_Simple_Triangle(rdtest.TestCase):
self.check_mesh_data(postvs_ref, postvs_data)
save_data = rd.TextureSave()
save_data.destType = rd.FileType.DDS
path = rdtest.get_tmp_path('temp.dds')
# Check that nothing breaks if we call typical enumeration functions on resources
for res in self.controller.GetResources():
res: rd.ResourceDescription
save_data.resourceId = res.resourceId
self.controller.GetShaderEntryPoints(res.resourceId)
self.controller.GetUsage(res.resourceId)
self.controller.GetBufferData(res.resourceId, 0, 0)
self.controller.GetTextureData(res.resourceId, rd.Subresource())
self.controller.SaveTexture(save_data, path)
@@ -55,12 +55,19 @@ class D3D12_Simple_Triangle(rdtest.TestCase):
tex = self.get_resource_by_name("dsvMStex").resourceId
self.check_pixel_value(tex, 1, 1, [0.2, (0x55)/255.0, 0.0, 1.0])
save_data = rd.TextureSave()
save_data.destType = rd.FileType.DDS
path = rdtest.get_tmp_path('temp.dds')
# Check that nothing breaks if we call typical enumeration functions on resources
for res in self.controller.GetResources():
res: rd.ResourceDescription
save_data.resourceId = res.resourceId
self.controller.GetShaderEntryPoints(res.resourceId)
self.controller.GetUsage(res.resourceId)
self.controller.GetBufferData(res.resourceId, 0, 0)
self.controller.GetTextureData(res.resourceId, rd.Subresource())
self.controller.SaveTexture(save_data, path)
+7
View File
@@ -49,11 +49,18 @@ class GL_Simple_Triangle(rdtest.TestCase):
self.check_mesh_data(postvs_ref, postvs_data)
save_data = rd.TextureSave()
save_data.destType = rd.FileType.DDS
path = rdtest.get_tmp_path('temp.dds')
# Check that nothing breaks if we call typical enumeration functions on resources
for res in self.controller.GetResources():
res: rd.ResourceDescription
save_data.resourceId = res.resourceId
self.controller.GetShaderEntryPoints(res.resourceId)
self.controller.GetUsage(res.resourceId)
self.controller.GetBufferData(res.resourceId, 0, 0)
self.controller.GetTextureData(res.resourceId, rd.Subresource())
self.controller.SaveTexture(save_data, path)
@@ -49,11 +49,18 @@ class VK_Simple_Triangle(rdtest.TestCase):
self.check_mesh_data(postvs_ref, postvs_data)
save_data = rd.TextureSave()
save_data.destType = rd.FileType.DDS
path = rdtest.get_tmp_path('temp.dds')
# Check that nothing breaks if we call typical enumeration functions on resources
for res in self.controller.GetResources():
res: rd.ResourceDescription
save_data.resourceId = res.resourceId
self.controller.GetShaderEntryPoints(res.resourceId)
self.controller.GetUsage(res.resourceId)
self.controller.GetBufferData(res.resourceId, 0, 0)
self.controller.GetTextureData(res.resourceId, rd.Subresource())
self.controller.SaveTexture(save_data, path)