vulkan: windows support

This commit is contained in:
flyinghead 2019-10-15 21:25:24 +02:00
parent 43d87877be
commit a6c56ba748
5 changed files with 54 additions and 82 deletions

View File

@ -1,74 +0,0 @@
//
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "InitializeDll.h"
#define STRICT
#define VC_EXTRALEAN 1
#include <windows.h>
#include <assert.h>
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
if (! glslang::InitProcess())
return FALSE;
break;
case DLL_THREAD_ATTACH:
if (! glslang::InitThread())
return FALSE;
break;
case DLL_THREAD_DETACH:
if (! glslang::DetachThread())
return FALSE;
break;
case DLL_PROCESS_DETACH:
glslang::DetachProcess();
break;
default:
assert(0 && "DllMain(): Reason for calling DLL Main is unknown");
return FALSE;
}
return TRUE;
}

View File

@ -278,7 +278,6 @@ public:
1, &subpass, settings.rend.RenderToTextureBuffer ? ARRAY_SIZE(vramWriteDeps) : ARRAY_SIZE(dependencies),
settings.rend.RenderToTextureBuffer ? vramWriteDeps : dependencies));
renderPass = *rttRenderPass;
printf("RttPipelineManager renderPass %p created\n", (VkRenderPass)renderPass);
}
private:

View File

@ -35,6 +35,7 @@ class VulkanContext
public:
VulkanContext() { verify(contextInstance == nullptr); contextInstance = this; }
~VulkanContext();
bool Init();
bool InitInstance(const char** extensions, uint32_t extensions_count);
bool InitDevice();
void CreateSwapChain();

View File

@ -133,14 +133,7 @@ bool VulkanContext::InitInstance(const char** extensions, uint32_t extensions_co
#ifndef __ANDROID__
vext.push_back("VK_EXT_debug_utils");
extensions_count += 1;
// layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
// layer_names.push_back("VK_LAYER_LUNARG_api_dump");
// layer_names.push_back("VK_LAYER_LUNARG_core_validation");
// layer_names.push_back("VK_LAYER_LUNARG_image");
// layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
// layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
// layer_names.push_back("VK_LAYER_LUNARG_swapchain");
// layer_names.push_back("VK_LAYER_GOOGLE_threading");
layer_names.push_back("VK_LAYER_LUNARG_standard_validation");
#else
vext.push_back("VK_EXT_debug_report"); // NDK <= 19?
@ -571,6 +564,37 @@ void VulkanContext::CreateSwapChain()
}
}
bool VulkanContext::Init()
{
std::vector<const char *> extensions;
extensions.push_back("VK_KHR_surface");
#if defined(_WIN32)
extensions.push_back("VK_KHR_win32_surface");
#elif defined(__MACH__)
extensions.push_back("VK_MVK_macos_surface");
#elif defined(SUPPORT_X11)
extensions.push_back("VK_KHR_xlib_surface");
#endif
if (!InitInstance(&extensions[0], extensions.size()))
return false;
VkSurfaceKHR surface = nullptr;
#if defined(_WIN32)
VkWin32SurfaceCreateInfoKHR createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
createInfo.hinstance = GetModuleHandle(NULL);
createInfo.hwnd = (HWND)libPvr_GetRenderTarget();
if (vkCreateWin32SurfaceKHR(*instance, &createInfo, nullptr, &surface) != VK_SUCCESS)
{
ERROR_LOG(RENDERER, "Windows surface creation failed");
return false;
}
#endif
SetSurface(surface);
return InitDevice();
}
void VulkanContext::NewFrame()
{
if (HasSurfaceDimensionChanged())

View File

@ -8,6 +8,9 @@
#include "win_keyboard.h"
#include "hw/sh4/dyna/blockmanager.h"
#include "log/LogManager.h"
#ifdef USE_VULKAN
#include "rend/vulkan/vulkan.h"
#endif
#define _WIN32_WINNT 0x0500
#include <windows.h>
@ -720,10 +723,29 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
#ifdef _WIN64
setup_seh();
#endif
#ifdef USE_VULKAN
VulkanContext *vulkanContext = nullptr;
if (settings.pvr.rend == 4)
{
vulkanContext = new VulkanContext();
if (!vulkanContext->Init())
{
settings.pvr.rend = 0;
delete vulkanContext;
vulkanContext = nullptr;
ERROR_LOG(RENDERER, "Vulkan initialization failed. Falling back to Open GL");
}
}
#endif
rend_thread(NULL);
dc_term();
#ifdef USE_VULKAN
if (vulkanContext != nullptr)
delete vulkanContext;
#endif
}
#ifndef __GNUC__
__except( ExeptionHandler(GetExceptionInformation()) )