Skip to content

Commit

Permalink
Rework config defines
Browse files Browse the repository at this point in the history
Now they can be overwritten without editing the file
  • Loading branch information
Daft-Freak committed Oct 3, 2024
1 parent 251e5dc commit 30e5676
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
16 changes: 16 additions & 0 deletions lib/config.h
Original file line number Diff line number Diff line change
@@ -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
36 changes: 18 additions & 18 deletions lib/render-3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -97,7 +97,7 @@ Render3D::Render3D() : tile_surf(reinterpret_cast<uint8_t *>(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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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<VertexOutData *>(multicore_fifo_pop_blocking());
Expand Down Expand Up @@ -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)
Expand All @@ -282,7 +282,7 @@ void Render3D::rasterise()
}
#endif

#ifdef PICO_INTERP
#if PICO_INTERP
// setup interpolators
auto config = interp_default_config();

Expand Down Expand Up @@ -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;
Expand All @@ -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 ...
Expand Down Expand Up @@ -365,15 +365,15 @@ 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

tile_surf.data = reinterpret_cast<uint8_t *>(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
}
Expand All @@ -386,7 +386,7 @@ void Render3D::rasterise()
}
}

#ifdef PICO_MULTICORE
#if PICO_MULTICORE
if(core_num == 0)
{
// wait for core1 and reset
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -774,15 +774,15 @@ 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;
#endif

auto end_ptr = col_ptr + (x2 - x1);

#ifdef PICO_INTERP
#if PICO_INTERP
interp1->accum[0] = u.raw();
interp1->accum[1] = v.raw();

Expand All @@ -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)});
Expand Down
8 changes: 2 additions & 6 deletions lib/render-3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 30e5676

Please sign in to comment.