Browse Source

metal: check for depth compare mode support before setting it on a texture.

Sasha Szpakowski 1 year ago
parent
commit
0523aa6f8f

+ 2 - 0
src/modules/graphics/metal/Graphics.h

@@ -137,6 +137,8 @@ public:
 
 
 	id<MTLSamplerState> getCachedSampler(const SamplerState &s);
 	id<MTLSamplerState> getCachedSampler(const SamplerState &s);
 
 
+	bool isDepthCompareSamplerSupported() const;
+
 	StreamBuffer *getUniformBuffer() const { return uniformBuffer; }
 	StreamBuffer *getUniformBuffer() const { return uniformBuffer; }
 	Buffer *getDefaultAttributesBuffer() const { return defaultAttributesBuffer; }
 	Buffer *getDefaultAttributesBuffer() const { return defaultAttributesBuffer; }
 
 

+ 6 - 1
src/modules/graphics/metal/Graphics.mm

@@ -810,7 +810,7 @@ id<MTLSamplerState> Graphics::getCachedSampler(const SamplerState &s)
 	desc.lodMinClamp = s.minLod;
 	desc.lodMinClamp = s.minLod;
 	desc.lodMaxClamp = s.maxLod;
 	desc.lodMaxClamp = s.maxLod;
 
 
-	// TODO: This isn't supported on some older iOS devices...
+	// This isn't supported on some older iOS devices. Texture code checks for support.
 	if (s.depthSampleMode.hasValue)
 	if (s.depthSampleMode.hasValue)
 		desc.compareFunction = getMTLCompareFunction(s.depthSampleMode.value);
 		desc.compareFunction = getMTLCompareFunction(s.depthSampleMode.value);
 
 
@@ -822,6 +822,11 @@ id<MTLSamplerState> Graphics::getCachedSampler(const SamplerState &s)
 	return sampler;
 	return sampler;
 }}
 }}
 
 
+bool Graphics::isDepthCompareSamplerSupported() const
+{
+	return families.mac[1] || families.macCatalyst[1] || families.apple[3];
+}
+
 id<MTLDepthStencilState> Graphics::getCachedDepthStencilState(const DepthState &depth, const StencilState &stencil)
 id<MTLDepthStencilState> Graphics::getCachedDepthStencilState(const DepthState &depth, const StencilState &stencil)
 {
 {
 	uint64 key = (depth.compare << 0) | ((uint32)depth.write << 8)
 	uint64 key = (depth.compare << 0) | ((uint32)depth.write << 8)

+ 3 - 0
src/modules/graphics/metal/Texture.mm

@@ -339,6 +339,9 @@ void Texture::copyToBuffer(love::graphics::Buffer *dest, int slice, int mipmap,
 
 
 void Texture::setSamplerState(const SamplerState &s)
 void Texture::setSamplerState(const SamplerState &s)
 { @autoreleasepool {
 { @autoreleasepool {
+	if (s.depthSampleMode.hasValue && !Graphics::getInstance()->isDepthCompareSamplerSupported())
+		throw love::Exception("Depth comparison sampling in shaders is not supported on this system.");
+
 	// Base class does common validation and assigns samplerState.
 	// Base class does common validation and assigns samplerState.
 	love::graphics::Texture::setSamplerState(s);
 	love::graphics::Texture::setSamplerState(s);