OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #ifndef GrVkPipelineState_DEFINED | 9 #ifndef GrVkPipelineState_DEFINED |
10 #define GrVkPipelineState_DEFINED | 10 #define GrVkPipelineState_DEFINED |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 void addUniformResources(GrVkCommandBuffer&); | 49 void addUniformResources(GrVkCommandBuffer&); |
50 | 50 |
51 void freeGPUResources(const GrVkGpu* gpu); | 51 void freeGPUResources(const GrVkGpu* gpu); |
52 | 52 |
53 // This releases resources that only a given instance of a GrVkPipelineState
needs to hold onto | 53 // This releases resources that only a given instance of a GrVkPipelineState
needs to hold onto |
54 // and don't need to survive across new uses of the GrVkPipelineState. | 54 // and don't need to survive across new uses of the GrVkPipelineState. |
55 void freeTempResources(const GrVkGpu* gpu); | 55 void freeTempResources(const GrVkGpu* gpu); |
56 | 56 |
57 void abandonGPUResources(); | 57 void abandonGPUResources(); |
58 | 58 |
59 // The key is composed of two parts: | |
60 // 1. uint32_t for total key length | |
61 // 2. Pipeline state data | |
62 enum StateKeyOffsets { | |
63 // Part 1. | |
64 kLength_StateKeyOffset = 0, | |
65 // Part 2. | |
66 kData_StateKeyOffset = kLength_StateKeyOffset + sizeof(uint32_t), | |
67 }; | |
68 static void BuildStateKey(const GrPipeline&, GrPrimitiveType primitiveType, | |
69 SkTArray<unsigned char, true>* key); | |
70 | |
71 /** | 59 /** |
72 * For Vulkan we want to cache the entire VkPipeline for reuse of draws. The
Desc here holds all | 60 * For Vulkan we want to cache the entire VkPipeline for reuse of draws. The
Desc here holds all |
73 * the information needed to differentiate one pipeline from another. | 61 * the information needed to differentiate one pipeline from another. |
74 * | 62 * |
75 * The GrGLSLProgramDesc contains all the information need to create the act
ual shaders for the | 63 * The GrProgramDesc contains all the information need to create the actual
shaders for the |
76 * pipeline. | 64 * pipeline. |
77 * | 65 * |
78 * The fStateKey is used to store all the inputs for the rest of the state s
tored on the | 66 * For Vulkan we need to add to the GrProgramDesc to include the rest of the
state on the |
79 * pipeline. This includes stencil settings, blending information, render pa
ss format, draw face | 67 * pipline. This includes stencil settings, blending information, render pas
s format, draw face |
80 * information, and primitive type. Note that some state is set dynamically
on the pipeline for | 68 * information, and primitive type. Note that some state is set dynamically
on the pipeline for |
81 * each draw and thus is not included in this descriptor. This includes the
viewport, scissor, | 69 * each draw and thus is not included in this descriptor. This includes the
viewport, scissor, |
82 * and blend constant. | 70 * and blend constant. |
83 * | |
84 * A checksum which includes the fProgramDesc and fStateKey is included at t
he top of the Desc | |
85 * for caching purposes and faster equality checks. | |
86 */ | 71 */ |
87 struct Desc { | 72 class Desc : public GrProgramDesc { |
88 uint32_t fChecksum; | 73 public: |
89 GrProgramDesc fProgramDesc; | 74 static bool Build(Desc*, |
90 | 75 const GrPrimitiveProcessor&, |
91 enum { | 76 const GrPipeline&, |
92 kRenderPassKeyAlloc = 12, // This is typical color attachment with n
o stencil or msaa | 77 GrPrimitiveType primitiveType, |
93 kStencilKeyAlloc = sizeof(GrStencilSettings), | 78 const GrGLSLCaps&); |
94 kDrawFaceKeyAlloc = 4, | 79 private: |
95 kBlendingKeyAlloc = 4, | 80 typedef GrProgramDesc INHERITED; |
96 kPrimitiveTypeKeyAlloc = 4, | |
97 kPreAllocSize = kData_StateKeyOffset + kRenderPassKeyAlloc + kStenci
lKeyAlloc + | |
98 kDrawFaceKeyAlloc + kBlendingKeyAlloc + kPrimitiveTy
peKeyAlloc, | |
99 }; | |
100 SkSTArray<kPreAllocSize, uint8_t, true> fStateKey; | |
101 | |
102 bool operator== (const Desc& that) const { | |
103 if (fChecksum != that.fChecksum || fProgramDesc != that.fProgramDesc
) { | |
104 return false; | |
105 } | |
106 // We store the keyLength at the start of fVkKey. Thus we don't have
to worry about | |
107 // different length keys since we will fail on the comparison immedi
ately. Therefore we | |
108 // just use this PipelineDesc to get the length to iterate over. | |
109 int keyLength = fStateKey.count(); | |
110 SkASSERT(SkIsAlign4(keyLength)); | |
111 int l = keyLength >> 2; | |
112 const uint32_t* aKey = reinterpret_cast<const uint32_t*>(fStateKey.b
egin()); | |
113 const uint32_t* bKey = reinterpret_cast<const uint32_t*>(that.fState
Key.begin()); | |
114 for (int i = 0; i < l; ++i) { | |
115 if (aKey[i] != bKey[i]) { | |
116 return false; | |
117 } | |
118 } | |
119 return true; | |
120 } | |
121 | |
122 static bool Less(const Desc& a, const Desc& b) { | |
123 if (a.fChecksum != b.fChecksum) { | |
124 return a.fChecksum < b.fChecksum ? true : false; | |
125 } | |
126 bool progDescLess = GrProgramDesc::Less(a.fProgramDesc, b.fProgramDe
sc); | |
127 if (progDescLess || a.fProgramDesc != b.fProgramDesc) { | |
128 return progDescLess; | |
129 } | |
130 | |
131 int keyLength = a.fStateKey.count(); | |
132 SkASSERT(SkIsAlign4(keyLength)); | |
133 int l = keyLength >> 2; | |
134 const uint32_t* aKey = reinterpret_cast<const uint32_t*>(a.fStateKey
.begin()); | |
135 const uint32_t* bKey = reinterpret_cast<const uint32_t*>(b.fStateKey
.begin()); | |
136 for (int i = 0; i < l; ++i) { | |
137 if (aKey[i] != bKey[i]) { | |
138 return aKey[i] < bKey[i] ? true : false; | |
139 } | |
140 } | |
141 return false; | |
142 } | |
143 }; | 81 }; |
144 | 82 |
145 const Desc& getDesc() { return fDesc; } | 83 const Desc& getDesc() { return fDesc; } |
146 | 84 |
147 private: | 85 private: |
148 typedef GrVkPipelineStateDataManager::UniformInfoArray UniformInfoArray; | 86 typedef GrVkPipelineStateDataManager::UniformInfoArray UniformInfoArray; |
149 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 87 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
150 | 88 |
151 GrVkPipelineState(GrVkGpu* gpu, | 89 GrVkPipelineState(GrVkGpu* gpu, |
152 const GrVkPipelineState::Desc&, | 90 const GrVkPipelineState::Desc&, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 Desc fDesc; | 227 Desc fDesc; |
290 | 228 |
291 GrVkPipelineStateDataManager fDataManager; | 229 GrVkPipelineStateDataManager fDataManager; |
292 | 230 |
293 int fNumSamplers; | 231 int fNumSamplers; |
294 | 232 |
295 friend class GrVkPipelineStateBuilder; | 233 friend class GrVkPipelineStateBuilder; |
296 }; | 234 }; |
297 | 235 |
298 #endif | 236 #endif |
OLD | NEW |