PatchLength1.hlsl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // RUN: %dxc -E main -T hs_6_0 %s | FileCheck %s
  2. // CHECK: @dx.op.storePatchConstant.f32(i32 106, i32 0, i32 2, i8 0, float 3.000000e+00)
  3. // CHECK: @dx.op.storePatchConstant.f32(i32 106, i32 1, i32 0, i8 0, float 3.000000e+00)
  4. //--------------------------------------------------------------------------------------
  5. // SimpleTessellation.hlsl
  6. //
  7. // Advanced Technology Group (ATG)
  8. // Copyright (C) Microsoft Corporation. All rights reserved.
  9. //--------------------------------------------------------------------------------------
  10. struct VSSceneIn
  11. {
  12. float3 pos : POSITION;
  13. float3 norm : NORMAL;
  14. float2 tex : TEXCOORD0;
  15. };
  16. struct PSSceneIn
  17. {
  18. float4 pos : SV_Position;
  19. float2 tex : TEXCOORD0;
  20. float3 norm : NORMAL;
  21. uint RTIndex : SV_RenderTargetArrayIndex;
  22. };
  23. cbuffer cb0
  24. {
  25. float4x4 g_mWorldViewProj;
  26. };
  27. Texture2D g_txDiffuse : register( t0 );
  28. SamplerState g_sampler : register( s0 );
  29. //////////////////////////////////////////////////////////////////////////////////////////
  30. // Regular VS/PS rendering
  31. PSSceneIn VSSceneMain( VSSceneIn input )
  32. {
  33. PSSceneIn output;
  34. output.pos = mul( float4( input.pos, 1.0 ), g_mWorldViewProj );
  35. output.tex = input.tex;
  36. output.norm = input.norm;
  37. return output;
  38. }
  39. float4 PSSceneMain( PSSceneIn input ) : SV_Target
  40. {
  41. return g_txDiffuse.Sample( g_sampler, input.tex );
  42. }
  43. //////////////////////////////////////////////////////////////////////////////////////////
  44. // Simple forwarding Tessellation shaders
  45. struct HSPerVertexData
  46. {
  47. // This is just the original vertex verbatim. In many real life cases this would be a
  48. // control point instead
  49. PSSceneIn v;
  50. };
  51. struct HSPerPatchData
  52. {
  53. // We at least have to specify tess factors per patch
  54. // As we're tesselating triangles, there will be 4 tess factors
  55. // In real life case this might contain face normal, for example
  56. float edges[ 3 ] : SV_TessFactor;
  57. float inside : SV_InsideTessFactor;
  58. };
  59. float4 HSPerPatchFunc()
  60. {
  61. return 1.8;
  62. }
  63. HSPerPatchData HSPerPatchFunc( const InputPatch< PSSceneIn, 3 > points, OutputPatch< HSPerVertexData, 3 > opoints )
  64. {
  65. HSPerPatchData d;
  66. d.edges[ 0 ] = points[0].tex.x;
  67. d.edges[ 1 ] = opoints[1].v.tex.y;
  68. d.edges[ 2 ] = points.Length;
  69. d.inside = opoints.Length;
  70. return d;
  71. }
  72. // hull per-control point shader
  73. [domain("tri")]
  74. [partitioning("fractional_odd")]
  75. [outputtopology("triangle_cw")]
  76. [patchconstantfunc("HSPerPatchFunc")]
  77. [outputcontrolpoints(3)]
  78. HSPerVertexData main( const uint id : SV_OutputControlPointID,
  79. const InputPatch< PSSceneIn, 3 > points )
  80. {
  81. HSPerVertexData v;
  82. // Just forward the vertex
  83. v.v = points[ id ];
  84. return v;
  85. }