From 27378f3537e9dbe0bfeb1ebb8a653e6050f2ea4a Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sun, 8 Feb 2026 18:29:34 -0800 Subject: Implement basic perf counters --- src/swgfx.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/swgfx.c') diff --git a/src/swgfx.c b/src/swgfx.c index bbf9a5b..78d5434 100644 --- a/src/swgfx.c +++ b/src/swgfx.c @@ -19,6 +19,8 @@ Coordinate systems: #include #include + + static constexpr sgVec3 Up3 = (sgVec3){0,1,0}; typedef struct sgViewport_t { int x0, y0, width, height; } sgViewport_t; @@ -50,6 +52,7 @@ typedef struct swgfx { sgTextureFilter textureFilter; // Filter method for the texture. sgImage defaultTexture; // A default for when no texture is provided. sgPixel defaultPixel; // The single-pixel of the default texture. + sgCounters counters; } swgfx; static inline int mod(int a, int m) { return (m + (a % m)) % m; } @@ -306,6 +309,9 @@ static inline R* Depth(swgfx* gfx, int x, int y) { static inline void SetPixel(swgfx* gfx, const sgVec2i p, sgPixel colour) { assert(gfx); *Pixel(gfx, p.x, p.y) = colour; +#if SWGFX_PROFILING + gfx->counters.pixels++; +#endif // SWGFX_PROFILING } static inline void SetDepth(swgfx* gfx, const sgVec2i p, R depth) { @@ -448,6 +454,9 @@ static void DrawTriangle2(swgfx* gfx, const sgTri2* const tri) { } } } +#if SWGFX_PROFILING + gfx->counters.triangles2++; +#endif // SWGFX_PROFILING } static inline sgVec4 PerspDivide(sgVec4 v) { @@ -677,6 +686,9 @@ static void DrawTriangle3(swgfx* gfx, const sgTri3* const tri) { for (int i = 0; i < numTris; ++i) { DrawTriangle3PostClip(gfx, &tris[i]); } +#if SWGFX_PROFILING + gfx->counters.triangles3++; +#endif // SWGFX_PROFILING } #define is_pow2_or_0(X) ((X & (X - 1)) == 0) @@ -768,6 +780,10 @@ void sgPresent(swgfx* gfx, sgVec2i dimensions, sgScreenPixel* screen) { } } } + +#if SWGFX_PROFILING + gfx->counters.frames++; +#endif // SWGFX_PROFILING } static void sgUpdateViewProjection(swgfx* gfx) { @@ -930,6 +946,11 @@ static bool ViewportWithinBuffer(swgfx* gfx) { ((vp.y0 + vp.height) <= gfx->dims.y); } +sgCounters sgGetCounters(const swgfx* gfx) { + assert(gfx); + return gfx->counters; +} + void sgCheck(swgfx* gfx) { assert(gfx); assert(ViewportWithinBuffer(gfx)); -- cgit v1.2.3