Update to latest zvulkan
This commit is contained in:
parent
4e78ba469c
commit
5e22b07db2
16 changed files with 260 additions and 219 deletions
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue