hlsl-semantics.azsl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Reference: https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/dx-graphics-hlsl-semantics
  2. // All examples target DX12 and Shader model 6 or above
  3. struct VS_OUTPUT
  4. {
  5. float4 Position : SV_POSITION;
  6. float4 Diffuse : COLOR0;
  7. float2 TextureUV : TEXCOORD0;
  8. };
  9. VS_OUTPUT ValidVS1( float4 vPos : POSITION,
  10. float3 vNormal : NORMAL,
  11. float2 vTexCoord0 : TEXCOORD)
  12. {
  13. VS_OUTPUT Output;
  14. return Output;
  15. }
  16. struct VS_INPUT
  17. {
  18. float4 vPos : POSITION;
  19. float3 vNormal : NORMAL;
  20. float2 vTexCoord0 : TEXCOORD;
  21. };
  22. VS_OUTPUT ValidVS2(VS_INPUT input)
  23. {
  24. VS_OUTPUT Output;
  25. return Output;
  26. }
  27. struct PSSceneIn{float2 uv : TEXCOORD ; float4 color : COLOR;};
  28. uniform Texture2D g_txDiffuse;
  29. sampler g_samLinear;
  30. float4 PSPointSprite(PSSceneIn input) : SV_Target
  31. {
  32. return g_txDiffuse.Sample( g_samLinear, input.uv ) * input.color;
  33. }
  34. // Invalid examples
  35. // These examples are only invalid when compiled with dxc for Shader Model 6 and later
  36. // Other compilers (fxc, Shader Model 5 or earlier) can compile some of them, but we keep
  37. // them here to illustrate the differences in the supported grammar.
  38. // AZSLc will not error here, because the syntax is still valid
  39. // Expected DXC error: Semantic must be defined for all parameters of an entry function or patch constant function
  40. VS_OUTPUT InvalidVS1( float4 vPos : POSITION,
  41. uniform int nNumLights )
  42. {
  43. VS_OUTPUT Output;
  44. return Output;
  45. }
  46. // Double Binding Semantics are not supported in SM6.0
  47. // Expected DXC error: Parameter with semantic SV_POSITION has overlapping semantic index at 0
  48. float4x4 WorldView[60] : WORLDVIEW : register(c16);
  49. float4 InvalidVS2( float3 Pos : SV_POSITION, int4 IPos : SV_POSITION ) : SV_POSITION
  50. {
  51. float3 P = mul(float4(Pos, 1), (float4x3)WorldView[IPos.w]);
  52. return float4(P,1);
  53. }
  54. // Expected DXC error: invalid semantic 'COLOR' for ps 6.0
  55. float4 InvalidPS1( float4 screenSpace : SV_Position ) : COLOR
  56. {
  57. }