1 /* 2 * Copyright 2021 Google LLC 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 skgpu_UniformManager_DEFINED 9 #define skgpu_UniformManager_DEFINED 10 11 #include "experimental/graphite/src/DrawTypes.h" 12 #include "experimental/graphite/src/Uniform.h" 13 #include "include/core/SkSpan.h" 14 15 namespace skgpu { 16 17 enum class Layout { 18 kStd140, 19 kStd430, 20 kMetal, /** This is our own self-imposed layout we use for Metal. */ 21 }; 22 23 class UniformManager { 24 public: 25 UniformManager(Layout layout); 26 27 /* 28 * Use the uniform 'definitions' to write the data in 'srcs' into 'dst' (if it is non-null). 29 * If non-null, 'offsets' is filled in with the offset of each uniform w/in 'dst'. The 30 * number of bytes that was written (or would've been written) to 'dst' is returned. 31 * In practice one should call: 32 * auto bytes = writeUniforms(definitions, nullptr, nullptr, nullptr); 33 * // allocate dst and offsets memory 34 * writeUniforms(definitions, src, offsets, dst); 35 */ 36 uint32_t writeUniforms(SkSpan<const Uniform> definitions, 37 void** srcs, 38 uint32_t* offsets, 39 void *dst); 40 41 private: 42 SLType getUniformTypeForLayout(SLType type); 43 44 Layout fLayout; 45 }; 46 47 } // namespace skgpu 48 49 #endif // skgpu_UniformManager_DEFINED 50