tess-fixed-input-array-builtin-array.invalid.asm.tesc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma clang diagnostic ignored "-Wmissing-prototypes"
  2. #include <metal_stdlib>
  3. #include <simd/simd.h>
  4. using namespace metal;
  5. struct VertexOutput
  6. {
  7. float4 pos;
  8. float2 uv;
  9. };
  10. struct HSOut
  11. {
  12. float4 pos;
  13. float2 uv;
  14. };
  15. struct HSConstantOut
  16. {
  17. float EdgeTess[3];
  18. float InsideTess;
  19. };
  20. struct VertexOutput_1
  21. {
  22. float2 uv;
  23. };
  24. struct HSOut_1
  25. {
  26. float2 uv;
  27. };
  28. struct main0_out
  29. {
  30. HSOut_1 _entryPointOutput;
  31. float4 gl_Position;
  32. };
  33. struct main0_in
  34. {
  35. float2 VertexOutput_uv [[attribute(0)]];
  36. float4 gl_Position [[attribute(1)]];
  37. };
  38. // Implementation of an array copy function to cover GLSL's ability to copy an array via assignment.
  39. template<typename T, uint N>
  40. void spvArrayCopyFromStack1(thread T (&dst)[N], thread const T (&src)[N])
  41. {
  42. for (uint i = 0; i < N; dst[i] = src[i], i++);
  43. }
  44. template<typename T, uint N>
  45. void spvArrayCopyFromConstant1(thread T (&dst)[N], constant T (&src)[N])
  46. {
  47. for (uint i = 0; i < N; dst[i] = src[i], i++);
  48. }
  49. HSOut _hs_main(thread const VertexOutput (&p)[3], thread const uint& i)
  50. {
  51. HSOut _output;
  52. _output.pos = p[i].pos;
  53. _output.uv = p[i].uv;
  54. return _output;
  55. }
  56. HSConstantOut PatchHS(thread const VertexOutput (&_patch)[3])
  57. {
  58. HSConstantOut _output;
  59. _output.EdgeTess[0] = (float2(1.0) + _patch[0].uv).x;
  60. _output.EdgeTess[1] = (float2(1.0) + _patch[0].uv).x;
  61. _output.EdgeTess[2] = (float2(1.0) + _patch[0].uv).x;
  62. _output.InsideTess = (float2(1.0) + _patch[0].uv).x;
  63. return _output;
  64. }
  65. kernel void main0(main0_in in [[stage_in]], uint gl_InvocationID [[thread_index_in_threadgroup]], uint gl_PrimitiveID [[threadgroup_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLTriangleTessellationFactorsHalf* spvTessLevel [[buffer(26)]], threadgroup main0_in* gl_in [[threadgroup(0)]])
  66. {
  67. device main0_out* gl_out = &spvOut[gl_PrimitiveID * 3];
  68. if (gl_InvocationID < spvIndirectParams[0])
  69. gl_in[gl_InvocationID] = in;
  70. threadgroup_barrier(mem_flags::mem_threadgroup);
  71. if (gl_InvocationID >= 3)
  72. return;
  73. VertexOutput p[3];
  74. p[0].pos = gl_in[0].gl_Position;
  75. p[0].uv = gl_in[0].VertexOutput_uv;
  76. p[1].pos = gl_in[1].gl_Position;
  77. p[1].uv = gl_in[1].VertexOutput_uv;
  78. p[2].pos = gl_in[2].gl_Position;
  79. p[2].uv = gl_in[2].VertexOutput_uv;
  80. uint i = gl_InvocationID;
  81. VertexOutput param[3];
  82. spvArrayCopyFromStack1(param, p);
  83. uint param_1 = i;
  84. HSOut flattenTemp = _hs_main(param, param_1);
  85. gl_out[gl_InvocationID].gl_Position = flattenTemp.pos;
  86. gl_out[gl_InvocationID]._entryPointOutput.uv = flattenTemp.uv;
  87. threadgroup_barrier(mem_flags::mem_device);
  88. if (int(gl_InvocationID) == 0)
  89. {
  90. VertexOutput param_2[3];
  91. spvArrayCopyFromStack1(param_2, p);
  92. HSConstantOut _patchConstantResult = PatchHS(param_2);
  93. spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[0] = half(_patchConstantResult.EdgeTess[0]);
  94. spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[1] = half(_patchConstantResult.EdgeTess[1]);
  95. spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[2] = half(_patchConstantResult.EdgeTess[2]);
  96. spvTessLevel[gl_PrimitiveID].insideTessellationFactor = half(_patchConstantResult.InsideTess);
  97. }
  98. }