From 5d8f69f2d492a15189e4b976ccca3fa092876419 Mon Sep 17 00:00:00 2001 From: egdaniel Date: Wed, 7 Sep 2016 07:24:12 -0700 Subject: Merge GrGLSLProgramDesc into GrProgramDesc BUG=skia: Review-Url: https://codereview.chromium.org/2318523006 --- src/gpu/GrProgramDesc.cpp | 184 ++++++++++++++++++++++++++++ src/gpu/GrProgramDesc.h | 53 +++++--- src/gpu/gl/GrGLGpuProgramCache.cpp | 7 +- src/gpu/gl/GrGLProgram.h | 2 +- src/gpu/gl/builders/GrGLProgramBuilder.cpp | 6 +- src/gpu/gl/builders/GrGLProgramBuilder.h | 6 +- src/gpu/glsl/GrGLSLProgramDesc.cpp | 187 ----------------------------- src/gpu/glsl/GrGLSLProgramDesc.h | 63 ---------- src/gpu/vk/GrVkPipelineState.h | 4 +- src/gpu/vk/GrVkPipelineStateBuilder.cpp | 2 +- src/gpu/vk/GrVkPipelineStateBuilder.h | 4 +- src/gpu/vk/GrVkPipelineStateCache.cpp | 6 +- 12 files changed, 241 insertions(+), 283 deletions(-) create mode 100644 src/gpu/GrProgramDesc.cpp delete mode 100644 src/gpu/glsl/GrGLSLProgramDesc.cpp delete mode 100644 src/gpu/glsl/GrGLSLProgramDesc.h (limited to 'src/gpu') diff --git a/src/gpu/GrProgramDesc.cpp b/src/gpu/GrProgramDesc.cpp new file mode 100644 index 0000000000..a22063c3f4 --- /dev/null +++ b/src/gpu/GrProgramDesc.cpp @@ -0,0 +1,184 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "GrProgramDesc.h" + +#include "GrProcessor.h" +#include "GrPipeline.h" +#include "GrRenderTargetPriv.h" +#include "SkChecksum.h" +#include "glsl/GrGLSLFragmentProcessor.h" +#include "glsl/GrGLSLFragmentShaderBuilder.h" +#include "glsl/GrGLSLCaps.h" + +static uint16_t sampler_key(GrSLType samplerType, GrPixelConfig config, GrShaderFlags visibility, + const GrGLSLCaps& caps) { + enum { + kFirstSamplerType = kTexture2DSampler_GrSLType, + kLastSamplerType = kTextureBufferSampler_GrSLType, + kSamplerTypeKeyBits = 4 + }; + GR_STATIC_ASSERT(kLastSamplerType - kFirstSamplerType < (1 << kSamplerTypeKeyBits)); + + SkASSERT((int)samplerType >= kFirstSamplerType && (int)samplerType <= kLastSamplerType); + int samplerTypeKey = samplerType - kFirstSamplerType; + + return SkToU16(caps.configTextureSwizzle(config).asKey() | + (samplerTypeKey << 8) | + (caps.samplerPrecision(config, visibility) << (8 + kSamplerTypeKeyBits))); +} + +static void add_sampler_keys(GrProcessorKeyBuilder* b, const GrProcessor& proc, + const GrGLSLCaps& caps) { + int numTextures = proc.numTextures(); + int numSamplers = numTextures + proc.numBuffers(); + // Need two bytes per key (swizzle, sampler type, and precision). + int word32Count = (numSamplers + 1) / 2; + if (0 == word32Count) { + return; + } + uint16_t* k16 = SkTCast(b->add32n(word32Count)); + int i = 0; + for (; i < numTextures; ++i) { + const GrTextureAccess& access = proc.textureAccess(i); + const GrTexture* tex = access.getTexture(); + k16[i] = sampler_key(tex->samplerType(), tex->config(), access.getVisibility(), caps); + } + for (; i < numSamplers; ++i) { + const GrBufferAccess& access = proc.bufferAccess(i - numTextures); + k16[i] = sampler_key(kTextureBufferSampler_GrSLType, access.texelConfig(), + access.visibility(), caps); + } + // zero the last 16 bits if the number of samplers is odd. + if (numSamplers & 0x1) { + k16[numSamplers] = 0; + } +} + +/** + * A function which emits a meta key into the key builder. This is required because shader code may + * be dependent on properties of the effect that the effect itself doesn't use + * in its key (e.g. the pixel format of textures used). So we create a meta-key for + * every effect using this function. It is also responsible for inserting the effect's class ID + * which must be different for every GrProcessor subclass. It can fail if an effect uses too many + * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and GPs share this + * function because it is hairy, though FPs do not have attribs, and GPs do not have transforms + */ +static bool gen_meta_key(const GrProcessor& proc, + const GrGLSLCaps& glslCaps, + uint32_t transformKey, + GrProcessorKeyBuilder* b) { + size_t processorKeySize = b->size(); + uint32_t classID = proc.classID(); + + // Currently we allow 16 bits for the class id and the overall processor key size. + static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)SK_MaxU16); + if ((processorKeySize | classID) & kMetaKeyInvalidMask) { + return false; + } + + add_sampler_keys(b, proc, glslCaps); + + uint32_t* key = b->add32n(2); + key[0] = (classID << 16) | SkToU32(processorKeySize); + key[1] = transformKey; + return true; +} + +static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc, + const GrFragmentProcessor& fp, + const GrGLSLCaps& glslCaps, + GrProcessorKeyBuilder* b) { + for (int i = 0; i < fp.numChildProcessors(); ++i) { + if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), glslCaps, b)) { + return false; + } + } + + fp.getGLSLProcessorKey(glslCaps, b); + + return gen_meta_key(fp, glslCaps, primProc.getTransformKey(fp.coordTransforms(), + fp.numTransformsExclChildren()), b); +} + +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. + + GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t)); + // Make room for everything up to the effect keys. + desc->key().reset(); + desc->key().push_back_n(kProcessorKeysOffset); + + GrProcessorKeyBuilder b(&desc->key()); + + primProc.getGLSLProcessorKey(glslCaps, &b); + if (!gen_meta_key(primProc, glslCaps, 0, &b)) { + desc->key().reset(); + return false; + } + GrProcessor::RequiredFeatures requiredFeatures = primProc.requiredFeatures(); + + 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)) { + desc->key().reset(); + return false; + } + requiredFeatures |= fp.requiredFeatures(); + } + + const GrXferProcessor& xp = pipeline.getXferProcessor(); + xp.getGLSLProcessorKey(glslCaps, &b); + if (!gen_meta_key(xp, glslCaps, 0, &b)) { + desc->key().reset(); + return false; + } + requiredFeatures |= xp.requiredFeatures(); + + // --------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 = desc->atOffset(); + + // make sure any padding in the header is zeroed. + memset(header, 0, kHeaderSize); + + GrRenderTarget* rt = pipeline.getRenderTarget(); + + if (requiredFeatures & (GrProcessor::kFragmentPosition_RequiredFeature | + GrProcessor::kSampleLocations_RequiredFeature)) { + header->fSurfaceOriginKey = GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(rt->origin()); + } else { + header->fSurfaceOriginKey = 0; + } + + if (requiredFeatures & GrProcessor::kSampleLocations_RequiredFeature) { + SkASSERT(pipeline.isHWAntialiasState()); + header->fSamplePatternKey = + rt->renderTargetPriv().getMultisampleSpecs(pipeline.getStencil()).fUniqueID; + } else { + header->fSamplePatternKey = 0; + } + + header->fOutputSwizzle = glslCaps.configOutputSwizzle(rt->config()).asKey(); + + if (pipeline.ignoresCoverage()) { + header->fIgnoresCoverage = 1; + } else { + header->fIgnoresCoverage = 0; + } + + header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); + header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); + header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); + 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(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(); } -protected: - template T* atOffset() { - return reinterpret_cast(reinterpret_cast(fKey.begin()) + OFFSET); - } - - template const T* atOffset() const { - return reinterpret_cast(reinterpret_cast(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 T* atOffset() { + return reinterpret_cast(reinterpret_cast(fKey.begin()) + OFFSET); + } + + template const T* atOffset() const { + return reinterpret_cast(reinterpret_cast(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.cpp b/src/gpu/glsl/GrGLSLProgramDesc.cpp deleted file mode 100644 index c44759a5ef..0000000000 --- a/src/gpu/glsl/GrGLSLProgramDesc.cpp +++ /dev/null @@ -1,187 +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. - */ -#include "GrGLSLProgramDesc.h" - -#include "GrProcessor.h" -#include "GrPipeline.h" -#include "GrRenderTargetPriv.h" -#include "SkChecksum.h" -#include "glsl/GrGLSLFragmentProcessor.h" -#include "glsl/GrGLSLFragmentShaderBuilder.h" -#include "glsl/GrGLSLCaps.h" - -static uint16_t sampler_key(GrSLType samplerType, GrPixelConfig config, GrShaderFlags visibility, - const GrGLSLCaps& caps) { - enum { - kFirstSamplerType = kTexture2DSampler_GrSLType, - kLastSamplerType = kTextureBufferSampler_GrSLType, - kSamplerTypeKeyBits = 4 - }; - GR_STATIC_ASSERT(kLastSamplerType - kFirstSamplerType < (1 << kSamplerTypeKeyBits)); - - SkASSERT((int)samplerType >= kFirstSamplerType && (int)samplerType <= kLastSamplerType); - int samplerTypeKey = samplerType - kFirstSamplerType; - - return SkToU16(caps.configTextureSwizzle(config).asKey() | - (samplerTypeKey << 8) | - (caps.samplerPrecision(config, visibility) << (8 + kSamplerTypeKeyBits))); -} - -static void add_sampler_keys(GrProcessorKeyBuilder* b, const GrProcessor& proc, - const GrGLSLCaps& caps) { - int numTextures = proc.numTextures(); - int numSamplers = numTextures + proc.numBuffers(); - // Need two bytes per key (swizzle, sampler type, and precision). - int word32Count = (numSamplers + 1) / 2; - if (0 == word32Count) { - return; - } - uint16_t* k16 = SkTCast(b->add32n(word32Count)); - int i = 0; - for (; i < numTextures; ++i) { - const GrTextureAccess& access = proc.textureAccess(i); - const GrTexture* tex = access.getTexture(); - k16[i] = sampler_key(tex->samplerType(), tex->config(), access.getVisibility(), caps); - } - for (; i < numSamplers; ++i) { - const GrBufferAccess& access = proc.bufferAccess(i - numTextures); - k16[i] = sampler_key(kTextureBufferSampler_GrSLType, access.texelConfig(), - access.visibility(), caps); - } - // zero the last 16 bits if the number of samplers is odd. - if (numSamplers & 0x1) { - k16[numSamplers] = 0; - } -} - -/** - * A function which emits a meta key into the key builder. This is required because shader code may - * be dependent on properties of the effect that the effect itself doesn't use - * in its key (e.g. the pixel format of textures used). So we create a meta-key for - * every effect using this function. It is also responsible for inserting the effect's class ID - * which must be different for every GrProcessor subclass. It can fail if an effect uses too many - * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and GPs share this - * function because it is hairy, though FPs do not have attribs, and GPs do not have transforms - */ -static bool gen_meta_key(const GrProcessor& proc, - const GrGLSLCaps& glslCaps, - uint32_t transformKey, - GrProcessorKeyBuilder* b) { - size_t processorKeySize = b->size(); - uint32_t classID = proc.classID(); - - // Currently we allow 16 bits for the class id and the overall processor key size. - static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)SK_MaxU16); - if ((processorKeySize | classID) & kMetaKeyInvalidMask) { - return false; - } - - add_sampler_keys(b, proc, glslCaps); - - uint32_t* key = b->add32n(2); - key[0] = (classID << 16) | SkToU32(processorKeySize); - key[1] = transformKey; - return true; -} - -static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc, - const GrFragmentProcessor& fp, - const GrGLSLCaps& glslCaps, - GrProcessorKeyBuilder* b) { - for (int i = 0; i < fp.numChildProcessors(); ++i) { - if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), glslCaps, b)) { - return false; - } - } - - fp.getGLSLProcessorKey(glslCaps, b); - - return gen_meta_key(fp, glslCaps, primProc.getTransformKey(fp.coordTransforms(), - fp.numTransformsExclChildren()), b); -} - -bool GrGLSLProgramDescBuilder::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); - - GrProcessorKeyBuilder b(&glDesc->key()); - - primProc.getGLSLProcessorKey(glslCaps, &b); - if (!gen_meta_key(primProc, glslCaps, 0, &b)) { - glDesc->key().reset(); - return false; - } - GrProcessor::RequiredFeatures requiredFeatures = primProc.requiredFeatures(); - - 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(); - return false; - } - requiredFeatures |= fp.requiredFeatures(); - } - - const GrXferProcessor& xp = pipeline.getXferProcessor(); - xp.getGLSLProcessorKey(glslCaps, &b); - if (!gen_meta_key(xp, glslCaps, 0, &b)) { - glDesc->key().reset(); - return false; - } - requiredFeatures |= xp.requiredFeatures(); - - // --------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(); - - // make sure any padding in the header is zeroed. - memset(header, 0, kHeaderSize); - - GrRenderTarget* rt = pipeline.getRenderTarget(); - - if (requiredFeatures & (GrProcessor::kFragmentPosition_RequiredFeature | - GrProcessor::kSampleLocations_RequiredFeature)) { - header->fSurfaceOriginKey = GrGLSLFragmentShaderBuilder::KeyForSurfaceOrigin(rt->origin()); - } else { - header->fSurfaceOriginKey = 0; - } - - if (requiredFeatures & GrProcessor::kSampleLocations_RequiredFeature) { - SkASSERT(pipeline.isHWAntialiasState()); - header->fSamplePatternKey = - rt->renderTargetPriv().getMultisampleSpecs(pipeline.getStencil()).fUniqueID; - } else { - header->fSamplePatternKey = 0; - } - - header->fOutputSwizzle = glslCaps.configOutputSwizzle(rt->config()).asKey(); - - if (pipeline.ignoresCoverage()) { - header->fIgnoresCoverage = 1; - } else { - header->fIgnoresCoverage = 0; - } - - header->fSnapVerticesToPixelCenters = pipeline.snapVerticesToPixelCenters(); - header->fColorEffectCnt = pipeline.numColorFragmentProcessors(); - header->fCoverageEffectCnt = pipeline.numCoverageFragmentProcessors(); - glDesc->finalize(); - return true; -} 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 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); -- cgit v1.2.3