[graphite] Fix SamplerState creation.
I was creating a descriptor wrapped in a smart pointer, then creating a
raw descriptor and setting up that, and then using the original
wrapped descriptor to create the sampler. As a extra bonus, because of
the raw descriptor this also introduced a memory leak.
I also added some useful labels for GPU capture.
Bug: skia:13118
Change-Id: I8a589b2ae82e05f4fcad5c31177b04d5dde0cd97
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/566882
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/graphite/mtl/MtlSampler.mm b/src/gpu/graphite/mtl/MtlSampler.mm
index 5e93c0a..9c56267 100644
--- a/src/gpu/graphite/mtl/MtlSampler.mm
+++ b/src/gpu/graphite/mtl/MtlSampler.mm
@@ -67,22 +67,41 @@
SkUNREACHABLE;
}();
- auto samplerDesc = [[MTLSamplerDescriptor alloc] init];
- samplerDesc.rAddressMode = MTLSamplerAddressModeClampToEdge;
- samplerDesc.sAddressMode = tile_mode_to_mtl_sampler_address(xTileMode, gpu->mtlCaps());
- samplerDesc.tAddressMode = tile_mode_to_mtl_sampler_address(yTileMode, gpu->mtlCaps());
- samplerDesc.magFilter = minMagFilter;
- samplerDesc.minFilter = minMagFilter;
- samplerDesc.mipFilter = mipFilter;
- samplerDesc.lodMinClamp = 0.0f;
- samplerDesc.lodMaxClamp = FLT_MAX; // default value according to docs.
- samplerDesc.maxAnisotropy = 1.0f;
- samplerDesc.normalizedCoordinates = true;
+ (*desc).rAddressMode = MTLSamplerAddressModeClampToEdge;
+ (*desc).sAddressMode = tile_mode_to_mtl_sampler_address(xTileMode, gpu->mtlCaps());
+ (*desc).tAddressMode = tile_mode_to_mtl_sampler_address(yTileMode, gpu->mtlCaps());
+ (*desc).magFilter = minMagFilter;
+ (*desc).minFilter = minMagFilter;
+ (*desc).mipFilter = mipFilter;
+ (*desc).lodMinClamp = 0.0f;
+ (*desc).lodMaxClamp = FLT_MAX; // default value according to docs.
+ (*desc).maxAnisotropy = 1; // TODO: if we start using aniso, need to add to key
+ (*desc).normalizedCoordinates = true;
if (@available(macOS 10.11, iOS 9.0, *)) {
- samplerDesc.compareFunction = MTLCompareFunctionNever;
+ (*desc).compareFunction = MTLCompareFunctionNever;
}
#ifdef SK_ENABLE_MTL_DEBUG_INFO
- // TODO: add label?
+ NSString* tileModeLabels[] = {
+ @"Clamp",
+ @"Repeat",
+ @"Mirror",
+ @"Decal"
+ };
+ NSString* minMagFilterLabels[] = {
+ @"Nearest",
+ @"Linear"
+ };
+ NSString* mipFilterLabels[] = {
+ @"MipNone",
+ @"MipNearest",
+ @"MipLinear"
+ };
+
+ (*desc).label = [NSString stringWithFormat:@"X%@Y%@%@%@",
+ tileModeLabels[(int)xTileMode],
+ tileModeLabels[(int)yTileMode],
+ minMagFilterLabels[(int)samplingOptions.filter],
+ mipFilterLabels[(int)samplingOptions.mipmap]];
#endif
sk_cfp<id<MTLSamplerState>> sampler([gpu->device() newSamplerStateWithDescriptor:desc.get()]);