• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 #ifndef COMPILER_TRANSLATOR_MSL_PIPELINE_H_
8 #define COMPILER_TRANSLATOR_MSL_PIPELINE_H_
9 
10 #include "compiler/translator/Symbol.h"
11 #include "compiler/translator/msl/ModifyStruct.h"
12 #include "compiler/translator/msl/Name.h"
13 #include "compiler/translator/msl/SymbolEnv.h"
14 
15 namespace sh
16 {
17 
18 // Data that is scoped as `external` and `internal` for a given pipeline.
19 template <typename T>
20 struct PipelineScoped
21 {
22     // Data that is configured to talk externally to the program.
23     // May coincide with `internal`, but may also diverge from `internal`.
24     const T *external = nullptr;
25 
26     // Extra data that is configured to talk externally to the program.
27     // Used only for adjusting Metal's InstanceId.
28     const T *externalExtra = nullptr;
29 
30     // Data that is configured to talk internally within the program.
31     // May coincide with `external`, but may also diverge from `external`.
32     const T *internal = nullptr;
33 
34     // Returns true iff the input coincides with either `external` or `internal` data.
matchesPipelineScoped35     bool matches(const T &object) const { return external == &object || internal == &object; }
36 
37     // Both `external` and `internal` representations are non-null.
isTotallyFullPipelineScoped38     bool isTotallyFull() const { return external && internal; }
39 
40     // Both `external` and `internal` representations are null.
isTotallyEmptyPipelineScoped41     bool isTotallyEmpty() const { return !external && !internal; }
42 
43     // Both `external` and `internal` representations are the same.
isUniformPipelineScoped44     bool isUniform() const { return external == internal; }
45 };
46 
47 // Represents a high-level program pipeline.
48 class Pipeline
49 {
50   public:
51     enum class Type
52     {
53         VertexIn,
54         VertexOut,
55         FragmentIn,
56         FragmentOut,
57         UserUniforms,
58         AngleUniforms,
59         NonConstantGlobals,
60         InvocationVertexGlobals,
61         InvocationFragmentGlobals,
62         UniformBuffer,
63         Texture,
64         Image,
65         InstanceId,
66     };
67 
68     enum class Variant
69     {
70         // For all internal pipeline uses.
71         // For external pipeline uses if pipeline does not require splitting or saturation.
72         Original,
73 
74         // Only for external pipeline uses if the pipeline was split or saturated.
75         Modified,
76     };
77 
78   public:
79     // The type of the pipeline.
80     Type type;
81 
82     // Non-null if a global instance of the pipeline struct already exists.
83     // If non-null struct splitting should not be needed.
84     const TVariable *globalInstanceVar;
85 
86   public:
87     // Returns true iff the variable belongs to the pipeline.
88     bool uses(const TVariable &var) const;
89 
90     // Returns the name for the struct type that stores variables of this pipeline.
91     Name getStructTypeName(Variant variant) const;
92 
93     // Returns the name for the struct instance that stores variables of this pipeline.
94     Name getStructInstanceName(Variant variant) const;
95 
96     ModifyStructConfig externalStructModifyConfig() const;
97 
98     // Returns true if the pipeline always requires a non-parameter local instance declaration of
99     // the pipeline structures.
100     bool alwaysRequiresLocalVariableDeclarationInMain() const;
101 
102     // Returns true iff the pipeline is an output pipeline. The external pipeline structure should
103     // be returned from `main`.
104     bool isPipelineOut() const;
105 
106     AddressSpace externalAddressSpace() const;
107 };
108 
109 // A collection of various pipeline structures.
110 struct PipelineStructs : angle::NonCopyable
111 {
112     PipelineScoped<TStructure> fragmentIn;
113     PipelineScoped<TStructure> fragmentOut;
114     PipelineScoped<TStructure> vertexIn;
115     PipelineScoped<TStructure> vertexOut;
116     PipelineScoped<TStructure> userUniforms;
117     PipelineScoped<TStructure> angleUniforms;
118     PipelineScoped<TStructure> nonConstantGlobals;
119     PipelineScoped<TStructure> invocationVertexGlobals;
120     PipelineScoped<TStructure> invocationFragmentGlobals;
121     PipelineScoped<TStructure> uniformBuffers;
122     PipelineScoped<TStructure> texture;
123     PipelineScoped<TStructure> image;
124     PipelineScoped<TStructure> instanceId;
125 
126     bool matches(const TStructure &s, bool internal, bool external) const;
127 };
128 
129 }  // namespace sh
130 
131 #endif  // COMPILER_TRANSLATOR_MSL_PIPELINE_H_
132