Skip to content

Commit

Permalink
Added support for HLSL (#2318)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Apr 29, 2020
1 parent d2541d5 commit 87a5c7a
Show file tree
Hide file tree
Showing 15 changed files with 1,022 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
"title": "HCL",
"owner": "outsideris"
},
"hlsl": {
"title": "HLSL",
"require": "c",
"owner": "RunDevelopment"
},
"http": {
"title": "HTTP",
"optional": [
Expand Down
20 changes: 20 additions & 0 deletions components/prism-hlsl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Prism.languages.hlsl = Prism.languages.extend('c', {

// Regarding keywords and class names:
// The list of all keywords was split into 'keyword' and 'class-name' tokens based on whether they are capitalized.
// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-keywords
// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-reserved-words
'class-name': [
Prism.languages.c['class-name'],
/\b(?:AppendStructuredBuffer|BlendState|Buffer|ByteAddressBuffer|CompileShader|ComputeShader|ConsumeStructuredBuffer|DepthStencilState|DepthStencilView|DomainShader|GeometryShader|Hullshader|InputPatch|LineStream|OutputPatch|PixelShader|PointStream|RasterizerState|RenderTargetView|RWBuffer|RWByteAddressBuffer|RWStructuredBuffer|RWTexture(?:1D|1DArray|2D|2DArray|3D)|SamplerComparisonState|SamplerState|StructuredBuffer|Texture(?:1D|1DArray|2D|2DArray|2DMS|2DMSArray|3D|Cube|CubeArray)|TriangleStream|VertexShader)\b/
],
'keyword': [
// HLSL keyword
/\b(?:asm|asm_fragment|auto|break|case|catch|cbuffer|centroid|char|class|column_major|compile|compile_fragment|const|const_cast|continue|default|delete|discard|do|dynamic_cast|else|enum|explicit|export|extern|for|friend|fxgroup|goto|groupshared|if|in|inline|inout|interface|line|lineadj|linear|long|matrix|mutable|namespace|new|nointerpolation|noperspective|operator|out|packoffset|pass|pixelfragment|point|precise|private|protected|public|register|reinterpret_cast|return|row_major|sample|sampler|shared|short|signed|sizeof|snorm|stateblock|stateblock_state|static|static_cast|string|struct|switch|tbuffer|technique|technique10|technique11|template|texture|this|throw|triangle|triangleadj|try|typedef|typename|uniform|union|unorm|unsigned|using|vector|vertexfragment|virtual|void|volatile|while)\b/,
// scalar, vector, and matrix types
/\b(?:bool|double|dword|float|half|int|min(?:10float|12int|16(?:float|int|uint))|uint)(?:[1-4](?:x[1-4])?)?\b/
],
// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-grammar#floating-point-numbers
'number': /(?:(?:\b\d+\.?\d*|\B\.\d+)(?:[eE][+-]?\d+)?|\b0x[\da-fA-F]+)[fFhHlLuU]?\b/,
'boolean': /\b(?:false|true)\b/
});
1 change: 1 addition & 0 deletions components/prism-hlsl.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions examples/prism-hlsl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h2>Full example</h2>
<pre><code>// Source: https://github.com/mellinoe/veldrid/blob/d60e5a036add2123a15f0da02f1da65a80503d54/src/Veldrid.ImGui/Assets/HLSL/imgui-frag.hlsl

struct PS_INPUT
{
float4 pos : SV_POSITION;
float4 col : COLOR0;
float2 uv : TEXCOORD0;
};

Texture2D FontTexture : register(t0);
sampler FontSampler : register(s0);

float4 FS(PS_INPUT input) : SV_Target
{
float4 out_col = input.col * FontTexture.Sample(FontSampler, input.uv);
return out_col;
}</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"haml": "ruby",
"handlebars": "markup-templating",
"haxe": "clike",
"hlsl": "c",
"java": "clike",
"javadoc": [
"markup",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"graphql": "GraphQL",
"hs": "Haskell",
"hcl": "HCL",
"hlsl": "HLSL",
"http": "HTTP",
"hpkp": "HTTP Public-Key-Pins",
"hsts": "HTTP Strict-Transport-Security",
Expand Down
Loading

0 comments on commit 87a5c7a

Please sign in to comment.