1// 2// Copyright 2020 The ANGLE Project Authors. All rights reserved. 3// Use of this source code is governed by a BSD-style license that can be 4// found in the LICENSE file. 5// 6// SamplerMtl.mm: 7// Defines the class interface for SamplerMtl, implementing SamplerImpl. 8// 9 10#include "libANGLE/renderer/metal/SamplerMtl.h" 11 12#include "common/debug.h" 13#include "libANGLE/Context.h" 14#include "libANGLE/renderer/metal/ContextMtl.h" 15#include "libANGLE/renderer/metal/DisplayMtl.h" 16#include "libANGLE/renderer/metal/mtl_state_cache.h" 17 18namespace rx 19{ 20 21SamplerMtl::SamplerMtl(const gl::SamplerState &state) : SamplerImpl(state) {} 22 23SamplerMtl::~SamplerMtl() = default; 24 25void SamplerMtl::onDestroy(const gl::Context *context) 26{ 27 mSamplerState = nil; 28} 29 30const mtl::AutoObjCPtr<id<MTLSamplerState>> &SamplerMtl::getSampler(ContextMtl *contextMtl) 31{ 32 if (!mSamplerState) 33 { 34 mtl::SamplerDesc samplerDesc(mState); 35 36 mSamplerState = contextMtl->getDisplay()->getStateCache().getSamplerState( 37 contextMtl->getMetalDevice(), samplerDesc); 38 } 39 40 return mSamplerState; 41} 42 43angle::Result SamplerMtl::syncState(const gl::Context *context, const bool dirty) 44{ 45 if (dirty) 46 { 47 // Recreate sampler 48 mSamplerState = nil; 49 50 if (mCompareMode != mState.getCompareMode() || mCompareFunc != mState.getCompareFunc()) 51 { 52 ContextMtl *contextMtl = mtl::GetImpl(context); 53 54 mCompareMode = mState.getCompareMode(); 55 mCompareFunc = mState.getCompareFunc(); 56 57 // Tell context to rebind textures so that ProgramMtl has a chance to verify 58 // depth texture compare mode. 59 contextMtl->invalidateCurrentTextures(); 60 } 61 } 62 return angle::Result::Continue; 63} 64 65} // namespace rx 66