From afbe61a402201a5d23726cde1a83a040d36ee2be Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Wed, 25 Jan 2023 02:54:13 -0800 Subject: [PATCH] distribute rendering to master and slave --- main-hosted.cpp | 3 ++- main-saturn.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- raytracing.cpp | 8 ++++++-- raytracing.hpp | 2 +- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/main-hosted.cpp b/main-hosted.cpp index 088b900..56c00e5 100644 --- a/main-hosted.cpp +++ b/main-hosted.cpp @@ -50,7 +50,8 @@ void render_ppm(ostream& out) int main() { - render(put_pixel); + render(0, put_pixel); + render(1, put_pixel); render_ppm(cout); } diff --git a/main-saturn.cpp b/main-saturn.cpp index 087c93b..0487605 100644 --- a/main-saturn.cpp +++ b/main-saturn.cpp @@ -54,6 +54,43 @@ void fill(T * buf, T v, int32_t n) noexcept } } +extern "C" +void slave_main(void) +{ + render(1, put_pixel); + + while (1) {} +} + +void start_slave() +{ + /* + Items Common to Command Issue Timing + As mentioned above, issuing commands for 300 µs from V-BLANK-IN is + prohibited. + */ + while ((smpc.reg.SF & 0x01) == 1); + + smpc.reg.SF = 1; + smpc.reg.COMREG = COMREG__SSHOFF; + + while ((smpc.reg.SF & 0x01) == 1); + + /* + volatile void (*foo)(uint32_t, void*); + foo = *(volatile void (**)(uint32_t, void*))0x6000310; + foo(0x94, (void*)&slave_main); + */ + sh2_vec[0x94] = (uint32_t)(&slave_main); + + for (volatile int i = 0; i < 10; i++); + + smpc.reg.SF = 1; + smpc.reg.COMREG = COMREG__SSHON; + + while ((smpc.reg.SF & 0x01) == 1); +} + void main_asdf() { // DISP: Please make sure to change this bit from 0 to 1 during V blank. @@ -89,7 +126,9 @@ void main_asdf() vdp2.reg.WCTLB = 0; vdp2.reg.WCTLC = 0; - render(put_pixel); + start_slave(); + + render(0, put_pixel); } extern "C" diff --git a/raytracing.cpp b/raytracing.cpp index 6c3ceea..7b324a1 100644 --- a/raytracing.cpp +++ b/raytracing.cpp @@ -173,13 +173,17 @@ static vec3 trace_ray } } -void render(void (&put_pixel) (int32_t x, int32_t y, const vec3& c)) +void render(int half, void (&put_pixel) (int32_t x, int32_t y, const vec3& c)) { using namespace canvas; vec3 origin = vec3(0, 0, 0); - for (int x = -(width/2); x < (width/2); x++) { + int x_low = half ? 0 : -(width/2); + int x_high = half ? (width/2) : 0; + + //for (int x = -(width/2); x < (width/2); x++) { + for (int x = x_low; x < x_high; x++) { for (int y = -(height/2 + 1); y < (height/2 + 1); y++) { vec3 direction = canvas_to_viewport(x, y); vec3 color = trace_ray(origin, direction, diff --git a/raytracing.hpp b/raytracing.hpp index b8eeb4e..21fa63d 100644 --- a/raytracing.hpp +++ b/raytracing.hpp @@ -12,4 +12,4 @@ namespace canvas { constexpr int height = (1 << bit_height); } -void render(void (&put_pixel) (int32_t x, int32_t y, const vec3& c)); +void render(int half, void (&put_pixel) (int32_t x, int32_t y, const vec3& c));