├── README.md
├── .gitmodules
├── Spv.Generator
├── OperandType.cs
├── Spv.Generator.csproj
├── Operand.cs
├── LiteralString.cs
├── LiteralInteger.cs
├── Instruction.cs
├── Module.cs
└── Autogenerated
│ ├── GlslStd450Grammar.cs
│ └── OpenClGrammar.cs
├── Spv.Generator.Testing
├── Spv.Generator.Testing.csproj
└── Program.cs
├── generate_instructions
├── LICENSE
├── SpvGen.sln
├── .gitignore
└── tools
└── codegen.py
/README.md:
--------------------------------------------------------------------------------
1 | # Spv.Generator
2 |
3 | A runtime SPIR-V assembler in C#
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "SPIRV-Headers"]
2 | path = SPIRV-Headers
3 | url = https://github.com/KhronosGroup/SPIRV-Headers.git
4 |
--------------------------------------------------------------------------------
/Spv.Generator/OperandType.cs:
--------------------------------------------------------------------------------
1 | namespace Spv.Generator
2 | {
3 | public enum OperandType
4 | {
5 | Invalid,
6 | Number,
7 | String,
8 | Instruction,
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Spv.Generator.Testing/Spv.Generator.Testing.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net5.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Spv.Generator/Spv.Generator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Spv.Generator/Operand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace Spv.Generator
5 | {
6 | public interface Operand : IEquatable
7 | {
8 | OperandType Type { get; }
9 |
10 | ushort WordCount { get; }
11 |
12 | void WriteOperand(Stream stream);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/generate_instructions:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | python3 tools/codegen.py SPIRV-Headers/include/spirv/unified1/spirv.core.grammar.json SpvGen/Autogenerated/CoreGrammar.cs
4 | python3 tools/codegen.py SPIRV-Headers/include/spirv/unified1/extinst.glsl.std.450.grammar.json SpvGen/Autogenerated/GlslStd450Grammar.cs
5 | python3 tools/codegen.py SPIRV-Headers/include/spirv/unified1/extinst.opencl.std.100.grammar.json SpvGen/Autogenerated/OpenClGrammar.cs
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Permission is hereby granted, free of charge, to any
2 | person obtaining a copy of this software and associated
3 | documentation files (the "Software"), to deal in the
4 | Software without restriction, including without
5 | limitation the rights to use, copy, modify, merge,
6 | publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software
8 | is furnished to do so, subject to the following
9 | conditions:
10 |
11 | The above copyright notice and this permission notice
12 | shall be included in all copies or substantial portions
13 | of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 | DEALINGS IN THE SOFTWARE.
24 |
--------------------------------------------------------------------------------
/Spv.Generator/LiteralString.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Text;
4 |
5 | namespace Spv.Generator
6 | {
7 | public class LiteralString : Operand, IEquatable
8 | {
9 | public OperandType Type => OperandType.String;
10 |
11 | private string _value;
12 |
13 | public LiteralString(string value)
14 | {
15 | _value = value;
16 | }
17 |
18 | public ushort WordCount => (ushort)(_value.Length / 4 + 1);
19 |
20 | public void WriteOperand(Stream stream)
21 | {
22 | byte[] rawValue = Encoding.ASCII.GetBytes(_value);
23 |
24 | stream.Write(rawValue);
25 |
26 | int paddingSize = 4 - (rawValue.Length % 4);
27 |
28 | stream.Write(new byte[paddingSize]);
29 | }
30 |
31 | public override bool Equals(object obj)
32 | {
33 | return obj is LiteralString literalString && Equals(literalString);
34 | }
35 |
36 | public bool Equals(LiteralString cmpObj)
37 | {
38 | return Type == cmpObj.Type && _value.Equals(cmpObj._value);
39 | }
40 |
41 | public override int GetHashCode()
42 | {
43 | return HashCode.Combine(Type, _value);
44 | }
45 |
46 | public bool Equals(Operand obj)
47 | {
48 | return obj is LiteralString literalString && Equals(literalString);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Spv.Generator.Testing/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using static Spv.Specification;
4 |
5 | namespace Spv.Generator.Testing
6 | {
7 | class Program
8 | {
9 | private class TestModule : Module
10 | {
11 | public TestModule() : base(Specification.Version) { }
12 |
13 | public void Construct()
14 | {
15 | AddCapability(Capability.Shader);
16 | SetMemoryModel(AddressingModel.Logical, MemoryModel.Simple);
17 |
18 | Instruction floatType = TypeFloat(32);
19 | Instruction floatInputType = TypePointer(StorageClass.Input, floatType);
20 | Instruction floatOutputType = TypePointer(StorageClass.Output, floatType);
21 | Instruction vec4Type = TypeVector(floatType, 4);
22 | Instruction vec4OutputPtrType = TypePointer(StorageClass.Output, vec4Type);
23 |
24 | Instruction inputTest = Variable(floatInputType, StorageClass.Input);
25 | Instruction outputTest = Variable(floatOutputType, StorageClass.Output);
26 | Instruction outputColor = Variable(vec4OutputPtrType, StorageClass.Output);
27 |
28 | Name(inputTest, "inputTest");
29 | Name(outputColor, "outputColor");
30 | AddGlobalVariable(inputTest);
31 | AddGlobalVariable(outputTest);
32 | AddGlobalVariable(outputColor);
33 |
34 | Instruction rColor = Constant(floatType, 0.5f);
35 | Instruction gColor = Constant(floatType, 0.0f);
36 | Instruction bColor = Constant(floatType, 0.0f);
37 | Instruction aColor = Constant(floatType, 1.0f);
38 |
39 | Instruction compositeColor = ConstantComposite(vec4Type, rColor, gColor, bColor, aColor);
40 |
41 | Instruction voidType = TypeVoid();
42 |
43 | Instruction mainFunctionType = TypeFunction(voidType, true);
44 | Instruction mainFunction = Function(voidType, FunctionControlMask.MaskNone, mainFunctionType);
45 | AddLabel(Label());
46 |
47 | Instruction tempInput = Load(floatType, inputTest);
48 |
49 | Instruction resultSqrt = GlslSqrt(floatType, tempInput);
50 |
51 | Store(outputTest, resultSqrt);
52 | Store(outputColor, compositeColor);
53 |
54 | Return();
55 | FunctionEnd();
56 |
57 | AddEntryPoint(ExecutionModel.Fragment, mainFunction, "main", inputTest, outputTest, outputColor);
58 | AddExecutionMode(mainFunction, ExecutionMode.OriginLowerLeft);
59 | }
60 | }
61 |
62 | static void Main(string[] Args)
63 | {
64 | TestModule module = new TestModule();
65 | module.Construct();
66 |
67 | byte[] ModuleData = module.Generate();
68 |
69 | File.WriteAllBytes(Args[0], ModuleData);
70 |
71 | Console.WriteLine(Args[0]);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/SpvGen.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.31129.286
5 | MinimumVisualStudioVersion = 15.0.26124.0
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spv.Generator", "Spv.Generator\Spv.Generator.csproj", "{5C528C34-D206-400B-9329-64C9D8109E4A}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spv.Generator.Testing", "Spv.Generator.Testing\Spv.Generator.Testing.csproj", "{C21248F1-05EA-4F86-B5C5-78AD8371D887}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Debug|x64 = Debug|x64
14 | Debug|x86 = Debug|x86
15 | Release|Any CPU = Release|Any CPU
16 | Release|x64 = Release|x64
17 | Release|x86 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {5C528C34-D206-400B-9329-64C9D8109E4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {5C528C34-D206-400B-9329-64C9D8109E4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {5C528C34-D206-400B-9329-64C9D8109E4A}.Debug|x64.ActiveCfg = Debug|Any CPU
23 | {5C528C34-D206-400B-9329-64C9D8109E4A}.Debug|x64.Build.0 = Debug|Any CPU
24 | {5C528C34-D206-400B-9329-64C9D8109E4A}.Debug|x86.ActiveCfg = Debug|Any CPU
25 | {5C528C34-D206-400B-9329-64C9D8109E4A}.Debug|x86.Build.0 = Debug|Any CPU
26 | {5C528C34-D206-400B-9329-64C9D8109E4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {5C528C34-D206-400B-9329-64C9D8109E4A}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {5C528C34-D206-400B-9329-64C9D8109E4A}.Release|x64.ActiveCfg = Release|Any CPU
29 | {5C528C34-D206-400B-9329-64C9D8109E4A}.Release|x64.Build.0 = Release|Any CPU
30 | {5C528C34-D206-400B-9329-64C9D8109E4A}.Release|x86.ActiveCfg = Release|Any CPU
31 | {5C528C34-D206-400B-9329-64C9D8109E4A}.Release|x86.Build.0 = Release|Any CPU
32 | {C21248F1-05EA-4F86-B5C5-78AD8371D887}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {C21248F1-05EA-4F86-B5C5-78AD8371D887}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {C21248F1-05EA-4F86-B5C5-78AD8371D887}.Debug|x64.ActiveCfg = Debug|Any CPU
35 | {C21248F1-05EA-4F86-B5C5-78AD8371D887}.Debug|x64.Build.0 = Debug|Any CPU
36 | {C21248F1-05EA-4F86-B5C5-78AD8371D887}.Debug|x86.ActiveCfg = Debug|Any CPU
37 | {C21248F1-05EA-4F86-B5C5-78AD8371D887}.Debug|x86.Build.0 = Debug|Any CPU
38 | {C21248F1-05EA-4F86-B5C5-78AD8371D887}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {C21248F1-05EA-4F86-B5C5-78AD8371D887}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {C21248F1-05EA-4F86-B5C5-78AD8371D887}.Release|x64.ActiveCfg = Release|Any CPU
41 | {C21248F1-05EA-4F86-B5C5-78AD8371D887}.Release|x64.Build.0 = Release|Any CPU
42 | {C21248F1-05EA-4F86-B5C5-78AD8371D887}.Release|x86.ActiveCfg = Release|Any CPU
43 | {C21248F1-05EA-4F86-B5C5-78AD8371D887}.Release|x86.Build.0 = Release|Any CPU
44 | EndGlobalSection
45 | GlobalSection(SolutionProperties) = preSolution
46 | HideSolutionNode = FALSE
47 | EndGlobalSection
48 | GlobalSection(ExtensibilityGlobals) = postSolution
49 | SolutionGuid = {A124425D-B928-412E-925B-7EDCC390166A}
50 | EndGlobalSection
51 | EndGlobal
52 |
--------------------------------------------------------------------------------
/Spv.Generator/LiteralInteger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 | using System.Runtime.InteropServices;
5 |
6 | namespace Spv.Generator
7 | {
8 | public class LiteralInteger : Operand, IEquatable
9 | {
10 | public OperandType Type => OperandType.Number;
11 |
12 | private enum IntegerType
13 | {
14 | UInt32,
15 | Int32,
16 | UInt64,
17 | Int64,
18 | Float32,
19 | Float64,
20 | }
21 |
22 | private IntegerType _integerType;
23 |
24 | private byte[] _data;
25 |
26 | private LiteralInteger(byte[] data, IntegerType integerType)
27 | {
28 | _data = data;
29 | _integerType = integerType;
30 | }
31 |
32 | public static implicit operator LiteralInteger(int value) => Create(value, IntegerType.Int32);
33 | public static implicit operator LiteralInteger(uint value) => Create(value, IntegerType.UInt32);
34 | public static implicit operator LiteralInteger(long value) => Create(value, IntegerType.Int64);
35 | public static implicit operator LiteralInteger(ulong value) => Create(value, IntegerType.UInt64);
36 | public static implicit operator LiteralInteger(float value) => Create(value, IntegerType.Float32);
37 | public static implicit operator LiteralInteger(double value) => Create(value, IntegerType.Float64);
38 | public static implicit operator LiteralInteger(Enum value) => Create((int)Convert.ChangeType(value, typeof(int)), IntegerType.Int32);
39 |
40 | // NOTE: this is not in the standard, but this is some syntax sugar useful in some instructions (TypeInt ect)
41 | public static implicit operator LiteralInteger(bool value) => Create(Convert.ToInt32(value), IntegerType.Int32);
42 |
43 |
44 | public static LiteralInteger CreateForEnum(T value) where T : struct
45 | {
46 | return Create(value, IntegerType.Int32);
47 | }
48 |
49 | private static LiteralInteger Create(T value, IntegerType integerType) where T: struct
50 | {
51 | return new LiteralInteger(MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref value, 1)).ToArray(), integerType);
52 | }
53 |
54 | public ushort WordCount => (ushort)(_data.Length / 4);
55 |
56 | public void WriteOperand(Stream stream)
57 | {
58 | stream.Write(_data);
59 | }
60 |
61 | public override bool Equals(object obj)
62 | {
63 | return obj is LiteralInteger literalInteger && Equals(literalInteger);
64 | }
65 |
66 | public bool Equals(LiteralInteger cmpObj)
67 | {
68 | return Type == cmpObj.Type && _integerType == cmpObj._integerType && _data.SequenceEqual(cmpObj._data);
69 | }
70 |
71 | public override int GetHashCode()
72 | {
73 | return HashCode.Combine(Type, _data);
74 | }
75 |
76 | public bool Equals(Operand obj)
77 | {
78 | return obj is LiteralInteger literalInteger && Equals(literalInteger);
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/Spv.Generator/Instruction.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.IO;
5 | using System.Linq;
6 |
7 | namespace Spv.Generator
8 | {
9 | public sealed class Instruction : Operand, IEquatable
10 | {
11 | public const uint InvalidId = uint.MaxValue;
12 |
13 | public Specification.Op Opcode { get; private set; }
14 | private Instruction _resultType;
15 | public List _operands;
16 |
17 | public uint Id { get; set; }
18 |
19 | public Instruction(Specification.Op opcode, uint id = InvalidId, Instruction resultType = null)
20 | {
21 | Opcode = opcode;
22 | Id = id;
23 | _resultType = resultType;
24 |
25 | _operands = new List();
26 | }
27 |
28 | public void SetId(uint id)
29 | {
30 | Id = id;
31 | }
32 |
33 | public OperandType Type => OperandType.Instruction;
34 |
35 | public ushort GetTotalWordCount()
36 | {
37 | ushort result = WordCount;
38 |
39 | if (Id != InvalidId)
40 | {
41 | result++;
42 | }
43 |
44 | if (_resultType != null)
45 | {
46 | result += _resultType.WordCount;
47 | }
48 |
49 | foreach (Operand operand in _operands)
50 | {
51 | result += operand.WordCount;
52 | }
53 |
54 | return result;
55 | }
56 |
57 | public ushort WordCount => 1;
58 |
59 | private void AddOperand(Operand value)
60 | {
61 | Debug.Assert(value != null);
62 | _operands.Add(value);
63 | }
64 |
65 | public void AddOperand(Operand[] value)
66 | {
67 | foreach (Operand instruction in value)
68 | {
69 | AddOperand(instruction);
70 | }
71 | }
72 |
73 | public void AddOperand(LiteralInteger[] value)
74 | {
75 | foreach (LiteralInteger instruction in value)
76 | {
77 | AddOperand(instruction);
78 | }
79 | }
80 |
81 | public void AddOperand(LiteralInteger value)
82 | {
83 | AddOperand((Operand)value);
84 | }
85 |
86 | public void AddOperand(Instruction[] value)
87 | {
88 | foreach (Instruction instruction in value)
89 | {
90 | AddOperand(instruction);
91 | }
92 | }
93 |
94 | public void AddOperand(Instruction value)
95 | {
96 | AddOperand((Operand)value);
97 | }
98 |
99 | public void AddOperand(string value)
100 | {
101 | AddOperand(new LiteralString(value));
102 | }
103 |
104 | public void AddOperand(T value) where T: struct
105 | {
106 | if (!typeof(T).IsPrimitive && !typeof(T).IsEnum)
107 | {
108 | throw new InvalidOperationException();
109 | }
110 |
111 | AddOperand(LiteralInteger.CreateForEnum(value));
112 | }
113 |
114 | public void Write(Stream stream)
115 | {
116 | BinaryWriter writer = new BinaryWriter(stream);
117 |
118 | // Word 0
119 | writer.Write((ushort)Opcode);
120 | writer.Write(GetTotalWordCount());
121 |
122 | _resultType?.WriteOperand(stream);
123 |
124 | if (Id != InvalidId)
125 | {
126 | writer.Write(Id);
127 | }
128 |
129 | foreach (Operand operand in _operands)
130 | {
131 | operand.WriteOperand(stream);
132 | }
133 | }
134 |
135 | public void WriteOperand(Stream stream)
136 | {
137 | Debug.Assert(Id != InvalidId);
138 |
139 | if (Id == InvalidId)
140 | {
141 | string methodToCall;
142 |
143 | if (Opcode == Specification.Op.OpVariable)
144 | {
145 | methodToCall = "AddLocalVariable or AddGlobalVariable";
146 | }
147 | else if (Opcode == Specification.Op.OpLabel)
148 | {
149 | methodToCall = "AddLabel";
150 | }
151 | else
152 | {
153 | throw new InvalidOperationException("Internal error");
154 | }
155 |
156 | throw new InvalidOperationException($"Id wasn't bound to the module, please make sure to call {methodToCall}");
157 | }
158 |
159 | stream.Write(BitConverter.GetBytes(Id));
160 | }
161 |
162 | public override bool Equals(object obj)
163 | {
164 | return obj is Instruction instruction && Equals(instruction);
165 | }
166 |
167 | public bool Equals(Instruction cmpObj)
168 | {
169 | bool result = Type == cmpObj.Type && Id == cmpObj.Id;
170 |
171 | if (result)
172 | {
173 | if (_resultType != null && cmpObj._resultType != null)
174 | {
175 | result &= _resultType.Equals(cmpObj._resultType);
176 | }
177 | else if (_resultType != null || cmpObj._resultType != null)
178 | {
179 | return false;
180 | }
181 | }
182 |
183 | if (result)
184 | {
185 | result &= EqualsContent(cmpObj);
186 | }
187 |
188 | return result;
189 | }
190 |
191 | public bool EqualsContent(Instruction cmpObj)
192 | {
193 | return _operands.SequenceEqual(cmpObj._operands);
194 | }
195 |
196 | public bool EqualsResultType(Instruction cmpObj)
197 | {
198 | return _resultType.Opcode == cmpObj._resultType.Opcode && _resultType.EqualsContent(cmpObj._resultType);
199 | }
200 |
201 | public override int GetHashCode()
202 | {
203 | return HashCode.Combine(Opcode, Id, _resultType, _operands);
204 | }
205 |
206 | public bool Equals(Operand obj)
207 | {
208 | return obj is Instruction instruction && Equals(instruction);
209 | }
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### DotnetCore ###
2 | # .NET Core build folders
3 | /bin
4 | /obj
5 |
6 | # Common node modules locations
7 | /node_modules
8 | /wwwroot/node_modules
9 |
10 |
11 | ### VisualStudioCode ###
12 | .vscode/*
13 | !.vscode/settings.json
14 | !.vscode/tasks.json
15 | !.vscode/launch.json
16 | !.vscode/extensions.json
17 |
18 | ### VisualStudioCode Patch ###
19 | # Ignore all local history of files
20 | .history
21 |
22 | ### VisualStudio ###
23 | ## Ignore Visual Studio temporary files, build results, and
24 | ## files generated by popular Visual Studio add-ons.
25 | ##
26 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
27 |
28 | # User-specific files
29 | *.rsuser
30 | *.suo
31 | *.user
32 | *.userosscache
33 | *.sln.docstates
34 |
35 | # User-specific files (MonoDevelop/Xamarin Studio)
36 | *.userprefs
37 |
38 | # Mono auto generated files
39 | mono_crash.*
40 |
41 | # Build results
42 | [Dd]ebug/
43 | [Dd]ebugPublic/
44 | [Rr]elease/
45 | [Rr]eleases/
46 | x64/
47 | x86/
48 | [Aa][Rr][Mm]/
49 | [Aa][Rr][Mm]64/
50 | bld/
51 | [Bb]in/
52 | [Oo]bj/
53 | [Ll]og/
54 |
55 | # Visual Studio 2015/2017 cache/options directory
56 | .vs/
57 | # Uncomment if you have tasks that create the project's static files in wwwroot
58 | #wwwroot/
59 |
60 | # Visual Studio 2017 auto generated files
61 | Generated\ Files/
62 |
63 | # MSTest test Results
64 | [Tt]est[Rr]esult*/
65 | [Bb]uild[Ll]og.*
66 |
67 | # NUnit
68 | *.VisualState.xml
69 | TestResult.xml
70 | nunit-*.xml
71 |
72 | # Build Results of an ATL Project
73 | [Dd]ebugPS/
74 | [Rr]eleasePS/
75 | dlldata.c
76 |
77 | # Benchmark Results
78 | BenchmarkDotNet.Artifacts/
79 |
80 | # .NET Core
81 | project.lock.json
82 | project.fragment.lock.json
83 | artifacts/
84 |
85 | # StyleCop
86 | StyleCopReport.xml
87 |
88 | # Files built by Visual Studio
89 | *_i.c
90 | *_p.c
91 | *_h.h
92 | *.ilk
93 | *.obj
94 | *.iobj
95 | *.pch
96 | *.pdb
97 | *.ipdb
98 | *.pgc
99 | *.pgd
100 | *.rsp
101 | *.sbr
102 | *.tlb
103 | *.tli
104 | *.tlh
105 | *.tmp
106 | *.tmp_proj
107 | *_wpftmp.csproj
108 | *.log
109 | *.vspscc
110 | *.vssscc
111 | .builds
112 | *.pidb
113 | *.svclog
114 | *.scc
115 |
116 | # Chutzpah Test files
117 | _Chutzpah*
118 |
119 | # Visual C++ cache files
120 | ipch/
121 | *.aps
122 | *.ncb
123 | *.opendb
124 | *.opensdf
125 | *.sdf
126 | *.cachefile
127 | *.VC.db
128 | *.VC.VC.opendb
129 |
130 | # Visual Studio profiler
131 | *.psess
132 | *.vsp
133 | *.vspx
134 | *.sap
135 |
136 | # Visual Studio Trace Files
137 | *.e2e
138 |
139 | # TFS 2012 Local Workspace
140 | $tf/
141 |
142 | # Guidance Automation Toolkit
143 | *.gpState
144 |
145 | # ReSharper is a .NET coding add-in
146 | _ReSharper*/
147 | *.[Rr]e[Ss]harper
148 | *.DotSettings.user
149 |
150 | # JustCode is a .NET coding add-in
151 | .JustCode
152 |
153 | # TeamCity is a build add-in
154 | _TeamCity*
155 |
156 | # DotCover is a Code Coverage Tool
157 | *.dotCover
158 |
159 | # AxoCover is a Code Coverage Tool
160 | .axoCover/*
161 | !.axoCover/settings.json
162 |
163 | # Visual Studio code coverage results
164 | *.coverage
165 | *.coveragexml
166 |
167 | # NCrunch
168 | _NCrunch_*
169 | .*crunch*.local.xml
170 | nCrunchTemp_*
171 |
172 | # MightyMoose
173 | *.mm.*
174 | AutoTest.Net/
175 |
176 | # Web workbench (sass)
177 | .sass-cache/
178 |
179 | # Installshield output folder
180 | [Ee]xpress/
181 |
182 | # DocProject is a documentation generator add-in
183 | DocProject/buildhelp/
184 | DocProject/Help/*.HxT
185 | DocProject/Help/*.HxC
186 | DocProject/Help/*.hhc
187 | DocProject/Help/*.hhk
188 | DocProject/Help/*.hhp
189 | DocProject/Help/Html2
190 | DocProject/Help/html
191 |
192 | # Click-Once directory
193 | publish/
194 |
195 | # Publish Web Output
196 | *.[Pp]ublish.xml
197 | *.azurePubxml
198 | # Note: Comment the next line if you want to checkin your web deploy settings,
199 | # but database connection strings (with potential passwords) will be unencrypted
200 | *.pubxml
201 | *.publishproj
202 |
203 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
204 | # checkin your Azure Web App publish settings, but sensitive information contained
205 | # in these scripts will be unencrypted
206 | PublishScripts/
207 |
208 | # NuGet Packages
209 | *.nupkg
210 | # NuGet Symbol Packages
211 | *.snupkg
212 | # The packages folder can be ignored because of Package Restore
213 | **/[Pp]ackages/*
214 | # except build/, which is used as an MSBuild target.
215 | !**/[Pp]ackages/build/
216 | # Uncomment if necessary however generally it will be regenerated when needed
217 | #!**/[Pp]ackages/repositories.config
218 | # NuGet v3's project.json files produces more ignorable files
219 | *.nuget.props
220 | *.nuget.targets
221 |
222 | # Microsoft Azure Build Output
223 | csx/
224 | *.build.csdef
225 |
226 | # Microsoft Azure Emulator
227 | ecf/
228 | rcf/
229 |
230 | # Windows Store app package directories and files
231 | AppPackages/
232 | BundleArtifacts/
233 | Package.StoreAssociation.xml
234 | _pkginfo.txt
235 | *.appx
236 | *.appxbundle
237 | *.appxupload
238 |
239 | # Visual Studio cache files
240 | # files ending in .cache can be ignored
241 | *.[Cc]ache
242 | # but keep track of directories ending in .cache
243 | !?*.[Cc]ache/
244 |
245 | # Others
246 | ClientBin/
247 | ~$*
248 | *~
249 | *.dbmdl
250 | *.dbproj.schemaview
251 | *.jfm
252 | *.pfx
253 | *.publishsettings
254 | orleans.codegen.cs
255 |
256 | # Including strong name files can present a security risk
257 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
258 | #*.snk
259 |
260 | # Since there are multiple workflows, uncomment next line to ignore bower_components
261 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
262 | #bower_components/
263 |
264 | # RIA/Silverlight projects
265 | Generated_Code/
266 |
267 | # Backup & report files from converting an old project file
268 | # to a newer Visual Studio version. Backup files are not needed,
269 | # because we have git ;-)
270 | _UpgradeReport_Files/
271 | Backup*/
272 | UpgradeLog*.XML
273 | UpgradeLog*.htm
274 | ServiceFabricBackup/
275 | *.rptproj.bak
276 |
277 | # SQL Server files
278 | *.mdf
279 | *.ldf
280 | *.ndf
281 |
282 | # Business Intelligence projects
283 | *.rdl.data
284 | *.bim.layout
285 | *.bim_*.settings
286 | *.rptproj.rsuser
287 | *- [Bb]ackup.rdl
288 | *- [Bb]ackup ([0-9]).rdl
289 | *- [Bb]ackup ([0-9][0-9]).rdl
290 |
291 | # Microsoft Fakes
292 | FakesAssemblies/
293 |
294 | # GhostDoc plugin setting file
295 | *.GhostDoc.xml
296 |
297 | # Node.js Tools for Visual Studio
298 | .ntvs_analysis.dat
299 | node_modules/
300 |
301 | # Visual Studio 6 build log
302 | *.plg
303 |
304 | # Visual Studio 6 workspace options file
305 | *.opt
306 |
307 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
308 | *.vbw
309 |
310 | # Visual Studio LightSwitch build output
311 | **/*.HTMLClient/GeneratedArtifacts
312 | **/*.DesktopClient/GeneratedArtifacts
313 | **/*.DesktopClient/ModelManifest.xml
314 | **/*.Server/GeneratedArtifacts
315 | **/*.Server/ModelManifest.xml
316 | _Pvt_Extensions
317 |
318 | # Paket dependency manager
319 | .paket/paket.exe
320 | paket-files/
321 |
322 | # FAKE - F# Make
323 | .fake/
324 |
325 | # CodeRush personal settings
326 | .cr/personal
327 |
328 | # Python Tools for Visual Studio (PTVS)
329 | __pycache__/
330 | *.pyc
331 |
332 | # Cake - Uncomment if you are using it
333 | # tools/**
334 | # !tools/packages.config
335 |
336 | # Tabs Studio
337 | *.tss
338 |
339 | # Telerik's JustMock configuration file
340 | *.jmconfig
341 |
342 | # BizTalk build output
343 | *.btp.cs
344 | *.btm.cs
345 | *.odx.cs
346 | *.xsd.cs
347 |
348 | # OpenCover UI analysis results
349 | OpenCover/
350 |
351 | # Azure Stream Analytics local run output
352 | ASALocalRun/
353 |
354 | # MSBuild Binary and Structured Log
355 | *.binlog
356 |
357 | # NVidia Nsight GPU debugger configuration file
358 | *.nvuser
359 |
360 | # MFractors (Xamarin productivity tool) working folder
361 | .mfractor/
362 |
363 | # Local History for Visual Studio
364 | .localhistory/
365 |
366 | # BeatPulse healthcheck temp database
367 | healthchecksdb
368 |
369 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
370 | MigrationBackup/
371 |
372 | *.spv
373 |
374 | */Properties/launchSettings.json
--------------------------------------------------------------------------------
/Spv.Generator/Module.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.IO;
5 | using System.Linq;
6 | using static Spv.Specification;
7 |
8 | namespace Spv.Generator
9 | {
10 | public partial class Module
11 | {
12 | // TODO: register to SPIR-V registry
13 | private const int GeneratorId = 0;
14 |
15 | private readonly uint _version;
16 |
17 | private uint _bound;
18 |
19 | // Follow spec order here why keeping it as dumb as possible.
20 | private List _capabilities;
21 | private List _extensions;
22 | private List _extInstImports;
23 | private AddressingModel _addressingModel;
24 | private MemoryModel _memoryModel;
25 |
26 | private List _entrypoints;
27 | private List _executionModes;
28 | private List _debug;
29 | private List _annotations;
30 |
31 | // In the declaration block.
32 | private List _typeDeclarations;
33 | // In the declaration block.
34 | private List _globals;
35 | // In the declaration block, for function that aren't defined in the module.
36 | private List _functionsDeclarations;
37 |
38 | private List _functionsDefinitions;
39 |
40 | public Module(uint version)
41 | {
42 | _version = version;
43 | _bound = 1;
44 | _capabilities = new List();
45 | _extensions = new List();
46 | _extInstImports = new List();
47 | _addressingModel = AddressingModel.Logical;
48 | _memoryModel = MemoryModel.Simple;
49 | _entrypoints = new List();
50 | _executionModes = new List();
51 | _debug = new List();
52 | _annotations = new List();
53 | _typeDeclarations = new List();
54 | _globals = new List();
55 | _functionsDeclarations = new List();
56 | _functionsDefinitions = new List();
57 | }
58 |
59 | private uint GetNewId()
60 | {
61 | return _bound++;
62 | }
63 |
64 | public void AddCapability(Capability capability)
65 | {
66 | _capabilities.Add(capability);
67 | }
68 |
69 | public void AddExtension(string extension)
70 | {
71 | _extensions.Add(extension);
72 | }
73 |
74 | public Instruction AddExtInstImport(string import)
75 | {
76 | Instruction instruction = new Instruction(Op.OpExtInstImport);
77 | instruction.AddOperand(import);
78 |
79 | foreach (Instruction extInstImport in _extInstImports)
80 | {
81 | if (extInstImport.Opcode == Op.OpExtInstImport && extInstImport.EqualsContent(instruction))
82 | {
83 | // update the duplicate instance to use the good id so it ends up being encoded right.
84 | return extInstImport;
85 | }
86 | }
87 |
88 | instruction.SetId(GetNewId());
89 |
90 | _extInstImports.Add(instruction);
91 |
92 | return instruction;
93 | }
94 |
95 | private void AddTypeDeclaration(Instruction instruction, bool forceIdAllocation)
96 | {
97 | if (!forceIdAllocation)
98 | {
99 | foreach (Instruction typeDeclaration in _typeDeclarations)
100 | {
101 | if (typeDeclaration.Opcode == instruction.Opcode && typeDeclaration.EqualsContent(instruction))
102 | {
103 | // update the duplicate instance to use the good id so it ends up being encoded right.
104 | instruction.SetId(typeDeclaration.Id);
105 |
106 | return;
107 | }
108 | }
109 | }
110 |
111 | instruction.SetId(GetNewId());
112 |
113 | _typeDeclarations.Add(instruction);
114 | }
115 |
116 | public void AddEntryPoint(ExecutionModel executionModel, Instruction function, string name, params Instruction[] interfaces)
117 | {
118 | Debug.Assert(function.Opcode == Op.OpFunction);
119 |
120 | Instruction entryPoint = new Instruction(Op.OpEntryPoint);
121 |
122 | entryPoint.AddOperand(executionModel);
123 | entryPoint.AddOperand(function);
124 | entryPoint.AddOperand(name);
125 | entryPoint.AddOperand(interfaces);
126 |
127 | _entrypoints.Add(entryPoint);
128 | }
129 |
130 | public void AddExecutionMode(Instruction function, ExecutionMode mode, params Operand[] parameters)
131 | {
132 | Debug.Assert(function.Opcode == Op.OpFunction);
133 |
134 | Instruction executionModeInstruction = new Instruction(Op.OpExecutionMode);
135 |
136 | executionModeInstruction.AddOperand(function);
137 | executionModeInstruction.AddOperand(mode);
138 | executionModeInstruction.AddOperand(parameters);
139 |
140 | _executionModes.Add(executionModeInstruction);
141 | }
142 |
143 | private void AddToFunctionDefinitions(Instruction instruction)
144 | {
145 | Debug.Assert(instruction.Opcode != Op.OpTypeInt);
146 | _functionsDefinitions.Add(instruction);
147 | }
148 |
149 | private void AddAnnotation(Instruction annotation)
150 | {
151 | _annotations.Add(annotation);
152 | }
153 |
154 | private void AddDebug(Instruction debug)
155 | {
156 | _debug.Add(debug);
157 | }
158 |
159 | public void AddLabel(Instruction label)
160 | {
161 | Debug.Assert(label.Opcode == Op.OpLabel);
162 |
163 | label.SetId(GetNewId());
164 |
165 | AddToFunctionDefinitions(label);
166 | }
167 |
168 |
169 | public void AddLocalVariable(Instruction variable)
170 | {
171 | // TODO: ensure it has the local modifier
172 | Debug.Assert(variable.Opcode == Op.OpVariable);
173 |
174 | variable.SetId(GetNewId());
175 |
176 | AddToFunctionDefinitions(variable);
177 | }
178 |
179 | public void AddGlobalVariable(Instruction variable)
180 | {
181 | // TODO: ensure it has the global modifier
182 | // TODO: all constants opcodes (OpSpecXXX and the rest of the OpConstantXXX)
183 | Debug.Assert(variable.Opcode == Op.OpVariable);
184 |
185 | variable.SetId(GetNewId());
186 |
187 | _globals.Add(variable);
188 | }
189 |
190 | private void AddConstant(Instruction constant)
191 | {
192 | Debug.Assert(constant.Opcode == Op.OpConstant ||
193 | constant.Opcode == Op.OpConstantFalse ||
194 | constant.Opcode == Op.OpConstantTrue ||
195 | constant.Opcode == Op.OpConstantNull ||
196 | constant.Opcode == Op.OpConstantComposite);
197 |
198 | foreach (Instruction global in _globals)
199 | {
200 | if (global.Opcode == constant.Opcode && global.EqualsContent(constant) && global.EqualsResultType(constant))
201 | {
202 | // update the duplicate instance to use the good id so it ends up being encoded right.
203 | constant.SetId(global.Id);
204 |
205 | return;
206 | }
207 | }
208 |
209 | constant.SetId(GetNewId());
210 |
211 | _globals.Add(constant);
212 | }
213 |
214 | public Instruction ExtInst(Instruction resultType, Instruction set, LiteralInteger instruction, params Operand[] parameters)
215 | {
216 | Instruction result = new Instruction(Op.OpExtInst, GetNewId(), resultType);
217 |
218 | result.AddOperand(set);
219 | result.AddOperand(instruction);
220 | result.AddOperand(parameters);
221 | AddToFunctionDefinitions(result);
222 |
223 | return result;
224 | }
225 |
226 | public void SetMemoryModel(AddressingModel addressingModel, MemoryModel memoryModel)
227 | {
228 | _addressingModel = addressingModel;
229 | _memoryModel = memoryModel;
230 | }
231 |
232 | // TODO: Found a way to make the auto generate one used.
233 | public Instruction OpenClPrintf(Instruction resultType, Instruction format, params Instruction[] additionalarguments)
234 | {
235 | Instruction result = new Instruction(Op.OpExtInst, GetNewId(), resultType);
236 |
237 | result.AddOperand(AddExtInstImport("OpenCL.std"));
238 | result.AddOperand((LiteralInteger)184);
239 | result.AddOperand(format);
240 | result.AddOperand(additionalarguments);
241 | AddToFunctionDefinitions(result);
242 |
243 | return result;
244 | }
245 |
246 | public byte[] Generate()
247 | {
248 | using (MemoryStream stream = new MemoryStream())
249 | {
250 | BinaryWriter writer = new BinaryWriter(stream);
251 |
252 | // Header
253 | writer.Write(MagicNumber);
254 | writer.Write(_version);
255 | writer.Write(GeneratorId);
256 | writer.Write(_bound);
257 | writer.Write(0u);
258 |
259 | // 1.
260 | foreach (Capability capability in _capabilities)
261 | {
262 | Instruction capabilityInstruction = new Instruction(Op.OpCapability);
263 |
264 | capabilityInstruction.AddOperand(capability);
265 | capabilityInstruction.Write(stream);
266 | }
267 |
268 | // 2.
269 | foreach (string extension in _extensions)
270 | {
271 | Instruction extensionInstruction = new Instruction(Op.OpExtension);
272 |
273 | extensionInstruction.AddOperand(extension);
274 | extensionInstruction.Write(stream);
275 | }
276 |
277 | // 3.
278 | foreach (Instruction extInstImport in _extInstImports)
279 | {
280 | extInstImport.Write(stream);
281 | }
282 |
283 | // 4.
284 | Instruction memoryModelInstruction = new Instruction(Op.OpMemoryModel);
285 | memoryModelInstruction.AddOperand(_addressingModel);
286 | memoryModelInstruction.AddOperand(_memoryModel);
287 | memoryModelInstruction.Write(stream);
288 |
289 | // 5.
290 | foreach (Instruction entrypoint in _entrypoints)
291 | {
292 | entrypoint.Write(stream);
293 | }
294 |
295 | // 6.
296 | foreach (Instruction executionMode in _executionModes)
297 | {
298 | executionMode.Write(stream);
299 | }
300 |
301 | // 7.
302 | // TODO: order debug information correclty.
303 | foreach (Instruction debug in _debug)
304 | {
305 | debug.Write(stream);
306 | }
307 |
308 | // 8.
309 | foreach (Instruction annotation in _annotations)
310 | {
311 | annotation.Write(stream);
312 | }
313 |
314 | // Ensure that everything is in the right order in the declarations section
315 | List declarations = new List();
316 | declarations.AddRange(_typeDeclarations);
317 | declarations.AddRange(_globals);
318 | declarations.Sort((Instruction x, Instruction y) => x.Id.CompareTo(y.Id));
319 |
320 | // 9.
321 | foreach (Instruction declaration in declarations)
322 | {
323 | declaration.Write(stream);
324 | }
325 |
326 | // 10.
327 | foreach (Instruction functionDeclaration in _functionsDeclarations)
328 | {
329 | functionDeclaration.Write(stream);
330 | }
331 |
332 | // 11.
333 | foreach (Instruction functionDefinition in _functionsDefinitions)
334 | {
335 | functionDefinition.Write(stream);
336 | }
337 |
338 | return stream.ToArray();
339 | }
340 | }
341 | }
342 | }
343 |
--------------------------------------------------------------------------------
/tools/codegen.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # -*- coding: utf-8 -*-
3 |
4 | import datetime
5 | import json
6 | import sys
7 | import os
8 |
9 | class CodeStream:
10 | def __init__(self):
11 | self.code = ""
12 | self.spaces = 0
13 |
14 | def get(self): return self.code
15 |
16 | def indent(self): self.spaces += 4
17 | def unindent(self): self.spaces -= 4
18 |
19 | def write(self, text):
20 | self.code += text
21 |
22 | def begin_line(self):
23 | self.write(" " * self.spaces)
24 |
25 | def write_line(self, line=""):
26 | self.begin_line()
27 | self.write(line + "\n")
28 |
29 | class MethodArgument:
30 | def __init__(self, name, real_type, c_sharp_type, optional, variable, behind_optional_argument = None):
31 | self.name = name
32 | self.real_type = real_type
33 | self.c_sharp_type = c_sharp_type
34 | self.optional = optional
35 | self.variable = variable
36 | self.behind_optional_argument = behind_optional_argument
37 |
38 | def get_prototype_name(self):
39 | if self.optional:
40 | return '{0} {1} = {2}'.format(self.c_sharp_type, self.name, self.get_default_value())
41 | if self.variable:
42 | return 'params {0}[] {1}'.format(self.c_sharp_type, self.name)
43 | return '{0} {1}'.format(self.c_sharp_type, self.name)
44 |
45 | def get_default_value(self):
46 | default_value = 'null'
47 |
48 | if self.c_sharp_type == 'bool':
49 | default_value = 'false'
50 | # Assume enum if it's not an Instruction,
51 | # We use some invalid value in this case to detect that the user hasn't send anything
52 | # TODO: improve this
53 | elif self.c_sharp_type != 'Instruction' and self.c_sharp_type != 'string':
54 | default_value = '({0})int.MaxValue'.format(self.c_sharp_type)
55 |
56 | return default_value
57 |
58 | def get_as_operand(self):
59 | enum_defined = [
60 | 'FPRoundingMode'
61 | ]
62 |
63 | kind = self.c_sharp_type
64 |
65 | if kind in enum_defined:
66 | return 'LiteralInteger.CreateForEnum({0})'.format(self.name)
67 |
68 | return self.name
69 |
70 | def generate_add_operant_operation(self, stream):
71 | # skip result type as it's send in the constructor
72 | if self.name == 'resultType' or self.name == 'forceIdAllocation':
73 | return
74 |
75 | if self.optional:
76 | optional_check = self
77 | elif self.behind_optional_argument:
78 | optional_check = self.behind_optional_argument
79 | else:
80 | optional_check = None
81 |
82 | if optional_check != None:
83 | stream.write_line("if ({0} != {1})".format(optional_check.name, optional_check.get_default_value()))
84 | stream.write_line("{")
85 | stream.indent()
86 | stream.write_line('result.AddOperand({0});'.format(self.name))
87 | if optional_check != None:
88 | stream.unindent()
89 | stream.write_line("}")
90 |
91 | class MethodInfo:
92 | def fix_possible_argument_conflicts(self, name):
93 | conflict_count = -1
94 |
95 | for argument in self.arguments:
96 | if argument.name == name:
97 | conflict_count += 1
98 |
99 | if conflict_count > 0:
100 | index = 0
101 | for argument in self.arguments:
102 | if argument.name == name:
103 | argument.name = '{0}{1}'.format(argument.name, index)
104 | index += 1
105 |
106 | def __init__(self, instruction, extinst_info):
107 | self.extinst_info = extinst_info
108 | self.bound_increment_needed = False
109 | self.result_type_index = -1
110 | self.opcode = instruction['opcode']
111 | self.arguments = []
112 |
113 | if extinst_info != None:
114 | self.cl = 'ExtInst'
115 | self.name = extinst_info['function_prefix'] + instruction['opname'][:1].upper() + instruction['opname'][1:]
116 | self.arguments.append(MethodArgument("resultType", 'IdRef', 'Instruction', False, False))
117 | else:
118 | self.name = instruction['opname'][2:]
119 | self.cl = instruction['class']
120 | i = 0
121 |
122 | if 'operands' in instruction:
123 | for operand in instruction['operands']:
124 | if operand['kind'] != 'IdResult':
125 | if operand['kind'] == 'IdResultType':
126 | self.result_type_index = i
127 |
128 | variable = 'quantifier' in operand and operand['quantifier'] == '*'
129 | optional = 'quantifier' in operand and operand['quantifier'] == '?'
130 |
131 | # The core grammar doesn't contains the optional when ImageOperands is defined on image instructions, add them manually.
132 | if operand['kind'] == "ImageOperands" and self.cl == "Image":
133 | image_operands = MethodArgument(get_argument_name(operand, i), operand['kind'], get_type_by_operand(operand), False, False)
134 |
135 | if optional:
136 | # TODO: improve this as this generate two if..
137 | image_operands.behind_optional_argument = image_operands
138 |
139 | self.arguments.append(image_operands)
140 | self.arguments.append(MethodArgument("imageOperandIds", 'IdRef', 'Instruction', False, True, image_operands))
141 | else:
142 | self.arguments.append(MethodArgument(get_argument_name(operand, i), operand['kind'], get_type_by_operand(operand), optional, variable))
143 |
144 | # Decoration and ExecutionMode are special as they carry variable operands
145 | if operand['kind'] in ['Decoration', 'ExecutionMode']:
146 | self.arguments.append(MethodArgument('parameters', 'Operands', 'Operand', False, True))
147 |
148 | i += 1
149 | else:
150 | self.bound_increment_needed = True
151 |
152 | if self.cl == 'Type-Declaration':
153 | force_id_allocation_arg = MethodArgument('forceIdAllocation', 'bool', 'bool', not self.name in ['TypeFunction', 'TypeStruct'], False)
154 | if self.name in ['TypeFunction', 'TypeStruct']:
155 | self.arguments.insert(len(self.arguments) - 1, force_id_allocation_arg)
156 | else:
157 | self.arguments.append(force_id_allocation_arg)
158 |
159 | for argument in self.arguments:
160 | self.fix_possible_argument_conflicts(argument.name)
161 |
162 |
163 | def get_instructions_by_class(spec_data, cl):
164 | result = []
165 | for instruction in spec_data['instructions']:
166 | if instruction['class'] == cl:
167 | result.append(instruction)
168 | return result
169 |
170 | def get_instruction_by_name(spec_data, opname):
171 | for instruction in spec_data['instructions']:
172 | if instruction['opname'] == opname:
173 | return instruction
174 | return None
175 |
176 | def get_argument_name(operand, position):
177 | if operand['kind'] == 'IdResultType':
178 | return 'resultType'
179 |
180 | if 'name' in operand and not '\n' in operand['name'] and not '~' in operand['name'] and not ',' in operand['name'] and operand['name'].isascii():
181 | name = operand['name'].replace('\'', '').replace(' ', '').replace('.', '')
182 |
183 | name = name[0].lower() + name[1:]
184 |
185 | # replace reserved words
186 | if name == 'object':
187 | return 'obj'
188 | if name == 'string':
189 | return 'str'
190 | elif name == 'base':
191 | return 'baseObj'
192 | elif name == 'default':
193 | return 'defaultObj'
194 | elif name == 'event':
195 | return 'eventObj'
196 | elif name == 'result':
197 | return 'resultObj'
198 |
199 | return name
200 |
201 | # the name wasn't derived from the description, try to match some common types that are allowed.
202 | namemapping = [
203 | 'Dim',
204 | 'ImageFormat',
205 | 'AccessQualifier',
206 | 'AccessQualifier',
207 | 'StorageClass',
208 | 'SamplerAddressingMode',
209 | 'SamplerFilterMode',
210 | 'FunctionControl',
211 | 'ImageOperands',
212 | 'LoopControl',
213 | 'SelectionControl',
214 | 'MemoryAccess',
215 | 'Decoration',
216 | 'SourceLanguage'
217 | ]
218 |
219 | if operand['kind'] in namemapping:
220 | return operand['kind'][0].lower() + operand['kind'][1:]
221 |
222 | # Dref case
223 | if 'name' in operand and operand['name'] == '\'D~ref~\'':
224 | return 'dRef'
225 |
226 | # this case is a pain to handle, let's just give up in this case
227 | if operand['kind'] in ['IdRef', 'PairIdRefIdRef'] and 'quantifier' in operand and operand['quantifier'] == '*':
228 | return 'parameters'
229 |
230 |
231 | print('// Unmanaged argument name: {0}'.format(operand))
232 |
233 |
234 | return 'arg{0}'.format(position)
235 |
236 | def get_type_by_operand(operand):
237 | enum_masks = ['MemoryAccess', 'ImageOperands', 'LoopControl', 'SelectionControl', 'FunctionControl']
238 |
239 | typemapping = {
240 | 'LiteralString': 'string',
241 | 'IdRef': 'Instruction',
242 | 'IdResultType': 'Instruction',
243 | 'IdScope': 'Instruction',
244 | 'IdMemorySemantics': 'Instruction',
245 | 'PairIdRefIdRef': 'Instruction',
246 | 'LiteralContextDependentNumber': 'LiteralInteger',
247 | 'LiteralSpecConstantOpInteger': 'LiteralInteger',
248 | 'PairLiteralIntegerIdRef': 'Operand',
249 | 'PairIdRefLiteralInteger': 'Operand',
250 | 'LiteralExtInstInteger': 'LiteralInteger',
251 | }
252 |
253 | kind = operand['kind']
254 |
255 | result = kind
256 |
257 | if kind in typemapping:
258 | result = typemapping[kind]
259 | if kind in enum_masks:
260 | result = kind + 'Mask'
261 |
262 | #if 'quantifier' in operand and operand['quantifier'] == '*':
263 | # result = 'params {0}[]'.format(result)
264 |
265 |
266 | return result
267 |
268 | def generate_method_for_instruction(stream, instruction, extinst_info):
269 | method_info = MethodInfo(instruction, extinst_info)
270 |
271 | # Ignore OpenCL printf as it cannot generate for now.
272 | if method_info.name == 'OpenClPrintf':
273 | return
274 |
275 | stream.indent()
276 | generate_method_prototye(stream, method_info)
277 | generate_method_definition(stream, method_info)
278 | stream.unindent()
279 |
280 | def generate_method_definition(stream, method_info):
281 | stream.write_line('{')
282 | stream.indent()
283 |
284 | if method_info.extinst_info != None:
285 | arguments = []
286 |
287 | for argument in method_info.arguments[1:]:
288 | arguments.append(argument.get_as_operand())
289 |
290 | arguments = ', '.join(arguments)
291 |
292 |
293 | stream.write_line('return ExtInst(resultType, AddExtInstImport("{0}"), {1}, {2});'.format(method_info.extinst_info['name'], method_info.opcode, arguments))
294 | elif method_info.bound_increment_needed:
295 | if method_info.result_type_index != -1:
296 | argument = method_info.arguments[method_info.result_type_index]
297 | if method_info.cl == 'Constant-Creation' and method_info.name.startswith('Constant'):
298 | stream.write_line('Instruction result = new Instruction(Op.Op{0}, Instruction.InvalidId, {1});'.format(method_info.name, argument.name))
299 | else:
300 | stream.write_line('Instruction result = new Instruction(Op.Op{0}, GetNewId(), {1});'.format(method_info.name, argument.name))
301 | else:
302 | # Optimization: here we explictly don't set the id because it will be set in AddTypeDeclaration/AddLabel.
303 | # In the end this permit to not reserve id that will be discared.
304 | if method_info.cl == 'Type-Declaration' or method_info.name == 'Label':
305 | stream.write_line('Instruction result = new Instruction(Op.Op{0});'.format(method_info.name))
306 | else:
307 | stream.write_line('Instruction result = new Instruction(Op.Op{0}, GetNewId());'.format(method_info.name))
308 | else:
309 | if method_info.result_type_index != -1:
310 | raise "TODO"
311 | stream.write_line('Instruction result = new Instruction(Op.Op{0});'.format(method_info.name))
312 |
313 | if method_info.extinst_info == None:
314 | stream.write_line()
315 |
316 | for argument in method_info.arguments:
317 | argument.generate_add_operant_operation(stream)
318 |
319 | if method_info.cl == 'Type-Declaration':
320 | stream.write_line('AddTypeDeclaration(result, forceIdAllocation);')
321 | stream.write_line()
322 | elif method_info.cl == 'Debug':
323 | stream.write_line('AddDebug(result);')
324 | stream.write_line()
325 | elif method_info.cl == 'Annotation':
326 | stream.write_line('AddAnnotation(result);')
327 | stream.write_line()
328 | elif method_info.cl == 'Constant-Creation' and method_info.name.startswith('Constant'):
329 | stream.write_line('AddConstant(result);')
330 | stream.write_line()
331 | elif not method_info.name == 'Variable' and not method_info.name == 'Label':
332 | stream.write_line('AddToFunctionDefinitions(result);')
333 | stream.write_line()
334 | stream.write_line('return result;')
335 |
336 | stream.unindent()
337 | stream.write_line('}')
338 | stream.write_line()
339 |
340 | def generate_method_prototye(stream, method_info):
341 | stream.begin_line()
342 | stream.write('public Instruction {0}('.format(method_info.name))
343 |
344 | arguments = []
345 |
346 | i = 0
347 |
348 | for argument in method_info.arguments:
349 | arguments.append(argument.get_prototype_name())
350 | i += 1
351 |
352 | stream.write(', '.join(arguments))
353 | stream.write(')\n')
354 |
355 | def generate_methods_for_extinst(stream, spec_data, extinst_info):
356 | for instruction in spec_data['instructions']:
357 | generate_method_for_instruction(stream, instruction, extinst_info)
358 |
359 | def generate_methods_by_class(stream, spec_data, cl):
360 | opname_blacklist = [
361 | 'OpExtInstImport',
362 | 'OpExtension',
363 | ]
364 |
365 | stream.indent()
366 | stream.write_line('// {0}'.format(cl))
367 | stream.write_line()
368 | stream.unindent()
369 | for instruction in get_instructions_by_class(spec_data, cl):
370 | opname = instruction['opname']
371 |
372 | # Skip blacklisted op names (already defined with custom apis ect)
373 | if opname in opname_blacklist:
374 | continue
375 |
376 | generate_method_for_instruction(stream, instruction, None)
377 |
378 | def main():
379 | if len(sys.argv) < 3:
380 | print("usage: %s grammar.json Target.cs" % (sys.argv[0]))
381 | exit(1)
382 |
383 | spec_filepath = sys.argv[1]
384 | result_filepath = sys.argv[2]
385 |
386 |
387 | extinst_naming_mapping = {
388 | 'extinst.glsl.std.450.grammar.json': { 'name': 'GLSL.std.450', 'function_prefix': 'Glsl'},
389 | 'extinst.opencl.std.100.grammar.json': { 'name': 'OpenCL.std', 'function_prefix': 'OpenCl'},
390 | }
391 |
392 | spec_filename = os.path.basename(spec_filepath)
393 |
394 | extinst_info = None
395 |
396 | if spec_filename in extinst_naming_mapping:
397 | extinst_info = extinst_naming_mapping[spec_filename]
398 |
399 | with open(spec_filepath, "r") as f:
400 | spec_data = json.loads(f.read())
401 |
402 | stream = CodeStream()
403 |
404 | stream.write_line("// AUTOGENERATED: DO NOT EDIT")
405 | stream.write_line("// Last update date: {0}".format(datetime.datetime.now()))
406 |
407 | stream.write_line("#region Grammar License")
408 | for copyright_line in spec_data['copyright']:
409 | stream.write_line('// {0}'.format(copyright_line))
410 |
411 | stream.write_line("#endregion")
412 | stream.write_line()
413 |
414 |
415 | stream.write_line('using static Spv.Specification;')
416 | stream.write_line()
417 | stream.write_line('namespace Spv.Generator')
418 | stream.write_line('{')
419 | stream.indent()
420 | stream.write_line('public partial class Module')
421 | stream.write_line('{')
422 |
423 |
424 | if extinst_info != None:
425 | generate_methods_for_extinst(stream, spec_data, extinst_info)
426 | else:
427 | generate_methods_by_class(stream, spec_data, 'Miscellaneous')
428 | generate_methods_by_class(stream, spec_data, 'Debug')
429 | generate_methods_by_class(stream, spec_data, 'Annotation')
430 | generate_methods_by_class(stream, spec_data, 'Type-Declaration')
431 | generate_methods_by_class(stream, spec_data, 'Constant-Creation')
432 | generate_methods_by_class(stream, spec_data, 'Memory')
433 | generate_methods_by_class(stream, spec_data, 'Function')
434 | generate_methods_by_class(stream, spec_data, 'Image')
435 | generate_methods_by_class(stream, spec_data, 'Conversion')
436 | generate_methods_by_class(stream, spec_data, 'Composite')
437 | generate_methods_by_class(stream, spec_data, 'Arithmetic')
438 | generate_methods_by_class(stream, spec_data, 'Bit')
439 | generate_methods_by_class(stream, spec_data, 'Relational_and_Logical')
440 | generate_methods_by_class(stream, spec_data, 'Derivative')
441 | generate_methods_by_class(stream, spec_data, 'Control-Flow')
442 | generate_methods_by_class(stream, spec_data, 'Atomic')
443 | generate_methods_by_class(stream, spec_data, 'Primitive')
444 | generate_methods_by_class(stream, spec_data, 'Barrier')
445 | generate_methods_by_class(stream, spec_data, 'Group')
446 | generate_methods_by_class(stream, spec_data, 'Device-Side_Enqueue')
447 | generate_methods_by_class(stream, spec_data, 'Pipe')
448 | generate_methods_by_class(stream, spec_data, 'Non-Uniform')
449 | generate_methods_by_class(stream, spec_data, 'Reserved')
450 |
451 | stream.write_line('}')
452 | stream.unindent()
453 | stream.write_line('}')
454 |
455 | with open(result_filepath, "w+") as result_file:
456 | result_file.write(stream.get())
457 |
458 | return
459 |
460 |
461 | if __name__ == '__main__':
462 | main()
463 |
--------------------------------------------------------------------------------
/Spv.Generator/Autogenerated/GlslStd450Grammar.cs:
--------------------------------------------------------------------------------
1 | // AUTOGENERATED: DO NOT EDIT
2 | // Last update date: 2021-01-06 23:02:26.955269
3 | #region Grammar License
4 | // Copyright (c) 2014-2016 The Khronos Group Inc.
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and/or associated documentation files (the "Materials"),
8 | // to deal in the Materials without restriction, including without limitation
9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 | // and/or sell copies of the Materials, and to permit persons to whom the
11 | // Materials are furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Materials.
15 | //
16 | // MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
17 | // STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
18 | // HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
19 | //
20 | // THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 | // FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
26 | // IN THE MATERIALS.
27 | #endregion
28 |
29 | using static Spv.Specification;
30 |
31 | namespace Spv.Generator
32 | {
33 | public partial class Module
34 | {
35 | public Instruction GlslRound(Instruction resultType, Instruction x)
36 | {
37 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 1, x);
38 | }
39 |
40 | public Instruction GlslRoundEven(Instruction resultType, Instruction x)
41 | {
42 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 2, x);
43 | }
44 |
45 | public Instruction GlslTrunc(Instruction resultType, Instruction x)
46 | {
47 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 3, x);
48 | }
49 |
50 | public Instruction GlslFAbs(Instruction resultType, Instruction x)
51 | {
52 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 4, x);
53 | }
54 |
55 | public Instruction GlslSAbs(Instruction resultType, Instruction x)
56 | {
57 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 5, x);
58 | }
59 |
60 | public Instruction GlslFSign(Instruction resultType, Instruction x)
61 | {
62 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 6, x);
63 | }
64 |
65 | public Instruction GlslSSign(Instruction resultType, Instruction x)
66 | {
67 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 7, x);
68 | }
69 |
70 | public Instruction GlslFloor(Instruction resultType, Instruction x)
71 | {
72 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 8, x);
73 | }
74 |
75 | public Instruction GlslCeil(Instruction resultType, Instruction x)
76 | {
77 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 9, x);
78 | }
79 |
80 | public Instruction GlslFract(Instruction resultType, Instruction x)
81 | {
82 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 10, x);
83 | }
84 |
85 | public Instruction GlslRadians(Instruction resultType, Instruction degrees)
86 | {
87 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 11, degrees);
88 | }
89 |
90 | public Instruction GlslDegrees(Instruction resultType, Instruction radians)
91 | {
92 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 12, radians);
93 | }
94 |
95 | public Instruction GlslSin(Instruction resultType, Instruction x)
96 | {
97 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 13, x);
98 | }
99 |
100 | public Instruction GlslCos(Instruction resultType, Instruction x)
101 | {
102 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 14, x);
103 | }
104 |
105 | public Instruction GlslTan(Instruction resultType, Instruction x)
106 | {
107 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 15, x);
108 | }
109 |
110 | public Instruction GlslAsin(Instruction resultType, Instruction x)
111 | {
112 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 16, x);
113 | }
114 |
115 | public Instruction GlslAcos(Instruction resultType, Instruction x)
116 | {
117 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 17, x);
118 | }
119 |
120 | public Instruction GlslAtan(Instruction resultType, Instruction y_over_x)
121 | {
122 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 18, y_over_x);
123 | }
124 |
125 | public Instruction GlslSinh(Instruction resultType, Instruction x)
126 | {
127 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 19, x);
128 | }
129 |
130 | public Instruction GlslCosh(Instruction resultType, Instruction x)
131 | {
132 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 20, x);
133 | }
134 |
135 | public Instruction GlslTanh(Instruction resultType, Instruction x)
136 | {
137 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 21, x);
138 | }
139 |
140 | public Instruction GlslAsinh(Instruction resultType, Instruction x)
141 | {
142 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 22, x);
143 | }
144 |
145 | public Instruction GlslAcosh(Instruction resultType, Instruction x)
146 | {
147 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 23, x);
148 | }
149 |
150 | public Instruction GlslAtanh(Instruction resultType, Instruction x)
151 | {
152 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 24, x);
153 | }
154 |
155 | public Instruction GlslAtan2(Instruction resultType, Instruction y, Instruction x)
156 | {
157 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 25, y, x);
158 | }
159 |
160 | public Instruction GlslPow(Instruction resultType, Instruction x, Instruction y)
161 | {
162 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 26, x, y);
163 | }
164 |
165 | public Instruction GlslExp(Instruction resultType, Instruction x)
166 | {
167 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 27, x);
168 | }
169 |
170 | public Instruction GlslLog(Instruction resultType, Instruction x)
171 | {
172 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 28, x);
173 | }
174 |
175 | public Instruction GlslExp2(Instruction resultType, Instruction x)
176 | {
177 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 29, x);
178 | }
179 |
180 | public Instruction GlslLog2(Instruction resultType, Instruction x)
181 | {
182 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 30, x);
183 | }
184 |
185 | public Instruction GlslSqrt(Instruction resultType, Instruction x)
186 | {
187 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 31, x);
188 | }
189 |
190 | public Instruction GlslInverseSqrt(Instruction resultType, Instruction x)
191 | {
192 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 32, x);
193 | }
194 |
195 | public Instruction GlslDeterminant(Instruction resultType, Instruction x)
196 | {
197 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 33, x);
198 | }
199 |
200 | public Instruction GlslMatrixInverse(Instruction resultType, Instruction x)
201 | {
202 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 34, x);
203 | }
204 |
205 | public Instruction GlslModf(Instruction resultType, Instruction x, Instruction i)
206 | {
207 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 35, x, i);
208 | }
209 |
210 | public Instruction GlslModfStruct(Instruction resultType, Instruction x)
211 | {
212 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 36, x);
213 | }
214 |
215 | public Instruction GlslFMin(Instruction resultType, Instruction x, Instruction y)
216 | {
217 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 37, x, y);
218 | }
219 |
220 | public Instruction GlslUMin(Instruction resultType, Instruction x, Instruction y)
221 | {
222 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 38, x, y);
223 | }
224 |
225 | public Instruction GlslSMin(Instruction resultType, Instruction x, Instruction y)
226 | {
227 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 39, x, y);
228 | }
229 |
230 | public Instruction GlslFMax(Instruction resultType, Instruction x, Instruction y)
231 | {
232 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 40, x, y);
233 | }
234 |
235 | public Instruction GlslUMax(Instruction resultType, Instruction x, Instruction y)
236 | {
237 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 41, x, y);
238 | }
239 |
240 | public Instruction GlslSMax(Instruction resultType, Instruction x, Instruction y)
241 | {
242 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 42, x, y);
243 | }
244 |
245 | public Instruction GlslFClamp(Instruction resultType, Instruction x, Instruction minVal, Instruction maxVal)
246 | {
247 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 43, x, minVal, maxVal);
248 | }
249 |
250 | public Instruction GlslUClamp(Instruction resultType, Instruction x, Instruction minVal, Instruction maxVal)
251 | {
252 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 44, x, minVal, maxVal);
253 | }
254 |
255 | public Instruction GlslSClamp(Instruction resultType, Instruction x, Instruction minVal, Instruction maxVal)
256 | {
257 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 45, x, minVal, maxVal);
258 | }
259 |
260 | public Instruction GlslFMix(Instruction resultType, Instruction x, Instruction y, Instruction a)
261 | {
262 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 46, x, y, a);
263 | }
264 |
265 | public Instruction GlslIMix(Instruction resultType, Instruction x, Instruction y, Instruction a)
266 | {
267 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 47, x, y, a);
268 | }
269 |
270 | public Instruction GlslStep(Instruction resultType, Instruction edge, Instruction x)
271 | {
272 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 48, edge, x);
273 | }
274 |
275 | public Instruction GlslSmoothStep(Instruction resultType, Instruction edge0, Instruction edge1, Instruction x)
276 | {
277 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 49, edge0, edge1, x);
278 | }
279 |
280 | public Instruction GlslFma(Instruction resultType, Instruction a, Instruction b, Instruction c)
281 | {
282 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 50, a, b, c);
283 | }
284 |
285 | public Instruction GlslFrexp(Instruction resultType, Instruction x, Instruction exp)
286 | {
287 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 51, x, exp);
288 | }
289 |
290 | public Instruction GlslFrexpStruct(Instruction resultType, Instruction x)
291 | {
292 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 52, x);
293 | }
294 |
295 | public Instruction GlslLdexp(Instruction resultType, Instruction x, Instruction exp)
296 | {
297 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 53, x, exp);
298 | }
299 |
300 | public Instruction GlslPackSnorm4x8(Instruction resultType, Instruction v)
301 | {
302 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 54, v);
303 | }
304 |
305 | public Instruction GlslPackUnorm4x8(Instruction resultType, Instruction v)
306 | {
307 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 55, v);
308 | }
309 |
310 | public Instruction GlslPackSnorm2x16(Instruction resultType, Instruction v)
311 | {
312 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 56, v);
313 | }
314 |
315 | public Instruction GlslPackUnorm2x16(Instruction resultType, Instruction v)
316 | {
317 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 57, v);
318 | }
319 |
320 | public Instruction GlslPackHalf2x16(Instruction resultType, Instruction v)
321 | {
322 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 58, v);
323 | }
324 |
325 | public Instruction GlslPackDouble2x32(Instruction resultType, Instruction v)
326 | {
327 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 59, v);
328 | }
329 |
330 | public Instruction GlslUnpackSnorm2x16(Instruction resultType, Instruction p)
331 | {
332 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 60, p);
333 | }
334 |
335 | public Instruction GlslUnpackUnorm2x16(Instruction resultType, Instruction p)
336 | {
337 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 61, p);
338 | }
339 |
340 | public Instruction GlslUnpackHalf2x16(Instruction resultType, Instruction v)
341 | {
342 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 62, v);
343 | }
344 |
345 | public Instruction GlslUnpackSnorm4x8(Instruction resultType, Instruction p)
346 | {
347 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 63, p);
348 | }
349 |
350 | public Instruction GlslUnpackUnorm4x8(Instruction resultType, Instruction p)
351 | {
352 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 64, p);
353 | }
354 |
355 | public Instruction GlslUnpackDouble2x32(Instruction resultType, Instruction v)
356 | {
357 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 65, v);
358 | }
359 |
360 | public Instruction GlslLength(Instruction resultType, Instruction x)
361 | {
362 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 66, x);
363 | }
364 |
365 | public Instruction GlslDistance(Instruction resultType, Instruction p0, Instruction p1)
366 | {
367 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 67, p0, p1);
368 | }
369 |
370 | public Instruction GlslCross(Instruction resultType, Instruction x, Instruction y)
371 | {
372 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 68, x, y);
373 | }
374 |
375 | public Instruction GlslNormalize(Instruction resultType, Instruction x)
376 | {
377 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 69, x);
378 | }
379 |
380 | public Instruction GlslFaceForward(Instruction resultType, Instruction n, Instruction i, Instruction nref)
381 | {
382 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 70, n, i, nref);
383 | }
384 |
385 | public Instruction GlslReflect(Instruction resultType, Instruction i, Instruction n)
386 | {
387 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 71, i, n);
388 | }
389 |
390 | public Instruction GlslRefract(Instruction resultType, Instruction i, Instruction n, Instruction eta)
391 | {
392 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 72, i, n, eta);
393 | }
394 |
395 | public Instruction GlslFindILsb(Instruction resultType, Instruction value)
396 | {
397 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 73, value);
398 | }
399 |
400 | public Instruction GlslFindSMsb(Instruction resultType, Instruction value)
401 | {
402 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 74, value);
403 | }
404 |
405 | public Instruction GlslFindUMsb(Instruction resultType, Instruction value)
406 | {
407 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 75, value);
408 | }
409 |
410 | public Instruction GlslInterpolateAtCentroid(Instruction resultType, Instruction interpolant)
411 | {
412 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 76, interpolant);
413 | }
414 |
415 | public Instruction GlslInterpolateAtSample(Instruction resultType, Instruction interpolant, Instruction sample)
416 | {
417 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 77, interpolant, sample);
418 | }
419 |
420 | public Instruction GlslInterpolateAtOffset(Instruction resultType, Instruction interpolant, Instruction offset)
421 | {
422 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 78, interpolant, offset);
423 | }
424 |
425 | public Instruction GlslNMin(Instruction resultType, Instruction x, Instruction y)
426 | {
427 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 79, x, y);
428 | }
429 |
430 | public Instruction GlslNMax(Instruction resultType, Instruction x, Instruction y)
431 | {
432 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 80, x, y);
433 | }
434 |
435 | public Instruction GlslNClamp(Instruction resultType, Instruction x, Instruction minVal, Instruction maxVal)
436 | {
437 | return ExtInst(resultType, AddExtInstImport("GLSL.std.450"), 81, x, minVal, maxVal);
438 | }
439 |
440 | }
441 | }
442 |
--------------------------------------------------------------------------------
/Spv.Generator/Autogenerated/OpenClGrammar.cs:
--------------------------------------------------------------------------------
1 | // AUTOGENERATED: DO NOT EDIT
2 | // Last update date: 2021-01-06 23:02:27.020534
3 | #region Grammar License
4 | // Copyright (c) 2014-2016 The Khronos Group Inc.
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and/or associated documentation files (the "Materials"),
8 | // to deal in the Materials without restriction, including without limitation
9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 | // and/or sell copies of the Materials, and to permit persons to whom the
11 | // Materials are furnished to do so, subject to the following conditions:
12 | //
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Materials.
15 | //
16 | // MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
17 | // STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
18 | // HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
19 | //
20 | // THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 | // FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
26 | // IN THE MATERIALS.
27 | #endregion
28 |
29 | using static Spv.Specification;
30 |
31 | namespace Spv.Generator
32 | {
33 | public partial class Module
34 | {
35 | public Instruction OpenClAcos(Instruction resultType, Instruction x)
36 | {
37 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 0, x);
38 | }
39 |
40 | public Instruction OpenClAcosh(Instruction resultType, Instruction x)
41 | {
42 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 1, x);
43 | }
44 |
45 | public Instruction OpenClAcospi(Instruction resultType, Instruction x)
46 | {
47 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 2, x);
48 | }
49 |
50 | public Instruction OpenClAsin(Instruction resultType, Instruction x)
51 | {
52 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 3, x);
53 | }
54 |
55 | public Instruction OpenClAsinh(Instruction resultType, Instruction x)
56 | {
57 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 4, x);
58 | }
59 |
60 | public Instruction OpenClAsinpi(Instruction resultType, Instruction x)
61 | {
62 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 5, x);
63 | }
64 |
65 | public Instruction OpenClAtan(Instruction resultType, Instruction x)
66 | {
67 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 6, x);
68 | }
69 |
70 | public Instruction OpenClAtan2(Instruction resultType, Instruction y, Instruction x)
71 | {
72 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 7, y, x);
73 | }
74 |
75 | public Instruction OpenClAtanh(Instruction resultType, Instruction x)
76 | {
77 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 8, x);
78 | }
79 |
80 | public Instruction OpenClAtanpi(Instruction resultType, Instruction x)
81 | {
82 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 9, x);
83 | }
84 |
85 | public Instruction OpenClAtan2pi(Instruction resultType, Instruction y, Instruction x)
86 | {
87 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 10, y, x);
88 | }
89 |
90 | public Instruction OpenClCbrt(Instruction resultType, Instruction x)
91 | {
92 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 11, x);
93 | }
94 |
95 | public Instruction OpenClCeil(Instruction resultType, Instruction x)
96 | {
97 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 12, x);
98 | }
99 |
100 | public Instruction OpenClCopysign(Instruction resultType, Instruction x, Instruction y)
101 | {
102 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 13, x, y);
103 | }
104 |
105 | public Instruction OpenClCos(Instruction resultType, Instruction x)
106 | {
107 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 14, x);
108 | }
109 |
110 | public Instruction OpenClCosh(Instruction resultType, Instruction x)
111 | {
112 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 15, x);
113 | }
114 |
115 | public Instruction OpenClCospi(Instruction resultType, Instruction x)
116 | {
117 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 16, x);
118 | }
119 |
120 | public Instruction OpenClErfc(Instruction resultType, Instruction x)
121 | {
122 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 17, x);
123 | }
124 |
125 | public Instruction OpenClErf(Instruction resultType, Instruction x)
126 | {
127 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 18, x);
128 | }
129 |
130 | public Instruction OpenClExp(Instruction resultType, Instruction x)
131 | {
132 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 19, x);
133 | }
134 |
135 | public Instruction OpenClExp2(Instruction resultType, Instruction x)
136 | {
137 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 20, x);
138 | }
139 |
140 | public Instruction OpenClExp10(Instruction resultType, Instruction x)
141 | {
142 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 21, x);
143 | }
144 |
145 | public Instruction OpenClExpm1(Instruction resultType, Instruction x)
146 | {
147 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 22, x);
148 | }
149 |
150 | public Instruction OpenClFabs(Instruction resultType, Instruction x)
151 | {
152 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 23, x);
153 | }
154 |
155 | public Instruction OpenClFdim(Instruction resultType, Instruction x, Instruction y)
156 | {
157 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 24, x, y);
158 | }
159 |
160 | public Instruction OpenClFloor(Instruction resultType, Instruction x)
161 | {
162 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 25, x);
163 | }
164 |
165 | public Instruction OpenClFma(Instruction resultType, Instruction a, Instruction b, Instruction c)
166 | {
167 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 26, a, b, c);
168 | }
169 |
170 | public Instruction OpenClFmax(Instruction resultType, Instruction x, Instruction y)
171 | {
172 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 27, x, y);
173 | }
174 |
175 | public Instruction OpenClFmin(Instruction resultType, Instruction x, Instruction y)
176 | {
177 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 28, x, y);
178 | }
179 |
180 | public Instruction OpenClFmod(Instruction resultType, Instruction x, Instruction y)
181 | {
182 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 29, x, y);
183 | }
184 |
185 | public Instruction OpenClFract(Instruction resultType, Instruction x, Instruction ptr)
186 | {
187 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 30, x, ptr);
188 | }
189 |
190 | public Instruction OpenClFrexp(Instruction resultType, Instruction x, Instruction exp)
191 | {
192 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 31, x, exp);
193 | }
194 |
195 | public Instruction OpenClHypot(Instruction resultType, Instruction x, Instruction y)
196 | {
197 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 32, x, y);
198 | }
199 |
200 | public Instruction OpenClIlogb(Instruction resultType, Instruction x)
201 | {
202 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 33, x);
203 | }
204 |
205 | public Instruction OpenClLdexp(Instruction resultType, Instruction x, Instruction k)
206 | {
207 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 34, x, k);
208 | }
209 |
210 | public Instruction OpenClLgamma(Instruction resultType, Instruction x)
211 | {
212 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 35, x);
213 | }
214 |
215 | public Instruction OpenClLgamma_r(Instruction resultType, Instruction x, Instruction signp)
216 | {
217 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 36, x, signp);
218 | }
219 |
220 | public Instruction OpenClLog(Instruction resultType, Instruction x)
221 | {
222 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 37, x);
223 | }
224 |
225 | public Instruction OpenClLog2(Instruction resultType, Instruction x)
226 | {
227 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 38, x);
228 | }
229 |
230 | public Instruction OpenClLog10(Instruction resultType, Instruction x)
231 | {
232 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 39, x);
233 | }
234 |
235 | public Instruction OpenClLog1p(Instruction resultType, Instruction x)
236 | {
237 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 40, x);
238 | }
239 |
240 | public Instruction OpenClLogb(Instruction resultType, Instruction x)
241 | {
242 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 41, x);
243 | }
244 |
245 | public Instruction OpenClMad(Instruction resultType, Instruction a, Instruction b, Instruction c)
246 | {
247 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 42, a, b, c);
248 | }
249 |
250 | public Instruction OpenClMaxmag(Instruction resultType, Instruction x, Instruction y)
251 | {
252 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 43, x, y);
253 | }
254 |
255 | public Instruction OpenClMinmag(Instruction resultType, Instruction x, Instruction y)
256 | {
257 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 44, x, y);
258 | }
259 |
260 | public Instruction OpenClModf(Instruction resultType, Instruction x, Instruction iptr)
261 | {
262 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 45, x, iptr);
263 | }
264 |
265 | public Instruction OpenClNan(Instruction resultType, Instruction nancode)
266 | {
267 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 46, nancode);
268 | }
269 |
270 | public Instruction OpenClNextafter(Instruction resultType, Instruction x, Instruction y)
271 | {
272 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 47, x, y);
273 | }
274 |
275 | public Instruction OpenClPow(Instruction resultType, Instruction x, Instruction y)
276 | {
277 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 48, x, y);
278 | }
279 |
280 | public Instruction OpenClPown(Instruction resultType, Instruction x, Instruction y)
281 | {
282 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 49, x, y);
283 | }
284 |
285 | public Instruction OpenClPowr(Instruction resultType, Instruction x, Instruction y)
286 | {
287 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 50, x, y);
288 | }
289 |
290 | public Instruction OpenClRemainder(Instruction resultType, Instruction x, Instruction y)
291 | {
292 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 51, x, y);
293 | }
294 |
295 | public Instruction OpenClRemquo(Instruction resultType, Instruction x, Instruction y, Instruction quo)
296 | {
297 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 52, x, y, quo);
298 | }
299 |
300 | public Instruction OpenClRint(Instruction resultType, Instruction x)
301 | {
302 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 53, x);
303 | }
304 |
305 | public Instruction OpenClRootn(Instruction resultType, Instruction x, Instruction y)
306 | {
307 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 54, x, y);
308 | }
309 |
310 | public Instruction OpenClRound(Instruction resultType, Instruction x)
311 | {
312 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 55, x);
313 | }
314 |
315 | public Instruction OpenClRsqrt(Instruction resultType, Instruction x)
316 | {
317 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 56, x);
318 | }
319 |
320 | public Instruction OpenClSin(Instruction resultType, Instruction x)
321 | {
322 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 57, x);
323 | }
324 |
325 | public Instruction OpenClSincos(Instruction resultType, Instruction x, Instruction cosval)
326 | {
327 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 58, x, cosval);
328 | }
329 |
330 | public Instruction OpenClSinh(Instruction resultType, Instruction x)
331 | {
332 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 59, x);
333 | }
334 |
335 | public Instruction OpenClSinpi(Instruction resultType, Instruction x)
336 | {
337 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 60, x);
338 | }
339 |
340 | public Instruction OpenClSqrt(Instruction resultType, Instruction x)
341 | {
342 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 61, x);
343 | }
344 |
345 | public Instruction OpenClTan(Instruction resultType, Instruction x)
346 | {
347 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 62, x);
348 | }
349 |
350 | public Instruction OpenClTanh(Instruction resultType, Instruction x)
351 | {
352 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 63, x);
353 | }
354 |
355 | public Instruction OpenClTanpi(Instruction resultType, Instruction x)
356 | {
357 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 64, x);
358 | }
359 |
360 | public Instruction OpenClTgamma(Instruction resultType, Instruction x)
361 | {
362 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 65, x);
363 | }
364 |
365 | public Instruction OpenClTrunc(Instruction resultType, Instruction x)
366 | {
367 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 66, x);
368 | }
369 |
370 | public Instruction OpenClHalf_cos(Instruction resultType, Instruction x)
371 | {
372 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 67, x);
373 | }
374 |
375 | public Instruction OpenClHalf_divide(Instruction resultType, Instruction x, Instruction y)
376 | {
377 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 68, x, y);
378 | }
379 |
380 | public Instruction OpenClHalf_exp(Instruction resultType, Instruction x)
381 | {
382 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 69, x);
383 | }
384 |
385 | public Instruction OpenClHalf_exp2(Instruction resultType, Instruction x)
386 | {
387 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 70, x);
388 | }
389 |
390 | public Instruction OpenClHalf_exp10(Instruction resultType, Instruction x)
391 | {
392 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 71, x);
393 | }
394 |
395 | public Instruction OpenClHalf_log(Instruction resultType, Instruction x)
396 | {
397 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 72, x);
398 | }
399 |
400 | public Instruction OpenClHalf_log2(Instruction resultType, Instruction x)
401 | {
402 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 73, x);
403 | }
404 |
405 | public Instruction OpenClHalf_log10(Instruction resultType, Instruction x)
406 | {
407 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 74, x);
408 | }
409 |
410 | public Instruction OpenClHalf_powr(Instruction resultType, Instruction x, Instruction y)
411 | {
412 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 75, x, y);
413 | }
414 |
415 | public Instruction OpenClHalf_recip(Instruction resultType, Instruction x)
416 | {
417 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 76, x);
418 | }
419 |
420 | public Instruction OpenClHalf_rsqrt(Instruction resultType, Instruction x)
421 | {
422 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 77, x);
423 | }
424 |
425 | public Instruction OpenClHalf_sin(Instruction resultType, Instruction x)
426 | {
427 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 78, x);
428 | }
429 |
430 | public Instruction OpenClHalf_sqrt(Instruction resultType, Instruction x)
431 | {
432 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 79, x);
433 | }
434 |
435 | public Instruction OpenClHalf_tan(Instruction resultType, Instruction x)
436 | {
437 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 80, x);
438 | }
439 |
440 | public Instruction OpenClNative_cos(Instruction resultType, Instruction x)
441 | {
442 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 81, x);
443 | }
444 |
445 | public Instruction OpenClNative_divide(Instruction resultType, Instruction x, Instruction y)
446 | {
447 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 82, x, y);
448 | }
449 |
450 | public Instruction OpenClNative_exp(Instruction resultType, Instruction x)
451 | {
452 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 83, x);
453 | }
454 |
455 | public Instruction OpenClNative_exp2(Instruction resultType, Instruction x)
456 | {
457 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 84, x);
458 | }
459 |
460 | public Instruction OpenClNative_exp10(Instruction resultType, Instruction x)
461 | {
462 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 85, x);
463 | }
464 |
465 | public Instruction OpenClNative_log(Instruction resultType, Instruction x)
466 | {
467 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 86, x);
468 | }
469 |
470 | public Instruction OpenClNative_log2(Instruction resultType, Instruction x)
471 | {
472 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 87, x);
473 | }
474 |
475 | public Instruction OpenClNative_log10(Instruction resultType, Instruction x)
476 | {
477 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 88, x);
478 | }
479 |
480 | public Instruction OpenClNative_powr(Instruction resultType, Instruction x, Instruction y)
481 | {
482 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 89, x, y);
483 | }
484 |
485 | public Instruction OpenClNative_recip(Instruction resultType, Instruction x)
486 | {
487 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 90, x);
488 | }
489 |
490 | public Instruction OpenClNative_rsqrt(Instruction resultType, Instruction x)
491 | {
492 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 91, x);
493 | }
494 |
495 | public Instruction OpenClNative_sin(Instruction resultType, Instruction x)
496 | {
497 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 92, x);
498 | }
499 |
500 | public Instruction OpenClNative_sqrt(Instruction resultType, Instruction x)
501 | {
502 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 93, x);
503 | }
504 |
505 | public Instruction OpenClNative_tan(Instruction resultType, Instruction x)
506 | {
507 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 94, x);
508 | }
509 |
510 | public Instruction OpenClS_abs(Instruction resultType, Instruction x)
511 | {
512 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 141, x);
513 | }
514 |
515 | public Instruction OpenClS_abs_diff(Instruction resultType, Instruction x, Instruction y)
516 | {
517 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 142, x, y);
518 | }
519 |
520 | public Instruction OpenClS_add_sat(Instruction resultType, Instruction x, Instruction y)
521 | {
522 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 143, x, y);
523 | }
524 |
525 | public Instruction OpenClU_add_sat(Instruction resultType, Instruction x, Instruction y)
526 | {
527 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 144, x, y);
528 | }
529 |
530 | public Instruction OpenClS_hadd(Instruction resultType, Instruction x, Instruction y)
531 | {
532 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 145, x, y);
533 | }
534 |
535 | public Instruction OpenClU_hadd(Instruction resultType, Instruction x, Instruction y)
536 | {
537 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 146, x, y);
538 | }
539 |
540 | public Instruction OpenClS_rhadd(Instruction resultType, Instruction x, Instruction y)
541 | {
542 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 147, x, y);
543 | }
544 |
545 | public Instruction OpenClU_rhadd(Instruction resultType, Instruction x, Instruction y)
546 | {
547 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 148, x, y);
548 | }
549 |
550 | public Instruction OpenClS_clamp(Instruction resultType, Instruction x, Instruction minval, Instruction maxval)
551 | {
552 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 149, x, minval, maxval);
553 | }
554 |
555 | public Instruction OpenClU_clamp(Instruction resultType, Instruction x, Instruction minval, Instruction maxval)
556 | {
557 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 150, x, minval, maxval);
558 | }
559 |
560 | public Instruction OpenClClz(Instruction resultType, Instruction x)
561 | {
562 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 151, x);
563 | }
564 |
565 | public Instruction OpenClCtz(Instruction resultType, Instruction x)
566 | {
567 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 152, x);
568 | }
569 |
570 | public Instruction OpenClS_mad_hi(Instruction resultType, Instruction a, Instruction b, Instruction c)
571 | {
572 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 153, a, b, c);
573 | }
574 |
575 | public Instruction OpenClU_mad_sat(Instruction resultType, Instruction x, Instruction y, Instruction z)
576 | {
577 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 154, x, y, z);
578 | }
579 |
580 | public Instruction OpenClS_mad_sat(Instruction resultType, Instruction x, Instruction y, Instruction z)
581 | {
582 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 155, x, y, z);
583 | }
584 |
585 | public Instruction OpenClS_max(Instruction resultType, Instruction x, Instruction y)
586 | {
587 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 156, x, y);
588 | }
589 |
590 | public Instruction OpenClU_max(Instruction resultType, Instruction x, Instruction y)
591 | {
592 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 157, x, y);
593 | }
594 |
595 | public Instruction OpenClS_min(Instruction resultType, Instruction x, Instruction y)
596 | {
597 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 158, x, y);
598 | }
599 |
600 | public Instruction OpenClU_min(Instruction resultType, Instruction x, Instruction y)
601 | {
602 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 159, x, y);
603 | }
604 |
605 | public Instruction OpenClS_mul_hi(Instruction resultType, Instruction x, Instruction y)
606 | {
607 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 160, x, y);
608 | }
609 |
610 | public Instruction OpenClRotate(Instruction resultType, Instruction v, Instruction i)
611 | {
612 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 161, v, i);
613 | }
614 |
615 | public Instruction OpenClS_sub_sat(Instruction resultType, Instruction x, Instruction y)
616 | {
617 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 162, x, y);
618 | }
619 |
620 | public Instruction OpenClU_sub_sat(Instruction resultType, Instruction x, Instruction y)
621 | {
622 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 163, x, y);
623 | }
624 |
625 | public Instruction OpenClU_upsample(Instruction resultType, Instruction hi, Instruction lo)
626 | {
627 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 164, hi, lo);
628 | }
629 |
630 | public Instruction OpenClS_upsample(Instruction resultType, Instruction hi, Instruction lo)
631 | {
632 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 165, hi, lo);
633 | }
634 |
635 | public Instruction OpenClPopcount(Instruction resultType, Instruction x)
636 | {
637 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 166, x);
638 | }
639 |
640 | public Instruction OpenClS_mad24(Instruction resultType, Instruction x, Instruction y, Instruction z)
641 | {
642 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 167, x, y, z);
643 | }
644 |
645 | public Instruction OpenClU_mad24(Instruction resultType, Instruction x, Instruction y, Instruction z)
646 | {
647 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 168, x, y, z);
648 | }
649 |
650 | public Instruction OpenClS_mul24(Instruction resultType, Instruction x, Instruction y)
651 | {
652 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 169, x, y);
653 | }
654 |
655 | public Instruction OpenClU_mul24(Instruction resultType, Instruction x, Instruction y)
656 | {
657 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 170, x, y);
658 | }
659 |
660 | public Instruction OpenClU_abs(Instruction resultType, Instruction x)
661 | {
662 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 201, x);
663 | }
664 |
665 | public Instruction OpenClU_abs_diff(Instruction resultType, Instruction x, Instruction y)
666 | {
667 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 202, x, y);
668 | }
669 |
670 | public Instruction OpenClU_mul_hi(Instruction resultType, Instruction x, Instruction y)
671 | {
672 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 203, x, y);
673 | }
674 |
675 | public Instruction OpenClU_mad_hi(Instruction resultType, Instruction a, Instruction b, Instruction c)
676 | {
677 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 204, a, b, c);
678 | }
679 |
680 | public Instruction OpenClFclamp(Instruction resultType, Instruction x, Instruction minval, Instruction maxval)
681 | {
682 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 95, x, minval, maxval);
683 | }
684 |
685 | public Instruction OpenClDegrees(Instruction resultType, Instruction radians)
686 | {
687 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 96, radians);
688 | }
689 |
690 | public Instruction OpenClFmax_common(Instruction resultType, Instruction x, Instruction y)
691 | {
692 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 97, x, y);
693 | }
694 |
695 | public Instruction OpenClFmin_common(Instruction resultType, Instruction x, Instruction y)
696 | {
697 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 98, x, y);
698 | }
699 |
700 | public Instruction OpenClMix(Instruction resultType, Instruction x, Instruction y, Instruction a)
701 | {
702 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 99, x, y, a);
703 | }
704 |
705 | public Instruction OpenClRadians(Instruction resultType, Instruction degrees)
706 | {
707 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 100, degrees);
708 | }
709 |
710 | public Instruction OpenClStep(Instruction resultType, Instruction edge, Instruction x)
711 | {
712 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 101, edge, x);
713 | }
714 |
715 | public Instruction OpenClSmoothstep(Instruction resultType, Instruction edge0, Instruction edge1, Instruction x)
716 | {
717 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 102, edge0, edge1, x);
718 | }
719 |
720 | public Instruction OpenClSign(Instruction resultType, Instruction x)
721 | {
722 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 103, x);
723 | }
724 |
725 | public Instruction OpenClCross(Instruction resultType, Instruction p0, Instruction p1)
726 | {
727 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 104, p0, p1);
728 | }
729 |
730 | public Instruction OpenClDistance(Instruction resultType, Instruction p0, Instruction p1)
731 | {
732 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 105, p0, p1);
733 | }
734 |
735 | public Instruction OpenClLength(Instruction resultType, Instruction p)
736 | {
737 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 106, p);
738 | }
739 |
740 | public Instruction OpenClNormalize(Instruction resultType, Instruction p)
741 | {
742 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 107, p);
743 | }
744 |
745 | public Instruction OpenClFast_distance(Instruction resultType, Instruction p0, Instruction p1)
746 | {
747 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 108, p0, p1);
748 | }
749 |
750 | public Instruction OpenClFast_length(Instruction resultType, Instruction p)
751 | {
752 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 109, p);
753 | }
754 |
755 | public Instruction OpenClFast_normalize(Instruction resultType, Instruction p)
756 | {
757 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 110, p);
758 | }
759 |
760 | public Instruction OpenClBitselect(Instruction resultType, Instruction a, Instruction b, Instruction c)
761 | {
762 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 186, a, b, c);
763 | }
764 |
765 | public Instruction OpenClSelect(Instruction resultType, Instruction a, Instruction b, Instruction c)
766 | {
767 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 187, a, b, c);
768 | }
769 |
770 | public Instruction OpenClVloadn(Instruction resultType, Instruction offset, Instruction p, LiteralInteger n)
771 | {
772 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 171, offset, p, n);
773 | }
774 |
775 | public Instruction OpenClVstoren(Instruction resultType, Instruction data, Instruction offset, Instruction p)
776 | {
777 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 172, data, offset, p);
778 | }
779 |
780 | public Instruction OpenClVload_half(Instruction resultType, Instruction offset, Instruction p)
781 | {
782 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 173, offset, p);
783 | }
784 |
785 | public Instruction OpenClVload_halfn(Instruction resultType, Instruction offset, Instruction p, LiteralInteger n)
786 | {
787 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 174, offset, p, n);
788 | }
789 |
790 | public Instruction OpenClVstore_half(Instruction resultType, Instruction data, Instruction offset, Instruction p)
791 | {
792 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 175, data, offset, p);
793 | }
794 |
795 | public Instruction OpenClVstore_half_r(Instruction resultType, Instruction data, Instruction offset, Instruction p, FPRoundingMode mode)
796 | {
797 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 176, data, offset, p, LiteralInteger.CreateForEnum(mode));
798 | }
799 |
800 | public Instruction OpenClVstore_halfn(Instruction resultType, Instruction data, Instruction offset, Instruction p)
801 | {
802 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 177, data, offset, p);
803 | }
804 |
805 | public Instruction OpenClVstore_halfn_r(Instruction resultType, Instruction data, Instruction offset, Instruction p, FPRoundingMode mode)
806 | {
807 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 178, data, offset, p, LiteralInteger.CreateForEnum(mode));
808 | }
809 |
810 | public Instruction OpenClVloada_halfn(Instruction resultType, Instruction offset, Instruction p, LiteralInteger n)
811 | {
812 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 179, offset, p, n);
813 | }
814 |
815 | public Instruction OpenClVstorea_halfn(Instruction resultType, Instruction data, Instruction offset, Instruction p)
816 | {
817 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 180, data, offset, p);
818 | }
819 |
820 | public Instruction OpenClVstorea_halfn_r(Instruction resultType, Instruction data, Instruction offset, Instruction p, FPRoundingMode mode)
821 | {
822 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 181, data, offset, p, LiteralInteger.CreateForEnum(mode));
823 | }
824 |
825 | public Instruction OpenClShuffle(Instruction resultType, Instruction x, Instruction shufflemask)
826 | {
827 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 182, x, shufflemask);
828 | }
829 |
830 | public Instruction OpenClShuffle2(Instruction resultType, Instruction x, Instruction y, Instruction shufflemask)
831 | {
832 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 183, x, y, shufflemask);
833 | }
834 |
835 | public Instruction OpenClPrefetch(Instruction resultType, Instruction ptr, Instruction numelements)
836 | {
837 | return ExtInst(resultType, AddExtInstImport("OpenCL.std"), 185, ptr, numelements);
838 | }
839 |
840 | }
841 | }
842 |
--------------------------------------------------------------------------------