SimpleGS2.hlsl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // RUN: %dxc -E main -T gs_6_0 %s | FileCheck %s
  2. // CHECKNOT: SV_RenderTargetArrayIndex or SV_ViewportArrayIndex from any shader feeding rasterizer
  3. // CHECK: gsInstanceID
  4. // CHECK: emitStream
  5. // CHECK: emitStream
  6. // CHECK: emitStream
  7. // CHECK: cutStream
  8. // CHECK: i32 24}
  9. struct VSOut {
  10. float2 uv : TEXCOORD0;
  11. float4 clr : COLOR;
  12. float4 pos : SV_Position;
  13. uint index : SV_ViewportArrayIndex;
  14. };
  15. struct VSOutGSIn {
  16. float3 posSize : POSSIZE;
  17. float4 clr : COLOR;
  18. };
  19. struct VSOutGSArrayIn {
  20. float3 posSize : POSSIZE;
  21. float2 clr[2] : COLOR;
  22. };
  23. struct VSOutGSMatIn {
  24. float3 posSize : POSSIZE;
  25. float2x2 clr[2] : COLOR;
  26. };
  27. cbuffer b : register(b0) {
  28. float2 invViewportSize;
  29. };
  30. float4 NDC(float2 screen) {
  31. screen *= invViewportSize * 2;
  32. screen.x = screen.x - 1;
  33. screen.y = 1 - screen.y;
  34. return float4(screen, 0.5f, 1);
  35. }
  36. // geometry shader that outputs 3 vertices from a point
  37. [maxvertexcount(3)]
  38. [instance(24)]
  39. void main(point VSOutGSIn points[1], inout TriangleStream<VSOut> stream, uint InstanceID : SV_GSInstanceID) {
  40. VSOut v;
  41. const float2 verts[3] =
  42. {
  43. float2(-0.5f, -0.5f),
  44. float2(1.5f, -0.5f),
  45. float2(-0.5f, 1.5f)};
  46. const float sz = points[0].posSize.z;
  47. const float2 org = points[0].posSize.xy;
  48. const float4 clr = float4(points[0].clr); //[0][1], points[ 0 ].clr[1][0]);
  49. // triangle strip for the particle
  50. v.uv = float2(0, 0);
  51. v.clr = clr;
  52. v.pos = NDC(org + verts[InstanceID%3] * sz);
  53. v.index = 2;
  54. stream.Append(v);
  55. v.uv = float2(2, 0);
  56. v.clr = clr;
  57. v.pos = NDC(org + verts[(InstanceID%3) + 1] * sz);
  58. v.index = 2;
  59. stream.Append(v);
  60. v.uv = float2(0, 2);
  61. v.clr = clr;
  62. v.pos = NDC(org + verts[(InstanceID % 3) + 2] * sz);
  63. v.index = 2;
  64. stream.Append(v);
  65. stream.RestartStrip();
  66. }