Merge GrGLSLProgramDesc into GrProgramDesc

BUG=skia:

Review-Url: https://codereview.chromium.org/2318523006
This commit is contained in:
egdaniel 2016-09-07 07:24:12 -07:00 committed by Commit bot
parent 653212c37e
commit 5d8f69f2d4
12 changed files with 70 additions and 113 deletions

View File

@ -146,6 +146,7 @@
'<(skia_src_path)/gpu/GrPipelineBuilder.h',
'<(skia_src_path)/gpu/GrPrimitiveProcessor.cpp',
'<(skia_src_path)/gpu/GrPrimitiveProcessor.h',
'<(skia_src_path)/gpu/GrProgramDesc.cpp',
'<(skia_src_path)/gpu/GrProgramDesc.h',
'<(skia_src_path)/gpu/GrProgramElement.cpp',
'<(skia_src_path)/gpu/GrProcessor.cpp',
@ -421,8 +422,6 @@
'<(skia_src_path)/gpu/glsl/GrGLSLProgramBuilder.h',
'<(skia_src_path)/gpu/glsl/GrGLSLProgramDataManager.cpp',
'<(skia_src_path)/gpu/glsl/GrGLSLProgramDataManager.h',
'<(skia_src_path)/gpu/glsl/GrGLSLProgramDesc.cpp',
'<(skia_src_path)/gpu/glsl/GrGLSLProgramDesc.h',
'<(skia_src_path)/gpu/glsl/GrGLSLSampler.h',
'<(skia_src_path)/gpu/glsl/GrGLSLShaderBuilder.cpp',
'<(skia_src_path)/gpu/glsl/GrGLSLShaderBuilder.h',

View File

@ -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;
}

View File

@ -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 {

View File

@ -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;

View File

@ -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"

View File

@ -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)

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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,

View File

@ -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);