D3D11: Fixed frame buffer auto resizing.

This commit is contained in:
Branimir Karadžić 2015-04-14 17:02:41 -07:00
parent f3a17da8a8
commit 63cc071a6e
3 changed files with 71 additions and 39 deletions

View file

@ -1233,6 +1233,11 @@ BX_PRAGMA_DIAGNOSTIC_POP();
DX_RELEASE(m_backBufferDepthStencil, 0); DX_RELEASE(m_backBufferDepthStencil, 0);
DX_RELEASE(m_backBufferColor, 0); DX_RELEASE(m_backBufferColor, 0);
for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii)
{
m_frameBuffers[ii].preReset();
}
// invalidateCache(); // invalidateCache();
capturePreReset(); capturePreReset();
@ -1274,6 +1279,11 @@ BX_PRAGMA_DIAGNOSTIC_POP();
m_currentColor = m_backBufferColor; m_currentColor = m_backBufferColor;
m_currentDepthStencil = m_backBufferDepthStencil; m_currentDepthStencil = m_backBufferDepthStencil;
for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii)
{
m_frameBuffers[ii].postReset();
}
capturePostReset(); capturePostReset();
} }
@ -3016,35 +3026,10 @@ BX_PRAGMA_DIAGNOSTIC_POP();
m_dsv = NULL; m_dsv = NULL;
m_swapChain = NULL; m_swapChain = NULL;
m_num = 0; m_numTh = _num;
for (uint32_t ii = 0; ii < _num; ++ii) memcpy(m_th, _handles, _num*sizeof(TextureHandle) );
{
TextureHandle handle = _handles[ii];
if (isValid(handle) )
{
const TextureD3D11& texture = s_renderD3D11->m_textures[handle.idx];
if (isDepth( (TextureFormat::Enum)texture.m_textureFormat) )
{
BX_CHECK(NULL == m_dsv, "Frame buffer already has depth-stencil attached.");
const uint32_t msaaQuality = bx::uint32_satsub( (texture.m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1); postReset();
const DXGI_SAMPLE_DESC& msaa = s_msaa[msaaQuality];
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Format = s_textureFormat[texture.m_textureFormat].m_fmtDsv;
dsvDesc.ViewDimension = 1 < msaa.Count ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D;
dsvDesc.Flags = 0;
dsvDesc.Texture2D.MipSlice = 0;
DX_CHECK(s_renderD3D11->m_device->CreateDepthStencilView(texture.m_ptr, &dsvDesc, &m_dsv) );
}
else
{
DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(texture.m_ptr, NULL, &m_rtv[m_num]) );
DX_CHECK(s_renderD3D11->m_device->CreateShaderResourceView(texture.m_ptr, NULL, &m_srv[m_num]) );
m_num++;
}
}
}
} }
void FrameBufferD3D11::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) void FrameBufferD3D11::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat)
@ -3075,6 +3060,21 @@ BX_PRAGMA_DIAGNOSTIC_POP();
} }
uint16_t FrameBufferD3D11::destroy() uint16_t FrameBufferD3D11::destroy()
{
preReset();
DX_RELEASE(m_swapChain, 0);
m_num = 0;
m_numTh = 0;
uint16_t denseIdx = m_denseIdx;
m_denseIdx = UINT16_MAX;
return denseIdx;
}
void FrameBufferD3D11::preReset()
{ {
for (uint32_t ii = 0, num = m_num; ii < num; ++ii) for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
{ {
@ -3083,14 +3083,42 @@ BX_PRAGMA_DIAGNOSTIC_POP();
} }
DX_RELEASE(m_dsv, 0); DX_RELEASE(m_dsv, 0);
DX_RELEASE(m_swapChain, 0); }
m_num = 0; void FrameBufferD3D11::postReset()
{
if (0 < m_numTh)
{
m_num = 0;
for (uint32_t ii = 0; ii < m_numTh; ++ii)
{
TextureHandle handle = m_th[ii];
if (isValid(handle) )
{
const TextureD3D11& texture = s_renderD3D11->m_textures[handle.idx];
if (isDepth( (TextureFormat::Enum)texture.m_textureFormat) )
{
BX_CHECK(NULL == m_dsv, "Frame buffer already has depth-stencil attached.");
uint16_t denseIdx = m_denseIdx; const uint32_t msaaQuality = bx::uint32_satsub( (texture.m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1);
m_denseIdx = UINT16_MAX; const DXGI_SAMPLE_DESC& msaa = s_msaa[msaaQuality];
return denseIdx; D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Format = s_textureFormat[texture.m_textureFormat].m_fmtDsv;
dsvDesc.ViewDimension = 1 < msaa.Count ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D;
dsvDesc.Flags = 0;
dsvDesc.Texture2D.MipSlice = 0;
DX_CHECK(s_renderD3D11->m_device->CreateDepthStencilView(texture.m_ptr, &dsvDesc, &m_dsv) );
}
else
{
DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(texture.m_ptr, NULL, &m_rtv[m_num]) );
DX_CHECK(s_renderD3D11->m_device->CreateShaderResourceView(texture.m_ptr, NULL, &m_srv[m_num]) );
m_num++;
}
}
}
}
} }
void FrameBufferD3D11::resolve() void FrameBufferD3D11::resolve()

View file

@ -287,12 +287,16 @@ namespace bgfx { namespace d3d11
FrameBufferD3D11() FrameBufferD3D11()
: m_denseIdx(UINT16_MAX) : m_denseIdx(UINT16_MAX)
, m_num(0) , m_num(0)
, m_numTh(0)
, m_dsv(NULL)
{ {
} }
void create(uint8_t _num, const TextureHandle* _handles); void create(uint8_t _num, const TextureHandle* _handles);
void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat); void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat);
uint16_t destroy(); uint16_t destroy();
void preReset();
void postReset();
void resolve(); void resolve();
void clear(const Clear& _clear, const float _palette[][4]); void clear(const Clear& _clear, const float _palette[][4]);
@ -302,6 +306,8 @@ namespace bgfx { namespace d3d11
IDXGISwapChain* m_swapChain; IDXGISwapChain* m_swapChain;
uint16_t m_denseIdx; uint16_t m_denseIdx;
uint8_t m_num; uint8_t m_num;
uint8_t m_numTh;
TextureHandle m_th[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
}; };
} /* namespace d3d11 */ } // namespace bgfx } /* namespace d3d11 */ } // namespace bgfx

View file

@ -1948,8 +1948,7 @@ namespace bgfx { namespace gl
for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii) for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii)
{ {
FrameBufferGL& frameBuffer = m_frameBuffers[ii]; m_frameBuffers[ii].postReset();
frameBuffer.postReset();
} }
ovrPreReset(); ovrPreReset();
@ -4273,11 +4272,10 @@ namespace bgfx { namespace gl
void FrameBufferGL::create(uint8_t _num, const TextureHandle* _handles) void FrameBufferGL::create(uint8_t _num, const TextureHandle* _handles)
{ {
GL_CHECK(glGenFramebuffers(1, &m_fbo[0]) ); GL_CHECK(glGenFramebuffers(1, &m_fbo[0]) );
for (uint32_t ii = 0; ii < _num; ++ii)
{
m_th[ii] = _handles[ii];
}
m_numTh = _num; m_numTh = _num;
memcpy(m_th, _handles, _num*sizeof(TextureHandle) );
postReset(); postReset();
} }