Reduce usage of GrProgramDesc::KeyHeader
Ideally the GrProgramDesc would be a simple program key. We currently can't remove usage of the KeyHeader for "hasPointSize" but this, at least, removes the other uses.
Bug: skia:9455
Change-Id: Ie9e15997ee79c6ffe62b5cd2c96885ca06204383
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/247597
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrProgramDesc.h b/src/gpu/GrProgramDesc.h
index 25a7895..391bfe1 100644
--- a/src/gpu/GrProgramDesc.h
+++ b/src/gpu/GrProgramDesc.h
@@ -25,18 +25,20 @@
GrProgramDesc() {}
/**
- * Builds a program descriptor. Before the descriptor can be used, the client must call finalize
- * on the filled in GrProgramDesc.
- *
- * @param desc The built and finalized descriptor
- * @param renderTarget The target of the draw
- * @param programInfo Program information need to build the key
- * @param primitiveType Controls whether the shader will output a point size.
- * @param gpu Pointer to the GrGpu object the program will be used with.
- **/
+ * Builds a program descriptor. Before the descriptor can be used, the client must call finalize
+ * on the filled in GrProgramDesc.
+ *
+ * @param desc The built and finalized descriptor
+ * @param renderTarget The target of the draw
+ * @param programInfo Program information need to build the key
+ * @param primitiveType Controls whether the shader will output a point size.
+ * @param gpu Pointer to the GrGpu object the program will be used with.
+ **/
static bool Build(GrProgramDesc*, const GrRenderTarget*, const GrProgramInfo&,
GrPrimitiveType, GrGpu*);
+ // This is strictly an OpenGL call since the other backends have additional data in their
+ // keys
static bool BuildFromData(GrProgramDesc* desc, const void* keyData, size_t keyLength) {
if (!SkTFitsIn<int>(keyLength)) {
return false;
@@ -85,10 +87,12 @@
return !(*this == other);
}
- struct KeyHeader {
- bool hasPointSize() const { return fHasPointSize; }
+ // TODO: remove this use of the header
+ bool hasPointSize() const { return this->header().fHasPointSize; }
- // Set to uniquely idenitify any swizzling of the shader's output color(s).
+protected:
+ struct KeyHeader {
+ // Set to uniquely identify any swizzling of the shader's output color(s).
uint16_t fOutputSwizzle;
uint8_t fColorFragmentProcessorCnt; // Can be packed into 4 bits if required.
uint8_t fCoverageFragmentProcessorCnt;
@@ -101,10 +105,8 @@
};
GR_STATIC_ASSERT(sizeof(KeyHeader) == 6);
- // This should really only be used internally, base classes should return their own headers
const KeyHeader& header() const { return *this->atOffset<KeyHeader, kHeaderOffset>(); }
-protected:
template<typename T, size_t OFFSET> T* atOffset() {
return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + OFFSET);
}
diff --git a/src/gpu/GrSwizzle.h b/src/gpu/GrSwizzle.h
index 05db3c0..94562ff 100644
--- a/src/gpu/GrSwizzle.h
+++ b/src/gpu/GrSwizzle.h
@@ -24,9 +24,6 @@
static constexpr GrSwizzle Concat(const GrSwizzle& a, const GrSwizzle& b);
- /** Recreates a GrSwizzle from the output of asKey() */
- constexpr void setFromKey(uint16_t key);
-
constexpr bool operator==(const GrSwizzle& that) const { return fKey == that.fKey; }
constexpr bool operator!=(const GrSwizzle& that) const { return !(*this == that); }
@@ -100,16 +97,6 @@
return { outR, outG, outB, outA };
}
-/** Recreates a GrSwizzle from the output of asKey() */
-constexpr void GrSwizzle::setFromKey(uint16_t key) {
- fKey = key;
- for (int i = 0; i < 4; ++i) {
- fSwiz[i] = IToC(key & 15);
- key >>= 4;
- }
- SkASSERT(fSwiz[4] == '\0');
-}
-
template <SkAlphaType AlphaType>
constexpr float GrSwizzle::ComponentIndexToFloat(const SkRGBA4f<AlphaType>& color, int idx) {
if (idx <= 3) {
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index e6125e3..8cdf43d 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -269,7 +269,7 @@
fFS.getSecondaryColorOutputName(),
dstTextureSamplerHandle,
dstTextureOrigin,
- this->header().fOutputSwizzle);
+ this->pipeline().outputSwizzle());
fXferProcessor->emitCode(args);
// We have to check that effects and the code they emit are consistent, ie if an effect
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h
index d470b69..dc63aa8 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.h
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.h
@@ -44,6 +44,11 @@
GrProcessor::CustomFeatures processorFeatures() const {
return fProgramInfo.requestedFeatures();
}
+ bool snapVerticesToPixelCenters() const {
+ return fProgramInfo.pipeline().snapVerticesToPixelCenters();
+ }
+ // TODO: remove this usage of the descriptor's header
+ bool hasPointSize() const { return fDesc->hasPointSize(); }
// TODO: stop passing in the renderTarget for just the sampleLocations
int effectiveSampleCnt() const {
@@ -55,7 +60,6 @@
}
const GrProgramDesc* desc() const { return fDesc; }
- const GrProgramDesc::KeyHeader& header() const { return fDesc->header(); }
void appendUniformDecls(GrShaderFlags visibility, SkString*) const;
diff --git a/src/gpu/glsl/GrGLSLVertexGeoBuilder.cpp b/src/gpu/glsl/GrGLSLVertexGeoBuilder.cpp
index 5d0980f..ccec08d 100644
--- a/src/gpu/glsl/GrGLSLVertexGeoBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLVertexGeoBuilder.cpp
@@ -14,7 +14,7 @@
void GrGLSLVertexGeoBuilder::emitNormalizedSkPosition(SkString* out, const char* devPos,
const char* rtAdjustName,
GrSLType devPosType) {
- if (this->getProgramBuilder()->header().fSnapVerticesToPixelCenters) {
+ if (this->getProgramBuilder()->snapVerticesToPixelCenters()) {
if (kFloat3_GrSLType == devPosType) {
const char* p = devPos;
out->appendf("{float2 _posTmp = float2(%s.x/%s.z, %s.y/%s.z);", p, p, p, p);
@@ -37,8 +37,7 @@
void GrGLSLVertexBuilder::onFinalize() {
// We could have the GrGeometryProcessor do this, but its just easier to have it performed
// here. If we ever need to set variable pointsize, then we can reinvestigate.
- const GrProgramDesc::KeyHeader& header = this->getProgramBuilder()->desc()->header();
- if (header.hasPointSize()) {
+ if (this->getProgramBuilder()->hasPointSize()) {
this->codeAppend("sk_PointSize = 1.0;");
}
fProgramBuilder->varyingHandler()->getVertexDecls(&this->inputs(), &this->outputs());
diff --git a/src/gpu/glsl/GrGLSLXferProcessor.h b/src/gpu/glsl/GrGLSLXferProcessor.h
index b2f018e..7c935a1 100644
--- a/src/gpu/glsl/GrGLSLXferProcessor.h
+++ b/src/gpu/glsl/GrGLSLXferProcessor.h
@@ -36,7 +36,7 @@
const char* outputSecondary,
const SamplerHandle dstTextureSamplerHandle,
GrSurfaceOrigin dstTextureOrigin,
- uint16_t outputSwizzleKey)
+ const GrSwizzle& outputSwizzle)
: fXPFragBuilder(fragBuilder)
, fUniformHandler(uniformHandler)
, fShaderCaps(caps)
@@ -46,8 +46,8 @@
, fOutputPrimary(outputPrimary)
, fOutputSecondary(outputSecondary)
, fDstTextureSamplerHandle(dstTextureSamplerHandle)
- , fDstTextureOrigin(dstTextureOrigin) {
- fOutputSwizzle.setFromKey(outputSwizzleKey);
+ , fDstTextureOrigin(dstTextureOrigin)
+ , fOutputSwizzle(outputSwizzle) {
}
GrGLSLXPFragmentBuilder* fXPFragBuilder;
GrGLSLUniformHandler* fUniformHandler;
diff --git a/src/gpu/vk/GrVkPipelineStateBuilder.cpp b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
index 050429d..4d595e7 100644
--- a/src/gpu/vk/GrVkPipelineStateBuilder.cpp
+++ b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
@@ -134,6 +134,9 @@
const SkSL::Program::Inputs inputs[],
bool isSkSL) {
const Desc* desc = static_cast<const Desc*>(this->desc());
+ // Here we shear off the Vk-specific portion of the Desc in order to create the
+ // persistent key. This is bc Vk only caches the SPIRV code, not the fully compiled
+ // program, and that only depends on the base GrProgramDesc data.
sk_sp<SkData> key = SkData::MakeWithoutCopy(desc->asKey(), desc->shaderKeyLength());
sk_sp<SkData> data = GrPersistentCacheUtils::PackCachedShaders(isSkSL ? kSKSL_Tag : kSPIRV_Tag,
shaders,
@@ -201,6 +204,9 @@
SkFourByteTag shaderType = 0;
auto persistentCache = fGpu->getContext()->priv().getPersistentCache();
if (persistentCache) {
+ // Here we shear off the Vk-specific portion of the Desc in order to create the
+ // persistent key. This is bc Vk only caches the SPIRV code, not the fully compiled
+ // program, and that only depends on the base GrProgramDesc data.
sk_sp<SkData> key = SkData::MakeWithoutCopy(desc->asKey(), desc->shaderKeyLength());
cached = persistentCache->load(*key);
if (cached) {