[graphite] Split SkPipelineData out into its own file(s)

SkPipelineData is evolving into a big deal - it deserves it owns files.

Bug: skia:12701
Change-Id: I78b4100f1b90fa10f2b264e6d13fca6f15bba39b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/516157
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2022-03-04 14:00:04 -05:00 committed by SkCQ
parent 6cb0d972c2
commit 335a1d0454
12 changed files with 122 additions and 97 deletions

View File

@ -8,16 +8,11 @@
#include "experimental/graphite/src/ContextUtils.h"
#include <string>
#include "experimental/graphite/src/ContextPriv.h"
#include "experimental/graphite/src/DrawTypes.h"
#include "experimental/graphite/src/PaintParams.h"
#include "include/core/SkPaint.h"
#include "include/private/SkUniquePaintParamsID.h"
#include "src/core/SkBlenderBase.h"
#include "src/core/SkKeyHelpers.h"
#include "src/core/SkPipelineData.h"
#include "src/core/SkShaderCodeDictionary.h"
#include "src/core/SkUniform.h"
#include "src/core/SkUniformData.h"
namespace skgpu {

View File

@ -29,6 +29,7 @@
#include "src/core/SkMathPriv.h"
#include "src/core/SkPaintParamsKey.h"
#include "src/core/SkPipelineData.h"
#include "src/core/SkTBlockList.h"
#include "src/core/SkUniformData.h"
#include "src/gpu/BufferWriter.h"

View File

@ -8,7 +8,7 @@
#include "experimental/graphite/src/PipelineDataCache.h"
#include "src/core/SkOpts.h"
#include "src/core/SkUniformData.h"
#include "src/core/SkPipelineData.h"
namespace skgpu {

View File

@ -18,7 +18,7 @@
#include "experimental/graphite/src/PipelineDataCache.h"
#include "experimental/graphite/src/ResourceProvider.h"
#include "experimental/graphite/src/TaskGraph.h"
#include "src/core/SkUniformData.h"
#include "src/core/SkPipelineData.h"
namespace skgpu {

View File

@ -306,6 +306,8 @@ skia_core_sources = [
"$_src/core/SkPathPriv.h",
"$_src/core/SkPathRef.cpp",
"$_src/core/SkPath_serial.cpp",
"$_src/core/SkPipelineData.cpp",
"$_src/core/SkPipelineData.h",
"$_src/core/SkPixelRef.cpp",
"$_src/core/SkPixmap.cpp",
"$_src/core/SkPoint.cpp",

View File

@ -9,9 +9,9 @@
#include "src/core/SkDebugUtils.h"
#include "src/core/SkPaintParamsKey.h"
#include "src/core/SkPipelineData.h"
#include "src/core/SkShaderCodeDictionary.h"
#include "src/core/SkUniform.h"
#include "src/core/SkUniformData.h"
#include "src/shaders/SkShaderBase.h"
#ifdef SK_GRAPHITE_ENABLED

View File

@ -0,0 +1,62 @@
/*
* 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/SkOpts.h"
#include "src/core/SkPipelineData.h"
SkPipelineData::SkPipelineData(sk_sp<SkUniformData> initial) {
fUniformData.push_back(std::move(initial));
}
void SkPipelineData::add(sk_sp<SkUniformData> uniforms) {
fUniformData.push_back(std::move(uniforms));
}
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
for (auto& u : fUniformData) {
total += u->dataSize();
}
return total;
}
int SkPipelineData::count() const {
int total = 0;
for (auto& u : fUniformData) {
total += u->count();
}
return total;
}
bool SkPipelineData::operator==(const SkPipelineData& other) const {
if (fUniformData.size() != other.fUniformData.size()) {
return false;
}
for (size_t i = 0; i < fUniformData.size(); ++i) {
if (*fUniformData[i] != *other.fUniformData[i]) {
return false;
}
}
return true;
}
size_t SkPipelineData::hash() const {
int32_t hash = 0;
for (auto& u : fUniformData) {
hash = SkOpts::hash_fn(u->data(), u->dataSize(), hash);
}
return hash;
}

50
src/core/SkPipelineData.h Normal file
View File

@ -0,0 +1,50 @@
/*
* 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 SkPipelineData_DEFINED
#define SkPipelineData_DEFINED
#include <vector>
#include "include/core/SkRefCnt.h"
#include "src/core/SkUniformData.h"
class SkUniformData;
// 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 SkPipelineData {
public:
SkPipelineData() = default;
SkPipelineData(sk_sp<SkUniformData> initial);
void add(sk_sp<SkUniformData>);
bool empty() const { return fUniformData.empty(); }
size_t totalSize() const; // TODO: cache this?
int count() const; // TODO: cache this?
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>>;
using iterator = container::iterator;
using const_iterator = container::const_iterator;
inline iterator begin() noexcept { return fUniformData.begin(); }
inline const_iterator cbegin() const noexcept { return fUniformData.cbegin(); }
inline iterator end() noexcept { return fUniformData.end(); }
inline const_iterator cend() const noexcept { return fUniformData.cend(); }
private:
// TODO: SkUniformData should be held uniquely
std::vector<sk_sp<SkUniformData>> fUniformData;
};
#endif // SkPipelineData_DEFINED

View File

@ -7,7 +7,7 @@
#include "src/core/SkUniformData.h"
#include "src/core/SkOpts.h"
#include <cstring>
sk_sp<SkUniformData> SkUniformData::Make(SkSpan<const SkUniform> uniforms, size_t dataSize) {
// TODO: the offsets and data should just be allocated right after UniformData in an arena
@ -28,53 +28,3 @@ bool SkUniformData::operator==(const SkUniformData& other) const {
!memcmp(this->data(), other.data(), this->dataSize()) &&
!memcmp(this->offsets(), other.offsets(), this->count()*sizeof(uint32_t));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void SkPipelineData::add(sk_sp<SkUniformData> uniforms) {
fUniformData.push_back(std::move(uniforms));
}
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
for (auto& u : fUniformData) {
total += u->dataSize();
}
return total;
}
int SkPipelineData::count() const {
int total = 0;
for (auto& u : fUniformData) {
total += u->count();
}
return total;
}
bool SkPipelineData::operator==(const SkPipelineData& other) const {
if (fUniformData.size() != other.fUniformData.size()) {
return false;
}
for (size_t i = 0; i < fUniformData.size(); ++i) {
if (*fUniformData[i] != *other.fUniformData[i]) {
return false;
}
}
return true;
}
size_t SkPipelineData::hash() const {
int32_t hash = 0;
for (auto& u : fUniformData) {
hash = SkOpts::hash_fn(u->data(), u->dataSize(), hash);
}
return hash;
}

View File

@ -11,7 +11,6 @@
#include "include/core/SkRefCnt.h"
#include "include/core/SkSpan.h"
#include "src/core/SkUniform.h"
#include <vector>
/*
* TODO: Here is the plan of record for SkUniformData
@ -73,39 +72,4 @@ private:
const size_t fDataSize;
};
// 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 SkPipelineData {
public:
SkPipelineData() = default;
SkPipelineData(sk_sp<SkUniformData> initial) {
fUniformData.push_back(std::move(initial));
}
void add(sk_sp<SkUniformData>);
bool empty() const { return fUniformData.empty(); }
size_t totalSize() const; // TODO: cache this?
int count() const; // TODO: cache this?
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>>;
using iterator = container::iterator;
using const_iterator = container::const_iterator;
inline iterator begin() noexcept { return fUniformData.begin(); }
inline const_iterator cbegin() const noexcept { return fUniformData.cbegin(); }
inline iterator end() noexcept { return fUniformData.end(); }
inline const_iterator cend() const noexcept { return fUniformData.cend(); }
private:
// TODO: SkUniformData should be held uniquely
std::vector<sk_sp<SkUniformData>> fUniformData;
};
#endif // SkUniformData_DEFINED

View File

@ -11,8 +11,8 @@
#include "experimental/graphite/include/Recorder.h"
#include "experimental/graphite/src/PipelineDataCache.h"
#include "experimental/graphite/src/RecorderPriv.h"
#include "src/core/SkPipelineData.h"
#include "src/core/SkUniform.h"
#include "src/core/SkUniformData.h"
using namespace skgpu;

View File

@ -18,6 +18,7 @@
#include "include/effects/SkGradientShader.h"
#include "include/private/SkUniquePaintParamsID.h"
#include "src/core/SkKeyHelpers.h"
#include "src/core/SkPipelineData.h"
#include "src/core/SkShaderCodeDictionary.h"
#include "src/core/SkUniformData.h"