aboutsummaryrefslogtreecommitdiff
path: root/plugins/language_hlsl.lua
blob: a7a437528ac20e3c3899df3780df711cb1c70fe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
local style = require "core.style"
local common = require "core.common"

style.syntax["forbiddenbuiltin"] = { common.color "#ee0000" }
style.syntax["builtin"] = { common.color "#77eecc" }
local syntax = require "core.syntax"

syntax.add {
  files = { "%.hlsl$", },
  comment = "//",
  patterns = {
    { pattern = "//.-\n",               type = "comment"  },
    { pattern = { "/%*", "%*/" },       type = "comment"  },
    { pattern = { "#", "[^\\]\n" },     type = "comment"  },
    { pattern = { '"', '"', '\\' },     type = "string"   },
    { pattern = { "'", "'", '\\' },     type = "string"   },
    { pattern = "-?0x%x+",              type = "number"   },
    { pattern = "-?%d+[%d%.eE]*f?",     type = "number"   },
    { pattern = "-?%.?%d+f?",           type = "number"   },
    { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },

    { pattern = "int[1-9]x[1-9]",       type = "keyword2" },
    { pattern = "int1[0-6]x[1-9]",      type = "keyword2" },
    { pattern = "int[1-9]x1[0-6]",      type = "keyword2" },
    { pattern = "int1[0-6]x1[0-6]",     type = "keyword2" },
    { pattern = "int[1-4]",             type = "keyword2" },

    { pattern = "uint[1-9]x[1-9]",      type = "keyword2" },
    { pattern = "uint1[0-6]x[1-9]",     type = "keyword2" },
    { pattern = "uint[1-9]x1[0-6]",     type = "keyword2" },
    { pattern = "uint1[0-6]x1[0-6]",    type = "keyword2" },
    { pattern = "uint[1-4]",            type = "keyword2" },

    { pattern = "dword[1-9]x[1-9]",     type = "keyword2" },
    { pattern = "dword1[0-6]x[1-9]",    type = "keyword2" },
    { pattern = "dword[1-9]x1[0-6]",    type = "keyword2" },
    { pattern = "dword1[0-6]x1[0-6]",   type = "keyword2" },
    { pattern = "dword[1-4]",           type = "keyword2" },

    { pattern = "half[1-9]x[1-9]",      type = "keyword2" },
    { pattern = "half1[0-6]x[1-9]",     type = "keyword2" },
    { pattern = "half[1-9]x1[0-6]",     type = "keyword2" },
    { pattern = "half1[0-6]x1[0-6]",    type = "keyword2" },
    { pattern = "half[1-4]",            type = "keyword2" },

    { pattern = "float[1-9]x[1-9]",     type = "keyword2" },
    { pattern = "float1[0-6]x[1-9]",    type = "keyword2" },
    { pattern = "float[1-9]x1[0-6]",    type = "keyword2" },
    { pattern = "float1[0-6]x1[0-6]",   type = "keyword2" },
    { pattern = "float[1-4]",           type = "keyword2" },

    { pattern = "double[1-9]x[1-9]",    type = "keyword2" },
    { pattern = "double1[0-6]x[1-9]",   type = "keyword2" },
    { pattern = "double[1-9]x1[0-6]",   type = "keyword2" },
    { pattern = "double1[0-6]x1[0-6]",  type = "keyword2" },
    { pattern = "double[1-4]",          type = "keyword2" },

    { pattern = "ivec[2-4]",            type = "forbiddenbuiltin" },
    { pattern = "bvec[2-4]",            type = "forbiddenbuiltin" },
    { pattern = "uvec[2-4]",            type = "forbiddenbuiltin" },
    { pattern = "vec[2-4]",             type = "forbiddenbuiltin" },
    { pattern = "dmat[2-4]x[2-4]",      type = "forbiddenbuiltin" },
    { pattern = "dmat[2-4]",            type = "forbiddenbuiltin" },
    { pattern = "mat[2-4]x[2-4]",       type = "forbiddenbuiltin" },
    { pattern = "mat[2-4]",             type = "forbiddenbuiltin" },

    { pattern = "[%a_][%w_]*%f[(]",     type = "function" },
    { pattern = "[%a_][%w_]*",          type = "symbol"   },
  },
  symbols = {
    --https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-keywords
    --The symbols are added in the order they appear on this webpage, which is alphabetically
    ["AppendStructuredBuffer"]= "keyword",
    ["asm"]              = "keyword",
    ["asm_fragment"]     = "keyword",
    ["BlendState"]       = "keyword2",
    ["bool"]             = "keyword2",
    ["break"]            = "keyword",
    ["Buffer"]           = "keyword2",
    ["ByteAddressBuffer"]= "keyword2",
    ["case"]             = "keyword",
    ["cbuffer"]          = "keyword2",
    ["centroid"]         = "keyword2",
    ["class"]            = "keyword",
    ["column_major"]     = "keyword",
    ["compile"]          = "keyword",
    ["compile_fragment"] = "keyword",
    ["CompileShader"]    = "keyword",
    ["const"]            = "keyword",
    ["continue"]         = "keyword",
    ["ComputeShader"]    = "keyword",
    ["ConsumeStructuredBuffer"]= "keyword",
    ["default"]          = "keyword",
    ["DepthStencilState"]= "keyword",
    ["DepthStencilView"] = "keyword",
    ["discard"]          = "keyword",
    ["do"]               = "keyword",
    ["double"]           = "keyword2",
    ["DomainShader"]     = "keyword2",
    ["dword"]            = "keyword2",
    ["else"]             = "keyword",
    ["export"]           = "keyword",
    ["extern"]           = "keyword",
    ["false"]            = "literal",
    ["float"]            = "keyword2",
    ["for"]              = "keyword",
    ["fxgroup"]          = "keyword2",
    ["GeometryShader"]   = "keyword2",
    ["groupshared"]      = "keyword",
    ["half"]             = "keyword2",
    ["HullShader"]       = "keyword2",
    ["if"]               = "keyword",
    ["in"]               = "keyword",
    ["inline"]           = "keyword",
    ["inout"]            = "keyword",
    ["InputPatch"]       = "keyword2",
    ["int"]              = "keyword2",
    ["interface"]        = "keyword",
    ["line"]             = "keyword2",
    ["lineadj"]          = "keyword2",
    ["linear"]           = "keyword",
    ["LineStream"]       = "keyword2",
    ["matrix"]           = "keyword2",
    ["min16float"]       = "keyword2",
    ["min10float"]       = "keyword2",
    ["min16int"]         = "keyword2",
    ["min12int"]         = "keyword2",
    ["min16uint"]        = "keyword2",
    ["namespace"]        = "keyword",
    ["nointerpolation"]  = "keyword",
    ["noperspective"]    = "keyword",
    ["NULL"]             = "literal",
    ["out"]              = "keyword",
    ["OutputPatch"]      = "keyword2",
    ["packoffset"]       = "keyword",
    ["pass"]             = "keyword",
    ["pixelfragment"]    = "keyword",
    ["PixelShader"]      = "keyword2",
    ["point"]            = "keyword2",
    ["PointStream"]      = "keyword2",
    ["precise"]          = "keyword",
    ["RasterizerState"]  = "keyword2",
    ["RenderTargetView"] = "keyword2",
    ["return"]           = "keyword",
    ["register"]         = "keyword",
    ["row_major"]        = "keyword",
    ["RWBuffer"]         = "keyword2",
    ["RWByteAddressBuffer"]= "keyword2",
    ["RWStructuredBuffer"]= "keyword2",
    ["RWTexture1D"]      = "keyword2",
    ["RWTexture1DArray"] = "keyword2",
    ["RWTexture2D"]      = "keyword2",
    ["RWTexture2DArray"] = "keyword2",
    ["RWTexture3D"]      = "keyword2",
    ["sample"]           = "builtin",
    ["sampler"]          = "keyword2",
    ["SamplerState"]     = "keyword2",
    ["SamplerComparisonState"]= "keyword2",
    ["shared"]           = "keyword",
    ["snorm"]            = "keyword",
    ["stateblock"]       = "keyword",
    ["stateblock_state"] = "keyword",
    ["static"]           = "keyword",
    ["string"]           = "keyword2",
    ["struct"]           = "keyword",
    ["switch"]           = "keyword",
    ["StructuredBuffer"] = "keyword2",
    ["tbuffer"]          = "keyword2",
    ["technique"]        = "keyword2",
    ["technique10"]      = "keyword2",
    ["technique11"]      = "keyword2",
    ["texture"]          = "keyword2",
    ["Texture1D"]        = "keyword2",
    ["Texture1DArray"]   = "keyword2",
    ["Texture2D"]        = "keyword2",
    ["Texture2DArray"]   = "keyword2",
    ["Texture2DMS"]      = "keyword2",
    ["Texture2DMSArray"] = "keyword2",
    ["Texture3D"]        = "keyword2",
    ["TextureCube"]      = "keyword2",
    ["TextureCubeArray"] = "keyword2",
    ["true"]             = "literal",
    ["typedef"]          = "keyword",
    ["triangle"]         = "keyword2",
    ["triangleadj"]      = "keyword2",
    ["TriangleStream"]   = "keyword2",
    ["uint"]             = "keyword2",
    ["uniform"]          = "keyword",
    ["unorm"]            = "keyword",
    ["unsigned"]         = "keyword",
    ["vector"]           = "keyword2",
    ["vertexfragment"]   = "keyword2",
    ["VertexShader"]     = "keyword2",
    ["void"]             = "keyword",
    ["volatile"]         = "keyword",
    ["while"]            = "keyword",

    --https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-intrinsic-functions
    --The symbols are added in the order they appear on this webpage, which is alphabetically
    ["abort"]       = "builtin",
    ["abs"]         = "builtin",
    ["acos"]        = "builtin",
    ["all"]         = "builtin",
    ["any"]         = "builtin",
    ["asdouble"]    = "builtin",
    ["asfloat"]     = "builtin",
    ["asin"]        = "builtin",
    ["asint"]       = "builtin",
    ["asuint"]      = "builtin",
    ["atan"]        = "builtin",
    ["atan2"]       = "builtin",
    ["ceil"]        = "builtin",
    ["clamp"]       = "builtin",
    ["clip"]        = "builtin",
    ["cos"]         = "builtin",
    ["cosh"]        = "builtin",
    ["countbits"]   = "builtin",
    ["cross"]       = "builtin",
    ["ddx"]         = "builtin",
    ["ddx_coarse"]  = "builtin",
    ["ddx_fine"]    = "builtin",
    ["ddy"]         = "builtin",
    ["ddy_coarse"]  = "builtin",
    ["ddy_fine"]    = "builtin",
    ["degrees"]     = "builtin",
    ["determinant"] = "builtin",
    ["distance"]    = "builtin",
    ["dot"]         = "builtin",
    ["dst"]         = "builtin",
    ["errorf"]      = "builtin",
    ["exp"]         = "builtin",
    ["exp2"]        = "builtin",
    ["f16tof32"]    = "builtin",
    ["f32tof16"]    = "builtin",
    ["faceforward"] = "builtin",
    ["firstbithigh"]= "builtin",
    ["firstbitlow"] = "builtin",
    ["floor"]       = "builtin",
    ["fma"]         = "builtin",
    ["fmod"]        = "builtin",
    ["frac"]        = "builtin",
    ["frexp"]       = "builtin",
    ["fwidth"]      = "builtin",
    ["isfinite"]    = "builtin",
    ["isinf"]       = "builtin",
    ["isnan"]       = "builtin",
    ["ldexp"]       = "builtin",
    ["length"]      = "builtin",
    ["lerp"]        = "builtin",
    ["lit"]         = "builtin",
    ["log"]         = "builtin",
    ["log10"]       = "builtin",
    ["log2"]        = "builtin",
    ["mad"]         = "builtin",
    ["max"]         = "builtin",
    ["min"]         = "builtin",
    ["modf"]        = "builtin",
    ["msad4"]       = "builtin",
    ["mul"]         = "builtin",
    ["noise"]       = "builtin",
    ["normalize"]   = "builtin",
    ["pow"]         = "builtin",
    ["printf"]      = "builtin",
    ["radians"]     = "builtin",
    ["rcp"]         = "builtin",
    ["reflect"]     = "builtin",
    ["refract"]     = "builtin",
    ["reversebits"] = "builtin",
    ["round"]       = "builtin",
    ["rsqrt"]       = "builtin",
    ["saturate"]    = "builtin",
    ["sign"]        = "builtin",
    ["sin"]         = "builtin",
    ["sincos"]      = "builtin",
    ["sinh"]        = "builtin",
    ["smoothstep"]  = "builtin",
    ["sqrt"]        = "builtin",
    ["step"]        = "builtin",
    ["tan"]         = "builtin",
    ["tanh"]        = "builtin",
    ["transpose"]   = "builtin",
    ["trunc"]       = "builtin",

    --common symbols in GLSL that don't exist in HLSL
    ["mix"]        = "forbiddenbuiltin",
    ["fract"]      = "forbiddenbuiltin",
    ["inversesqrt"]= "forbiddenbuiltin",
    ["dFdx"]       = "forbiddenbuiltin",
    ["dFdy"]       = "forbiddenbuiltin",
    ["dFdxFine"]   = "forbiddenbuiltin",
    ["dFdyFine"]   = "forbiddenbuiltin",
    ["dFdxCoarse"] = "forbiddenbuiltin",
    ["dFdyCoarse"] = "forbiddenbuiltin",
  },
}