Skip to content

Commit 482e46f

Browse files
Add the hlsl shader grammar file from highlight-js library (#258)
1 parent 16d7cd8 commit 482e46f

File tree

2 files changed

+122
-1
lines changed

2 files changed

+122
-1
lines changed

templates/monogame/public/hlsl.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
Language: HLSL
3+
Description: High-level shader language
4+
Author: Stef Levesque
5+
Website: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl
6+
Category: graphics
7+
8+
From: https://github.com/highlightjs/highlightjs-hlsl/blob/master/src/languages/hlsl.js
9+
License: MIT https://github.com/highlightjs/highlightjs-hlsl/blob/master/LICENSE
10+
*/
11+
12+
const HLSL_NUMBER_RE = '(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?([hHfFlL]?)|\\.\\d+)([eE][-+]?\\d+)?([hHfFlL]?))';
13+
14+
const HLSL_NUMBER_MODE = {
15+
className: 'number',
16+
begin: HLSL_NUMBER_RE,
17+
relevance: 0
18+
};
19+
20+
export default function(hljs) {
21+
let matrixBases =
22+
'bool double float half int uint ' +
23+
'min16float min10float min16int min12int min16uint';
24+
25+
let matrixSuffixes = [
26+
'',
27+
'1', '2', '3', '4',
28+
'1x1', '1x2', '1x3', '1x4',
29+
'2x1', '2x2', '2x3', '2x4',
30+
'3x1', '3x2', '3x3', '3x4',
31+
'4x1', '4x2', '4x3', '4x4'
32+
];
33+
34+
let matrixTypes = [];
35+
for (let base of matrixBases.split(' ')) {
36+
for (let suffix of matrixSuffixes) {
37+
matrixTypes.push(base + suffix);
38+
}
39+
}
40+
41+
let semanticsSV =
42+
'SV_Coverage SV_Depth SV_DispatchThreadID SV_DomainLocation ' +
43+
'SV_GroupID SV_GroupIndex SV_GroupThreadID SV_GSInstanceID SV_InnerCoverage SV_InsideTessFactor ' +
44+
'SV_InstanceID SV_IsFrontFace SV_OutputControlPointID SV_Position SV_PrimitiveID ' +
45+
'SV_RenderTargetArrayIndex SV_SampleIndex SV_StencilRef SV_TessFactor SV_VertexID ' +
46+
'SV_ViewportArrayIndex, SV_ShadingRate';
47+
48+
let semanticsNum =
49+
'BINORMAL BLENDINDICES BLENDWEIGHT COLOR NORMAL POSITION PSIZE TANGENT TEXCOORD TESSFACTOR DEPTH ' +
50+
'SV_ClipDistance SV_CullDistance SV_DepthGreaterEqual SV_DepthLessEqual SV_Target ' +
51+
'SV_CLIPDISTANCE SV_CULLDISTANCE SV_DEPTHGREATEREQUAL SV_DEPTHLESSEQUAL SV_TARGET';
52+
53+
let semanticsTypes = semanticsNum.split(' ');
54+
for (let s of semanticsNum.split(' ')) {
55+
for (let n of Array(16).keys()) {
56+
semanticsTypes.push(s + n.toString());
57+
}
58+
}
59+
60+
return {
61+
name: 'HLSL',
62+
keywords: {
63+
keyword:
64+
'AppendStructuredBuffer asm asm_fragment BlendState break Buffer ByteAddressBuffer case ' +
65+
'cbuffer centroid class column_major compile compile_fragment CompileShader const continue ' +
66+
'ComputeShader ConsumeStructuredBuffer default DepthStencilState DepthStencilView discard do ' +
67+
'DomainShader dword else export extern false for fxgroup GeometryShader groupshared ' +
68+
'Hullshader if in inline inout InputPatch interface line lineadj linear LineStream ' +
69+
'matrix namespace nointerpolation noperspective ' +
70+
'NULL out OutputPatch packoffset pass pixelfragment PixelShader point PointStream precise ' +
71+
'RasterizerState RenderTargetView return register row_major RWBuffer RWByteAddressBuffer ' +
72+
'RWStructuredBuffer RWTexture1D RWTexture1DArray RWTexture2D RWTexture2DArray RWTexture3D sample ' +
73+
'sampler SamplerState SamplerComparisonState shared snorm stateblock stateblock_state static string ' +
74+
'struct switch StructuredBuffer tbuffer technique technique10 technique11 texture Texture1D ' +
75+
'Texture1DArray Texture2D Texture2DArray Texture2DMS Texture2DMSArray Texture3D TextureCube ' +
76+
'TextureCubeArray true typedef triangle triangleadj TriangleStream uint uniform unorm unsigned ' +
77+
'vector vertexfragment VertexShader void volatile while',
78+
type:
79+
matrixTypes.join(' ') + ' ' +
80+
'Buffer vector matrix sampler SamplerState PixelShader VertexShader ' +
81+
'texture Texture1D Texture1DArray Texture2D Texture2DArray Texture2DMS Texture2DMSArray Texture3D ' +
82+
'TextureCube TextureCubeArray struct typedef',
83+
built_in:
84+
'POSITIONT FOG PSIZE VFACE VPOS ' +
85+
semanticsTypes.join(' ') + ' ' +
86+
semanticsSV + ' ' +
87+
semanticsSV.toUpperCase() + ' ' +
88+
'abort abs acos all AllMemoryBarrier AllMemoryBarrierWithGroupSync any asdouble asfloat asin asint asuint ' +
89+
'atan atan2 ceil CheckAccessFullyMapped clamp clip cos cosh countbits cross D3DCOLORtoUBYTE4 ddx ddx_coarse ' +
90+
'ddx_fine ddy ddy_coarse ddy_fine degrees determinant DeviceMemoryBarrier DeviceMemoryBarrierWithGroupSync ' +
91+
'distance dot dst errorf EvaluateAttributeAtCentroid EvaluateAttributeAtSample EvaluateAttributeSnapped ' +
92+
'exp exp2 f16tof32 f32tof16 faceforward firstbithigh firstbitlow floor fma fmod frac frexp fwidth ' +
93+
'GetRenderTargetSampleCount GetRenderTargetSamplePosition GroupMemoryBarrier GroupMemoryBarrierWithGroupSync ' +
94+
'InterlockedAdd InterlockedAnd InterlockedCompareExchange InterlockedCompareStore InterlockedExchange ' +
95+
'InterlockedMax InterlockedMin InterlockedOr InterlockedXor isfinite isinf isnan ldexp length lerp lit log ' +
96+
'log10 log2 mad max min modf msad4 mul noise normalize pow printf Process2DQuadTessFactorsAvg ' +
97+
'Process2DQuadTessFactorsMax Process2DQuadTessFactorsMin ProcessIsolineTessFactors ProcessQuadTessFactorsAvg ' +
98+
'ProcessQuadTessFactorsMax ProcessQuadTessFactorsMin ProcessTriTessFactorsAvg ProcessTriTessFactorsMax ' +
99+
'ProcessTriTessFactorsMin radians rcp reflect refract reversebits round rsqrt saturate sign sin sincos sinh ' +
100+
'smoothstep sqrt step tan tanh tex1D tex1Dbias tex1Dgrad tex1Dlod tex1Dproj tex2D tex2Dbias tex2Dgrad ' +
101+
'tex2Dlod tex2Dproj tex3D tex3Dbias tex3Dgrad tex3Dlod tex3Dproj texCUBE texCUBEbias texCUBEgrad texCUBElod ' +
102+
'texCUBEproj transpose trunc',
103+
literal: 'true false'
104+
},
105+
illegal: '"',
106+
contains: [
107+
hljs.C_LINE_COMMENT_MODE,
108+
hljs.C_BLOCK_COMMENT_MODE,
109+
HLSL_NUMBER_MODE,
110+
{
111+
className: 'meta',
112+
begin: '#', end: '$'
113+
}
114+
]
115+
};
116+
}

templates/monogame/public/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import hlslLanguage from './hlsl.js';
2+
13
export default {
2-
defaultTheme: 'dark'
4+
defaultTheme: 'dark',
5+
configureHljs: (hljs) => {
6+
hljs.registerLanguage('hlsl', hlslLanguage);
7+
}
38
}

0 commit comments

Comments
 (0)