GPU/HW: Ensure buffers are unmapped before present
Darn DX11...
This commit is contained in:
parent
25db163347
commit
7159330f63
|
@ -76,6 +76,8 @@ bool GPU::Initialize()
|
||||||
|
|
||||||
void GPU::UpdateSettings(const Settings& old_settings)
|
void GPU::UpdateSettings(const Settings& old_settings)
|
||||||
{
|
{
|
||||||
|
FlushRender();
|
||||||
|
|
||||||
m_force_progressive_scan = g_settings.gpu_disable_interlacing;
|
m_force_progressive_scan = g_settings.gpu_disable_interlacing;
|
||||||
m_fifo_size = g_settings.gpu_fifo_size;
|
m_fifo_size = g_settings.gpu_fifo_size;
|
||||||
m_max_run_ahead = g_settings.gpu_max_run_ahead;
|
m_max_run_ahead = g_settings.gpu_max_run_ahead;
|
||||||
|
@ -1665,6 +1667,8 @@ void GPU::SetDisplayParameters(s32 display_width, s32 display_height, s32 active
|
||||||
|
|
||||||
bool GPU::PresentDisplay()
|
bool GPU::PresentDisplay()
|
||||||
{
|
{
|
||||||
|
FlushRender();
|
||||||
|
|
||||||
if (!HasDisplayTexture())
|
if (!HasDisplayTexture())
|
||||||
return g_gpu_device->BeginPresent(false);
|
return g_gpu_device->BeginPresent(false);
|
||||||
|
|
||||||
|
|
|
@ -713,6 +713,10 @@ void GPU_HW::DestroyBuffers()
|
||||||
{
|
{
|
||||||
ClearDisplayTexture();
|
ClearDisplayTexture();
|
||||||
|
|
||||||
|
DebugAssert((m_batch_vertex_ptr != nullptr) == (m_batch_index_ptr != nullptr));
|
||||||
|
if (m_batch_vertex_ptr)
|
||||||
|
UnmapGPUBuffer(0, 0);
|
||||||
|
|
||||||
m_vram_upload_buffer.reset();
|
m_vram_upload_buffer.reset();
|
||||||
m_vram_readback_download_texture.reset();
|
m_vram_readback_download_texture.reset();
|
||||||
g_gpu_device->RecycleTexture(std::move(m_downsample_texture));
|
g_gpu_device->RecycleTexture(std::move(m_downsample_texture));
|
||||||
|
@ -3054,13 +3058,14 @@ void GPU_HW::DispatchRenderCommand()
|
||||||
|
|
||||||
void GPU_HW::FlushRender()
|
void GPU_HW::FlushRender()
|
||||||
{
|
{
|
||||||
if (m_batch_index_count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const u32 base_vertex = m_batch_base_vertex;
|
const u32 base_vertex = m_batch_base_vertex;
|
||||||
const u32 base_index = m_batch_base_index;
|
const u32 base_index = m_batch_base_index;
|
||||||
const u32 index_count = m_batch_index_count;
|
const u32 index_count = m_batch_index_count;
|
||||||
UnmapGPUBuffer(m_batch_vertex_count, m_batch_index_count);
|
DebugAssert((m_batch_vertex_ptr != nullptr) == (m_batch_index_ptr != nullptr));
|
||||||
|
if (m_batch_vertex_ptr)
|
||||||
|
UnmapGPUBuffer(m_batch_vertex_count, index_count);
|
||||||
|
if (index_count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
GL_SCOPE_FMT("Hardware Draw {}", ++s_draw_number);
|
GL_SCOPE_FMT("Hardware Draw {}", ++s_draw_number);
|
||||||
|
|
|
@ -1046,12 +1046,14 @@ void D3D11Device::SetScissor(s32 x, s32 y, s32 width, s32 height)
|
||||||
|
|
||||||
void D3D11Device::Draw(u32 vertex_count, u32 base_vertex)
|
void D3D11Device::Draw(u32 vertex_count, u32 base_vertex)
|
||||||
{
|
{
|
||||||
|
DebugAssert(!m_vertex_buffer.IsMapped() && !m_index_buffer.IsMapped());
|
||||||
s_stats.num_draws++;
|
s_stats.num_draws++;
|
||||||
m_context->Draw(vertex_count, base_vertex);
|
m_context->Draw(vertex_count, base_vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D11Device::DrawIndexed(u32 index_count, u32 base_index, u32 base_vertex)
|
void D3D11Device::DrawIndexed(u32 index_count, u32 base_index, u32 base_vertex)
|
||||||
{
|
{
|
||||||
|
DebugAssert(!m_vertex_buffer.IsMapped() && !m_index_buffer.IsMapped());
|
||||||
s_stats.num_draws++;
|
s_stats.num_draws++;
|
||||||
m_context->DrawIndexed(index_count, base_index, base_vertex);
|
m_context->DrawIndexed(index_count, base_index, base_vertex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,8 @@ void D3D11StreamBuffer::Destroy()
|
||||||
|
|
||||||
D3D11StreamBuffer::MappingResult D3D11StreamBuffer::Map(ID3D11DeviceContext1* context, u32 alignment, u32 min_size)
|
D3D11StreamBuffer::MappingResult D3D11StreamBuffer::Map(ID3D11DeviceContext1* context, u32 alignment, u32 min_size)
|
||||||
{
|
{
|
||||||
|
DebugAssert(!m_mapped);
|
||||||
|
|
||||||
m_position = Common::AlignUp(m_position, alignment);
|
m_position = Common::AlignUp(m_position, alignment);
|
||||||
if ((m_position + min_size) >= m_size || !m_use_map_no_overwrite)
|
if ((m_position + min_size) >= m_size || !m_use_map_no_overwrite)
|
||||||
{
|
{
|
||||||
|
@ -91,12 +93,16 @@ D3D11StreamBuffer::MappingResult D3D11StreamBuffer::Map(ID3D11DeviceContext1* co
|
||||||
Panic("Map failed");
|
Panic("Map failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_mapped = true;
|
||||||
return MappingResult{static_cast<char*>(sr.pData) + m_position, m_position, m_position / alignment,
|
return MappingResult{static_cast<char*>(sr.pData) + m_position, m_position, m_position / alignment,
|
||||||
(m_size - m_position) / alignment};
|
(m_size - m_position) / alignment};
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D11StreamBuffer::Unmap(ID3D11DeviceContext1* context, u32 used_size)
|
void D3D11StreamBuffer::Unmap(ID3D11DeviceContext1* context, u32 used_size)
|
||||||
{
|
{
|
||||||
|
DebugAssert(m_mapped);
|
||||||
|
|
||||||
context->Unmap(m_buffer.Get(), 0);
|
context->Unmap(m_buffer.Get(), 0);
|
||||||
m_position += used_size;
|
m_position += used_size;
|
||||||
|
m_mapped = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ public:
|
||||||
ALWAYS_INLINE ID3D11Buffer* const* GetD3DBufferArray() const { return m_buffer.GetAddressOf(); }
|
ALWAYS_INLINE ID3D11Buffer* const* GetD3DBufferArray() const { return m_buffer.GetAddressOf(); }
|
||||||
ALWAYS_INLINE u32 GetSize() const { return m_size; }
|
ALWAYS_INLINE u32 GetSize() const { return m_size; }
|
||||||
ALWAYS_INLINE u32 GetPosition() const { return m_position; }
|
ALWAYS_INLINE u32 GetPosition() const { return m_position; }
|
||||||
|
ALWAYS_INLINE bool IsMapped() const { return m_mapped; }
|
||||||
|
|
||||||
bool Create(ID3D11Device* device, D3D11_BIND_FLAG bind_flags, u32 size);
|
bool Create(ID3D11Device* device, D3D11_BIND_FLAG bind_flags, u32 size);
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
@ -43,4 +44,5 @@ private:
|
||||||
u32 m_size;
|
u32 m_size;
|
||||||
u32 m_position;
|
u32 m_position;
|
||||||
bool m_use_map_no_overwrite = false;
|
bool m_use_map_no_overwrite = false;
|
||||||
|
bool m_mapped = false;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue