make menu bar disappear + change way scaling works

This commit is contained in:
CocoSimone
2023-02-10 14:22:00 +01:00
parent 0954bb23b1
commit 5d35fb229f
9 changed files with 71 additions and 73 deletions

View File

@@ -15,8 +15,6 @@ static CommandProcessor* command_processor;
static WSI* wsi; static WSI* wsi;
static std::unique_ptr<ParallelRdpWindowInfo> windowInfo; static std::unique_ptr<ParallelRdpWindowInfo> windowInfo;
std::vector<Semaphore> acquire_semaphore;
VkQueue GetGraphicsQueue() { VkQueue GetGraphicsQueue() {
return wsi->get_context().get_queue_info().queues[QUEUE_INDEX_GRAPHICS]; return wsi->get_context().get_queue_info().queues[QUEUE_INDEX_GRAPHICS];
} }
@@ -140,7 +138,7 @@ WSI* LoadWSIPlatform(Vulkan::WSIPlatform* wsi_platform, std::unique_ptr<Parallel
return wsi; return wsi;
} }
void LoadParallelRDP(const u8* rdram, SDL_Window* window) { void LoadParallelRDP(const u8* rdram) {
ResourceLayout vertLayout; ResourceLayout vertLayout;
ResourceLayout fragLayout; ResourceLayout fragLayout;
@@ -185,38 +183,28 @@ void LoadParallelRDP(const u8* rdram, SDL_Window* window) {
void InitParallelRDP(const u8* rdram, SDL_Window* window) { void InitParallelRDP(const u8* rdram, SDL_Window* window) {
g_Window = window; g_Window = window;
LoadWSIPlatform(new SDLWSIPlatform(), std::make_unique<SDLParallelRdpWindowInfo>()); LoadWSIPlatform(new SDLWSIPlatform(), std::make_unique<SDLParallelRdpWindowInfo>());
LoadParallelRDP(rdram, window); LoadParallelRDP(rdram);
} }
void DrawFullscreenTexturedQuad(float mainMenuBarHeight, Util::IntrusivePtr<Image> image, Util::IntrusivePtr<CommandBuffer> cmd) { void DrawFullscreenTexturedQuad(Util::IntrusivePtr<Image> image, Util::IntrusivePtr<CommandBuffer> cmd) {
cmd->set_texture(0, 0, image->get_view(), Vulkan::StockSampler::LinearClamp); cmd->set_texture(0, 0, image->get_view(), Vulkan::StockSampler::LinearClamp);
cmd->set_program(fullscreen_quad_program); cmd->set_program(fullscreen_quad_program);
cmd->set_quad_state(); cmd->set_quad_state();
auto data = static_cast<float*>(cmd->allocate_vertex_data(0, 6 * sizeof(float), 2 * sizeof(float))); auto data = static_cast<float*>(cmd->allocate_vertex_data(0, 6 * sizeof(float), 2 * sizeof(float)));
*data++ = -1.0f; data[0] = -1.0f;
*data++ = -3.0f; data[1] = -3.0f;
*data++ = -1.0f; data[2] = -1.0f;
*data++ = +1.0f; data[3] = +1.0f;
*data++ = +3.0f; data[4] = +3.0f;
*data++ = +1.0f; data[5] = +1.0f;
int sdlWinWidth, sdlWinHeight; auto windowSize = windowInfo->get_window_size();
SDL_GetWindowSize(g_Window, &sdlWinWidth, &sdlWinHeight);
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 width = (wsi->get_platform().get_surface_width() / windowSize.x) * zoom;
float platform_height = wsi->get_platform().get_surface_height(); float height = (wsi->get_platform().get_surface_height() / windowSize.y) * zoom;
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 uniform_data[] = { float uniform_data[] = {
// Size // Size
@@ -262,11 +250,11 @@ void UpdateScreen(n64::Core& core, Window& imguiWindow, Util::IntrusivePtr<Image
Util::IntrusivePtr<CommandBuffer> cmd = wsi->get_device().request_command_buffer(); Util::IntrusivePtr<CommandBuffer> cmd = wsi->get_device().request_command_buffer();
cmd->begin_render_pass(wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly)); 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(); cmd->end_render_pass();
wsi->get_device().submit(cmd); wsi->get_device().submit(cmd);

View File

@@ -9,8 +9,8 @@ static SDL_Window* g_Window;
class ParallelRdpWindowInfo { class ParallelRdpWindowInfo {
public: public:
struct CoordinatePair { struct CoordinatePair {
int x; float x;
int y; float y;
}; };
virtual CoordinatePair get_window_size() = 0; virtual CoordinatePair get_window_size() = 0;
virtual ~ParallelRdpWindowInfo() = default; virtual ~ParallelRdpWindowInfo() = default;
@@ -20,7 +20,7 @@ class SDLParallelRdpWindowInfo : public ParallelRdpWindowInfo {
CoordinatePair get_window_size() { CoordinatePair get_window_size() {
int width, height; int width, height;
SDL_GetWindowSize(g_Window, &width, &height); SDL_GetWindowSize(g_Window, &width, &height);
return CoordinatePair{ width, height }; return CoordinatePair{ static_cast<float>(width), static_cast<float>(height) };
} }
}; };

View File

@@ -75,7 +75,7 @@ void Core::Run(Window& window, float volumeL, float volumeR) {
UpdateScreenParallelRdp(*this, window, GetVI()); 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); mmio.ai.Step(mem, regs, missedCycles, volumeL, volumeR);
} else if(pause && romLoaded) { } else if(pause && romLoaded) {
UpdateScreenParallelRdp(*this, window, GetVI()); UpdateScreenParallelRdp(*this, window, GetVI());

View File

@@ -14,9 +14,16 @@
#define ISVIEWER_SIZE (0x13FFFFFF - 0x13FF0020) #define ISVIEWER_SIZE (0x13FFFFFF - 0x13FF0020)
#define ISVIEWER_DSIZE (ISVIEWER_SIZE - 1) #define ISVIEWER_DSIZE (ISVIEWER_SIZE - 1)
#define RDRAM_REGION 0 ... RDRAM_DSIZE #define RDRAM_REGION_START 0
#define DMEM_REGION 0x04000000 ... DMEM_DSIZE #define RDRAM_REGION_END RDRAM_DSIZE
#define IMEM_REGION 0x04001000 ... IMEM_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 MMIO_REGION 0x04040000 ... 0x048FFFFF
#define SP_REGION 0x04040000 ... 0x040FFFFF #define SP_REGION 0x04040000 ... 0x040FFFFF
#define DP_CMD_REGION 0x04100000 ... 0x041FFFFF #define DP_CMD_REGION 0x04100000 ... 0x041FFFFF

View File

@@ -108,10 +108,10 @@ u8 Mem::Read8(n64::Registers &regs, u64 vaddr, s64 pc) {
case 0x00000000 ... 0x007FFFFF: case 0x00000000 ... 0x007FFFFF:
return mmio.rdp.rdram[BYTE_ADDRESS(paddr)]; return mmio.rdp.rdram[BYTE_ADDRESS(paddr)];
case 0x04000000 ... 0x0403FFFF: case 0x04000000 ... 0x0403FFFF:
if ((paddr >> 12) & 1) if (paddr & 0x1000)
return mmio.rsp.imem[BYTE_ADDRESS(paddr) & IMEM_DSIZE]; return mmio.rsp.imem[BYTE_ADDRESS(paddr) - IMEM_REGION_START];
else else
return mmio.rsp.dmem[BYTE_ADDRESS(paddr) & DMEM_DSIZE]; return mmio.rsp.dmem[BYTE_ADDRESS(paddr) - DMEM_REGION_START];
case 0x04040000 ... 0x040FFFFF: case 0x04040000 ... 0x040FFFFF:
case 0x04100000 ... 0x041FFFFF: case 0x04100000 ... 0x041FFFFF:
case 0x04600000 ... 0x048FFFFF: case 0x04600000 ... 0x048FFFFF:
@@ -159,7 +159,7 @@ u16 Mem::Read16(n64::Registers &regs, u64 vaddr, s64 pc) {
case 0x00000000 ... 0x007FFFFF: case 0x00000000 ... 0x007FFFFF:
return Util::ReadAccess<u16>(mmio.rdp.rdram.data(), HALF_ADDRESS(paddr)); return Util::ReadAccess<u16>(mmio.rdp.rdram.data(), HALF_ADDRESS(paddr));
case 0x04000000 ... 0x0403FFFF: case 0x04000000 ... 0x0403FFFF:
if ((paddr >> 12) & 1) if (paddr & 0x1000)
return Util::ReadAccess<u16>(mmio.rsp.imem, HALF_ADDRESS(paddr) & IMEM_DSIZE); return Util::ReadAccess<u16>(mmio.rsp.imem, HALF_ADDRESS(paddr) & IMEM_DSIZE);
else else
return Util::ReadAccess<u16>(mmio.rsp.dmem, HALF_ADDRESS(paddr) & DMEM_DSIZE); return Util::ReadAccess<u16>(mmio.rsp.dmem, HALF_ADDRESS(paddr) & DMEM_DSIZE);
@@ -205,7 +205,7 @@ u32 Mem::Read32(n64::Registers &regs, u64 vaddr, s64 pc) {
case 0x00000000 ... 0x007FFFFF: case 0x00000000 ... 0x007FFFFF:
return Util::ReadAccess<u32>(mmio.rdp.rdram.data(), paddr); return Util::ReadAccess<u32>(mmio.rdp.rdram.data(), paddr);
case 0x04000000 ... 0x0403FFFF: case 0x04000000 ... 0x0403FFFF:
if((paddr >> 12) & 1) if(paddr & 0x1000)
return Util::ReadAccess<u32>(mmio.rsp.imem, paddr & IMEM_DSIZE); return Util::ReadAccess<u32>(mmio.rsp.imem, paddr & IMEM_DSIZE);
else else
return Util::ReadAccess<u32>(mmio.rsp.dmem, paddr & DMEM_DSIZE); return Util::ReadAccess<u32>(mmio.rsp.dmem, paddr & DMEM_DSIZE);
@@ -245,7 +245,7 @@ u64 Mem::Read64(n64::Registers &regs, u64 vaddr, s64 pc) {
case 0x00000000 ... 0x007FFFFF: case 0x00000000 ... 0x007FFFFF:
return Util::ReadAccess<u64>(mmio.rdp.rdram.data(), paddr); return Util::ReadAccess<u64>(mmio.rdp.rdram.data(), paddr);
case 0x04000000 ... 0x0403FFFF: case 0x04000000 ... 0x0403FFFF:
if ((paddr >> 12) & 1) if (paddr & 0x1000)
return Util::ReadAccess<u64>(mmio.rsp.imem, paddr & IMEM_DSIZE); return Util::ReadAccess<u64>(mmio.rsp.imem, paddr & IMEM_DSIZE);
else else
return Util::ReadAccess<u64>(mmio.rsp.dmem, paddr & DMEM_DSIZE); return Util::ReadAccess<u64>(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); FireException(regs, GetTLBExceptionCode(regs.cop0.tlbError, LOAD), 0, false);
} }
dyn.InvalidatePage(paddr); dyn.InvalidatePage(BYTE_ADDRESS(paddr));
const auto page = paddr >> 12; const auto page = paddr >> 12;
auto offset = paddr & 0xFFF; 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); FireException(regs, GetTLBExceptionCode(regs.cop0.tlbError, STORE), 0, false);
} }
dyn.InvalidatePage(paddr); dyn.InvalidatePage(HALF_ADDRESS(paddr));
const auto page = paddr >> 12; const auto page = paddr >> 12;
auto offset = paddr & 0xFFF; auto offset = paddr & 0xFFF;

View File

@@ -69,7 +69,7 @@ void VI::Write(MI& mi, Registers& regs, u32 paddr, u32 val) {
case 0x04400018: { case 0x04400018: {
vsync = val & 0x3FF; vsync = val & 0x3FF;
numHalflines = vsync >> 1; numHalflines = vsync >> 1;
cyclesPerHalfline = N64_CYCLES_PER_FRAME / numHalflines; cyclesPerHalfline = N64_CYCLES_PER_FRAME(false) / numHalflines;
} break; } break;
case 0x0440001C: { case 0x0440001C: {
hsync = val & 0x3FF; hsync = val & 0x3FF;

View File

@@ -14,7 +14,7 @@ using u128 = __uint128_t;
using s128 = __int128_t; using s128 = __int128_t;
#define N64_CPU_FREQ 93750000 #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 HALF_ADDRESS(addr) ((addr) ^ 2)
#define BYTE_ADDRESS(addr) ((addr) ^ 3) #define BYTE_ADDRESS(addr) ((addr) ^ 3)

View File

@@ -147,15 +147,15 @@ Window::~Window() {
SDL_Quit(); SDL_Quit();
} }
DrawData Window::Present(n64::Core& core) { ImDrawData* Window::Present(n64::Core& core) {
ImGui_ImplVulkan_NewFrame(); ImGui_ImplVulkan_NewFrame();
ImGui_ImplSDL2_NewFrame(window); ImGui_ImplSDL2_NewFrame(window);
ImGui::NewFrame(); ImGui::NewFrame();
float mainMenuBarHeight = Render(core); Render(core);
ImGui::Render(); ImGui::Render();
return {ImGui::GetDrawData(), mainMenuBarHeight}; return ImGui::GetDrawData();
} }
void Window::LoadROM(n64::Core& core, const std::string &path) { 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) { void Window::RenderMainMenuBar(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;
ImGui::BeginMainMenuBar(); ImGui::BeginMainMenuBar();
mainMenuBarHeight = ImGui::GetWindowSize().y; mainMenuBarHeight = ImGui::GetWindowSize().y;
if (ImGui::BeginMenu("File")) { if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("Open", "O")) { if (ImGui::MenuItem("Open", "O")) {
nfdchar_t *outpath; nfdchar_t *outpath;
@@ -265,15 +252,33 @@ float Window::Render(n64::Core& core) {
ImGui::EndMenu(); ImGui::EndMenu();
} }
ImGui::EndMainMenuBar(); 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{}; static std::string rom{};
if(renderGameList && gameList.RenderWidget(mainMenuBarHeight, rom)) { if(renderGameList && gameList.RenderWidget(mainMenuBarHeight, rom)) {
LoadROM(core, rom); LoadROM(core, rom);
renderGameList = false; renderGameList = false;
} }
mainMenuBarHeight = 0;
settings.RenderWidget(showSettings); settings.RenderWidget(showSettings);
ImGui::PopFont(); ImGui::PopFont();
return mainMenuBarHeight;
} }

View File

@@ -10,15 +10,10 @@
#include <frontend/imgui/Settings.hpp> #include <frontend/imgui/Settings.hpp>
#include <frontend/imgui/GameList.hpp> #include <frontend/imgui/GameList.hpp>
struct DrawData {
ImDrawData* first;
float second;
};
struct Window { struct Window {
explicit Window(n64::Core& core); explicit Window(n64::Core& core);
~Window(); ~Window();
DrawData Present(n64::Core& core); ImDrawData* Present(n64::Core& core);
[[nodiscard]] bool gotClosed(SDL_Event event); [[nodiscard]] bool gotClosed(SDL_Event event);
ImFont *uiFont{}, *codeFont{}; ImFont *uiFont{}, *codeFont{};
@@ -28,13 +23,16 @@ struct Window {
void LoadROM(n64::Core& core, const std::string& path); void LoadROM(n64::Core& core, const std::string& path);
private: private:
bool renderGameList = true; bool renderGameList = true;
bool showSettings = false;
float mainMenuBarHeight = 0;
SDL_Window* window{}; SDL_Window* window{};
std::string windowTitle{"Gadolinium"}; std::string windowTitle{"Gadolinium"};
std::string shadowWindowTitle{windowTitle}; std::string shadowWindowTitle{windowTitle};
std::string gameName{}; std::string gameName{};
void InitSDL(); void InitSDL();
void InitImgui(); void InitImgui();
float Render(n64::Core& core); void Render(n64::Core& core);
void RenderMainMenuBar(n64::Core& core);
VkPhysicalDevice physicalDevice{}; VkPhysicalDevice physicalDevice{};
VkDevice device{}; VkDevice device{};