From 6f4e7c60b29242a692f2595cd319d285792a3c3d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Aug 2020 00:46:16 +0200 Subject: GPU2D: allow writes to DISPCNT, master brightness, capture, dispFIFO regardless of POWCNT. fixes #665 --- src/GPU2D.cpp | 77 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 34 deletions(-) (limited to 'src/GPU2D.cpp') diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp index 604a4ee..2c3086c 100644 --- a/src/GPU2D.cpp +++ b/src/GPU2D.cpp @@ -35,9 +35,6 @@ // * [Gericom] bit15 is used as bottom green bit for palettes. TODO: check where this applies. // tested on the normal BG palette and applies there // -// oh also, changing DISPCNT bit16-17 midframe doesn't work (ignored? applied for next frame?) -// TODO, eventually: check whether other DISPCNT bits can be changed midframe -// // for VRAM display mode, VRAM must be mapped to LCDC // // FIFO display mode: @@ -78,7 +75,10 @@ // * for rotscaled sprites: coordinates that are inside the sprite are clamped to the sprite region // after being transformed for mosaic -// TODO: find which parts of DISPCNT are latched. for example, not possible to change video mode midframe. +// TODO: master brightness, display capture and mainmem FIFO are separate circuitry, distinct from +// the tile renderers. +// for example these aren't affected by POWCNT GPU-disable bits. +// to model the hardware more accurately, the relevant logic should be moved to GPU.cpp. GPU2D::GPU2D(u32 num) @@ -309,8 +309,6 @@ u32 GPU2D::Read32(u32 addr) void GPU2D::Write8(u32 addr, u8 val) { - if (!Enabled) return; - switch (addr & 0x00000FFF) { case 0x000: @@ -329,7 +327,12 @@ void GPU2D::Write8(u32 addr, u8 val) DispCnt = (DispCnt & 0x00FFFFFF) | (val << 24); if (Num) DispCnt &= 0xC0B1FFF7; return; + } + if (!Enabled) return; + + switch (addr & 0x00000FFF) + { case 0x008: BGCnt[0] = (BGCnt[0] & 0xFF00) | val; return; case 0x009: BGCnt[0] = (BGCnt[0] & 0x00FF) | (val << 8); return; case 0x00A: BGCnt[1] = (BGCnt[1] & 0xFF00) | val; return; @@ -405,8 +408,6 @@ void GPU2D::Write8(u32 addr, u8 val) void GPU2D::Write16(u32 addr, u16 val) { - if (!Enabled) return; - switch (addr & 0x00000FFF) { case 0x000: @@ -418,6 +419,22 @@ void GPU2D::Write16(u32 addr, u16 val) if (Num) DispCnt &= 0xC0B1FFF7; return; + case 0x068: + DispFIFO[DispFIFOWritePtr] = val; + return; + case 0x06A: + DispFIFO[DispFIFOWritePtr+1] = val; + DispFIFOWritePtr += 2; + DispFIFOWritePtr &= 0xF; + return; + + case 0x06C: MasterBrightness = val; return; + } + + if (!Enabled) return; + + switch (addr & 0x00000FFF) + { case 0x008: BGCnt[0] = val; return; case 0x00A: BGCnt[1] = val; return; case 0x00C: BGCnt[2] = val; return; @@ -526,17 +543,6 @@ void GPU2D::Write16(u32 addr, u16 val) EVY = val & 0x1F; if (EVY > 16) EVY = 16; return; - - case 0x068: - DispFIFO[DispFIFOWritePtr] = val; - return; - case 0x06A: - DispFIFO[DispFIFOWritePtr+1] = val; - DispFIFOWritePtr += 2; - DispFIFOWritePtr &= 0xF; - return; - - case 0x06C: MasterBrightness = val; return; } //printf("unknown GPU write16 %08X %04X\n", addr, val); @@ -544,8 +550,6 @@ void GPU2D::Write16(u32 addr, u16 val) void GPU2D::Write32(u32 addr, u32 val) { - if (!Enabled) return; - switch (addr & 0x00000FFF) { case 0x000: @@ -553,6 +557,24 @@ void GPU2D::Write32(u32 addr, u32 val) if (Num) DispCnt &= 0xC0B1FFF7; return; + case 0x064: + // TODO: check what happens when writing to it during display + // esp. if a capture is happening + CaptureCnt = val & 0xEF3F1F1F; + return; + + case 0x068: + DispFIFO[DispFIFOWritePtr] = val & 0xFFFF; + DispFIFO[DispFIFOWritePtr+1] = val >> 16; + DispFIFOWritePtr += 2; + DispFIFOWritePtr &= 0xF; + return; + } + + if (!Enabled) return; + + switch (addr & 0x00000FFF) + { case 0x028: if (val & 0x08000000) val |= 0xF0000000; BGXRef[0] = val; @@ -574,19 +596,6 @@ void GPU2D::Write32(u32 addr, u32 val) BGYRef[1] = val; if (GPU::VCount < 192) BGYRefInternal[1] = BGYRef[1]; return; - - case 0x064: - // TODO: check what happens when writing to it during display - // esp. if a capture is happening - CaptureCnt = val & 0xEF3F1F1F; - return; - - case 0x068: - DispFIFO[DispFIFOWritePtr] = val & 0xFFFF; - DispFIFO[DispFIFOWritePtr+1] = val >> 16; - DispFIFOWritePtr += 2; - DispFIFOWritePtr &= 0xF; - return; } Write16(addr, val&0xFFFF); -- cgit v1.2.3 From 9772201345ab47cc820fd6c08247c133605f8b84 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 4 Sep 2020 20:37:14 +0200 Subject: remove some UB - savestates used to read a four bytes from a single byte value - a few unassigned variables - some other things - also make the ROR macro an inline function --- src/ARM.h | 5 ++++- src/ARMJIT.cpp | 5 ++++- src/ARMJIT_A64/ARMJIT_ALU.cpp | 6 +++--- src/ARMJIT_A64/ARMJIT_Compiler.cpp | 2 +- src/ARMJIT_A64/ARMJIT_LoadStore.cpp | 6 +++--- src/ARMJIT_x64/ARMJIT_ALU.cpp | 6 +++--- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 2 +- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 8 ++++---- src/DMA.cpp | 6 ++++-- src/GPU2D.cpp | 1 + src/GPU3D.cpp | 14 +++++++------- src/NDS.cpp | 2 +- src/Savestate.cpp | 18 +++++++++++++++++- src/Savestate.h | 2 ++ src/Wifi.cpp | 2 +- src/dolphin/Arm64Emitter.cpp | 2 +- src/dolphin/Arm64Emitter.h | 2 +- src/dolphin/x64Emitter.cpp | 2 +- src/dolphin/x64Emitter.h | 2 +- 19 files changed, 60 insertions(+), 33 deletions(-) (limited to 'src/GPU2D.cpp') diff --git a/src/ARM.h b/src/ARM.h index deacbee..52c971a 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -24,7 +24,10 @@ #include "types.h" #include "NDS.h" -#define ROR(x, n) (((x) >> (n)) | ((x) << (32-(n)))) +inline u32 ROR(u32 x, u32 n) +{ + return (x >> (n&0x1F)) | (x << ((32-n)&0x1F)); +} enum { diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 31983f6..c9d2b62 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -1087,7 +1087,10 @@ void ResetBlockCache() InvalidLiterals.Clear(); for (int i = 0; i < ARMJIT_Memory::memregions_Count; i++) - memset(FastBlockLookupRegions[i], 0xFF, CodeRegionSizes[i] * sizeof(u64) / 2); + { + if (FastBlockLookupRegions[i]) + memset(FastBlockLookupRegions[i], 0xFF, CodeRegionSizes[i] * sizeof(u64) / 2); + } for (auto it = RestoreCandidates.begin(); it != RestoreCandidates.end(); it++) delete it->second; RestoreCandidates.clear(); diff --git a/src/ARMJIT_A64/ARMJIT_ALU.cpp b/src/ARMJIT_A64/ARMJIT_ALU.cpp index 26a89cb..52a2258 100644 --- a/src/ARMJIT_A64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_A64/ARMJIT_ALU.cpp @@ -436,7 +436,7 @@ void Compiler::A_Comp_GetOp2(bool S, Op2& op2) Comp_AddCycles_C(); u32 shift = (CurInstr.Instr >> 7) & 0x1E; - u32 imm = ROR(CurInstr.Instr & 0xFF, shift); + u32 imm = ::ROR(CurInstr.Instr & 0xFF, shift); if (S && shift && (CurInstr.SetFlags & 0x2)) { @@ -447,7 +447,7 @@ void Compiler::A_Comp_GetOp2(bool S, Op2& op2) ANDI2R(RCPSR, RCPSR, ~(1 << 29)); } - op2 = Op2(ROR(CurInstr.Instr & 0xFF, (CurInstr.Instr >> 7) & 0x1E)); + op2 = Op2(imm); } else { @@ -523,7 +523,7 @@ void Compiler::A_Comp_ALUMovOp() case ST_LSL: LSL(rd, op2.Reg.Rm, op2.Reg.ShiftAmount); break; case ST_LSR: LSR(rd, op2.Reg.Rm, op2.Reg.ShiftAmount); break; case ST_ASR: ASR(rd, op2.Reg.Rm, op2.Reg.ShiftAmount); break; - case ST_ROR: ROR_(rd, op2.Reg.Rm, op2.Reg.ShiftAmount); break; + case ST_ROR: ROR(rd, op2.Reg.Rm, op2.Reg.ShiftAmount); break; } } else diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.cpp b/src/ARMJIT_A64/ARMJIT_Compiler.cpp index b046123..80c7f04 100644 --- a/src/ARMJIT_A64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_A64/ARMJIT_Compiler.cpp @@ -76,7 +76,7 @@ void Compiler::A_Comp_MSR() if (CurInstr.Instr & (1 << 25)) { val = W0; - MOVI2R(val, ROR((CurInstr.Instr & 0xFF), ((CurInstr.Instr >> 7) & 0x1E))); + MOVI2R(val, ::ROR((CurInstr.Instr & 0xFF), ((CurInstr.Instr >> 7) & 0x1E))); } else { diff --git a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp index 6140ffc..14aa847 100644 --- a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp @@ -65,7 +65,7 @@ bool Compiler::Comp_MemLoadLiteral(int size, bool signExtend, int rd, u32 addr) if (size == 32) { CurCPU->DataRead32(addr & ~0x3, &val); - val = ROR(val, (addr & 0x3) << 3); + val = ::ROR(val, (addr & 0x3) << 3); } else if (size == 16) { @@ -151,7 +151,7 @@ void Compiler::Comp_MemAccess(int rd, int rn, Op2 offset, int size, int flags) { if (offset.Reg.ShiftType == ST_ROR) { - ROR_(W0, offset.Reg.Rm, offset.Reg.ShiftAmount); + ROR(W0, offset.Reg.Rm, offset.Reg.ShiftAmount); offset = Op2(W0); } @@ -220,7 +220,7 @@ void Compiler::Comp_MemAccess(int rd, int rn, Op2 offset, int size, int flags) if (size == 32) { if (staticAddress & 0x3) - ROR_(rdMapped, W0, (staticAddress & 0x3) << 3); + ROR(rdMapped, W0, (staticAddress & 0x3) << 3); else MOV(rdMapped, W0); } diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index 57a38c4..24d22ed 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -110,7 +110,7 @@ OpArg Compiler::A_Comp_GetALUOp2(bool S, bool& carryUsed) Comp_AddCycles_C(); u32 shift = (CurInstr.Instr >> 7) & 0x1E; - u32 imm = ROR(CurInstr.Instr & 0xFF, shift); + u32 imm = ::ROR(CurInstr.Instr & 0xFF, shift); carryUsed = false; if (S && shift) @@ -493,7 +493,7 @@ OpArg Compiler::Comp_RegShiftReg(int op, Gen::OpArg rs, Gen::OpArg rm, bool S, b { if (S) BT(32, R(RSCRATCH), Imm8(31)); - ROR_(32, R(RSCRATCH), R(ECX)); + ROR(32, R(RSCRATCH), R(ECX)); if (S) SETcc(CC_C, R(RSCRATCH2)); } @@ -555,7 +555,7 @@ OpArg Compiler::Comp_RegShiftImm(int op, int amount, OpArg rm, bool S, bool& car case 3: // ROR MOV(32, R(RSCRATCH), rm); if (amount > 0) - ROR_(32, R(RSCRATCH), Imm8(amount)); + ROR(32, R(RSCRATCH), Imm8(amount)); else { BT(32, R(RCPSR), Imm8(29)); diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 1fdbaf8..c6419c9 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -106,7 +106,7 @@ void Compiler::A_Comp_MSR() Comp_AddCycles_C(); OpArg val = CurInstr.Instr & (1 << 25) - ? Imm32(ROR((CurInstr.Instr & 0xFF), ((CurInstr.Instr >> 7) & 0x1E))) + ? Imm32(::ROR((CurInstr.Instr & 0xFF), ((CurInstr.Instr >> 7) & 0x1E))) : MapReg(CurInstr.A_Reg(0)); u32 mask = 0; diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 57d98cc..1be6608 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -73,7 +73,7 @@ bool Compiler::Comp_MemLoadLiteral(int size, bool signExtend, int rd, u32 addr) if (size == 32) { CurCPU->DataRead32(addr & ~0x3, &val); - val = ROR(val, (addr & 0x3) << 3); + val = ::ROR(val, (addr & 0x3) << 3); } else if (size == 16) { @@ -225,13 +225,13 @@ void Compiler::Comp_MemAccess(int rd, int rn, const Op2& op2, int size, int flag if (addrIsStatic) { if (staticAddress & 0x3) - ROR_(32, rdMapped, Imm8((staticAddress & 0x3) * 8)); + ROR(32, rdMapped, Imm8((staticAddress & 0x3) * 8)); } else { AND(32, R(RSCRATCH3), Imm8(0x3)); SHL(32, R(RSCRATCH3), Imm8(3)); - ROR_(32, rdMapped, R(RSCRATCH3)); + ROR(32, rdMapped, R(RSCRATCH3)); } } } @@ -270,7 +270,7 @@ void Compiler::Comp_MemAccess(int rd, int rn, const Op2& op2, int size, int flag { MOV(32, rdMapped, R(RSCRATCH)); if (staticAddress & 0x3) - ROR_(32, rdMapped, Imm8((staticAddress & 0x3) * 8)); + ROR(32, rdMapped, Imm8((staticAddress & 0x3) * 8)); } else { diff --git a/src/DMA.cpp b/src/DMA.cpp index cd2df45..18b8a2f 100644 --- a/src/DMA.cpp +++ b/src/DMA.cpp @@ -73,6 +73,8 @@ void DMA::Reset() SrcAddrInc = 0; DstAddrInc = 0; + Stall = false; + Running = false; InProgress = false; @@ -111,8 +113,8 @@ void DMA::DoSavestate(Savestate* file) file->Var32(&DstAddrInc); file->Var32(&Running); - file->Var32((u32*)&InProgress); - file->Var32((u32*)&IsGXFIFODMA); + file->Bool32(&InProgress); + file->Bool32(&IsGXFIFODMA); } void DMA::WriteCnt(u32 val) diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp index 2c3086c..07790b7 100644 --- a/src/GPU2D.cpp +++ b/src/GPU2D.cpp @@ -102,6 +102,7 @@ GPU2D::~GPU2D() void GPU2D::Reset() { + Enabled = false; DispCnt = 0; memset(BGCnt, 0, 4*2); memset(BGXPos, 0, 4*2); diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp index d9d6ba8..5ccacf4 100644 --- a/src/GPU3D.cpp +++ b/src/GPU3D.cpp @@ -470,7 +470,7 @@ void DoSavestate(Savestate* file) file->VarArray(vtx->Color, sizeof(s32)*3); file->VarArray(vtx->TexCoords, sizeof(s16)*2); - file->Var32((u32*)&vtx->Clipped); + file->Bool32(&vtx->Clipped); file->VarArray(vtx->FinalPosition, sizeof(s32)*2); file->VarArray(vtx->FinalColor, sizeof(s32)*3); @@ -507,7 +507,7 @@ void DoSavestate(Savestate* file) file->VarArray(vtx->Color, sizeof(s32)*3); file->VarArray(vtx->TexCoords, sizeof(s16)*2); - file->Var32((u32*)&vtx->Clipped); + file->Bool32(&vtx->Clipped); file->VarArray(vtx->FinalPosition, sizeof(s32)*2); file->VarArray(vtx->FinalColor, sizeof(s32)*3); @@ -545,17 +545,17 @@ void DoSavestate(Savestate* file) file->VarArray(poly->FinalZ, sizeof(s32)*10); file->VarArray(poly->FinalW, sizeof(s32)*10); - file->Var32((u32*)&poly->WBuffer); + file->Bool32(&poly->WBuffer); file->Var32(&poly->Attr); file->Var32(&poly->TexParam); file->Var32(&poly->TexPalette); - file->Var32((u32*)&poly->FacingView); - file->Var32((u32*)&poly->Translucent); + file->Bool32(&poly->FacingView); + file->Bool32(&poly->Translucent); - file->Var32((u32*)&poly->IsShadowMask); - file->Var32((u32*)&poly->IsShadow); + file->Bool32(&poly->IsShadowMask); + file->Bool32(&poly->IsShadow); if (file->IsAtleastVersion(4, 1)) file->Var32((u32*)&poly->Type); diff --git a/src/NDS.cpp b/src/NDS.cpp index f926399..20f149a 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -775,7 +775,7 @@ bool DoSavestate(Savestate* file) file->Var8(&WRAMCnt); - file->Var32((u32*)&RunningGame); + file->Bool32(&RunningGame); if (!file->Saving) { diff --git a/src/Savestate.cpp b/src/Savestate.cpp index 0337ff2..ba8ffd9 100644 --- a/src/Savestate.cpp +++ b/src/Savestate.cpp @@ -261,6 +261,22 @@ void Savestate::Var64(u64* var) } } +void Savestate::Bool32(bool* var) +{ + // for compability + if (Saving) + { + u32 val = *var; + Var32(&val); + } + else + { + u32 val; + Var32(&val); + *var = val != 0; + } +} + void Savestate::VarArray(void* data, u32 len) { if (Error) return; @@ -273,4 +289,4 @@ void Savestate::VarArray(void* data, u32 len) { fread(data, len, 1, file); } -} +} \ No newline at end of file diff --git a/src/Savestate.h b/src/Savestate.h index a5447b3..c3c2e1d 100644 --- a/src/Savestate.h +++ b/src/Savestate.h @@ -46,6 +46,8 @@ public: void Var32(u32* var); void Var64(u64* var); + void Bool32(bool* var); + void VarArray(void* data, u32 len); bool IsAtleastVersion(u32 major, u32 minor) diff --git a/src/Wifi.cpp b/src/Wifi.cpp index 8a06041..2957007 100644 --- a/src/Wifi.cpp +++ b/src/Wifi.cpp @@ -237,7 +237,7 @@ void DoSavestate(Savestate* file) file->Var64(&USCounter); file->Var64(&USCompare); - file->Var32((u32*)&BlockBeaconIRQ14); + file->Bool32(&BlockBeaconIRQ14); file->Var32(&ComStatus); file->Var32(&TXCurSlot); diff --git a/src/dolphin/Arm64Emitter.cpp b/src/dolphin/Arm64Emitter.cpp index 97c93ba..289b20c 100644 --- a/src/dolphin/Arm64Emitter.cpp +++ b/src/dolphin/Arm64Emitter.cpp @@ -1631,7 +1631,7 @@ void ARM64XEmitter::ASR(ARM64Reg Rd, ARM64Reg Rm, int shift) int bits = Is64Bit(Rd) ? 64 : 32; SBFM(Rd, Rm, shift, bits - 1); } -void ARM64XEmitter::ROR_(ARM64Reg Rd, ARM64Reg Rm, int shift) +void ARM64XEmitter::ROR(ARM64Reg Rd, ARM64Reg Rm, int shift) { EXTR(Rd, Rm, Rm, shift); } diff --git a/src/dolphin/Arm64Emitter.h b/src/dolphin/Arm64Emitter.h index 4c49502..3da3912 100644 --- a/src/dolphin/Arm64Emitter.h +++ b/src/dolphin/Arm64Emitter.h @@ -727,7 +727,7 @@ public: void LSR(ARM64Reg Rd, ARM64Reg Rm, int shift); void LSL(ARM64Reg Rd, ARM64Reg Rm, int shift); void ASR(ARM64Reg Rd, ARM64Reg Rm, int shift); - void ROR_(ARM64Reg Rd, ARM64Reg Rm, int shift); + void ROR(ARM64Reg Rd, ARM64Reg Rm, int shift); // Logical (immediate) void AND(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms, bool invert = false); diff --git a/src/dolphin/x64Emitter.cpp b/src/dolphin/x64Emitter.cpp index 343f314..fd90ba7 100644 --- a/src/dolphin/x64Emitter.cpp +++ b/src/dolphin/x64Emitter.cpp @@ -1214,7 +1214,7 @@ void XEmitter::ROL(int bits, const OpArg& dest, const OpArg& shift) { WriteShift(bits, dest, shift, 0); } -void XEmitter::ROR_(int bits, const OpArg& dest, const OpArg& shift) +void XEmitter::ROR(int bits, const OpArg& dest, const OpArg& shift) { WriteShift(bits, dest, shift, 1); } diff --git a/src/dolphin/x64Emitter.h b/src/dolphin/x64Emitter.h index 869acb6..8799600 100644 --- a/src/dolphin/x64Emitter.h +++ b/src/dolphin/x64Emitter.h @@ -489,7 +489,7 @@ public: // Shift void ROL(int bits, const OpArg& dest, const OpArg& shift); - void ROR_(int bits, const OpArg& dest, const OpArg& shift); + void ROR(int bits, const OpArg& dest, const OpArg& shift); void RCL(int bits, const OpArg& dest, const OpArg& shift); void RCR(int bits, const OpArg& dest, const OpArg& shift); void SHL(int bits, const OpArg& dest, const OpArg& shift); -- cgit v1.2.3 From a88df197089842f008bdeb1d79dc3b1a16c28da9 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 18 Sep 2020 00:29:08 +0200 Subject: avoid out-of-bounds read in GPU2D. fixes #763 --- src/GPU2D.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/GPU2D.cpp') diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp index 07790b7..7964aa4 100644 --- a/src/GPU2D.cpp +++ b/src/GPU2D.cpp @@ -815,7 +815,6 @@ void GPU2D::DrawScanline(u32 line) int i = 0; for (; i < (stride & ~1); i+=2) *(u64*)&dst[i] = *(u64*)&BGOBJLine[i]; - if (stride & 1) dst[i] = BGOBJLine[i]; } break; -- cgit v1.2.3 From 697730240394cd9fedcf7924f29ffa625fc784fd Mon Sep 17 00:00:00 2001 From: RSDuck Date: Wed, 30 Sep 2020 23:58:42 +0200 Subject: make OpenGL renderer a build option mostly meant for the Switch port --- CMakeLists.txt | 6 ++++++ src/CMakeLists.txt | 31 ++++++++++++++++++++--------- src/GPU.cpp | 13 ++++++++++-- src/GPU.h | 2 ++ src/GPU2D.cpp | 2 ++ src/GPU3D.cpp | 6 ++++++ src/GPU3D.h | 2 ++ src/frontend/qt_sdl/VideoSettingsDialog.cpp | 4 ++++ src/frontend/qt_sdl/main.cpp | 12 +++++++++++ 9 files changed, 67 insertions(+), 11 deletions(-) (limited to 'src/GPU2D.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 6729e73..8b8d699 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,12 @@ else() option(ENABLE_LTO "Enable link-time optimization" OFF) endif() +option(ENABLE_OGLRENDERER "Enable OpenGL renderer" ON) + +if (ENABLE_OGLRENDERER) + add_definitions(-DOGLRENDERER_ENABLED) +endif() + if (CMAKE_BUILD_TYPE STREQUAL Debug) add_compile_options(-Og) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8839fc2..d6c3897 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,17 +26,12 @@ add_library(core STATIC FIFO.h GBACart.cpp GPU.cpp - GPU_OpenGL.cpp - GPU_OpenGL_shaders.h GPU2D.cpp GPU3D.cpp - GPU3D_OpenGL.cpp - GPU3D_OpenGL_shaders.h GPU3D_Soft.cpp melonDLDI.h NDS.cpp NDSCart.cpp - OpenGLSupport.cpp Platform.h ROMList.h RTC.cpp @@ -52,6 +47,16 @@ add_library(core STATIC xxhash/xxhash.c ) +if (ENABLE_OGLRENDERER) + target_sources(core PRIVATE + GPU_OpenGL.cpp + GPU_OpenGL_shaders.h + GPU3D_OpenGL.cpp + GPU3D_OpenGL_shaders.h + OpenGLSupport.cpp + ) +endif() + if (ENABLE_JIT) enable_language(ASM) @@ -95,8 +100,16 @@ if (ENABLE_JIT) endif() endif() -if (WIN32) - target_link_libraries(core ole32 comctl32 ws2_32 opengl32) +if (ENABLE_OGLRENDERER) + if (WIN32) + target_link_libraries(core ole32 comctl32 ws2_32 opengl32) + else() + target_link_libraries(core GL EGL) + endif() else() - target_link_libraries(core GL EGL) -endif() + if (WIN32) + target_link_libraries(core ole32 comctl32 ws2_32) + else() + target_link_libraries(core) + endif() +endif() \ No newline at end of file diff --git a/src/GPU.cpp b/src/GPU.cpp index 29867db..7989750 100644 --- a/src/GPU.cpp +++ b/src/GPU.cpp @@ -280,6 +280,7 @@ void AssignFramebuffers() void InitRenderer(int renderer) { +#ifdef OGLRENDERER_ENABLED if (renderer == 1) { if (!GLCompositor::Init()) @@ -292,8 +293,8 @@ void InitRenderer(int renderer) renderer = 0; } } - - if (renderer == 0) + else +#endif { GPU3D::SoftRenderer::Init(); } @@ -308,11 +309,13 @@ void DeInitRenderer() { GPU3D::SoftRenderer::DeInit(); } +#ifdef OGLRENDERER_ENABLED else { GPU3D::GLRenderer::DeInit(); GLCompositor::DeInit(); } +#endif } void ResetRenderer() @@ -321,11 +324,13 @@ void ResetRenderer() { GPU3D::SoftRenderer::Reset(); } +#ifdef OGLRENDERER_ENABLED else { GLCompositor::Reset(); GPU3D::GLRenderer::Reset(); } +#endif } void SetRenderSettings(int renderer, RenderSettings& settings) @@ -364,11 +369,13 @@ void SetRenderSettings(int renderer, RenderSettings& settings) { GPU3D::SoftRenderer::SetRenderSettings(settings); } +#ifdef OGLRENDERER_ENABLED else { GLCompositor::SetRenderSettings(settings); GPU3D::GLRenderer::SetRenderSettings(settings); } +#endif } @@ -1055,7 +1062,9 @@ void StartScanline(u32 line) GPU2D_B->VBlank(); GPU3D::VBlank(); +#ifdef OGLRENDERER_ENABLED if (Accelerated) GLCompositor::RenderFrame(); +#endif } else if (VCount == 144) { diff --git a/src/GPU.h b/src/GPU.h index c7d25ec..1564ef7 100644 --- a/src/GPU.h +++ b/src/GPU.h @@ -437,6 +437,7 @@ void SetDispStat(u32 cpu, u16 val); void SetVCount(u16 val); +#ifdef OGLRENDERER_ENABLED namespace GLCompositor { @@ -450,6 +451,7 @@ void RenderFrame(); void BindOutputTexture(); } +#endif } diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp index 7964aa4..7774c65 100644 --- a/src/GPU2D.cpp +++ b/src/GPU2D.cpp @@ -949,6 +949,7 @@ void GPU2D::VBlankEnd() //OBJMosaicY = 0; //OBJMosaicYCount = 0; +#ifdef OGLRENDERER_ENABLED if (Accelerated) { if ((Num == 0) && (CaptureCnt & (1<<31)) && (((CaptureCnt >> 29) & 0x3) != 1)) @@ -956,6 +957,7 @@ void GPU2D::VBlankEnd() GPU3D::GLRenderer::PrepareCaptureFrame(); } } +#endif } diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp index 5ccacf4..74debfe 100644 --- a/src/GPU3D.cpp +++ b/src/GPU3D.cpp @@ -2528,13 +2528,19 @@ void VBlank() void VCount215() { if (GPU::Renderer == 0) SoftRenderer::RenderFrame(); +#ifdef OGLRENDERER_ENABLED else GLRenderer::RenderFrame(); +#endif } u32* GetLine(int line) { if (GPU::Renderer == 0) return SoftRenderer::GetLine(line); +#ifdef OGLRENDERER_ENABLED else return GLRenderer::GetLine(line); +#else + return NULL; +#endif } diff --git a/src/GPU3D.h b/src/GPU3D.h index 71f069d..c69adde 100644 --- a/src/GPU3D.h +++ b/src/GPU3D.h @@ -139,6 +139,7 @@ u32* GetLine(int line); } +#ifdef OGLRENDERER_ENABLED namespace GLRenderer { @@ -154,6 +155,7 @@ u32* GetLine(int line); void SetupAccelFrame(); } +#endif } diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 971fee7..1397ccd 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -50,6 +50,10 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui( connect(grp3DRenderer, SIGNAL(buttonClicked(int)), this, SLOT(onChange3DRenderer(int))); grp3DRenderer->button(Config::_3DRenderer)->setChecked(true); +#ifndef OGLRENDERER_ENABLED + ui->rb3DOpenGL->setEnabled(false); +#endif + ui->cbGLDisplay->setChecked(Config::ScreenUseGL != 0); ui->cbVSync->setChecked(Config::ScreenVSync != 0); diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 1900998..e0c12e3 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -49,7 +49,9 @@ #include "NDS.h" #include "GBACart.h" +#ifdef OGLRENDERER_ENABLED #include "OpenGLSupport.h" +#endif #include "GPU.h" #include "SPU.h" #include "Wifi.h" @@ -336,13 +338,17 @@ void EmuThread::run() videoSettings.Soft_Threaded = Config::Threaded3D != 0; videoSettings.GL_ScaleFactor = Config::GL_ScaleFactor; +#ifdef OGLRENDERER_ENABLED if (hasOGL) { oglContext->makeCurrent(oglSurface); videoRenderer = OpenGL::Init() ? Config::_3DRenderer : 0; } else +#endif + { videoRenderer = 0; + } GPU::InitRenderer(videoRenderer); GPU::SetRenderSettings(videoRenderer, videoSettings); @@ -396,13 +402,17 @@ void EmuThread::run() if (hasOGL != mainWindow->hasOGL) { hasOGL = mainWindow->hasOGL; +#ifdef OGLRENDERER_ENABLED if (hasOGL) { oglContext->makeCurrent(oglSurface); videoRenderer = OpenGL::Init() ? Config::_3DRenderer : 0; } else +#endif + { videoRenderer = 0; + } } else videoRenderer = hasOGL ? Config::_3DRenderer : 0; @@ -923,12 +933,14 @@ void ScreenPanelGL::paintGL() int frontbuf = GPU::FrontBuffer; glActiveTexture(GL_TEXTURE0); +#ifdef OGLRENDERER_ENABLED if (GPU::Renderer != 0) { // hardware-accelerated render GPU::GLCompositor::BindOutputTexture(); } else +#endif { // regular render glBindTexture(GL_TEXTURE_2D, screenTexture); -- cgit v1.2.3