xref: /aosp_15_r20/external/angle/src/compiler/translator/msl/DriverUniformMetal.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2020 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 // DriverUniformMetal:
7 //   Struct defining the default driver uniforms for direct and SpirV based ANGLE translation
8 //
9 
10 #include "compiler/translator/msl/DriverUniformMetal.h"
11 #include "compiler/translator/tree_util/BuiltIn.h"
12 #include "compiler/translator/tree_util/DriverUniform.h"
13 #include "compiler/translator/tree_util/IntermNode_util.h"
14 
15 namespace sh
16 {
17 
18 namespace
19 {
20 
21 // Metal specific driver uniforms
22 constexpr const char kXfbBufferOffsets[]       = "xfbBufferOffsets";
23 constexpr const char kXfbVerticesPerInstance[] = "xfbVerticesPerInstance";
24 constexpr const char kCoverageMask[]           = "coverageMask";
25 constexpr const char kUnused[]                 = "unused";
26 
27 }  // namespace
28 
29 // class DriverUniformMetal
30 // The fields here must match the DriverUniforms structure defined in ContextMtl.h.
createUniformFields(TSymbolTable * symbolTable)31 TFieldList *DriverUniformMetal::createUniformFields(TSymbolTable *symbolTable)
32 {
33     TFieldList *driverFieldList = DriverUniform::createUniformFields(symbolTable);
34 
35     constexpr size_t kNumGraphicsDriverUniformsMetal = 4;
36     constexpr std::array<const char *, kNumGraphicsDriverUniformsMetal>
37         kGraphicsDriverUniformNamesMetal = {
38             {kXfbBufferOffsets, kXfbVerticesPerInstance, kCoverageMask, kUnused}};
39 
40     const std::array<TType *, kNumGraphicsDriverUniformsMetal> kDriverUniformTypesMetal = {{
41         // xfbBufferOffsets: uvec4
42         new TType(EbtInt, EbpHigh, EvqGlobal, 4),
43         // xfbVerticesPerInstance: uint
44         new TType(EbtInt, EbpHigh, EvqGlobal),
45         // coverageMask: uint
46         new TType(EbtUInt, EbpHigh, EvqGlobal),
47         // unused: uvec2
48         new TType(EbtUInt, EbpHigh, EvqGlobal, 2),
49     }};
50 
51     for (size_t uniformIndex = 0; uniformIndex < kNumGraphicsDriverUniformsMetal; ++uniformIndex)
52     {
53         TField *driverUniformField =
54             new TField(kDriverUniformTypesMetal[uniformIndex],
55                        ImmutableString(kGraphicsDriverUniformNamesMetal[uniformIndex]),
56                        TSourceLoc(), SymbolType::AngleInternal);
57         driverFieldList->push_back(driverUniformField);
58     }
59 
60     return driverFieldList;
61 }
62 
getCoverageMaskField() const63 TIntermTyped *DriverUniformMetal::getCoverageMaskField() const
64 {
65     return createDriverUniformRef(kCoverageMask);
66 }
67 
68 }  // namespace sh
69