From 0aa86a7ae8315f93f9501323dc082af0ac869efc Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Tue, 18 Feb 2020 17:16:47 +0000 Subject: [PATCH] Validate that sampler compare function requires iOS GPU family 3v1 Bug: b/149025333 Change-Id: I8683188c6189a9390ac6568e4ab5434a6c1a99f9 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15942 Commit-Queue: Austin Eng Reviewed-by: Corentin Wallez --- src/dawn_native/metal/DeviceMTL.mm | 2 +- src/dawn_native/metal/SamplerMTL.h | 3 ++- src/dawn_native/metal/SamplerMTL.mm | 21 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm index 830b99a5ae..2b4a6ecc7a 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -106,7 +106,7 @@ namespace dawn_native { namespace metal { return RenderPipeline::Create(this, descriptor); } ResultOrError Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { - return new Sampler(this, descriptor); + return Sampler::Create(this, descriptor); } ResultOrError Device::CreateShaderModuleImpl( const ShaderModuleDescriptor* descriptor) { diff --git a/src/dawn_native/metal/SamplerMTL.h b/src/dawn_native/metal/SamplerMTL.h index 776c935629..205a7ecd2d 100644 --- a/src/dawn_native/metal/SamplerMTL.h +++ b/src/dawn_native/metal/SamplerMTL.h @@ -25,12 +25,13 @@ namespace dawn_native { namespace metal { class Sampler : public SamplerBase { public: - Sampler(Device* device, const SamplerDescriptor* descriptor); + static ResultOrError Create(Device* device, const SamplerDescriptor* descriptor); ~Sampler(); id GetMTLSamplerState(); private: + Sampler(Device* device, const SamplerDescriptor* descriptor); id mMtlSamplerState = nil; }; diff --git a/src/dawn_native/metal/SamplerMTL.mm b/src/dawn_native/metal/SamplerMTL.mm index c58e5823af..e29fbe189c 100644 --- a/src/dawn_native/metal/SamplerMTL.mm +++ b/src/dawn_native/metal/SamplerMTL.mm @@ -50,6 +50,20 @@ namespace dawn_native { namespace metal { } } + // static + ResultOrError Sampler::Create(Device* device, const SamplerDescriptor* descriptor) { +#if defined(DAWN_PLATFORM_IOS) + if (descriptor->compare != wgpu::CompareFunction::Never && + ![device->GetMTLDevice() supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]) { + // Unsupported before A9. + // TODO(b/149025333): Investigate emulation -- possibly expensive. + return DAWN_VALIDATION_ERROR( + "Sampler compare function requires at least iOS GPU family 3, version 1"); + } +#endif + return new Sampler(device, descriptor); + } + Sampler::Sampler(Device* device, const SamplerDescriptor* descriptor) : SamplerBase(device, descriptor) { MTLSamplerDescriptor* mtlDesc = [MTLSamplerDescriptor new]; @@ -64,7 +78,12 @@ namespace dawn_native { namespace metal { mtlDesc.lodMinClamp = descriptor->lodMinClamp; mtlDesc.lodMaxClamp = descriptor->lodMaxClamp; - mtlDesc.compareFunction = ToMetalCompareFunction(descriptor->compare); + + if (descriptor->compare != wgpu::CompareFunction::Never) { + // Anything other than Never is unsupported before A9, which we validate in + // Sampler::Create. + mtlDesc.compareFunction = ToMetalCompareFunction(descriptor->compare); + } mMtlSamplerState = [device->GetMTLDevice() newSamplerStateWithDescriptor:mtlDesc];