Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/coelckers/gzdoom
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Aug 5, 2019
2 parents a053149 + d9dcc26 commit be04789
Show file tree
Hide file tree
Showing 22 changed files with 2,730 additions and 342 deletions.
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Expand Up @@ -1482,8 +1482,14 @@ if( ZD_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE )
endif()

if( APPLE )
set( LINK_FRAMEWORKS "-framework Cocoa -framework IOKit -framework OpenGL")

if( HAVE_VULKAN )
set( LINK_FRAMEWORKS "${LINK_FRAMEWORKS} -framework QuartzCore" )
endif()

set_target_properties(zdoom PROPERTIES
LINK_FLAGS "-framework Cocoa -framework IOKit -framework OpenGL"
LINK_FLAGS "${LINK_FRAMEWORKS}"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/posix/osx/zdoom-info.plist" )

# Dymanic libraries like libvulkan.dylib or libMoltenVK.dylib will be loaded by dlopen()
Expand Down
5 changes: 4 additions & 1 deletion src/gamedata/fonts/specialfont.cpp
Expand Up @@ -102,7 +102,10 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **l

if (charlumps[i] != nullptr)
{
charlumps[i]->SetUseType(ETextureType::FontChar);
// If texture is used as a sprite, do not set use type
// Changing it would break actors that use this sprite
if (charlumps[i]->GetUseType() != ETextureType::Sprite)
charlumps[i]->SetUseType(ETextureType::FontChar);

Chars[i].OriginalPic = charlumps[i];
if (!noTranslate)
Expand Down
61 changes: 55 additions & 6 deletions src/posix/cocoa/i_video.mm
Expand Up @@ -35,6 +35,7 @@

#ifdef HAVE_VULKAN
#define VK_USE_PLATFORM_MACOS_MVK
#define VK_USE_PLATFORM_METAL_EXT
#include "volk/volk.h"
#endif

Expand Down Expand Up @@ -867,12 +868,37 @@ void I_GetVulkanDrawableSize(int *width, int *height)

bool I_GetVulkanPlatformExtensions(unsigned int *count, const char **names)
{
static const char* extensions[] =
static std::vector<const char*> extensions;

if (extensions.empty())
{
VK_KHR_SURFACE_EXTENSION_NAME,
VK_MVK_MACOS_SURFACE_EXTENSION_NAME
};
static const unsigned int extensionCount = static_cast<unsigned int>(sizeof extensions / sizeof extensions[0]);
uint32_t extensionPropertyCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &extensionPropertyCount, nullptr);

std::vector<VkExtensionProperties> extensionProperties(extensionPropertyCount);
vkEnumerateInstanceExtensionProperties(nullptr, &extensionPropertyCount, extensionProperties.data());

static const char* const EXTENSION_NAMES[] =
{
VK_KHR_SURFACE_EXTENSION_NAME, // KHR_surface, required
VK_EXT_METAL_SURFACE_EXTENSION_NAME, // EXT_metal_surface, optional, preferred
VK_MVK_MACOS_SURFACE_EXTENSION_NAME, // MVK_macos_surface, optional, deprecated
};

for (const VkExtensionProperties &currentProperties : extensionProperties)
{
for (const char *const extensionName : EXTENSION_NAMES)
{
if (strcmp(currentProperties.extensionName, extensionName) == 0)
{
extensions.push_back(extensionName);
}
}
}
}

static const unsigned int extensionCount = static_cast<unsigned int>(extensions.size());
assert(extensionCount >= 2); // KHR_surface + at least one of the platform surface extentions

if (count == nullptr && names == nullptr)
{
Expand All @@ -899,11 +925,34 @@ bool I_GetVulkanPlatformExtensions(unsigned int *count, const char **names)

bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface)
{
NSView *const view = CocoaVideo::GetWindow().contentView;
CALayer *const layer = view.layer;

// Set magnification filter for swapchain image when it's copied to a physical display surface
// This is needed for gfx-portability because MoltenVK uses preferred nearest sampling by default
const char *const magFilterEnv = getenv("MVK_CONFIG_SWAPCHAIN_MAG_FILTER_USE_NEAREST");
const bool useNearestFilter = magFilterEnv == nullptr || strtol(magFilterEnv, nullptr, 0) != 0;
layer.magnificationFilter = useNearestFilter ? kCAFilterNearest : kCAFilterLinear;

if (vkCreateMetalSurfaceEXT)
{
// Preferred surface creation path
VkMetalSurfaceCreateInfoEXT surfaceCreateInfo;
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
surfaceCreateInfo.pNext = nullptr;
surfaceCreateInfo.flags = 0;
surfaceCreateInfo.pLayer = static_cast<CAMetalLayer*>(layer);

const VkResult result = vkCreateMetalSurfaceEXT(instance, &surfaceCreateInfo, nullptr, surface);
return result == VK_SUCCESS;
}

// Deprecated surface creation path
VkMacOSSurfaceCreateInfoMVK windowCreateInfo;
windowCreateInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
windowCreateInfo.pNext = nullptr;
windowCreateInfo.flags = 0;
windowCreateInfo.pView = [CocoaVideo::GetWindow() contentView];
windowCreateInfo.pView = view;

const VkResult result = vkCreateMacOSSurfaceMVK(instance, &windowCreateInfo, nullptr, surface);
return result == VK_SUCCESS;
Expand Down
12 changes: 2 additions & 10 deletions src/rendering/vulkan/system/vk_swapchain.cpp
Expand Up @@ -44,7 +44,7 @@ uint32_t VulkanSwapChain::AcquireImage(int width, int height, VulkanSemaphore *s
{
break;
}
else if (result == VK_SUBOPTIMAL_KHR)
else if (result == VK_SUBOPTIMAL_KHR || result == VK_ERROR_SURFACE_LOST_KHR)
{
// Force the recreate to happen next frame.
// The spec is not very clear about what happens to the semaphore or the acquired image if the swapchain is recreated before the image is released with a call to vkQueuePresentKHR.
Expand All @@ -69,10 +69,6 @@ uint32_t VulkanSwapChain::AcquireImage(int width, int height, VulkanSemaphore *s
{
VulkanError("vkAcquireNextImageKHR failed: device lost");
}
else if (result == VK_ERROR_SURFACE_LOST_KHR)
{
VulkanError("vkAcquireNextImageKHR failed: surface lost");
}
else
{
VulkanError("vkAcquireNextImageKHR failed");
Expand All @@ -92,7 +88,7 @@ void VulkanSwapChain::QueuePresent(uint32_t imageIndex, VulkanSemaphore *semapho
presentInfo.pImageIndices = &imageIndex;
presentInfo.pResults = nullptr;
VkResult result = vkQueuePresentKHR(device->presentQueue, &presentInfo);
if (result == VK_SUBOPTIMAL_KHR || result == VK_ERROR_OUT_OF_DATE_KHR)
if (result == VK_SUBOPTIMAL_KHR || result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_ERROR_SURFACE_LOST_KHR)
{
lastSwapWidth = 0;
lastSwapHeight = 0;
Expand All @@ -108,10 +104,6 @@ void VulkanSwapChain::QueuePresent(uint32_t imageIndex, VulkanSemaphore *semapho
{
VulkanError("vkQueuePresentKHR failed: device lost");
}
else if (result == VK_ERROR_SURFACE_LOST_KHR)
{
VulkanError("vkQueuePresentKHR failed: surface lost");
}
else if (result != VK_SUCCESS)
{
VulkanError("vkQueuePresentKHR failed");
Expand Down
1 change: 1 addition & 0 deletions src/rendering/vulkan/thirdparty/volk/volk.c
Expand Up @@ -4,6 +4,7 @@

#ifdef __APPLE__
#define VK_USE_PLATFORM_MACOS_MVK
#define VK_USE_PLATFORM_METAL_EXT
#endif


Expand Down
7 changes: 6 additions & 1 deletion src/rendering/vulkan/thirdparty/vulkan/vk_icd.h
Expand Up @@ -88,7 +88,8 @@ typedef enum {
VK_ICD_WSI_PLATFORM_ANDROID,
VK_ICD_WSI_PLATFORM_MACOS,
VK_ICD_WSI_PLATFORM_IOS,
VK_ICD_WSI_PLATFORM_DISPLAY
VK_ICD_WSI_PLATFORM_DISPLAY,
VK_ICD_WSI_PLATFORM_HEADLESS
} VkIcdWsiPlatform;

typedef struct {
Expand Down Expand Up @@ -167,4 +168,8 @@ typedef struct {
VkExtent2D imageExtent;
} VkIcdSurfaceDisplay;

typedef struct {
VkIcdSurfaceBase base;
} VkIcdSurfaceHeadless;

#endif // VKICD_H
17 changes: 12 additions & 5 deletions src/rendering/vulkan/thirdparty/vulkan/vk_layer.h
Expand Up @@ -35,9 +35,6 @@
#define VK_LAYER_EXPORT
#endif

// Definition for VkLayerDispatchTable and VkLayerInstanceDispatchTable now appear in externally generated header
#include "vk_layer_dispatch_table.h"

#define MAX_NUM_UNKNOWN_EXTS 250

// Loader-Layer version negotiation API. Versions add the following features:
Expand All @@ -50,6 +47,9 @@

#define VK_CURRENT_CHAIN_VERSION 1

// Typedef for use in the interfaces below
typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName);

// Version negotiation values
typedef enum VkNegotiateLayerStructType {
LAYER_NEGOTIATE_UNINTIALIZED = 0,
Expand Down Expand Up @@ -82,7 +82,8 @@ typedef VkResult(VKAPI_PTR *PFN_PhysDevExt)(VkPhysicalDevice phys_device);
*/
typedef enum VkLayerFunction_ {
VK_LAYER_LINK_INFO = 0,
VK_LOADER_DATA_CALLBACK = 1
VK_LOADER_DATA_CALLBACK = 1,
VK_LOADER_LAYER_CREATE_DEVICE_CALLBACK = 2
} VkLayerFunction;

typedef struct VkLayerInstanceLink_ {
Expand All @@ -107,14 +108,20 @@ typedef VkResult (VKAPI_PTR *PFN_vkSetInstanceLoaderData)(VkInstance instance,
void *object);
typedef VkResult (VKAPI_PTR *PFN_vkSetDeviceLoaderData)(VkDevice device,
void *object);

typedef VkResult (VKAPI_PTR *PFN_vkLayerCreateDevice)(VkInstance instance, VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, PFN_vkGetInstanceProcAddr layerGIPA, PFN_vkGetDeviceProcAddr *nextGDPA);
typedef void (VKAPI_PTR *PFN_vkLayerDestroyDevice)(VkDevice physicalDevice, const VkAllocationCallbacks *pAllocator, PFN_vkDestroyDevice destroyFunction);
typedef struct {
VkStructureType sType; // VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO
const void *pNext;
VkLayerFunction function;
union {
VkLayerInstanceLink *pLayerInfo;
PFN_vkSetInstanceLoaderData pfnSetInstanceLoaderData;
struct {
PFN_vkLayerCreateDevice pfnLayerCreateDevice;
PFN_vkLayerDestroyDevice pfnLayerDestroyDevice;
} layerDevice;
} u;
} VkLayerInstanceCreateInfo;

Expand Down
19 changes: 13 additions & 6 deletions src/rendering/vulkan/thirdparty/vulkan/vulkan.h
Expand Up @@ -2,7 +2,7 @@
#define VULKAN_H_ 1

/*
** Copyright (c) 2015-2018 The Khronos Group Inc.
** Copyright (c) 2015-2019 The Khronos Group Inc.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,10 @@
#include "vulkan_android.h"
#endif

#ifdef VK_USE_PLATFORM_FUCHSIA
#include <zircon/types.h>
#include "vulkan_fuchsia.h"
#endif

#ifdef VK_USE_PLATFORM_IOS_MVK
#include "vulkan_ios.h"
Expand All @@ -34,13 +38,10 @@
#include "vulkan_macos.h"
#endif


#ifdef VK_USE_PLATFORM_MIR_KHR
#include <mir_toolkit/client_types.h>
#include "vulkan_mir.h"
#ifdef VK_USE_PLATFORM_METAL_EXT
#include "vulkan_metal.h"
#endif


#ifdef VK_USE_PLATFORM_VI_NN
#include "vulkan_vi.h"
#endif
Expand Down Expand Up @@ -76,4 +77,10 @@
#include "vulkan_xlib_xrandr.h"
#endif


#ifdef VK_USE_PLATFORM_GGP
#include <ggp_c/vulkan_types.h>
#include "vulkan_ggp.h"
#endif

#endif // VULKAN_H_

0 comments on commit be04789

Please sign in to comment.