From 30e56761a84b65336d57dc524a74b5d93ca09c7b Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Thu, 3 Oct 2024 22:55:50 +0100 Subject: [PATCH] Rework config defines Now they can be overwritten without editing the file --- lib/config.h | 16 ++++++++++++++++ lib/render-3d.cpp | 36 ++++++++++++++++++------------------ lib/render-3d.hpp | 8 ++------ 3 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 lib/config.h diff --git a/lib/config.h b/lib/config.h new file mode 100644 index 0000000..4848159 --- /dev/null +++ b/lib/config.h @@ -0,0 +1,16 @@ +#pragma once + +#ifdef PICO_BUILD +// default to fast +#ifndef PICO_INTERP +#define PICO_INTERP 1 +#endif + +#ifndef PICO_MULTICORE +#define PICO_MULTICORE 1 +#endif +#else +// not a pico so these make no sense +#undef PICO_INTERP +#undef PICO_MULTICORE +#endif \ No newline at end of file diff --git a/lib/render-3d.cpp b/lib/render-3d.cpp index d246f85..177d806 100644 --- a/lib/render-3d.cpp +++ b/lib/render-3d.cpp @@ -39,7 +39,7 @@ Pen operator +(Pen p, PenDelta d) return {uint8_t(p.r + d.r), uint8_t(p.g + d.g), uint8_t(p.b + d.b), uint8_t(p.a + d.a)}; } -#ifdef PICO_MULTICORE +#if PICO_MULTICORE auto_init_mutex(blit_mutex); enum class Core1Job @@ -97,7 +97,7 @@ Render3D::Render3D() : tile_surf(reinterpret_cast(tile_colour_buffer) for(int i = 0; i < max_textures; i++) textures[i] = nullptr; -#ifdef PICO_MULTICORE +#if PICO_MULTICORE // we own core1 now // theoretically this could handle multiple instances multicore_launch_core1(core1_entry); @@ -111,7 +111,7 @@ void Render3D::draw(int count, const uint8_t *ptr) auto trans = transformed_vertex_ptr; -#ifdef PICO_MULTICORE +#if PICO_MULTICORE auto core_num = get_core_num(); if(core_num == 0) { @@ -176,7 +176,7 @@ void Render3D::draw(int count, const uint8_t *ptr) trans += stride; } -#ifdef PICO_MULTICORE +#if PICO_MULTICORE if(core_num == 0) { auto trans2 = reinterpret_cast(multicore_fifo_pop_blocking()); @@ -272,7 +272,7 @@ void Render3D::rasterise() if(!transformed_vertex_ptr) return; -#ifdef PICO_MULTICORE +#if PICO_MULTICORE // launch the other core if needed auto core_num = get_core_num(); if(core_num == 0) @@ -282,7 +282,7 @@ void Render3D::rasterise() } #endif -#ifdef PICO_INTERP +#if PICO_INTERP // setup interpolators auto config = interp_default_config(); @@ -325,7 +325,7 @@ void Render3D::rasterise() auto depth_buf = tile_depth_buffer; const auto tile_buf_size = sizeof(tile_colour_buffer) / num_tile_bufs; -#ifdef PICO_MULTICORE +#if PICO_MULTICORE // offset for per-core tile buffers col_buf += core_num * tile_width * tile_height; depth_buf += core_num * tile_width * tile_height; @@ -335,7 +335,7 @@ void Render3D::rasterise() // rasterise triangles for each screen tile for(int y = 0; y < screen.bounds.h; y += tile_height) { -#ifdef PICO_MULTICORE +#if PICO_MULTICORE // split tiles between cores // C0 C1 C0 ... // C1 C0 C1 ... @@ -365,7 +365,7 @@ void Render3D::rasterise() if(screen.format == PixelFormat::BGR555) { // assume picovision, which has a 555 -> 555 blit -#ifdef PICO_MULTICORE +#if PICO_MULTICORE // blitting on both cores at once would blow up mutex_enter_blocking(&blit_mutex); #endif @@ -373,7 +373,7 @@ void Render3D::rasterise() tile_surf.data = reinterpret_cast(col_buf); screen.blit(&tile_surf, {0, 0, tile_width, tile_height}, {x, y}); -#ifdef PICO_MULTICORE +#if PICO_MULTICORE mutex_exit(&blit_mutex); #endif } @@ -386,7 +386,7 @@ void Render3D::rasterise() } } -#ifdef PICO_MULTICORE +#if PICO_MULTICORE if(core_num == 0) { // wait for core1 and reset @@ -540,7 +540,7 @@ void blit_fast_code(Render3D::fill_triangle)(VertexOutData *data, blit::Point ti y_start = 0; } -#ifdef PICO_INTERP +#if PICO_INTERP interp0->accum[0] = start_x.raw(); interp0->base[0] = start_x_step.raw(); interp0->accum[1] = end_x.raw(); @@ -576,7 +576,7 @@ void blit_fast_code(Render3D::fill_triangle)(VertexOutData *data, blit::Point ti gradient_h_line(int32_t(start_x), int32_t(end_x), start_z, end_z, y, start_col, end_col); } -#ifdef PICO_INTERP +#if PICO_INTERP // read back out start_x = Fixed32<>::from_raw(interp0->accum[0]); #endif @@ -612,7 +612,7 @@ void blit_fast_code(Render3D::fill_triangle)(VertexOutData *data, blit::Point ti y_start = 0; } -#ifdef PICO_INTERP +#if PICO_INTERP interp0->accum[0] = start_x.raw(); interp0->base[0] = start_x_step.raw(); interp0->accum[1] = end_x.raw(); @@ -696,7 +696,7 @@ void blit_fast_code(Render3D::gradient_h_line)(int x1, int x2, uint16_t z1, uint auto col_ptr = tile_colour_buffer + x1 + y * tile_width; auto depth_ptr = tile_depth_buffer + x1 + y * tile_width; -#ifdef PICO_MULTICORE +#if PICO_MULTICORE auto core_num = get_core_num(); col_ptr += core_num * tile_width * tile_height; depth_ptr += core_num * tile_width * tile_height; @@ -774,7 +774,7 @@ void blit_fast_code(Render3D::textured_h_line)(int x1, int x2, uint16_t z1, uint auto col_ptr = tile_colour_buffer + x1 + y * tile_width; auto depth_ptr = tile_depth_buffer + x1 + y * tile_width; -#ifdef PICO_MULTICORE +#if PICO_MULTICORE auto core_num = get_core_num(); col_ptr += core_num * tile_width * tile_height; depth_ptr += core_num * tile_width * tile_height; @@ -782,7 +782,7 @@ void blit_fast_code(Render3D::textured_h_line)(int x1, int x2, uint16_t z1, uint auto end_ptr = col_ptr + (x2 - x1); -#ifdef PICO_INTERP +#if PICO_INTERP interp1->accum[0] = u.raw(); interp1->accum[1] = v.raw(); @@ -806,7 +806,7 @@ void blit_fast_code(Render3D::textured_h_line)(int x1, int x2, uint16_t z1, uint continue; // this could be optimised -#ifdef PICO_INTERP +#if PICO_INTERP auto tex_col = tex->get_pixel(tex_offset); #else auto tex_col = tex->get_pixel({(u.raw() >> (16 - tex_size_bits)) & (tex_size - 1), (v.raw() >> (16 - tex_size_bits)) & (tex_size - 1)}); diff --git a/lib/render-3d.hpp b/lib/render-3d.hpp index 55059d5..98e8cd5 100644 --- a/lib/render-3d.hpp +++ b/lib/render-3d.hpp @@ -4,13 +4,9 @@ #include "graphics/surface.hpp" #include "types/point.hpp" +#include "config.h" #include "fixed-mat4.hpp" -#ifdef PICO_BUILD -// tiny bit of config -#define PICO_INTERP -#define PICO_MULTICORE -#endif class Render3D { @@ -72,7 +68,7 @@ class Render3D VertexOutData *transformed_vertex_ptr = nullptr; static constexpr int tile_width = 160, tile_height = 80; -#ifdef PICO_MULTICORE +#if PICO_MULTICORE static constexpr int num_tile_bufs = 2; #else static constexpr int num_tile_bufs = 1;