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/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 kHalfRenderArea[] = "halfRenderArea";
23 constexpr const char kFlipXY[] = "flipXY";
24 constexpr const char kNegFlipXY[] = "negFlipXY";
25 constexpr const char kEmulatedInstanceID[] = "emulatedInstanceID";
26 constexpr const char kCoverageMask[] = "coverageMask";
27
28 } // namespace
29
30 // class DriverUniformMetal
31 // The fields here must match the DriverUniforms structure defined in ContextMtl.h.
createUniformFields(TSymbolTable * symbolTable)32 TFieldList *DriverUniformMetal::createUniformFields(TSymbolTable *symbolTable)
33 {
34 TFieldList *driverFieldList = DriverUniform::createUniformFields(symbolTable);
35
36 constexpr size_t kNumGraphicsDriverUniformsMetal = 5;
37 constexpr std::array<const char *, kNumGraphicsDriverUniformsMetal>
38 kGraphicsDriverUniformNamesMetal = {
39 {kHalfRenderArea, kFlipXY, kNegFlipXY, kEmulatedInstanceID, kCoverageMask}};
40
41 const std::array<TType *, kNumGraphicsDriverUniformsMetal> kDriverUniformTypesMetal = {{
42 new TType(EbtFloat, EbpHigh, EvqGlobal, 2), // halfRenderArea
43 new TType(EbtFloat, EbpLow, EvqGlobal, 2), // flipXY
44 new TType(EbtFloat, EbpLow, EvqGlobal, 2), // negFlipXY
45 new TType(EbtUInt, EbpHigh,
46 EvqGlobal), // kEmulatedInstanceID - unused in SPIR-V Metal compiler
47 new TType(EbtUInt, EbpHigh, EvqGlobal), // kCoverageMask
48 }};
49
50 for (size_t uniformIndex = 0; uniformIndex < kNumGraphicsDriverUniformsMetal; ++uniformIndex)
51 {
52 TField *driverUniformField =
53 new TField(kDriverUniformTypesMetal[uniformIndex],
54 ImmutableString(kGraphicsDriverUniformNamesMetal[uniformIndex]),
55 TSourceLoc(), SymbolType::AngleInternal);
56 driverFieldList->push_back(driverUniformField);
57 }
58
59 return driverFieldList;
60 }
61
getHalfRenderAreaRef() const62 TIntermBinary *DriverUniformMetal::getHalfRenderAreaRef() const
63 {
64 return createDriverUniformRef(kHalfRenderArea);
65 }
66
getFlipXYRef() const67 TIntermBinary *DriverUniformMetal::getFlipXYRef() const
68 {
69 return createDriverUniformRef(kFlipXY);
70 }
71
getNegFlipXYRef() const72 TIntermBinary *DriverUniformMetal::getNegFlipXYRef() const
73 {
74 return createDriverUniformRef(kNegFlipXY);
75 }
76
getNegFlipYRef() const77 TIntermSwizzle *DriverUniformMetal::getNegFlipYRef() const
78 {
79 // Create a swizzle to "negFlipXY.y"
80 TIntermBinary *negFlipXY = createDriverUniformRef(kNegFlipXY);
81 TVector<int> swizzleOffsetY = {1};
82 TIntermSwizzle *negFlipY = new TIntermSwizzle(negFlipXY, swizzleOffsetY);
83 return negFlipY;
84 }
85
getCoverageMaskFieldRef() const86 TIntermBinary *DriverUniformMetal::getCoverageMaskFieldRef() const
87 {
88 return createDriverUniformRef(kCoverageMask);
89 }
90
91 } // namespace sh
92