robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1" Converted from vim9script 2" Language: HLSL (High-Level Shader Language) 3" Maintainer: Maxim Kim <habamax@gmail.com> 4" Last Change: 2026 Aug 11 5" https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-reference 6 7if exists ( "b:current_syntax" ) 8finish 9endif 10 11let s: expanded_types = [ 12 \'float' , 'double' , 'int' , 'uint' , 'bool' , 13 \'min10float' , 'min16float' , 'min12int' , 'min16int' , 'min16uint' , 14 \'float16_t' , 'int16_t' , 'uint16_t' , 'uint64_t' , 'int64_t' , 15 \'vector' , 'matrix' 16 \] 17 18" float1, float2 ... 19" ... 20" int1x1, int1x2 ... 21exe $ "syn keyword hlslType {s: expanded_types ->join () }" 22for s: idxN in range ( 1 , 4 ) 23let s: typeN = s: expanded_types ->mapnew ({ _ , type ->type .. s: idxN }) ->join () 24exe $ "syn keyword hlslType {s: typeN }" 25for s: idxM in range ( 1 , 4 ) 26let s: typeNxM = s: expanded_types 27 \ ->mapnew ({ _ , type ->$ "{type}{s: idxN } x{s: idxM } "})->join() 28exe $ "syn keyword hlslType {s: typeNxM }" 29unlet s: typeNxM 30endfor 31unlet s: idxM 32unlet s: typeN 33endfor 34unlet s: idxN 35syn keyword hlslType void dword half string texture sampler 36syn keyword hlslType extern nointerpolation precise shared groupshared static 37syn keyword hlslType uniform export extern volatile const row_major column_major 38syn keyword hlslType struct linear centroid noperspective sample 39syn keyword hlslType typedef namespace class interface enum 40syn keyword hlslType snorm unorm 41syn keyword hlslType vertexfragment pixelfragment 42syn keyword hlslType point line lineadj triangle triangleadj 43syn keyword hlslType technique10 technique11 44syn keyword hlslType cbuffer tbuffer 45syn keyword hlslType Buffer StructuredBuffer AppendStructuredBuffer 46syn keyword hlslType ByteAddressBuffer ConsumeStructuredBuffer 47syn keyword hlslType Texture1D Texture2D Texture3D Texture1DArray Texture2DArray 48syn keyword hlslType Texture2DMS Texture2DMSArray 49syn keyword hlslType TextureCube TextureCubeArray 50syn keyword hlslType RWBuffer RWByteAddressBuffer RWStructuredBuffer 51syn keyword hlslType RWTexture1D RWTexture1DArray RWTexture2D 52syn keyword hlslType RWTexture2DArray RWTexture3D 53syn keyword hlslType PointStream LineStream TriangleStream 54syn keyword hlslType SamplerState SamplerComparisonState 55syn keyword hlslType RasterizerState DepthStencilState BlendState 56syn keyword hlslType OutputPatch InputPatch 57" TODO: only recognize it in function parameter list 58syn keyword hlslType in out inout 59 60" legacy 61syn keyword hlslType sampler2D 62 63syn keyword hlslCondition if else switch case default 64syn keyword hlslRepeat while for do break continue 65syn keyword hlslStatement return discard compile compile_fragment packoffset 66syn keyword hlslStatement pass register fxgroup 67syn keyword hlslConstant true false NULL 68 69" simplified Semantic highlighting: SV_POSITION, SV_TARGET etc 70syn match hlslSemantic /:\s * \zs\k\+ / 71 72" POSITIONT BINORMAL[n] BLENDINDICES[n] BLENDWEIGHT[n] COLOR[n] NORMAL[n] 73" POSITION[n] PSIZE[n] TANGENT[n] TEXCOORD[n] 74 75" SV_ClipDistance[n] SV_CullDistance[n] SV_Coverage SV_Depth 76" SV_DepthGreaterEqual SV_DepthLessEqual SV_DispatchThreadID SV_DomainLocation 77" SV_GroupID SV_GroupIndex SV_GroupThreadID SV_GSInstanceID SV_InnerCoverage 78" SV_InsideTessFactor SV_InstanceID SV_IsFrontFace SV_OutputControlPointID 79" SV_Position SV_PrimitiveID SV_RenderTargetArrayIndex SV_SampleIndex 80" SV_StencilRef SV_Target[n], where 0 <= n <= 7 SV_TessFactor SV_VertexID 81" SV_ViewportArrayIndex SV_ShadingRate 82 83syntax match hlslInteger "\v-?< [ 0-9 ] +%(_ [ 0-9 ] +) * [ uUlL ] ?> "display 84syntax match hlslFloat "\v-?< [ 0-9 ] +%(_ [ 0-9 ] +) * %(\. [ 0-9 ] +%(_ [ 0-9 ] +) * )%( [ eE ][ +- ] = [ 0-9 ] +%(_ [ 0-9 ] +) * )= [ hHfFlL ] ?> "display 85syntax match hlslHex "\v<0 [ xX ][ 0-9A-Fa-f ] +%(_ [ 0-9A-Fa-f ] +) * [ uUlL ] ?> "display 86syntax match hlslOct "\v<0 [ oO ][ 0-7 ] +%(_ [ 0-7 ] +) * [ uUlL ] ?> "display 87syntax cluster hlslNumber contains = hlslInteger , hlslFloat , hlslHex , hlslOct 88 89syntax region hlslChar start = +' +skip = +\\\\\|\\' +end = +' +contains = hlslEscape 90syntax region hlslString start = +" +skip = +\\\\\|\\' +end = +" +contains = hlslEscape 91syntax match hlslEscape display contained /\\\( [ abefnrtv\\'" ] \|\o\{3}\|x\x\{2}\|u\x\{4}\|U\x\{8}\) / 92 93" TODO: better preproc 94syn region hlslPreProc start = /^\s * \zs# /end = /$ /contains = @hlslNumber , hlslString , hlslChar , @hlslComment 95 96syntax match hlslTodo "TODO "contained 97syntax match hlslTodo "XXX "contained 98syntax match hlslTodo "FIXME "contained 99syntax region hlslLineComment start = /\/\/ /end = /$ /contains = @Spell , hlslTodo 100syntax region hlslBlockComment start = /\/\* /end = /\*\/ /contains = @Spell , hlslTodo 101syntax cluster hlslComment contains = hlslLineComment , hlslBlockComment 102 103hi def link hlslType Type 104hi def link hlslStatement Statement 105hi def link hlslCondition Statement 106hi def link hlslRepeat Statement 107hi def link hlslInteger Number 108hi def link hlslFloat Float 109hi def link hlslHex Number 110hi def link hlslOct Number 111hi def link hlslLineComment Comment 112hi def link hlslBlockComment Comment 113hi def link hlslTodo Todo 114hi def link hlslChar Character 115hi def link hlslString String 116hi def link hlslEscape Special 117hi def link hlslPreProc PreProc 118hi def link hlslSemantic Identifier 119 120let b: current_syntax = "hlsl"