remove framebuffer tracking (#381)

* remove framebuffer tracking

* more
This commit is contained in:
Logan McNaughton 2025-04-15 11:08:40 +02:00 committed by GitHub
parent 27bb66df4c
commit 383b568012
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 2 additions and 145 deletions

View File

@ -108,7 +108,6 @@ fn main() {
.allowlist_function("rdp_process_commands")
.allowlist_function("rdp_check_callback")
.allowlist_function("rdp_new_processor")
.allowlist_function("rdp_check_framebuffers")
.allowlist_function("rdp_state_size")
.allowlist_function("rdp_save_state")
.allowlist_function("rdp_load_state")

View File

@ -52,25 +52,12 @@ enum vi_registers
VI_REGS_COUNT
};
typedef struct
{
uint32_t depthbuffer_address;
uint32_t framebuffer_address;
uint32_t texture_address;
uint32_t framebuffer_pixel_size;
uint32_t framebuffer_width;
uint32_t texture_pixel_size;
uint32_t texture_width;
uint32_t framebuffer_height;
} FrameBufferInfo;
typedef struct
{
uint32_t cmd_data[0x00040000 >> 2];
int cmd_cur;
int cmd_ptr;
uint32_t region;
FrameBufferInfo frame_buffer_info;
} RDP_DEVICE;
static SDL_Window *window;
@ -85,9 +72,6 @@ static GFX_INFO gfx_info;
static const uint32_t *fragment_spirv;
static size_t fragment_size;
std::vector<bool> rdram_dirty;
uint64_t sync_signal;
typedef struct
{
float SourceSize[4];
@ -219,12 +203,6 @@ void rdp_new_processor(GFX_INFO _gfx_info)
{
gfx_info = _gfx_info;
sync_signal = 0;
rdram_dirty.assign(gfx_info.RDRAM_SIZE / 8, false);
rdp_device.frame_buffer_info.framebuffer_address = rdram_dirty.size();
rdp_device.frame_buffer_info.depthbuffer_address = rdram_dirty.size();
rdp_device.frame_buffer_info.texture_address = rdram_dirty.size();
if (processor)
{
delete processor;
@ -469,16 +447,6 @@ CALL_BACK rdp_check_callback()
return return_value;
}
void rdp_check_framebuffers(uint32_t address)
{
if (sync_signal && rdram_dirty[address >> 3])
{
processor->wait_for_timeline(sync_signal);
rdram_dirty.assign(gfx_info.RDRAM_SIZE / 8, false);
sync_signal = 0;
}
}
size_t rdp_state_size()
{
return sizeof(RDP_DEVICE);
@ -486,7 +454,6 @@ size_t rdp_state_size()
void rdp_save_state(uint8_t *state)
{
processor->wait_for_timeline(processor->signal_timeline());
memcpy(state, &rdp_device, sizeof(RDP_DEVICE));
}
@ -495,47 +462,6 @@ void rdp_load_state(const uint8_t *state)
memcpy(&rdp_device, state, sizeof(RDP_DEVICE));
}
uint32_t texture_size(uint32_t area)
{
switch (rdp_device.frame_buffer_info.texture_pixel_size)
{
case 0:
return (area / 2) >> 3;
case 1:
return (area) >> 3;
case 2:
return (area * 2) >> 3;
case 3:
return (area * 4) >> 3;
default:
printf("Invalid texture pixel size: %u\n", rdp_device.frame_buffer_info.texture_pixel_size);
return 0;
}
}
uint32_t framebuffer_size()
{
switch (rdp_device.frame_buffer_info.framebuffer_pixel_size)
{
case 0:
return (rdp_device.frame_buffer_info.framebuffer_width * rdp_device.frame_buffer_info.framebuffer_height / 2) >> 3;
case 1:
return (rdp_device.frame_buffer_info.framebuffer_width * rdp_device.frame_buffer_info.framebuffer_height) >> 3;
case 2:
return (rdp_device.frame_buffer_info.framebuffer_width * rdp_device.frame_buffer_info.framebuffer_height * 2) >> 3;
case 3:
return (rdp_device.frame_buffer_info.framebuffer_width * rdp_device.frame_buffer_info.framebuffer_height * 4) >> 3;
default:
printf("Invalid framebuffer pixel size: %u\n", rdp_device.frame_buffer_info.framebuffer_pixel_size);
return 0;
}
}
uint32_t depthbuffer_size()
{
return (rdp_device.frame_buffer_info.framebuffer_width * rdp_device.frame_buffer_info.framebuffer_height * 2) >> 3;
}
uint64_t rdp_process_commands()
{
uint64_t interrupt_timer = 0;
@ -599,61 +525,6 @@ uint64_t rdp_process_commands()
switch (RDP::Op(command))
{
case RDP::Op::FillTriangle:
case RDP::Op::FillZBufferTriangle:
case RDP::Op::TextureTriangle:
case RDP::Op::TextureZBufferTriangle:
case RDP::Op::ShadeTriangle:
case RDP::Op::ShadeZBufferTriangle:
case RDP::Op::ShadeTextureTriangle:
case RDP::Op::ShadeTextureZBufferTriangle:
case RDP::Op::TextureRectangle:
case RDP::Op::TextureRectangleFlip:
case RDP::Op::FillRectangle:
if (!rdram_dirty[rdp_device.frame_buffer_info.framebuffer_address])
{
std::fill_n(rdram_dirty.begin() + rdp_device.frame_buffer_info.framebuffer_address, framebuffer_size(), true);
}
if (rdp_device.frame_buffer_info.depthbuffer_address < rdram_dirty.size() && !rdram_dirty[rdp_device.frame_buffer_info.depthbuffer_address])
{
std::fill_n(rdram_dirty.begin() + rdp_device.frame_buffer_info.depthbuffer_address, depthbuffer_size(), true);
}
break;
case RDP::Op::LoadTLut:
case RDP::Op::LoadTile:
if (!rdram_dirty[rdp_device.frame_buffer_info.texture_address])
{
uint32_t lower_right_t = (w2 & 0xFFF) >> 2;
std::fill_n(rdram_dirty.begin() +
rdp_device.frame_buffer_info.texture_address,
texture_size(rdp_device.frame_buffer_info.texture_width * lower_right_t), true);
}
break;
case RDP::Op::LoadBlock:
{
uint32_t upper_left_s = ((w1 >> 12) & 0xFFF) >> 2;
uint32_t offset_address = rdp_device.frame_buffer_info.texture_address + texture_size(upper_left_s);
if (!rdram_dirty[offset_address])
{
uint32_t lower_right_s = ((w2 >> 12) & 0xFFF) >> 2;
std::fill_n(rdram_dirty.begin() + offset_address, texture_size(lower_right_s - upper_left_s), true);
}
break;
}
case RDP::Op::SetColorImage:
rdp_device.frame_buffer_info.framebuffer_address = (w2 & 0x00FFFFFF) >> 3;
rdp_device.frame_buffer_info.framebuffer_pixel_size = (w1 >> 19) & 0x3;
rdp_device.frame_buffer_info.framebuffer_width = (w1 & 0x3FF) + 1;
break;
case RDP::Op::SetMaskImage:
rdp_device.frame_buffer_info.depthbuffer_address = (w2 & 0x00FFFFFF) >> 3;
break;
case RDP::Op::SetTextureImage:
rdp_device.frame_buffer_info.texture_address = (w2 & 0x00FFFFFF) >> 3;
rdp_device.frame_buffer_info.texture_pixel_size = (w1 >> 19) & 0x3;
rdp_device.frame_buffer_info.texture_width = (w1 & 0x3FF) + 1;
break;
case RDP::Op::SetScissor:
{
uint32_t upper_left_x = ((w1 >> 12) & 0xFFF) >> 2;
@ -668,12 +539,10 @@ uint64_t rdp_process_commands()
{
rdp_device.region = 0;
}
rdp_device.frame_buffer_info.framebuffer_height = lower_right_y;
break;
}
case RDP::Op::SyncFull:
sync_signal = processor->signal_timeline();
processor->wait_for_timeline(processor->signal_timeline());
interrupt_timer = rdp_device.region;
if (interrupt_timer == 0)
interrupt_timer = 5000;

View File

@ -42,7 +42,6 @@ extern "C"
CALL_BACK rdp_check_callback();
uint64_t rdp_process_commands();
void rdp_new_processor(GFX_INFO _gfx_info);
void rdp_check_framebuffers(uint32_t address);
size_t rdp_state_size();
void rdp_save_state(uint8_t *state);
void rdp_load_state(const uint8_t *state);

View File

@ -1,4 +1,4 @@
use crate::{device, ui};
use crate::device;
use rand_chacha::rand_core::RngCore;
const PI_DRAM_ADDR_REG: u32 = 0;
@ -83,7 +83,6 @@ fn dma_write(device: &mut device::Device) {
let cart_addr = device.pi.regs[PI_CART_ADDR_REG as usize] & !1;
let dram_addr = device.pi.regs[PI_DRAM_ADDR_REG as usize] & 0xFFFFFE;
let mut length = (device.pi.regs[PI_WR_LEN_REG as usize] & 0xFFFFFF) + 1;
ui::video::check_framebuffers(dram_addr);
/* PI seems to treat the first 128 bytes differently, see https://n64brew.dev/wiki/Peripheral_Interface#Unaligned_DMA_transfer */
if length >= 0x7f && (length & 1) != 0 {

View File

@ -1,5 +1,4 @@
use crate::device;
use crate::ui;
use std::alloc::{Layout, alloc_zeroed};
//const RDRAM_CONFIG_REG: u32 = 0;
@ -47,7 +46,6 @@ pub fn read_mem(
);
let masked_address = address as usize & RDRAM_MASK;
if address < device.rdram.size as u64 {
ui::video::check_framebuffers(masked_address as u32);
u32::from_ne_bytes(
device.rdram.mem[masked_address..masked_address + 4]
.try_into()
@ -60,7 +58,6 @@ pub fn read_mem(
pub fn write_mem(device: &mut device::Device, address: u64, value: u32, mask: u32) {
if address < device.rdram.size as u64 {
ui::video::check_framebuffers(address as u32);
let mut data = u32::from_ne_bytes(
device.rdram.mem[address as usize..(address + 4) as usize]
.try_into()

View File

@ -1,5 +1,4 @@
use crate::device;
use crate::ui;
const SP_MEM_ADDR_REG: u32 = 0;
const SP_DRAM_ADDR_REG: u32 = 1;
@ -147,7 +146,6 @@ fn do_dma(device: &mut device::Device, dma: RspDma) {
let mut dram_addr = dma.dramaddr & 0xfffff8;
let offset = dma.memaddr & 0x1000;
ui::video::check_framebuffers(dram_addr);
if dma.dir == DmaDir::Read {
let mut j = 0;
while j < count {

View File

@ -81,10 +81,6 @@ pub fn update_screen() {
unsafe { rdp_update_screen() }
}
pub fn check_framebuffers(address: u32) {
unsafe { rdp_check_framebuffers(address) }
}
pub fn state_size() -> usize {
unsafe { rdp_state_size() }
}