Browse Source

Merge pull request #1847 from nikeinikei/12.0-development

vulkan: fix crashes
slime73 2 years ago
parent
commit
a46d44500e

+ 6 - 1
src/modules/graphics/vulkan/Graphics.cpp

@@ -869,7 +869,7 @@ void Graphics::setStencilMode(StencilAction action, CompareMode compare, int val
 
 
 		if (!isRenderTargetActive() && !windowHasStencil)
 		if (!isRenderTargetActive() && !windowHasStencil)
 			throw love::Exception("The window must have stenciling enabled to draw to the main screen's stencil buffer");
 			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");
 			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
 	(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);
 	auto vulkanFormat = Vulkan::getTextureFormat(format);
 
 
 	VkFormatProperties formatProperties;
 	VkFormatProperties formatProperties;

+ 6 - 2
src/modules/graphics/vulkan/Vulkan.cpp

@@ -306,8 +306,11 @@ TextureFormat Vulkan::getTextureFormat(PixelFormat format)
 		textureFormat.internalFormat = VK_FORMAT_R5G6B5_UNORM_PACK16;
 		textureFormat.internalFormat = VK_FORMAT_R5G6B5_UNORM_PACK16;
 		break;
 		break;
 	case PIXELFORMAT_RGB10A2_UNORM:  // LSB->MSB: [r: g: b: a]
 	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]
 	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:
 	case PIXELFORMAT_STENCIL8:
 		textureFormat.internalFormat = VK_FORMAT_S8_UINT;
 		textureFormat.internalFormat = VK_FORMAT_S8_UINT;
 		textureFormat.internalFormatRepresentation = FORMATREPRESENTATION_UINT;
 		textureFormat.internalFormatRepresentation = FORMATREPRESENTATION_UINT;
@@ -370,7 +373,8 @@ TextureFormat Vulkan::getTextureFormat(PixelFormat format)
 		textureFormat.internalFormat = VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG;
 		textureFormat.internalFormat = VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG;
 		break;
 		break;
 	case PIXELFORMAT_ETC1_UNORM:
 	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:
 	case PIXELFORMAT_ETC2_RGB_UNORM:
 		textureFormat.internalFormat = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
 		textureFormat.internalFormat = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
 		break;
 		break;