system-values.hlsl 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. // For use with unit test SystemValueTest.
  2. // Allows for combinations of system values and arbitrary values to be declared
  3. // and used in any signature point and any shader stage just by setting define(s).
  4. // Example:
  5. // fxc system-values.hlsl /E HSMain /T hs_5_1 "/DHSCPIn_Defs=Def_ClipDistance Def_Arb(float,arb,ARB)"
  6. #define GLUE(a,b) a##b
  7. #define Def_Arb_NoSem(t,v) DECLARE(t v) USE(t,v)
  8. #define Def_Arb(t,v,s) DECLARE(t v : s) USE(t,v)
  9. #define Def_ArbAttr(a,t,v,s) DECLARE(a t v : s) USE(t,v)
  10. #define Def_Arb4(t,v,s) DECLARE(GLUE(t,4) v : s) USE(t,v.x) USE(t,v.y) USE(t,v.z) USE(t,v.w)
  11. #define Def_ArbArray2(t,v,s) DECLARE(t v[2] : s) USE(t,v[0]) USE(t,v[1])
  12. #define Def_ArbArray4(t,v,s) DECLARE(t v[4] : s) USE(t,v[0]) USE(t,v[1]) USE(t,v[2]) USE(t,v[3])
  13. #define Def_VertexID DECLARE(uint vid : SV_VertexID) USE(uint, vid)
  14. #define Def_InstanceID DECLARE(uint iid : SV_InstanceID) USE(uint, iid)
  15. #define Def_Position DECLARE(float4 pos : SV_Position) USE(float, pos.x) USE(float, pos.y) USE(float, pos.z) USE(float, pos.w)
  16. #define Def_Coverage DECLARE(uint cov : SV_Coverage) USE(uint, cov)
  17. #define Def_InnerCoverage DECLARE(uint icov : SV_InnerCoverage) USE(uint, icov)
  18. #define Def_PrimitiveID DECLARE(uint pid : SV_PrimitiveID) USE(uint, pid)
  19. #define Def_SampleIndex DECLARE(uint samp : SV_SampleIndex) USE(uint, samp)
  20. #define Def_IsFrontFace DECLARE(bool bff : SV_IsFrontFace) USE(bool, bff)
  21. #define Def_RenderTargetArrayIndex DECLARE(uint rtai : SV_RenderTargetArrayIndex) USE(uint, rtai)
  22. #define Def_ViewportArrayIndex DECLARE(uint vpai : SV_ViewportArrayIndex) USE(uint, vpai)
  23. #define Def_ClipDistance DECLARE(float clipdist : SV_ClipDistance) USE(float, clipdist)
  24. #define Def_CullDistance DECLARE(float culldist : SV_CullDistance) USE(float, culldist)
  25. #define Def_Target DECLARE(float4 target : SV_Target) USE(float, target.x) USE(float, target.y) USE(float, target.z) USE(float, target.w)
  26. #define Def_Depth DECLARE(float depth : SV_Depth) USE(float, depth)
  27. #define Def_DepthLessEqual DECLARE(float depthle : SV_DepthLessEqual) USE(float, depthle)
  28. #define Def_DepthGreaterEqual DECLARE(float depthge : SV_DepthGreaterEqual) USE(float, depthge)
  29. #define Def_StencilRef DECLARE(uint stencilref : SV_StencilRef) USE(uint, stencilref)
  30. #define Def_DispatchThreadID DECLARE(uint3 dtid : SV_DispatchThreadID) USE(uint, dtid.x) USE(uint, dtid.y) USE(uint, dtid.z)
  31. #define Def_GroupID DECLARE(uint3 gid : SV_GroupID) USE(uint, gid.x) USE(uint, gid.y) USE(uint, gid.z)
  32. #define Def_GroupIndex DECLARE(uint gindex : SV_GroupIndex) USE(uint, gindex)
  33. #define Def_GroupThreadID DECLARE(uint3 gtid : SV_GroupThreadID) USE(uint, gtid.x) USE(uint, gtid.y) USE(uint, gtid.z)
  34. #define Def_DomainLocation DECLARE(float2 domainloc : SV_DomainLocation) USE(float, domainloc.x) USE(float, domainloc.y)
  35. #define Def_OutputControlPointID DECLARE(uint ocpid : SV_OutputControlPointID) USE(uint, ocpid)
  36. #define Def_GSInstanceID DECLARE(uint gsiid : SV_GSInstanceID) USE(uint, gsiid)
  37. #define Def_ViewID DECLARE(uint viewID : SV_ViewID) USE(uint, viewID)
  38. #define Def_Barycentrics DECLARE(float3 BaryWeights : SV_Barycentrics) USE(float, BaryWeights.x) USE(float, BaryWeights.y) USE(float, BaryWeights.z)
  39. #define Def_ShadingRate DECLARE(uint rate : SV_ShadingRate) USE(uint, rate)
  40. #define Domain_Quad 0
  41. #define Domain_Tri 1
  42. #define Domain_Isoline 2
  43. #ifndef DOMAIN
  44. #define DOMAIN Domain_Quad
  45. #endif
  46. #if DOMAIN == Domain_Quad
  47. #define Attribute_Domain [domain("quad")]
  48. #define Def_TessFactor DECLARE(float tfactor[4] : SV_TessFactor) USE(float, tfactor[0]) USE(float, tfactor[1]) USE(float, tfactor[2]) USE(float, tfactor[3])
  49. #define Def_InsideTessFactor DECLARE(float itfactor[2] : SV_InsideTessFactor) USE(float, itfactor[0]) USE(float, itfactor[1])
  50. #endif
  51. #if DOMAIN == Domain_Tri
  52. #define Attribute_Domain [domain("tri")]
  53. #define Def_TessFactor DECLARE(float tfactor[3] : SV_TessFactor) USE(float, tfactor[0]) USE(float, tfactor[1]) USE(float, tfactor[2])
  54. #define Def_InsideTessFactor DECLARE(float itfactor : SV_InsideTessFactor) USE(float, itfactor[0])
  55. #endif
  56. #if DOMAIN == Domain_Isoline
  57. #define Attribute_Domain [domain("isoline")]
  58. #define Def_TessFactor DECLARE(float tfactor[2] : SV_TessFactor) USE(float, tfactor[0]) USE(float, tfactor[1])
  59. #define Def_InsideTessFactor DECLARE(float itfactor : SV_InsideTessFactor) USE(float, itfactor)
  60. #endif
  61. #define DECLARE(decl) decl;
  62. #define USE(t,v)
  63. struct VSIn
  64. {
  65. #ifdef VSIn_Defs
  66. VSIn_Defs
  67. #endif
  68. };
  69. struct VSOut
  70. {
  71. float _Arb0 : _Arb0;
  72. #ifdef VSOut_Defs
  73. VSOut_Defs
  74. #endif
  75. };
  76. struct PCIn
  77. {
  78. #ifdef PCIn_Defs
  79. PCIn_Defs
  80. #endif
  81. };
  82. struct HSIn
  83. {
  84. #ifdef HSIn_Defs
  85. HSIn_Defs
  86. #endif
  87. };
  88. struct HSCPIn
  89. {
  90. float _Arb0 : _Arb0;
  91. #ifdef HSCPIn_Defs
  92. HSCPIn_Defs
  93. #endif
  94. };
  95. struct HSCPOut
  96. {
  97. float _Arb0 : _Arb0;
  98. #ifdef HSCPOut_Defs
  99. HSCPOut_Defs
  100. #endif
  101. };
  102. struct PCOut
  103. {
  104. float _Arb0 : _Arb0;
  105. Def_TessFactor
  106. Def_InsideTessFactor
  107. #ifdef PCOut_Defs
  108. PCOut_Defs
  109. #endif
  110. };
  111. struct DSIn
  112. {
  113. Def_TessFactor
  114. Def_InsideTessFactor
  115. #ifdef DSIn_Defs
  116. DSIn_Defs
  117. #endif
  118. };
  119. struct DSCPIn
  120. {
  121. #ifdef DSCPIn_Defs
  122. DSCPIn_Defs
  123. #endif
  124. };
  125. struct DSOut
  126. {
  127. float _Arb0 : _Arb0;
  128. #ifdef DSOut_Defs
  129. DSOut_Defs
  130. #endif
  131. };
  132. struct GSVIn
  133. {
  134. float _Arb0 : _Arb0;
  135. #ifdef GSVIn_Defs
  136. GSVIn_Defs
  137. #endif
  138. };
  139. struct GSIn
  140. {
  141. #ifdef GSIn_Defs
  142. GSIn_Defs
  143. #endif
  144. };
  145. struct GSOut
  146. {
  147. float _Arb0 : _Arb0;
  148. #ifdef GSOut_Defs
  149. GSOut_Defs
  150. #endif
  151. };
  152. struct PSIn
  153. {
  154. #ifdef PSIn_Defs
  155. PSIn_Defs
  156. #endif
  157. };
  158. struct PSOut
  159. {
  160. #ifdef PSOut_Defs
  161. PSOut_Defs
  162. #endif
  163. float4 out1 : SV_Target1;
  164. };
  165. struct CSIn
  166. {
  167. #ifdef CSIn_Defs
  168. CSIn_Defs
  169. #endif
  170. };
  171. #undef DECLARE
  172. #undef USE
  173. void VSMain(
  174. #ifdef VSIn_Defs
  175. in VSIn In,
  176. #endif
  177. out VSOut Out)
  178. {
  179. Out._Arb0 = 0;
  180. #ifdef VSIn_Defs
  181. #define DECLARE(decl)
  182. #define USE(t,v) Out._Arb0 += (float)In.v;
  183. VSIn_Defs
  184. #undef DECLARE
  185. #undef USE
  186. #endif
  187. #ifdef VSOut_Defs
  188. #define DECLARE(decl)
  189. #define USE(t,v) Out.v = (t)Out._Arb0;
  190. VSOut_Defs
  191. #undef DECLARE
  192. #undef USE
  193. #endif
  194. }
  195. void PCMain(
  196. #ifdef HSCPIn_Defs
  197. in InputPatch<HSCPIn, 4> InPatch,
  198. #endif
  199. #ifdef HSCPOut_Defs
  200. in OutputPatch<HSCPOut, 4> OutPatch,
  201. #endif
  202. #ifdef PCIn_Defs
  203. in PCIn In,
  204. #endif
  205. out PCOut Out)
  206. {
  207. Out._Arb0 = 0;
  208. #ifdef HSCPIn_Defs
  209. #define DECLARE(decl)
  210. #define USE(t,v) Out._Arb0 += (float)InPatch[1].v;
  211. HSCPIn_Defs
  212. #undef DECLARE
  213. #undef USE
  214. #endif
  215. #ifdef HSCPOut_Defs
  216. #define DECLARE(decl)
  217. #define USE(t,v) Out._Arb0 += (float)OutPatch[1].v;
  218. HSCPOut_Defs
  219. #undef DECLARE
  220. #undef USE
  221. #endif
  222. #ifdef PCIn_Defs
  223. #define DECLARE(decl)
  224. #define USE(t,v) Out._Arb0 += (float)In.v;
  225. PCIn_Defs
  226. #undef DECLARE
  227. #undef USE
  228. #endif
  229. #define DECLARE(decl)
  230. #define USE(t,v) Out.v = (t)Out._Arb0;
  231. Def_TessFactor
  232. Def_InsideTessFactor
  233. #ifdef PCOut_Defs
  234. PCOut_Defs
  235. #endif
  236. #undef DECLARE
  237. #undef USE
  238. }
  239. Attribute_Domain
  240. [partitioning("integer")]
  241. [outputtopology("triangle_cw")]
  242. [outputcontrolpoints(4)]
  243. [patchconstantfunc("PCMain")]
  244. HSCPOut HSMain(
  245. in InputPatch<HSCPIn, 4> InPatch
  246. #ifdef HSIn_Defs
  247. ,in HSIn In
  248. #endif
  249. )
  250. {
  251. HSCPOut Out;
  252. Out._Arb0 = 0;
  253. #ifdef HSCPIn_Defs
  254. #define DECLARE(decl)
  255. #define USE(t,v) Out._Arb0 += (float)InPatch[1].v;
  256. HSCPIn_Defs
  257. #undef DECLARE
  258. #undef USE
  259. #endif
  260. #ifdef HSIn_Defs
  261. #define DECLARE(decl)
  262. #define USE(t,v) Out._Arb0 += (float)In.v;
  263. HSIn_Defs
  264. #undef DECLARE
  265. #undef USE
  266. #endif
  267. #ifdef HSCPOut_Defs
  268. #define DECLARE(decl)
  269. #define USE(t,v) Out.v = (t)Out._Arb0;
  270. HSCPOut_Defs
  271. #undef DECLARE
  272. #undef USE
  273. #endif
  274. return Out;
  275. }
  276. Attribute_Domain
  277. void DSMain(
  278. #ifdef DSCPIn_Defs
  279. in OutputPatch<DSCPIn, 4> InPatch,
  280. #endif
  281. in DSIn In,
  282. out DSOut Out)
  283. {
  284. Out._Arb0 = 0;
  285. #ifdef DSCPIn_Defs
  286. #define DECLARE(decl)
  287. #define USE(t,v) Out._Arb0 += (float)InPatch[1].v;
  288. DSCPIn_Defs
  289. #undef DECLARE
  290. #undef USE
  291. #endif
  292. #ifdef DSIn_Defs
  293. #define DECLARE(decl)
  294. #define USE(t,v) Out._Arb0 += (float)In.v;
  295. DSIn_Defs
  296. #undef DECLARE
  297. #undef USE
  298. #endif
  299. #ifdef DSOut_Defs
  300. #define DECLARE(decl)
  301. #define USE(t,v) Out.v = (t)Out._Arb0;
  302. DSOut_Defs
  303. #undef DECLARE
  304. #undef USE
  305. #endif
  306. }
  307. [maxvertexcount(1)]
  308. void GSMain(
  309. in triangleadj GSVIn VIn[6],
  310. #ifdef GSIn_Defs
  311. // in GSIn In,
  312. #define DECLARE(decl) decl,
  313. #define USE(t,v)
  314. GSIn_Defs
  315. #undef DECLARE
  316. #undef USE
  317. #endif
  318. inout PointStream<GSOut> Stream)
  319. {
  320. GSOut Out = (GSOut)0;
  321. #ifdef GSVIn_Defs
  322. #define DECLARE(decl)
  323. #define USE(t,v) Out._Arb0 += (float)VIn[1].v;
  324. GSVIn_Defs
  325. #undef DECLARE
  326. #undef USE
  327. #endif
  328. #ifdef GSIn_Defs
  329. #define DECLARE(decl)
  330. #define USE(t,v) Out._Arb0 += (float)v;
  331. GSIn_Defs
  332. #undef DECLARE
  333. #undef USE
  334. #endif
  335. #ifdef GSOut_Defs
  336. #define DECLARE(decl)
  337. #define USE(t,v) Out.v = (t)Out._Arb0;
  338. GSOut_Defs
  339. #undef DECLARE
  340. #undef USE
  341. #endif
  342. Stream.Append(Out);
  343. }
  344. void PSMain(
  345. #ifdef PSIn_Defs
  346. in PSIn In,
  347. #endif
  348. out PSOut Out)
  349. {
  350. Out.out1 = 0;
  351. #ifdef PSIn_Defs
  352. #define DECLARE(decl)
  353. #define USE(t,v) Out.out1 += (float4)In.v;
  354. PSIn_Defs
  355. #undef DECLARE
  356. #undef USE
  357. #endif
  358. #ifdef PSOut_Defs
  359. #define DECLARE(decl)
  360. #define USE(t,v) Out.v = (t)Out.out1.x;
  361. PSOut_Defs
  362. #undef DECLARE
  363. #undef USE
  364. #endif
  365. }
  366. RWStructuredBuffer<int> Buf;
  367. [numthreads(8,4,2)]
  368. void CSMain(
  369. #ifdef CSIn_Defs
  370. CSIn In
  371. #endif
  372. )
  373. {
  374. int Out = 0;
  375. #ifdef CSIn_Defs
  376. #define DECLARE(decl)
  377. #define USE(t,v) Out += (int)In.v;
  378. CSIn_Defs
  379. #undef DECLARE
  380. #undef USE
  381. #endif
  382. #ifdef CSIn_Defs
  383. #define DECLARE(decl)
  384. #define USE(t,v) InterlockedAdd(Buf[((uint)In.v) % 256], Out);
  385. CSIn_Defs
  386. #undef DECLARE
  387. #undef USE
  388. #endif
  389. }