Skip to content
Permalink
Browse files

- set default magnification filter for Metal layer to nearest

Magnification filter is applied to swapchain image when it's copied to a physical display surface
This is needed for gfx-portability because MoltenVK uses nearest sampling by default
  • Loading branch information...
alexey-lysiuk committed Aug 4, 2019
1 parent 3c0ff17 commit d9dcc26dc6a247764ce3db39ff7bd49619669e15
Showing with 18 additions and 3 deletions.
  1. +7 −1 src/CMakeLists.txt
  2. +11 −2 src/posix/cocoa/i_video.mm
@@ -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()
@@ -925,14 +925,23 @@ 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*>(CocoaVideo::GetWindow().contentView.layer);
surfaceCreateInfo.pLayer = static_cast<CAMetalLayer*>(layer);

const VkResult result = vkCreateMetalSurfaceEXT(instance, &surfaceCreateInfo, nullptr, surface);
return result == VK_SUCCESS;
@@ -943,7 +952,7 @@ bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface)
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;

0 comments on commit d9dcc26

Please sign in to comment.
You can’t perform that action at this time.