From 023f2e776eff285da50bcae18f44cb7216e9cc00 Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Fri, 9 Oct 2020 15:38:58 -0400 Subject: [PATCH] Use push constants cap in Metal. * Sets the cap and uses it for verifying vertex/fragmentBytes size instead of a magic number. * Also makes maxPushConstantsSize unsigned to avoid warnings and unnecessary casting. Change-Id: I2aaea853604eb3c652ddbae3adb0168a4e41799a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/324880 Reviewed-by: Greg Daniel Commit-Queue: Jim Van Verth --- src/gpu/GrCaps.h | 4 ++-- src/gpu/mtl/GrMtlCaps.mm | 2 ++ src/gpu/mtl/GrMtlPipelineStateDataManager.mm | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h index 89d729edf8..70be646606 100644 --- a/src/gpu/GrCaps.h +++ b/src/gpu/GrCaps.h @@ -204,7 +204,7 @@ public: return this->maxWindowRectangles() > 0 && this->onIsWindowRectanglesSupportedForRT(rt); } - int maxPushConstantsSize() const { return fMaxPushConstantsSize; } + uint32_t maxPushConstantsSize() const { return fMaxPushConstantsSize; } virtual bool isFormatSRGB(const GrBackendFormat&) const = 0; @@ -544,7 +544,7 @@ protected: int fMaxTileSize; int fMaxWindowRectangles; int fInternalMultisampleCount; - int fMaxPushConstantsSize = 0; + uint32_t fMaxPushConstantsSize = 0; GrDriverBugWorkarounds fDriverBugWorkarounds; diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm index 962f9b9a8d..09fdeb9c72 100644 --- a/src/gpu/mtl/GrMtlCaps.mm +++ b/src/gpu/mtl/GrMtlCaps.mm @@ -287,6 +287,8 @@ void GrMtlCaps::initGrCaps(const id device) { fMaxPreferredRenderTargetSize = fMaxRenderTargetSize; fMaxTextureSize = fMaxRenderTargetSize; + fMaxPushConstantsSize = 4*1024; + // Init sample counts. All devices support 1 (i.e. 0 in skia). fSampleCounts.push_back(1); if (@available(iOS 9.0, *)) { diff --git a/src/gpu/mtl/GrMtlPipelineStateDataManager.mm b/src/gpu/mtl/GrMtlPipelineStateDataManager.mm index 63722e1ef9..b8ed721155 100644 --- a/src/gpu/mtl/GrMtlPipelineStateDataManager.mm +++ b/src/gpu/mtl/GrMtlPipelineStateDataManager.mm @@ -332,7 +332,7 @@ void GrMtlPipelineStateDataManager::uploadAndBindUniformBuffers( id renderCmdEncoder) const { if (fUniformSize && fUniformsDirty) { if (@available(macOS 10.11, iOS 8.3, *)) { - SkASSERT(fUniformSize <= 4*1024); + SkASSERT(fUniformSize <= gpu->caps()->maxPushConstantsSize()); [renderCmdEncoder setVertexBytes: fUniformData.get() length: fUniformSize atIndex: GrMtlUniformHandler::kUniformBinding];