• 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_TRANSLATORMETALDIRECT_PIPELINE_H_
8 #define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_PIPELINE_H_
9 
10 #include "compiler/translator/Symbol.h"
11 #include "compiler/translator/TranslatorMetalDirect/ModifyStruct.h"
12 #include "compiler/translator/TranslatorMetalDirect/Name.h"
13 #include "compiler/translator/TranslatorMetalDirect/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         InstanceId,
65     };
66 
67     enum class Variant
68     {
69         // For all internal pipeline uses.
70         // For external pipeline uses if pipeline does not require splitting or saturation.
71         Original,
72 
73         // Only for external pipeline uses if the pipeline was split or saturated.
74         Modified,
75     };
76 
77   public:
78     // The type of the pipeline.
79     Type type;
80 
81     // Non-null if a global instance of the pipeline struct already exists.
82     // If non-null struct splitting should not be needed.
83     const TVariable *globalInstanceVar;
84 
85   public:
86     // Returns true iff the variable belongs to the pipeline.
87     bool uses(const TVariable &var) const;
88 
89     // Returns the name for the struct type that stores variables of this pipeline.
90     Name getStructTypeName(Variant variant) const;
91 
92     // Returns the name for the struct instance that stores variables of this pipeline.
93     Name getStructInstanceName(Variant variant) const;
94 
95     ModifyStructConfig externalStructModifyConfig() const;
96 
97     // Returns true if the pipeline always requires a non-parameter local instance declaration of
98     // the pipeline structures.
99     bool alwaysRequiresLocalVariableDeclarationInMain() const;
100 
101     // Returns true iff the pipeline is an output pipeline. The external pipeline structure should
102     // be returned from `main`.
103     bool isPipelineOut() const;
104 
105     AddressSpace externalAddressSpace() const;
106 };
107 
108 // A collection of various pipeline structures.
109 struct PipelineStructs : angle::NonCopyable
110 {
111     PipelineScoped<TStructure> fragmentIn;
112     PipelineScoped<TStructure> fragmentOut;
113     PipelineScoped<TStructure> vertexIn;
114     PipelineScoped<TStructure> vertexOut;
115     PipelineScoped<TStructure> userUniforms;
116     PipelineScoped<TStructure> angleUniforms;
117     PipelineScoped<TStructure> nonConstantGlobals;
118     PipelineScoped<TStructure> invocationVertexGlobals;
119     PipelineScoped<TStructure> invocationFragmentGlobals;
120     PipelineScoped<TStructure> uniformBuffers;
121     PipelineScoped<TStructure> texture;
122     PipelineScoped<TStructure> instanceId;
123 
124     bool matches(const TStructure &s, bool internal, bool external) const;
125 };
126 
127 }  // namespace sh
128 
129 #endif  // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_PIPELINE_H_
130