Skip to content

Commit 856e40e

Browse files
authored
Reimplement draw call merging & refactor aurora::gx (#37)
1 parent 528a266 commit 856e40e

31 files changed

Lines changed: 507 additions & 760 deletions

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ if (AURORA_ENABLE_GX)
7171
# aurora_gx sources
7272
lib/gfx/common.cpp
7373
lib/gfx/texture.cpp
74-
lib/gfx/gx.cpp
75-
lib/gfx/gx_shader.cpp
7674
lib/gfx/texture_convert.cpp
77-
lib/gfx/shader_info.cpp
78-
lib/gfx/model/shader.cpp
79-
lib/gfx/fifo.cpp
80-
lib/gfx/command_processor.cpp
75+
lib/gx/command_processor.cpp
76+
lib/gx/fifo.cpp
77+
lib/gx/gx.cpp
78+
lib/gx/pipeline.cpp
79+
lib/gx/shader.cpp
80+
lib/gx/shader_info.cpp
8181
lib/dolphin/gx/GXBump.cpp
8282
lib/dolphin/gx/GXCull.cpp
8383
lib/dolphin/gx/GXDispList.cpp

cmake/aurora_gx.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
add_library(aurora_gx STATIC
22
lib/gfx/common.cpp
33
lib/gfx/texture.cpp
4-
lib/gfx/gx.cpp
5-
lib/gfx/gx_shader.cpp
64
lib/gfx/texture_convert.cpp
7-
lib/gfx/shader_info.cpp
8-
lib/gfx/model/shader.cpp
9-
lib/gfx/fifo.cpp
10-
lib/gfx/command_processor.cpp
5+
lib/gx/command_processor.cpp
6+
lib/gx/fifo.cpp
7+
lib/gx/gx.cpp
8+
lib/gx/pipeline.cpp
9+
lib/gx/shader.cpp
10+
lib/gx/shader_info.cpp
1111
lib/dolphin/gx/GXBump.cpp
1212
lib/dolphin/gx/GXCull.cpp
1313
lib/dolphin/gx/GXDispList.cpp

include/aurora/aurora.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,6 @@ void aurora_end_frame();
102102
AuroraBackend aurora_get_backend();
103103
const AuroraBackend* aurora_get_available_backends(size_t* count);
104104

105-
#ifndef NDEBUG
106-
#define AURORA_GFX_DEBUG_GROUPS
107-
#endif
108-
109-
void push_debug_group(const char* label);
110-
void pop_debug_group();
111-
112105
#ifdef __cplusplus
113106
}
114107
#endif

include/aurora/gfx.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef AURORA_GFX_H
2+
#define AURORA_GFX_H
3+
4+
#ifdef __cplusplus
5+
#include <cstdint>
6+
7+
extern "C" {
8+
#else
9+
#include "stdint.h"
10+
#endif
11+
12+
#ifndef NDEBUG
13+
#define AURORA_GFX_DEBUG_GROUPS
14+
#endif
15+
16+
void push_debug_group(const char* label);
17+
void pop_debug_group();
18+
19+
typedef struct {
20+
uint32_t queuedPipelines;
21+
uint32_t createdPipelines;
22+
uint32_t drawCallCount;
23+
uint32_t mergedDrawCallCount;
24+
uint32_t lastVertSize;
25+
uint32_t lastUniformSize;
26+
uint32_t lastIndexSize;
27+
uint32_t lastStorageSize;
28+
} AuroraStats;
29+
30+
const AuroraStats* aurora_get_stats();
31+
32+
#ifdef __cplusplus
33+
}
34+
#endif
35+
36+
#endif

lib/dolphin/gx/GXDispList.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "gx.hpp"
22
#include "__gx.h"
33

4-
#include "../../gfx/fifo.hpp"
4+
#include "../../gx/command_processor.hpp"
5+
#include "../../gx/fifo.hpp"
56

67
#include <cstring>
78

@@ -24,7 +25,7 @@ void GXBeginDisplayList(void* list, u32 size) {
2425
__gx->inDispList = 1;
2526

2627
// Redirect FIFO writes to the user-provided buffer
27-
aurora::gfx::fifo::begin_display_list(static_cast<u8*>(list), size);
28+
aurora::gx::fifo::begin_display_list(static_cast<u8*>(list), size);
2829
}
2930

3031
u32 GXEndDisplayList() {
@@ -34,7 +35,7 @@ u32 GXEndDisplayList() {
3435
}
3536

3637
// End FIFO redirection and get the byte count (ROUNDUP32)
37-
u32 bytesWritten = aurora::gfx::fifo::end_display_list();
38+
u32 bytesWritten = aurora::gx::fifo::end_display_list();
3839

3940
// Restore saved shadow register state
4041
if (__gx->dlSaveContext != 0) {
@@ -60,10 +61,10 @@ void GXCallDisplayList(const void* data, u32 nbytes) {
6061
// Drain the internal FIFO so that any pending CP register writes
6162
// (VCD, VAT, etc.) are processed into g_gxState before the display
6263
// list's draw commands reference them.
63-
aurora::gfx::fifo::drain();
64+
aurora::gx::fifo::drain();
6465

6566
// Process the display list through the command processor
66-
aurora::gfx::fifo::process(static_cast<const u8*>(data), nbytes, true);
67+
aurora::gx::fifo::process(static_cast<const u8*>(data), nbytes, true);
6768
}
6869

6970
void GXCallDisplayListLE(const void* data, u32 nbytes) {
@@ -80,9 +81,9 @@ void GXCallDisplayListLE(const void* data, u32 nbytes) {
8081
// Drain the internal FIFO so that any pending CP register writes
8182
// (VCD, VAT, etc.) are processed into g_gxState before the display
8283
// list's draw commands reference them.
83-
aurora::gfx::fifo::drain();
84+
aurora::gx::fifo::drain();
8485

8586
// Process the display list through the command processor (little-endian)
86-
aurora::gfx::fifo::process(static_cast<const u8*>(data), nbytes, false);
87+
aurora::gx::fifo::process(static_cast<const u8*>(data), nbytes, false);
8788
}
8889
}

lib/dolphin/gx/GXManage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "gx.hpp"
22
#include "__gx.h"
33

4-
#include "../../gfx/fifo.hpp"
4+
#include "../../gx/fifo.hpp"
55

66
#include <cstring>
77

@@ -29,7 +29,7 @@ GXFifoObj* GXInit(void* base, u32 size) {
2929
__gx->vNum = 0;
3030

3131
// Initialize FIFO subsystem
32-
aurora::gfx::fifo::init();
32+
aurora::gx::fifo::init();
3333
GXInitFifoBase(&sFifoObj, base, size);
3434
GXSetCPUFifo(&sFifoObj);
3535
GXSetGPFifo(&sFifoObj);

lib/dolphin/gx/GXVert.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "gx.hpp"
22
#include "__gx.h"
3-
#include "../../gfx/fifo.hpp"
3+
#include "../../gx/fifo.hpp"
44

55
// Track vertex count between GXBegin/GXEnd for mismatch detection
66
static u16 sBeginNVerts = 0;
@@ -27,13 +27,13 @@ void GXBegin(GXPrimitive primitive, GXVtxFmt vtxFmt, u16 nVerts) {
2727

2828
// Record state for vertex count validation in GXEnd
2929
sBeginNVerts = nVerts;
30-
sBeginFifoSize = aurora::gfx::fifo::get_buffer_size();
30+
sBeginFifoSize = aurora::gx::fifo::get_buffer_size();
3131
sInBegin = true;
3232
}
3333

3434
void GXEnd() {
3535
if (sInBegin) {
36-
u32 bytesWritten = aurora::gfx::fifo::get_buffer_size() - sBeginFifoSize;
36+
u32 bytesWritten = aurora::gx::fifo::get_buffer_size() - sBeginFifoSize;
3737
if (sBeginNVerts > 0 && bytesWritten > 0) {
3838
u32 vtxSize = bytesWritten / sBeginNVerts;
3939
u32 remainder = bytesWritten % sBeginNVerts;
@@ -48,8 +48,8 @@ void GXEnd() {
4848
}
4949
sInBegin = false;
5050
}
51-
if (!aurora::gfx::fifo::in_display_list()) {
52-
aurora::gfx::fifo::drain();
51+
if (!aurora::gx::fifo::in_display_list()) {
52+
aurora::gx::fifo::drain();
5353
}
5454
}
5555

@@ -201,28 +201,27 @@ void GXTexCoord1x16(u16 index) { GX_WRITE_U16(index); }
201201

202202
void GXTexCoord1x8(u8 index) { GX_WRITE_U8(index); }
203203

204-
void GXCmd1u8(const u8 x) { aurora::gfx::fifo::write_u8(static_cast<uint8_t>(x)); }
205-
void GXCmd1u16(const u16 x) { aurora::gfx::fifo::write_u16(static_cast<uint16_t>(x)); }
206-
void GXCmd1u32(const u32 x) { aurora::gfx::fifo::write_u32(static_cast<uint32_t>(x)); }
207-
208-
void GXParam1u8(const u8 x) { aurora::gfx::fifo::write_u8(static_cast<uint8_t>(x)); }
209-
void GXParam1u16(const u16 x) { aurora::gfx::fifo::write_u16(static_cast<uint16_t>(x)); }
210-
void GXParam1u32(const u32 x) { aurora::gfx::fifo::write_u32(static_cast<uint32_t>(x)); }
211-
void GXParam1s8(const s8 x) { aurora::gfx::fifo::write_u8(static_cast<uint8_t>(x)); }
212-
void GXParam1s16(const s16 x) { aurora::gfx::fifo::write_u16(static_cast<uint16_t>(x)); }
213-
void GXParam1s32(const s32 x) { aurora::gfx::fifo::write_u32(static_cast<uint32_t>(x)); }
214-
void GXParam1f32(const f32 x) { aurora::gfx::fifo::write_f32(x); }
204+
void GXCmd1u8(const u8 x) { aurora::gx::fifo::write_u8(x); }
205+
void GXCmd1u16(const u16 x) { aurora::gx::fifo::write_u16(x); }
206+
void GXCmd1u32(const u32 x) { aurora::gx::fifo::write_u32(x); }
207+
208+
void GXParam1u8(const u8 x) { aurora::gx::fifo::write_u8(x); }
209+
void GXParam1u16(const u16 x) { aurora::gx::fifo::write_u16(x); }
210+
void GXParam1u32(const u32 x) { aurora::gx::fifo::write_u32(x); }
211+
void GXParam1s8(const s8 x) { aurora::gx::fifo::write_u8(static_cast<uint8_t>(x)); }
212+
void GXParam1s16(const s16 x) { aurora::gx::fifo::write_u16(static_cast<uint16_t>(x)); }
213+
void GXParam1s32(const s32 x) { aurora::gx::fifo::write_u32(static_cast<uint32_t>(x)); }
214+
void GXParam1f32(const f32 x) { aurora::gx::fifo::write_f32(x); }
215215
void GXParam3f32(const f32 x, const f32 y, const f32 z) {
216-
aurora::gfx::fifo::write_f32(x);
217-
aurora::gfx::fifo::write_f32(y);
218-
aurora::gfx::fifo::write_f32(z);
216+
aurora::gx::fifo::write_f32(x);
217+
aurora::gx::fifo::write_f32(y);
218+
aurora::gx::fifo::write_f32(z);
219219
}
220220
void GXParam4f32(const f32 x, const f32 y, const f32 z, const f32 w) {
221-
aurora::gfx::fifo::write_f32(x);
222-
aurora::gfx::fifo::write_f32(y);
223-
aurora::gfx::fifo::write_f32(z);
224-
aurora::gfx::fifo::write_f32(w);
221+
aurora::gx::fifo::write_f32(x);
222+
aurora::gx::fifo::write_f32(y);
223+
aurora::gx::fifo::write_f32(z);
224+
aurora::gx::fifo::write_f32(w);
225225
}
226226

227-
228227
} // extern "C"

lib/dolphin/gx/__gx.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
#include <dolphin/gx.h>
44

55
// Forward declare FIFO write functions
6-
namespace aurora::gfx::fifo {
6+
namespace aurora::gx::fifo {
77
void write_u8(u8 val);
88
void write_u16(u16 val);
99
void write_u32(u32 val);
1010
void write_f32(f32 val);
1111
} // namespace aurora::gfx::fifo
1212

1313
// FIFO write macros - route through software FIFO buffer
14-
#define GX_WRITE_U8(ub) aurora::gfx::fifo::write_u8(static_cast<u8>(ub))
15-
#define GX_WRITE_U16(us) aurora::gfx::fifo::write_u16(static_cast<u16>(us))
16-
#define GX_WRITE_U32(ui) aurora::gfx::fifo::write_u32(static_cast<u32>(ui))
17-
#define GX_WRITE_F32(f) aurora::gfx::fifo::write_f32(static_cast<f32>(f))
14+
#define GX_WRITE_U8(ub) aurora::gx::fifo::write_u8(static_cast<u8>(ub))
15+
#define GX_WRITE_U16(us) aurora::gx::fifo::write_u16(static_cast<u16>(us))
16+
#define GX_WRITE_U32(ui) aurora::gx::fifo::write_u32(static_cast<u32>(ui))
17+
#define GX_WRITE_F32(f) aurora::gx::fifo::write_f32(static_cast<f32>(f))
1818

1919
// XF register write: opcode 0x10, address in XF space (0x1000+addr), then value
2020
#define GX_WRITE_XF_REG(addr, value) \

lib/dolphin/gx/gx.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#pragma once
22

33
#include "../../internal.hpp"
4-
#include "../../gfx/gx.hpp"
4+
#include "../../gx/gx.hpp"
55

66
static aurora::Module Log("aurora::gx");
77

8-
using aurora::gfx::gx::g_gxState;
8+
using aurora::gx::g_gxState;
99

1010
template <typename T>
1111
static inline void update_gx_state(T& val, T newVal) {

lib/gfx/command_processor.hpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)