• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright(C) 2021 Advanced Micro Devices, Inc.
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
8 // are met:
9 //
10 //    Redistributions of source code must retain the above copyright
11 //    notice, this list of conditions and the following disclaimer.
12 //
13 //    Redistributions in binary form must reproduce the above
14 //    copyright notice, this list of conditions and the following
15 //    disclaimer in the documentation and/or other materials provided
16 //    with the distribution.
17 //
18 //    Neither the name of 3Dlabs Inc. Ltd. nor the names of its
19 //    contributors may be used to endorse or promote products derived
20 //    from this software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 // POSSIBILITY OF SUCH DAMAGE.
34 //
35 
36 #pragma once
37 
38 //
39 // GL_EXT_spirv_intrinsics
40 //
41 #include "Common.h"
42 #include <variant>
43 
44 namespace glslang {
45 
46 class TIntermTyped;
47 class TIntermConstantUnion;
48 class TType;
49 
50 // SPIR-V requirements
51 struct TSpirvRequirement {
52     POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
53 
54     // capability = [..]
55     TSet<TString> extensions;
56     // extension = [..]
57     TSet<int> capabilities;
58 };
59 
60 // SPIR-V execution modes
61 struct TSpirvExecutionMode {
62     POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
63 
64     // spirv_execution_mode
65     TMap<int, TVector<const TIntermConstantUnion*>> modes;
66     // spirv_execution_mode_id
67     TMap<int, TVector<const TIntermTyped*> > modeIds;
68 };
69 
70 // SPIR-V decorations
71 struct TSpirvDecorate {
72     POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
73 
74     // spirv_decorate
75     TMap<int, TVector<const TIntermConstantUnion*> > decorates;
76     // spirv_decorate_id
77     TMap<int, TVector<const TIntermTyped*>> decorateIds;
78     // spirv_decorate_string
79     TMap<int, TVector<const TIntermConstantUnion*> > decorateStrings;
80 };
81 
82 // SPIR-V instruction
83 struct TSpirvInstruction {
84     POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
85 
TSpirvInstructionTSpirvInstruction86     TSpirvInstruction() { set = ""; id = -1; }
87 
88     bool operator==(const TSpirvInstruction& rhs) const { return set == rhs.set && id == rhs.id; }
89     bool operator!=(const TSpirvInstruction& rhs) const { return !operator==(rhs); }
90 
91     // spirv_instruction
92     TString set;
93     int     id;
94 };
95 
96 // SPIR-V type parameter
97 struct TSpirvTypeParameter {
98     POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
99 
TSpirvTypeParameterTSpirvTypeParameter100     TSpirvTypeParameter(const TIntermConstantUnion* arg) { value = arg; }
TSpirvTypeParameterTSpirvTypeParameter101     TSpirvTypeParameter(const TType* arg) { value = arg; }
102 
getAsConstantTSpirvTypeParameter103     const TIntermConstantUnion* getAsConstant() const
104     {
105         if (value.index() == 0)
106             return std::get<const TIntermConstantUnion*>(value);
107         return nullptr;
108     }
getAsTypeTSpirvTypeParameter109     const TType* getAsType() const
110     {
111         if (value.index() == 1)
112             return std::get<const TType*>(value);
113         return nullptr;
114     }
115 
116     bool operator==(const TSpirvTypeParameter& rhs) const;
117     bool operator!=(const TSpirvTypeParameter& rhs) const { return !operator==(rhs); }
118 
119     // Parameter value: constant expression or type specifier
120     std::variant<const TIntermConstantUnion*, const TType*> value;
121 };
122 
123 typedef TVector<TSpirvTypeParameter> TSpirvTypeParameters;
124 
125 // SPIR-V type
126 struct TSpirvType {
127     POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
128 
129     bool operator==(const TSpirvType& rhs) const
130     {
131         return spirvInst == rhs.spirvInst && typeParams == rhs.typeParams;
132     }
133     bool operator!=(const TSpirvType& rhs) const { return !operator==(rhs); }
134 
135     // spirv_type
136     TSpirvInstruction spirvInst;
137     TSpirvTypeParameters typeParams;
138 };
139 
140 } // end namespace glslang
141