GPU: Implement VRAM-to-VRAM copies

This commit is contained in:
Connor McLaughlin 2019-09-18 00:58:30 +10:00
parent ff83f15abe
commit 4d38213f23
4 changed files with 56 additions and 2 deletions

View File

@ -343,7 +343,10 @@ void GPU::WriteGP0(u32 value)
case 0x00: // NOP
break;
case 0x02: // Fill Rectnagle
case 0x01: // Clear cache
break;
case 0x02: // Fill Rectangle
{
if (!HandleFillRectangleCommand())
return;
@ -357,13 +360,20 @@ void GPU::WriteGP0(u32 value)
}
break;
case 0xC0: // Copy Rectnagle VRAM->CPU
case 0xC0: // Copy Rectangle VRAM->CPU
{
if (!HandleCopyRectangleVRAMToCPUCommand())
return;
}
break;
case 0x80: // Copy Rectangle VRAM->VRAM
{
if (!HandleCopyRectangleVRAMToVRAMCommand())
return;
}
break;
case 0xE1: // Set draw mode
{
// 0..10 bits match GPUSTAT
@ -669,6 +679,32 @@ bool GPU::HandleCopyRectangleVRAMToCPUCommand()
return true;
}
bool GPU::HandleCopyRectangleVRAMToVRAMCommand()
{
if (m_GP0_command.size() < 4)
return false;
const u32 src_x = m_GP0_command[1] & UINT32_C(0xFFFF);
const u32 src_y = m_GP0_command[1] >> 16;
const u32 dst_x = m_GP0_command[2] & UINT32_C(0xFFFF);
const u32 dst_y = m_GP0_command[2] >> 16;
const u32 width = m_GP0_command[3] & UINT32_C(0xFFFF);
const u32 height = m_GP0_command[3] >> 16;
Log_DebugPrintf("Copy rectangle from VRAM to VRAM src=(%u,%u), dst=(%u,%u), size=(%u,%u)", src_x, src_y, dst_x, dst_y,
width, height);
if ((src_x + width) > VRAM_WIDTH || (src_y + height) > VRAM_HEIGHT || (dst_x + width) > VRAM_WIDTH ||
(dst_y + height) > VRAM_HEIGHT)
{
Panic("Out of bounds VRAM copy");
return true;
}
CopyVRAM(src_x, src_y, dst_x, dst_y, width, height);
return true;
}
void GPU::UpdateDisplay()
{
m_texture_config.page_changed = true;
@ -681,6 +717,8 @@ void GPU::FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color) {}
void GPU::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data) {}
void GPU::CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height) {}
void GPU::DispatchRenderCommand(RenderCommand rc, u32 num_vertices) {}
void GPU::FlushRender() {}

View File

@ -131,12 +131,14 @@ protected:
bool HandleFillRectangleCommand();
bool HandleCopyRectangleCPUToVRAMCommand();
bool HandleCopyRectangleVRAMToCPUCommand();
bool HandleCopyRectangleVRAMToVRAMCommand();
// Rendering in the backend
virtual void UpdateDisplay();
virtual void ReadVRAM(u32 x, u32 y, u32 width, u32 height, void* buffer);
virtual void FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color);
virtual void UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data);
virtual void CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height);
virtual void DispatchRenderCommand(RenderCommand rc, u32 num_vertices);
virtual void FlushRender();

View File

@ -300,6 +300,19 @@ void GPU_HW_OpenGL::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void*
rgba_data.data());
}
void GPU_HW_OpenGL::CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height)
{
glDisable(GL_SCISSOR_TEST);
// lower-left origin flip
src_y = VRAM_HEIGHT - src_y - height;
dst_y = VRAM_HEIGHT - dst_y - height;
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer_fbo_id);
glBlitFramebuffer(src_x, src_y, src_x + width, src_y + height, dst_x, dst_y, dst_x + width, dst_y + height,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
void GPU_HW_OpenGL::UpdateTexturePageTexture()
{
glBindFramebuffer(GL_FRAMEBUFFER, m_texture_page_fbo_id);

View File

@ -21,6 +21,7 @@ protected:
void ReadVRAM(u32 x, u32 y, u32 width, u32 height, void* buffer) override;
void FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color) override;
void UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data) override;
void CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height) override;
void UpdateTexturePageTexture() override;
void FlushRender() override;