Commit 27a3d31d by Jonah Ryan-Davis

Fix issues presenting MetalSurfaces

MetalSurfaceEXT and MacOSSurfaceMVK were inheriting incorrectly from the base class MetalSurface, and were improperly initialized. Additionally, none of the drawables were ever released, meaning there were no re-used drawables. Add an @autoreleasepool around the drawable retrival path, as per the spec: https://developer.apple.com/documentation/quartzcore/cametallayer?language=objc#3172024 Bug: chromium:1015454 Change-Id: Idd2f1842977a6f5dccecf31d152d454a44e9261c Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/37948Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarJonah Ryan-Davis <jonahr@google.com>
parent 88264e3e
......@@ -61,4 +61,6 @@ swiftshader_source_set("WSI") {
"../../third_party/marl:Marl_headers",
"../Vulkan:swiftshader_libvulkan_headers",
]
configs = [ "../Vulkan:swiftshader_libvulkan_private_config", ]
}
......@@ -28,7 +28,7 @@ namespace vk {
class MetalLayer;
class MetalSurface : public SurfaceKHR, public ObjectBase<MetalSurface, VkSurfaceKHR> {
class MetalSurface : public SurfaceKHR {
public:
MetalSurface(const void *pCreateInfo, void *mem);
......@@ -47,13 +47,15 @@ protected:
};
#ifdef VK_USE_PLATFORM_METAL_EXT
class MetalSurfaceEXT : public MetalSurface {
class MetalSurfaceEXT : public MetalSurface, public ObjectBase<MetalSurfaceEXT, VkSurfaceKHR> {
public:
MetalSurfaceEXT(const VkMetalSurfaceCreateInfoEXT *pCreateInfo, void *mem);
};
#endif
#ifdef VK_USE_PLATFORM_MACOS_MVK
class MacOSSurfaceMVK : public MetalSurface {
class MacOSSurfaceMVK : public MetalSurface, public ObjectBase<MacOSSurfaceMVK, VkSurfaceKHR> {
public:
MacOSSurfaceMVK(const VkMacOSSurfaceCreateInfoMVK *pCreateInfo, void *mem);
};
#endif
......
......@@ -139,15 +139,19 @@ void MetalSurface::getSurfaceCapabilities(VkSurfaceCapabilitiesKHR *pSurfaceCapa
VkResult MetalSurface::present(PresentImage* image) API_AVAILABLE(macosx(10.11))
{
auto drawable = metalLayer->getNextDrawable();
if(drawable)
@autoreleasepool
{
VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
[drawable.texture replaceRegion:MTLRegionMake2D(0, 0, extent.width, extent.height)
mipmapLevel:0
withBytes:image->getImageMemory()->getOffsetPointer(0)
bytesPerRow:image->getImage()->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0)];
[drawable present];
auto drawable = metalLayer->getNextDrawable();
if(drawable)
{
VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
[drawable.texture replaceRegion:MTLRegionMake2D(0, 0, extent.width, extent.height)
mipmapLevel:0
withBytes:image->getImageMemory()->getOffsetPointer(0)
bytesPerRow:image->getImage()->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0)];
[drawable present];
}
}
return VK_SUCCESS;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment