From da1c28bd16590a68cb1db891e158f29499919b6a Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 2 Oct 2023 21:34:34 +1000 Subject: [PATCH] Misc: Fix arm32 build --- CMakeLists.txt | 8 +++++++- src/common/fastjmp.cpp | 24 ++++++++++++++++++++++++ src/common/fastjmp.h | 2 ++ src/core/bus.h | 2 ++ src/util/opengl_device.cpp | 36 +++++++++++++++++++++++++----------- src/util/opengl_texture.cpp | 10 ++++++++-- src/util/vulkan_builders.h | 4 ++-- 7 files changed, 70 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 636e83c9c..485be291d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,7 +150,13 @@ elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86" OR "${CMAKE_SYSTEM_PROCESSOR}" "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686") set(CPU_ARCH "x86") elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64") - set(CPU_ARCH "aarch64") + if(CMAKE_SIZEOF_VOID_P EQUAL 8) # Might have an A64 kernel, e.g. Raspbian. + set(CPU_ARCH "aarch64") + else() + set(CPU_ARCH "aarch32") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm -march=armv7-a") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm -march=armv7-a") + endif() elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l") set(CPU_ARCH "aarch32") diff --git a/src/common/fastjmp.cpp b/src/common/fastjmp.cpp index 6c793f919..6b028b926 100644 --- a/src/common/fastjmp.cpp +++ b/src/common/fastjmp.cpp @@ -87,6 +87,30 @@ asm( br x30 )"); +#elif defined(__arm__) + +asm( + "\t.global " PREFIX "fastjmp_set\n" + "\t.global " PREFIX "fastjmp_jmp\n" + "\t.text\n" + "\t" PREFIX "fastjmp_set:" R"( + vstmia r0!, {d8-d15} + stmia r0!, {r4-r14} + fmrx r1, fpscr + str r1, [r0] + mov r0, #0 + bx lr +)" + +"\t" PREFIX "fastjmp_jmp:" R"( + vldmia r0!, {d8-d15} + ldmia r0!, {r4-r14} + ldr r0, [r0] + fmxr fpscr, r0 + mov r0, r1 + bx lr +)"); + #elif defined(__riscv) && __riscv_xlen == 64 asm( diff --git a/src/common/fastjmp.h b/src/common/fastjmp.h index b0bab768c..91a603b2e 100644 --- a/src/common/fastjmp.h +++ b/src/common/fastjmp.h @@ -14,6 +14,8 @@ struct fastjmp_buf static constexpr std::size_t BUF_SIZE = 240; #elif defined(_M_ARM64) || defined(__aarch64__) static constexpr std::size_t BUF_SIZE = 168; +#elif defined(_M_ARM) || defined(__arm__) + static constexpr std::size_t BUF_SIZE = 112; #elif defined(__x86_64__) static constexpr std::size_t BUF_SIZE = 64; #elif defined(_M_IX86) || defined(__i386__) diff --git a/src/core/bus.h b/src/core/bus.h index 6c6190494..88c4b38ce 100644 --- a/src/core/bus.h +++ b/src/core/bus.h @@ -102,8 +102,10 @@ enum : u32 FASTMEM_LUT_NUM_SLOTS = FASTMEM_LUT_NUM_PAGES * 2, }; +#ifdef ENABLE_MMAP_FASTMEM // Fastmem region size is 4GB to cover the entire 32-bit address space. static constexpr size_t FASTMEM_ARENA_SIZE = UINT64_C(0x100000000); +#endif bool AllocateMemory(); void ReleaseMemory(); diff --git a/src/util/opengl_device.cpp b/src/util/opengl_device.cpp index 3d7e1f57b..c6ef0f360 100644 --- a/src/util/opengl_device.cpp +++ b/src/util/opengl_device.cpp @@ -82,6 +82,8 @@ bool OpenGLDevice::DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 width, } else { + glBindFramebuffer(GL_READ_FRAMEBUFFER, m_read_fbo); + if (T->GetLayers() > 1) glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, T->GetGLId(), level, layer); else @@ -91,6 +93,7 @@ bool OpenGLDevice::DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 width, glReadPixels(x, y, width, height, gl_format, gl_type, out_data); glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); } return true; @@ -137,17 +140,24 @@ void OpenGLDevice::CopyTextureRegion(GPUTexture* dst, u32 dst_x, u32 dst_y, u32 else glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, D->GetGLTarget(), did, dst_level); if (S->IsTextureArray()) - glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, sid, src_level, src_layer); + glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, sid, src_level, src_layer); else - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, S->GetGLTarget(), sid, src_level); + glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, S->GetGLTarget(), sid, src_level); glDisable(GL_SCISSOR_TEST); - glBlitFramebuffer(src_x, src_y, src_x + width, src_y + width, dst_x, dst_y, dst_x + width, dst_y + height, + glBlitFramebuffer(src_x, src_y, src_x + width, src_y + height, dst_x, dst_y, dst_x + width, dst_y + height, GL_COLOR_BUFFER_BIT, GL_NEAREST); glEnable(GL_SCISSOR_TEST); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_current_framebuffer ? m_current_framebuffer->GetGLId() : 0); - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + if (m_current_framebuffer) + { + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_current_framebuffer ? m_current_framebuffer->GetGLId() : 0); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + } + else + { + glBindFramebuffer(GL_FRAMEBUFFER, 0); + } } } @@ -185,8 +195,15 @@ void OpenGLDevice::ResolveTextureRegion(GPUTexture* dst, u32 dst_x, u32 dst_y, u GL_COLOR_BUFFER_BIT, GL_LINEAR); glEnable(GL_SCISSOR_TEST); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_current_framebuffer ? m_current_framebuffer->GetGLId() : 0); - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + if (m_current_framebuffer) + { + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_current_framebuffer ? m_current_framebuffer->GetGLId() : 0); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + } + else + { + glBindFramebuffer(GL_FRAMEBUFFER, 0); + } } void OpenGLDevice::ClearRenderTarget(GPUTexture* t, u32 c) @@ -638,9 +655,6 @@ bool OpenGLDevice::CreateBuffers(bool buggy_pbo) m_read_fbo = fbos[0]; m_write_fbo = fbos[1]; - // Read FBO gets left bound. - glBindFramebuffer(GL_READ_FRAMEBUFFER, m_read_fbo); - return true; } @@ -665,7 +679,7 @@ bool OpenGLDevice::BeginPresent(bool skip_present) return false; } - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); const Common::Rectangle window_rc = Common::Rectangle::FromExtents(0, 0, m_window_info.surface_width, m_window_info.surface_height); diff --git a/src/util/opengl_texture.cpp b/src/util/opengl_texture.cpp index 7e61fe6bb..5f308fe82 100644 --- a/src/util/opengl_texture.cpp +++ b/src/util/opengl_texture.cpp @@ -484,7 +484,10 @@ void OpenGLDevice::CommitClear(OpenGLTexture* tex) glDisable(GL_SCISSOR_TEST); if (tex->IsDepthStencil()) { - glClearDepth(tex->GetClearDepth()); + if (glClearDepthf) + glClearDepthf(tex->GetClearDepth()); + else + glClearDepth(tex->GetClearDepth()); glClear(GL_DEPTH_BUFFER_BIT); } else @@ -556,7 +559,10 @@ void OpenGLDevice::CommitClear(OpenGLFramebuffer* fb) case GPUTexture::State::Cleared: { - glClearDepth(DS->GetClearDepth()); + if (glClearDepthf) + glClearDepthf(DS->GetClearDepth()); + else + glClearDepth(DS->GetClearDepth()); clear_flags |= GL_DEPTH_BUFFER_BIT; DS->SetState(GPUTexture::State::Dirty); } diff --git a/src/util/vulkan_builders.h b/src/util/vulkan_builders.h index ccec95cfd..3709dcc19 100644 --- a/src/util/vulkan_builders.h +++ b/src/util/vulkan_builders.h @@ -11,7 +11,7 @@ #include #include -#ifdef _DEBUG +#if defined(_DEBUG) && !defined(CPU_ARCH_ARM32) && !defined(CPU_ARCH_X86) #define ENABLE_VULKAN_DEBUG_OBJECTS 1 #endif @@ -413,4 +413,4 @@ static inline void SetObjectName(VkDevice device, T object_handle, const std::st SetFormattedObjectName(device, object_handle, "%.*s", static_cast(sv.length()), sv.data()); #endif } -} // namespace Vulkan \ No newline at end of file +} // namespace Vulkan