lib_entries2.hlsl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // RUN: %dxc -T lib_6_3 -auto-binding-space 11 %s | FileCheck %s
  2. // Make sure entry function exist.
  3. // CHECK: @cs_main()
  4. // Make sure signatures are lowered.
  5. // CHECK: dx.op.threadId
  6. // CHECK: dx.op.groupId
  7. // Make sure entry function exist.
  8. // CHECK: @gs_main()
  9. // Make sure signatures are lowered.
  10. // CHECK: dx.op.loadInput
  11. // CHECK: dx.op.storeOutput
  12. // CHECK: dx.op.emitStream
  13. // CHECK: dx.op.cutStream
  14. // Make sure entry function exist.
  15. // CHECK: @ds_main()
  16. // Make sure signatures are lowered.
  17. // CHECK: dx.op.loadPatchConstant
  18. // CHECK: dx.op.domainLocation
  19. // CHECK: dx.op.loadInput
  20. // CHECK: dx.op.storeOutput
  21. // Make sure patch constant function exist.
  22. // CHECK: HSPerPatchFunc
  23. // Make sure signatures are lowered.
  24. // CHECK: dx.op.storePatchConstant
  25. // Make sure entry function exist.
  26. // CHECK: @hs_main()
  27. // Make sure signatures are lowered.
  28. // CHECK: dx.op.outputControlPointID
  29. // CHECK: dx.op.loadInput
  30. // CHECK: dx.op.storeOutput
  31. // Make sure entry function exist.
  32. // CHECK: @vs_main()
  33. // Make sure signatures are lowered.
  34. // CHECK: dx.op.loadInput
  35. // CHECK: dx.op.storeOutput
  36. // Make sure entry function exist.
  37. // CHECK: @ps_main()
  38. // Make sure signatures are lowered.
  39. // CHECK: dx.op.loadInput
  40. // CHECK: dx.op.storeOutput
  41. // Finish ps_main
  42. // CHECK: ret void
  43. // Make sure function entrys exist.
  44. // CHECK: !dx.entryPoints = !{{{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}}}
  45. // Make sure cs don't have signature.
  46. // CHECK: !"cs_main", null
  47. void StoreCSOutput(uint2 tid, uint2 gid);
  48. [shader("compute")]
  49. [numthreads(8,8,1)]
  50. void cs_main( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
  51. {
  52. StoreCSOutput(tid, gid);
  53. }
  54. // GS
  55. struct GSOut {
  56. float2 uv : TEXCOORD0;
  57. float4 pos : SV_Position;
  58. };
  59. // geometry shader that outputs 3 vertices from a point
  60. [shader("geometry")]
  61. [maxvertexcount(3)]
  62. [instance(24)]
  63. void gs_main(InputPatch<GSOut, 2>points, inout PointStream<GSOut> stream) {
  64. stream.Append(points[0]);
  65. stream.RestartStrip();
  66. }
  67. // DS
  68. struct PSSceneIn {
  69. float4 pos : SV_Position;
  70. float2 tex : TEXCOORD0;
  71. float3 norm : NORMAL;
  72. uint RTIndex : SV_RenderTargetArrayIndex;
  73. };
  74. struct HSPerVertexData {
  75. // This is just the original vertex verbatim. In many real life cases this would be a
  76. // control point instead
  77. PSSceneIn v;
  78. };
  79. struct HSPerPatchData {
  80. // We at least have to specify tess factors per patch
  81. // As we're tesselating triangles, there will be 4 tess factors
  82. // In real life case this might contain face normal, for example
  83. float edges[3] : SV_TessFactor;
  84. float inside : SV_InsideTessFactor;
  85. };
  86. // domain shader that actually outputs the triangle vertices
  87. [shader("domain")]
  88. [domain("tri")] PSSceneIn ds_main(const float3 bary
  89. : SV_DomainLocation,
  90. const OutputPatch<HSPerVertexData, 3> patch,
  91. const HSPerPatchData perPatchData) {
  92. PSSceneIn v;
  93. // Compute interpolated coordinates
  94. v.pos = patch[0].v.pos * bary.x + patch[1].v.pos * bary.y + patch[2].v.pos * bary.z + perPatchData.edges[1];
  95. v.tex = patch[0].v.tex * bary.x + patch[1].v.tex * bary.y + patch[2].v.tex * bary.z + perPatchData.edges[0];
  96. v.norm = patch[0].v.norm * bary.x + patch[1].v.norm * bary.y + patch[2].v.norm * bary.z + perPatchData.inside;
  97. v.RTIndex = 0;
  98. return v;
  99. }
  100. // HS
  101. HSPerPatchData HSPerPatchFunc( const InputPatch< PSSceneIn, 3 > points, OutputPatch<HSPerVertexData, 3> outp)
  102. {
  103. HSPerPatchData d;
  104. d.edges[ 0 ] = 1;
  105. d.edges[ 1 ] = 1;
  106. d.edges[ 2 ] = 1;
  107. d.inside = 1;
  108. return d;
  109. }
  110. // hull per-control point shader
  111. [shader("hull")]
  112. [domain("tri")]
  113. [partitioning("fractional_odd")]
  114. [outputtopology("triangle_cw")]
  115. [patchconstantfunc("HSPerPatchFunc")]
  116. [outputcontrolpoints(3)]
  117. HSPerVertexData hs_main( const uint id : SV_OutputControlPointID,
  118. const InputPatch< PSSceneIn, 3 > points)
  119. {
  120. HSPerVertexData v;
  121. // Just forward the vertex
  122. v.v = points[ id ];
  123. return v;
  124. }
  125. // VS
  126. struct VS_INPUT
  127. {
  128. float3 vPosition : POSITION;
  129. float3 vNormal : NORMAL;
  130. float2 vTexcoord : TEXCOORD0;
  131. };
  132. struct VS_OUTPUT
  133. {
  134. float3 vNormal : NORMAL;
  135. float2 vTexcoord : TEXCOORD0;
  136. float4 vPosition : SV_POSITION;
  137. };
  138. [shader("vertex")]
  139. VS_OUTPUT vs_main(VS_INPUT Input)
  140. {
  141. VS_OUTPUT Output;
  142. Output.vPosition = float4( Input.vPosition, 1.0 );
  143. Output.vNormal = Input.vNormal;
  144. Output.vTexcoord = Input.vTexcoord;
  145. return Output;
  146. }
  147. // PS
  148. [shader("pixel")]
  149. float4 ps_main(float4 a : A) : SV_TARGET
  150. {
  151. return a;
  152. }