distribute rendering to master and slave

This commit is contained in:
Zack Buhman 2023-01-25 02:54:13 -08:00
parent ab809791cd
commit afbe61a402
4 changed files with 49 additions and 5 deletions

View File

@ -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);
}

View File

@ -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"

View File

@ -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,

View File

@ -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));