Fixed Bug where metal surface pointer wasnt actually set

This commit is contained in:
matthieu.ranger
2020-06-27 18:46:38 -04:00
parent 0079a09305
commit d28e0f51fa
3 changed files with 8 additions and 14 deletions

View File

@@ -155,7 +155,7 @@ public:
* Returns drawing area raw pointer * Returns drawing area raw pointer
* Unsafe version for MoltenVK to modify pointer * Unsafe version for MoltenVK to modify pointer
*/ */
void* GetRenderSurface() { void* &GetRenderSurface() {
return window_info.render_surface; return window_info.render_surface;
} }

View File

@@ -43,7 +43,6 @@
#ifdef __APPLE__ #ifdef __APPLE__
#define VK_USE_PLATFORM_METAL_EXT #define VK_USE_PLATFORM_METAL_EXT
#include <objc/message.h> #include <objc/message.h>
#include "common/file_util.h"
#include "vulkan/vulkan_macos.h" #include "vulkan/vulkan_macos.h"
#include "vulkan/vulkan_metal.h" #include "vulkan/vulkan_metal.h"
#endif #endif
@@ -277,10 +276,9 @@ bool RendererVulkan::TryPresent(int /*timeout_ms*/) {
return true; return true;
} }
void PrepareWindow([[maybe_unused]] void* render_surface) { void PrepareMetalWindow([[maybe_unused]] void* &render_surface) {
#if defined(VK_USE_PLATFORM_METAL_EXT) #if defined(VK_USE_PLATFORM_METAL_EXT)
// This is kinda messy, but it avoids having to write Objective C++ just to create a metal // Hackish: avoids having to write Objective C++ just to create a metal layer.
// layer.
id view = reinterpret_cast<id>(render_surface); id view = reinterpret_cast<id>(render_surface);
Class clsCAMetalLayer = objc_getClass("CAMetalLayer"); Class clsCAMetalLayer = objc_getClass("CAMetalLayer");
if (!clsCAMetalLayer) { if (!clsCAMetalLayer) {
@@ -309,27 +307,25 @@ void PrepareWindow([[maybe_unused]] void* render_surface) {
// layer.contentsScale = factor // layer.contentsScale = factor
reinterpret_cast<void (*)(id, SEL, double)>(objc_msgSend)( reinterpret_cast<void (*)(id, SEL, double)>(objc_msgSend)(
layer, sel_getUid("setContentsScale:"), factor); layer, sel_getUid("setContentsScale:"), factor);
// Store the layer pointer, that way MoltenVK doesn't call [NSView layer] outside the main // Store layer ptr, so MoltenVK doesn't call [NSView layer] outside main thread.
// thread.
render_surface = layer; render_surface = layer;
#endif #endif
} }
bool RendererVulkan::Init() { bool RendererVulkan::Init() {
PrepareWindow(render_window.GetRenderSurface()); #ifdef __APPLE__
PrepareMetalWindow(render_window.GetRenderSurface());
#endif
library = OpenVulkanLibrary(); library = OpenVulkanLibrary();
instance = CreateInstance(library, dld, render_window.GetWindowInfo().type, instance = CreateInstance(library, dld, render_window.GetWindowInfo().type,
Settings::values.renderer_debug); Settings::values.renderer_debug);
if (!instance || !CreateDebugCallback() || !CreateSurface() || !PickDevices()) { if (!instance || !CreateDebugCallback() || !CreateSurface() || !PickDevices()) {
return false; return false;
} }
Report(); Report();
memory_manager = std::make_unique<VKMemoryManager>(*device); memory_manager = std::make_unique<VKMemoryManager>(*device);
resource_manager = std::make_unique<VKResourceManager>(*device); resource_manager = std::make_unique<VKResourceManager>(*device);
const auto& framebuffer = render_window.GetFramebufferLayout(); const auto& framebuffer = render_window.GetFramebufferLayout();
swapchain = std::make_unique<VKSwapchain>(*surface, *device); swapchain = std::make_unique<VKSwapchain>(*surface, *device);
swapchain->Create(framebuffer.width, framebuffer.height, false); swapchain->Create(framebuffer.width, framebuffer.height, false);
@@ -381,7 +377,6 @@ bool RendererVulkan::CreateDebugCallback() {
bool RendererVulkan::CreateSurface() { bool RendererVulkan::CreateSurface() {
[[maybe_unused]] const auto& window_info = render_window.GetWindowInfo(); [[maybe_unused]] const auto& window_info = render_window.GetWindowInfo();
VkSurfaceKHR unsafe_surface = nullptr; VkSurfaceKHR unsafe_surface = nullptr;
#ifdef _WIN32 #ifdef _WIN32
if (window_info.type == Core::Frontend::WindowSystemType::Windows) { if (window_info.type == Core::Frontend::WindowSystemType::Windows) {
const HWND hWnd = static_cast<HWND>(window_info.render_surface); const HWND hWnd = static_cast<HWND>(window_info.render_surface);
@@ -444,7 +439,6 @@ bool RendererVulkan::CreateSurface() {
LOG_ERROR(Render_Vulkan, "Presentation not supported on this platform"); LOG_ERROR(Render_Vulkan, "Presentation not supported on this platform");
return false; return false;
} }
surface = vk::SurfaceKHR(unsafe_surface, *instance, dld); surface = vk::SurfaceKHR(unsafe_surface, *instance, dld);
return true; return true;
} }

View File

@@ -36,7 +36,7 @@ struct VKScreenInfo {
bool is_srgb{}; bool is_srgb{};
}; };
void PrepareWindow([[maybe_unused]] void* render_surface); void PrepareMetalWindow([[maybe_unused]] void* &render_surface);
class RendererVulkan final : public VideoCore::RendererBase { class RendererVulkan final : public VideoCore::RendererBase {
public: public: