From 5d35fb229f16545814517c47c03f0a2adcd09db7 Mon Sep 17 00:00:00 2001 From: CocoSimone Date: Fri, 10 Feb 2023 14:22:00 +0100 Subject: [PATCH] make menu bar disappear + change way scaling works --- external/parallel-rdp/ParallelRDPWrapper.cpp | 46 ++++++++------------ external/parallel-rdp/ParallelRDPWrapper.hpp | 6 +-- src/backend/Core.cpp | 2 +- src/backend/MemoryRegions.hpp | 13 ++++-- src/backend/core/Mem.cpp | 16 +++---- src/backend/core/mmio/VI.cpp | 2 +- src/common.hpp | 2 +- src/frontend/imgui/Window.cpp | 45 ++++++++++--------- src/frontend/imgui/Window.hpp | 12 +++-- 9 files changed, 71 insertions(+), 73 deletions(-) diff --git a/external/parallel-rdp/ParallelRDPWrapper.cpp b/external/parallel-rdp/ParallelRDPWrapper.cpp index 45ea0cc6..7a6b90c6 100644 --- a/external/parallel-rdp/ParallelRDPWrapper.cpp +++ b/external/parallel-rdp/ParallelRDPWrapper.cpp @@ -15,8 +15,6 @@ static CommandProcessor* command_processor; static WSI* wsi; static std::unique_ptr windowInfo; -std::vector acquire_semaphore; - VkQueue GetGraphicsQueue() { return wsi->get_context().get_queue_info().queues[QUEUE_INDEX_GRAPHICS]; } @@ -140,7 +138,7 @@ WSI* LoadWSIPlatform(Vulkan::WSIPlatform* wsi_platform, std::unique_ptr()); - LoadParallelRDP(rdram, window); + LoadParallelRDP(rdram); } -void DrawFullscreenTexturedQuad(float mainMenuBarHeight, Util::IntrusivePtr image, Util::IntrusivePtr cmd) { +void DrawFullscreenTexturedQuad(Util::IntrusivePtr image, Util::IntrusivePtr cmd) { cmd->set_texture(0, 0, image->get_view(), Vulkan::StockSampler::LinearClamp); cmd->set_program(fullscreen_quad_program); cmd->set_quad_state(); auto data = static_cast(cmd->allocate_vertex_data(0, 6 * sizeof(float), 2 * sizeof(float))); - *data++ = -1.0f; - *data++ = -3.0f; - *data++ = -1.0f; - *data++ = +1.0f; - *data++ = +3.0f; - *data++ = +1.0f; + data[0] = -1.0f; + data[1] = -3.0f; + data[2] = -1.0f; + data[3] = +1.0f; + data[4] = +3.0f; + data[5] = +1.0f; - int sdlWinWidth, sdlWinHeight; - SDL_GetWindowSize(g_Window, &sdlWinWidth, &sdlWinHeight); + auto windowSize = windowInfo->get_window_size(); - sdlWinHeight -= mainMenuBarHeight; + float zoom = std::min(windowSize.x / wsi->get_platform().get_surface_width(), + windowSize.y / wsi->get_platform().get_surface_height()); - float platform_width = wsi->get_platform().get_surface_width(); - float platform_height = wsi->get_platform().get_surface_height(); - - platform_height -= mainMenuBarHeight; - - float zoom = std::min( - (float)sdlWinWidth / platform_width, - (float)sdlWinHeight / platform_height); - - - float width = (platform_width / (float)sdlWinWidth) * zoom; - float height = (platform_height / (float)sdlWinHeight) * zoom; + float width = (wsi->get_platform().get_surface_width() / windowSize.x) * zoom; + float height = (wsi->get_platform().get_surface_height() / windowSize.y) * zoom; float uniform_data[] = { // Size @@ -262,11 +250,11 @@ void UpdateScreen(n64::Core& core, Window& imguiWindow, Util::IntrusivePtr cmd = wsi->get_device().request_command_buffer(); cmd->begin_render_pass(wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly)); - DrawData data = imguiWindow.Present(core); + ImDrawData* drawData = imguiWindow.Present(core); - DrawFullscreenTexturedQuad(data.second, image, cmd); + DrawFullscreenTexturedQuad(image, cmd); - ImGui_ImplVulkan_RenderDrawData(data.first, cmd->get_command_buffer()); + ImGui_ImplVulkan_RenderDrawData(drawData, cmd->get_command_buffer()); cmd->end_render_pass(); wsi->get_device().submit(cmd); diff --git a/external/parallel-rdp/ParallelRDPWrapper.hpp b/external/parallel-rdp/ParallelRDPWrapper.hpp index f06d6168..adbb97bb 100644 --- a/external/parallel-rdp/ParallelRDPWrapper.hpp +++ b/external/parallel-rdp/ParallelRDPWrapper.hpp @@ -9,8 +9,8 @@ static SDL_Window* g_Window; class ParallelRdpWindowInfo { public: struct CoordinatePair { - int x; - int y; + float x; + float y; }; virtual CoordinatePair get_window_size() = 0; virtual ~ParallelRdpWindowInfo() = default; @@ -20,7 +20,7 @@ class SDLParallelRdpWindowInfo : public ParallelRdpWindowInfo { CoordinatePair get_window_size() { int width, height; SDL_GetWindowSize(g_Window, &width, &height); - return CoordinatePair{ width, height }; + return CoordinatePair{ static_cast(width), static_cast(height) }; } }; diff --git a/src/backend/Core.cpp b/src/backend/Core.cpp index b9d8939e..10ae9293 100644 --- a/src/backend/Core.cpp +++ b/src/backend/Core.cpp @@ -75,7 +75,7 @@ void Core::Run(Window& window, float volumeL, float volumeR) { UpdateScreenParallelRdp(*this, window, GetVI()); - int missedCycles = N64_CYCLES_PER_FRAME - frameCycles; + int missedCycles = N64_CYCLES_PER_FRAME(false) - frameCycles; mmio.ai.Step(mem, regs, missedCycles, volumeL, volumeR); } else if(pause && romLoaded) { UpdateScreenParallelRdp(*this, window, GetVI()); diff --git a/src/backend/MemoryRegions.hpp b/src/backend/MemoryRegions.hpp index 856de750..4d964863 100644 --- a/src/backend/MemoryRegions.hpp +++ b/src/backend/MemoryRegions.hpp @@ -14,9 +14,16 @@ #define ISVIEWER_SIZE (0x13FFFFFF - 0x13FF0020) #define ISVIEWER_DSIZE (ISVIEWER_SIZE - 1) -#define RDRAM_REGION 0 ... RDRAM_DSIZE -#define DMEM_REGION 0x04000000 ... DMEM_DSIZE -#define IMEM_REGION 0x04001000 ... IMEM_DSIZE +#define RDRAM_REGION_START 0 +#define RDRAM_REGION_END RDRAM_DSIZE +#define DMEM_REGION_START 0x4000000 +#define DMEM_REGION_END (DMEM_REGION_START + DMEM_DSIZE) +#define IMEM_REGION_START 0x4001000 +#define IMEM_REGION_END (IMEM_REGION_START + IMEM_DSIZE) + +#define RDRAM_REGION RDRAM_REGION_START ... RDRAM_REGION_END +#define DMEM_REGION DMEM_REGION_START ... DMEM_REGION_END +#define IMEM_REGION IMEM_REGION_START ... IMEM_REGION_END #define MMIO_REGION 0x04040000 ... 0x048FFFFF #define SP_REGION 0x04040000 ... 0x040FFFFF #define DP_CMD_REGION 0x04100000 ... 0x041FFFFF diff --git a/src/backend/core/Mem.cpp b/src/backend/core/Mem.cpp index c651df2c..8a176825 100644 --- a/src/backend/core/Mem.cpp +++ b/src/backend/core/Mem.cpp @@ -108,10 +108,10 @@ u8 Mem::Read8(n64::Registers ®s, u64 vaddr, s64 pc) { case 0x00000000 ... 0x007FFFFF: return mmio.rdp.rdram[BYTE_ADDRESS(paddr)]; case 0x04000000 ... 0x0403FFFF: - if ((paddr >> 12) & 1) - return mmio.rsp.imem[BYTE_ADDRESS(paddr) & IMEM_DSIZE]; + if (paddr & 0x1000) + return mmio.rsp.imem[BYTE_ADDRESS(paddr) - IMEM_REGION_START]; else - return mmio.rsp.dmem[BYTE_ADDRESS(paddr) & DMEM_DSIZE]; + return mmio.rsp.dmem[BYTE_ADDRESS(paddr) - DMEM_REGION_START]; case 0x04040000 ... 0x040FFFFF: case 0x04100000 ... 0x041FFFFF: case 0x04600000 ... 0x048FFFFF: @@ -159,7 +159,7 @@ u16 Mem::Read16(n64::Registers ®s, u64 vaddr, s64 pc) { case 0x00000000 ... 0x007FFFFF: return Util::ReadAccess(mmio.rdp.rdram.data(), HALF_ADDRESS(paddr)); case 0x04000000 ... 0x0403FFFF: - if ((paddr >> 12) & 1) + if (paddr & 0x1000) return Util::ReadAccess(mmio.rsp.imem, HALF_ADDRESS(paddr) & IMEM_DSIZE); else return Util::ReadAccess(mmio.rsp.dmem, HALF_ADDRESS(paddr) & DMEM_DSIZE); @@ -205,7 +205,7 @@ u32 Mem::Read32(n64::Registers ®s, u64 vaddr, s64 pc) { case 0x00000000 ... 0x007FFFFF: return Util::ReadAccess(mmio.rdp.rdram.data(), paddr); case 0x04000000 ... 0x0403FFFF: - if((paddr >> 12) & 1) + if(paddr & 0x1000) return Util::ReadAccess(mmio.rsp.imem, paddr & IMEM_DSIZE); else return Util::ReadAccess(mmio.rsp.dmem, paddr & DMEM_DSIZE); @@ -245,7 +245,7 @@ u64 Mem::Read64(n64::Registers ®s, u64 vaddr, s64 pc) { case 0x00000000 ... 0x007FFFFF: return Util::ReadAccess(mmio.rdp.rdram.data(), paddr); case 0x04000000 ... 0x0403FFFF: - if ((paddr >> 12) & 1) + if (paddr & 0x1000) return Util::ReadAccess(mmio.rsp.imem, paddr & IMEM_DSIZE); else return Util::ReadAccess(mmio.rsp.dmem, paddr & DMEM_DSIZE); @@ -288,7 +288,7 @@ void Mem::Write8(Registers& regs, n64::JIT::Dynarec& dyn, u64 vaddr, u32 val, s6 FireException(regs, GetTLBExceptionCode(regs.cop0.tlbError, LOAD), 0, false); } - dyn.InvalidatePage(paddr); + dyn.InvalidatePage(BYTE_ADDRESS(paddr)); const auto page = paddr >> 12; auto offset = paddr & 0xFFF; @@ -349,7 +349,7 @@ void Mem::Write16(Registers& regs, n64::JIT::Dynarec& dyn, u64 vaddr, u32 val, s FireException(regs, GetTLBExceptionCode(regs.cop0.tlbError, STORE), 0, false); } - dyn.InvalidatePage(paddr); + dyn.InvalidatePage(HALF_ADDRESS(paddr)); const auto page = paddr >> 12; auto offset = paddr & 0xFFF; diff --git a/src/backend/core/mmio/VI.cpp b/src/backend/core/mmio/VI.cpp index 610ee289..c2b507d7 100644 --- a/src/backend/core/mmio/VI.cpp +++ b/src/backend/core/mmio/VI.cpp @@ -69,7 +69,7 @@ void VI::Write(MI& mi, Registers& regs, u32 paddr, u32 val) { case 0x04400018: { vsync = val & 0x3FF; numHalflines = vsync >> 1; - cyclesPerHalfline = N64_CYCLES_PER_FRAME / numHalflines; + cyclesPerHalfline = N64_CYCLES_PER_FRAME(false) / numHalflines; } break; case 0x0440001C: { hsync = val & 0x3FF; diff --git a/src/common.hpp b/src/common.hpp index 83d18146..834e1e50 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -14,7 +14,7 @@ using u128 = __uint128_t; using s128 = __int128_t; #define N64_CPU_FREQ 93750000 -#define N64_CYCLES_PER_FRAME ((N64_CPU_FREQ) / 60) +#define N64_CYCLES_PER_FRAME(pal) ((N64_CPU_FREQ) / (pal ? 50 : 60)) #define HALF_ADDRESS(addr) ((addr) ^ 2) #define BYTE_ADDRESS(addr) ((addr) ^ 3) diff --git a/src/frontend/imgui/Window.cpp b/src/frontend/imgui/Window.cpp index 710a6bc6..2483a8de 100644 --- a/src/frontend/imgui/Window.cpp +++ b/src/frontend/imgui/Window.cpp @@ -147,15 +147,15 @@ Window::~Window() { SDL_Quit(); } -DrawData Window::Present(n64::Core& core) { +ImDrawData* Window::Present(n64::Core& core) { ImGui_ImplVulkan_NewFrame(); ImGui_ImplSDL2_NewFrame(window); ImGui::NewFrame(); - float mainMenuBarHeight = Render(core); + Render(core); ImGui::Render(); - return {ImGui::GetDrawData(), mainMenuBarHeight}; + return ImGui::GetDrawData(); } void Window::LoadROM(n64::Core& core, const std::string &path) { @@ -192,23 +192,10 @@ void Window::LoadROM(n64::Core& core, const std::string &path) { } } -float Window::Render(n64::Core& core) { - ImGui::PushFont(uiFont); - - u32 ticks = SDL_GetTicks(); - static u32 lastFrame = 0; - if(!core.pause && lastFrame < ticks - 1000) { - lastFrame = ticks; - windowTitle += fmt::format(" | {:02d} In-Game FPS", core.mem.mmio.vi.swaps); - core.mem.mmio.vi.swaps = 0; - SDL_SetWindowTitle(window, windowTitle.c_str()); - windowTitle = shadowWindowTitle; - } - - static bool showSettings = false; - static float mainMenuBarHeight = 0; +void Window::RenderMainMenuBar(n64::Core &core) { ImGui::BeginMainMenuBar(); mainMenuBarHeight = ImGui::GetWindowSize().y; + if (ImGui::BeginMenu("File")) { if (ImGui::MenuItem("Open", "O")) { nfdchar_t *outpath; @@ -265,15 +252,33 @@ float Window::Render(n64::Core& core) { ImGui::EndMenu(); } ImGui::EndMainMenuBar(); +} + +void Window::Render(n64::Core& core) { + ImGui::PushFont(uiFont); + + u32 ticks = SDL_GetTicks(); + static u32 lastFrame = 0; + if(!core.pause && lastFrame < ticks - 1000) { + lastFrame = ticks; + windowTitle += fmt::format(" | {:02d} In-Game FPS", core.mem.mmio.vi.swaps); + core.mem.mmio.vi.swaps = 0; + SDL_SetWindowTitle(window, windowTitle.c_str()); + windowTitle = shadowWindowTitle; + } + + if(SDL_GetMouseFocus()) { + RenderMainMenuBar(core); + } static std::string rom{}; if(renderGameList && gameList.RenderWidget(mainMenuBarHeight, rom)) { LoadROM(core, rom); renderGameList = false; } + + mainMenuBarHeight = 0; settings.RenderWidget(showSettings); ImGui::PopFont(); - - return mainMenuBarHeight; } diff --git a/src/frontend/imgui/Window.hpp b/src/frontend/imgui/Window.hpp index bba80f81..63ba357a 100644 --- a/src/frontend/imgui/Window.hpp +++ b/src/frontend/imgui/Window.hpp @@ -10,15 +10,10 @@ #include #include -struct DrawData { - ImDrawData* first; - float second; -}; - struct Window { explicit Window(n64::Core& core); ~Window(); - DrawData Present(n64::Core& core); + ImDrawData* Present(n64::Core& core); [[nodiscard]] bool gotClosed(SDL_Event event); ImFont *uiFont{}, *codeFont{}; @@ -28,13 +23,16 @@ struct Window { void LoadROM(n64::Core& core, const std::string& path); private: bool renderGameList = true; + bool showSettings = false; + float mainMenuBarHeight = 0; SDL_Window* window{}; std::string windowTitle{"Gadolinium"}; std::string shadowWindowTitle{windowTitle}; std::string gameName{}; void InitSDL(); void InitImgui(); - float Render(n64::Core& core); + void Render(n64::Core& core); + void RenderMainMenuBar(n64::Core& core); VkPhysicalDevice physicalDevice{}; VkDevice device{};