This commit is contained in:
Branimir Karadžić 2016-02-18 16:52:58 -08:00
parent 4e4af5983a
commit 13a95332d9
3 changed files with 86 additions and 124 deletions

View File

@ -275,10 +275,11 @@ namespace bgfx { namespace d3d11
IDXGISwapChain* m_swapChain; IDXGISwapChain* m_swapChain;
uint32_t m_width; uint32_t m_width;
uint32_t m_height; uint32_t m_height;
Attachment m_attachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
uint16_t m_denseIdx; uint16_t m_denseIdx;
uint8_t m_num; uint8_t m_num;
uint8_t m_numTh; uint8_t m_numTh;
Attachment m_attachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
}; };
struct TimerQueryD3D11 struct TimerQueryD3D11

View File

@ -1317,21 +1317,30 @@ namespace bgfx { namespace d3d9
// If frame buffer has only depth attachment D3DFMT_NULL // If frame buffer has only depth attachment D3DFMT_NULL
// render target is created. // 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) 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) ); 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) ); 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) 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_dsIdx = UINT8_MAX;
m_num = 0; m_num = 0;
m_numTh = _num;
m_needResolve = false; m_needResolve = false;
memcpy(m_attachment, _attachment, _num*sizeof(Attachment) ); memcpy(m_attachment, _attachment, _num*sizeof(Attachment) );
@ -3081,34 +3091,29 @@ namespace bgfx { namespace d3d9
{ {
const TextureD3D9& texture = s_renderD3D9->m_textures[handle.idx]; const TextureD3D9& texture = s_renderD3D9->m_textures[handle.idx];
if (NULL != texture.m_surface)
{
m_surface[ii] = texture.m_surface;
m_surface[ii]->AddRef();
}
else
{
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) ) if (isDepth( (TextureFormat::Enum)texture.m_textureFormat) )
{ {
m_depthHandle = handle; m_dsIdx = uint8_t(ii);
if (NULL != texture.m_surface)
{
m_depthStencil = texture.m_surface;
m_depthStencil->AddRef();
} }
else else
{ {
m_depthStencil = texture.getSurface(); ++m_num;
}
}
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_needResolve |= true m_needResolve |= true
@ -3139,7 +3144,7 @@ namespace bgfx { namespace d3d9
params.BackBufferHeight = m_height; params.BackBufferHeight = m_height;
DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(&params, &m_swapChain) ); DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(&params, &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( DX_CHECK(s_renderD3D9->m_device->CreateDepthStencilSurface(
params.BackBufferWidth params.BackBufferWidth
@ -3148,11 +3153,11 @@ namespace bgfx { namespace d3d9
, params.MultiSampleType , params.MultiSampleType
, params.MultiSampleQuality , params.MultiSampleQuality
, FALSE , FALSE
, &m_depthStencil , &m_surface[1]
, NULL , NULL
) ); ) );
m_colorHandle[0].idx = invalidHandle; m_dsIdx = 1;
m_denseIdx = _denseIdx; m_denseIdx = _denseIdx;
m_num = 1; m_num = 1;
m_needResolve = false; m_needResolve = false;
@ -3162,44 +3167,29 @@ namespace bgfx { namespace d3d9
{ {
if (NULL != m_hwnd) if (NULL != m_hwnd)
{ {
DX_RELEASE(m_depthStencil, 0); DX_RELEASE(m_surface[0], 0);
DX_RELEASE(m_color[0], 0); DX_RELEASE(m_surface[1], 0);
DX_RELEASE(m_swapChain, 0); DX_RELEASE(m_swapChain, 0);
} }
else else
{ {
for (uint32_t ii = 0, num = m_num; ii < num; ++ii) uint32_t num = m_numTh;
{ num += uint32_t(0 < m_numTh && 0 == m_num);
m_colorHandle[ii].idx = invalidHandle;
IDirect3DSurface9* ptr = m_color[ii]; for (uint32_t ii = 0; ii < num; ++ii)
{
IDirect3DSurface9* ptr = m_surface[ii];
if (NULL != ptr) if (NULL != ptr)
{ {
ptr->Release(); 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_hwnd = NULL;
m_num = 0; m_num = 0;
m_depthHandle.idx = invalidHandle; m_numTh = 0;
uint16_t denseIdx = m_denseIdx; uint16_t denseIdx = m_denseIdx;
m_denseIdx = UINT16_MAX; m_denseIdx = UINT16_MAX;
@ -3216,15 +3206,9 @@ namespace bgfx { namespace d3d9
{ {
if (m_needResolve) 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]; const TextureD3D9& texture = s_renderD3D9->m_textures[m_attachment[ii].handle.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];
texture.resolve(); texture.resolve();
} }
} }
@ -3234,28 +3218,19 @@ namespace bgfx { namespace d3d9
{ {
if (NULL != m_hwnd) if (NULL != m_hwnd)
{ {
DX_RELEASE(m_color[0], 0); DX_RELEASE(m_surface[0], 0);
DX_RELEASE(m_depthStencil, 0); DX_RELEASE(m_surface[1], 0);
DX_RELEASE(m_swapChain, 0); DX_RELEASE(m_swapChain, 0);
} }
else else
{ {
for (uint32_t ii = 0, num = m_num; ii < num; ++ii) uint32_t num = m_numTh;
{ num += uint32_t(0 < m_numTh && 0 == m_num);
m_color[ii]->Release();
m_color[ii] = NULL;
}
if (isValid(m_depthHandle) ) for (uint32_t ii = 0; ii < num; ++ii)
{ {
if (0 == m_num) m_surface[ii]->Release();
{ m_surface[ii] = NULL;
m_color[0]->Release();
m_color[0] = NULL;
}
m_depthStencil->Release();
m_depthStencil = NULL;
} }
} }
} }
@ -3270,69 +3245,55 @@ namespace bgfx { namespace d3d9
params.BackBufferHeight = m_height; params.BackBufferHeight = m_height;
DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(&params, &m_swapChain) ); DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(&params, &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 DX_CHECK(s_renderD3D9->m_device->CreateDepthStencilSurface(params.BackBufferWidth
, params.BackBufferHeight , params.BackBufferHeight
, params.AutoDepthStencilFormat , params.AutoDepthStencilFormat
, params.MultiSampleType , params.MultiSampleType
, params.MultiSampleQuality , params.MultiSampleQuality
, FALSE , FALSE
, &m_depthStencil , &m_surface[1]
, NULL , 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) ) if (isValid(th) )
{ {
TextureD3D9& texture = s_renderD3D9->m_textures[th.idx]; TextureD3D9& texture = s_renderD3D9->m_textures[th.idx];
if (NULL != texture.m_surface) if (NULL != texture.m_surface)
{ {
m_color[ii] = texture.m_surface; m_surface[ii] = texture.m_surface;
m_color[ii]->AddRef(); m_surface[ii]->AddRef();
} }
else 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) )
{
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) if (0 == m_num)
{ {
createNullColorRT(); createNullColorRT();
} }
} }
} }
}
void FrameBufferD3D9::createNullColorRT() void FrameBufferD3D9::createNullColorRT()
{ {
const TextureD3D9& texture = s_renderD3D9->m_textures[m_depthHandle.idx]; DX_CHECK(s_renderD3D9->m_device->CreateRenderTarget(
DX_CHECK(s_renderD3D9->m_device->CreateRenderTarget(texture.m_width m_width
, texture.m_height , m_height
, D3DFMT_NULL , D3DFMT_NULL
, D3DMULTISAMPLE_NONE , D3DMULTISAMPLE_NONE
, 0 , 0
, false , false
, &m_color[0] , &m_surface[1]
, NULL , NULL
) ); ) );
} }

View File

@ -383,10 +383,11 @@ namespace bgfx { namespace d3d9
FrameBufferD3D9() FrameBufferD3D9()
: m_hwnd(NULL) : m_hwnd(NULL)
, m_denseIdx(UINT16_MAX) , m_denseIdx(UINT16_MAX)
, m_num(0)
, m_needResolve(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); void create(uint8_t _num, const Attachment* _attachment);
@ -398,19 +399,18 @@ namespace bgfx { namespace d3d9
void postReset(); void postReset();
void createNullColorRT(); void createNullColorRT();
IDirect3DSurface9* m_color[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1]; IDirect3DSurface9* m_surface[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
IDirect3DSurface9* m_depthStencil;
IDirect3DSwapChain9* m_swapChain; IDirect3DSwapChain9* m_swapChain;
HWND m_hwnd; HWND m_hwnd;
uint32_t m_width; uint32_t m_width;
uint32_t m_height; 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]; Attachment m_attachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
uint16_t m_denseIdx; uint16_t m_denseIdx;
uint8_t m_num;
bool m_needResolve; bool m_needResolve;
uint8_t m_num;
uint8_t m_numTh;
uint8_t m_dsIdx;
}; };
struct TimerQueryD3D9 struct TimerQueryD3D9