Cleanup.
This commit is contained in:
parent
4e4af5983a
commit
13a95332d9
@ -275,10 +275,11 @@ namespace bgfx { namespace d3d11
|
||||
IDXGISwapChain* m_swapChain;
|
||||
uint32_t m_width;
|
||||
uint32_t m_height;
|
||||
|
||||
Attachment m_attachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
|
||||
uint16_t m_denseIdx;
|
||||
uint8_t m_num;
|
||||
uint8_t m_numTh;
|
||||
Attachment m_attachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
|
||||
};
|
||||
|
||||
struct TimerQueryD3D11
|
||||
|
@ -1317,21 +1317,30 @@ namespace bgfx { namespace d3d9
|
||||
|
||||
// If frame buffer has only depth attachment D3DFMT_NULL
|
||||
// render target is created.
|
||||
uint32_t fbnum = bx::uint32_max(1, frameBuffer.m_num);
|
||||
const uint32_t fbnum = bx::uint32_max(2, frameBuffer.m_numTh);
|
||||
const uint8_t dsIdx = frameBuffer.m_dsIdx;
|
||||
|
||||
DX_CHECK(m_device->SetDepthStencilSurface(UINT8_MAX == dsIdx
|
||||
? m_backBufferDepthStencil
|
||||
: frameBuffer.m_surface[dsIdx]
|
||||
) );
|
||||
|
||||
uint32_t rtIdx = 0;
|
||||
for (uint32_t ii = 0; ii < fbnum; ++ii)
|
||||
{
|
||||
DX_CHECK(m_device->SetRenderTarget(ii, frameBuffer.m_color[ii]) );
|
||||
IDirect3DSurface9* surface = frameBuffer.m_surface[ii];
|
||||
if (ii != dsIdx)
|
||||
{
|
||||
DX_CHECK(m_device->SetRenderTarget(rtIdx, surface) );
|
||||
++rtIdx;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t ii = fbnum, num = g_caps.maxFBAttachments; ii < num; ++ii)
|
||||
for (uint32_t ii = rtIdx, num = g_caps.maxFBAttachments; ii < num; ++ii)
|
||||
{
|
||||
DX_CHECK(m_device->SetRenderTarget(ii, NULL) );
|
||||
}
|
||||
|
||||
IDirect3DSurface9* depthStencil = frameBuffer.m_depthStencil;
|
||||
DX_CHECK(m_device->SetDepthStencilSurface(NULL != depthStencil ? depthStencil : m_backBufferDepthStencil) );
|
||||
|
||||
DX_CHECK(m_device->SetRenderState(D3DRS_SRGBWRITEENABLE, FALSE) );
|
||||
}
|
||||
|
||||
@ -3064,13 +3073,14 @@ namespace bgfx { namespace d3d9
|
||||
|
||||
void FrameBufferD3D9::create(uint8_t _num, const Attachment* _attachment)
|
||||
{
|
||||
for (uint32_t ii = 0; ii < BX_COUNTOF(m_color); ++ii)
|
||||
for (uint32_t ii = 0; ii < BX_COUNTOF(m_surface); ++ii)
|
||||
{
|
||||
m_color[ii] = NULL;
|
||||
m_surface[ii] = NULL;
|
||||
}
|
||||
m_depthStencil = NULL;
|
||||
|
||||
m_num = 0;
|
||||
m_dsIdx = UINT8_MAX;
|
||||
m_num = 0;
|
||||
m_numTh = _num;
|
||||
m_needResolve = false;
|
||||
memcpy(m_attachment, _attachment, _num*sizeof(Attachment) );
|
||||
|
||||
@ -3081,34 +3091,29 @@ namespace bgfx { namespace d3d9
|
||||
{
|
||||
const TextureD3D9& texture = s_renderD3D9->m_textures[handle.idx];
|
||||
|
||||
if (isDepth( (TextureFormat::Enum)texture.m_textureFormat) )
|
||||
if (NULL != texture.m_surface)
|
||||
{
|
||||
m_depthHandle = handle;
|
||||
if (NULL != texture.m_surface)
|
||||
{
|
||||
m_depthStencil = texture.m_surface;
|
||||
m_depthStencil->AddRef();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_depthStencil = texture.getSurface();
|
||||
}
|
||||
m_surface[ii] = texture.m_surface;
|
||||
m_surface[ii]->AddRef();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_colorHandle[m_num] = handle;
|
||||
if (NULL != texture.m_surface)
|
||||
{
|
||||
m_color[m_num] = texture.m_surface;
|
||||
m_color[m_num]->AddRef();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_color[m_num] = texture.getSurface(uint8_t(m_attachment[ii].layer), uint8_t(m_attachment[ii].mip) );
|
||||
m_attachment[m_num].layer = m_attachment[ii].layer;
|
||||
m_attachment[m_num].mip = m_attachment[ii].mip;
|
||||
}
|
||||
m_num++;
|
||||
m_surface[ii] = texture.getSurface(uint8_t(m_attachment[ii].layer), uint8_t(m_attachment[ii].mip) );
|
||||
}
|
||||
|
||||
if (0 == m_num)
|
||||
{
|
||||
m_width = texture.m_width;
|
||||
m_height = texture.m_height;
|
||||
}
|
||||
|
||||
if (isDepth( (TextureFormat::Enum)texture.m_textureFormat) )
|
||||
{
|
||||
m_dsIdx = uint8_t(ii);
|
||||
}
|
||||
else
|
||||
{
|
||||
++m_num;
|
||||
}
|
||||
|
||||
m_needResolve |= true
|
||||
@ -3139,7 +3144,7 @@ namespace bgfx { namespace d3d9
|
||||
params.BackBufferHeight = m_height;
|
||||
|
||||
DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(¶ms, &m_swapChain) );
|
||||
DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_color[0]) );
|
||||
DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_surface[0]) );
|
||||
|
||||
DX_CHECK(s_renderD3D9->m_device->CreateDepthStencilSurface(
|
||||
params.BackBufferWidth
|
||||
@ -3148,11 +3153,11 @@ namespace bgfx { namespace d3d9
|
||||
, params.MultiSampleType
|
||||
, params.MultiSampleQuality
|
||||
, FALSE
|
||||
, &m_depthStencil
|
||||
, &m_surface[1]
|
||||
, NULL
|
||||
) );
|
||||
|
||||
m_colorHandle[0].idx = invalidHandle;
|
||||
m_dsIdx = 1;
|
||||
m_denseIdx = _denseIdx;
|
||||
m_num = 1;
|
||||
m_needResolve = false;
|
||||
@ -3162,44 +3167,29 @@ namespace bgfx { namespace d3d9
|
||||
{
|
||||
if (NULL != m_hwnd)
|
||||
{
|
||||
DX_RELEASE(m_depthStencil, 0);
|
||||
DX_RELEASE(m_color[0], 0);
|
||||
DX_RELEASE(m_swapChain, 0);
|
||||
DX_RELEASE(m_surface[0], 0);
|
||||
DX_RELEASE(m_surface[1], 0);
|
||||
DX_RELEASE(m_swapChain, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
|
||||
{
|
||||
m_colorHandle[ii].idx = invalidHandle;
|
||||
uint32_t num = m_numTh;
|
||||
num += uint32_t(0 < m_numTh && 0 == m_num);
|
||||
|
||||
IDirect3DSurface9* ptr = m_color[ii];
|
||||
for (uint32_t ii = 0; ii < num; ++ii)
|
||||
{
|
||||
IDirect3DSurface9* ptr = m_surface[ii];
|
||||
if (NULL != ptr)
|
||||
{
|
||||
ptr->Release();
|
||||
m_color[ii] = NULL;
|
||||
m_surface[ii] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != m_depthStencil)
|
||||
{
|
||||
if (0 == m_num)
|
||||
{
|
||||
IDirect3DSurface9* ptr = m_color[0];
|
||||
if (NULL != ptr)
|
||||
{
|
||||
ptr->Release();
|
||||
m_color[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
m_depthStencil->Release();
|
||||
m_depthStencil = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
m_hwnd = NULL;
|
||||
m_num = 0;
|
||||
m_depthHandle.idx = invalidHandle;
|
||||
m_hwnd = NULL;
|
||||
m_num = 0;
|
||||
m_numTh = 0;
|
||||
|
||||
uint16_t denseIdx = m_denseIdx;
|
||||
m_denseIdx = UINT16_MAX;
|
||||
@ -3216,15 +3206,9 @@ namespace bgfx { namespace d3d9
|
||||
{
|
||||
if (m_needResolve)
|
||||
{
|
||||
if (isValid(m_depthHandle) )
|
||||
for (uint32_t ii = 0, num = m_numTh; ii < num; ++ii)
|
||||
{
|
||||
const TextureD3D9& texture = s_renderD3D9->m_textures[m_depthHandle.idx];
|
||||
texture.resolve();
|
||||
}
|
||||
|
||||
for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
|
||||
{
|
||||
const TextureD3D9& texture = s_renderD3D9->m_textures[m_colorHandle[ii].idx];
|
||||
const TextureD3D9& texture = s_renderD3D9->m_textures[m_attachment[ii].handle.idx];
|
||||
texture.resolve();
|
||||
}
|
||||
}
|
||||
@ -3234,28 +3218,19 @@ namespace bgfx { namespace d3d9
|
||||
{
|
||||
if (NULL != m_hwnd)
|
||||
{
|
||||
DX_RELEASE(m_color[0], 0);
|
||||
DX_RELEASE(m_depthStencil, 0);
|
||||
DX_RELEASE(m_surface[0], 0);
|
||||
DX_RELEASE(m_surface[1], 0);
|
||||
DX_RELEASE(m_swapChain, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
|
||||
{
|
||||
m_color[ii]->Release();
|
||||
m_color[ii] = NULL;
|
||||
}
|
||||
uint32_t num = m_numTh;
|
||||
num += uint32_t(0 < m_numTh && 0 == m_num);
|
||||
|
||||
if (isValid(m_depthHandle) )
|
||||
for (uint32_t ii = 0; ii < num; ++ii)
|
||||
{
|
||||
if (0 == m_num)
|
||||
{
|
||||
m_color[0]->Release();
|
||||
m_color[0] = NULL;
|
||||
}
|
||||
|
||||
m_depthStencil->Release();
|
||||
m_depthStencil = NULL;
|
||||
m_surface[ii]->Release();
|
||||
m_surface[ii] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3270,69 +3245,55 @@ namespace bgfx { namespace d3d9
|
||||
params.BackBufferHeight = m_height;
|
||||
|
||||
DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(¶ms, &m_swapChain) );
|
||||
DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_color[0]) );
|
||||
DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_surface[0]) );
|
||||
DX_CHECK(s_renderD3D9->m_device->CreateDepthStencilSurface(params.BackBufferWidth
|
||||
, params.BackBufferHeight
|
||||
, params.AutoDepthStencilFormat
|
||||
, params.MultiSampleType
|
||||
, params.MultiSampleQuality
|
||||
, FALSE
|
||||
, &m_depthStencil
|
||||
, &m_surface[1]
|
||||
, NULL
|
||||
) );
|
||||
}
|
||||
else
|
||||
else if (0 < m_numTh)
|
||||
{
|
||||
for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
|
||||
for (uint32_t ii = 0, num = m_numTh; ii < num; ++ii)
|
||||
{
|
||||
TextureHandle th = m_colorHandle[ii];
|
||||
TextureHandle th = m_attachment[ii].handle;
|
||||
|
||||
if (isValid(th) )
|
||||
{
|
||||
TextureD3D9& texture = s_renderD3D9->m_textures[th.idx];
|
||||
if (NULL != texture.m_surface)
|
||||
{
|
||||
m_color[ii] = texture.m_surface;
|
||||
m_color[ii]->AddRef();
|
||||
m_surface[ii] = texture.m_surface;
|
||||
m_surface[ii]->AddRef();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_color[ii] = texture.getSurface(uint8_t(m_attachment[ii].layer), uint8_t(m_attachment[ii].mip) );
|
||||
m_surface[ii] = texture.getSurface(uint8_t(m_attachment[ii].layer), uint8_t(m_attachment[ii].mip) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isValid(m_depthHandle) )
|
||||
if (0 == m_num)
|
||||
{
|
||||
TextureD3D9& texture = s_renderD3D9->m_textures[m_depthHandle.idx];
|
||||
if (NULL != texture.m_surface)
|
||||
{
|
||||
m_depthStencil = texture.m_surface;
|
||||
m_depthStencil->AddRef();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_depthStencil = texture.getSurface();
|
||||
}
|
||||
|
||||
if (0 == m_num)
|
||||
{
|
||||
createNullColorRT();
|
||||
}
|
||||
createNullColorRT();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FrameBufferD3D9::createNullColorRT()
|
||||
{
|
||||
const TextureD3D9& texture = s_renderD3D9->m_textures[m_depthHandle.idx];
|
||||
DX_CHECK(s_renderD3D9->m_device->CreateRenderTarget(texture.m_width
|
||||
, texture.m_height
|
||||
DX_CHECK(s_renderD3D9->m_device->CreateRenderTarget(
|
||||
m_width
|
||||
, m_height
|
||||
, D3DFMT_NULL
|
||||
, D3DMULTISAMPLE_NONE
|
||||
, 0
|
||||
, false
|
||||
, &m_color[0]
|
||||
, &m_surface[1]
|
||||
, NULL
|
||||
) );
|
||||
}
|
||||
|
@ -383,10 +383,11 @@ namespace bgfx { namespace d3d9
|
||||
FrameBufferD3D9()
|
||||
: m_hwnd(NULL)
|
||||
, m_denseIdx(UINT16_MAX)
|
||||
, m_num(0)
|
||||
, m_needResolve(0)
|
||||
, m_num(0)
|
||||
, m_numTh(0)
|
||||
, m_dsIdx(UINT8_MAX)
|
||||
{
|
||||
m_depthHandle.idx = invalidHandle;
|
||||
}
|
||||
|
||||
void create(uint8_t _num, const Attachment* _attachment);
|
||||
@ -398,19 +399,18 @@ namespace bgfx { namespace d3d9
|
||||
void postReset();
|
||||
void createNullColorRT();
|
||||
|
||||
IDirect3DSurface9* m_color[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
|
||||
IDirect3DSurface9* m_depthStencil;
|
||||
IDirect3DSurface9* m_surface[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
|
||||
IDirect3DSwapChain9* m_swapChain;
|
||||
HWND m_hwnd;
|
||||
uint32_t m_width;
|
||||
uint32_t m_height;
|
||||
|
||||
TextureHandle m_colorHandle[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
|
||||
TextureHandle m_depthHandle;
|
||||
Attachment m_attachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
|
||||
uint16_t m_denseIdx;
|
||||
uint8_t m_num;
|
||||
bool m_needResolve;
|
||||
uint8_t m_num;
|
||||
uint8_t m_numTh;
|
||||
uint8_t m_dsIdx;
|
||||
};
|
||||
|
||||
struct TimerQueryD3D9
|
||||
|
Loading…
Reference in New Issue
Block a user