mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 00:58:30 -05:00
D3D12: Fixed resizing backbuffer.
This commit is contained in:
parent
f166412693
commit
653e8eaa91
2 changed files with 59 additions and 26 deletions
|
@ -433,7 +433,6 @@ namespace bgfx { namespace d3d12
|
|||
, m_flags(BGFX_RESET_NONE)
|
||||
, m_fsChanges(0)
|
||||
, m_vsChanges(0)
|
||||
, m_frame(0)
|
||||
, m_backBufferColorIdx(0)
|
||||
, m_rtMsaa(false)
|
||||
{
|
||||
|
@ -501,7 +500,7 @@ namespace bgfx { namespace d3d12
|
|||
|
||||
HRESULT hr;
|
||||
|
||||
hr = CreateDXGIFactory1(__uuidof(IDXGIFactory), (void**)&m_factory);
|
||||
hr = CreateDXGIFactory1(__uuidof(m_factory), (void**)&m_factory);
|
||||
BX_WARN(SUCCEEDED(hr), "Unable to create DXGI factory.");
|
||||
|
||||
if (FAILED(hr) )
|
||||
|
@ -659,7 +658,7 @@ namespace bgfx { namespace d3d12
|
|||
);
|
||||
hr = m_factory->CreateSwapChain(m_cmd.m_commandQueue
|
||||
, &m_scd
|
||||
, &m_swapChain
|
||||
, reinterpret_cast<IDXGISwapChain**>(&m_swapChain)
|
||||
);
|
||||
BX_WARN(SUCCEEDED(hr), "Failed to create swap chain.");
|
||||
if (FAILED(hr) )
|
||||
|
@ -1526,7 +1525,9 @@ namespace bgfx { namespace d3d12
|
|||
void invalidateCache()
|
||||
{
|
||||
m_pipelineStateCache.invalidate();
|
||||
|
||||
m_samplerStateCache.invalidate();
|
||||
m_samplerAllocator.reset();
|
||||
}
|
||||
|
||||
void updateMsaa()
|
||||
|
@ -1571,19 +1572,25 @@ data.NumQualityLevels = 0;
|
|||
m_textVideoMem.clear();
|
||||
|
||||
m_resolution = _resolution;
|
||||
|
||||
m_scd.BufferDesc.Width = _resolution.m_width;
|
||||
m_scd.BufferDesc.Width = _resolution.m_width;
|
||||
m_scd.BufferDesc.Height = _resolution.m_height;
|
||||
|
||||
preReset();
|
||||
|
||||
if (resize)
|
||||
{
|
||||
DX_CHECK(m_swapChain->ResizeBuffers(m_scd.BufferCount
|
||||
uint32_t nodeMask[] = { 1, 1, 1, 1 };
|
||||
BX_STATIC_ASSERT(BX_COUNTOF(m_backBufferColor) == BX_COUNTOF(nodeMask) );
|
||||
IUnknown* presentQueue[] ={ m_cmd.m_commandQueue, m_cmd.m_commandQueue, m_cmd.m_commandQueue, m_cmd.m_commandQueue };
|
||||
BX_STATIC_ASSERT(BX_COUNTOF(m_backBufferColor) == BX_COUNTOF(presentQueue) );
|
||||
|
||||
DX_CHECK(m_swapChain->ResizeBuffers1(m_scd.BufferCount
|
||||
, m_scd.BufferDesc.Width
|
||||
, m_scd.BufferDesc.Height
|
||||
, m_scd.BufferDesc.Format
|
||||
, m_scd.Flags
|
||||
, nodeMask
|
||||
, presentQueue
|
||||
) );
|
||||
}
|
||||
else
|
||||
|
@ -1596,7 +1603,7 @@ data.NumQualityLevels = 0;
|
|||
HRESULT hr;
|
||||
hr = m_factory->CreateSwapChain(m_cmd.m_commandQueue
|
||||
, &m_scd
|
||||
, &m_swapChain
|
||||
, reinterpret_cast<IDXGISwapChain**>(&m_swapChain)
|
||||
);
|
||||
BGFX_FATAL(SUCCEEDED(hr), bgfx::Fatal::UnableToInitialize, "Failed to create swap chain.");
|
||||
}
|
||||
|
@ -2408,9 +2415,9 @@ data.NumQualityLevels = 0;
|
|||
D3D12_FEATURE_DATA_ARCHITECTURE m_architecture;
|
||||
D3D12_FEATURE_DATA_D3D12_OPTIONS m_options;
|
||||
|
||||
IDXGIFactory1* m_factory;
|
||||
IDXGIFactory4* m_factory;
|
||||
|
||||
IDXGISwapChain* m_swapChain;
|
||||
IDXGISwapChain3* m_swapChain;
|
||||
int64_t m_presentElapsed;
|
||||
uint16_t m_lost;
|
||||
uint16_t m_numWindows;
|
||||
|
@ -2467,7 +2474,6 @@ data.NumQualityLevels = 0;
|
|||
uint32_t m_vsChanges;
|
||||
|
||||
FrameBufferHandle m_fbh;
|
||||
uint32_t m_frame;
|
||||
uint32_t m_backBufferColorIdx;
|
||||
bool m_rtMsaa;
|
||||
};
|
||||
|
@ -2695,6 +2701,13 @@ data.NumQualityLevels = 0;
|
|||
m_handleAlloc->free(_idx);
|
||||
}
|
||||
|
||||
void DescriptorAllocator::reset()
|
||||
{
|
||||
uint16_t max = m_handleAlloc->getMaxHandles();
|
||||
bx::destroyHandleAlloc(g_allocator, m_handleAlloc);
|
||||
m_handleAlloc = bx::createHandleAlloc(g_allocator, max);
|
||||
}
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE DescriptorAllocator::get(uint16_t _idx)
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle = { m_gpuHandle.ptr + _idx * m_numDescriptorsPerBlock * m_incrementSize };
|
||||
|
@ -3643,8 +3656,7 @@ data.NumQualityLevels = 0;
|
|||
uint32_t statsNumIndices = 0;
|
||||
uint32_t statsKeyType[2] = {};
|
||||
|
||||
m_backBufferColorIdx = m_frame % m_scd.BufferCount;
|
||||
m_frame++;
|
||||
m_backBufferColorIdx = m_swapChain->GetCurrentBackBufferIndex();
|
||||
|
||||
const uint64_t f0 = BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_FACTOR, BGFX_STATE_BLEND_FACTOR);
|
||||
const uint64_t f1 = BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_INV_FACTOR, BGFX_STATE_BLEND_INV_FACTOR);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <d3d12.h>
|
||||
#include <d3dx12.h>
|
||||
#include <dxgidebug.h>
|
||||
#include <dxgi1_4.h>
|
||||
|
||||
#include "renderer.h"
|
||||
#include "renderer_d3d.h"
|
||||
|
@ -86,6 +86,7 @@ namespace bgfx { namespace d3d12
|
|||
uint16_t alloc(ID3D12Resource* _ptr, const D3D12_SHADER_RESOURCE_VIEW_DESC* _desc);
|
||||
uint16_t alloc(const uint32_t* _flags, uint32_t _num = BGFX_CONFIG_MAX_TEXTURE_SAMPLERS);
|
||||
void free(uint16_t _handle);
|
||||
void reset();
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE get(uint16_t _handle);
|
||||
|
||||
|
@ -396,28 +397,48 @@ namespace bgfx { namespace d3d12
|
|||
BX_CHECK(0 == m_control.available(), "");
|
||||
}
|
||||
|
||||
bool tryFinish(uint64_t _waitFence)
|
||||
{
|
||||
if (0 < m_control.available() )
|
||||
{
|
||||
if (consume(0)
|
||||
&& _waitFence <= m_completedFence)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void release(ID3D12Resource* _ptr)
|
||||
{
|
||||
m_release[m_control.m_current].push_back(_ptr);
|
||||
}
|
||||
|
||||
void consume()
|
||||
bool consume(uint32_t _ms = INFINITE)
|
||||
{
|
||||
CommandList& commandList = m_commandList[m_control.m_read];
|
||||
WaitForSingleObject(commandList.m_event, INFINITE);
|
||||
CloseHandle(commandList.m_event);
|
||||
commandList.m_event = NULL;
|
||||
m_completedFence = m_fence->GetCompletedValue();
|
||||
m_commandQueue->Wait(m_fence, m_completedFence);
|
||||
|
||||
ResourceArray& ra = m_release[m_control.m_read];
|
||||
for (ResourceArray::iterator it = ra.begin(), itEnd = ra.end(); it != itEnd; ++it)
|
||||
if (WAIT_OBJECT_0 == WaitForSingleObject(commandList.m_event, _ms) )
|
||||
{
|
||||
DX_RELEASE(*it, 0);
|
||||
}
|
||||
ra.clear();
|
||||
CloseHandle(commandList.m_event);
|
||||
commandList.m_event = NULL;
|
||||
m_completedFence = m_fence->GetCompletedValue();
|
||||
m_commandQueue->Wait(m_fence, m_completedFence);
|
||||
|
||||
m_control.consume(1);
|
||||
ResourceArray& ra = m_release[m_control.m_read];
|
||||
for (ResourceArray::iterator it = ra.begin(), itEnd = ra.end(); it != itEnd; ++it)
|
||||
{
|
||||
DX_RELEASE(*it, 0);
|
||||
}
|
||||
ra.clear();
|
||||
|
||||
m_control.consume(1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
struct CommandList
|
||||
|
|
Loading…
Reference in a new issue