Update to latest zvulkan
This commit is contained in:
parent
4e78ba469c
commit
5e22b07db2
16 changed files with 260 additions and 219 deletions
|
|
@ -10,6 +10,15 @@
|
|||
#ifndef VOLK_H_
|
||||
#define VOLK_H_
|
||||
|
||||
//************************************************************************************
|
||||
//** IF YOU UPDATE THIS FILE TO A NEWER VERSION OF VOLK, ADD THIS TO THE NEW FILE:
|
||||
//************************************************************************************
|
||||
|
||||
#include "../vulkan.h" // note: zvulkan's version
|
||||
|
||||
//************************************************************************************
|
||||
//************************************************************************************
|
||||
|
||||
#if defined(VULKAN_H_) && !defined(VK_NO_PROTOTYPES)
|
||||
# error To use volk, you need to define VK_NO_PROTOTYPES before including vulkan.h
|
||||
#endif
|
||||
|
|
|
|||
127
libraries/ZVulkan/include/zvulkan/vulkan.h
Normal file
127
libraries/ZVulkan/include/zvulkan/vulkan.h
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
ZVulkan include header for vulkan.
|
||||
Include this one instead of the system vulkan.h header.
|
||||
|
||||
We can't use the system header because we don't want to include platform specific headers (windows.h and xlib.h in particular).
|
||||
On Linux we even have many competing platform technologies that may not always be available on the system building the project.
|
||||
*/
|
||||
|
||||
#ifndef VULKAN_H_
|
||||
#define VULKAN_H_
|
||||
|
||||
#define VK_NO_PROTOTYPES // Volk needs this
|
||||
|
||||
// Declare what we intend to support for each OS:
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define VK_USE_PLATFORM_WIN32_KHR
|
||||
#elif defined(__APPLE__)
|
||||
#define VK_USE_PLATFORM_MACOS_MVK
|
||||
#define VK_USE_PLATFORM_METAL_EXT
|
||||
#else
|
||||
#define VK_USE_PLATFORM_XLIB_KHR
|
||||
#define VK_USE_PLATFORM_WAYLAND_KHR
|
||||
#endif
|
||||
|
||||
#include "vulkan/vk_platform.h"
|
||||
#include "vulkan/vulkan_core.h"
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
#include "vulkan/vulkan_android.h"
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_FUCHSIA
|
||||
#include <zircon/types.h>
|
||||
#include "vulkan/vulkan_fuchsia.h"
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_IOS_MVK
|
||||
#include "vulkan/vulkan_ios.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MACOS_MVK
|
||||
#include "vulkan/vulkan_macos.h"
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_METAL_EXT
|
||||
#include "vulkan/vulkan_metal.h"
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_VI_NN
|
||||
#include "vulkan/vulkan_vi.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
|
||||
//#include <wayland-client.h>
|
||||
struct wl_display;
|
||||
struct wl_surface;
|
||||
|
||||
#include "vulkan/vulkan_wayland.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
|
||||
// #include <windows.h>
|
||||
typedef unsigned long DWORD;
|
||||
typedef const wchar_t* LPCWSTR;
|
||||
typedef void* HANDLE;
|
||||
typedef struct HINSTANCE__* HINSTANCE;
|
||||
typedef struct HWND__* HWND;
|
||||
typedef struct HMONITOR__* HMONITOR;
|
||||
typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
|
||||
|
||||
#include "vulkan/vulkan_win32.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
#include <xcb/xcb.h>
|
||||
#include "vulkan/vulkan_xcb.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
|
||||
// #include <X11/Xlib.h>
|
||||
typedef struct _XDisplay Display;
|
||||
typedef unsigned long XID;
|
||||
typedef unsigned long VisualID;
|
||||
typedef XID Window;
|
||||
|
||||
#include "vulkan/vulkan_xlib.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
|
||||
#include <directfb.h>
|
||||
#include "vulkan/vulkan_directfb.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include "vulkan/vulkan_xlib_xrandr.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_GGP
|
||||
#include <ggp_c/vulkan_types.h>
|
||||
#include "vulkan/vulkan_ggp.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_SCREEN_QNX
|
||||
#include <screen/screen.h>
|
||||
#include "vulkan/vulkan_screen.h"
|
||||
#endif
|
||||
|
||||
#ifdef VK_ENABLE_BETA_EXTENSIONS
|
||||
#include "vulkan/vulkan_beta.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -13,8 +13,11 @@ public:
|
|||
|
||||
VulkanInstanceBuilder& ApiVersionsToTry(const std::vector<uint32_t>& versions);
|
||||
VulkanInstanceBuilder& RequireExtension(const std::string& extensionName);
|
||||
VulkanInstanceBuilder& RequireSurfaceExtensions(bool enable = true);
|
||||
VulkanInstanceBuilder& RequireExtensions(const std::vector<std::string>& extensions);
|
||||
VulkanInstanceBuilder& RequireExtensions(const std::vector<const char*>& extensions);
|
||||
VulkanInstanceBuilder& RequireExtensions(const char** extensions, size_t count);
|
||||
VulkanInstanceBuilder& OptionalExtension(const std::string& extensionName);
|
||||
VulkanInstanceBuilder& OptionalSwapchainColorspace();
|
||||
VulkanInstanceBuilder& DebugLayer(bool enable = true);
|
||||
|
||||
std::shared_ptr<VulkanInstance> Create();
|
||||
|
|
@ -26,23 +29,6 @@ private:
|
|||
bool debugLayer = false;
|
||||
};
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
|
||||
class VulkanSurfaceBuilder
|
||||
{
|
||||
public:
|
||||
VulkanSurfaceBuilder();
|
||||
|
||||
VulkanSurfaceBuilder& Win32Window(HWND handle);
|
||||
|
||||
std::shared_ptr<VulkanSurface> Create(std::shared_ptr<VulkanInstance> instance);
|
||||
|
||||
private:
|
||||
HWND hwnd = {};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
class VulkanDeviceBuilder
|
||||
{
|
||||
public:
|
||||
|
|
@ -211,8 +197,8 @@ enum class ShaderType
|
|||
class ShaderIncludeResult
|
||||
{
|
||||
public:
|
||||
ShaderIncludeResult(std::string name, std::string text) : name(std::move(name)), text(std::move(text)) { }
|
||||
ShaderIncludeResult(std::string error) : text(std::move(error)) { }
|
||||
ShaderIncludeResult(std::string name, std::string text) : name(std::move(name)), text(std::move(text)) {}
|
||||
ShaderIncludeResult(std::string error) : text(std::move(error)) {}
|
||||
|
||||
std::string name; // fully resolved name of the included header file
|
||||
std::string text; // the file contents - or include error message if name is empty
|
||||
|
|
@ -247,7 +233,7 @@ public:
|
|||
ShaderBuilder& Code(std::vector<uint32_t> spirv) { code = std::move(spirv); return *this; }
|
||||
ShaderBuilder& DebugName(const char* name) { debugName = name; return *this; }
|
||||
|
||||
std::unique_ptr<VulkanShader> Create(const char *shadername, VulkanDevice *device);
|
||||
std::unique_ptr<VulkanShader> Create(const char* shadername, VulkanDevice* device);
|
||||
|
||||
private:
|
||||
std::vector<uint32_t> code;
|
||||
|
|
@ -403,9 +389,14 @@ public:
|
|||
GraphicsPipelineBuilder& AddVertexShader(VulkanShader *shader);
|
||||
GraphicsPipelineBuilder& AddFragmentShader(VulkanShader *shader);
|
||||
|
||||
GraphicsPipelineBuilder& AddConstant(uint32_t constantID, const void* data, size_t size);
|
||||
GraphicsPipelineBuilder& AddConstant(uint32_t constantID, uint32_t value);
|
||||
GraphicsPipelineBuilder& AddConstant(uint32_t constantID, int32_t value);
|
||||
GraphicsPipelineBuilder& AddConstant(uint32_t constantID, float value);
|
||||
|
||||
GraphicsPipelineBuilder& AddVertexBufferBinding(int index, size_t stride);
|
||||
GraphicsPipelineBuilder& AddVertexAttribute(int location, int binding, VkFormat format, size_t offset);
|
||||
|
||||
|
||||
GraphicsPipelineBuilder& AddDynamicState(VkDynamicState state);
|
||||
|
||||
GraphicsPipelineBuilder& PolygonMode(VkPolygonMode mode) {rasterizer.polygonMode = mode; return *this;};
|
||||
|
|
@ -433,6 +424,15 @@ private:
|
|||
std::vector<VkVertexInputAttributeDescription> vertexInputAttributes;
|
||||
std::vector<VkDynamicState> dynamicStates;
|
||||
|
||||
struct ShaderSpecialization
|
||||
{
|
||||
VkSpecializationInfo info = {};
|
||||
std::vector<VkSpecializationMapEntry> entries;
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
|
||||
std::vector<std::unique_ptr<ShaderSpecialization>> specializations;
|
||||
|
||||
VulkanPipelineCache* cache = nullptr;
|
||||
const char* debugName = nullptr;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,12 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define VK_USE_PLATFORM_WIN32_KHR
|
||||
#elif defined(__APPLE__)
|
||||
#define VK_USE_PLATFORM_MACOS_MVK
|
||||
#define VK_USE_PLATFORM_METAL_EXT
|
||||
#endif
|
||||
|
||||
#include "vulkan.h"
|
||||
#include "volk/volk.h"
|
||||
#include "vk_mem_alloc/vk_mem_alloc.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,11 +10,4 @@ public:
|
|||
|
||||
std::shared_ptr<VulkanInstance> Instance;
|
||||
VkSurfaceKHR Surface = VK_NULL_HANDLE;
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
|
||||
VulkanSurface(std::shared_ptr<VulkanInstance> instance, HWND window);
|
||||
HWND Window = 0;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public:
|
|||
VulkanSwapChain(VulkanDevice* device);
|
||||
~VulkanSwapChain();
|
||||
|
||||
void Create(int width, int height, int imageCount, bool vsync, bool hdr, bool exclusivefullscreen);
|
||||
void Create(int width, int height, int imageCount, bool vsync, bool hdr);
|
||||
bool Lost() const { return lost; }
|
||||
|
||||
int Width() const { return actualExtent.width; }
|
||||
|
|
@ -42,9 +42,9 @@ public:
|
|||
private:
|
||||
void SelectFormat(const VulkanSurfaceCapabilities& caps, bool hdr);
|
||||
|
||||
bool CreateSwapchain(int width, int height, int imageCount, bool vsync, bool hdr, bool exclusivefullscreen);
|
||||
bool CreateSwapchain(int width, int height, int imageCount, bool vsync, bool hdr);
|
||||
|
||||
VulkanSurfaceCapabilities GetSurfaceCapabilities(bool exclusivefullscreen);
|
||||
VulkanSurfaceCapabilities GetSurfaceCapabilities();
|
||||
|
||||
VulkanDevice* device = nullptr;
|
||||
bool lost = true;
|
||||
|
|
@ -52,7 +52,7 @@ private:
|
|||
VkExtent2D actualExtent = {};
|
||||
VkSwapchainKHR swapchain = VK_NULL_HANDLE;
|
||||
VkSurfaceFormatKHR format = {};
|
||||
VkPresentModeKHR presentMode;
|
||||
VkPresentModeKHR presentMode = {};
|
||||
std::vector<std::unique_ptr<VulkanImage>> images;
|
||||
std::vector<std::unique_ptr<VulkanImageView>> views;
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ std::string to_string(const T& val) {
|
|||
#define UINT_PTR uintptr_t
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_MSC_VER) && !defined(strdup)
|
||||
#define strdup _strdup
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -7559,7 +7559,7 @@ static void ForEachOpaque(const TType& type, const TString& path, Function callb
|
|||
for (size_t dimIndex = 0; dimIndex < indices.size(); ++dimIndex)
|
||||
{
|
||||
++indices[dimIndex];
|
||||
if (indices[dimIndex] < type.getArraySizes()->getDimSize(dimIndex))
|
||||
if (indices[dimIndex] < (int)type.getArraySizes()->getDimSize((int)dimIndex))
|
||||
break;
|
||||
else
|
||||
indices[dimIndex] = 0;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ 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.
|
||||
**/
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include "../Public/resource_limits_c.h"
|
||||
#include "../Public/ResourceLimits.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -1177,7 +1177,7 @@ Id Builder::createDebugLocalVariable(Id type, char const*const name, size_t cons
|
|||
inst->addIdOperand(currentDebugScopeId.top()); // scope id
|
||||
inst->addIdOperand(makeUintConstant(NonSemanticShaderDebugInfo100FlagIsLocal)); // flags id
|
||||
if(argNumber != 0) {
|
||||
inst->addIdOperand(makeUintConstant(argNumber));
|
||||
inst->addIdOperand(makeUintConstant((unsigned int)argNumber));
|
||||
}
|
||||
|
||||
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(inst));
|
||||
|
|
|
|||
|
|
@ -1,17 +1,4 @@
|
|||
|
||||
#if defined(_WIN32)
|
||||
#define VK_USE_PLATFORM_WIN32_KHR
|
||||
#elif defined(__APPLE__)
|
||||
#define VK_USE_PLATFORM_MACOS_MVK
|
||||
#define VK_USE_PLATFORM_METAL_EXT
|
||||
#else
|
||||
#if defined(VULKAN_USE_XLIB)
|
||||
#define VK_USE_PLATFORM_XLIB_KHR
|
||||
#elif defined(VULKAN_USE_WAYLAND)
|
||||
#define VK_USE_PLATFORM_WAYLAND_KHR
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This file is part of volk library; see volk.h for version/license details */
|
||||
/* clang-format off */
|
||||
#include "volk/volk.h"
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ std::vector<uint32_t> GLSLCompiler::Compile(uint32_t apiVersion)
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::unique_ptr<VulkanShader> ShaderBuilder::Create(const char *shadername, VulkanDevice *device)
|
||||
std::unique_ptr<VulkanShader> ShaderBuilder::Create(const char* shadername, VulkanDevice* device)
|
||||
{
|
||||
VkShaderModuleCreateInfo createInfo = {};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
|
|
@ -1107,6 +1107,48 @@ GraphicsPipelineBuilder& GraphicsPipelineBuilder::AddFragmentShader(VulkanShader
|
|||
return *this;
|
||||
}
|
||||
|
||||
GraphicsPipelineBuilder& GraphicsPipelineBuilder::AddConstant(uint32_t constantID, const void* data, size_t size)
|
||||
{
|
||||
VkPipelineShaderStageCreateInfo& stage = shaderStages.back();
|
||||
if (!stage.pSpecializationInfo)
|
||||
{
|
||||
specializations.push_back(std::make_unique<ShaderSpecialization>());
|
||||
stage.pSpecializationInfo = &specializations.back()->info;
|
||||
}
|
||||
|
||||
ShaderSpecialization* s = specializations.back().get();
|
||||
|
||||
VkSpecializationMapEntry entry = {};
|
||||
entry.constantID = constantID;
|
||||
entry.offset = (uint32_t)s->data.size();
|
||||
entry.size = (uint32_t)size;
|
||||
|
||||
s->data.insert(s->data.end(), (uint8_t*)data, (uint8_t*)data + size);
|
||||
s->entries.push_back(entry);
|
||||
|
||||
s->info.mapEntryCount = (uint32_t)s->entries.size();
|
||||
s->info.dataSize = (uint32_t)s->data.size();
|
||||
s->info.pMapEntries = s->entries.data();
|
||||
s->info.pData = s->data.data();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
GraphicsPipelineBuilder& GraphicsPipelineBuilder::AddConstant(uint32_t constantID, uint32_t value)
|
||||
{
|
||||
return AddConstant(constantID, &value, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
GraphicsPipelineBuilder& GraphicsPipelineBuilder::AddConstant(uint32_t constantID, int32_t value)
|
||||
{
|
||||
return AddConstant(constantID, &value, sizeof(int32_t));
|
||||
}
|
||||
|
||||
GraphicsPipelineBuilder& GraphicsPipelineBuilder::AddConstant(uint32_t constantID, float value)
|
||||
{
|
||||
return AddConstant(constantID, &value, sizeof(float));
|
||||
}
|
||||
|
||||
GraphicsPipelineBuilder& GraphicsPipelineBuilder::AddVertexBufferBinding(int index, size_t stride)
|
||||
{
|
||||
VkVertexInputBindingDescription desc = {};
|
||||
|
|
@ -1616,22 +1658,30 @@ VulkanInstanceBuilder& VulkanInstanceBuilder::RequireExtension(const std::string
|
|||
return *this;
|
||||
}
|
||||
|
||||
VulkanInstanceBuilder& VulkanInstanceBuilder::RequireSurfaceExtensions(bool enable)
|
||||
VulkanInstanceBuilder& VulkanInstanceBuilder::RequireExtensions(const std::vector<std::string>& extensions)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
RequireExtension(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
for (const auto& ext : extensions)
|
||||
RequireExtension(ext);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||
RequireExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
|
||||
#elif defined(VK_USE_PLATFORM_MACOS_MVK)
|
||||
RequireExtension(VK_MVK_MACOS_SURFACE_EXTENSION_NAME);
|
||||
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
|
||||
RequireExtension(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
|
||||
#endif
|
||||
VulkanInstanceBuilder& VulkanInstanceBuilder::RequireExtensions(const std::vector<const char*>& extensions)
|
||||
{
|
||||
for (const auto& ext : extensions)
|
||||
RequireExtension(ext);
|
||||
return *this;
|
||||
}
|
||||
|
||||
OptionalExtension(VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME); // For HDR support
|
||||
}
|
||||
VulkanInstanceBuilder& VulkanInstanceBuilder::RequireExtensions(const char** extensions, size_t count)
|
||||
{
|
||||
for (size_t i = 0; i < count; i++)
|
||||
RequireExtension(extensions[i]);
|
||||
return *this;
|
||||
}
|
||||
|
||||
VulkanInstanceBuilder& VulkanInstanceBuilder::OptionalSwapchainColorspace()
|
||||
{
|
||||
OptionalExtension(VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME); // For HDR support
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -1654,27 +1704,6 @@ std::shared_ptr<VulkanInstance> VulkanInstanceBuilder::Create()
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
|
||||
VulkanSurfaceBuilder::VulkanSurfaceBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
VulkanSurfaceBuilder& VulkanSurfaceBuilder::Win32Window(HWND hwnd)
|
||||
{
|
||||
this->hwnd = hwnd;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::shared_ptr<VulkanSurface> VulkanSurfaceBuilder::Create(std::shared_ptr<VulkanInstance> instance)
|
||||
{
|
||||
return std::make_shared<VulkanSurface>(std::move(instance), hwnd);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef VK_KHR_MAINTENANCE4_EXTENSION_NAME
|
||||
#define VK_KHR_MAINTENANCE4_EXTENSION_NAME "VK_KHR_maintenance4"
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,18 +10,3 @@ VulkanSurface::~VulkanSurface()
|
|||
{
|
||||
vkDestroySurfaceKHR(Instance->Instance, Surface, nullptr);
|
||||
}
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
|
||||
VulkanSurface::VulkanSurface(std::shared_ptr<VulkanInstance> instance, HWND window) : Instance(std::move(instance)), Window(window)
|
||||
{
|
||||
VkWin32SurfaceCreateInfoKHR createInfo = { VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR };
|
||||
createInfo.hwnd = window;
|
||||
createInfo.hinstance = GetModuleHandle(nullptr);
|
||||
|
||||
VkResult result = vkCreateWin32SurfaceKHR(Instance->Instance, &createInfo, nullptr, &Surface);
|
||||
if (result != VK_SUCCESS)
|
||||
VulkanError("Could not create vulkan surface");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,6 +4,18 @@
|
|||
#include "vulkansurface.h"
|
||||
#include "vulkanbuilders.h"
|
||||
|
||||
#if defined(WIN32)
|
||||
#define NOMINMAX
|
||||
#define WIN32_MEAN_AND_LEAN
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(WIN32)
|
||||
#define NOMINMAX
|
||||
#define WIN32_MEAN_AND_LEAN
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
VulkanSwapChain::VulkanSwapChain(VulkanDevice* device) : device(device)
|
||||
{
|
||||
}
|
||||
|
|
@ -16,18 +28,12 @@ VulkanSwapChain::~VulkanSwapChain()
|
|||
vkDestroySwapchainKHR(device->device, swapchain, nullptr);
|
||||
}
|
||||
|
||||
void VulkanSwapChain::Create(int width, int height, int imageCount, bool vsync, bool hdr, bool exclusivefullscreen)
|
||||
void VulkanSwapChain::Create(int width, int height, int imageCount, bool vsync, bool hdr)
|
||||
{
|
||||
views.clear();
|
||||
images.clear();
|
||||
|
||||
CreateSwapchain(width, height, imageCount, vsync, hdr, exclusivefullscreen);
|
||||
|
||||
if (exclusivefullscreen && lost)
|
||||
{
|
||||
// We could not acquire exclusive fullscreen. Fall back to normal fullsceen instead.
|
||||
CreateSwapchain(width, height, imageCount, vsync, hdr, false);
|
||||
}
|
||||
CreateSwapchain(width, height, imageCount, vsync, hdr);
|
||||
|
||||
if (swapchain)
|
||||
{
|
||||
|
|
@ -89,18 +95,11 @@ void VulkanSwapChain::SelectFormat(const VulkanSurfaceCapabilities& caps, bool h
|
|||
format = caps.Formats.front();
|
||||
}
|
||||
|
||||
bool VulkanSwapChain::CreateSwapchain(int width, int height, int imageCount, bool vsync, bool hdr, bool exclusivefullscreen)
|
||||
bool VulkanSwapChain::CreateSwapchain(int width, int height, int imageCount, bool vsync, bool hdr)
|
||||
{
|
||||
lost = false;
|
||||
|
||||
VulkanSurfaceCapabilities caps = GetSurfaceCapabilities(exclusivefullscreen);
|
||||
|
||||
if (exclusivefullscreen && (caps.PresentModes.empty() || !caps.FullScreenExclusive.fullScreenExclusiveSupported))
|
||||
{
|
||||
// Try again without exclusive full screen.
|
||||
exclusivefullscreen = false;
|
||||
caps = GetSurfaceCapabilities(exclusivefullscreen);
|
||||
}
|
||||
VulkanSurfaceCapabilities caps = GetSurfaceCapabilities();
|
||||
|
||||
if (caps.PresentModes.empty())
|
||||
VulkanError("No surface present modes supported");
|
||||
|
|
@ -117,20 +116,10 @@ bool VulkanSwapChain::CreateSwapchain(int width, int height, int imageCount, boo
|
|||
}
|
||||
else
|
||||
{
|
||||
if (exclusivefullscreen) // Exclusive full screen doesn't seem to support mailbox for some reason, even if it is advertised
|
||||
{
|
||||
if (supportsImmediate)
|
||||
presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||
else if (supportsMailbox)
|
||||
presentMode = VK_PRESENT_MODE_MAILBOX_KHR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*if (supportsMailbox)
|
||||
presentMode = VK_PRESENT_MODE_MAILBOX_KHR;
|
||||
else*/ if (supportsImmediate)
|
||||
presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||
}
|
||||
/*if (supportsMailbox)
|
||||
presentMode = VK_PRESENT_MODE_MAILBOX_KHR;
|
||||
else*/ if (supportsImmediate)
|
||||
presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||
}
|
||||
|
||||
SelectFormat(caps, hdr);
|
||||
|
|
@ -185,16 +174,6 @@ bool VulkanSwapChain::CreateSwapchain(int width, int height, int imageCount, boo
|
|||
swapChainCreateInfo.clipped = VK_TRUE; // Applications SHOULD set this value to VK_TRUE if they do not expect to read back the content of presentable images before presenting them or after reacquiring them, and if their fragment shaders do not have any side effects that require them to run for all pixels in the presentable image
|
||||
swapChainCreateInfo.oldSwapchain = swapchain;
|
||||
|
||||
#ifdef WIN32
|
||||
if (exclusivefullscreen)
|
||||
{
|
||||
swapChainCreateInfo.pNext = &exclusiveInfo;
|
||||
exclusiveInfo.pNext = &exclusiveWin32Info;
|
||||
exclusiveInfo.fullScreenExclusive = VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT;
|
||||
exclusiveWin32Info.hmonitor = MonitorFromWindow(device->Surface->Window, MONITOR_DEFAULTTONEAREST);
|
||||
}
|
||||
#endif
|
||||
|
||||
VkResult result = vkCreateSwapchainKHR(device->device, &swapChainCreateInfo, nullptr, &swapchain);
|
||||
|
||||
if (swapChainCreateInfo.oldSwapchain)
|
||||
|
|
@ -207,17 +186,6 @@ bool VulkanSwapChain::CreateSwapchain(int width, int height, int imageCount, boo
|
|||
return false;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
if (exclusivefullscreen)
|
||||
{
|
||||
result = vkAcquireFullScreenExclusiveModeEXT(device->device, swapchain);
|
||||
if (result != VK_SUCCESS)
|
||||
{
|
||||
lost = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -285,7 +253,7 @@ void VulkanSwapChain::QueuePresent(int imageIndex, VulkanSemaphore* semaphore)
|
|||
}
|
||||
}
|
||||
|
||||
VulkanSurfaceCapabilities VulkanSwapChain::GetSurfaceCapabilities(bool exclusivefullscreen)
|
||||
VulkanSurfaceCapabilities VulkanSwapChain::GetSurfaceCapabilities()
|
||||
{
|
||||
// They sure made it easy to query something that isn't even time critical. Good job guys!
|
||||
|
||||
|
|
@ -297,42 +265,15 @@ VulkanSurfaceCapabilities VulkanSwapChain::GetSurfaceCapabilities(bool exclusive
|
|||
VkSurfaceFullScreenExclusiveWin32InfoEXT exclusiveWin32Info = { VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_WIN32_INFO_EXT };
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
if (exclusivefullscreen)
|
||||
{
|
||||
exclusiveInfo.fullScreenExclusive = VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT;
|
||||
exclusiveWin32Info.hmonitor = MonitorFromWindow(device->Surface->Window, MONITOR_DEFAULTTONEAREST);
|
||||
}
|
||||
#endif
|
||||
|
||||
surfaceInfo.surface = device->Surface->Surface;
|
||||
|
||||
if (device->SupportsExtension(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME))
|
||||
{
|
||||
const void** next = &surfaceInfo.pNext;
|
||||
|
||||
#ifdef WIN32
|
||||
if (exclusivefullscreen && device->SupportsExtension(VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME))
|
||||
{
|
||||
*next = &exclusiveInfo;
|
||||
next = const_cast<const void**>(&exclusiveInfo.pNext);
|
||||
|
||||
*next = &exclusiveWin32Info;
|
||||
next = &exclusiveWin32Info.pNext;
|
||||
}
|
||||
#endif
|
||||
|
||||
VkSurfaceCapabilities2KHR caps2 = { VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR };
|
||||
next = const_cast<const void**>(&caps2.pNext);
|
||||
|
||||
#ifdef WIN32
|
||||
if (exclusivefullscreen && device->SupportsExtension(VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME))
|
||||
{
|
||||
*next = &caps.FullScreenExclusive;
|
||||
next = const_cast<const void**>(&caps.FullScreenExclusive.pNext);
|
||||
}
|
||||
#endif
|
||||
|
||||
VkResult result = vkGetPhysicalDeviceSurfaceCapabilities2KHR(device->PhysicalDevice.Device, &surfaceInfo, &caps2);
|
||||
if (result != VK_SUCCESS)
|
||||
VulkanError("vkGetPhysicalDeviceSurfaceCapabilities2KHR failed");
|
||||
|
|
@ -346,39 +287,17 @@ VulkanSurfaceCapabilities VulkanSwapChain::GetSurfaceCapabilities(bool exclusive
|
|||
VulkanError("vkGetPhysicalDeviceSurfaceCapabilitiesKHR failed");
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
if (exclusivefullscreen && device->SupportsExtension(VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME))
|
||||
{
|
||||
const void** next = &surfaceInfo.pNext;
|
||||
uint32_t presentModeCount = 0;
|
||||
VkResult result = vkGetPhysicalDeviceSurfacePresentModesKHR(device->PhysicalDevice.Device, device->Surface->Surface, &presentModeCount, nullptr);
|
||||
if (result != VK_SUCCESS)
|
||||
VulkanError("vkGetPhysicalDeviceSurfacePresentModesKHR failed");
|
||||
|
||||
uint32_t presentModeCount = 0;
|
||||
VkResult result = vkGetPhysicalDeviceSurfacePresentModes2EXT(device->PhysicalDevice.Device, &surfaceInfo, &presentModeCount, nullptr);
|
||||
if (result != VK_SUCCESS)
|
||||
VulkanError("vkGetPhysicalDeviceSurfacePresentModes2EXT failed");
|
||||
|
||||
if (presentModeCount > 0)
|
||||
{
|
||||
caps.PresentModes.resize(presentModeCount);
|
||||
result = vkGetPhysicalDeviceSurfacePresentModes2EXT(device->PhysicalDevice.Device, &surfaceInfo, &presentModeCount, caps.PresentModes.data());
|
||||
if (result != VK_SUCCESS)
|
||||
VulkanError("vkGetPhysicalDeviceSurfacePresentModes2EXT failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (presentModeCount > 0)
|
||||
{
|
||||
uint32_t presentModeCount = 0;
|
||||
VkResult result = vkGetPhysicalDeviceSurfacePresentModesKHR(device->PhysicalDevice.Device, device->Surface->Surface, &presentModeCount, nullptr);
|
||||
caps.PresentModes.resize(presentModeCount);
|
||||
result = vkGetPhysicalDeviceSurfacePresentModesKHR(device->PhysicalDevice.Device, device->Surface->Surface, &presentModeCount, caps.PresentModes.data());
|
||||
if (result != VK_SUCCESS)
|
||||
VulkanError("vkGetPhysicalDeviceSurfacePresentModesKHR failed");
|
||||
|
||||
if (presentModeCount > 0)
|
||||
{
|
||||
caps.PresentModes.resize(presentModeCount);
|
||||
result = vkGetPhysicalDeviceSurfacePresentModesKHR(device->PhysicalDevice.Device, device->Surface->Surface, &presentModeCount, caps.PresentModes.data());
|
||||
if (result != VK_SUCCESS)
|
||||
VulkanError("vkGetPhysicalDeviceSurfacePresentModesKHR failed");
|
||||
}
|
||||
}
|
||||
|
||||
if (device->SupportsExtension(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME))
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@
|
|||
#include "vk_framebuffer.h"
|
||||
|
||||
CVAR(Bool, vk_hdr, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
|
||||
CVAR(Bool, vk_exclusivefullscreen, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
|
||||
|
||||
VkFramebufferManager::VkFramebufferManager(VulkanRenderDevice* fb) : fb(fb)
|
||||
{
|
||||
|
|
@ -57,8 +56,7 @@ void VkFramebufferManager::AcquireImage()
|
|||
if (!SwapChain)
|
||||
return;
|
||||
|
||||
bool exclusiveFullscreen = fb->IsFullscreen() && vk_exclusivefullscreen;
|
||||
if (SwapChain->Lost() || fb->GetClientWidth() != CurrentWidth || fb->GetClientHeight() != CurrentHeight || fb->GetVSync() != CurrentVSync || CurrentHdr != vk_hdr || CurrentExclusiveFullscreen != exclusiveFullscreen)
|
||||
if (SwapChain->Lost() || fb->GetClientWidth() != CurrentWidth || fb->GetClientHeight() != CurrentHeight || fb->GetVSync() != CurrentVSync || CurrentHdr != vk_hdr)
|
||||
{
|
||||
Framebuffers.clear();
|
||||
|
||||
|
|
@ -66,9 +64,8 @@ void VkFramebufferManager::AcquireImage()
|
|||
CurrentHeight = fb->GetClientHeight();
|
||||
CurrentVSync = fb->GetVSync();
|
||||
CurrentHdr = vk_hdr;
|
||||
CurrentExclusiveFullscreen = exclusiveFullscreen;
|
||||
|
||||
SwapChain->Create(CurrentWidth, CurrentHeight, CurrentVSync ? 2 : 3, CurrentVSync, CurrentHdr, CurrentExclusiveFullscreen);
|
||||
SwapChain->Create(CurrentWidth, CurrentHeight, CurrentVSync ? 2 : 3, CurrentVSync, CurrentHdr);
|
||||
}
|
||||
|
||||
PresentImageIndex = SwapChain->AcquireImage(SwapChainImageAvailableSemaphore.get());
|
||||
|
|
|
|||
|
|
@ -32,5 +32,4 @@ private:
|
|||
int CurrentHeight = 0;
|
||||
bool CurrentVSync = false;
|
||||
bool CurrentHdr = false;
|
||||
bool CurrentExclusiveFullscreen = false;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue