Flutter Engine
The Flutter Engine
GrVkPipelineStateDataManager.cpp
Go to the documentation of this file.
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
9
16
18 uint32_t uniformSize,
19 bool usePushConstants)
20 : INHERITED(uniforms.count(), uniformSize)
21 , fUsePushConstants(usePushConstants) {
22 // We must add uniforms in same order as the UniformInfoArray so that UniformHandles already
23 // owned by other objects will still match up here.
24 int i = 0;
27 for (const auto& uniformInfo : uniforms.items()) {
28 Uniform& uniform = fUniforms[i];
29 SkASSERT(GrShaderVar::kNonArray == uniformInfo.fVariable.getArrayCount() ||
30 uniformInfo.fVariable.getArrayCount() > 0);
32 uniform.fArrayCount = uniformInfo.fVariable.getArrayCount();
33 )
34
35 uniform.fOffset = uniformInfo.fOffsets[memLayout];
36 uniform.fType = uniformInfo.fVariable.getType();
37 ++i;
38 }
39}
40
41std::pair<sk_sp<GrGpuBuffer>, bool> GrVkPipelineStateDataManager::uploadUniforms(
42 GrVkGpu* gpu, VkPipelineLayout layout, GrVkCommandBuffer* commandBuffer) {
43 if (fUniformSize == 0) {
44 return std::make_pair(nullptr, true);
45 }
46 if (fUsePushConstants) {
47 commandBuffer->pushConstants(gpu, layout, gpu->vkCaps().getPushConstantStageFlags(),
49 fUniformBuffer = nullptr;
50 } else {
51 if (fUniformsDirty) {
52 GrResourceProvider* resourceProvider = gpu->getContext()->priv().resourceProvider();
53 fUniformBuffer = resourceProvider->createBuffer(fUniformData.get(),
57 if (!fUniformBuffer) {
58 return std::make_pair(nullptr, false);
59 }
60 fUniformsDirty = false;
61 }
62 }
63
64 return std::make_pair(fUniformBuffer, true);
65}
66
68 int arrayCount,
69 const int32_t v[]) const {
70 if (fUsePushConstants) {
71 const Uniform& uni = fUniforms[u.toIndex()];
73 SkASSERT(arrayCount > 0);
74 SkASSERT(arrayCount <= uni.fArrayCount ||
75 (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
76
77 void* buffer = this->getBufferPtrAndMarkDirty(uni);
78 SkASSERT(sizeof(int32_t) == 4);
79 memcpy(buffer, v, arrayCount * sizeof(int32_t));
80 } else {
81 return this->INHERITED::set1iv(u, arrayCount, v);
82 }
83}
84
86 int arrayCount,
87 const float v[]) const {
88 if (fUsePushConstants) {
89 const Uniform& uni = fUniforms[u.toIndex()];
91 SkASSERT(arrayCount > 0);
92 SkASSERT(arrayCount <= uni.fArrayCount ||
93 (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
94
95 void* buffer = this->getBufferPtrAndMarkDirty(uni);
96 SkASSERT(sizeof(float) == 4);
97 memcpy(buffer, v, arrayCount * sizeof(float));
98 } else {
99 return this->INHERITED::set1fv(u, arrayCount, v);
100 }
101}
102
104 int arrayCount,
105 const int32_t v[]) const {
106 if (fUsePushConstants) {
107 const Uniform& uni = fUniforms[u.toIndex()];
109 SkASSERT(arrayCount > 0);
110 SkASSERT(arrayCount <= uni.fArrayCount ||
111 (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
112
113 void* buffer = this->getBufferPtrAndMarkDirty(uni);
114 SkASSERT(sizeof(int32_t) == 4);
115 memcpy(buffer, v, arrayCount * 2 * sizeof(int32_t));
116 } else {
117 return this->INHERITED::set2iv(u, arrayCount, v);
118 }
119}
120
122 int arrayCount,
123 const float v[]) const {
124 if (fUsePushConstants) {
125 const Uniform& uni = fUniforms[u.toIndex()];
127 SkASSERT(arrayCount > 0);
128 SkASSERT(arrayCount <= uni.fArrayCount ||
129 (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
130
131 void* buffer = this->getBufferPtrAndMarkDirty(uni);
132 SkASSERT(sizeof(float) == 4);
133 memcpy(buffer, v, arrayCount * 2 * sizeof(float));
134 } else {
135 return this->INHERITED::set2fv(u, arrayCount, v);
136 }
137}
138
140 int arrayCount,
141 const float m[]) const {
142 if (fUsePushConstants) {
143 // upload as std430
144 const Uniform& uni = fUniforms[u.toIndex()];
146 SkASSERT(arrayCount > 0);
147 SkASSERT(arrayCount <= uni.fArrayCount ||
148 (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
149
150 void* buffer = fUniformData.get();
151 fUniformsDirty = true;
152
153 static_assert(sizeof(float) == 4);
154 buffer = static_cast<char*>(buffer) + uni.fOffset;
155 memcpy(buffer, m, arrayCount * 2 * 2 * sizeof(float));
156 } else {
157 this->INHERITED::setMatrix2fv(u, arrayCount, m);
158 }
159}
160
int count
Definition: FontMgrTest.cpp:50
@ kDynamic_GrAccessPattern
Definition: GrTypesPriv.h:426
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
GrResourceProvider * resourceProvider()
GrDirectContextPriv priv()
GrDirectContext * getContext()
Definition: GrGpu.h:67
sk_sp< GrGpuBuffer > createBuffer(size_t size, GrGpuBufferType, GrAccessPattern, ZeroInit)
void set1fv(UniformHandle, int arrayCount, const float v[]) const override
void * getBufferPtrAndMarkDirty(const Uniform &uni) const
void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override
void set2iv(UniformHandle, int arrayCount, const int32_t v[]) const override
void set2fv(UniformHandle, int arrayCount, const float v[]) const override
void set1iv(UniformHandle, int arrayCount, const int32_t v[]) const override
skia_private::TArray< Uniform, true > fUniforms
VkShaderStageFlags getPushConstantStageFlags() const
Definition: GrVkCaps.cpp:2060
void pushConstants(const GrVkGpu *gpu, VkPipelineLayout layout, VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size, const void *values)
const GrVkCaps & vkCaps() const
Definition: GrVkGpu.h:61
std::pair< sk_sp< GrGpuBuffer >, bool > uploadUniforms(GrVkGpu *gpu, VkPipelineLayout, GrVkCommandBuffer *commandBuffer)
void set1fv(UniformHandle, int arrayCount, const float v[]) const override
void set2fv(UniformHandle, int arrayCount, const float v[]) const override
void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override
void set1iv(UniformHandle, int arrayCount, const int32_t v[]) const override
void set2iv(UniformHandle, int arrayCount, const int32_t v[]) const override
GrVkPipelineStateDataManager(const UniformInfoArray &, uint32_t uniformSize, bool usePushConstants)
void * get()
Definition: SkAutoMalloc.h:64
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126