xref: /aosp_15_r20/external/angle/src/compiler/translator/wgsl/OutputUniformBlocks.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2024 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #ifndef COMPILER_TRANSLATOR_WGSL_OUTPUT_UNIFORM_BLOCKS_H_
8 #define COMPILER_TRANSLATOR_WGSL_OUTPUT_UNIFORM_BLOCKS_H_
9 
10 #include "compiler/translator/Compiler.h"
11 #include "compiler/translator/IntermNode.h"
12 
13 namespace sh
14 {
15 
16 const char kDefaultUniformBlockVarType[]     = "ANGLE_DefaultUniformBlock";
17 const char kDefaultUniformBlockVarName[]     = "ANGLE_defaultUniformBlock";
18 const uint32_t kDefaultUniformBlockBindGroup = 0;
19 const uint32_t kDefaultVertexUniformBlockBinding   = 0;
20 const uint32_t kDefaultFragmentUniformBlockBinding = 1;
21 
22 struct UniformBlockMetadata
23 {
24     // A list of structs used anywhere in the uniform address space. These will require special
25     // handling (@align() attributes, wrapping of basic types, etc.) to ensure they fit WGSL's
26     // uniform layout requirements.
27     // The key is TSymbolUniqueId::get().
28     TUnorderedSet<int> structsInUniformAddressSpace;
29 };
30 
31 // Given a GLSL AST `root`, fills in `outMetadata`, to be used when outputting WGSL.
32 // If the AST is manipulated after calling this, it may be out of sync with the data recorded in
33 // `outMetadata`.
34 bool RecordUniformBlockMetadata(TIntermBlock *root, UniformBlockMetadata &outMetadata);
35 
36 // TODO(anglebug.com/42267100): for now does not output all uniform blocks,
37 // just the default block. (fails for  matCx2, bool, and arrays with stride less than 16.)
38 bool OutputUniformBlocks(TCompiler *compiler, TIntermBlock *root);
39 
40 }  // namespace sh
41 
42 #endif  // COMPILER_TRANSLATOR_WGSL_OUTPUT_UNIFORM_BLOCKS_H_
43