Fix a couple framebuffer related bugs in D3D renderer

1. A crash in D3D11 renderer when create a texture with flag BGFX_TEXTURE_RT_WRITE_ONLY then override it, bcause m_srv is NULL.
2. In headless mode, RendererContextD3D12::m_swapChain is NULL, clear it resulting a D3D12 debug error
This commit is contained in:
Minmin Gong 2020-02-26 15:32:12 -08:00 committed by Бранимир Караџић
parent ca509c136d
commit 68e27b6655
2 changed files with 17 additions and 9 deletions

View File

@ -4465,14 +4465,19 @@ namespace bgfx { namespace d3d11
void TextureD3D11::overrideInternal(uintptr_t _ptr) void TextureD3D11::overrideInternal(uintptr_t _ptr)
{ {
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc{}; D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc{};
const bool readable = (m_srv != NULL);
if (readable) {
m_srv->GetDesc(&srvDesc); m_srv->GetDesc(&srvDesc);
}
destroy(); destroy();
m_flags |= BGFX_SAMPLER_INTERNAL_SHARED; m_flags |= BGFX_SAMPLER_INTERNAL_SHARED;
m_ptr = (ID3D11Resource*)_ptr; m_ptr = (ID3D11Resource*)_ptr;
if (readable) {
s_renderD3D11->m_device->CreateShaderResourceView(m_ptr, &srvDesc, &m_srv); s_renderD3D11->m_device->CreateShaderResourceView(m_ptr, &srvDesc, &m_srv);
} }
}
void TextureD3D11::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) void TextureD3D11::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem)
{ {

View File

@ -2436,6 +2436,8 @@ namespace bgfx { namespace d3d12
} }
if (!isValid(_fbh) ) if (!isValid(_fbh) )
{
if (NULL != m_swapChain)
{ {
m_rtvHandle = getCPUHandleHeapStart(m_rtvDescriptorHeap); m_rtvHandle = getCPUHandleHeapStart(m_rtvDescriptorHeap);
uint32_t rtvDescriptorSize = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); uint32_t rtvDescriptorSize = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
@ -2446,6 +2448,7 @@ namespace bgfx { namespace d3d12
m_currentDepthStencil = &m_dsvHandle; m_currentDepthStencil = &m_dsvHandle;
m_commandList->OMSetRenderTargets(1, m_currentColor, true, m_currentDepthStencil); m_commandList->OMSetRenderTargets(1, m_currentColor, true, m_currentDepthStencil);
} }
}
else else
{ {
FrameBufferD3D12& frameBuffer = m_frameBuffers[_fbh.idx]; FrameBufferD3D12& frameBuffer = m_frameBuffers[_fbh.idx];