• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//
2// Copyright (c) 2019 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// TOutputVulkanGLSLForMetal:
7//    This is a special version Vulkan GLSL output that will make some special
8//    considerations for Metal backend limitations.
9//
10
11#include "compiler/translator/OutputVulkanGLSLForMetal.h"
12
13#include "common/apple_platform_utils.h"
14#include "compiler/translator/BaseTypes.h"
15#include "compiler/translator/Symbol.h"
16#include "compiler/translator/util.h"
17
18namespace sh
19{
20
21namespace
22{
23bool gOverrideRemoveInvariant = false;
24
25bool ShoudRemoveInvariant(const TType &type)
26{
27    if (gOverrideRemoveInvariant)
28    {
29        return true;
30    }
31
32    if (type.getQualifier() != EvqPosition)
33    {
34        // Metal only supports invariant for gl_Position
35        return true;
36    }
37
38    if (ANGLE_APPLE_AVAILABLE_XCI(10.14, 13.0, 12))
39    {
40        return false;
41    }
42    else
43    {
44        // Metal 2.1 is not available, so we need to remove "invariant" keyword
45        return true;
46    }
47}
48
49}
50
51// static
52void TOutputVulkanGLSLForMetal::RemoveInvariantForTest(bool remove)
53{
54    gOverrideRemoveInvariant = remove;
55}
56
57TOutputVulkanGLSLForMetal::TOutputVulkanGLSLForMetal(TInfoSinkBase &objSink,
58                                                     ShArrayIndexClampingStrategy clampingStrategy,
59                                                     ShHashFunction64 hashFunction,
60                                                     NameMap &nameMap,
61                                                     TSymbolTable *symbolTable,
62                                                     sh::GLenum shaderType,
63                                                     int shaderVersion,
64                                                     ShShaderOutput output,
65                                                     ShCompileOptions compileOptions)
66    : TOutputVulkanGLSL(objSink,
67                        clampingStrategy,
68                        hashFunction,
69                        nameMap,
70                        symbolTable,
71                        shaderType,
72                        shaderVersion,
73                        output,
74                        false,
75                        true,
76                        compileOptions)
77{}
78
79void TOutputVulkanGLSLForMetal::writeVariableType(const TType &type,
80                                                  const TSymbol *symbol,
81                                                  bool isFunctionArgument)
82{
83    TType overrideType(type);
84
85    // Remove invariant keyword if required.
86    if (type.isInvariant() && ShoudRemoveInvariant(type))
87    {
88        overrideType.setInvariant(false);
89    }
90
91    TOutputVulkanGLSL::writeVariableType(overrideType, symbol, isFunctionArgument);
92}
93
94bool TOutputVulkanGLSLForMetal::visitGlobalQualifierDeclaration(
95    Visit visit,
96    TIntermGlobalQualifierDeclaration *node)
97{
98    TInfoSinkBase &out = objSink();
99    ASSERT(visit == PreVisit);
100    const TIntermSymbol *symbol = node->getSymbol();
101
102    // No support for the |precise| keyword from EXT_gpu_shader5 (or ES3.2).
103    ASSERT(node->isInvariant());
104
105    if (!ShoudRemoveInvariant(symbol->getType()))
106    {
107        out << "invariant ";
108    }
109    out << hashName(&symbol->variable());
110    return false;
111}
112}  // namespace sh
113