Vim HLSL syntax highlighting

a guest Dec 27th, 2012 175 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. " Vim syntax file the High Level Shader Language
  2. " Language:     HLSL (DirectX 11)
  3. " Author:       Marc Costa <>
  4. " Date:         December 27, 2012
  5. " File Types:   .hlsl, .hlslc, .hlslh, .hlsl
  6. " Version:      0.1
  7. " Notes:        Adapted from hlsl.vim - Kevin Bjorke <>
  9. " For version 5.x: Clear all syntax items
  10. " For version 6.x: Quit when a syntax file was already loaded
  11. if version < 600
  12.  syntax clear
  13. elseif exists("b:current_syntax")
  14.  finish
  15. endif
  17. " Read the C syntax to start with
  18. if version < 600
  19.   so <sfile>:p:h/c.vim
  20. else
  21.   runtime! syntax/c.vim
  22.   unlet b:current_syntax
  23. endif
  25. " Annotations
  26. syn match           hlslAnnotation          /<.*;>/
  28. " Attributes
  29. syn match           hlslAttribute           /^\s*\[maxvertexcount(\d\+)\]/
  30. syn match           hlslAttribute           /^\s*\[domain("\(tri\|quad\|isoline\)")\]/
  31. syn match           hlslAttribute           /^\s*\[earlydepthstencil\]/
  32. syn match           hlslAttribute           /^\s*\[instance(\d\+)\]/
  33. syn match           hlslAttribute           /^\s*\[maxtessfactor(\d\+)\]/
  34. syn match           hlslAttribute           /^\s*\[numthreads(\s*\w\+\s*,\s*\w\+\s*,\s*\w\+\s*)\]/
  35. syn match           hlslAttribute           /^\s*\[outputcontrolpoints(\d\+)\]/
  36. syn match           hlslAttribute           /^\s*\[outputtopology("\(point\|line\|triangle_cw\|triangle_ccw\)")\]/
  37. syn match           hlslAttribute           /^\s*\[partitioning("\(integer\|fractional_even\|fractional_odd\|pow2\)")\]/
  38. syn match           hlslAttribute           /^\s*\[patchconstantfunc("[\d\w_]\+")\]/
  40. syn match           hlslAttribute           /^\s*\[numthreads\]/
  42. syn match           hlslAttribute           /^\s*\[\w*\((\d*)\)\=\]/ contains=hlslAttributes
  43. syn keyword         hlslAttributes          contained fastop loop unroll allow_uav_condition branch flatten forcecase call
  45. " Intrinsic functions
  46. syn keyword         hlslFunc                abs acos acosh asin asinh atan atanh cos cosh exp exp2 floor log log10 log2 round rsqrt sin sincos sinh sqrt tan tanh trunc
  47. syn keyword         hlslFunc                AllMemoryBarrier AllMemoryBarrierWithGroupSync DeviceMemoryBarrier DeviceMemoryBarrierWithGroupSync GroupMemoryBarrier GroupMemoryBarrierWithGroupSync
  48. syn keyword         hlslFunc                abort clip errorf printf
  49. syn keyword         hlslFunc                all any countbits faceforward firstbithigh firstbitlow isfinite isinf isnan max min noise pow reversebits sign
  50. syn keyword         hlslFunc                asdouble asfloat asint asuint D3DCOLORtoUBYTE4 f16tof32 f32tof16
  51. syn keyword         hlslFunc                ceil clamp degrees fma fmod frac frexp ldexp lerp mad modf radiants saturate smoothstep step
  52. syn keyword         hlslFunc                cross determinant distance dot dst length lit msad4 mul normalize rcp reflect refract transpose
  53. syn keyword         hlslFunc                ddx ddx_coarse ddx_fine ddy ddy_coarse ddy_fine fwidth
  54. syn keyword         hlslFunc                EvaluateAttributeAtCentroid EvaluateAttributeAtSample EvaluateAttributeSnapped
  55. syn keyword         hlslFunc                GetRenderTargetSampleCount GetRenderTargetSamplePosition
  56. syn keyword         hlslFunc                InterlockedAdd InterlockedAnd InterlockedCompareExchange InterlockedCompareStore InterlockedExchange InterlockedMax InterlockedMin InterlockedOr InterlockedXor
  57. syn keyword         hlslFunc                Process2DQuadTessFactorsAvg Process2DQuadTessFactorsMax Process2DQuadTessFactorsMin ProcessIsolineTessFactors
  58. syn keyword         hlslFunc                ProcessQuadTessFactorsAvg ProcessQuadTessFactorsMax ProcessQuadTessFactorsMin ProcessTriTessFactorsAvg ProcessTriTessFactorsMax ProcessTriTessFactorsMin
  59. syn keyword         hlslFunc                tex1D tex1Dbias tex1Dgrad tex1Dlod tex1Dproj
  60. syn keyword         hlslFunc                tex2D tex2Dbias tex2Dgrad tex2Dlod tex2Dproj
  61. syn keyword         hlslFunc                tex3D tex3Dbias tex3Dgrad tex3Dlod tex3Dproj
  62. syn keyword         hlslFunc                texCUBE texCUBEbias texCUBEgrad texCUBElod texCUBEproj
  64. syn keyword         hlslFunc                RestartStrip
  65. syn keyword         hlslFunc                CalculateLevelOfDetail CalculateLevelOfDetailUnclamped Gather GetDimensions GetSamplePosition Load Sample SampleBias SampleCmp SampleCmpLevelZero SampleGrad SampleLevel
  66. syn keyword         hlslFunc                Append Consume DecrementCounter IncrementCounter
  67. syn keyword         hlslFunc                Load2 Load3 Load4 Store Store2 Store3 Store4
  68. syn keyword         hlslFunc                GatherRed GatherGreen GatherBlue GatherAlpha GatherCmp GatherCmpRed GatherCmpGreen GatherCmpBlue GatherCmpAlpha
  69. syn match           hlslFunc                /\.mips\[\d\+\]\[\d\+\]/
  70. syn match           hlslFunc                /\.sample\[\d\+\]\[\d\+\]/
  72. " Layout Qualifiers
  73. syn keyword         hlslLayoutQual          const row_major column_major
  74. syn keyword         hlslLayoutQual          point line triangle lineadj triangleadj
  75. syn keyword         hlslLayoutQual          InputPatch OutputPatch
  76. syn match           hlslLayoutQual          /PointStream<\s*\w\+\s*>/
  77. syn match           hlslLayoutQual          /LineStream<\s*\w\+\s*>/
  78. syn match           hlslLayoutQual          /TriangleStream<\s*\w\+\s*>/
  80. " User defined Semantics
  81. syn match           hlslSemantic            /:\s*[A-Z]\w*/
  82. syn match           hlslSemantic            /:\s*packoffset(c\d\+\(\.[xyzw]\)\=)/ " packoffset
  83. syn match           hlslSemantic            /:\s*register(\(r\|x\|v\|t\|s\|cb\|icb\|b\|c\|u\)\d\+)/ " register
  84. "
  85. " System-Value Semantics
  86. " Vertex Shader
  87. syn match           hlslSemantic            /SV_ClipDistance\d\+/
  88. syn match           hlslSemantic            /SV_CullDistance\d\+/
  89. syn keyword         hlslSemantic            SV_Position SV_InstanceID SV_PrimitiveID SV_VertexID
  90. " Tessellation pipeline
  91. syn keyword         hlslSemantic            SV_DomainLocation SV_InsideTessFactor SV_OutputControlPointID SV_TessFactor
  92. " Geometry Shader
  93. syn keyword         hlslSemantic            SV_GSInstanceID SV_RenderTargetArrayIndex
  94. " Pixel Shader - MSAA
  95. syn keyword         hlslSemantic            SV_Coverage SV_Depth SV_IsFrontFace SV_SampleIndex
  96. syn match           hlslSemantic            /SV_Target[0-7]/
  97. " Compute Shader
  98. syn keyword         hlslSemantic            SV_DispatchThreadID SV_GroupID SV_GroupIndex SV_GroupThreadID
  100. " Shader profiles
  101. " Cg profiles
  102. syn keyword         hlslProfile             arbfp1 arbvp1 fp20 vp20 fp30 vp30 ps_1_1 ps_1_2 ps_1_3
  103. " Shader Model 1
  104. syn keyword         hlslProfile             vs_1_1
  105. " Shader Model 2
  106. syn keyword         hlslProfile             ps_2_0 ps_2_x vs_2_0 vs_2_x
  107. " Shader Model 3
  108. syn keyword         hlslProfile             ps_3_0 vs_3_0
  109. " Shader Model 4
  110. syn keyword         hlslProfile             gs_4_0 ps_4_0 vs_4_0 gs_4_1 ps_4_1 vs_4_1
  111. " Shader Model 5
  112. syn keyword         hlslProfile             cs_4_0 cs_4_1 cs_5_0 ds_5_0 gs_5_0 hs_5_0 ps_5_0 vs_5_0
  114. " Swizzling
  115. syn match           hlslSwizzle             /\.[xyzw]\{1,4\}\>/
  116. syn match           hlslSwizzle             /\.[rgba]\{1,4\}\>/
  117. syn match           hlslSwizzle             /\.\(_m[0-3]\{2}\)\{1,4\}/
  118. syn match           hlslSwizzle             /\.\(_[1-4]\{2}\)\{1,4\}/
  120. " Other Statements
  121. syn keyword         hlslStatement           discard
  123. " Storage class
  124. syn keyword         hlslStorageClass        in out inout
  125. syn keyword         hlslStorageClass        extern nointerpolation precise shared groupshared static uniform volatile
  126. syn keyword         hlslStorageClass        snorm unorm
  127. syn keyword         hlslStorageClass        linear centroid nointerpolation noperspective sample
  129. " Types
  130. " Buffer types
  131. syn match           hlslType                /AppendStructuredBuffer<\s*\w\+\s*>/
  132. syn match           hlslType                /Buffer<\s*\w\+\s*>/
  133. syn match           hlslType                /ByteAddressBuffer<\s*\w\+\s*>/
  134. syn match           hlslType                /ConsumeStructuredBuffer<\s*\w\+\s*>/
  135. syn match           hlslType                /RWBuffer<\s*\w\+\s*>/
  136. syn match           hlslType                /RWByteAddressBuffer<\s*\w\+\s*>/
  137. syn match           hlslType                /RWStructuredBuffer<\s*\w\+\s*>/
  138. syn match           hlslType                /StructuredBuffer<\s*\w\+\s*>/
  140. " Scalar types
  141. syn keyword         hlslType                bool int uint dword half float double
  142. syn keyword         hlslType                min16float min10float min16int min12int min16uint
  144. " Vector types
  145. syn match           hlslType                /vector<\s*\w\+,\s*[1-4]\s*>/
  146. syn keyword         hlslType                bool1 bool2 bool3 bool4
  147. syn keyword         hlslType                int1 int2 int3 int4
  148. syn keyword         hlslType                uint1 uint2 uint3 uint4
  149. syn keyword         hlslType                dword1 dword2 dword3 dword4
  150. syn keyword         hlslType                half1 half2 half3 half4
  151. syn keyword         hlslType                float1 float2 float3 float4
  152. syn keyword         hlslType                double1 double2 double3 double4
  153. syn keyword         hlslType                min16float1 min16float2 min16float3 min16float4
  154. syn keyword         hlslType                min10float1 min10float2 min10float3 min10float4
  155. syn keyword         hlslType                min16int1 min16int2 min16int3 min16int4
  156. syn keyword         hlslType                min12int1 min12int2 min12int3 min12int4
  157. syn keyword         hlslType                min16uint1 min16uint2 min16uint3 min16uint4
  159. " Matrix types
  160. syn match           hlslType                /matrix<\s*\w\+\s*,\s*[1-4]\s*,\s*[1-4]\s*>/
  161. syn keyword         hlslType                bool1x1 bool2x1 bool3x1 bool4x1 bool1x2 bool2x2 bool3x2 bool4x2 bool1x3 bool2x3 bool3x3 bool4x3 bool1x4 bool2x4 bool3x4 bool4x4
  162. syn keyword         hlslType                int1x1 int2x1 int3x1 int4x1 int1x2 int2x2 int3x2 int4x2 int1x3 int2x3 int3x3 int4x3 int1x4 int2x4 int3x4 int4x4
  163. syn keyword         hlslType                uint1x1 uint2x1 uint3x1 uint4x1 uint1x2 uint2x2 uint3x2 uint4x2 uint1x3 uint2x3 uint3x3 uint4x3 uint1x4 uint2x4 uint3x4 uint4x4
  164. syn keyword         hlslType                dword1x1 dword2x1 dword3x1 dword4x1 dword1x2 dword2x2 dword3x2 dword4x2 dword1x3 dword2x3 dword3x3 dword4x3 dword1x4 dword2x4 dword3x4 dword4x4
  165. syn keyword         hlslType                half1x1 half2x1 half3x1 half4x1 half1x2 half2x2 half3x2 half4x2 half1x3 half2x3 half3x3 half4x3 half1x4 half2x4 half3x4 half4x4
  166. syn keyword         hlslType                float1x1 float2x1 float3x1 float4x1 float1x2 float2x2 float3x2 float4x2 float1x3 float2x3 float3x3 float4x3 float1x4 float2x4 float3x4 float4x4
  167. syn keyword         hlslType                double1x1 double2x1 double3x1 double4x1 double1x2 double2x2 double3x2 double4x2 double1x3 double2x3 double3x3 double4x3 double1x4 double2x4 double3x4 double4x4
  168. syn keyword         hlslType                min16float1x1 min16float2x1 min16float3x1 min16float4x1 min16float1x2 min16float2x2 min16float3x2 min16float4x2 min16float1x3 min16float2x3 min16float3x3 min16float4x3 min16float1x4 min16float2x4 min16float3x4 min16float4x4
  169. syn keyword         hlslType                min10float1x1 min10float2x1 min10float3x1 min10float4x1 min10float1x2 min10float2x2 min10float3x2 min10float4x2 min10float1x3 min10float2x3 min10float3x3 min10float4x3 min10float1x4 min10float2x4 min10float3x4 min10float4x4
  170. syn keyword         hlslType                min16int1x1 min16int2x1 min16int3x1 min16int4x1 min16int1x2 min16int2x2 min16int3x2 min16int4x2 min16int1x3 min16int2x3 min16int3x3 min16int4x3 min16int1x4 min16int2x4 min16int3x4 min16int4x4
  171. syn keyword         hlslType                min12int1x1 min12int2x1 min12int3x1 min12int4x1 min12int1x2 min12int2x2 min12int3x2 min12int4x2 min12int1x3 min12int2x3 min12int3x3 min12int4x3 min12int1x4 min12int2x4 min12int3x4 min12int4x4
  172. syn keyword         hlslType                min16uint1x1 min16uint2x1 min16uint3x1 min16uint4x1 min16uint1x2 min16uint2x2 min16uint3x2 min16uint4x2 min16uint1x3 min16uint2x3 min16uint3x3 min16uint4x3 min16uint1x4 min16uint2x4 min16uint3x4 min16uint4x4
  174. " Sampler types
  175. syn keyword         hlslType                Sampler Sampler1D Sampler2D Sampler3D SamplerCUBE SamplerState SampleComparisonState
  177. " Texture types
  178. syn keyword         hlslType                Texture1D Texture2D Texture2DArray Texture2DMS Texture2DMSArray Texture3D TextureCube
  179. syn keyword         hlslType                RWTexture1D RWTexture2D RWTexture2DArray RWTexture3D
  180. syn keyword         hlslTypeDeprec          texture
  182. " State Groups args
  183. " Sampler state group
  184. syn keyword         hlslStateGroupArg       Filter AddressU AddressV AddressW MipLODBias MaxAnisotropy ComparisonFunc BorderColor MinLOD MaxLOD ComparisonFilter
  186. " Default highlighting
  187. if version >= 508 || !exists("did_hlsl_syntax_inits")
  188.   if version < 508
  189.     let did_hlsl_syntax_inits = 1
  190.     command -nargs=+ HiLink hi link <args>
  191.   else
  192.     command -nargs=+ HiLink hi def link <args>
  193.   endif
  194.   HiLink hlslProfile        hlslStatement
  195.   HiLink hlslStateGroupArg  hlslStatement
  196.   HiLink hlslStatement      Statement
  197.   HiLink hlslType           Type
  198.   HiLink hlslTypeDeprec     WarningMsg
  199.   HiLink hlslStorageClass   StorageClass
  200.   HiLink hlslSemantic       PreProc
  201.   HiLink hlslFunc           hlslStatement
  202.   HiLink hlslLayoutQual     hlslFunc
  203.   HiLink hlslAnnotation     PreProc
  204.   HiLink hlslSwizzle        SpecialChar
  205.   HiLink hlslAttribute      Statement
  206.   HiLink hlslAttributes     hlslAttribute
  207.   delcommand HiLink
  208. endif
  210. let b:current_syntax = "hlsl"
RAW Paste Data