Skip to content

Commit

Permalink
metal: check for depth compare mode support before setting it on a te…
Browse files Browse the repository at this point in the history
…xture.
  • Loading branch information
slime73 committed Jan 1, 2024
1 parent 9b537ed commit 0523aa6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/modules/graphics/metal/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class Graphics final : public love::graphics::Graphics

id<MTLSamplerState> getCachedSampler(const SamplerState &s);

bool isDepthCompareSamplerSupported() const;

StreamBuffer *getUniformBuffer() const { return uniformBuffer; }
Buffer *getDefaultAttributesBuffer() const { return defaultAttributesBuffer; }

Expand Down
7 changes: 6 additions & 1 deletion src/modules/graphics/metal/Graphics.mm
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ static bool isClampOne(SamplerState::WrapMode w)
desc.lodMinClamp = s.minLod;
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)
desc.compareFunction = getMTLCompareFunction(s.depthSampleMode.value);

Expand All @@ -822,6 +822,11 @@ static bool isClampOne(SamplerState::WrapMode w)
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)
{
uint64 key = (depth.compare << 0) | ((uint32)depth.write << 8)
Expand Down
3 changes: 3 additions & 0 deletions src/modules/graphics/metal/Texture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ static MTLTextureType getMTLTextureType(TextureType type, int msaa)

void Texture::setSamplerState(const SamplerState &s)
{ @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.
love::graphics::Texture::setSamplerState(s);

Expand Down

0 comments on commit 0523aa6

Please sign in to comment.