Reland "implemented GrMtlSampler for metal gpu backend"
This reverts commit35f9637a78
. Reason for revert: <Removed setting border color since we don't clamp to border anyway> Original change's description: > Revert "implemented GrMtlSampler for metal gpu backend" > > This reverts commit93fa10fbbc
. > > Reason for revert: <Breaking build on macOS ver < 10.12> > > Original change's description: > > implemented GrMtlSampler for metal gpu backend > > > > Bug: skia: > > Change-Id: I936e5510e5ee146c0fc6bdbc0d5f5352359fbe7d > > Reviewed-on: https://skia-review.googlesource.com/145893 > > Commit-Queue: Timothy Liang <timliang@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,timliang@google.com > > Change-Id: I4184890610e3147abc63b7d9bdfa8ec8120a11ef > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia: > Reviewed-on: https://skia-review.googlesource.com/146580 > Reviewed-by: Timothy Liang <timliang@google.com> > Commit-Queue: Timothy Liang <timliang@google.com> Bug: skia: Change-Id: Icbf31144cba79c621eff4741871d27172f1004b7 Reviewed-on: https://skia-review.googlesource.com/146581 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Timothy Liang <timliang@google.com>
This commit is contained in:
parent
87785d5573
commit
2eb8e02756
@ -645,6 +645,8 @@ skia_metal_sources = [
|
||||
"$_src/gpu/mtl/GrMtlRenderTarget.mm",
|
||||
"$_src/gpu/mtl/GrMtlResourceProvider.h",
|
||||
"$_src/gpu/mtl/GrMtlResourceProvider.mm",
|
||||
"$_src/gpu/mtl/GrMtlSampler.h",
|
||||
"$_src/gpu/mtl/GrMtlSampler.mm",
|
||||
"$_src/gpu/mtl/GrMtlTexture.h",
|
||||
"$_src/gpu/mtl/GrMtlTexture.mm",
|
||||
"$_src/gpu/mtl/GrMtlTextureRenderTarget.h",
|
||||
|
30
src/gpu/mtl/GrMtlSampler.h
Normal file
30
src/gpu/mtl/GrMtlSampler.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2018 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef GrMtlSampler_DEFINED
|
||||
#define GrMtlSampler_DEFINED
|
||||
|
||||
#import <metal/metal.h>
|
||||
|
||||
class GrSamplerState;
|
||||
class GrMtlGpu;
|
||||
|
||||
// This class only acts as a wrapper for a MTLSamplerState object for now, but will be more useful
|
||||
// once we start caching sampler states.
|
||||
class GrMtlSampler {
|
||||
public:
|
||||
static GrMtlSampler* Create(const GrMtlGpu* gpu, const GrSamplerState&, uint32_t maxMipLevel);
|
||||
|
||||
id<MTLSamplerState> mtlSamplerState() const { return fMtlSamplerState; }
|
||||
|
||||
private:
|
||||
GrMtlSampler(id<MTLSamplerState> mtlSamplerState) : fMtlSamplerState(mtlSamplerState) {}
|
||||
|
||||
id<MTLSamplerState> fMtlSamplerState;
|
||||
};
|
||||
|
||||
#endif
|
53
src/gpu/mtl/GrMtlSampler.mm
Normal file
53
src/gpu/mtl/GrMtlSampler.mm
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2018 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "GrMtlSampler.h"
|
||||
|
||||
#include "GrMtlGpu.h"
|
||||
|
||||
static inline MTLSamplerAddressMode wrap_mode_to_mtl_sampler_address(
|
||||
GrSamplerState::WrapMode wrapMode) {
|
||||
switch (wrapMode) {
|
||||
case GrSamplerState::WrapMode::kClamp:
|
||||
return MTLSamplerAddressModeClampToEdge;
|
||||
case GrSamplerState::WrapMode::kRepeat:
|
||||
return MTLSamplerAddressModeRepeat;
|
||||
case GrSamplerState::WrapMode::kMirrorRepeat:
|
||||
return MTLSamplerAddressModeMirrorRepeat;
|
||||
}
|
||||
SK_ABORT("Unknown wrap mode.");
|
||||
return MTLSamplerAddressModeClampToEdge;
|
||||
}
|
||||
|
||||
GrMtlSampler* GrMtlSampler::Create(const GrMtlGpu* gpu, const GrSamplerState& samplerState,
|
||||
uint32_t maxMipLevel) {
|
||||
static MTLSamplerMinMagFilter mtlMinMagFilterModes[] = {
|
||||
MTLSamplerMinMagFilterNearest,
|
||||
MTLSamplerMinMagFilterLinear,
|
||||
MTLSamplerMinMagFilterLinear
|
||||
};
|
||||
|
||||
GR_STATIC_ASSERT((int)GrSamplerState::Filter::kNearest == 0);
|
||||
GR_STATIC_ASSERT((int)GrSamplerState::Filter::kBilerp == 1);
|
||||
GR_STATIC_ASSERT((int)GrSamplerState::Filter::kMipMap == 2);
|
||||
|
||||
auto samplerDesc = [[MTLSamplerDescriptor alloc] init];
|
||||
samplerDesc.rAddressMode = MTLSamplerAddressModeClampToEdge;
|
||||
samplerDesc.sAddressMode = wrap_mode_to_mtl_sampler_address(samplerState.wrapModeX());
|
||||
samplerDesc.tAddressMode = wrap_mode_to_mtl_sampler_address(samplerState.wrapModeY());
|
||||
samplerDesc.magFilter = mtlMinMagFilterModes[static_cast<int>(samplerState.filter())];
|
||||
samplerDesc.minFilter = mtlMinMagFilterModes[static_cast<int>(samplerState.filter())];
|
||||
samplerDesc.mipFilter = MTLSamplerMipFilterLinear;
|
||||
samplerDesc.lodMinClamp = 0.0f;
|
||||
bool useMipMaps = GrSamplerState::Filter::kMipMap == samplerState.filter() && maxMipLevel > 0;
|
||||
samplerDesc.lodMaxClamp = !useMipMaps ? 0.0f : (float)(maxMipLevel);
|
||||
samplerDesc.maxAnisotropy = 1.0f;
|
||||
samplerDesc.normalizedCoordinates = true;
|
||||
samplerDesc.compareFunction = MTLCompareFunctionNever;
|
||||
|
||||
return new GrMtlSampler([gpu->device() newSamplerStateWithDescriptor: samplerDesc]);
|
||||
}
|
Loading…
Reference in New Issue
Block a user