20kdm2: new memory map; new pipelining implementation

This commit is contained in:
Zack Buhman 2025-04-27 02:31:20 -05:00
parent ee2235c632
commit eb45b65895
3 changed files with 134 additions and 51 deletions

View File

@ -11,7 +11,7 @@
#include "holly/ta_global_parameter.hpp"
#include "holly/ta_parameter.hpp"
#include "holly/ta_vertex_parameter.hpp"
#include "holly/texture_memory_alloc3.hpp"
#include "holly/texture_memory_alloc5.hpp"
#include "holly/video_output.hpp"
#include "systembus.hpp"
@ -1584,14 +1584,17 @@ constexpr struct opb_size opb_size[ta_cont_count] = {
static volatile int ta_in_use = 0;
static volatile int core_in_use = 0;
static volatile int next_frame;
static volatile int next_frame = 0;
static volatile int framebuffer_ix = 0;
static volatile int next_frame_ix = 0;
static inline void pump_events(uint32_t istnrm)
{
if (istnrm & istnrm::v_blank_in) {
system.ISTNRM = istnrm::v_blank_in;
holly.FB_R_SOF1 = texture_memory_alloc.framebuffer[next_frame].start;
next_frame = 1;
holly.FB_R_SOF1 = texture_memory_alloc.framebuffer[next_frame_ix].start;
}
if (istnrm & istnrm::end_of_render_tsp) {
@ -1599,12 +1602,23 @@ static inline void pump_events(uint32_t istnrm)
| istnrm::end_of_render_isp
| istnrm::end_of_render_video;
next_frame_ix = framebuffer_ix;
framebuffer_ix += 1;
if (framebuffer_ix >= 3) framebuffer_ix = 0;
core_in_use = 0;
}
if (istnrm & istnrm::end_of_transferring_opaque_modifier_volume_list) {
system.ISTNRM = istnrm::end_of_transferring_opaque_modifier_volume_list;
core_in_use = 1;
core_start_render2(texture_memory_alloc.region_array.start,
texture_memory_alloc.isp_tsp_parameters.start,
texture_memory_alloc.background[0].start,
texture_memory_alloc.framebuffer[framebuffer_ix].start,
framebuffer_width);
ta_in_use = 0;
}
}
@ -1668,17 +1682,15 @@ int main()
| istnrm::v_blank_in
| istnrm::end_of_transferring_opaque_modifier_volume_list;
for (int i = 0; i < 2; i++) {
region_array_multipass(tile_width,
tile_height,
opb_size,
ta_cont_count,
texture_memory_alloc.region_array[i].start,
texture_memory_alloc.object_list[i].start);
region_array_multipass(tile_width,
tile_height,
opb_size,
ta_cont_count,
texture_memory_alloc.region_array.start,
texture_memory_alloc.object_list.start);
background_parameter2(texture_memory_alloc.background[i].start,
0xff202040);
}
background_parameter2(texture_memory_alloc.background[0].start,
0xff202040);
ta_parameter_writer writer = ta_parameter_writer(ta_parameter_buf, (sizeof (ta_parameter_buf)));
@ -1703,30 +1715,7 @@ int main()
holly.FPU_SHAD_SCALE = fpu_shad_scale::simple_shadow_enable::parameter_selection_volume_mode;
for (int i = 0; i < 2; i++) {
trans = update_analog(trans);
mat4x4 trans_inv = inverse(trans);
writer.offset = 0;
transfer_scene(writer, trans, trans_inv);
ta_polygon_converter_init2(texture_memory_alloc.isp_tsp_parameters[i].start,
texture_memory_alloc.isp_tsp_parameters[i].end,
texture_memory_alloc.object_list[i].start,
texture_memory_alloc.object_list[i].end,
opb_size[0].total(),
ta_alloc,
tile_width,
tile_height);
ta_polygon_converter_writeback(writer.buf, writer.offset);
ta_polygon_converter_transfer(writer.buf, writer.offset);
while (ta_in_use);
}
int ta = 0;
while (1) {
int core = !ta;
maple::dma_wait_complete();
do_get_condition();
@ -1736,11 +1725,12 @@ int main()
transfer_scene(writer, trans, trans_inv);
while (ta_in_use);
while (core_in_use);
ta_in_use = 1;
ta_polygon_converter_init2(texture_memory_alloc.isp_tsp_parameters[ta].start,
texture_memory_alloc.isp_tsp_parameters[ta].end,
texture_memory_alloc.object_list[ta].start,
texture_memory_alloc.object_list[ta].end,
ta_polygon_converter_init2(texture_memory_alloc.isp_tsp_parameters.start,
texture_memory_alloc.isp_tsp_parameters.end,
texture_memory_alloc.object_list.start,
texture_memory_alloc.object_list.end,
opb_size[0].total(),
ta_alloc,
tile_width,
@ -1748,16 +1738,7 @@ int main()
ta_polygon_converter_writeback(writer.buf, writer.offset);
ta_polygon_converter_transfer(writer.buf, writer.offset);
while (current_frame != core);
core_in_use = 1;
core_start_render2(texture_memory_alloc.region_array[core].start,
texture_memory_alloc.isp_tsp_parameters[core].start,
texture_memory_alloc.background[core].start,
texture_memory_alloc.framebuffer[core].start,
framebuffer_width);
ta = !ta;
next_frame = ta;
while (next_frame)
next_frame = 0;
}
}

View File

@ -0,0 +1,32 @@
#pragma once
#include <cstdint>
#include <cstddef>
struct texture_memory_alloc__start_end {
uint32_t start;
uint32_t end;
};
struct texture_memory_alloc {
struct texture_memory_alloc__start_end isp_tsp_parameters;
struct texture_memory_alloc__start_end object_list;
struct texture_memory_alloc__start_end region_array;
struct texture_memory_alloc__start_end framebuffer[3];
struct texture_memory_alloc__start_end background[2];
struct texture_memory_alloc__start_end texture;
};
constexpr texture_memory_alloc texture_memory_alloc = {
// 32-bit addresses start end start end
.isp_tsp_parameters = {0x000000, 0x11bfe0},
.object_list = {0x400000, 0x495fe0},
.region_array = {0x11c000, 0x12c000},
.framebuffer = {{0x496000, 0x52c000},
{0x12c000, 0x1c2000},
{0x52c000, 0x5c2000}},
.background = {{0x1c2000, 0x1c2020},
{0x5c2000, 0x5c2020}},
// 64-bit addresses
.texture = {0x384040, 0x800000}
};

View File

@ -0,0 +1,70 @@
import struct
with open("texture_memory_write_64_read_32.bin", "rb") as f:
buf = memoryview(f.read())
lookup = [
struct.unpack("<I", buf[i*4:i*4+4])[0] & 0x7fff_ffff
for i in range(8 * 1024 * 1024 // 4)
]
#for n in lookup:
# print(f"{n:08x}")
allocations = {
"isp_tsp_parameters" : (0x11_c000 , 32 ),
"object_list" : (0x09_6000 , 32 ),
"region_array" : (0x01_0000 , 0 ),
"framebuffer0" : (0x09_6000 , 0 ),
"framebuffer1" : (0x09_6000 , 0 ),
"framebuffer2" : (0x09_6000 , 0 ),
"background0" : (0x00_0040 , 32 ),
"background1" : (0x00_0040 , 32 ),
}
def gen_allocations():
acc = [0x00_0000, 0x40_0000]
acc_i = 0
for name, (size, pad) in allocations.items():
start = acc[acc_i]
end = start + size - pad
yield name, (start, end)
acc[acc_i] += size
acc_i = int(not acc_i)
def print_alloc():
for name, (start, end) in gen_allocations():
print(name, f"{start:06x}", f"{end:06x}")
print_alloc()
def allocate_bitmap(mem, lookup, start, end):
word_s = start // 4
end_s = end // 4
for i in range(word_s, end_s):
addr64 = lookup[i]
assert mem[addr64] == 0, (mem[addr64], i, addr64)
mem[addr64] = (1 << 31) | i
mem64 = [0] * (0x80_0000 // 4)
for name, (start, end) in gen_allocations():
allocate_bitmap(mem64, lookup, start, end)
from PIL import Image
im = Image.new("RGB", (1024, 2048))
width, height = im.size
for y in range(height):
for x in range(width):
color = (255, 128, 0) if mem64[y * 1024 + x] != 0 else (0, 255, 0)
im.putpixel((x, y), color)
im.save("map.png")
texture_address = None
for i in reversed(range(len(mem64))):
if mem64[i] != 0:
texture_address = (i + 1) * 4
break
print(f"texture {texture_address:06x}")