From 9565f4bd902b48b1c659feabbbfa46a10dadf8a5 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Tue, 15 Mar 2022 12:52:36 -0400 Subject: [PATCH] [graphite] Plumb Recorder down into KeyHelpers The KeyContext is used in the addToKey methods but must appear in the AddToKey methods bc the latter can call the former. Bug: skia:12701 Change-Id: I3143afec8337b1e3e12f1c3cc198714009ca6930 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/520539 Reviewed-by: Jim Van Verth Commit-Queue: Robert Phillips --- experimental/graphite/src/Context.cpp | 4 +- experimental/graphite/src/ContextUtils.cpp | 9 +- experimental/graphite/src/ContextUtils.h | 2 +- experimental/graphite/src/DrawPass.cpp | 2 +- experimental/graphite/src/PaintParams.cpp | 10 +-- experimental/graphite/src/PaintParams.h | 4 +- gn/core.gni | 2 + src/core/SkBlendModeBlender.cpp | 6 +- src/core/SkBlenderBase.h | 4 +- src/core/SkKeyContext.cpp | 26 ++++++ src/core/SkKeyContext.h | 53 ++++++++++++ src/core/SkKeyHelpers.cpp | 82 ++++++++++++------- src/core/SkKeyHelpers.h | 39 +++++---- src/core/SkPipelineData.cpp | 8 ++ src/core/SkPipelineData.h | 12 +++ src/core/SkShaderCodeDictionary.cpp | 11 ++- src/gpu/effects/GrTextureEffect.cpp | 5 +- src/image/SkImage.cpp | 6 +- src/shaders/SkColorShader.cpp | 8 +- src/shaders/SkColorShader.h | 4 +- src/shaders/SkComposeShader.cpp | 5 +- src/shaders/SkComposeShader.h | 2 +- src/shaders/SkImageShader.cpp | 23 +++++- src/shaders/SkImageShader.h | 4 +- src/shaders/SkShader.cpp | 4 +- src/shaders/SkShaderBase.h | 6 +- src/shaders/gradients/SkLinearGradient.cpp | 4 +- src/shaders/gradients/SkLinearGradient.h | 2 +- src/shaders/gradients/SkRadialGradient.cpp | 4 +- src/shaders/gradients/SkRadialGradient.h | 2 +- src/shaders/gradients/SkSweepGradient.cpp | 4 +- src/shaders/gradients/SkSweepGradient.h | 2 +- .../gradients/SkTwoPointConicalGradient.cpp | 4 +- .../gradients/SkTwoPointConicalGradient.h | 2 +- tests/graphite/CommandBufferTest.cpp | 7 +- tests/graphite/UniformTest.cpp | 9 +- 36 files changed, 277 insertions(+), 104 deletions(-) create mode 100644 src/core/SkKeyContext.cpp create mode 100644 src/core/SkKeyContext.h diff --git a/experimental/graphite/src/Context.cpp b/experimental/graphite/src/Context.cpp index 7b64b7f0b1..9e22aec376 100644 --- a/experimental/graphite/src/Context.cpp +++ b/experimental/graphite/src/Context.cpp @@ -19,6 +19,7 @@ #include "experimental/graphite/src/Renderer.h" #include "experimental/graphite/src/ResourceProvider.h" #include "include/core/SkPathTypes.h" +#include "src/core/SkKeyContext.h" #include "src/core/SkKeyHelpers.h" #include "src/core/SkShaderCodeDictionary.h" @@ -74,6 +75,7 @@ void Context::preCompile(const PaintCombo& paintCombo) { }; SkShaderCodeDictionary* dict = fGlobalCache->shaderCodeDictionary(); + SkKeyContext keyContext(dict); SkPaintParamsKeyBuilder builder(dict, SkBackend::kGraphite); @@ -81,7 +83,7 @@ void Context::preCompile(const PaintCombo& paintCombo) { for (auto& shaderCombo: paintCombo.fShaders) { for (auto shaderType: shaderCombo.fTypes) { for (auto tm: shaderCombo.fTileModes) { - auto uniqueID = CreateKey(dict, &builder, shaderType, tm, bm); + auto uniqueID = CreateKey(keyContext, &builder, shaderType, tm, bm); GraphicsPipelineDesc desc; diff --git a/experimental/graphite/src/ContextUtils.cpp b/experimental/graphite/src/ContextUtils.cpp index ba5f176482..02c7b94158 100644 --- a/experimental/graphite/src/ContextUtils.cpp +++ b/experimental/graphite/src/ContextUtils.cpp @@ -11,24 +11,29 @@ #include "experimental/graphite/src/PaintParams.h" #include "include/private/SkUniquePaintParamsID.h" #include "src/core/SkBlenderBase.h" +#include "src/core/SkKeyContext.h" #include "src/core/SkPipelineData.h" #include "src/core/SkShaderCodeDictionary.h" namespace skgpu { std::tuple> ExtractPaintData( - SkShaderCodeDictionary* dict, + Recorder* recorder, SkPaintParamsKeyBuilder* builder, const PaintParams& p) { SkDEBUGCODE(builder->checkReset()); + SkKeyContext keyContext(recorder); + std::unique_ptr pipelineData = std::make_unique(); - p.toKey(dict, builder, pipelineData.get()); + p.toKey(keyContext, builder, pipelineData.get()); SkPaintParamsKey key = builder->lockAsKey(); + auto dict = keyContext.dict(); + auto entry = dict->findOrCreate(key, pipelineData->blendInfo()); return { entry->uniqueID(), std::move(pipelineData) }; diff --git a/experimental/graphite/src/ContextUtils.h b/experimental/graphite/src/ContextUtils.h index 063995479e..9afcc2cb5c 100644 --- a/experimental/graphite/src/ContextUtils.h +++ b/experimental/graphite/src/ContextUtils.h @@ -25,7 +25,7 @@ namespace skgpu { class PaintParams; std::tuple> ExtractPaintData( - SkShaderCodeDictionary*, + Recorder*, SkPaintParamsKeyBuilder* builder, const PaintParams&); diff --git a/experimental/graphite/src/DrawPass.cpp b/experimental/graphite/src/DrawPass.cpp index 22530145f9..b7fd24ff20 100644 --- a/experimental/graphite/src/DrawPass.cpp +++ b/experimental/graphite/src/DrawPass.cpp @@ -305,7 +305,7 @@ std::unique_ptr DrawPass::Make(Recorder* recorder, uint32_t shadingIndex = PipelineDataCache::kInvalidUniformID; if (draw.fPaintParams.has_value()) { std::unique_ptr pipelineData; - std::tie(shaderID, pipelineData) = ExtractPaintData(dict, &builder, + std::tie(shaderID, pipelineData) = ExtractPaintData(recorder, &builder, draw.fPaintParams.value()); shadingIndex = shadingUniformBindings.addUniforms(std::move(pipelineData)); } // else depth-only diff --git a/experimental/graphite/src/PaintParams.cpp b/experimental/graphite/src/PaintParams.cpp index 186dc587c3..2248f4fcae 100644 --- a/experimental/graphite/src/PaintParams.cpp +++ b/experimental/graphite/src/PaintParams.cpp @@ -40,20 +40,20 @@ sk_sp PaintParams::refBlender() const { return fBlender; } sk_sp PaintParams::refShader() const { return fShader; } -void PaintParams::toKey(SkShaderCodeDictionary* dict, +void PaintParams::toKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData) const { if (fShader) { - as_SB(fShader)->addToKey(dict, builder, pipelineData); + as_SB(fShader)->addToKey(keyContext, builder, pipelineData); } else { - SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, fColor.premul()); + SolidColorShaderBlock::AddToKey(keyContext, builder, pipelineData, fColor.premul()); } if (fBlender) { - as_BB(fBlender)->addToKey(dict, builder, pipelineData); + as_BB(fBlender)->addToKey(keyContext, builder, pipelineData); } else { - BlendModeBlock::AddToKey(dict, builder, pipelineData, SkBlendMode::kSrcOver); + BlendModeBlock::AddToKey(keyContext, builder, pipelineData, SkBlendMode::kSrcOver); } SkASSERT(builder->sizeInBytes() > 0); diff --git a/experimental/graphite/src/PaintParams.h b/experimental/graphite/src/PaintParams.h index 6fe085da30..43a2c86aa0 100644 --- a/experimental/graphite/src/PaintParams.h +++ b/experimental/graphite/src/PaintParams.h @@ -15,7 +15,7 @@ enum class SkBackend : uint8_t; class SkPaintParamsKeyBuilder; class SkPipelineData; class SkShader; -class SkShaderCodeDictionary; +class SkKeyContext; namespace skgpu { @@ -44,7 +44,7 @@ public: SkShader* shader() const { return fShader.get(); } sk_sp refShader() const; - void toKey(SkShaderCodeDictionary*, + void toKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*) const; diff --git a/gn/core.gni b/gn/core.gni index 026d16aa8f..ed74966894 100644 --- a/gn/core.gni +++ b/gn/core.gni @@ -247,6 +247,8 @@ skia_core_sources = [ "$_src/core/SkImageFilter_Base.h", "$_src/core/SkImageGenerator.cpp", "$_src/core/SkImageInfo.cpp", + "$_src/core/SkKeyContext.cpp", + "$_src/core/SkKeyContext.h", "$_src/core/SkKeyHelpers.cpp", "$_src/core/SkKeyHelpers.h", "$_src/core/SkLRUCache.h", diff --git a/src/core/SkBlendModeBlender.cpp b/src/core/SkBlendModeBlender.cpp index 919cb599cf..d903bed23e 100644 --- a/src/core/SkBlendModeBlender.cpp +++ b/src/core/SkBlendModeBlender.cpp @@ -64,14 +64,14 @@ sk_sp SkBlender::Mode(SkBlendMode mode) { } #ifdef SK_ENABLE_SKSL -void SkBlenderBase::addToKey(SkShaderCodeDictionary* dict, +void SkBlenderBase::addToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData) const { if (std::optional bm = as_BB(this)->asBlendMode(); bm.has_value()) { - BlendModeBlock::AddToKey(dict, builder, pipelineData, bm.value()); + BlendModeBlock::AddToKey(keyContext, builder, pipelineData, bm.value()); } else { - BlendModeBlock::AddToKey(dict, builder, pipelineData, SkBlendMode::kSrcOver); + BlendModeBlock::AddToKey(keyContext, builder, pipelineData, SkBlendMode::kSrcOver); } } #endif diff --git a/src/core/SkBlenderBase.h b/src/core/SkBlenderBase.h index 697cd03c40..c2b48dabf9 100644 --- a/src/core/SkBlenderBase.h +++ b/src/core/SkBlenderBase.h @@ -21,7 +21,7 @@ class SkColorInfo; class SkPaintParamsKeyBuilder; class SkPipelineData; class SkRuntimeEffect; -class SkShaderCodeDictionary; +class SkKeyContext; /** * Encapsulates a blend function, including non-public APIs. @@ -59,7 +59,7 @@ public: #ifdef SK_ENABLE_SKSL // TODO: make pure virtual - virtual void addToKey(SkShaderCodeDictionary*, + virtual void addToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*) const; #endif diff --git a/src/core/SkKeyContext.cpp b/src/core/SkKeyContext.cpp new file mode 100644 index 0000000000..348f9f48b3 --- /dev/null +++ b/src/core/SkKeyContext.cpp @@ -0,0 +1,26 @@ +/* + * Copyright 2022 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "src/core/SkKeyContext.h" + +#ifdef SK_GRAPHITE_ENABLED +#include "experimental/graphite/src/RecorderPriv.h" +#include "experimental/graphite/src/ResourceProvider.h" + +SkKeyContext::SkKeyContext(skgpu::Recorder* recorder) : fRecorder(recorder) { + fDictionary = fRecorder->priv().resourceProvider()->shaderCodeDictionary(); +} +#endif + +#if SK_SUPPORT_GPU +#include "include/gpu/GrRecordingContext.h" + +SkKeyContext::SkKeyContext(GrRecordingContext* rContext) : fRecordingContext(rContext) { + // TODO: fill this out for Ganesh + fDictionary = nullptr; +} +#endif diff --git a/src/core/SkKeyContext.h b/src/core/SkKeyContext.h new file mode 100644 index 0000000000..f21fbd42d4 --- /dev/null +++ b/src/core/SkKeyContext.h @@ -0,0 +1,53 @@ +/* + * Copyright 2022 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkKeyContext_DEFINED +#define SkKeyContext_DEFINED + +#include "include/gpu/GrTypes.h" + +#ifdef SK_GRAPHITE_ENABLED +namespace skgpu { class Recorder; } +#endif + +#if SK_SUPPORT_GPU +class GrRecordingContext; +#endif + +class SkShaderCodeDictionary; + +// The key context must always be able to provide a valid SkShaderCodeDictionary. Depending +// on the calling context it can also supply a backend-specific resource providing +// object (e.g., a Recorder). +class SkKeyContext { +public: + // Constructor for the pre-compile code path + SkKeyContext(SkShaderCodeDictionary* dict) : fDictionary(dict) {} +#ifdef SK_GRAPHITE_ENABLED + SkKeyContext(skgpu::Recorder*); + skgpu::Recorder* recorder() const { return fRecorder; } +#endif +#if SK_SUPPORT_GPU + SkKeyContext(GrRecordingContext*); + GrRecordingContext* recordingContext() const { return fRecordingContext; } +#endif + + SkShaderCodeDictionary* dict() const { return fDictionary; } + +private: +#ifdef SK_GRAPHITE_ENABLED + skgpu::Recorder* fRecorder = nullptr; +#endif + +#if SK_SUPPORT_GPU + GrRecordingContext* fRecordingContext = nullptr; +#endif + + SkShaderCodeDictionary* fDictionary; +}; + +#endif // SkKeyContext_DEFINED diff --git a/src/core/SkKeyHelpers.cpp b/src/core/SkKeyHelpers.cpp index 4eeb1048a4..b0663c15c7 100644 --- a/src/core/SkKeyHelpers.cpp +++ b/src/core/SkKeyHelpers.cpp @@ -8,6 +8,7 @@ #include "src/core/SkKeyHelpers.h" #include "src/core/SkDebugUtils.h" +#include "src/core/SkKeyContext.h" #include "src/core/SkPaintParamsKey.h" #include "src/core/SkPipelineData.h" #include "src/core/SkShaderCodeDictionary.h" @@ -15,6 +16,7 @@ #include "src/shaders/SkShaderBase.h" #ifdef SK_GRAPHITE_ENABLED +#include "experimental/graphite/src/TextureProxy.h" #include "experimental/graphite/src/UniformManager.h" #include "src/gpu/Blend.h" #endif @@ -49,7 +51,7 @@ namespace DepthStencilOnlyBlock { static const int kBlockDataSize = 0; -void AddToKey(SkShaderCodeDictionary* /* dict */, +void AddToKey(const SkKeyContext& /* keyContext */, SkPaintParamsKeyBuilder* builder, SkPipelineData* /* pipelineData */) { builder->beginBlock(SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw); @@ -92,13 +94,15 @@ sk_sp make_solid_uniform_data(SkShaderCodeDictionary* dict, } // anonymous namespace -void AddToKey(SkShaderCodeDictionary* dict, +void AddToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData, const SkPMColor4f& premulColor) { #ifdef SK_GRAPHITE_ENABLED if (builder->backend() == SkBackend::kGraphite) { + auto dict = keyContext.dict(); + builder->beginBlock(SkBuiltInCodeSnippetID::kSolidColorShader); builder->endBlock(); @@ -274,13 +278,14 @@ GradientData::GradientData(SkShader::GradientType type, } } -void AddToKey(SkShaderCodeDictionary* dict, +void AddToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder *builder, SkPipelineData* pipelineData, const GradientData& gradData) { #ifdef SK_GRAPHITE_ENABLED if (builder->backend() == SkBackend::kGraphite) { + auto dict = keyContext.dict(); SkBuiltInCodeSnippetID codeSnippetID = SkBuiltInCodeSnippetID::kSolidColorShader; switch (gradData.fType) { case SkShader::kLinear_GradientType: @@ -328,7 +333,7 @@ void AddToKey(SkShaderCodeDictionary* dict, if (builder->backend() == SkBackend::kSkVM || builder->backend() == SkBackend::kGanesh) { // TODO: add implementation of other backends - SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, kErrorColor); + SolidColorShaderBlock::AddToKey(keyContext, builder, pipelineData, kErrorColor); } } @@ -341,11 +346,9 @@ namespace { #ifdef SK_GRAPHITE_ENABLED -// For now, the image shader doesn't have any uniforms. This will probably change. -#if 0 sk_sp make_image_uniform_data(SkShaderCodeDictionary* dict, const ImageData& imgData) { - SkDEBUGCODE(static constexpr size_t kExpectedNumUniforms = 0;) + static constexpr size_t kExpectedNumUniforms = 1; SkSpan uniforms = dict->getUniforms(SkBuiltInCodeSnippetID::kImageShader); SkASSERT(uniforms.size() == kExpectedNumUniforms); @@ -357,23 +360,42 @@ sk_sp make_image_uniform_data(SkShaderCodeDictionary* dict, sk_sp result = SkUniformData::Make(uniforms, dataSize); // TODO: add the required data to ImageData and assemble the uniforms here + const void* srcs[kExpectedNumUniforms] = { &imgData.fSubset }; - mgr.writeUniforms(result->uniforms(), nullptr, result->offsets(), result->data()); + mgr.writeUniforms(result->uniforms(), srcs, result->offsets(), result->data()); return result; } -#endif #endif // SK_GRAPHITE_ENABLED } // anonymous namespace -void AddToKey(SkShaderCodeDictionary* dict, +ImageData::ImageData(const SkSamplingOptions& sampling, + SkTileMode tileModeX, + SkTileMode tileModeY, + SkRect subset) + : fSampling(sampling) + , fTileModes{tileModeX, tileModeY} + , fSubset(subset) { +} + +void AddToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData, const ImageData& imgData) { #ifdef SK_GRAPHITE_ENABLED if (builder->backend() == SkBackend::kGraphite) { + if (pipelineData && !imgData.fTextureProxy) { + // We're dropping the ImageShader here. This could be an instance of trying to draw + // a raster-backed image w/ a Graphite-backed canvas. + // TODO: At some point the pre-compile path should also be creating a texture + // proxy (i.e., we can remove the 'pipelineData' in the above test). + SolidColorShaderBlock::AddToKey(keyContext, builder, pipelineData, kErrorColor); + return; + } + + auto dict = keyContext.dict(); builder->beginBlock(SkBuiltInCodeSnippetID::kImageShader); // TODO: bytes are overkill for just tilemodes. We could add smaller/bit-width @@ -384,12 +406,13 @@ void AddToKey(SkShaderCodeDictionary* dict, builder->endBlock(); - // For now, the image shader doesn't have any uniforms. This will probably change. -#if 0 if (pipelineData) { + pipelineData->addImage(imgData.fSampling, + imgData.fTileModes, + std::move(imgData.fTextureProxy)); + pipelineData->add(make_image_uniform_data(dict, imgData)); } -#endif return; } @@ -397,7 +420,7 @@ void AddToKey(SkShaderCodeDictionary* dict, if (builder->backend() == SkBackend::kSkVM || builder->backend() == SkBackend::kGanesh) { // TODO: add implementation for other backends - SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, kErrorColor); + SolidColorShaderBlock::AddToKey(keyContext, builder, pipelineData, kErrorColor); } } @@ -433,13 +456,14 @@ sk_sp make_blendshader_uniform_data(SkShaderCodeDictionary* dict, } // anonymous namespace -void AddToKey(SkShaderCodeDictionary* dict, +void AddToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder *builder, SkPipelineData* pipelineData, const BlendData& blendData) { #ifdef SK_GRAPHITE_ENABLED if (builder->backend() == SkBackend::kGraphite) { + auto dict = keyContext.dict(); // When extracted into SkShaderInfo::SnippetEntries the children will appear after their // parent. Thus, the parent's uniform data must appear in the uniform block before the // uniform data of the children. @@ -453,11 +477,11 @@ void AddToKey(SkShaderCodeDictionary* dict, // TODO: add startChild/endChild entry points to SkPaintParamsKeyBuilder. They could be // used to compute and store the number of children w/in a block's header. int start = builder->sizeInBytes(); - as_SB(blendData.fDst)->addToKey(dict, builder, pipelineData); + as_SB(blendData.fDst)->addToKey(keyContext, builder, pipelineData); int firstShaderSize = builder->sizeInBytes() - start; start = builder->sizeInBytes(); - as_SB(blendData.fSrc)->addToKey(dict, builder, pipelineData); + as_SB(blendData.fSrc)->addToKey(keyContext, builder, pipelineData); int secondShaderSize = builder->sizeInBytes() - start; builder->endBlock(); @@ -472,7 +496,7 @@ void AddToKey(SkShaderCodeDictionary* dict, if (builder->backend() == SkBackend::kSkVM || builder->backend() == SkBackend::kGanesh) { // TODO: add implementation for other backends - SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, kErrorColor); + SolidColorShaderBlock::AddToKey(keyContext, builder, pipelineData, kErrorColor); } } @@ -528,7 +552,7 @@ static const int kFixedFunctionBlockDataSize = 1; static const int kShaderBasedBlockDataSize = 1; #endif -void AddToKey(SkShaderCodeDictionary* dict, +void AddToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder *builder, SkPipelineData* pipelineData, SkBlendMode bm) { @@ -567,7 +591,7 @@ void AddToKey(SkShaderCodeDictionary* dict, if (builder->backend() == SkBackend::kSkVM || builder->backend() == SkBackend::kGanesh) { // TODO: add implementation for other backends - SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, kErrorColor); + SolidColorShaderBlock::AddToKey(keyContext, builder, pipelineData, kErrorColor); } } @@ -575,7 +599,7 @@ void AddToKey(SkShaderCodeDictionary* dict, //-------------------------------------------------------------------------------------------------- #ifdef SK_GRAPHITE_ENABLED -SkUniquePaintParamsID CreateKey(SkShaderCodeDictionary* dict, +SkUniquePaintParamsID CreateKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, skgpu::ShaderCombo::ShaderType s, SkTileMode tm, @@ -584,34 +608,36 @@ SkUniquePaintParamsID CreateKey(SkShaderCodeDictionary* dict, switch (s) { case skgpu::ShaderCombo::ShaderType::kNone: - DepthStencilOnlyBlock::AddToKey(dict, builder, nullptr); + DepthStencilOnlyBlock::AddToKey(keyContext, builder, nullptr); break; case skgpu::ShaderCombo::ShaderType::kSolidColor: - SolidColorShaderBlock::AddToKey(dict, builder, nullptr, kErrorColor); + SolidColorShaderBlock::AddToKey(keyContext, builder, nullptr, kErrorColor); break; case skgpu::ShaderCombo::ShaderType::kLinearGradient: - GradientShaderBlocks::AddToKey(dict, builder, nullptr, + GradientShaderBlocks::AddToKey(keyContext, builder, nullptr, { SkShader::kLinear_GradientType, tm, 0 }); break; case skgpu::ShaderCombo::ShaderType::kRadialGradient: - GradientShaderBlocks::AddToKey(dict, builder, nullptr, + GradientShaderBlocks::AddToKey(keyContext, builder, nullptr, { SkShader::kRadial_GradientType, tm, 0 }); break; case skgpu::ShaderCombo::ShaderType::kSweepGradient: - GradientShaderBlocks::AddToKey(dict, builder, nullptr, + GradientShaderBlocks::AddToKey(keyContext, builder, nullptr, { SkShader::kSweep_GradientType, tm, 0 }); break; case skgpu::ShaderCombo::ShaderType::kConicalGradient: - GradientShaderBlocks::AddToKey(dict, builder, nullptr, + GradientShaderBlocks::AddToKey(keyContext, builder, nullptr, { SkShader::kConical_GradientType, tm, 0 }); break; } // TODO: the blendInfo should be filled in by BlendModeBlock::AddToKey SkPipelineData::BlendInfo blendInfo = get_blend_info(bm); - BlendModeBlock::AddToKey(dict, builder, /* pipelineData*/ nullptr, bm); + BlendModeBlock::AddToKey(keyContext, builder, /* pipelineData*/ nullptr, bm); SkPaintParamsKey key = builder->lockAsKey(); + auto dict = keyContext.dict(); + auto entry = dict->findOrCreate(key, blendInfo); return entry->uniqueID(); diff --git a/src/core/SkKeyHelpers.h b/src/core/SkKeyHelpers.h index abe3e71a09..aba62f6f2c 100644 --- a/src/core/SkKeyHelpers.h +++ b/src/core/SkKeyHelpers.h @@ -13,21 +13,24 @@ #endif #include "include/core/SkBlendMode.h" +#include "include/core/SkSamplingOptions.h" #include "include/core/SkShader.h" #include "include/core/SkTileMode.h" #include "include/private/SkColorData.h" enum class SkBackend : uint8_t; class SkPaintParamsKeyBuilder; -class SkShaderCodeDictionary; class SkPipelineData; class SkUniquePaintParamsID; +class SkKeyContext; + +namespace skgpu { class TextureProxy; } // The KeyHelpers can be used to manually construct an SkPaintParamsKey namespace DepthStencilOnlyBlock { - void AddToKey(SkShaderCodeDictionary*, + void AddToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*); @@ -35,7 +38,7 @@ namespace DepthStencilOnlyBlock { namespace SolidColorShaderBlock { - void AddToKey(SkShaderCodeDictionary*, + void AddToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*, const SkPMColor4f&); @@ -88,7 +91,7 @@ namespace GradientShaderBlocks { float fOffsets[kMaxStops]; }; - void AddToKey(SkShaderCodeDictionary*, + void AddToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*, const GradientData&); @@ -98,18 +101,24 @@ namespace GradientShaderBlocks { namespace ImageShaderBlock { struct ImageData { - bool operator==(const ImageData& rhs) const { - return fTileModes[0] == rhs.fTileModes[0] && - fTileModes[1] == rhs.fTileModes[1]; - } - bool operator!=(const ImageData& rhs) const { return !(*this == rhs); } + ImageData(const SkSamplingOptions& sampling, + SkTileMode tileModeX, + SkTileMode tileModeY, + SkRect subset); - // TODO: add the other image shader parameters that could impact code snippet selection - // (e.g., sampling options, subsetting, etc.) + SkSamplingOptions fSampling; SkTileMode fTileModes[2]; + SkRect fSubset; + +#ifdef SK_GRAPHITE_ENABLED + // TODO: Currently this is only filled in when we're generating the key from an actual + // SkImageShader. In the pre-compile case we will need to create a Graphite promise + // image which holds the appropriate data. + sk_sp fTextureProxy; +#endif }; - void AddToKey(SkShaderCodeDictionary*, + void AddToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*, const ImageData&); @@ -125,7 +134,7 @@ namespace BlendShaderBlock { SkBlendMode fBM; }; - void AddToKey(SkShaderCodeDictionary*, + void AddToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*, const BlendData&); @@ -134,7 +143,7 @@ namespace BlendShaderBlock { namespace BlendModeBlock { - void AddToKey(SkShaderCodeDictionary*, + void AddToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*, SkBlendMode); @@ -143,7 +152,7 @@ namespace BlendModeBlock { #ifdef SK_GRAPHITE_ENABLED // Bridge between the combinations system and the SkPaintParamsKey -SkUniquePaintParamsID CreateKey(SkShaderCodeDictionary*, +SkUniquePaintParamsID CreateKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, skgpu::ShaderCombo::ShaderType, SkTileMode, diff --git a/src/core/SkPipelineData.cpp b/src/core/SkPipelineData.cpp index 58d3e8bfd6..71215a47a8 100644 --- a/src/core/SkPipelineData.cpp +++ b/src/core/SkPipelineData.cpp @@ -18,6 +18,14 @@ void SkPipelineData::add(sk_sp uniforms) { fUniformData.push_back(std::move(uniforms)); } +#ifdef SK_GRAPHITE_ENABLED +void SkPipelineData::addImage(const SkSamplingOptions& sampling, + const SkTileMode tileModes[2], + sk_sp proxy) { + fProxies.push_back({std::move(proxy), sampling, {tileModes[0], tileModes[1]}}); +} +#endif + size_t SkPipelineData::totalUniformSize() const { size_t total = 0; diff --git a/src/core/SkPipelineData.h b/src/core/SkPipelineData.h index a4e7a30293..9e63b6bd58 100644 --- a/src/core/SkPipelineData.h +++ b/src/core/SkPipelineData.h @@ -10,10 +10,13 @@ #include #include "include/core/SkRefCnt.h" +#include "include/core/SkSamplingOptions.h" +#include "include/core/SkTileMode.h" #include "include/private/SkColorData.h" #include "src/core/SkUniformData.h" #ifdef SK_GRAPHITE_ENABLED +#include "experimental/graphite/src/TextureProxy.h" #include "src/gpu/Blend.h" #endif @@ -49,6 +52,8 @@ public: fBlendInfo = blendInfo; } const BlendInfo& blendInfo() const { return fBlendInfo; } + + void addImage(const SkSamplingOptions&, const SkTileMode[2], sk_sp); #endif void add(sk_sp); @@ -75,6 +80,13 @@ private: std::vector> fUniformData; #ifdef SK_GRAPHITE_ENABLED + struct TextureInfo { + sk_sp fProxy; + SkSamplingOptions fSamplingOptions; + SkTileMode fTileModes[2]; + }; + + std::vector fProxies; BlendInfo fBlendInfo; #endif }; diff --git a/src/core/SkShaderCodeDictionary.cpp b/src/core/SkShaderCodeDictionary.cpp index 806c4b207f..09d102d26d 100644 --- a/src/core/SkShaderCodeDictionary.cpp +++ b/src/core/SkShaderCodeDictionary.cpp @@ -320,11 +320,14 @@ static const char* kSolidShaderSkSL = "}\n"; //-------------------------------------------------------------------------------------------------- -static constexpr int kNumImageShaderUniforms = 0; +static constexpr int kNumImageShaderUniforms = 1; +static constexpr SkUniform kImageShaderUniforms[kNumImageShaderUniforms] = { + { "subset", SkSLType::kFloat4 }, +}; static const char* kImageShaderName = "image_shader"; static const char* kImageShaderSkSL = - "half4 image_shader() {\n" + "half4 image_shader(float4 subset) {\n" " float c = fract(abs(sk_FragCoord.x/10.0));\n" " return half4(1.0, 1.0 - c, 1.0 - c, 1.0);\n" "}\n"; @@ -596,7 +599,7 @@ SkShaderCodeDictionary::SkShaderCodeDictionary() { { kLinearGrad4Fields, kNumLinearGrad4Fields } }; fBuiltInCodeSnippets[(int) SkBuiltInCodeSnippetID::kImageShader] = { - { nullptr, kNumImageShaderUniforms }, + SkMakeSpan(kImageShaderUniforms, kNumImageShaderUniforms), kImageShaderName, kImageShaderSkSL, GenerateDefaultGlueCode, kNoChildren, @@ -611,7 +614,7 @@ SkShaderCodeDictionary::SkShaderCodeDictionary() { }; fBuiltInCodeSnippets[(int) SkBuiltInCodeSnippetID::kFixedFunctionBlender] = { { }, // no uniforms - "", "", // fixed function blending doesn't have any static SkSL + "FF-blending", "", // fixed function blending doesn't have any static SkSL GenerateFixedFunctionBlenderGlueCode, kNoChildren, { kFixedFunctionBlenderFields, kNumFixedFunctionBlenderFields } diff --git a/src/gpu/effects/GrTextureEffect.cpp b/src/gpu/effects/GrTextureEffect.cpp index 98076d5dad..9153a974f5 100644 --- a/src/gpu/effects/GrTextureEffect.cpp +++ b/src/gpu/effects/GrTextureEffect.cpp @@ -498,8 +498,9 @@ void GrTextureEffect::Impl::emitCode(EmitArgs& args) { const char* clampStopSwizzle) { if (clamp) { fb->codeAppendf("clampedCoord%s = clamp(subsetCoord%s, %s%s, %s%s);", - coordSwizzle, coordSwizzle, clampName, clampStartSwizzle, clampName, - clampStopSwizzle); + coordSwizzle, coordSwizzle, + clampName, clampStartSwizzle, + clampName, clampStopSwizzle); } else { fb->codeAppendf("clampedCoord%s = subsetCoord%s;", coordSwizzle, coordSwizzle); } diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 19d35364e8..de5975089b 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -453,6 +453,8 @@ GrBackendTexture SkImage_Base::onGetBackendTexture(bool flushPendingGrContextIO, return GrBackendTexture(); // invalid } +#endif // SK_SUPPORT_GPU + #ifdef SK_GRAPHITE_ENABLED std::tuple SkImage_Base::asView( skgpu::Recorder* recorder, skgpu::Mipmapped mipmapped) const { @@ -464,9 +466,7 @@ std::tuple SkImage_Base::asView( } return this->onAsView(recorder, mipmapped); } -#endif - -#endif // SK_SUPPORT_GPU +#endif // SK_GRAPHITE_ENABLED GrDirectContext* SkImage_Base::directContext() const { #if SK_SUPPORT_GPU diff --git a/src/shaders/SkColorShader.cpp b/src/shaders/SkColorShader.cpp index f21d831fd1..faacbd526c 100644 --- a/src/shaders/SkColorShader.cpp +++ b/src/shaders/SkColorShader.cpp @@ -141,16 +141,16 @@ std::unique_ptr SkColor4Shader::asFragmentProcessor( #endif #ifdef SK_ENABLE_SKSL -void SkColorShader::addToKey(SkShaderCodeDictionary* dict, +void SkColorShader::addToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData) const { - SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, + SolidColorShaderBlock::AddToKey(keyContext, builder, pipelineData, SkColor4f::FromColor(fColor).premul()); } -void SkColor4Shader::addToKey(SkShaderCodeDictionary* dict, +void SkColor4Shader::addToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData) const { - SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, fColor.premul()); + SolidColorShaderBlock::AddToKey(keyContext, builder, pipelineData, fColor.premul()); } #endif diff --git a/src/shaders/SkColorShader.h b/src/shaders/SkColorShader.h index 27f615c06b..c4dcd8106d 100644 --- a/src/shaders/SkColorShader.h +++ b/src/shaders/SkColorShader.h @@ -35,7 +35,7 @@ public: #endif #ifdef SK_ENABLE_SKSL - void addToKey(SkShaderCodeDictionary*, + void addToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*) const override; #endif @@ -70,7 +70,7 @@ public: std::unique_ptr asFragmentProcessor(const GrFPArgs&) const override; #endif #ifdef SK_ENABLE_SKSL - void addToKey(SkShaderCodeDictionary*, + void addToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*) const override; #endif diff --git a/src/shaders/SkComposeShader.cpp b/src/shaders/SkComposeShader.cpp index 91b6a693c9..3c489de811 100644 --- a/src/shaders/SkComposeShader.cpp +++ b/src/shaders/SkComposeShader.cpp @@ -193,12 +193,13 @@ std::unique_ptr SkShader_Blend::asFragmentProcessor( #endif #ifdef SK_ENABLE_SKSL -void SkShader_Blend::addToKey(SkShaderCodeDictionary* dict, +void SkShader_Blend::addToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData) const { // TODO: add blender support SkASSERT(!fBlender); - BlendShaderBlock::AddToKey(dict, builder, pipelineData, { fDst.get(), fSrc.get(), fMode }); + BlendShaderBlock::AddToKey(keyContext, builder, pipelineData, + { fDst.get(), fSrc.get(), fMode }); } #endif diff --git a/src/shaders/SkComposeShader.h b/src/shaders/SkComposeShader.h index c51c5e7983..65636bec34 100644 --- a/src/shaders/SkComposeShader.h +++ b/src/shaders/SkComposeShader.h @@ -31,7 +31,7 @@ public: #endif #ifdef SK_ENABLE_SKSL - void addToKey(SkShaderCodeDictionary*, + void addToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*) const override; #endif diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp index e420000317..651377fa15 100755 --- a/src/shaders/SkImageShader.cpp +++ b/src/shaders/SkImageShader.cpp @@ -27,6 +27,12 @@ #include "src/shaders/SkTransformShader.h" #ifdef SK_ENABLE_SKSL + +#ifdef SK_GRAPHITE_ENABLED +#include "experimental/graphite/src/Image_Graphite.h" +#endif + +#include "src/core/SkKeyContext.h" #include "src/core/SkKeyHelpers.h" #endif @@ -379,10 +385,23 @@ std::unique_ptr SkImageShader::asFragmentProcessor( #endif #ifdef SK_ENABLE_SKSL -void SkImageShader::addToKey(SkShaderCodeDictionary* dict, +void SkImageShader::addToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData) const { - ImageShaderBlock::AddToKey(dict, builder, pipelineData, { fTileModeX, fTileModeY }); + ImageShaderBlock::ImageData imgData(fSampling, fTileModeX, fTileModeY, fSubset); + +#ifdef SK_GRAPHITE_ENABLED + if (as_IB(fImage)->isGraphiteBacked()) { + skgpu::Image* grImage = static_cast(fImage.get()); + + auto mipmapped = (fSampling.mipmap != SkMipmapMode::kNone) ? skgpu::Mipmapped::kYes + : skgpu::Mipmapped::kNo; + auto[view, ct] = grImage->asView(keyContext.recorder(), mipmapped); + imgData.fTextureProxy = view.refProxy(); + } +#endif + + ImageShaderBlock::AddToKey(keyContext, builder, pipelineData, imgData); } #endif diff --git a/src/shaders/SkImageShader.h b/src/shaders/SkImageShader.h index 1d46bbd8ee..04de7195ea 100644 --- a/src/shaders/SkImageShader.h +++ b/src/shaders/SkImageShader.h @@ -13,7 +13,7 @@ #include "src/shaders/SkBitmapProcShader.h" #include "src/shaders/SkShaderBase.h" -class SkShaderCodeDictionary; +class SkKeyContext; class SkImageShader : public SkShaderBase { public: @@ -46,7 +46,7 @@ public: std::unique_ptr asFragmentProcessor(const GrFPArgs&) const override; #endif #ifdef SK_ENABLE_SKSL - void addToKey(SkShaderCodeDictionary*, + void addToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*) const override; #endif diff --git a/src/shaders/SkShader.cpp b/src/shaders/SkShader.cpp index ded608c73d..5851828e5d 100644 --- a/src/shaders/SkShader.cpp +++ b/src/shaders/SkShader.cpp @@ -154,10 +154,10 @@ SkUpdatableShader* SkShaderBase::onUpdatableShader(SkArenaAlloc* alloc) const { #ifdef SK_ENABLE_SKSL // TODO: add implementations for derived classes -void SkShaderBase::addToKey(SkShaderCodeDictionary* dict, +void SkShaderBase::addToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData) const { - SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, {1, 0, 0, 1}); + SolidColorShaderBlock::AddToKey(keyContext, builder, pipelineData, {1, 0, 0, 1}); } #endif diff --git a/src/shaders/SkShaderBase.h b/src/shaders/SkShaderBase.h index 2c0257b978..d3e130a7f3 100644 --- a/src/shaders/SkShaderBase.h +++ b/src/shaders/SkShaderBase.h @@ -33,7 +33,7 @@ class SkPaintParamsKeyBuilder; class SkPipelineData; class SkRasterPipeline; class SkRuntimeEffect; -class SkShaderCodeDictionary; +class SkKeyContext; class SkStageUpdater; class SkUpdatableShader; @@ -219,11 +219,11 @@ public: Add implementation details, for the specified backend, of this SkShader to the provided key. - @param dictionary dictionary of code fragments available to be used in the key + @param keyContext backend context for key creation @param builder builder for creating the key for this SkShader @param pipelineData if non-null, storage for this shader's data */ - virtual void addToKey(SkShaderCodeDictionary* dictionary, + virtual void addToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData) const; #endif diff --git a/src/shaders/gradients/SkLinearGradient.cpp b/src/shaders/gradients/SkLinearGradient.cpp index 31446f698e..78387f9060 100644 --- a/src/shaders/gradients/SkLinearGradient.cpp +++ b/src/shaders/gradients/SkLinearGradient.cpp @@ -109,7 +109,7 @@ std::unique_ptr SkLinearGradient::asFragmentProcessor( #endif #ifdef SK_ENABLE_SKSL -void SkLinearGradient::addToKey(SkShaderCodeDictionary* dict, +void SkLinearGradient::addToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData) const { GradientShaderBlocks::GradientData data(kLinear_GradientType, @@ -120,6 +120,6 @@ void SkLinearGradient::addToKey(SkShaderCodeDictionary* dict, fOrigColors4f, fOrigPos); - GradientShaderBlocks::AddToKey(dict, builder, pipelineData, data); + GradientShaderBlocks::AddToKey(keyContext, builder, pipelineData, data); } #endif diff --git a/src/shaders/gradients/SkLinearGradient.h b/src/shaders/gradients/SkLinearGradient.h index 765646ccb0..1a839aa09d 100644 --- a/src/shaders/gradients/SkLinearGradient.h +++ b/src/shaders/gradients/SkLinearGradient.h @@ -21,7 +21,7 @@ public: std::unique_ptr asFragmentProcessor(const GrFPArgs&) const override; #endif #ifdef SK_ENABLE_SKSL - void addToKey(SkShaderCodeDictionary*, + void addToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*) const override; #endif diff --git a/src/shaders/gradients/SkRadialGradient.cpp b/src/shaders/gradients/SkRadialGradient.cpp index d1791ddf98..61d9f975f9 100644 --- a/src/shaders/gradients/SkRadialGradient.cpp +++ b/src/shaders/gradients/SkRadialGradient.cpp @@ -87,7 +87,7 @@ std::unique_ptr SkRadialGradient::asFragmentProcessor( #endif #ifdef SK_ENABLE_SKSL -void SkRadialGradient::addToKey(SkShaderCodeDictionary* dict, +void SkRadialGradient::addToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData) const { GradientShaderBlocks::GradientData data(kRadial_GradientType, @@ -98,6 +98,6 @@ void SkRadialGradient::addToKey(SkShaderCodeDictionary* dict, fOrigColors4f, fOrigPos); - GradientShaderBlocks::AddToKey(dict, builder, pipelineData, data); + GradientShaderBlocks::AddToKey(keyContext, builder, pipelineData, data); } #endif diff --git a/src/shaders/gradients/SkRadialGradient.h b/src/shaders/gradients/SkRadialGradient.h index 4c2fac0fe7..3d67def8fc 100644 --- a/src/shaders/gradients/SkRadialGradient.h +++ b/src/shaders/gradients/SkRadialGradient.h @@ -21,7 +21,7 @@ public: std::unique_ptr asFragmentProcessor(const GrFPArgs&) const override; #endif #ifdef SK_ENABLE_SKSL - void addToKey(SkShaderCodeDictionary*, + void addToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*) const override; #endif diff --git a/src/shaders/gradients/SkSweepGradient.cpp b/src/shaders/gradients/SkSweepGradient.cpp index 96b239dc15..1572c44981 100644 --- a/src/shaders/gradients/SkSweepGradient.cpp +++ b/src/shaders/gradients/SkSweepGradient.cpp @@ -111,7 +111,7 @@ std::unique_ptr SkSweepGradient::asFragmentProcessor( #endif #ifdef SK_ENABLE_SKSL -void SkSweepGradient::addToKey(SkShaderCodeDictionary* dict, +void SkSweepGradient::addToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData) const { GradientShaderBlocks::GradientData data(kSweep_GradientType, @@ -122,6 +122,6 @@ void SkSweepGradient::addToKey(SkShaderCodeDictionary* dict, fOrigColors4f, fOrigPos); - GradientShaderBlocks::AddToKey(dict, builder, pipelineData, data); + GradientShaderBlocks::AddToKey(keyContext, builder, pipelineData, data); } #endif diff --git a/src/shaders/gradients/SkSweepGradient.h b/src/shaders/gradients/SkSweepGradient.h index 6772e1d43d..46e0430855 100644 --- a/src/shaders/gradients/SkSweepGradient.h +++ b/src/shaders/gradients/SkSweepGradient.h @@ -22,7 +22,7 @@ public: std::unique_ptr asFragmentProcessor(const GrFPArgs&) const override; #endif #ifdef SK_ENABLE_SKSL - void addToKey(SkShaderCodeDictionary*, + void addToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*) const override; #endif diff --git a/src/shaders/gradients/SkTwoPointConicalGradient.cpp b/src/shaders/gradients/SkTwoPointConicalGradient.cpp index 1c923386e3..3f5a945ab7 100644 --- a/src/shaders/gradients/SkTwoPointConicalGradient.cpp +++ b/src/shaders/gradients/SkTwoPointConicalGradient.cpp @@ -281,7 +281,7 @@ std::unique_ptr SkTwoPointConicalGradient::asFragmentProces #endif #ifdef SK_ENABLE_SKSL -void SkTwoPointConicalGradient::addToKey(SkShaderCodeDictionary* dict, +void SkTwoPointConicalGradient::addToKey(const SkKeyContext& keyContext, SkPaintParamsKeyBuilder* builder, SkPipelineData* pipelineData) const { GradientShaderBlocks::GradientData data(kConical_GradientType, @@ -292,6 +292,6 @@ void SkTwoPointConicalGradient::addToKey(SkShaderCodeDictionary* dict, fOrigColors4f, fOrigPos); - GradientShaderBlocks::AddToKey(dict, builder, pipelineData, data); + GradientShaderBlocks::AddToKey(keyContext, builder, pipelineData, data); } #endif diff --git a/src/shaders/gradients/SkTwoPointConicalGradient.h b/src/shaders/gradients/SkTwoPointConicalGradient.h index bbf0498b60..d9e3d0c121 100644 --- a/src/shaders/gradients/SkTwoPointConicalGradient.h +++ b/src/shaders/gradients/SkTwoPointConicalGradient.h @@ -54,7 +54,7 @@ public: std::unique_ptr asFragmentProcessor(const GrFPArgs&) const override; #endif #ifdef SK_ENABLE_SKSL - void addToKey(SkShaderCodeDictionary*, + void addToKey(const SkKeyContext&, SkPaintParamsKeyBuilder*, SkPipelineData*) const override; #endif diff --git a/tests/graphite/CommandBufferTest.cpp b/tests/graphite/CommandBufferTest.cpp index 2503b79213..e2a350d06b 100644 --- a/tests/graphite/CommandBufferTest.cpp +++ b/tests/graphite/CommandBufferTest.cpp @@ -28,6 +28,7 @@ #include "experimental/graphite/src/UniformManager.h" #include "experimental/graphite/src/geom/Shape.h" #include "experimental/graphite/src/geom/Transform_graphite.h" +#include "src/core/SkKeyContext.h" #include "src/core/SkKeyHelpers.h" #include "src/core/SkShaderCodeDictionary.h" #include "src/core/SkUniformData.h" @@ -235,8 +236,8 @@ DEF_GRAPHITE_TEST_FOR_CONTEXTS(CommandBufferTest, reporter, context) { gpu->testingOnly_startCapture(); #endif auto recorder = context->makeRecorder(); + SkKeyContext keyContext(recorder.get()); auto resourceProvider = recorder->priv().resourceProvider(); - auto dict = resourceProvider->shaderCodeDictionary(); auto commandBuffer = resourceProvider->createCommandBuffer(); SkISize textureSize = { kTextureWidth, kTextureHeight }; @@ -256,9 +257,11 @@ DEF_GRAPHITE_TEST_FOR_CONTEXTS(CommandBufferTest, reporter, context) { SkUniquePaintParamsID uniqueID; { + auto dict = keyContext.dict(); + SkPaintParamsKeyBuilder builder(dict, SkBackend::kGraphite); - uniqueID = CreateKey(dict, + uniqueID = CreateKey(keyContext, &builder, ShaderCombo::ShaderType::kSolidColor, SkTileMode::kClamp, diff --git a/tests/graphite/UniformTest.cpp b/tests/graphite/UniformTest.cpp index ae6bfe8860..f91a1ca667 100644 --- a/tests/graphite/UniformTest.cpp +++ b/tests/graphite/UniformTest.cpp @@ -17,6 +17,7 @@ #include "include/core/SkPaint.h" #include "include/effects/SkGradientShader.h" #include "include/private/SkUniquePaintParamsID.h" +#include "src/core/SkKeyContext.h" #include "src/core/SkKeyHelpers.h" #include "src/core/SkPipelineData.h" #include "src/core/SkShaderCodeDictionary.h" @@ -74,7 +75,8 @@ DEF_GRAPHITE_TEST_FOR_CONTEXTS(UniformTest, reporter, context) { using namespace skgpu; auto recorder = context->makeRecorder(); - auto dict = recorder->priv().resourceProvider()->shaderCodeDictionary(); + SkKeyContext keyContext(recorder.get()); + auto dict = keyContext.dict(); SkPaintParamsKeyBuilder builder(dict, SkBackend::kGraphite); @@ -96,9 +98,10 @@ DEF_GRAPHITE_TEST_FOR_CONTEXTS(UniformTest, reporter, context) { for (auto bm : { SkBlendMode::kSrc, SkBlendMode::kSrcOver }) { auto [ p, expectedNumUniforms ] = create_paint(s, tm, bm); - auto [ uniqueID1, pipelineData] = ExtractPaintData(dict, &builder, PaintParams(p)); + auto [ uniqueID1, pipelineData] = ExtractPaintData(recorder.get(), &builder, + PaintParams(p)); - SkUniquePaintParamsID uniqueID2 = CreateKey(dict, &builder, s, tm, bm); + SkUniquePaintParamsID uniqueID2 = CreateKey(keyContext, &builder, s, tm, bm); // ExtractPaintData and CreateKey agree REPORTER_ASSERT(reporter, uniqueID1 == uniqueID2);