[graphite] Rename SkUniformBlock to SkPipelineData

and:
 UniformCache -> PipelineDataCache
 UniformCacheTest -> PipelineDataCacheTest

Bug: skia:12701
Change-Id: Ia28c223edb8d741d15fa9fa83695ac6b99284d5e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/514156
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2022-03-01 16:44:48 -05:00 committed by SkCQ
parent 60c5837632
commit b61366b54f
36 changed files with 185 additions and 182 deletions

View File

@ -25,7 +25,7 @@ class Recording;
class ResourceProvider;
class Task;
class TaskGraph;
class UniformCache;
class PipelineDataCache;
class Recorder final {
public:
@ -79,7 +79,7 @@ private:
std::unique_ptr<ResourceProvider> fResourceProvider;
std::unique_ptr<TaskGraph> fGraph;
std::unique_ptr<UniformCache> fUniformCache;
std::unique_ptr<PipelineDataCache> fPipelineDataCache;
std::unique_ptr<DrawBufferManager> fDrawBufferManager;
std::vector<Device*> fTrackedDevices;

View File

@ -21,22 +21,22 @@
namespace skgpu {
std::tuple<SkUniquePaintParamsID, std::unique_ptr<SkUniformBlock>> ExtractPaintData(
std::tuple<SkUniquePaintParamsID, std::unique_ptr<SkPipelineData>> ExtractPaintData(
SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
const PaintParams& p) {
SkDEBUGCODE(builder->checkReset());
std::unique_ptr<SkUniformBlock> block = std::make_unique<SkUniformBlock>();
std::unique_ptr<SkPipelineData> pipelineData = std::make_unique<SkPipelineData>();
p.toKey(dict, builder, block.get());
p.toKey(dict, builder, pipelineData.get());
SkPaintParamsKey key = builder->lockAsKey();
auto entry = dict->findOrCreate(key);
return { entry->uniqueID(), std::move(block) };
return { entry->uniqueID(), std::move(pipelineData) };
}
} // namespace skgpu

View File

@ -15,16 +15,16 @@
enum class CodeSnippetID : uint8_t;
class SkPaintParamsKeyBuilder;
class SkPipelineData;
class SkShaderCodeDictionary;
class SkUniform;
class SkUniformBlock;
class SkUniquePaintParamsID;
namespace skgpu {
class PaintParams;
std::tuple<SkUniquePaintParamsID, std::unique_ptr<SkUniformBlock>> ExtractPaintData(
std::tuple<SkUniquePaintParamsID, std::unique_ptr<SkPipelineData>> ExtractPaintData(
SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder* builder,
const PaintParams&);

View File

@ -19,11 +19,11 @@
#include "experimental/graphite/src/GlobalCache.h"
#include "experimental/graphite/src/GraphicsPipeline.h"
#include "experimental/graphite/src/GraphicsPipelineDesc.h"
#include "experimental/graphite/src/PipelineDataCache.h"
#include "experimental/graphite/src/RecorderPriv.h"
#include "experimental/graphite/src/Renderer.h"
#include "experimental/graphite/src/ResourceProvider.h"
#include "experimental/graphite/src/TextureProxy.h"
#include "experimental/graphite/src/UniformCache.h"
#include "experimental/graphite/src/UniformManager.h"
#include "experimental/graphite/src/geom/BoundsManager.h"
@ -173,19 +173,22 @@ private:
namespace {
// For now, we're treating the uniforms, samplers, and textures as a unit. That means that, in
// this cache, two pipelineData objects that have the same uniforms but different samplers or
// textures will be treated as distinct objects (and the uniforms will be uploaded twice).
class UniformBindingCache {
public:
UniformBindingCache(DrawBufferManager* bufferMgr, UniformCache* cache)
UniformBindingCache(DrawBufferManager* bufferMgr, PipelineDataCache* cache)
: fBufferMgr(bufferMgr), fCache(cache) {}
uint32_t addUniforms(std::unique_ptr<SkUniformBlock> uniformBlock) {
if (!uniformBlock || uniformBlock->empty()) {
return UniformCache::kInvalidUniformID;
uint32_t addUniforms(std::unique_ptr<SkPipelineData> pipelineData) {
if (!pipelineData || pipelineData->empty()) {
return PipelineDataCache::kInvalidUniformID;
}
uint32_t index = fCache->insert(std::move(uniformBlock));
uint32_t index = fCache->insert(std::move(pipelineData));
if (fBindings.find(index) == fBindings.end()) {
SkUniformBlock* tmp = fCache->lookup(index);
SkPipelineData* tmp = fCache->lookup(index);
// First time encountering this data, so upload to the GPU
size_t totalDataSize = tmp->totalSize();
auto [writer, bufferInfo] = fBufferMgr->getUniformWriter(totalDataSize);
@ -207,7 +210,7 @@ public:
private:
DrawBufferManager* fBufferMgr;
UniformCache* fCache;
PipelineDataCache* fCache;
std::unordered_map<uint32_t, BindBufferInfo> fBindings;
};
@ -275,9 +278,9 @@ std::unique_ptr<DrawPass> DrawPass::Make(Recorder* recorder,
Rect passBounds = Rect::InfiniteInverted();
DrawBufferManager* bufferMgr = recorder->priv().drawBufferManager();
UniformCache geometryUniforms;
PipelineDataCache geometryUniforms;
UniformBindingCache geometryUniformBindings(bufferMgr, &geometryUniforms);
UniformBindingCache shadingUniformBindings(bufferMgr, recorder->priv().uniformCache());
UniformBindingCache shadingUniformBindings(bufferMgr, recorder->priv().pipelineDataCache());
std::unordered_map<const GraphicsPipelineDesc*, uint32_t, Hash, Eq> pipelineDescToIndex;
@ -297,12 +300,12 @@ std::unique_ptr<DrawPass> DrawPass::Make(Recorder* recorder,
// bound independently of those used by the rest of the RenderStep, then we can upload now
// and remember the location for re-use on any RenderStep that does shading.
SkUniquePaintParamsID shaderID;
std::unique_ptr<SkUniformBlock> shadingUniforms;
uint32_t shadingIndex = UniformCache::kInvalidUniformID;
std::unique_ptr<SkPipelineData> pipelineData;
uint32_t shadingIndex = PipelineDataCache::kInvalidUniformID;
if (draw.fPaintParams.has_value()) {
std::tie(shaderID, shadingUniforms) = ExtractPaintData(dict, &builder,
std::tie(shaderID, pipelineData) = ExtractPaintData(dict, &builder,
draw.fPaintParams.value());
shadingIndex = shadingUniformBindings.addUniforms(std::move(shadingUniforms));
shadingIndex = shadingUniformBindings.addUniforms(std::move(pipelineData));
} // else depth-only
for (int stepIndex = 0; stepIndex < draw.fRenderer.numRenderSteps(); ++stepIndex) {
@ -310,13 +313,13 @@ std::unique_ptr<DrawPass> DrawPass::Make(Recorder* recorder,
const bool performsShading = draw.fPaintParams.has_value() && step->performsShading();
SkUniquePaintParamsID stepShaderID;
uint32_t stepShadingIndex = UniformCache::kInvalidUniformID;
uint32_t stepShadingIndex = PipelineDataCache::kInvalidUniformID;
if (performsShading) {
stepShaderID = shaderID;
stepShadingIndex = shadingIndex;
} // else depth-only draw or stencil-only step of renderer so no shading is needed
uint32_t geometryIndex = UniformCache::kInvalidUniformID;
uint32_t geometryIndex = PipelineDataCache::kInvalidUniformID;
if (step->numUniforms() > 0) {
// TODO: Get layout from the GPU
auto uniforms = step->writeUniforms(Layout::kMetal,
@ -325,7 +328,7 @@ std::unique_ptr<DrawPass> DrawPass::Make(Recorder* recorder,
draw.fShape);
geometryIndex = geometryUniformBindings.addUniforms(
std::make_unique<SkUniformBlock>(std::move(uniforms)));
std::make_unique<SkPipelineData>(std::move(uniforms)));
}
GraphicsPipelineDesc desc;
@ -366,8 +369,8 @@ std::unique_ptr<DrawPass> DrawPass::Make(Recorder* recorder,
// Used to track when a new pipeline or dynamic state needs recording between draw steps.
// Setting to # render steps ensures the very first time through the loop will bind a pipeline.
uint32_t lastPipeline = draws->renderStepCount();
uint32_t lastShadingUniforms = UniformCache::kInvalidUniformID;
uint32_t lastGeometryUniforms = UniformCache::kInvalidUniformID;
uint32_t lastShadingUniforms = PipelineDataCache::kInvalidUniformID;
uint32_t lastGeometryUniforms = PipelineDataCache::kInvalidUniformID;
SkIRect lastScissor = SkIRect::MakeSize(drawPass->fTarget->dimensions());
for (const SortKey& key : keys) {
@ -393,12 +396,12 @@ std::unique_ptr<DrawPass> DrawPass::Make(Recorder* recorder,
if (pipelineChange) {
drawPass->fCommands.emplace_back(BindGraphicsPipeline{key.pipeline()});
lastPipeline = key.pipeline();
lastShadingUniforms = UniformCache::kInvalidUniformID;
lastGeometryUniforms = UniformCache::kInvalidUniformID;
lastShadingUniforms = PipelineDataCache::kInvalidUniformID;
lastGeometryUniforms = PipelineDataCache::kInvalidUniformID;
}
if (stateChange) {
if (key.geometryUniforms() != lastGeometryUniforms) {
if (key.geometryUniforms() != UniformCache::kInvalidUniformID) {
if (key.geometryUniforms() != PipelineDataCache::kInvalidUniformID) {
auto binding = geometryUniformBindings.getBinding(key.geometryUniforms());
drawPass->fCommands.emplace_back(
BindUniformBuffer{binding, UniformSlot::kRenderStep});
@ -406,7 +409,7 @@ std::unique_ptr<DrawPass> DrawPass::Make(Recorder* recorder,
lastGeometryUniforms = key.geometryUniforms();
}
if (key.shadingUniforms() != lastShadingUniforms) {
if (key.shadingUniforms() != UniformCache::kInvalidUniformID) {
if (key.shadingUniforms() != PipelineDataCache::kInvalidUniformID) {
auto binding = shadingUniformBindings.getBinding(key.shadingUniforms());
drawPass->fCommands.emplace_back(
BindUniformBuffer{binding, UniformSlot::kPaint});

View File

@ -42,18 +42,18 @@ sk_sp<SkShader> PaintParams::refShader() const { return fShader; }
void PaintParams::toKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock) const {
SkPipelineData* pipelineData) const {
if (fShader) {
as_SB(fShader)->addToKey(dict, builder, uniformBlock);
as_SB(fShader)->addToKey(dict, builder, pipelineData);
} else {
SolidColorShaderBlock::AddToKey(dict, builder, uniformBlock, fColor);
SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, fColor);
}
if (fBlender) {
as_BB(fBlender)->addToKey(dict, builder, uniformBlock);
as_BB(fBlender)->addToKey(dict, builder, pipelineData);
} else {
BlendModeBlock::AddToKey(dict, builder, uniformBlock, SkBlendMode::kSrcOver);
BlendModeBlock::AddToKey(dict, builder, pipelineData, SkBlendMode::kSrcOver);
}
SkASSERT(builder->sizeInBytes() > 0);

View File

@ -13,9 +13,9 @@
enum class SkBackend : uint8_t;
class SkPaintParamsKeyBuilder;
class SkPipelineData;
class SkShader;
class SkShaderCodeDictionary;
class SkUniformBlock;
namespace skgpu {
@ -46,7 +46,7 @@ public:
void toKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*) const;
SkPipelineData*) const;
private:
SkColor4f fColor;

View File

@ -5,22 +5,22 @@
* found in the LICENSE file.
*/
#include "experimental/graphite/src/UniformCache.h"
#include "experimental/graphite/src/PipelineDataCache.h"
#include "src/core/SkOpts.h"
#include "src/core/SkUniformData.h"
namespace skgpu {
size_t UniformCache::Hash::operator()(SkUniformBlock* ub) const {
if (!ub) {
size_t PipelineDataCache::Hash::operator()(SkPipelineData* pd) const {
if (!pd) {
return 0;
}
return ub->hash();
return pd->hash();
}
bool UniformCache::Eq::operator()(SkUniformBlock* a, SkUniformBlock* b) const {
bool PipelineDataCache::Eq::operator()(SkPipelineData* a, SkPipelineData* b) const {
if (!a || !b) {
return !a && !b;
}
@ -28,7 +28,7 @@ bool UniformCache::Eq::operator()(SkUniformBlock* a, SkUniformBlock* b) const {
return *a == *b;
};
UniformCache::UniformCache() {
PipelineDataCache::PipelineDataCache() {
// kInvalidUniformID is reserved
static_assert(kInvalidUniformID == 0);
fUniformBlock.push_back(nullptr);
@ -36,7 +36,7 @@ UniformCache::UniformCache() {
}
#ifdef SK_DEBUG
void UniformCache::validate() const {
void PipelineDataCache::validate() const {
for (size_t i = 0; i < fUniformBlock.size(); ++i) {
auto kv = fUniformBlockIDs.find(fUniformBlock[i].get());
SkASSERT(kv != fUniformBlockIDs.end());
@ -46,22 +46,22 @@ void UniformCache::validate() const {
}
#endif
uint32_t UniformCache::insert(std::unique_ptr<SkUniformBlock> block) {
auto kv = fUniformBlockIDs.find(block.get());
uint32_t PipelineDataCache::insert(std::unique_ptr<SkPipelineData> pipelineData) {
auto kv = fUniformBlockIDs.find(pipelineData.get());
if (kv != fUniformBlockIDs.end()) {
return kv->second;
}
uint32_t id = SkTo<uint32_t>(fUniformBlock.size());
SkASSERT(block && id != kInvalidUniformID);
SkASSERT(pipelineData && id != kInvalidUniformID);
fUniformBlockIDs.insert({block.get(), id});
fUniformBlock.push_back(std::move(block));
fUniformBlockIDs.insert({pipelineData.get(), id});
fUniformBlock.push_back(std::move(pipelineData));
this->validate();
return id;
}
SkUniformBlock* UniformCache::lookup(uint32_t uniqueID) {
SkPipelineData* PipelineDataCache::lookup(uint32_t uniqueID) {
SkASSERT(uniqueID < fUniformBlock.size());
return fUniformBlock[uniqueID].get();
}

View File

@ -5,26 +5,26 @@
* found in the LICENSE file.
*/
#ifndef skgpu_UniformCache_DEFINED
#define skgpu_UniformCache_DEFINED
#ifndef skgpu_PipelineDataCache_DEFINED
#define skgpu_PipelineDataCache_DEFINED
#include "include/core/SkRefCnt.h"
#include <unordered_map>
#include <vector>
class SkUniformBlock;
class SkPipelineData;
namespace skgpu {
class UniformCache {
class PipelineDataCache {
public:
static constexpr uint32_t kInvalidUniformID = 0;
UniformCache();
PipelineDataCache();
// TODO: Revisit the UniformCache::insert and UniformData::Make APIs:
// TODO: Revisit the PipelineDataCache::insert and UniformData::Make APIs:
// 1. UniformData::Make requires knowing the data size up front, which involves two invocations
// of the UniformManager. Ideally, we could align uniforms on the fly into a dynamic buffer.
// 2. UniformData stores the offsets for each uniform, but these aren't needed after we've
@ -45,9 +45,9 @@ public:
// Add the block of uniform data to the cache and return a unique ID that corresponds to its
// contents. If an identical block of data is already in the cache, that unique ID is returned.
uint32_t insert(std::unique_ptr<SkUniformBlock>);
uint32_t insert(std::unique_ptr<SkPipelineData>);
SkUniformBlock* lookup(uint32_t uniqueID);
SkPipelineData* lookup(uint32_t uniqueID);
// The number of unique UniformBlock objects in the cache
size_t count() const {
@ -58,16 +58,16 @@ public:
private:
struct Hash {
// This hash operator de-references and hashes the data contents
size_t operator()(SkUniformBlock*) const;
size_t operator()(SkPipelineData*) const;
};
struct Eq {
// This equality operator de-references and compares the actual data contents
bool operator()(SkUniformBlock*, SkUniformBlock*) const;
bool operator()(SkPipelineData*, SkPipelineData*) const;
};
// The UniformBlock's unique ID is only unique w/in a Recorder _not_ globally
std::unordered_map<SkUniformBlock*, uint32_t, Hash, Eq> fUniformBlockIDs;
std::vector<std::unique_ptr<SkUniformBlock>> fUniformBlock;
std::unordered_map<SkPipelineData*, uint32_t, Hash, Eq> fUniformBlockIDs;
std::vector<std::unique_ptr<SkPipelineData>> fUniformBlock;
#ifdef SK_DEBUG
void validate() const;
@ -78,4 +78,4 @@ private:
} // namespace skgpu
#endif // skgpu_UniformCache_DEFINED
#endif // skgpu_PipelineDataCache_DEFINED

View File

@ -15,9 +15,9 @@
#include "experimental/graphite/src/DrawBufferManager.h"
#include "experimental/graphite/src/GlobalCache.h"
#include "experimental/graphite/src/Gpu.h"
#include "experimental/graphite/src/PipelineDataCache.h"
#include "experimental/graphite/src/ResourceProvider.h"
#include "experimental/graphite/src/TaskGraph.h"
#include "experimental/graphite/src/UniformCache.h"
#include "src/core/SkUniformData.h"
namespace skgpu {
@ -27,7 +27,7 @@ namespace skgpu {
Recorder::Recorder(sk_sp<Gpu> gpu, sk_sp<GlobalCache> globalCache)
: fGpu(std::move(gpu))
, fGraph(new TaskGraph)
, fUniformCache(new UniformCache) {
, fPipelineDataCache(new PipelineDataCache) {
fResourceProvider = fGpu->makeResourceProvider(std::move(globalCache), this->singleOwner());
fDrawBufferManager.reset(new DrawBufferManager(fResourceProvider.get(),

View File

@ -18,8 +18,8 @@ ResourceProvider* RecorderPriv::resourceProvider() const {
return fRecorder->fResourceProvider.get();
}
UniformCache* RecorderPriv::uniformCache() const {
return fRecorder->fUniformCache.get();
PipelineDataCache* RecorderPriv::pipelineDataCache() const {
return fRecorder->fPipelineDataCache.get();
}
const Caps* RecorderPriv::caps() const {

View File

@ -17,7 +17,7 @@ public:
void add(sk_sp<Task>);
ResourceProvider* resourceProvider() const;
UniformCache* uniformCache() const;
PipelineDataCache* pipelineDataCache() const;
DrawBufferManager* drawBufferManager() const;
const Caps* caps() const;

View File

@ -64,6 +64,8 @@ skia_graphite_sources = [
"$_src/Log.h",
"$_src/PaintParams.cpp",
"$_src/PaintParams.h",
"$_src/PipelineDataCache.cpp",
"$_src/PipelineDataCache.h",
"$_src/Recorder.cpp",
"$_src/RecorderPriv.cpp",
"$_src/RecorderPriv.h",
@ -93,8 +95,6 @@ skia_graphite_sources = [
"$_src/TextureProxy.cpp",
"$_src/TextureProxy.h",
"$_src/TextureProxyView.h",
"$_src/UniformCache.cpp",
"$_src/UniformCache.h",
"$_src/UniformManager.cpp",
"$_src/UniformManager.h",
"$_src/UploadTask.cpp",

View File

@ -339,11 +339,11 @@ graphite_tests_sources = [
"$_tests/graphite/IntersectionTreeTest.cpp",
"$_tests/graphite/KeyTest.cpp",
"$_tests/graphite/MaskTest.cpp",
"$_tests/graphite/PipelineDataCacheTest.cpp",
"$_tests/graphite/RecorderTest.cpp",
"$_tests/graphite/RectTest.cpp",
"$_tests/graphite/ShapeTest.cpp",
"$_tests/graphite/TransformTest.cpp",
"$_tests/graphite/UniformCacheTest.cpp",
"$_tests/graphite/UniformTest.cpp",
]

View File

@ -66,12 +66,12 @@ sk_sp<SkBlender> SkBlender::Mode(SkBlendMode mode) {
#ifdef SK_ENABLE_SKSL
void SkBlenderBase::addToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock) const {
SkPipelineData* pipelineData) const {
if (std::optional<SkBlendMode> bm = as_BB(this)->asBlendMode(); bm.has_value()) {
BlendModeBlock::AddToKey(dict, builder, uniformBlock, bm.value());
BlendModeBlock::AddToKey(dict, builder, pipelineData, bm.value());
} else {
BlendModeBlock::AddToKey(dict, builder, uniformBlock, SkBlendMode::kSrcOver);
BlendModeBlock::AddToKey(dict, builder, pipelineData, SkBlendMode::kSrcOver);
}
}
#endif

View File

@ -19,9 +19,9 @@ enum class SkBackend : uint8_t;
struct GrFPArgs;
class GrFragmentProcessor;
class SkPaintParamsKeyBuilder;
class SkPipelineData;
class SkRuntimeEffect;
class SkShaderCodeDictionary;
class SkUniformBlock;
/**
* Encapsulates a blend function, including non-public APIs.
@ -61,7 +61,7 @@ public:
// TODO: make pure virtual
virtual void addToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*) const;
SkPipelineData*) const;
#endif
static SkFlattenable::Type GetFlattenableType() { return kSkBlender_Type; }

View File

@ -48,7 +48,7 @@ static const int kBlockDataSize = 0;
void AddToKey(SkShaderCodeDictionary* /* dict */,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* /* uniformBlock */) {
SkPipelineData* /* pipelineData */) {
builder->beginBlock(SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw);
builder->endBlock();
@ -90,7 +90,7 @@ sk_sp<SkUniformData> make_solid_uniform_data(SkShaderCodeDictionary* dict, SkCol
void AddToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock,
SkPipelineData* pipelineData,
const SkColor4f& color) {
#ifdef SK_GRAPHITE_ENABLED
@ -102,8 +102,8 @@ void AddToKey(SkShaderCodeDictionary* dict,
SkBuiltInCodeSnippetID::kSolidColorShader,
kBlockDataSize);
if (uniformBlock) {
uniformBlock->add(make_solid_uniform_data(dict, color));
if (pipelineData) {
pipelineData->add(make_solid_uniform_data(dict, color));
}
return;
}
@ -272,7 +272,7 @@ GradientData::GradientData(SkShader::GradientType type,
void AddToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder *builder,
SkUniformBlock* uniformBlock,
SkPipelineData* pipelineData,
const GradientData& gradData) {
#ifdef SK_GRAPHITE_ENABLED
@ -281,26 +281,26 @@ void AddToKey(SkShaderCodeDictionary* dict,
switch (gradData.fType) {
case SkShader::kLinear_GradientType:
codeSnippetID = SkBuiltInCodeSnippetID::kLinearGradientShader;
if (uniformBlock) {
uniformBlock->add(make_linear_gradient_uniform_data(dict, gradData));
if (pipelineData) {
pipelineData->add(make_linear_gradient_uniform_data(dict, gradData));
}
break;
case SkShader::kRadial_GradientType:
codeSnippetID = SkBuiltInCodeSnippetID::kRadialGradientShader;
if (uniformBlock) {
uniformBlock->add(make_radial_gradient_uniform_data(dict, gradData));
if (pipelineData) {
pipelineData->add(make_radial_gradient_uniform_data(dict, gradData));
}
break;
case SkShader::kSweep_GradientType:
codeSnippetID = SkBuiltInCodeSnippetID::kSweepGradientShader;
if (uniformBlock) {
uniformBlock->add(make_sweep_gradient_uniform_data(dict, gradData));
if (pipelineData) {
pipelineData->add(make_sweep_gradient_uniform_data(dict, gradData));
}
break;
case SkShader::GradientType::kConical_GradientType:
codeSnippetID = SkBuiltInCodeSnippetID::kConicalGradientShader;
if (uniformBlock) {
uniformBlock->add(make_conical_gradient_uniform_data(dict, gradData));
if (pipelineData) {
pipelineData->add(make_conical_gradient_uniform_data(dict, gradData));
}
break;
case SkShader::GradientType::kColor_GradientType:
@ -324,7 +324,7 @@ void AddToKey(SkShaderCodeDictionary* dict,
if (builder->backend() == SkBackend::kSkVM || builder->backend() == SkBackend::kGanesh) {
// TODO: add implementation of other backends
SolidColorShaderBlock::AddToKey(dict, builder, uniformBlock, SkColors::kRed);
SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, SkColors::kRed);
}
}
@ -362,7 +362,7 @@ sk_sp<SkUniformData> make_image_uniform_data(SkShaderCodeDictionary* dict,
void AddToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock,
SkPipelineData* pipelineData,
const ImageData& imgData) {
#ifdef SK_GRAPHITE_ENABLED
@ -377,8 +377,8 @@ void AddToKey(SkShaderCodeDictionary* dict,
builder->endBlock();
if (uniformBlock) {
uniformBlock->add(make_image_uniform_data(dict, imgData));
if (pipelineData) {
pipelineData->add(make_image_uniform_data(dict, imgData));
}
return;
}
@ -386,7 +386,7 @@ void AddToKey(SkShaderCodeDictionary* dict,
if (builder->backend() == SkBackend::kSkVM || builder->backend() == SkBackend::kGanesh) {
// TODO: add implementation for other backends
SolidColorShaderBlock::AddToKey(dict, builder, uniformBlock, SkColors::kRed);
SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, SkColors::kRed);
}
}
@ -424,7 +424,7 @@ sk_sp<SkUniformData> make_blendshader_uniform_data(SkShaderCodeDictionary* dict,
void AddToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder *builder,
SkUniformBlock* uniformBlock,
SkPipelineData* pipelineData,
const BlendData& blendData) {
#ifdef SK_GRAPHITE_ENABLED
@ -432,8 +432,8 @@ void AddToKey(SkShaderCodeDictionary* 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.
if (uniformBlock) {
uniformBlock->add(make_blendshader_uniform_data(dict, blendData.fBM));
if (pipelineData) {
pipelineData->add(make_blendshader_uniform_data(dict, blendData.fBM));
}
builder->beginBlock(SkBuiltInCodeSnippetID::kBlendShader);
@ -442,11 +442,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, uniformBlock);
as_SB(blendData.fDst)->addToKey(dict, builder, pipelineData);
int firstShaderSize = builder->sizeInBytes() - start;
start = builder->sizeInBytes();
as_SB(blendData.fSrc)->addToKey(dict, builder, uniformBlock);
as_SB(blendData.fSrc)->addToKey(dict, builder, pipelineData);
int secondShaderSize = builder->sizeInBytes() - start;
builder->endBlock();
@ -461,7 +461,7 @@ void AddToKey(SkShaderCodeDictionary* dict,
if (builder->backend() == SkBackend::kSkVM || builder->backend() == SkBackend::kGanesh) {
// TODO: add implementation for other backends
SolidColorShaderBlock::AddToKey(dict, builder, uniformBlock, SkColors::kRed);
SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, SkColors::kRed);
}
}
@ -476,7 +476,7 @@ static const int kBlockDataSize = 1;
void AddToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder *builder,
SkUniformBlock* uniformBlock,
SkPipelineData* pipelineData,
SkBlendMode bm) {
#ifdef SK_GRAPHITE_ENABLED
@ -494,7 +494,7 @@ void AddToKey(SkShaderCodeDictionary* dict,
if (builder->backend() == SkBackend::kSkVM || builder->backend() == SkBackend::kGanesh) {
// TODO: add implementation for other backends
SolidColorShaderBlock::AddToKey(dict, builder, uniformBlock, SkColors::kRed);
SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, SkColors::kRed);
}
}

View File

@ -20,7 +20,7 @@ enum class SkBackend : uint8_t;
class SkPaintParamsKey;
class SkPaintParamsKeyBuilder;
class SkShaderCodeDictionary;
class SkUniformBlock;
class SkPipelineData;
// The KeyHelpers can be used to manually construct an SkPaintParamsKey
@ -28,7 +28,7 @@ namespace DepthStencilOnlyBlock {
void AddToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*);
SkPipelineData*);
} // namespace DepthStencilOnlyBlock
@ -36,7 +36,7 @@ namespace SolidColorShaderBlock {
void AddToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*,
SkPipelineData*,
const SkColor4f&);
} // namespace SolidColorShaderBlock
@ -89,7 +89,7 @@ namespace GradientShaderBlocks {
void AddToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*,
SkPipelineData*,
const GradientData&);
} // namespace GradientShaderBlocks
@ -110,7 +110,7 @@ namespace ImageShaderBlock {
void AddToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*,
SkPipelineData*,
const ImageData&);
} // namespace ImageShaderBlock
@ -126,7 +126,7 @@ namespace BlendShaderBlock {
void AddToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*,
SkPipelineData*,
const BlendData&);
} // namespace BlendShaderBlock
@ -135,7 +135,7 @@ namespace BlendModeBlock {
void AddToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*,
SkPipelineData*,
SkBlendMode);
} // namespace BlendModeBlock

View File

@ -30,11 +30,11 @@ bool SkUniformData::operator==(const SkUniformData& other) const {
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void SkUniformBlock::add(sk_sp<SkUniformData> uniforms) {
void SkPipelineData::add(sk_sp<SkUniformData> uniforms) {
fUniformData.push_back(std::move(uniforms));
}
size_t SkUniformBlock::totalSize() const {
size_t SkPipelineData::totalSize() const {
size_t total = 0;
// TODO: It seems like we need to worry about alignment between the separate sets of uniforms
@ -45,7 +45,7 @@ size_t SkUniformBlock::totalSize() const {
return total;
}
int SkUniformBlock::count() const {
int SkPipelineData::count() const {
int total = 0;
for (auto& u : fUniformData) {
@ -55,7 +55,7 @@ int SkUniformBlock::count() const {
return total;
}
bool SkUniformBlock::operator==(const SkUniformBlock& other) const {
bool SkPipelineData::operator==(const SkPipelineData& other) const {
if (fUniformData.size() != other.fUniformData.size()) {
return false;
}
@ -69,7 +69,7 @@ bool SkUniformBlock::operator==(const SkUniformBlock& other) const {
return true;
}
size_t SkUniformBlock::hash() const {
size_t SkPipelineData::hash() const {
int32_t hash = 0;
for (auto& u : fUniformData) {

View File

@ -73,14 +73,14 @@ private:
const size_t fDataSize;
};
// TODO: The current plan for fixing uniform padding is for the SkUniformBlock to hold a
// TODO: The current plan for fixing uniform padding is for the SkPipelineData to hold a
// persistent uniformManager. A stretch goal for this system would be for this combination
// to accumulate all the uniforms and then rearrange them to minimize padding. This would,
// obviously, vastly complicate uniform accumulation.
class SkUniformBlock {
class SkPipelineData {
public:
SkUniformBlock() = default;
SkUniformBlock(sk_sp<SkUniformData> initial) {
SkPipelineData() = default;
SkPipelineData(sk_sp<SkUniformData> initial) {
fUniformData.push_back(std::move(initial));
}
@ -90,8 +90,8 @@ public:
size_t totalSize() const; // TODO: cache this?
int count() const; // TODO: cache this?
bool operator==(const SkUniformBlock&) const;
bool operator!=(const SkUniformBlock& other) const { return !(*this == other); }
bool operator==(const SkPipelineData&) const;
bool operator!=(const SkPipelineData& other) const { return !(*this == other); }
size_t hash() const;
using container = std::vector<sk_sp<SkUniformData>>;

View File

@ -143,14 +143,14 @@ std::unique_ptr<GrFragmentProcessor> SkColor4Shader::asFragmentProcessor(
#ifdef SK_ENABLE_SKSL
void SkColorShader::addToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock) const {
SolidColorShaderBlock::AddToKey(dict, builder, uniformBlock,
SkPipelineData* pipelineData) const {
SolidColorShaderBlock::AddToKey(dict, builder, pipelineData,
SkColor4f::FromColor(fColor));
}
void SkColor4Shader::addToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock) const {
SolidColorShaderBlock::AddToKey(dict, builder, uniformBlock, fColor);
SkPipelineData* pipelineData) const {
SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, fColor);
}
#endif

View File

@ -37,7 +37,7 @@ public:
#ifdef SK_ENABLE_SKSL
void addToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*) const override;
SkPipelineData*) const override;
#endif
private:
@ -72,7 +72,7 @@ public:
#ifdef SK_ENABLE_SKSL
void addToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*) const override;
SkPipelineData*) const override;
#endif
private:

View File

@ -195,10 +195,10 @@ std::unique_ptr<GrFragmentProcessor> SkShader_Blend::asFragmentProcessor(
#ifdef SK_ENABLE_SKSL
void SkShader_Blend::addToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock) const {
SkPipelineData* pipelineData) const {
// TODO: add blender support
SkASSERT(!fBlender);
BlendShaderBlock::AddToKey(dict, builder, uniformBlock, { fDst.get(), fSrc.get(), fMode });
BlendShaderBlock::AddToKey(dict, builder, pipelineData, { fDst.get(), fSrc.get(), fMode });
}
#endif

View File

@ -33,7 +33,7 @@ public:
#ifdef SK_ENABLE_SKSL
void addToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*) const override;
SkPipelineData*) const override;
#endif
protected:

View File

@ -379,8 +379,8 @@ std::unique_ptr<GrFragmentProcessor> SkImageShader::asFragmentProcessor(
#ifdef SK_ENABLE_SKSL
void SkImageShader::addToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock) const {
ImageShaderBlock::AddToKey(dict, builder, uniformBlock, { fTileModeX, fTileModeY });
SkPipelineData* pipelineData) const {
ImageShaderBlock::AddToKey(dict, builder, pipelineData, { fTileModeX, fTileModeY });
}
#endif

View File

@ -48,7 +48,7 @@ public:
#ifdef SK_ENABLE_SKSL
void addToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*) const override;
SkPipelineData*) const override;
#endif
static SkM44 CubicResamplerMatrix(float B, float C);

View File

@ -156,8 +156,8 @@ SkUpdatableShader* SkShaderBase::onUpdatableShader(SkArenaAlloc* alloc) const {
// TODO: add implementations for derived classes
void SkShaderBase::addToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock) const {
SolidColorShaderBlock::AddToKey(dict, builder, uniformBlock, SkColors::kRed);
SkPipelineData* pipelineData) const {
SolidColorShaderBlock::AddToKey(dict, builder, pipelineData, SkColors::kRed);
}
#endif

View File

@ -30,10 +30,10 @@ class SkImage;
struct SkImageInfo;
class SkPaint;
class SkPaintParamsKeyBuilder;
class SkPipelineData;
class SkRasterPipeline;
class SkRuntimeEffect;
class SkShaderCodeDictionary;
class SkUniformBlock;
class SkStageUpdater;
class SkUpdatableShader;
@ -221,11 +221,11 @@ public:
@param dictionary dictionary of code fragments available to be used in the key
@param builder builder for creating the key for this SkShader
@param uniformBlock if non-null, storage for this shader's uniform data
@param pipelineData if non-null, storage for this shader's data
*/
virtual void addToKey(SkShaderCodeDictionary* dictionary,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock) const;
SkPipelineData* pipelineData) const;
#endif
protected:

View File

@ -111,7 +111,7 @@ std::unique_ptr<GrFragmentProcessor> SkLinearGradient::asFragmentProcessor(
#ifdef SK_ENABLE_SKSL
void SkLinearGradient::addToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock) const {
SkPipelineData* pipelineData) const {
GradientShaderBlocks::GradientData data(kLinear_GradientType,
fStart, fEnd,
0.0f, 0.0f,
@ -120,6 +120,6 @@ void SkLinearGradient::addToKey(SkShaderCodeDictionary* dict,
fOrigColors4f,
fOrigPos);
GradientShaderBlocks::AddToKey(dict, builder, uniformBlock, data);
GradientShaderBlocks::AddToKey(dict, builder, pipelineData, data);
}
#endif

View File

@ -23,7 +23,7 @@ public:
#ifdef SK_ENABLE_SKSL
void addToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*) const override;
SkPipelineData*) const override;
#endif
protected:

View File

@ -89,7 +89,7 @@ std::unique_ptr<GrFragmentProcessor> SkRadialGradient::asFragmentProcessor(
#ifdef SK_ENABLE_SKSL
void SkRadialGradient::addToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock) const {
SkPipelineData* pipelineData) const {
GradientShaderBlocks::GradientData data(kRadial_GradientType,
fCenter, { 0.0f, 0.0f },
fRadius, 0.0f,
@ -98,6 +98,6 @@ void SkRadialGradient::addToKey(SkShaderCodeDictionary* dict,
fOrigColors4f,
fOrigPos);
GradientShaderBlocks::AddToKey(dict, builder, uniformBlock, data);
GradientShaderBlocks::AddToKey(dict, builder, pipelineData, data);
}
#endif

View File

@ -23,7 +23,7 @@ public:
#ifdef SK_ENABLE_SKSL
void addToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*) const override;
SkPipelineData*) const override;
#endif
protected:
SkRadialGradient(SkReadBuffer& buffer);

View File

@ -113,7 +113,7 @@ std::unique_ptr<GrFragmentProcessor> SkSweepGradient::asFragmentProcessor(
#ifdef SK_ENABLE_SKSL
void SkSweepGradient::addToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock) const {
SkPipelineData* pipelineData) const {
GradientShaderBlocks::GradientData data(kSweep_GradientType,
fCenter, { 0.0f, 0.0f },
0.0, 0.0f,
@ -122,6 +122,6 @@ void SkSweepGradient::addToKey(SkShaderCodeDictionary* dict,
fOrigColors4f,
fOrigPos);
GradientShaderBlocks::AddToKey(dict, builder, uniformBlock, data);
GradientShaderBlocks::AddToKey(dict, builder, pipelineData, data);
}
#endif

View File

@ -24,7 +24,7 @@ public:
#ifdef SK_ENABLE_SKSL
void addToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*) const override;
SkPipelineData*) const override;
#endif
SkScalar getTBias() const { return fTBias; }

View File

@ -283,7 +283,7 @@ std::unique_ptr<GrFragmentProcessor> SkTwoPointConicalGradient::asFragmentProces
#ifdef SK_ENABLE_SKSL
void SkTwoPointConicalGradient::addToKey(SkShaderCodeDictionary* dict,
SkPaintParamsKeyBuilder* builder,
SkUniformBlock* uniformBlock) const {
SkPipelineData* pipelineData) const {
GradientShaderBlocks::GradientData data(kConical_GradientType,
fCenter1, fCenter2,
fRadius1, fRadius2,
@ -292,6 +292,6 @@ void SkTwoPointConicalGradient::addToKey(SkShaderCodeDictionary* dict,
fOrigColors4f,
fOrigPos);
GradientShaderBlocks::AddToKey(dict, builder, uniformBlock, data);
GradientShaderBlocks::AddToKey(dict, builder, pipelineData, data);
}
#endif

View File

@ -56,7 +56,7 @@ public:
#ifdef SK_ENABLE_SKSL
void addToKey(SkShaderCodeDictionary*,
SkPaintParamsKeyBuilder*,
SkUniformBlock*) const override;
SkPipelineData*) const override;
#endif
bool isOpaque() const override;

View File

@ -9,8 +9,8 @@
#include "experimental/graphite/include/Context.h"
#include "experimental/graphite/include/Recorder.h"
#include "experimental/graphite/src/PipelineDataCache.h"
#include "experimental/graphite/src/RecorderPriv.h"
#include "experimental/graphite/src/UniformCache.h"
#include "src/core/SkUniform.h"
#include "src/core/SkUniformData.h"
@ -18,7 +18,7 @@ using namespace skgpu;
namespace {
std::unique_ptr<SkUniformBlock> make_ub(int numUniforms, int dataSize) {
std::unique_ptr<SkPipelineData> make_pd(int numUniforms, int dataSize) {
static constexpr int kMaxUniforms = 3;
static constexpr SkUniform kUniforms[kMaxUniforms] {
{"point0", SkSLType::kFloat2 },
@ -37,66 +37,66 @@ std::unique_ptr<SkUniformBlock> make_ub(int numUniforms, int dataSize) {
ud->data()[i] = i % 255;
}
return std::make_unique<SkUniformBlock>(std::move(ud));
return std::make_unique<SkPipelineData>(std::move(ud));
}
} // anonymous namespace
DEF_GRAPHITE_TEST_FOR_CONTEXTS(UniformCacheTest, reporter, context) {
DEF_GRAPHITE_TEST_FOR_CONTEXTS(PipelineDataCacheTest, reporter, context) {
std::unique_ptr<Recorder> recorder = context->makeRecorder();
auto cache = recorder->priv().uniformCache();
auto cache = recorder->priv().pipelineDataCache();
REPORTER_ASSERT(reporter, cache->count() == 0);
// Nullptr should already be in the cache and return kInvalidUniformID
{
uint32_t result0 = cache->insert(nullptr);
REPORTER_ASSERT(reporter, result0 == UniformCache::kInvalidUniformID);
REPORTER_ASSERT(reporter, result0 == PipelineDataCache::kInvalidUniformID);
REPORTER_ASSERT(reporter, cache->count() == 0);
}
// Add a new unique UB
SkUniformBlock* danglingUB1 = nullptr;
// Add a new unique PD
SkPipelineData* danglingPD1 = nullptr;
uint32_t result1;
{
std::unique_ptr<SkUniformBlock> ub1 = make_ub(2, 16);
danglingUB1 = ub1.get();
result1 = cache->insert(std::move(ub1));
REPORTER_ASSERT(reporter, result1 != UniformCache::kInvalidUniformID);
SkUniformBlock* lookup = cache->lookup(result1);
REPORTER_ASSERT(reporter, lookup == danglingUB1);
std::unique_ptr<SkPipelineData> pd1 = make_pd(2, 16);
danglingPD1 = pd1.get();
result1 = cache->insert(std::move(pd1));
REPORTER_ASSERT(reporter, result1 != PipelineDataCache::kInvalidUniformID);
SkPipelineData* lookup = cache->lookup(result1);
REPORTER_ASSERT(reporter, lookup == danglingPD1);
REPORTER_ASSERT(reporter, cache->count() == 1);
}
// Try to add a duplicate UB
// Try to add a duplicate PD
{
std::unique_ptr<SkUniformBlock> ub2 = make_ub(2, 16);
SkUniformBlock* danglingUB2 = ub2.get();
uint32_t result2 = cache->insert(std::move(ub2));
REPORTER_ASSERT(reporter, result2 != UniformCache::kInvalidUniformID);
std::unique_ptr<SkPipelineData> pd2 = make_pd(2, 16);
SkPipelineData* danglingPD2 = pd2.get();
uint32_t result2 = cache->insert(std::move(pd2));
REPORTER_ASSERT(reporter, result2 != PipelineDataCache::kInvalidUniformID);
REPORTER_ASSERT(reporter, result2 == result1);
SkUniformBlock* lookup = cache->lookup(result2);
REPORTER_ASSERT(reporter, lookup != danglingUB2);
REPORTER_ASSERT(reporter, lookup == danglingUB1);
SkPipelineData* lookup = cache->lookup(result2);
REPORTER_ASSERT(reporter, lookup != danglingPD2);
REPORTER_ASSERT(reporter, lookup == danglingPD1);
REPORTER_ASSERT(reporter, cache->count() == 1);
}
// Add a second new unique UB
// Add a second new unique PD
{
std::unique_ptr<SkUniformBlock> ub3 = make_ub(3, 16);
SkUniformBlock* danglingUB3 = ub3.get();
uint32_t result3 = cache->insert(std::move(ub3));
REPORTER_ASSERT(reporter, result3 != UniformCache::kInvalidUniformID);
std::unique_ptr<SkPipelineData> pd3 = make_pd(3, 16);
SkPipelineData* danglingPD3 = pd3.get();
uint32_t result3 = cache->insert(std::move(pd3));
REPORTER_ASSERT(reporter, result3 != PipelineDataCache::kInvalidUniformID);
REPORTER_ASSERT(reporter, result3 != result1);
SkUniformBlock* lookup = cache->lookup(result3);
REPORTER_ASSERT(reporter, lookup == danglingUB3);
REPORTER_ASSERT(reporter, lookup != danglingUB1);
SkPipelineData* lookup = cache->lookup(result3);
REPORTER_ASSERT(reporter, lookup == danglingPD3);
REPORTER_ASSERT(reporter, lookup != danglingPD1);
REPORTER_ASSERT(reporter, cache->count() == 2);
}
// TODO(robertphillips): expand this test to exercise all the UD comparison failure modes
// TODO(robertphillips): expand this test to exercise all the PD comparison failure modes
}