From dc59d7f71ff36ebfb4629ae937229202d1a02f70 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Sat, 30 May 2020 13:13:25 +0300 Subject: [PATCH] core/gpu: Optimize VRAM accesses all over the place Former-commit-id: a14fc75968c5ce6016acc88fe2cc24eaac8b305b Former-commit-id: 41f3142ea586c981cd5ccc7eb5a69f49bdcc591d --- rustboyadvance-core/src/gpu/mod.rs | 9 ++++++--- rustboyadvance-core/src/gpu/regs.rs | 4 ++-- rustboyadvance-core/src/gpu/render/obj.rs | 4 ++-- rustboyadvance-core/src/gpu/render/text.rs | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/rustboyadvance-core/src/gpu/mod.rs b/rustboyadvance-core/src/gpu/mod.rs index 9c47667..252d873 100644 --- a/rustboyadvance-core/src/gpu/mod.rs +++ b/rustboyadvance-core/src/gpu/mod.rs @@ -263,7 +263,7 @@ impl Gpu { #[inline] pub fn read_pixel_index_bpp4(&self, addr: u32, x: u32, y: u32) -> usize { - let ofs = addr - VRAM_ADDR + index2d!(u32, x / 2, y, 4); + let ofs = addr + index2d!(u32, x / 2, y, 4); let ofs = ofs as usize; let byte = self.vram.read_8(ofs as u32); if x & 1 != 0 { @@ -275,7 +275,7 @@ impl Gpu { #[inline] pub fn read_pixel_index_bpp8(&self, addr: u32, x: u32, y: u32) -> usize { - let ofs = addr - VRAM_ADDR; + let ofs = addr; self.vram.read_8(ofs + index2d!(u32, x, y, 8)) as usize } @@ -312,7 +312,10 @@ impl Gpu { pub fn render_scanline(&mut self) { if self.dispcnt.force_blank() { - for x in self.frame_buffer[self.vcount * DISPLAY_WIDTH..].iter_mut().take(DISPLAY_WIDTH) { + for x in self.frame_buffer[self.vcount * DISPLAY_WIDTH..] + .iter_mut() + .take(DISPLAY_WIDTH) + { *x = 0xf8f8f8; } return; diff --git a/rustboyadvance-core/src/gpu/regs.rs b/rustboyadvance-core/src/gpu/regs.rs index 4bc923c..ccca08b 100644 --- a/rustboyadvance-core/src/gpu/regs.rs +++ b/rustboyadvance-core/src/gpu/regs.rs @@ -31,11 +31,11 @@ impl DisplayControl { impl BgControl { pub fn char_block(&self) -> u32 { - VRAM_ADDR + (self.character_base_block() as u32) * 0x4000 + (self.character_base_block() as u32) * 0x4000 } pub fn screen_block(&self) -> u32 { - VRAM_ADDR + (self.screen_base_block() as u32) * SCREEN_BLOCK_SIZE + (self.screen_base_block() as u32) * SCREEN_BLOCK_SIZE } pub fn size_regular(&self) -> (u32, u32) { diff --git a/rustboyadvance-core/src/gpu/render/obj.rs b/rustboyadvance-core/src/gpu/render/obj.rs index 3f95579..296084d 100644 --- a/rustboyadvance-core/src/gpu/render/obj.rs +++ b/rustboyadvance-core/src/gpu/render/obj.rs @@ -97,7 +97,7 @@ impl Gpu { return; } - let tile_base = OVRAM + 0x20 * (attrs.2.tile() as u32); + let tile_base = OVRAM - VRAM_ADDR + 0x20 * (attrs.2.tile() as u32); let (tile_size, pixel_format) = attrs.tile_format(); let palette_bank = match pixel_format { @@ -190,7 +190,7 @@ impl Gpu { return; } - let tile_base = OVRAM + 0x20 * (attrs.2.tile() as u32); + let tile_base = OVRAM - VRAM_ADDR + 0x20 * (attrs.2.tile() as u32); let (tile_size, pixel_format) = attrs.tile_format(); let palette_bank = match pixel_format { diff --git a/rustboyadvance-core/src/gpu/render/text.rs b/rustboyadvance-core/src/gpu/render/text.rs index 3864b92..4712587 100644 --- a/rustboyadvance-core/src/gpu/render/text.rs +++ b/rustboyadvance-core/src/gpu/render/text.rs @@ -56,7 +56,7 @@ impl Gpu { + SCREEN_BLOCK_SIZE * sbb + 2 * index2d!(u32, se_row, se_column, 32); for _ in se_row..32 { - let entry = TileMapEntry(self.vram.read_16(map_addr - VRAM_ADDR)); + let entry = TileMapEntry(self.vram.read_16(map_addr)); let tile_addr = tileset_base + entry.tile_index() * tile_size; for tile_px in start_tile_x..8 { @@ -121,7 +121,7 @@ impl Gpu { } } let map_addr = screen_block + index2d!(u32, t.0 / 8, t.1 / 8, texture_size / 8); - let tile_index = self.vram.read_8(map_addr - VRAM_ADDR) as u32; + let tile_index = self.vram.read_8(map_addr) as u32; let tile_addr = char_block + tile_index * 0x40; let color = self.get_palette_color(