aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2018-06-08 10:49:00 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-08 19:43:47 +0000
commit1471df99f0c7b5d9df43e7462d68a6635c3c59be (patch)
tree5da4a18207b47907ba3d538c38a9d8ae2dfff9ef
parentd0d409d3ebd083b4f5263949e404c1700c615d3b (diff)
Remove include of GrGLProgramBuilder.h from GrGLProgram.h and GrVkPipelineState.h
Make GrGLProgram and GrCkPipelineState cons. public and remove builder friendship. Neither GrGLProgram nor GrVkPipelineState need to know their Desc so remove it. Move the VK desc subclass defn. to GrVkPipelineStateBuilder since it needs it while GrVkPipelineState does not. Some IWYU improvements. Move declaration of the built-in uniform struct to GrGLSLUniformHandler.h from GrGLSLProgramBuilder.h. Change-Id: Ib46817408a83a79a0f718ba2bc19411410d9065a Reviewed-on: https://skia-review.googlesource.com/133060 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
-rw-r--r--samplecode/SampleCCPRGeometry.cpp1
-rw-r--r--src/gpu/GrPathProcessor.cpp3
-rw-r--r--src/gpu/gl/GrGLProgram.cpp7
-rw-r--r--src/gpu/gl/GrGLProgram.h57
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.cpp1
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.h11
-rw-r--r--src/gpu/glsl/GrGLSLUniformHandler.h8
-rw-r--r--src/gpu/vk/GrVkPipeline.cpp2
-rw-r--r--src/gpu/vk/GrVkPipelineState.cpp55
-rw-r--r--src/gpu/vk/GrVkPipelineState.h81
-rw-r--r--src/gpu/vk/GrVkPipelineStateBuilder.cpp65
-rw-r--r--src/gpu/vk/GrVkPipelineStateBuilder.h41
-rw-r--r--src/gpu/vk/GrVkPipelineStateCache.cpp14
-rw-r--r--src/gpu/vk/GrVkResourceProvider.h5
14 files changed, 161 insertions, 190 deletions
diff --git a/samplecode/SampleCCPRGeometry.cpp b/samplecode/SampleCCPRGeometry.cpp
index 52e1181e8c..f2f88bff45 100644
--- a/samplecode/SampleCCPRGeometry.cpp
+++ b/samplecode/SampleCCPRGeometry.cpp
@@ -24,6 +24,7 @@
#include "ccpr/GrCCCoverageProcessor.h"
#include "ccpr/GrCCGeometry.h"
#include "gl/GrGLGpu.cpp"
+#include "glsl/GrGLSLFragmentProcessor.h"
#include "ops/GrDrawOp.h"
using TriPointInstance = GrCCCoverageProcessor::TriPointInstance;
diff --git a/src/gpu/GrPathProcessor.cpp b/src/gpu/GrPathProcessor.cpp
index 3dc6601d29..43c0bb07ca 100644
--- a/src/gpu/GrPathProcessor.cpp
+++ b/src/gpu/GrPathProcessor.cpp
@@ -6,10 +6,11 @@
*/
#include "GrPathProcessor.h"
-
#include "GrShaderCaps.h"
#include "gl/GrGLGpu.h"
+#include "gl/GrGLVaryingHandler.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLPrimitiveProcessor.h"
#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLVarying.h"
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index 1be8126552..ea5c18c4ff 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -25,9 +25,9 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
-GrGLProgram::GrGLProgram(GrGLGpu* gpu,
- const GrProgramDesc& desc,
- const BuiltinUniformHandles& builtinUniforms,
+GrGLProgram::GrGLProgram(
+ GrGLGpu* gpu,
+ const GrGLSLBuiltinUniformHandles& builtinUniforms,
GrGLuint programID,
const UniformInfoArray& uniforms,
const UniformInfoArray& textureSamplers,
@@ -43,7 +43,6 @@ GrGLProgram::GrGLProgram(GrGLGpu* gpu,
, fXferProcessor(std::move(xferProcessor))
, fFragmentProcessors(std::move(fragmentProcessors))
, fFragmentProcessorCnt(fragmentProcessorCnt)
- , fDesc(desc)
, fGpu(gpu)
, fProgramDataManager(gpu, programID, uniforms, pathProcVaryings)
, fNumTextureSamplers(textureSamplers.count())
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index 79d27b0d0c..a43e4f4294 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -9,20 +9,17 @@
#ifndef GrGLProgram_DEFINED
#define GrGLProgram_DEFINED
-#include "GrGLContext.h"
-#include "GrProgramDesc.h"
-#include "GrGLTexture.h"
#include "GrGLProgramDataManager.h"
#include "glsl/GrGLSLProgramDataManager.h"
#include "glsl/GrGLSLUniformHandler.h"
-#include "SkString.h"
-
-#include "builders/GrGLProgramBuilder.h"
-
-class GrGLInstalledProcessors;
-class GrGLProgramBuilder;
+class GrGLSLFragmentProcessor;
+class GrGLSLPrimitiveProcessor;
+class GrGLSLXferProcessor;
class GrPipeline;
+class GrPrimitiveProcessor;
+class GrRenderTargetProxy;
+class GrResourceIOProcessor;
/**
* This class manages a GPU program and records per-program information.
@@ -35,7 +32,21 @@ class GrPipeline;
*/
class GrGLProgram : public SkRefCnt {
public:
- typedef GrGLSLProgramBuilder::BuiltinUniformHandles BuiltinUniformHandles;
+ using UniformHandle = GrGLSLProgramDataManager::UniformHandle;
+ using UniformInfoArray = GrGLProgramDataManager::UniformInfoArray;
+ using VaryingInfoArray = GrGLProgramDataManager::VaryingInfoArray;
+
+ GrGLProgram(GrGLGpu*,
+ const GrGLSLBuiltinUniformHandles&,
+ GrGLuint programID,
+ const UniformInfoArray& uniforms,
+ const UniformInfoArray& textureSamplers,
+ const UniformInfoArray& texelBuffers,
+ const VaryingInfoArray&, // used for NVPR only currently
+ std::unique_ptr<GrGLSLPrimitiveProcessor> geometryProcessor,
+ std::unique_ptr<GrGLSLXferProcessor> xferProcessor,
+ std::unique_ptr<std::unique_ptr<GrGLSLFragmentProcessor>[]> fragmentProcessors,
+ int fragmentProcessorCnt);
~GrGLProgram();
@@ -44,8 +55,6 @@ public:
*/
void abandon();
- const GrProgramDesc& getDesc() { return fDesc; }
-
/**
* Gets the GL program ID for this program.
*/
@@ -101,24 +110,7 @@ public:
*/
void generateMipmaps(const GrPrimitiveProcessor&, const GrPipeline&);
-protected:
- using UniformHandle = GrGLSLProgramDataManager::UniformHandle ;
- using UniformInfoArray = GrGLProgramDataManager::UniformInfoArray;
- using VaryingInfoArray = GrGLProgramDataManager::VaryingInfoArray;
-
- GrGLProgram(GrGLGpu*,
- const GrProgramDesc&,
- const BuiltinUniformHandles&,
- GrGLuint programID,
- const UniformInfoArray& uniforms,
- const UniformInfoArray& textureSamplers,
- const UniformInfoArray& texelBuffers,
- const VaryingInfoArray&, // used for NVPR only currently
- std::unique_ptr<GrGLSLPrimitiveProcessor> geometryProcessor,
- std::unique_ptr<GrGLSLXferProcessor> xferProcessor,
- std::unique_ptr<std::unique_ptr<GrGLSLFragmentProcessor>[]> fragmentProcessors,
- int fragmentProcessorCnt);
-
+private:
// A helper to loop over effects, set the transforms (via subclass) and bind textures
void setFragmentData(const GrPrimitiveProcessor&, const GrPipeline&, int* nextTexSamplerIdx,
int* nextTexelBufferIdx);
@@ -134,7 +126,7 @@ protected:
// these reflect the current values of uniforms (GL uniform values travel with program)
RenderTargetState fRenderTargetState;
- BuiltinUniformHandles fBuiltinUniformHandles;
+ GrGLSLBuiltinUniformHandles fBuiltinUniformHandles;
GrGLuint fProgramID;
// the installed effects
@@ -143,15 +135,12 @@ protected:
std::unique_ptr<std::unique_ptr<GrGLSLFragmentProcessor>[]> fFragmentProcessors;
int fFragmentProcessorCnt;
- GrProgramDesc fDesc;
GrGLGpu* fGpu;
GrGLProgramDataManager fProgramDataManager;
int fNumTextureSamplers;
int fNumTexelBuffers;
- friend class GrGLProgramBuilder;
-
typedef SkRefCnt INHERITED;
};
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index 658390228d..86dcfef7a4 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -385,7 +385,6 @@ void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) {
GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) {
return new GrGLProgram(fGpu,
- *this->desc(),
fUniformHandles,
programID,
fUniformHandler.fUniforms,
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h
index 04d169d4d9..7d0ce74abe 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.h
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.h
@@ -54,15 +54,6 @@ public:
return this->uniformHandler()->texelBufferVariable(handle);
}
- // Handles for program uniforms (other than per-effect uniforms)
- struct BuiltinUniformHandles {
- UniformHandle fRTAdjustmentUni;
-
- // We use the render target height to provide a y-down frag coord when specifying
- // origin_upper_left is not supported.
- UniformHandle fRTHeightUni;
- };
-
// Used to add a uniform for the RenderTarget height (used for frag position) without mangling
// the name of the uniform inside of a stage.
void addRTHeightUniform(const char* name);
@@ -94,7 +85,7 @@ public:
const GrPrimitiveProcessor& fPrimProc;
GrProgramDesc* fDesc;
- BuiltinUniformHandles fUniformHandles;
+ GrGLSLBuiltinUniformHandles fUniformHandles;
std::unique_ptr<GrGLSLPrimitiveProcessor> fGeometryProcessor;
std::unique_ptr<GrGLSLXferProcessor> fXferProcessor;
diff --git a/src/gpu/glsl/GrGLSLUniformHandler.h b/src/gpu/glsl/GrGLSLUniformHandler.h
index 662486eebe..fe89b882b6 100644
--- a/src/gpu/glsl/GrGLSLUniformHandler.h
+++ b/src/gpu/glsl/GrGLSLUniformHandler.h
@@ -17,6 +17,14 @@
class GrGLSLProgramBuilder;
+// Handles for program uniforms (other than per-effect uniforms)
+struct GrGLSLBuiltinUniformHandles {
+ GrGLSLProgramDataManager::UniformHandle fRTAdjustmentUni;
+ // We use the render target height to provide a y-down frag coord when specifying
+ // origin_upper_left is not supported.
+ GrGLSLProgramDataManager::UniformHandle fRTHeightUni;
+};
+
class GrGLSLUniformHandler {
public:
virtual ~GrGLSLUniformHandler() {}
diff --git a/src/gpu/vk/GrVkPipeline.cpp b/src/gpu/vk/GrVkPipeline.cpp
index b72b05b850..500ab967cc 100644
--- a/src/gpu/vk/GrVkPipeline.cpp
+++ b/src/gpu/vk/GrVkPipeline.cpp
@@ -6,9 +6,9 @@
*/
#include "GrVkPipeline.h"
-
#include "GrGeometryProcessor.h"
#include "GrPipeline.h"
+#include "GrStencilSettings.h"
#include "GrVkCommandBuffer.h"
#include "GrVkGpu.h"
#include "GrVkRenderTarget.h"
diff --git a/src/gpu/vk/GrVkPipelineState.cpp b/src/gpu/vk/GrVkPipelineState.cpp
index f49e636161..993f57d9e4 100644
--- a/src/gpu/vk/GrVkPipelineState.cpp
+++ b/src/gpu/vk/GrVkPipelineState.cpp
@@ -6,10 +6,10 @@
*/
#include "GrVkPipelineState.h"
-
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrPipeline.h"
+#include "GrRenderTarget.h"
#include "GrTexturePriv.h"
#include "GrVkBufferView.h"
#include "GrVkCommandBuffer.h"
@@ -19,23 +19,22 @@
#include "GrVkImageView.h"
#include "GrVkMemory.h"
#include "GrVkPipeline.h"
-#include "GrVkRenderTarget.h"
#include "GrVkSampler.h"
#include "GrVkTexelBuffer.h"
#include "GrVkTexture.h"
#include "GrVkUniformBuffer.h"
+#include "SkMipMap.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLGeometryProcessor.h"
#include "glsl/GrGLSLXferProcessor.h"
-#include "SkMipMap.h"
-GrVkPipelineState::GrVkPipelineState(GrVkGpu* gpu,
- const GrVkPipelineState::Desc& desc,
+GrVkPipelineState::GrVkPipelineState(
+ GrVkGpu* gpu,
GrVkPipeline* pipeline,
VkPipelineLayout layout,
const GrVkDescriptorSetManager::Handle& samplerDSHandle,
const GrVkDescriptorSetManager::Handle& texelBufferDSHandle,
- const BuiltinUniformHandles& builtinUniformHandles,
+ const GrGLSLBuiltinUniformHandles& builtinUniformHandles,
const UniformInfoArray& uniforms,
uint32_t geometryUniformSize,
uint32_t fragmentUniformSize,
@@ -57,7 +56,6 @@ GrVkPipelineState::GrVkPipelineState(GrVkGpu* gpu,
, fXferProcessor(std::move(xferProcessor))
, fFragmentProcessors(std::move(fragmentProcessors))
, fFragmentProcessorCnt(fragmentProcessorCnt)
- , fDesc(desc)
, fDataManager(uniforms, geometryUniformSize, fragmentUniformSize) {
fSamplers.setReserve(numSamplers);
fTextureViews.setReserve(numSamplers);
@@ -543,46 +541,3 @@ void GrVkPipelineState::addUniformResources(GrVkCommandBuffer& commandBuffer) {
commandBuffer.addResource(fTexelBuffers[i]);
}
}
-
-////////////////////////////////////////////////////////////////////////////////
-
-uint32_t get_blend_info_key(const GrPipeline& pipeline) {
- GrXferProcessor::BlendInfo blendInfo;
- pipeline.getXferProcessor().getBlendInfo(&blendInfo);
-
- static const uint32_t kBlendWriteShift = 1;
- static const uint32_t kBlendCoeffShift = 5;
- GR_STATIC_ASSERT(kLast_GrBlendCoeff < (1 << kBlendCoeffShift));
- GR_STATIC_ASSERT(kFirstAdvancedGrBlendEquation - 1 < 4);
-
- uint32_t key = blendInfo.fWriteColor;
- key |= (blendInfo.fSrcBlend << kBlendWriteShift);
- key |= (blendInfo.fDstBlend << (kBlendWriteShift + kBlendCoeffShift));
- key |= (blendInfo.fEquation << (kBlendWriteShift + 2 * kBlendCoeffShift));
-
- return key;
-}
-
-bool GrVkPipelineState::Desc::Build(Desc* desc,
- const GrPrimitiveProcessor& primProc,
- const GrPipeline& pipeline,
- const GrStencilSettings& stencil,
- GrPrimitiveType primitiveType,
- const GrShaderCaps& caps) {
- if (!INHERITED::Build(desc, primProc, primitiveType == GrPrimitiveType::kPoints, pipeline,
- caps)) {
- return false;
- }
-
- GrProcessorKeyBuilder b(&desc->key());
- GrVkRenderTarget* vkRT = (GrVkRenderTarget*)pipeline.renderTarget();
- vkRT->simpleRenderPass()->genKey(&b);
-
- stencil.genKey(&b);
-
- b.add32(get_blend_info_key(pipeline));
-
- b.add32((uint32_t)primitiveType);
-
- return true;
-}
diff --git a/src/gpu/vk/GrVkPipelineState.h b/src/gpu/vk/GrVkPipelineState.h
index 92fa5e50d7..2ea01c1479 100644
--- a/src/gpu/vk/GrVkPipelineState.h
+++ b/src/gpu/vk/GrVkPipelineState.h
@@ -9,16 +9,13 @@
#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 "vk/GrVkDefines.h"
class GrPipeline;
+class GrStencilSettings;
class GrVkBufferView;
class GrVkCommandBuffer;
class GrVkDescriptorPool;
@@ -37,11 +34,27 @@ class GrVkUniformBuffer;
*/
class GrVkPipelineState : public SkRefCnt {
public:
- typedef GrGLSLProgramBuilder::BuiltinUniformHandles BuiltinUniformHandles;
+ using UniformInfoArray = GrVkPipelineStateDataManager::UniformInfoArray;
+ using UniformHandle = GrGLSLProgramDataManager::UniformHandle;
- ~GrVkPipelineState();
+ GrVkPipelineState(
+ GrVkGpu* gpu,
+ GrVkPipeline* pipeline,
+ VkPipelineLayout layout,
+ const GrVkDescriptorSetManager::Handle& samplerDSHandle,
+ const GrVkDescriptorSetManager::Handle& texelBufferDSHandle,
+ const GrGLSLBuiltinUniformHandles& builtinUniformHandles,
+ const UniformInfoArray& uniforms,
+ uint32_t geometryUniformSize,
+ uint32_t fragmentUniformSize,
+ uint32_t numSamplers,
+ uint32_t numTexelBuffers,
+ std::unique_ptr<GrGLSLPrimitiveProcessor> geometryProcessor,
+ std::unique_ptr<GrGLSLXferProcessor> xferProcessor,
+ std::unique_ptr<std::unique_ptr<GrGLSLFragmentProcessor>[]> fragmentProcessors,
+ int fFragmentProcessorCnt);
- GrVkPipeline* vkPipeline() const { return fPipeline; }
+ ~GrVkPipelineState();
void setData(GrVkGpu*, const GrPrimitiveProcessor&, const GrPipeline&);
@@ -57,55 +70,7 @@ public:
void abandonGPUResources();
- /**
- * For Vulkan we want to cache the entire VkPipeline for reuse of draws. The Desc here holds all
- * the information needed to differentiate one pipeline from another.
- *
- * The GrProgramDesc contains all the information need to create the actual shaders for the
- * pipeline.
- *
- * For Vulkan we need to add to the GrProgramDesc to include the rest of the state on the
- * pipline. This includes stencil settings, blending information, render pass format, draw face
- * information, and primitive type. Note that some state is set dynamically on the pipeline for
- * each draw and thus is not included in this descriptor. This includes the viewport, scissor,
- * and blend constant.
- */
- class Desc : public GrProgramDesc {
- public:
- static bool Build(Desc*,
- const GrPrimitiveProcessor&,
- const GrPipeline&,
- const GrStencilSettings&,
- GrPrimitiveType primitiveType,
- const GrShaderCaps&);
- private:
- typedef GrProgramDesc INHERITED;
- };
-
- const Desc& getDesc() { return fDesc; }
-
private:
- typedef GrVkPipelineStateDataManager::UniformInfoArray UniformInfoArray;
- typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
-
- GrVkPipelineState(
- GrVkGpu* gpu,
- const GrVkPipelineState::Desc&,
- GrVkPipeline* pipeline,
- VkPipelineLayout layout,
- const GrVkDescriptorSetManager::Handle& samplerDSHandle,
- const GrVkDescriptorSetManager::Handle& texelBufferDSHandle,
- const BuiltinUniformHandles& builtinUniformHandles,
- const UniformInfoArray& uniforms,
- uint32_t geometryUniformSize,
- uint32_t fragmentUniformSize,
- uint32_t numSamplers,
- uint32_t numTexelBuffers,
- std::unique_ptr<GrGLSLPrimitiveProcessor> geometryProcessor,
- std::unique_ptr<GrGLSLXferProcessor> xferProcessor,
- std::unique_ptr<std::unique_ptr<GrGLSLFragmentProcessor>[]> fragmentProcessors,
- int fFragmentProcessorCnt);
-
void writeUniformBuffers(const GrVkGpu* gpu);
void writeSamplers(
@@ -190,7 +155,7 @@ private:
// Tracks the current render target uniforms stored in the vertex buffer.
RenderTargetState fRenderTargetState;
- BuiltinUniformHandles fBuiltinUniformHandles;
+ GrGLSLBuiltinUniformHandles fBuiltinUniformHandles;
// Processors in the GrVkPipelineState
std::unique_ptr<GrGLSLPrimitiveProcessor> fGeometryProcessor;
@@ -198,14 +163,10 @@ private:
std::unique_ptr<std::unique_ptr<GrGLSLFragmentProcessor>[]> fFragmentProcessors;
int fFragmentProcessorCnt;
- Desc fDesc;
-
GrVkPipelineStateDataManager fDataManager;
int fNumSamplers;
int fNumTexelBuffers;
-
- friend class GrVkPipelineStateBuilder;
};
#endif
diff --git a/src/gpu/vk/GrVkPipelineStateBuilder.cpp b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
index 2893a3e53f..c67847ce9c 100644
--- a/src/gpu/vk/GrVkPipelineStateBuilder.cpp
+++ b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
@@ -6,23 +6,23 @@
*/
#include "vk/GrVkPipelineStateBuilder.h"
-
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrShaderCaps.h"
+#include "GrStencilSettings.h"
+#include "GrVkRenderTarget.h"
#include "vk/GrVkDescriptorSetManager.h"
#include "vk/GrVkGpu.h"
#include "vk/GrVkRenderPass.h"
-
GrVkPipelineState* GrVkPipelineStateBuilder::CreatePipelineState(
- GrVkGpu* gpu,
- const GrPipeline& pipeline,
- const GrStencilSettings& stencil,
- const GrPrimitiveProcessor& primProc,
- GrPrimitiveType primitiveType,
- GrVkPipelineState::Desc* desc,
- const GrVkRenderPass& renderPass) {
+ GrVkGpu* gpu,
+ const GrPipeline& pipeline,
+ const GrStencilSettings& stencil,
+ const GrPrimitiveProcessor& primProc,
+ GrPrimitiveType primitiveType,
+ Desc* desc,
+ const GrVkRenderPass& renderPass) {
// create a builder. This will be handed off to effects so they can use it to add
// uniforms, varyings, textures, etc
GrVkPipelineStateBuilder builder(gpu, pipeline, primProc, desc);
@@ -61,7 +61,7 @@ bool GrVkPipelineStateBuilder::createVkShaderModule(VkShaderStageFlagBits stage,
VkShaderModule* shaderModule,
VkPipelineShaderStageCreateInfo* stageInfo,
const SkSL::Program::Settings& settings,
- GrVkPipelineState::Desc* desc) {
+ Desc* desc) {
SkString shaderString;
for (int i = 0; i < builder.fCompilerStrings.count(); ++i) {
if (builder.fCompilerStrings[i]) {
@@ -90,7 +90,7 @@ bool GrVkPipelineStateBuilder::createVkShaderModule(VkShaderStageFlagBits stage,
GrVkPipelineState* GrVkPipelineStateBuilder::finalize(const GrStencilSettings& stencil,
GrPrimitiveType primitiveType,
const GrVkRenderPass& renderPass,
- GrVkPipelineState::Desc* desc) {
+ Desc* desc) {
VkDescriptorSetLayout dsLayout[3];
VkPipelineLayout pipelineLayout;
VkShaderModule vertShaderModule = VK_NULL_HANDLE;
@@ -195,7 +195,6 @@ GrVkPipelineState* GrVkPipelineStateBuilder::finalize(const GrStencilSettings& s
}
return new GrVkPipelineState(fGpu,
- *desc,
pipeline,
pipelineLayout,
samplerDSHandle,
@@ -212,3 +211,45 @@ GrVkPipelineState* GrVkPipelineStateBuilder::finalize(const GrStencilSettings& s
fFragmentProcessorCnt);
}
+//////////////////////////////////////////////////////////////////////////////
+
+uint32_t get_blend_info_key(const GrPipeline& pipeline) {
+ GrXferProcessor::BlendInfo blendInfo;
+ pipeline.getXferProcessor().getBlendInfo(&blendInfo);
+
+ static const uint32_t kBlendWriteShift = 1;
+ static const uint32_t kBlendCoeffShift = 5;
+ GR_STATIC_ASSERT(kLast_GrBlendCoeff < (1 << kBlendCoeffShift));
+ GR_STATIC_ASSERT(kFirstAdvancedGrBlendEquation - 1 < 4);
+
+ uint32_t key = blendInfo.fWriteColor;
+ key |= (blendInfo.fSrcBlend << kBlendWriteShift);
+ key |= (blendInfo.fDstBlend << (kBlendWriteShift + kBlendCoeffShift));
+ key |= (blendInfo.fEquation << (kBlendWriteShift + 2 * kBlendCoeffShift));
+
+ return key;
+}
+
+bool GrVkPipelineStateBuilder::Desc::Build(Desc* desc,
+ const GrPrimitiveProcessor& primProc,
+ const GrPipeline& pipeline,
+ const GrStencilSettings& stencil,
+ GrPrimitiveType primitiveType,
+ const GrShaderCaps& caps) {
+ if (!INHERITED::Build(desc, primProc, primitiveType == GrPrimitiveType::kPoints, pipeline,
+ caps)) {
+ return false;
+ }
+
+ GrProcessorKeyBuilder b(&desc->key());
+ GrVkRenderTarget* vkRT = (GrVkRenderTarget*)pipeline.renderTarget();
+ vkRT->simpleRenderPass()->genKey(&b);
+
+ stencil.genKey(&b);
+
+ b.add32(get_blend_info_key(pipeline));
+
+ b.add32((uint32_t)primitiveType);
+
+ return true;
+}
diff --git a/src/gpu/vk/GrVkPipelineStateBuilder.h b/src/gpu/vk/GrVkPipelineStateBuilder.h
index ae59ec4e02..5fdb0eae5a 100644
--- a/src/gpu/vk/GrVkPipelineStateBuilder.h
+++ b/src/gpu/vk/GrVkPipelineStateBuilder.h
@@ -8,22 +8,47 @@
#ifndef GrVkPipelineStateBuilder_DEFINED
#define GrVkPipelineStateBuilder_DEFINED
-#include "glsl/GrGLSLProgramBuilder.h"
-
#include "GrPipeline.h"
+#include "GrProgramDesc.h"
#include "GrVkPipelineState.h"
#include "GrVkUniformHandler.h"
#include "GrVkVaryingHandler.h"
#include "SkSLCompiler.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "vk/GrVkDefines.h"
-class GrProgramDesc;
class GrVkGpu;
class GrVkRenderPass;
class GrVkPipelineStateBuilder : public GrGLSLProgramBuilder {
public:
+ /**
+ * For Vulkan we want to cache the entire VkPipeline for reuse of draws. The Desc here holds all
+ * the information needed to differentiate one pipeline from another.
+ *
+ * The GrProgramDesc contains all the information need to create the actual shaders for the
+ * pipeline.
+ *
+ * For Vulkan we need to add to the GrProgramDesc to include the rest of the state on the
+ * pipline. This includes stencil settings, blending information, render pass format, draw face
+ * information, and primitive type. Note that some state is set dynamically on the pipeline for
+ * each draw and thus is not included in this descriptor. This includes the viewport, scissor,
+ * and blend constant.
+ */
+ class Desc : public GrProgramDesc {
+ public:
+ static bool Build(Desc*,
+ const GrPrimitiveProcessor&,
+ const GrPipeline&,
+ const GrStencilSettings&,
+ GrPrimitiveType primitiveType,
+ const GrShaderCaps&);
+
+ private:
+ typedef GrProgramDesc INHERITED;
+ };
+
/** Generates a pipeline state.
*
* The GrVkPipelineState implements what is specified in the GrPipeline and GrPrimitiveProcessor
@@ -37,7 +62,7 @@ public:
const GrStencilSettings&,
const GrPrimitiveProcessor&,
GrPrimitiveType,
- GrVkPipelineState::Desc*,
+ Desc*,
const GrVkRenderPass& renderPass);
const GrCaps* caps() const override;
@@ -56,22 +81,22 @@ private:
GrVkPipelineState* finalize(const GrStencilSettings&,
GrPrimitiveType primitiveType,
const GrVkRenderPass& renderPass,
- GrVkPipelineState::Desc*);
+ Desc*);
bool createVkShaderModule(VkShaderStageFlagBits stage,
const GrGLSLShaderBuilder& builder,
VkShaderModule* shaderModule,
VkPipelineShaderStageCreateInfo* stageInfo,
const SkSL::Program::Settings& settings,
- GrVkPipelineState::Desc* desc);
+ Desc* desc);
GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
GrVkGpu* fGpu;
- GrVkVaryingHandler fVaryingHandler;
- GrVkUniformHandler fUniformHandler;
+ GrVkVaryingHandler fVaryingHandler;
+ GrVkUniformHandler fUniformHandler;
typedef GrGLSLProgramBuilder INHERITED;
};
diff --git a/src/gpu/vk/GrVkPipelineStateCache.cpp b/src/gpu/vk/GrVkPipelineStateCache.cpp
index caffe05bd5..f7423c790b 100644
--- a/src/gpu/vk/GrVkPipelineStateCache.cpp
+++ b/src/gpu/vk/GrVkPipelineStateCache.cpp
@@ -5,13 +5,13 @@
* found in the LICENSE file.
*/
-#include "GrVkResourceProvider.h"
-
-#include "GrVkGpu.h"
#include "GrProcessor.h"
-#include "GrRenderTargetPriv.h" // TODO: remove once refPipelineState gets passed stencil settings.
+#include "GrRenderTargetPriv.h" // TODO: remove once refPipelineState gets passed stencil settings.
+#include "GrStencilSettings.h"
+#include "GrVkGpu.h"
#include "GrVkPipelineState.h"
#include "GrVkPipelineStateBuilder.h"
+#include "GrVkResourceProvider.h"
#include "SkOpts.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLProgramDataManager.h"
@@ -91,9 +91,9 @@ GrVkPipelineState* GrVkResourceProvider::PipelineStateCache::refPipelineState(
}
// Get GrVkProgramDesc
- GrVkPipelineState::Desc desc;
- if (!GrVkPipelineState::Desc::Build(&desc, primProc, pipeline, stencil,
- primitiveType, *fGpu->caps()->shaderCaps())) {
+ GrVkPipelineStateBuilder::Desc desc;
+ if (!GrVkPipelineStateBuilder::Desc::Build(&desc, primProc, pipeline, stencil, primitiveType,
+ *fGpu->caps()->shaderCaps())) {
GrCapsDebugf(fGpu->caps(), "Failed to build vk program descriptor!\n");
return nullptr;
}
diff --git a/src/gpu/vk/GrVkResourceProvider.h b/src/gpu/vk/GrVkResourceProvider.h
index d130f0c06d..00263c87f6 100644
--- a/src/gpu/vk/GrVkResourceProvider.h
+++ b/src/gpu/vk/GrVkResourceProvider.h
@@ -11,7 +11,7 @@
#include "GrResourceHandle.h"
#include "GrVkDescriptorPool.h"
#include "GrVkDescriptorSetManager.h"
-#include "GrVkPipelineState.h"
+#include "GrVkPipelineStateBuilder.h"
#include "GrVkRenderPass.h"
#include "GrVkResource.h"
#include "GrVkUtil.h"
@@ -28,6 +28,7 @@ class GrSamplerState;
class GrVkCopyPipeline;
class GrVkGpu;
class GrVkPipeline;
+class GrVkPipelineState;
class GrVkPrimaryCommandBuffer;
class GrVkRenderTarget;
class GrVkSampler;
@@ -190,7 +191,7 @@ private:
}
};
- SkLRUCache<const GrVkPipelineState::Desc, std::unique_ptr<Entry>, DescHash> fMap;
+ SkLRUCache<const GrVkPipelineStateBuilder::Desc, std::unique_ptr<Entry>, DescHash> fMap;
GrVkGpu* fGpu;