Skip to content

Commit

Permalink
GPU: Implement PGXP for lines
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Dec 22, 2024
1 parent b81287e commit 0b4e302
Show file tree
Hide file tree
Showing 13 changed files with 312 additions and 87 deletions.
5 changes: 5 additions & 0 deletions src/common/gsvector_neon.h
Original file line number Diff line number Diff line change
Expand Up @@ -3131,6 +3131,11 @@ class alignas(16) GSVector4

ALWAYS_INLINE GSVector2 zw() const { return GSVector2(vget_high_s32(v4s)); }

ALWAYS_INLINE static GSVector4 xyxy(const GSVector2& l, const GSVector2& h)
{
return GSVector4(vcombine_f32(l.v2s, h.v2s));
}

#define VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, ws, wn) \
ALWAYS_INLINE GSVector4 xs##ys##zs##ws() const \
{ \
Expand Down
5 changes: 5 additions & 0 deletions src/common/gsvector_nosimd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2316,6 +2316,11 @@ class alignas(16) GSVector4

ALWAYS_INLINE GSVector2 zw() const { return GSVector2(z, w); }

ALWAYS_INLINE static GSVector4 xyxy(const GSVector2& l, const GSVector2& h)
{
return GSVector4(l.x, l.y, h.x, h.y);
}

#define VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, ws, wn) \
ALWAYS_INLINE GSVector4 xs##ys##zs##ws() const { return GSVector4(F32[xn], F32[yn], F32[zn], F32[wn]); }

Expand Down
14 changes: 7 additions & 7 deletions src/core/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class GPU final
/// Returns the number of vertices in the buffered poly-line.
ALWAYS_INLINE u32 GetPolyLineVertexCount() const
{
return (static_cast<u32>(m_blit_buffer.size()) + BoolToUInt32(m_render_command.shading_enable)) >>
return (static_cast<u32>(m_polyline_buffer.size()) + BoolToUInt32(m_render_command.shading_enable)) >>
BoolToUInt8(m_render_command.shading_enable);
}

Expand Down Expand Up @@ -520,20 +520,20 @@ class GPU final
u16 row;
} m_vram_transfer = {};

std::unique_ptr<GPUDump::Recorder> m_gpu_dump;

HeapFIFOQueue<u64, MAX_FIFO_SIZE> m_fifo;
std::vector<u32> m_blit_buffer;
TickCount m_max_run_ahead = 128;
u32 m_fifo_size = 128;
u32 m_blit_remaining_words;
GPURenderCommand m_render_command{};

std::unique_ptr<GPUDump::Recorder> m_gpu_dump;
std::vector<u32> m_blit_buffer;
std::vector<u64> m_polyline_buffer;

ALWAYS_INLINE u32 FifoPop() { return Truncate32(m_fifo.Pop()); }
ALWAYS_INLINE u32 FifoPeek() { return Truncate32(m_fifo.Peek()); }
ALWAYS_INLINE u32 FifoPeek(u32 i) { return Truncate32(m_fifo.Peek(i)); }

TickCount m_max_run_ahead = 128;
u32 m_fifo_size = 128;

private:
using GP0CommandHandler = bool (GPU::*)();
using GP0CommandHandlerTable = std::array<GP0CommandHandler, 256>;
Expand Down
19 changes: 19 additions & 0 deletions src/core/gpu_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ GPUBackendDrawLineCommand* GPUBackend::NewDrawLineCommand(u32 num_vertices)
return cmd;
}

GPUBackendDrawPreciseLineCommand* GPUBackend::NewDrawPreciseLineCommand(u32 num_vertices)
{
const u32 size =
sizeof(GPUBackendDrawPreciseLineCommand) + (num_vertices * sizeof(GPUBackendDrawPreciseLineCommand::Vertex));
GPUBackendDrawPreciseLineCommand* cmd = static_cast<GPUBackendDrawPreciseLineCommand*>(
GPUThread::AllocateCommand(GPUBackendCommandType::DrawPreciseLine, size));
cmd->num_vertices = Truncate16(num_vertices);
return cmd;
}

void GPUBackend::PushCommand(GPUThreadCommand* cmd)
{
GPUThread::PushCommand(cmd);
Expand Down Expand Up @@ -489,6 +499,15 @@ void GPUBackend::HandleCommand(const GPUThreadCommand* cmd)
s_counters.num_primitives += ccmd->num_vertices / 2;
DrawLine(ccmd);
}
break;

case GPUBackendCommandType::DrawPreciseLine:
{
const GPUBackendDrawPreciseLineCommand* ccmd = static_cast<const GPUBackendDrawPreciseLineCommand*>(cmd);
s_counters.num_vertices += ccmd->num_vertices;
s_counters.num_primitives += ccmd->num_vertices / 2;
DrawPreciseLine(ccmd);
}
break;

DefaultCaseIsUnreachable();
Expand Down
2 changes: 2 additions & 0 deletions src/core/gpu_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class GPUBackend
static GPUBackendDrawPrecisePolygonCommand* NewDrawPrecisePolygonCommand(u32 num_vertices);
static GPUBackendDrawRectangleCommand* NewDrawRectangleCommand();
static GPUBackendDrawLineCommand* NewDrawLineCommand(u32 num_vertices);
static GPUBackendDrawPreciseLineCommand* NewDrawPreciseLineCommand(u32 num_vertices);
static void PushCommand(GPUThreadCommand* cmd);
static void PushCommandAndWakeThread(GPUThreadCommand* cmd);
static void PushCommandAndSync(GPUThreadCommand* cmd, bool spin);
Expand Down Expand Up @@ -125,6 +126,7 @@ class GPUBackend
virtual void DrawPrecisePolygon(const GPUBackendDrawPrecisePolygonCommand* cmd) = 0;
virtual void DrawSprite(const GPUBackendDrawRectangleCommand* cmd) = 0;
virtual void DrawLine(const GPUBackendDrawLineCommand* cmd) = 0;
virtual void DrawPreciseLine(const GPUBackendDrawPreciseLineCommand* cmd) = 0;

virtual void DrawingAreaChanged() = 0;
virtual void UpdateCLUT(GPUTexturePaletteReg reg, bool clut_is_8bit) = 0;
Expand Down
Loading

0 comments on commit 0b4e302

Please sign in to comment.