Flutter Engine
The Flutter Engine
GrMtlPipelineStateDataManager.mm
Go to the documentation of this file.
1/*
2 * Copyright 2018 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
13
14#if !__has_feature(objc_arc)
15#error This file must be compiled with Arc. Use -fobjc-arc flag
16#endif
17
18GR_NORETAIN_BEGIN
19
21 uint32_t uniformSize)
22 : INHERITED(uniforms.count(), uniformSize) {
23 // We must add uniforms in same order is the UniformInfoArray so that UniformHandles already
24 // owned by other objects will still match up here.
25 int i = 0;
26 for (const auto& uniformInfo : uniforms.items()) {
27 Uniform& uniform = fUniforms[i];
28 SkASSERT(GrShaderVar::kNonArray == uniformInfo.fVariable.getArrayCount() ||
29 uniformInfo.fVariable.getArrayCount() > 0);
31 uniform.fArrayCount = uniformInfo.fVariable.getArrayCount();
32 )
33 uniform.fOffset = uniformInfo.fUBOffset;
34 uniform.fType = uniformInfo.fVariable.getType();
35 ++i;
36 }
37
39}
40
42 int arrayCount,
43 const int32_t v[]) const {
44 const Uniform& uni = fUniforms[u.toIndex()];
46 SkASSERT(arrayCount > 0);
47 SkASSERT(arrayCount <= uni.fArrayCount ||
48 (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
49
50 void* buffer = this->getBufferPtrAndMarkDirty(uni);
51 this->copyUniforms(buffer, v, arrayCount, uni.fType);
52}
53
55 int arrayCount,
56 const float v[]) const {
57 const Uniform& uni = fUniforms[u.toIndex()];
59 SkASSERT(arrayCount > 0);
60 SkASSERT(arrayCount <= uni.fArrayCount ||
61 (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
62
63 void* buffer = this->getBufferPtrAndMarkDirty(uni);
64 this->copyUniforms(buffer, v, arrayCount, uni.fType);
65}
66
68 int arrayCount,
69 const int32_t v[]) const {
70 const Uniform& uni = fUniforms[u.toIndex()];
72 SkASSERT(arrayCount > 0);
73 SkASSERT(arrayCount <= uni.fArrayCount ||
74 (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
75
76 void* buffer = this->getBufferPtrAndMarkDirty(uni);
77 this->copyUniforms(buffer, v, arrayCount * 2, uni.fType);
78}
79
81 int arrayCount,
82 const float v[]) const {
83 const Uniform& uni = fUniforms[u.toIndex()];
85 SkASSERT(arrayCount > 0);
86 SkASSERT(arrayCount <= uni.fArrayCount ||
87 (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
88
89 void* buffer = this->getBufferPtrAndMarkDirty(uni);
90 this->copyUniforms(buffer, v, arrayCount * 2, uni.fType);
91}
92
93void GrMtlPipelineStateDataManager::setMatrix2f(UniformHandle u, const float matrix[]) const {
94 this->setMatrix2fv(u, 1, matrix);
95}
96
98 int arrayCount,
99 const float m[]) const {
100 const Uniform& uni = fUniforms[u.toIndex()];
102 SkASSERT(arrayCount > 0);
103 SkASSERT(arrayCount <= uni.fArrayCount ||
104 (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
105
106 void* buffer = this->getBufferPtrAndMarkDirty(uni);
107 this->copyUniforms(buffer, m, arrayCount * 4, uni.fType);
108}
109
111 GrMtlGpu* gpu,
112 GrMtlRenderCommandEncoder* renderCmdEncoder) const {
114 fUniformsDirty = false;
115 if (@available(macOS 10.11, iOS 8.3, tvOS 9.0, *)) {
116 if (fUniformSize <= gpu->caps()->maxPushConstantsSize()) {
117 renderCmdEncoder->setVertexBytes(fUniformData.get(), fUniformSize,
119 renderCmdEncoder->setFragmentBytes(fUniformData.get(), fUniformSize,
121 return;
122 }
123 }
124
125 // upload the data
128 char* destPtr = static_cast<char*>(slice.fBuffer->map()) + slice.fOffset;
129 memcpy(destPtr, fUniformData.get(), fUniformSize);
130
131 renderCmdEncoder->setVertexBuffer(buffer->mtlBuffer(), slice.fOffset,
133 renderCmdEncoder->setFragmentBuffer(buffer->mtlBuffer(), slice.fOffset,
135 }
136}
137
139 fUniformsDirty = true;
140}
141
142GR_NORETAIN_END
int count
Definition: FontMgrTest.cpp:50
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
void * map()
Definition: GrGpuBuffer.cpp:28
GrRingBuffer * uniformsRingBuffer() override
Definition: GrMtlGpu.h:118
void set2iv(UniformHandle, int arrayCount, const int32_t v[]) const override
void setMatrix2f(UniformHandle, const float matrix[]) const override
void set1iv(UniformHandle, int arrayCount, const int32_t v[]) const override
void set2fv(UniformHandle, int arrayCount, const float v[]) const override
void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override
GrMtlPipelineStateDataManager(const UniformInfoArray &, uint32_t uniformSize)
void set1fv(UniformHandle, int arrayCount, const float v[]) const override
void uploadAndBindUniformBuffers(GrMtlGpu *gpu, GrMtlRenderCommandEncoder *renderCmdEncoder) const
void setFragmentBuffer(id< MTLBuffer > buffer, NSUInteger offset, NSUInteger index)
void setFragmentBytes(const void *bytes, NSUInteger length, NSUInteger index) SK_API_AVAILABLE(macos(10.11)
void setVertexBytes(const void *bytes, NSUInteger length, NSUInteger index) SK_API_AVAILABLE(macos(10.11)
void setVertexBuffer(id< MTLBuffer > buffer, NSUInteger offset, NSUInteger index)
Slice suballocate(size_t size)
void * getBufferPtrAndMarkDirty(const Uniform &uni) const
int copyUniforms(void *dest, const void *src, int numUniforms, SkSLType uniformType) const
skia_private::TArray< Uniform, true > fUniforms
void * get()
Definition: SkAutoMalloc.h:64
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
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
GrGpuBuffer * fBuffer
Definition: GrRingBuffer.h:40