• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 
9 #ifndef GrVkPipelineState_DEFINED
10 #define GrVkPipelineState_DEFINED
11 
12 #include "include/gpu/vk/GrVkTypes.h"
13 #include "src/gpu/GrRefCnt.h"
14 #include "src/gpu/glsl/GrGLSLProgramBuilder.h"
15 #include "src/gpu/vk/GrVkDescriptorSet.h"
16 #include "src/gpu/vk/GrVkDescriptorSetManager.h"
17 #include "src/gpu/vk/GrVkPipelineStateDataManager.h"
18 
19 class GrPipeline;
20 class GrStencilSettings;
21 class GrVkBuffer;
22 class GrVkCommandBuffer;
23 class GrVkDescriptorPool;
24 class GrVkGpu;
25 class GrVkImageView;
26 class GrVkPipeline;
27 class GrVkRenderTarget;
28 class GrVkSampler;
29 class GrVkTexture;
30 
31 /**
32  * This class holds onto a GrVkPipeline object that we use for draws. Besides storing the acutal
33  * GrVkPipeline object, this class is also responsible handling all uniforms, descriptors, samplers,
34  * and other similar objects that are used along with the VkPipeline in the draw. This includes both
35  * allocating and freeing these objects, as well as updating their values.
36  */
37 class GrVkPipelineState {
38 public:
39     using UniformInfoArray = GrVkPipelineStateDataManager::UniformInfoArray;
40     using UniformHandle = GrGLSLProgramDataManager::UniformHandle;
41 
42     GrVkPipelineState(GrVkGpu*,
43                       sk_sp<const GrVkPipeline>,
44                       const GrVkDescriptorSetManager::Handle& samplerDSHandle,
45                       const GrGLSLBuiltinUniformHandles& builtinUniformHandles,
46                       const UniformInfoArray& uniforms,
47                       uint32_t uniformSize,
48                       bool usePushConstants,
49                       const UniformInfoArray& samplers,
50                       std::unique_ptr<GrGeometryProcessor::ProgramImpl>,
51                       std::unique_ptr<GrXferProcessor::ProgramImpl>,
52                       std::vector<std::unique_ptr<GrFragmentProcessor::ProgramImpl>> fpImpls);
53 
54     ~GrVkPipelineState();
55 
56     bool setAndBindUniforms(GrVkGpu*, SkISize colorAttachmentDimensions, const GrProgramInfo&,
57                             GrVkCommandBuffer*);
58     /**
59      * This must be called after setAndBindUniforms() since that function invalidates texture
60      * bindings.
61      */
62     bool setAndBindTextures(GrVkGpu*,
63                             const GrGeometryProcessor&,
64                             const GrPipeline&,
65                             const GrSurfaceProxy* const geomProcTextures[],
66                             GrVkCommandBuffer*);
67 
68     bool setAndBindInputAttachment(GrVkGpu*, gr_rp<const GrVkDescriptorSet> inputDescSet,
69                                    GrVkCommandBuffer*);
70 
71     void bindPipeline(const GrVkGpu* gpu, GrVkCommandBuffer* commandBuffer);
72 
73     void freeGPUResources(GrVkGpu* gpu);
74 
75 private:
76     /**
77      * We use the RT's size and origin to adjust from Skia device space to vulkan normalized device
78      * space and to make device space positions have the correct origin for processors that require
79      * them.
80      */
81     struct RenderTargetState {
82         SkISize         fRenderTargetSize;
83         GrSurfaceOrigin fRenderTargetOrigin;
84 
RenderTargetStateRenderTargetState85         RenderTargetState() { this->invalidate(); }
invalidateRenderTargetState86         void invalidate() {
87             fRenderTargetSize.fWidth = -1;
88             fRenderTargetSize.fHeight = -1;
89             fRenderTargetOrigin = (GrSurfaceOrigin)-1;
90         }
91     };
92 
93     // Helper for setData() that sets the view matrix and loads the render target height uniform
94     void setRenderTargetState(SkISize colorAttachmentDimensions, GrSurfaceOrigin);
95 
96     // GrManagedResources
97     sk_sp<const GrVkPipeline> fPipeline;
98 
99     const GrVkDescriptorSetManager::Handle fSamplerDSHandle;
100 
101     SkSTArray<4, const GrVkSampler*> fImmutableSamplers;
102 
103     // Tracks the current render target uniforms stored in the vertex buffer.
104     RenderTargetState fRenderTargetState;
105     GrGLSLBuiltinUniformHandles fBuiltinUniformHandles;
106 
107     // Processors in the GrVkPipelineState
108     std::unique_ptr<GrGeometryProcessor::ProgramImpl>              fGPImpl;
109     std::unique_ptr<GrXferProcessor::ProgramImpl>                  fXPImpl;
110     std::vector<std::unique_ptr<GrFragmentProcessor::ProgramImpl>> fFPImpls;
111 
112     GrVkPipelineStateDataManager fDataManager;
113 
114     int fNumSamplers;
115 };
116 
117 #endif
118