[graphite] Fully use SampleCount in TextureInfo::Datas and ContextOptions

These changes build correctly with SampleCount defined as the current
pseudo-enum class and defined as a regular enum class.

Bug: b/452351267
Change-Id: If47fdbb38332893c399e6c064c01ede3a183a776
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1104816
Commit-Queue: Robert Phillips <robertphillips@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Auto-Submit: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/include/gpu/graphite/ContextOptions.h b/include/gpu/graphite/ContextOptions.h
index 458f3b1..7d92a27 100644
--- a/include/gpu/graphite/ContextOptions.h
+++ b/include/gpu/graphite/ContextOptions.h
@@ -11,6 +11,7 @@
 #include "include/core/SkRefCnt.h"
 #include "include/core/SkSize.h"
 #include "include/core/SkSpan.h"
+#include "include/gpu/graphite/GraphiteTypes.h"
 #include "include/private/base/SkAPI.h"
 #include "include/private/base/SkMath.h"
 
@@ -49,7 +50,7 @@
      *
      * If <= 1, Graphite will disable internal code paths that use multisampling.
      */
-    uint8_t fInternalMultisampleCount = 4;
+    SampleCount fInternalMultisampleCount = SampleCount::k4;
 
     /**
      * If set, this specifies the max width/height of MSAA textures that Graphite should use for
diff --git a/include/gpu/graphite/GraphiteTypes.h b/include/gpu/graphite/GraphiteTypes.h
index 448f076..72b0302 100644
--- a/include/gpu/graphite/GraphiteTypes.h
+++ b/include/gpu/graphite/GraphiteTypes.h
@@ -253,6 +253,18 @@
     V fValue;
 };
 
+/**
+ * Convert an integer value to a strictly typed SampleCount value, rounding down to the lowest
+ * valid sample count if needed if `sampleCount` is not already equivalent.
+ */
+constexpr SampleCount ToSampleCount(uint32_t sampleCount) {
+    return sampleCount >= 16 ? SampleCount::k16 :
+           sampleCount >= 8  ? SampleCount::k8  :
+           sampleCount >= 4  ? SampleCount::k4  :
+           sampleCount >= 2  ? SampleCount::k2  :
+                               SampleCount::k1;
+}
+
 /*
  * This enum allows mapping from a set of observed RenderSteps (e.g., from a GraphicsPipeline
  * printout) to the correct 'drawTypes' parameter needed by the Precompilation API.
diff --git a/include/gpu/graphite/TextureInfo.h b/include/gpu/graphite/TextureInfo.h
index 3fa6d08..916176f 100644
--- a/include/gpu/graphite/TextureInfo.h
+++ b/include/gpu/graphite/TextureInfo.h
@@ -46,7 +46,7 @@
     public:
         virtual ~Data() = default;
 
-        Data(uint8_t sampleCount, skgpu::Mipmapped mipmapped)
+        Data(SampleCount sampleCount, skgpu::Mipmapped mipmapped)
                 : fSampleCount(sampleCount)
                 , fMipmapped(mipmapped) {}
 
@@ -56,11 +56,7 @@
         Data& operator=(const Data&) = default;
 
         // NOTE: These fields are accessible via the backend-specific subclasses.
-
-        // Must be a valid SampleCount value, or TextureInfo creation will fail to wrap the backend
-        // specific data. This is not strongly typed so that it can be assigned directly from the
-        // backend GPU API's representation, which is often just an integer.
-        uint8_t fSampleCount = 1;
+        SampleCount fSampleCount = SampleCount::k1;
         Mipmapped fMipmapped = Mipmapped::kNo;
 
     private:
@@ -95,7 +91,7 @@
 
     Protected isProtected() const { return fProtected; }
     SampleCount sampleCount() const {
-        return fData.has_value() ? static_cast<SampleCount>(fData->fSampleCount) : SampleCount::k1;
+        return fData.has_value() ? fData->fSampleCount : SampleCount::k1;
     }
     Mipmapped mipmapped() const {
         return fData.has_value() ? fData->fMipmapped   : Mipmapped::kNo;
@@ -119,9 +115,6 @@
             : fBackend(BackendTextureData::kBackend)
             , fViewFormat(data.viewFormat())
             , fProtected(data.isProtected()) {
-        // TextureInfoPriv should not construct a TextureInfo if `data` would fail this assert.
-        SkASSERT(data.fSampleCount == 1 || data.fSampleCount == 2 || data.fSampleCount == 4 ||
-                 data.fSampleCount == 8 || data.fSampleCount == 16);
         fData.emplace<BackendTextureData>(data);
     }
 
diff --git a/include/gpu/graphite/dawn/DawnGraphiteTypes.h b/include/gpu/graphite/dawn/DawnGraphiteTypes.h
index ee5ca9d..bd75f26 100644
--- a/include/gpu/graphite/dawn/DawnGraphiteTypes.h
+++ b/include/gpu/graphite/dawn/DawnGraphiteTypes.h
@@ -48,7 +48,7 @@
 
     explicit DawnTextureInfo(WGPUTexture texture);
 
-    DawnTextureInfo(uint32_t sampleCount,
+    DawnTextureInfo(SampleCount sampleCount,
                     Mipmapped mipmapped,
                     wgpu::TextureFormat format,
                     wgpu::TextureUsage usage,
@@ -61,7 +61,7 @@
                               aspect,
                               /*slice=*/0) {}
 
-    DawnTextureInfo(uint32_t sampleCount,
+    DawnTextureInfo(SampleCount sampleCount,
                     Mipmapped mipmapped,
                     wgpu::TextureFormat format,
                     wgpu::TextureFormat viewFormat,
@@ -76,7 +76,7 @@
             , fSlice(slice) {}
 
 #if !defined(__EMSCRIPTEN__)
-    DawnTextureInfo(uint32_t sampleCount,
+    DawnTextureInfo(SampleCount sampleCount,
                     Mipmapped mipmapped,
                     wgpu::TextureFormat format,
                     wgpu::TextureFormat viewFormat,
diff --git a/include/gpu/graphite/mtl/MtlGraphiteTypes.h b/include/gpu/graphite/mtl/MtlGraphiteTypes.h
index c670076..0505add 100644
--- a/include/gpu/graphite/mtl/MtlGraphiteTypes.h
+++ b/include/gpu/graphite/mtl/MtlGraphiteTypes.h
@@ -35,7 +35,7 @@
 
     MtlTextureInfo() = default;
     explicit MtlTextureInfo(CFTypeRef mtlTexture);
-    MtlTextureInfo(uint32_t sampleCount,
+    MtlTextureInfo(SampleCount sampleCount,
                    skgpu::Mipmapped mipmapped,
                    MTLPixelFormat format,
                    MTLTextureUsage usage,
diff --git a/include/gpu/graphite/vk/VulkanGraphiteTypes.h b/include/gpu/graphite/vk/VulkanGraphiteTypes.h
index 31bee40..d4bddb2 100644
--- a/include/gpu/graphite/vk/VulkanGraphiteTypes.h
+++ b/include/gpu/graphite/vk/VulkanGraphiteTypes.h
@@ -46,7 +46,8 @@
                       VkSharingMode sharingMode,
                       VkImageAspectFlags aspectMask,
                       VulkanYcbcrConversionInfo ycbcrConversionInfo)
-            : Data(static_cast<uint8_t>(sampleCount), mipmapped)
+            // VkSampleCountFlagBits is value equivalent to SampleCount
+            : Data(static_cast<SampleCount>(sampleCount), mipmapped)
             , fFlags(flags)
             , fFormat(format)
             , fImageTiling(imageTiling)
diff --git a/relnotes/graphite-sample-count.md b/relnotes/graphite-sample-count.md
new file mode 100644
index 0000000..d182b30
--- /dev/null
+++ b/relnotes/graphite-sample-count.md
@@ -0,0 +1,4 @@
+Backend specific texture infos, e.g. `DawnTextureInfo`,
+`VulkanTextureInfo`, and `MtlTextureInfo`'s `fSampleCount` field, and the
+`ContextOptions::fInternalMultisampleCount` field are now `SampleCount`. A helper
+function, `ToSampleCount(uint32_t) -> SampleCount` is provided if needing to convert a variable value vs. just updating a constant.
diff --git a/src/gpu/graphite/Caps.cpp b/src/gpu/graphite/Caps.cpp
index 7acf9f9..aa4d09d 100644
--- a/src/gpu/graphite/Caps.cpp
+++ b/src/gpu/graphite/Caps.cpp
@@ -28,9 +28,7 @@
 void Caps::finishInitialization(const ContextOptions& options) {
     fCapabilities->initSkCaps(fShaderCaps.get());
 
-    // Round requested sample count to the lower power of 2 and clamp to [1, 16]
-    fDefaultMSAASamples = static_cast<SampleCount>(
-            SkPrevPow2(SkTPin((int) options.fInternalMultisampleCount, 1, 16)));
+    fDefaultMSAASamples = options.fInternalMultisampleCount;
 
     if (options.fShaderErrorHandler) {
         fShaderErrorHandler = options.fShaderErrorHandler;
diff --git a/src/gpu/graphite/ResourceTypes.h b/src/gpu/graphite/ResourceTypes.h
index 01a6481..b59ddea 100644
--- a/src/gpu/graphite/ResourceTypes.h
+++ b/src/gpu/graphite/ResourceTypes.h
@@ -27,10 +27,6 @@
 // The same goes for SampleCount
 SK_MAKE_BITMASK_OPS(SampleCount::V)
 
-static constexpr bool IsValidSampleCount(uint32_t sampleCount) {
-    return SkIsPow2(sampleCount) && sampleCount >= 1 && sampleCount <= 16;
-}
-
 /**
  * There are only a few possible valid sample counts (1, 2, 4, 8, 16). So we can key on those 5
  * options instead of the actual sample value. The resulting key value only requires 3 bits of space
diff --git a/src/gpu/graphite/SerializationUtils.cpp b/src/gpu/graphite/SerializationUtils.cpp
index 1837c4f..6302bd1 100644
--- a/src/gpu/graphite/SerializationUtils.cpp
+++ b/src/gpu/graphite/SerializationUtils.cpp
@@ -28,6 +28,10 @@
 
 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'p', 'e' };
 
+constexpr bool is_valid_samplecount(uint32_t sampleCount) {
+    return SkIsPow2(sampleCount) && sampleCount >= 1 && sampleCount <= 16;
+}
+
 [[nodiscard]] bool stream_is_pipeline(SkStream* stream) {
     char magic[8];
     static_assert(sizeof(kMagic) == sizeof(magic), "");
@@ -153,7 +157,7 @@
     if (storeOp >= kStoreOpCount) {
         return false;
     }
-    if (!IsValidSampleCount(sampleCount)) {
+    if (!is_valid_samplecount(sampleCount)) {
         return false;
     }
 
@@ -212,7 +216,7 @@
     renderPassDesc->fWriteSwizzle = SwizzleCtorAccessor::Make(swizzle);
 
     uint8_t sampleCount;
-    if (!stream->readU8(&sampleCount) || !IsValidSampleCount(sampleCount)) {
+    if (!stream->readU8(&sampleCount) || !is_valid_samplecount(sampleCount)) {
         return false;
     }
     renderPassDesc->fSampleCount = static_cast<SampleCount>(sampleCount);
diff --git a/src/gpu/graphite/TextureInfo.cpp b/src/gpu/graphite/TextureInfo.cpp
index 1f2204d..4ac6499 100644
--- a/src/gpu/graphite/TextureInfo.cpp
+++ b/src/gpu/graphite/TextureInfo.cpp
@@ -64,7 +64,7 @@
                           TextureFormatName(fViewFormat),
                           fData->toBackendString().c_str(),
                           TextureFormatBytesPerBlock(fViewFormat),
-                          fData->fSampleCount,
+                          (unsigned) fData->fSampleCount,
                           static_cast<int>(fData->fMipmapped),
                           static_cast<int>(fProtected));
 }
diff --git a/src/gpu/graphite/TextureInfoPriv.h b/src/gpu/graphite/TextureInfoPriv.h
index 8fcae11..9f3edcf 100644
--- a/src/gpu/graphite/TextureInfoPriv.h
+++ b/src/gpu/graphite/TextureInfoPriv.h
@@ -29,11 +29,6 @@
 
     template <typename BackendTextureInfo>
     static TextureInfo Make(const BackendTextureInfo& data) {
-        // Validate that the uint8_t data.fSampleCount can be cast to a SampleCount value. If not
-        // then return an empty TextureInfo since the data is invalid.
-        if (!IsValidSampleCount(data.fSampleCount)) {
-            return TextureInfo();
-        }
         return TextureInfo(data);
     }
 
diff --git a/src/gpu/graphite/dawn/DawnCaps.cpp b/src/gpu/graphite/dawn/DawnCaps.cpp
index b2fb7dd..62ccaa3 100644
--- a/src/gpu/graphite/dawn/DawnCaps.cpp
+++ b/src/gpu/graphite/dawn/DawnCaps.cpp
@@ -100,7 +100,7 @@
 
 bool DawnCaps::isTexturableIgnoreSampleCount(const TextureInfo& info) const {
     auto overrideDawnInfo = TextureInfoPriv::Get<DawnTextureInfo>(info);
-    overrideDawnInfo.fSampleCount = 1;
+    overrideDawnInfo.fSampleCount = SampleCount::k1;
     TextureInfo overrideInfo = TextureInfos::MakeDawn(overrideDawnInfo);
     return this->isTexturable(overrideInfo);
 }
@@ -224,7 +224,7 @@
     }
 
     DawnTextureInfo info;
-    info.fSampleCount = (uint8_t) desc.fSampleCount;
+    info.fSampleCount = desc.fSampleCount;
     info.fMipmapped   = Mipmapped::kNo;
     info.fFormat      = TextureFormatToDawnFormat(desc.fFormat);
     info.fUsage       = wgpu::TextureUsage::RenderAttachment;
@@ -258,7 +258,7 @@
     }
 
     DawnTextureInfo info;
-    info.fSampleCount = 1;
+    info.fSampleCount = SampleCount::k1;
     info.fMipmapped = mipmapped;
     info.fFormat = format;
     info.fViewFormat = format;
@@ -270,7 +270,7 @@
 TextureInfo DawnCaps::getTextureInfoForSampledCopy(const TextureInfo& textureInfo,
                                                    Mipmapped mipmapped) const {
     DawnTextureInfo info;
-    info.fSampleCount = 1;
+    info.fSampleCount = SampleCount::k1;
     info.fMipmapped = mipmapped;
     info.fFormat = TextureInfoPriv::Get<DawnTextureInfo>(textureInfo).getViewFormat();
     info.fUsage = wgpu::TextureUsage::TextureBinding | wgpu::TextureUsage::CopyDst |
@@ -305,7 +305,7 @@
     }
 
     DawnTextureInfo info;
-    info.fSampleCount = 1;
+    info.fSampleCount = SampleCount::k1;
     info.fMipmapped = mipmapped;
     info.fFormat = format;
     info.fViewFormat = format;
@@ -330,7 +330,7 @@
                                wgpu::TextureUsage::TextureBinding |
                                wgpu::TextureUsage::CopySrc;
     DawnTextureInfo info;
-    info.fSampleCount = 1;
+    info.fSampleCount = SampleCount::k1;
     info.fMipmapped = Mipmapped::kNo;
     info.fFormat = format;
     info.fViewFormat = format;
diff --git a/src/gpu/graphite/dawn/DawnResourceProvider.cpp b/src/gpu/graphite/dawn/DawnResourceProvider.cpp
index 6c43a7a..91da296 100644
--- a/src/gpu/graphite/dawn/DawnResourceProvider.cpp
+++ b/src/gpu/graphite/dawn/DawnResourceProvider.cpp
@@ -538,7 +538,7 @@
 
     // Derive the load texture's info from MSAA texture's info.
     DawnTextureInfo dawnMsaaLoadTextureInfo = TextureInfoPriv::Get<DawnTextureInfo>(msaaInfo);
-    dawnMsaaLoadTextureInfo.fSampleCount = 1;
+    dawnMsaaLoadTextureInfo.fSampleCount = SampleCount::k1;
     dawnMsaaLoadTextureInfo.fUsage |= wgpu::TextureUsage::TextureBinding;
 
 #if !defined(__EMSCRIPTEN__)
diff --git a/src/gpu/graphite/dawn/DawnTextureInfo.cpp b/src/gpu/graphite/dawn/DawnTextureInfo.cpp
index 6331e20..3c2da60 100644
--- a/src/gpu/graphite/dawn/DawnTextureInfo.cpp
+++ b/src/gpu/graphite/dawn/DawnTextureInfo.cpp
@@ -16,7 +16,7 @@
 
 DawnTextureInfo::DawnTextureInfo(WGPUTexture texture)
         : DawnTextureInfo(
-                wgpuTextureGetSampleCount(texture),
+                ToSampleCount(wgpuTextureGetSampleCount(texture)),
                 wgpuTextureGetMipLevelCount(texture) > 1 ? Mipmapped::kYes : Mipmapped::kNo,
                 /*format=*/static_cast<wgpu::TextureFormat>(wgpuTextureGetFormat(texture)),
                 /*viewFormat=*/static_cast<wgpu::TextureFormat>(wgpuTextureGetFormat(texture)),
diff --git a/src/gpu/graphite/mtl/MtlCaps.mm b/src/gpu/graphite/mtl/MtlCaps.mm
index f2bb71c..ae1da6d 100644
--- a/src/gpu/graphite/mtl/MtlCaps.mm
+++ b/src/gpu/graphite/mtl/MtlCaps.mm
@@ -820,7 +820,7 @@
     }
 
     MtlTextureInfo info;
-    info.fSampleCount = (uint8_t) desc.fSampleCount;
+    info.fSampleCount = desc.fSampleCount;
     info.fMipmapped = Mipmapped::kNo;
     info.fFormat = TextureFormatToMTLPixelFormat(desc.fFormat);
     info.fUsage = MTLTextureUsageRenderTarget;
@@ -845,7 +845,7 @@
     }
 
     MtlTextureInfo info;
-    info.fSampleCount = 1;
+    info.fSampleCount = SampleCount::k1;
     info.fMipmapped = mipmapped;
     info.fFormat = format;
     info.fUsage = usage;
@@ -858,7 +858,7 @@
 TextureInfo MtlCaps::getTextureInfoForSampledCopy(const TextureInfo& textureInfo,
                                                   Mipmapped mipmapped) const {
     MtlTextureInfo info;
-    info.fSampleCount = 1;
+    info.fSampleCount = SampleCount::k1;
     info.fMipmapped = mipmapped;
     info.fFormat = TextureInfoPriv::Get<MtlTextureInfo>(textureInfo).fFormat;
     info.fUsage = MTLTextureUsageShaderRead;
@@ -902,7 +902,7 @@
     }
 
     MtlTextureInfo info;
-    info.fSampleCount = 1;
+    info.fSampleCount = SampleCount::k1;
     info.fMipmapped = mipmapped;
     info.fFormat = format;
     info.fUsage = usage;
@@ -925,7 +925,7 @@
     }
 
     MtlTextureInfo info;
-    info.fSampleCount = 1;
+    info.fSampleCount = SampleCount::k1;
     info.fMipmapped = Mipmapped::kNo;
     info.fFormat = format;
     info.fUsage = MTLTextureUsageShaderWrite | MTLTextureUsageShaderRead;
diff --git a/src/gpu/graphite/mtl/MtlTextureInfo.mm b/src/gpu/graphite/mtl/MtlTextureInfo.mm
index c757e11..f255742 100644
--- a/src/gpu/graphite/mtl/MtlTextureInfo.mm
+++ b/src/gpu/graphite/mtl/MtlTextureInfo.mm
@@ -23,7 +23,7 @@
     SkASSERT(texture);
     id<MTLTexture> mtlTex = (id<MTLTexture>)texture;
 
-    fSampleCount = mtlTex.sampleCount;
+    fSampleCount = ToSampleCount(mtlTex.sampleCount);
     fMipmapped = mtlTex.mipmapLevelCount > 1 ? Mipmapped::kYes : Mipmapped::kNo;
 
     fFormat = mtlTex.pixelFormat;
diff --git a/src/gpu/graphite/vk/VulkanCaps.cpp b/src/gpu/graphite/vk/VulkanCaps.cpp
index e743bd5..25a9f18 100644
--- a/src/gpu/graphite/vk/VulkanCaps.cpp
+++ b/src/gpu/graphite/vk/VulkanCaps.cpp
@@ -726,7 +726,7 @@
     }
 
     VulkanTextureInfo info;
-    info.fSampleCount = (uint8_t) desc.fSampleCount;
+    info.fSampleCount = desc.fSampleCount;
     info.fMipmapped = Mipmapped::kNo;
     info.fFlags = createFlags;
     info.fFormat = TextureFormatToVkFormat(desc.fFormat);
@@ -753,7 +753,7 @@
     }
 
     VulkanTextureInfo info;
-    info.fSampleCount = 1;
+    info.fSampleCount = SampleCount::k1;
     info.fMipmapped = mipmapped;
     info.fFlags = (isProtected == Protected::kYes) ? VK_IMAGE_CREATE_PROTECTED_BIT : 0;
     info.fFormat = format;
@@ -787,7 +787,7 @@
 TextureInfo VulkanCaps::getTextureInfoForSampledCopy(const TextureInfo& textureInfo,
                                                      Mipmapped mipmapped) const {
     VulkanTextureInfo info;
-    info.fSampleCount = 1;
+    info.fSampleCount = SampleCount::k1;
     info.fMipmapped = mipmapped;
     info.fFormat = TextureInfoPriv::Get<VulkanTextureInfo>(textureInfo).fFormat;
     info.fFlags = (textureInfo.isProtected() == Protected::kYes) ?
@@ -831,7 +831,7 @@
     }
 
     VulkanTextureInfo info;
-    info.fSampleCount = 1;
+    info.fSampleCount = SampleCount::k1;
     info.fMipmapped = mipmapped;
     info.fFlags = (isProtected == Protected::kYes) ? VK_IMAGE_CREATE_PROTECTED_BIT : 0;
     info.fFormat = format;
@@ -857,7 +857,7 @@
     }
 
     VulkanTextureInfo info;
-    info.fSampleCount = 1;
+    info.fSampleCount = SampleCount::k1;
     info.fMipmapped = Mipmapped::kNo;
     info.fFlags = 0;
     info.fFormat = format;
@@ -1997,7 +1997,6 @@
 }
 
 bool VulkanCaps::isRenderable(const VulkanTextureInfo& vkInfo) const {
-    SkASSERT(IsValidSampleCount(vkInfo.fSampleCount));
     const FormatInfo& info = this->getFormatInfo(vkInfo.fFormat);
     // All renderable vulkan textures within graphite must also support input attachment usage
     return info.isRenderable(vkInfo.fImageTiling, (SampleCount) vkInfo.fSampleCount) &&
@@ -2022,7 +2021,7 @@
         return false;
     }
 
-    if (vkInfo.fSampleCount > 1) {
+    if (vkInfo.fSampleCount > SampleCount::k1) {
         return false;
     }
 
@@ -2049,7 +2048,7 @@
         return false;
     }
 
-    if (vkInfo.fSampleCount > 1) {
+    if (vkInfo.fSampleCount > SampleCount::k1) {
         return false;
     }
 
diff --git a/tests/graphite/DawnBackendTextureTest.cpp b/tests/graphite/DawnBackendTextureTest.cpp
index e7bfc3c..e8fac71 100644
--- a/tests/graphite/DawnBackendTextureTest.cpp
+++ b/tests/graphite/DawnBackendTextureTest.cpp
@@ -28,7 +28,7 @@
     auto recorder = context->makeRecorder();
 
     DawnTextureInfo textureInfo;
-    textureInfo.fSampleCount = 1;
+    textureInfo.fSampleCount = SampleCount::k1;
     textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
     textureInfo.fFormat = wgpu::TextureFormat::RGBA8Unorm;
     textureInfo.fUsage = wgpu::TextureUsage::TextureBinding;
@@ -52,7 +52,7 @@
     auto recorder = context->makeRecorder();
 
     DawnTextureInfo textureInfo;
-    textureInfo.fSampleCount = 1;
+    textureInfo.fSampleCount = SampleCount::k1;
     textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
     textureInfo.fFormat = wgpu::TextureFormat::RGBA8Unorm;
     textureInfo.fUsage = wgpu::TextureUsage::TextureBinding;
diff --git a/tests/graphite/MtlBackendTextureTest.mm b/tests/graphite/MtlBackendTextureTest.mm
index 5c4172d..0992835 100644
--- a/tests/graphite/MtlBackendTextureTest.mm
+++ b/tests/graphite/MtlBackendTextureTest.mm
@@ -24,7 +24,7 @@
     auto recorder = context->makeRecorder();
 
     MtlTextureInfo textureInfo;
-    textureInfo.fSampleCount = 1;
+    textureInfo.fSampleCount = SampleCount::k1;
     textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
     textureInfo.fFormat = MTLPixelFormatRGBA8Unorm;
     textureInfo.fStorageMode = MTLStorageModePrivate;
@@ -53,7 +53,7 @@
 
     // It should fail with a sample count greater than 1
     textureInfo.fFormat = MTLPixelFormatRGBA8Unorm;
-    textureInfo.fSampleCount = 4;
+    textureInfo.fSampleCount = SampleCount::k4;
     beTexture = recorder->createBackendTexture(kSize, TextureInfos::MakeMetal(textureInfo));
     REPORTER_ASSERT(reporter, !beTexture.isValid());
     recorder->deleteBackendTexture(beTexture);
diff --git a/tests/graphite/VulkanBackendTextureTest.cpp b/tests/graphite/VulkanBackendTextureTest.cpp
index 0e856fa..2777b4c5e 100644
--- a/tests/graphite/VulkanBackendTextureTest.cpp
+++ b/tests/graphite/VulkanBackendTextureTest.cpp
@@ -28,7 +28,7 @@
     bool isProtected = context->priv().caps()->protectedSupport();
 
     VulkanTextureInfo textureInfo;
-    textureInfo.fSampleCount = 1;
+    textureInfo.fSampleCount = SampleCount::k1;
     textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
     textureInfo.fFlags = isProtected ? VK_IMAGE_CREATE_PROTECTED_BIT : 0;
     textureInfo.fFormat = VK_FORMAT_R8G8B8A8_UNORM;
@@ -55,7 +55,7 @@
     bool isProtected = context->priv().caps()->protectedSupport();
 
     VulkanTextureInfo textureInfo;
-    textureInfo.fSampleCount = 1;
+    textureInfo.fSampleCount = SampleCount::k1;
     textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
     textureInfo.fFlags = isProtected ? VK_IMAGE_CREATE_PROTECTED_BIT : 0;
     textureInfo.fFormat = VK_FORMAT_R8G8B8A8_UNORM;
diff --git a/tools/flags/CommonFlagsGraphite.cpp b/tools/flags/CommonFlagsGraphite.cpp
index c06585a..76ebf3a 100644
--- a/tools/flags/CommonFlagsGraphite.cpp
+++ b/tools/flags/CommonFlagsGraphite.cpp
@@ -35,7 +35,8 @@
     testOptions->fContextOptions.fExecutor = gGpuExecutor.get();
 
     if (FLAGS_internalSamples >= 0) {
-        testOptions->fContextOptions.fInternalMultisampleCount = FLAGS_internalSamples;
+        testOptions->fContextOptions.fInternalMultisampleCount =
+                skgpu::graphite::ToSampleCount(FLAGS_internalSamples);
     }
     if (FLAGS_internalMSAATileSize > 0) {
         testOptions->fContextOptions.fInternalMSAATileSize = {FLAGS_internalMSAATileSize,
diff --git a/tools/gpu/BackendSurfaceFactory.cpp b/tools/gpu/BackendSurfaceFactory.cpp
index 1d88bd8..dbfce09 100644
--- a/tools/gpu/BackendSurfaceFactory.cpp
+++ b/tools/gpu/BackendSurfaceFactory.cpp
@@ -179,7 +179,7 @@
     textureInfo.fAspect      = wgpu::TextureAspect::All;
     textureInfo.fFormat      = texture.GetFormat();
     textureInfo.fMipmapped   = mipmapped;
-    textureInfo.fSampleCount = texture.GetSampleCount();
+    textureInfo.fSampleCount = skgpu::graphite::ToSampleCount(texture.GetSampleCount());
     textureInfo.fUsage       = texture.GetUsage();
 
     skgpu::graphite::BackendTexture betFromView =
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 7bfe154..d5bccb0 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -220,7 +220,6 @@
 
 static DEFINE_int(msaa, 1, "Number of subpixel samples. 0 for no HW antialiasing.");
 static DEFINE_bool(dmsaa, false, "Use internal MSAA to render to non-MSAA surfaces?");
-static DEFINE_int(msaa_tile_size, 0, "Tile size of MSAA rendering.");
 
 static DEFINE_string(bisect, "", "Path to a .skp or .svg file to bisect.");
 
@@ -668,11 +667,8 @@
     CommonFlags::SetTestOptions(&gto.fTestOptions);
     gto.fPriv.fPathRendererStrategy = get_path_renderer_strategy_type(FLAGS_pathstrategy[0]);
     if (FLAGS_msaa <= 0) {
-        gto.fTestOptions.fContextOptions.fInternalMultisampleCount = 1;
-    }
-    if (FLAGS_msaa_tile_size > 0) {
-        gto.fTestOptions.fContextOptions.fInternalMSAATileSize = {FLAGS_msaa_tile_size,
-                                                                  FLAGS_msaa_tile_size};
+        gto.fTestOptions.fContextOptions.fInternalMultisampleCount =
+                skgpu::graphite::SampleCount::k1;
     }
     paramsBuilder.graphiteTestOptions(gto);
 #endif
diff --git a/tools/window/GraphiteDawnWindowContext.cpp b/tools/window/GraphiteDawnWindowContext.cpp
index 3f613fd..3306ad6 100644
--- a/tools/window/GraphiteDawnWindowContext.cpp
+++ b/tools/window/GraphiteDawnWindowContext.cpp
@@ -106,7 +106,7 @@
     SkASSERT(surfaceTexture.texture);
     auto texture = surfaceTexture.texture;
 
-    skgpu::graphite::DawnTextureInfo info(/*sampleCount=*/1,
+    skgpu::graphite::DawnTextureInfo info(skgpu::graphite::SampleCount::k1,
                                           skgpu::Mipmapped::kNo,
                                           fSurfaceFormat,
                                           texture.GetUsage(),