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