From b0fb00c54f6fc5f99a0ff968ffe507ad80f72fa8 Mon Sep 17 00:00:00 2001 From: niki Date: Tue, 20 Sep 2022 14:49:56 +0200 Subject: [PATCH] vulkan: fix crashes in isPixelFormatSupported and setStencilMode --- src/modules/graphics/vulkan/Graphics.cpp | 7 ++++++- src/modules/graphics/vulkan/Vulkan.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index c5a5e6e5f..c000e09ff 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -869,7 +869,7 @@ void Graphics::setStencilMode(StencilAction action, CompareMode compare, int val if (!isRenderTargetActive() && !windowHasStencil) throw love::Exception("The window must have stenciling enabled to draw to the main screen's stencil buffer"); - if (isRenderTargetActive() && (rts.temporaryRTFlags & TEMPORARY_RT_STENCIL) == 0 && dsTexture == nullptr || !isPixelFormatStencil(dsTexture->getPixelFormat())) + else if (isRenderTargetActive() && (rts.temporaryRTFlags & TEMPORARY_RT_STENCIL) == 0 && (dsTexture == nullptr || !isPixelFormatStencil(dsTexture->getPixelFormat()))) throw love::Exception("drawing to the stencil buffer with a render target active requires either stencil=true or a custom stencil-type to be used, in setRenderTarget"); } @@ -942,6 +942,11 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRG { (void)sRGB; // fixme: sRGB + bool rendertarget = (usage & PIXELFORMATUSAGEFLAGS_RENDERTARGET) != 0; + bool readable = (usage & PIXELFORMATUSAGEFLAGS_SAMPLE) != 0; + + format = getSizedFormat(format, rendertarget, readable); + auto vulkanFormat = Vulkan::getTextureFormat(format); VkFormatProperties formatProperties; diff --git a/src/modules/graphics/vulkan/Vulkan.cpp b/src/modules/graphics/vulkan/Vulkan.cpp index 19924284f..6660d5f02 100644 --- a/src/modules/graphics/vulkan/Vulkan.cpp +++ b/src/modules/graphics/vulkan/Vulkan.cpp @@ -306,8 +306,11 @@ TextureFormat Vulkan::getTextureFormat(PixelFormat format) textureFormat.internalFormat = VK_FORMAT_R5G6B5_UNORM_PACK16; break; case PIXELFORMAT_RGB10A2_UNORM: // LSB->MSB: [r: g: b: a] + textureFormat.internalFormat = VK_FORMAT_A2R10G10B10_UNORM_PACK32; + break; case PIXELFORMAT_RG11B10_FLOAT: // LSB->MSB: [r: g: b] - throw love::Exception("unimplemented pixel format (rgb10a2, rg11b10)"); + textureFormat.internalFormat = VK_FORMAT_B10G11R11_UFLOAT_PACK32; + break; case PIXELFORMAT_STENCIL8: textureFormat.internalFormat = VK_FORMAT_S8_UINT; textureFormat.internalFormatRepresentation = FORMATREPRESENTATION_UINT; @@ -370,7 +373,8 @@ TextureFormat Vulkan::getTextureFormat(PixelFormat format) textureFormat.internalFormat = VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG; break; case PIXELFORMAT_ETC1_UNORM: - throw love::Exception("unimplemented pixel format: etc1"); + textureFormat.internalFormat = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; + break; case PIXELFORMAT_ETC2_RGB_UNORM: textureFormat.internalFormat = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; break;