aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar egdaniel <egdaniel@google.com>2016-09-07 07:24:12 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-07 07:24:12 -0700
commit5d8f69f2d492a15189e4b976ccca3fa092876419 (patch)
treecd3992a510ba5260e7c03bbe298d96af68a49c0b /src/gpu
parent653212c37efaa6d3175882559634772528bb8ad2 (diff)
Merge GrGLSLProgramDesc into GrProgramDesc
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrProgramDesc.cpp (renamed from src/gpu/glsl/GrGLSLProgramDesc.cpp)27
-rw-r--r--src/gpu/GrProgramDesc.h53
-rw-r--r--src/gpu/gl/GrGLGpuProgramCache.cpp7
-rw-r--r--src/gpu/gl/GrGLProgram.h2
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.cpp6
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.h6
-rw-r--r--src/gpu/glsl/GrGLSLProgramDesc.h63
-rw-r--r--src/gpu/vk/GrVkPipelineState.h4
-rw-r--r--src/gpu/vk/GrVkPipelineStateBuilder.cpp2
-rw-r--r--src/gpu/vk/GrVkPipelineStateBuilder.h4
-rw-r--r--src/gpu/vk/GrVkPipelineStateCache.cpp6
11 files changed, 69 insertions, 111 deletions
diff --git a/src/gpu/glsl/GrGLSLProgramDesc.cpp b/src/gpu/GrProgramDesc.cpp
index c44759a5ef..a22063c3f4 100644
--- a/src/gpu/glsl/GrGLSLProgramDesc.cpp
+++ b/src/gpu/GrProgramDesc.cpp
@@ -4,7 +4,7 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
-#include "GrGLSLProgramDesc.h"
+#include "GrProgramDesc.h"
#include "GrProcessor.h"
#include "GrPipeline.h"
@@ -104,27 +104,25 @@ static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc,
fp.numTransformsExclChildren()), b);
}
-bool GrGLSLProgramDescBuilder::Build(GrProgramDesc* desc,
- const GrPrimitiveProcessor& primProc,
- const GrPipeline& pipeline,
- const GrGLSLCaps& glslCaps) {
+bool GrProgramDesc::Build(GrProgramDesc* desc,
+ const GrPrimitiveProcessor& primProc,
+ const GrPipeline& pipeline,
+ const GrGLSLCaps& glslCaps) {
// The descriptor is used as a cache key. Thus when a field of the
// descriptor will not affect program generation (because of the attribute
// bindings in use or other descriptor field settings) it should be set
// to a canonical value to avoid duplicate programs with different keys.
- GrGLSLProgramDesc* glDesc = (GrGLSLProgramDesc*)desc;
-
GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t));
// Make room for everything up to the effect keys.
- glDesc->key().reset();
- glDesc->key().push_back_n(kProcessorKeysOffset);
+ desc->key().reset();
+ desc->key().push_back_n(kProcessorKeysOffset);
- GrProcessorKeyBuilder b(&glDesc->key());
+ GrProcessorKeyBuilder b(&desc->key());
primProc.getGLSLProcessorKey(glslCaps, &b);
if (!gen_meta_key(primProc, glslCaps, 0, &b)) {
- glDesc->key().reset();
+ desc->key().reset();
return false;
}
GrProcessor::RequiredFeatures requiredFeatures = primProc.requiredFeatures();
@@ -132,7 +130,7 @@ bool GrGLSLProgramDescBuilder::Build(GrProgramDesc* desc,
for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
const GrFragmentProcessor& fp = pipeline.getFragmentProcessor(i);
if (!gen_frag_proc_and_meta_keys(primProc, fp, glslCaps, &b)) {
- glDesc->key().reset();
+ desc->key().reset();
return false;
}
requiredFeatures |= fp.requiredFeatures();
@@ -141,7 +139,7 @@ bool GrGLSLProgramDescBuilder::Build(GrProgramDesc* desc,
const GrXferProcessor& xp = pipeline.getXferProcessor();
xp.getGLSLProcessorKey(glslCaps, &b);
if (!gen_meta_key(xp, glslCaps, 0, &b)) {
- glDesc->key().reset();
+ desc->key().reset();
return false;
}
requiredFeatures |= xp.requiredFeatures();
@@ -149,7 +147,7 @@ bool GrGLSLProgramDescBuilder::Build(GrProgramDesc* desc,
// --------DO NOT MOVE HEADER ABOVE THIS LINE--------------------------------------------------
// Because header is a pointer into the dynamic array, we can't push any new data into the key
// below here.
- KeyHeader* header = glDesc->atOffset<KeyHeader, kHeaderOffset>();
+ KeyHeader* header = desc->atOffset<KeyHeader, kHeaderOffset>();
// make sure any padding in the header is zeroed.
memset(header, 0, kHeaderSize);
@@ -182,6 +180,5 @@ bool GrGLSLProgramDescBuilder::Build(GrProgramDesc* desc,
header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters();
header->fColorEffectCnt = pipeline.numColorFragmentProcessors();
header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors();
- glDesc->finalize();
return true;
}
diff --git a/src/gpu/GrProgramDesc.h b/src/gpu/GrProgramDesc.h
index b17d146a8c..1f5a5819f5 100644
--- a/src/gpu/GrProgramDesc.h
+++ b/src/gpu/GrProgramDesc.h
@@ -13,13 +13,34 @@
#include "SkOpts.h"
#include "SkTArray.h"
-/** This class describes a program to generate. It also serves as a program cache key. Very little
- of this is GL-specific. The GL-specific parts could be factored out into a subclass. */
+class GrGLSLCaps;
+class GrPipeline;
+class GrPrimitiveProcessor;
+
+/** This class describes a program to generate. It also serves as a program cache key */
class GrProgramDesc {
public:
// Creates an uninitialized key that must be populated by GrGpu::buildProgramDesc()
GrProgramDesc() {}
+ /**
+ * Builds a program descriptor. Before the descriptor can be used, the client must call finalize
+ * on the returned GrProgramDesc.
+ *
+ * @param GrPrimitiveProcessor The geometry
+ * @param GrPipeline The optimized drawstate. The descriptor will represent a program
+ * which this optstate can use to draw with. The optstate contains
+ * general draw information, as well as the specific color, geometry,
+ * and coverage stages which will be used to generate the GL Program for
+ * this optstate.
+ * @param GrGLSLCaps Capabilities of the GLSL backend.
+ * @param GrProgramDesc The built and finalized descriptor
+ **/
+ static bool Build(GrProgramDesc*,
+ const GrPrimitiveProcessor&,
+ const GrPipeline&,
+ const GrGLSLCaps&);
+
// Returns this as a uint32_t array to be used as a key in the program cache.
const uint32_t* asKey() const {
return reinterpret_cast<const uint32_t*>(fKey.begin());
@@ -97,15 +118,6 @@ public:
// 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);
- }
-
- template<typename T, size_t OFFSET> const T* atOffset() const {
- return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin()) + OFFSET);
- }
-
void finalize() {
int keyLength = fKey.count();
SkASSERT(0 == (keyLength % 4));
@@ -116,11 +128,20 @@ protected:
*checksum = SkOpts::hash(fKey.begin(), keyLength);
}
+protected:
+ template<typename T, size_t OFFSET> T* atOffset() {
+ return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + OFFSET);
+ }
+
+ template<typename T, size_t OFFSET> const T* atOffset() const {
+ return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin()) + OFFSET);
+ }
+
// The key, stored in fKey, is composed of four parts:
// 1. uint32_t for total key length.
// 2. uint32_t for a checksum.
- // 3. Header struct defined above. Also room for extensions to the header
- // 4. A Backend specific payload. Room is preallocated for this
+ // 3. Header struct defined above.
+ // 4. A Backend specific payload which includes the per-processor keys.
enum KeyOffsets {
// Part 1.
kLengthOffset = 0,
@@ -128,7 +149,11 @@ protected:
kChecksumOffset = kLengthOffset + sizeof(uint32_t),
// Part 3.
kHeaderOffset = kChecksumOffset + sizeof(uint32_t),
- kHeaderSize = SkAlign4(2 * sizeof(KeyHeader)),
+ kHeaderSize = SkAlign4(sizeof(KeyHeader)),
+ // Part 4.
+ // This is the offset into the backenend specific part of the key, which includes
+ // per-processor keys.
+ kProcessorKeysOffset = kHeaderOffset + kHeaderSize,
};
enum {
diff --git a/src/gpu/gl/GrGLGpuProgramCache.cpp b/src/gpu/gl/GrGLGpuProgramCache.cpp
index ae93926c79..8dd5d0c29d 100644
--- a/src/gpu/gl/GrGLGpuProgramCache.cpp
+++ b/src/gpu/gl/GrGLGpuProgramCache.cpp
@@ -9,10 +9,10 @@
#include "builders/GrGLProgramBuilder.h"
#include "GrProcessor.h"
+#include "GrProgramDesc.h"
#include "GrGLPathRendering.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLProgramDataManager.h"
-#include "glsl/GrGLSLProgramDesc.h"
#include "SkTSearch.h"
#ifdef PROGRAM_CACHE_STATS
@@ -112,11 +112,12 @@ GrGLProgram* GrGLGpu::ProgramCache::refProgram(const GrGLGpu* gpu,
#endif
// Get GrGLProgramDesc
- GrGLSLProgramDesc desc;
- if (!GrGLSLProgramDescBuilder::Build(&desc, primProc, pipeline, *gpu->glCaps().glslCaps())) {
+ GrProgramDesc desc;
+ if (!GrProgramDesc::Build(&desc, primProc, pipeline, *gpu->glCaps().glslCaps())) {
GrCapsDebugf(gpu->caps(), "Failed to gl program descriptor!\n");
return nullptr;
}
+ desc.finalize();
Entry* entry = nullptr;
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index 462ea14294..ea98d87915 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -10,10 +10,10 @@
#define GrGLProgram_DEFINED
#include "GrGLContext.h"
+#include "GrProgramDesc.h"
#include "GrGLTexture.h"
#include "GrGLProgramDataManager.h"
#include "glsl/GrGLSLProgramDataManager.h"
-#include "glsl/GrGLSLProgramDesc.h"
#include "glsl/GrGLSLUniformHandler.h"
#include "SkString.h"
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index 2bbeb42af6..370cee6a0e 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -10,6 +10,7 @@
#include "GrAutoLocaleSetter.h"
#include "GrCoordTransform.h"
#include "GrGLProgramBuilder.h"
+#include "GrProgramDesc.h"
#include "GrSwizzle.h"
#include "GrTexture.h"
#include "SkTraceEvent.h"
@@ -21,7 +22,6 @@
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLGeometryProcessor.h"
#include "glsl/GrGLSLProgramDataManager.h"
-#include "glsl/GrGLSLProgramDesc.h"
#include "glsl/GrGLSLSampler.h"
#include "glsl/GrGLSLXferProcessor.h"
@@ -30,7 +30,7 @@
GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrPipeline& pipeline,
const GrPrimitiveProcessor& primProc,
- const GrGLSLProgramDesc& desc,
+ const GrProgramDesc& desc,
GrGLGpu* gpu) {
GrAutoLocaleSetter als("C");
@@ -56,7 +56,7 @@ GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrPipeline& pipeline,
GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu,
const GrPipeline& pipeline,
const GrPrimitiveProcessor& primProc,
- const GrGLSLProgramDesc& desc)
+ const GrProgramDesc& desc)
: INHERITED(pipeline, primProc, desc)
, fGpu(gpu)
, fVaryingHandler(this)
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h
index 4f441be668..253f9e6328 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.h
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.h
@@ -17,7 +17,7 @@
class GrFragmentProcessor;
class GrGLContextInfo;
-class GrGLSLProgramDesc;
+class GrProgramDesc;
class GrGLSLShaderBuilder;
class GrGLSLCaps;
@@ -32,7 +32,7 @@ public:
*/
static GrGLProgram* CreateProgram(const GrPipeline&,
const GrPrimitiveProcessor&,
- const GrGLSLProgramDesc&,
+ const GrProgramDesc&,
GrGLGpu*);
const GrCaps* caps() const override;
@@ -42,7 +42,7 @@ public:
private:
GrGLProgramBuilder(GrGLGpu*, const GrPipeline&, const GrPrimitiveProcessor&,
- const GrGLSLProgramDesc&);
+ const GrProgramDesc&);
bool compileAndAttachShaders(GrGLSLShaderBuilder& shader,
GrGLuint programId,
diff --git a/src/gpu/glsl/GrGLSLProgramDesc.h b/src/gpu/glsl/GrGLSLProgramDesc.h
deleted file mode 100644
index 1498179885..0000000000
--- a/src/gpu/glsl/GrGLSLProgramDesc.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-* Copyright 2016 Google Inc.
-*
-* Use of this source code is governed by a BSD-style license that can be
-* found in the LICENSE file.
-*/
-
-#ifndef GrGLSLProgramDesc_DEFINED
-#define GrGLSLProgramDesc_DEFINED
-
-#include "GrColor.h"
-#include "GrProgramDesc.h"
-#include "GrGpu.h"
-#include "GrTypesPriv.h"
-
-class GrGLSLProgramDescBuilder;
-
-class GrGLSLProgramDesc : public GrProgramDesc {
- friend class GrGLSLProgramDescBuilder;
-};
-
-/**
-* This class can be used to build a GrProgramDesc. It also provides helpers for accessing
-* GL specific info in the header.
-*/
-class GrGLSLProgramDescBuilder {
-public:
- typedef GrProgramDesc::KeyHeader KeyHeader;
- // The key, stored in fKey, is composed of five parts(first 2 are defined in the key itself):
- // 1. uint32_t for total key length.
- // 2. uint32_t for a checksum.
- // 3. Header struct defined above.
- // 4. Backend-specific information including per-processor keys and their key lengths.
- // Each processor's key is a variable length array of uint32_t.
- enum {
- // Part 3.
- kHeaderOffset = GrGLSLProgramDesc::kHeaderOffset,
- kHeaderSize = SkAlign4(sizeof(KeyHeader)),
- // Part 4.
- // This is the offset into the backenend specific part of the key, which includes
- // per-processor keys.
- kProcessorKeysOffset = kHeaderOffset + kHeaderSize,
- };
-
- /**
- * Builds a GLSL specific program descriptor
- *
- * @param GrPrimitiveProcessor The geometry
- * @param GrPipeline The optimized drawstate. The descriptor will represent a program
- * which this optstate can use to draw with. The optstate contains
- * general draw information, as well as the specific color, geometry,
- * and coverage stages which will be used to generate the GL Program for
- * this optstate.
- * @param GrGLSLCaps Capabilities of the GLSL backend.
- * @param GrProgramDesc The built and finalized descriptor
- **/
- static bool Build(GrProgramDesc*,
- const GrPrimitiveProcessor&,
- const GrPipeline&,
- const GrGLSLCaps&);
-};
-
-#endif
diff --git a/src/gpu/vk/GrVkPipelineState.h b/src/gpu/vk/GrVkPipelineState.h
index f92cdeabab..ad32ece6bc 100644
--- a/src/gpu/vk/GrVkPipelineState.h
+++ b/src/gpu/vk/GrVkPipelineState.h
@@ -9,12 +9,12 @@
#ifndef GrVkPipelineState_DEFINED
#define GrVkPipelineState_DEFINED
+#include "GrProgramDesc.h"
#include "GrStencilSettings.h"
#include "GrVkDescriptorSetManager.h"
#include "GrVkImage.h"
#include "GrVkPipelineStateDataManager.h"
#include "glsl/GrGLSLProgramBuilder.h"
-#include "glsl/GrGLSLProgramDesc.h"
#include "vk/GrVkDefines.h"
@@ -86,7 +86,7 @@ public:
*/
struct Desc {
uint32_t fChecksum;
- GrGLSLProgramDesc fProgramDesc;
+ GrProgramDesc fProgramDesc;
enum {
kRenderPassKeyAlloc = 12, // This is typical color attachment with no stencil or msaa
diff --git a/src/gpu/vk/GrVkPipelineStateBuilder.cpp b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
index f607c98989..dead7d142b 100644
--- a/src/gpu/vk/GrVkPipelineStateBuilder.cpp
+++ b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
@@ -39,7 +39,7 @@ GrVkPipelineState* GrVkPipelineStateBuilder::CreatePipelineState(
GrVkPipelineStateBuilder::GrVkPipelineStateBuilder(GrVkGpu* gpu,
const GrPipeline& pipeline,
const GrPrimitiveProcessor& primProc,
- const GrGLSLProgramDesc& desc)
+ const GrProgramDesc& desc)
: INHERITED(pipeline, primProc, desc)
, fGpu(gpu)
, fVaryingHandler(this)
diff --git a/src/gpu/vk/GrVkPipelineStateBuilder.h b/src/gpu/vk/GrVkPipelineStateBuilder.h
index 96d9fe2f22..c887e36d43 100644
--- a/src/gpu/vk/GrVkPipelineStateBuilder.h
+++ b/src/gpu/vk/GrVkPipelineStateBuilder.h
@@ -17,9 +17,9 @@
#include "vk/GrVkDefines.h"
+class GrProgramDesc;
class GrVkGpu;
class GrVkRenderPass;
-class GrGLSLProgramDesc;
class GrVkPipelineStateBuilder : public GrGLSLProgramBuilder {
public:
@@ -48,7 +48,7 @@ private:
GrVkPipelineStateBuilder(GrVkGpu*,
const GrPipeline&,
const GrPrimitiveProcessor&,
- const GrGLSLProgramDesc&);
+ const GrProgramDesc&);
GrVkPipelineState* finalize(GrPrimitiveType primitiveType,
const GrVkRenderPass& renderPass,
diff --git a/src/gpu/vk/GrVkPipelineStateCache.cpp b/src/gpu/vk/GrVkPipelineStateCache.cpp
index d404a8d444..1becad5adf 100644
--- a/src/gpu/vk/GrVkPipelineStateCache.cpp
+++ b/src/gpu/vk/GrVkPipelineStateCache.cpp
@@ -99,13 +99,11 @@ sk_sp<GrVkPipelineState> GrVkResourceProvider::PipelineStateCache::refPipelineSt
#endif
// Get GrVkProgramDesc
GrVkPipelineState::Desc desc;
- if (!GrGLSLProgramDescBuilder::Build(&desc.fProgramDesc,
- primProc,
- pipeline,
- *fGpu->vkCaps().glslCaps())) {
+ if (!GrProgramDesc::Build(&desc.fProgramDesc, primProc, pipeline, *fGpu->vkCaps().glslCaps())) {
GrCapsDebugf(fGpu->caps(), "Failed to build vk program descriptor!\n");
return nullptr;
}
+ desc.fProgramDesc.finalize();
// Get vulkan specific descriptor key
GrVkPipelineState::BuildStateKey(pipeline, primitiveType, &desc.fStateKey);