Debugger: Improved tilemap viewer performance

This commit is contained in:
Sour 2019-03-30 11:52:15 -04:00
parent 7e4a141b7b
commit 2100ddb712
5 changed files with 22 additions and 24 deletions

View file

@ -58,7 +58,7 @@ void PpuTools::BlendColors(uint8_t output[4], uint8_t input[4])
output[3] = 0xFF;
}
uint32_t PpuTools::GetRgbPixelColor(uint8_t colorIndex, uint8_t palette, uint8_t bpp, bool directColorMode, uint16_t basePaletteOffset)
uint32_t PpuTools::GetRgbPixelColor(uint8_t* cgram, uint8_t colorIndex, uint8_t palette, uint8_t bpp, bool directColorMode, uint16_t basePaletteOffset)
{
uint16_t paletteColor;
if(bpp == 8 && directColorMode) {
@ -68,7 +68,6 @@ uint32_t PpuTools::GetRgbPixelColor(uint8_t colorIndex, uint8_t palette, uint8_t
(((colorIndex & 0xC0) | ((palette & 0x04) << 3)) << 7)
);
} else {
uint8_t* cgram = _ppu->GetCgRam();
uint16_t paletteRamOffset = basePaletteOffset + (palette * (1 << bpp) + colorIndex) * 2;
paletteColor = cgram[paletteRamOffset] | (cgram[paletteRamOffset + 1] << 8);
}
@ -150,7 +149,7 @@ void PpuTools::GetTileView(GetTileViewOptions options, uint32_t *outBuffer)
if(directColor) {
rgbColor = ToArgb(((color & 0x07) << 2) | ((color & 0x38) << 4) | ((color & 0xC0) << 7));
} else {
rgbColor = GetRgbPixelColor(color, 0, 8, false, 0);
rgbColor = GetRgbPixelColor(cgram, color, 0, 8, false, 0);
}
outBuffer[((row * 8) + y) * (options.Width * 8) + column * 8 + x] = rgbColor;
}
@ -170,7 +169,7 @@ void PpuTools::GetTileView(GetTileViewOptions options, uint32_t *outBuffer)
for(int x = 0; x < 8; x++) {
uint8_t color = GetTilePixelColor(ram, ramMask, bpp, pixelStart, 7 - x);
if(color != 0) {
outBuffer[((row * 8) + y) * (options.Width * 8) + column * 8 + x] = GetRgbPixelColor(color, options.Palette, bpp, directColor, 0);
outBuffer[((row * 8) + y) * (options.Width * 8) + column * 8 + x] = GetRgbPixelColor(cgram, color, options.Palette, bpp, directColor, 0);
}
}
}
@ -190,7 +189,7 @@ void PpuTools::GetTileView(GetTileViewOptions options, uint32_t *outBuffer)
}
}
void PpuTools::GetTilemap(GetTilemapOptions options, uint32_t* outBuffer)
void PpuTools::GetTilemap(GetTilemapOptions options, uint8_t* vram, uint8_t* cgram, uint32_t* outBuffer)
{
static constexpr uint8_t layerBpp[8][4] = {
{ 2,2,2,2 }, { 4,4,2,0 }, { 4,4,0,0 }, { 8,4,0,0 }, { 8,2,0,0 }, { 4,2,0,0 }, { 4,0,0,0 }, { 8,0,0,0 }
@ -206,8 +205,6 @@ void PpuTools::GetTilemap(GetTilemapOptions options, uint32_t* outBuffer)
basePaletteOffset = options.Layer * 64;
}
uint8_t *vram = _ppu->GetVideoRam();
uint8_t *cgram = _ppu->GetCgRam();
LayerConfig layer = state.Layers[options.Layer];
uint32_t bgColor = ToArgb((cgram[1] << 8) | cgram[0]);
@ -238,7 +235,7 @@ void PpuTools::GetTilemap(GetTilemapOptions options, uint32_t* outBuffer)
if(directColor) {
rgbColor = ToArgb(((color & 0x07) << 2) | ((color & 0x38) << 4) | ((color & 0xC0) << 7));
} else {
rgbColor = GetRgbPixelColor(color, 0, 8, false, 0);
rgbColor = GetRgbPixelColor(cgram, color, 0, 8, false, 0);
}
outBuffer[((row * 8) + y) * 1024 + column * 8 + x] = rgbColor;
}
@ -277,7 +274,7 @@ void PpuTools::GetTilemap(GetTilemapOptions options, uint32_t* outBuffer)
uint8_t color = GetTilePixelColor(vram, Ppu::VideoRamSize - 1, bpp, pixelStart, shift);
if(color != 0) {
uint8_t palette = bpp == 8 ? 0 : (vram[addr + 1] >> 2) & 0x07;
outBuffer[((row * 8) + y) * 1024 + column * 8 + x] = GetRgbPixelColor(color, palette, bpp, directColor, basePaletteOffset);
outBuffer[((row * 8) + y) * 1024 + column * 8 + x] = GetRgbPixelColor(cgram, color, palette, bpp, directColor, basePaletteOffset);
}
}
}

View file

@ -17,13 +17,13 @@ private:
uint32_t ToArgb(uint16_t color);
void BlendColors(uint8_t output[4], uint8_t input[4]);
uint32_t GetRgbPixelColor(uint8_t colorIndex, uint8_t palette, uint8_t bpp, bool directColorMode, uint16_t basePaletteOffset);
uint32_t GetRgbPixelColor(uint8_t* cgram, uint8_t colorIndex, uint8_t palette, uint8_t bpp, bool directColorMode, uint16_t basePaletteOffset);
public:
PpuTools(Console *console, Ppu *ppu);
void GetTileView(GetTileViewOptions options, uint32_t *outBuffer);
void GetTilemap(GetTilemapOptions options, uint32_t *outBuffer);
void GetTilemap(GetTilemapOptions options, uint8_t* vram, uint8_t* cgram, uint32_t *outBuffer);
void SetViewerUpdateTiming(uint32_t viewerId, uint16_t scanline, uint16_t cycle);
void RemoveViewer(uint32_t viewerId);

View file

@ -69,7 +69,7 @@ extern "C"
DllExport void __stdcall GetMemoryAccessCounts(uint32_t offset, uint32_t length, SnesMemoryType memoryType, MemoryOperationType operationType, uint32_t* counts) { GetDebugger()->GetMemoryAccessCounter()->GetAccessCounts(offset, length, memoryType, operationType, counts); }
DllExport void __stdcall GetCdlData(uint32_t offset, uint32_t length, SnesMemoryType memoryType, uint8_t* cdlData) { GetDebugger()->GetCodeDataLogger()->GetCdlData(offset, length, memoryType, cdlData); }
DllExport void __stdcall GetTilemap(GetTilemapOptions options, uint32_t *buffer) { GetDebugger()->GetPpuTools()->GetTilemap(options, buffer); }
DllExport void __stdcall GetTilemap(GetTilemapOptions options, uint8_t *vram, uint8_t *cgram, uint32_t *buffer) { GetDebugger()->GetPpuTools()->GetTilemap(options, vram, cgram, buffer); }
DllExport void __stdcall GetTileView(GetTileViewOptions options, uint32_t *buffer) { GetDebugger()->GetPpuTools()->GetTileView(options, buffer); }
DllExport void __stdcall SetViewerUpdateTiming(uint32_t viewerId, uint16_t scanline, uint16_t cycle) { GetDebugger()->GetPpuTools()->SetViewerUpdateTiming(viewerId, scanline, cycle); }

View file

@ -18,6 +18,8 @@ namespace Mesen.GUI.Debugger
private NotificationListener _notifListener;
private GetTilemapOptions _options;
private DebugState _state;
private byte[] _cgram;
private byte[] _vram;
private byte[] _tilemapData;
private Bitmap _tilemapImage;
private bool _zoomed;
@ -72,13 +74,14 @@ namespace Mesen.GUI.Debugger
private void RefreshData()
{
_state = DebugApi.GetState();
lock(_tilemapData) {
DebugApi.GetTilemap(_options, _tilemapData);
}
_vram = DebugApi.GetMemoryState(SnesMemoryType.VideoRam);
_cgram = DebugApi.GetMemoryState(SnesMemoryType.CGRam);
}
private void RefreshViewer()
{
DebugApi.GetTilemap(_options, _vram, _cgram, _tilemapData);
int mapWidth = _state.Ppu.BgMode == 7 ? 1024 : _state.Ppu.Layers[_options.Layer].DoubleWidth ? 512 : 256;
int mapHeight = _state.Ppu.BgMode == 7 ? 1024 : _state.Ppu.Layers[_options.Layer].DoubleHeight ? 512 : 256;
if(_tilemapImage.Width != mapWidth || _tilemapImage.Height != mapHeight) {
@ -86,14 +89,12 @@ namespace Mesen.GUI.Debugger
picTilemap.Image = _tilemapImage;
}
using(Graphics g = Graphics.FromImage(_tilemapImage)) {
lock(_tilemapData) {
GCHandle handle = GCHandle.Alloc(_tilemapData, GCHandleType.Pinned);
Bitmap source = new Bitmap(mapWidth, mapHeight, 4 * 1024, PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
try {
g.DrawImage(source, 0, 0);
} finally {
handle.Free();
}
GCHandle handle = GCHandle.Alloc(_tilemapData, GCHandleType.Pinned);
Bitmap source = new Bitmap(mapWidth, mapHeight, 4 * 1024, PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
try {
g.DrawImage(source, 0, 0);
} finally {
handle.Free();
}
}

View file

@ -71,7 +71,7 @@ namespace Mesen.GUI
return buffer;
}
[DllImport(DllPath)] public static extern void GetTilemap(GetTilemapOptions options, [In, Out] byte[] buffer);
[DllImport(DllPath)] public static extern void GetTilemap(GetTilemapOptions options, byte[] vram, byte[] cgram, [In, Out] byte[] buffer);
[DllImport(DllPath)] public static extern void GetTileView(GetTileViewOptions options, [In, Out] byte[] buffer);
[DllImport(DllPath)] public static extern void SetViewerUpdateTiming(Int32 viewerId, Int32 scanline, Int32 cycle);