Debian Codegraph @

src/gpu/ganesh/vk/GrVkPipelineState.h

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