system-values.hlsl 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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 Def_CullPrimitive DECLARE(bool cullprim : SV_CullPrimitive) USE(bool, cullprim)
  41. #define Domain_Quad 0
  42. #define Domain_Tri 1
  43. #define Domain_Isoline 2
  44. #ifndef DOMAIN
  45. #define DOMAIN Domain_Quad
  46. #endif
  47. #if DOMAIN == Domain_Quad
  48. #define Attribute_Domain [domain("quad")]
  49. #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])
  50. #define Def_InsideTessFactor DECLARE(float itfactor[2] : SV_InsideTessFactor) USE(float, itfactor[0]) USE(float, itfactor[1])
  51. #endif
  52. #if DOMAIN == Domain_Tri
  53. #define Attribute_Domain [domain("tri")]
  54. #define Def_TessFactor DECLARE(float tfactor[3] : SV_TessFactor) USE(float, tfactor[0]) USE(float, tfactor[1]) USE(float, tfactor[2])
  55. #define Def_InsideTessFactor DECLARE(float itfactor : SV_InsideTessFactor) USE(float, itfactor[0])
  56. #endif
  57. #if DOMAIN == Domain_Isoline
  58. #define Attribute_Domain [domain("isoline")]
  59. #define Def_TessFactor DECLARE(float tfactor[2] : SV_TessFactor) USE(float, tfactor[0]) USE(float, tfactor[1])
  60. #define Def_InsideTessFactor DECLARE(float itfactor : SV_InsideTessFactor) USE(float, itfactor)
  61. #endif
  62. #define DECLARE(decl) decl;
  63. #define USE(t,v)
  64. struct VSIn
  65. {
  66. #ifdef VSIn_Defs
  67. VSIn_Defs
  68. #endif
  69. };
  70. struct VSOut
  71. {
  72. float _Arb0 : _Arb0;
  73. #ifdef VSOut_Defs
  74. VSOut_Defs
  75. #endif
  76. };
  77. struct PCIn
  78. {
  79. #ifdef PCIn_Defs
  80. PCIn_Defs
  81. #endif
  82. };
  83. struct HSIn
  84. {
  85. #ifdef HSIn_Defs
  86. HSIn_Defs
  87. #endif
  88. };
  89. struct HSCPIn
  90. {
  91. float _Arb0 : _Arb0;
  92. #ifdef HSCPIn_Defs
  93. HSCPIn_Defs
  94. #endif
  95. };
  96. struct HSCPOut
  97. {
  98. float _Arb0 : _Arb0;
  99. #ifdef HSCPOut_Defs
  100. HSCPOut_Defs
  101. #endif
  102. };
  103. struct PCOut
  104. {
  105. float _Arb0 : _Arb0;
  106. Def_TessFactor
  107. Def_InsideTessFactor
  108. #ifdef PCOut_Defs
  109. PCOut_Defs
  110. #endif
  111. };
  112. struct DSIn
  113. {
  114. Def_TessFactor
  115. Def_InsideTessFactor
  116. #ifdef DSIn_Defs
  117. DSIn_Defs
  118. #endif
  119. };
  120. struct DSCPIn
  121. {
  122. #ifdef DSCPIn_Defs
  123. DSCPIn_Defs
  124. #endif
  125. };
  126. struct DSOut
  127. {
  128. float _Arb0 : _Arb0;
  129. #ifdef DSOut_Defs
  130. DSOut_Defs
  131. #endif
  132. };
  133. struct GSVIn
  134. {
  135. float _Arb0 : _Arb0;
  136. #ifdef GSVIn_Defs
  137. GSVIn_Defs
  138. #endif
  139. };
  140. struct GSIn
  141. {
  142. #ifdef GSIn_Defs
  143. GSIn_Defs
  144. #endif
  145. };
  146. struct GSOut
  147. {
  148. float _Arb0 : _Arb0;
  149. #ifdef GSOut_Defs
  150. GSOut_Defs
  151. #endif
  152. };
  153. struct PSIn
  154. {
  155. #ifdef PSIn_Defs
  156. PSIn_Defs
  157. #endif
  158. };
  159. struct PSOut
  160. {
  161. #ifdef PSOut_Defs
  162. PSOut_Defs
  163. #endif
  164. float4 out1 : SV_Target1;
  165. };
  166. struct CSIn
  167. {
  168. #ifdef CSIn_Defs
  169. CSIn_Defs
  170. #endif
  171. };
  172. #undef DECLARE
  173. #undef USE
  174. void VSMain(
  175. #ifdef VSIn_Defs
  176. in VSIn In,
  177. #endif
  178. out VSOut Out)
  179. {
  180. Out._Arb0 = 0;
  181. #ifdef VSIn_Defs
  182. #define DECLARE(decl)
  183. #define USE(t,v) Out._Arb0 += (float)In.v;
  184. VSIn_Defs
  185. #undef DECLARE
  186. #undef USE
  187. #endif
  188. #ifdef VSOut_Defs
  189. #define DECLARE(decl)
  190. #define USE(t,v) Out.v = (t)Out._Arb0;
  191. VSOut_Defs
  192. #undef DECLARE
  193. #undef USE
  194. #endif
  195. }
  196. void PCMain(
  197. #ifdef HSCPIn_Defs
  198. in InputPatch<HSCPIn, 4> InPatch,
  199. #endif
  200. #ifdef HSCPOut_Defs
  201. in OutputPatch<HSCPOut, 4> OutPatch,
  202. #endif
  203. #ifdef PCIn_Defs
  204. in PCIn In,
  205. #endif
  206. out PCOut Out)
  207. {
  208. Out._Arb0 = 0;
  209. #ifdef HSCPIn_Defs
  210. #define DECLARE(decl)
  211. #define USE(t,v) Out._Arb0 += (float)InPatch[1].v;
  212. HSCPIn_Defs
  213. #undef DECLARE
  214. #undef USE
  215. #endif
  216. #ifdef HSCPOut_Defs
  217. #define DECLARE(decl)
  218. #define USE(t,v) Out._Arb0 += (float)OutPatch[1].v;
  219. HSCPOut_Defs
  220. #undef DECLARE
  221. #undef USE
  222. #endif
  223. #ifdef PCIn_Defs
  224. #define DECLARE(decl)
  225. #define USE(t,v) Out._Arb0 += (float)In.v;
  226. PCIn_Defs
  227. #undef DECLARE
  228. #undef USE
  229. #endif
  230. #define DECLARE(decl)
  231. #define USE(t,v) Out.v = (t)Out._Arb0;
  232. Def_TessFactor
  233. Def_InsideTessFactor
  234. #ifdef PCOut_Defs
  235. PCOut_Defs
  236. #endif
  237. #undef DECLARE
  238. #undef USE
  239. }
  240. Attribute_Domain
  241. [partitioning("integer")]
  242. [outputtopology("triangle_cw")]
  243. [outputcontrolpoints(4)]
  244. [patchconstantfunc("PCMain")]
  245. HSCPOut HSMain(
  246. in InputPatch<HSCPIn, 4> InPatch
  247. #ifdef HSIn_Defs
  248. ,in HSIn In
  249. #endif
  250. )
  251. {
  252. HSCPOut Out;
  253. Out._Arb0 = 0;
  254. #ifdef HSCPIn_Defs
  255. #define DECLARE(decl)
  256. #define USE(t,v) Out._Arb0 += (float)InPatch[1].v;
  257. HSCPIn_Defs
  258. #undef DECLARE
  259. #undef USE
  260. #endif
  261. #ifdef HSIn_Defs
  262. #define DECLARE(decl)
  263. #define USE(t,v) Out._Arb0 += (float)In.v;
  264. HSIn_Defs
  265. #undef DECLARE
  266. #undef USE
  267. #endif
  268. #ifdef HSCPOut_Defs
  269. #define DECLARE(decl)
  270. #define USE(t,v) Out.v = (t)Out._Arb0;
  271. HSCPOut_Defs
  272. #undef DECLARE
  273. #undef USE
  274. #endif
  275. return Out;
  276. }
  277. Attribute_Domain
  278. void DSMain(
  279. #ifdef DSCPIn_Defs
  280. in OutputPatch<DSCPIn, 4> InPatch,
  281. #endif
  282. in DSIn In,
  283. out DSOut Out)
  284. {
  285. Out._Arb0 = 0;
  286. #ifdef DSCPIn_Defs
  287. #define DECLARE(decl)
  288. #define USE(t,v) Out._Arb0 += (float)InPatch[1].v;
  289. DSCPIn_Defs
  290. #undef DECLARE
  291. #undef USE
  292. #endif
  293. #ifdef DSIn_Defs
  294. #define DECLARE(decl)
  295. #define USE(t,v) Out._Arb0 += (float)In.v;
  296. DSIn_Defs
  297. #undef DECLARE
  298. #undef USE
  299. #endif
  300. #ifdef DSOut_Defs
  301. #define DECLARE(decl)
  302. #define USE(t,v) Out.v = (t)Out._Arb0;
  303. DSOut_Defs
  304. #undef DECLARE
  305. #undef USE
  306. #endif
  307. }
  308. [maxvertexcount(1)]
  309. void GSMain(
  310. in triangleadj GSVIn VIn[6],
  311. #ifdef GSIn_Defs
  312. // in GSIn In,
  313. #define DECLARE(decl) decl,
  314. #define USE(t,v)
  315. GSIn_Defs
  316. #undef DECLARE
  317. #undef USE
  318. #endif
  319. inout PointStream<GSOut> Stream)
  320. {
  321. GSOut Out = (GSOut)0;
  322. #ifdef GSVIn_Defs
  323. #define DECLARE(decl)
  324. #define USE(t,v) Out._Arb0 += (float)VIn[1].v;
  325. GSVIn_Defs
  326. #undef DECLARE
  327. #undef USE
  328. #endif
  329. #ifdef GSIn_Defs
  330. #define DECLARE(decl)
  331. #define USE(t,v) Out._Arb0 += (float)v;
  332. GSIn_Defs
  333. #undef DECLARE
  334. #undef USE
  335. #endif
  336. #ifdef GSOut_Defs
  337. #define DECLARE(decl)
  338. #define USE(t,v) Out.v = (t)Out._Arb0;
  339. GSOut_Defs
  340. #undef DECLARE
  341. #undef USE
  342. #endif
  343. Stream.Append(Out);
  344. }
  345. void PSMain(
  346. #ifdef PSIn_Defs
  347. in PSIn In,
  348. #endif
  349. out PSOut Out)
  350. {
  351. Out.out1 = 0;
  352. #ifdef PSIn_Defs
  353. #define DECLARE(decl)
  354. #define USE(t,v) Out.out1 += (float4)In.v;
  355. PSIn_Defs
  356. #undef DECLARE
  357. #undef USE
  358. #endif
  359. #ifdef PSOut_Defs
  360. #define DECLARE(decl)
  361. #define USE(t,v) Out.v = (t)Out.out1.x;
  362. PSOut_Defs
  363. #undef DECLARE
  364. #undef USE
  365. #endif
  366. }
  367. RWStructuredBuffer<int> Buf;
  368. [numthreads(8,4,2)]
  369. void CSMain(
  370. #ifdef CSIn_Defs
  371. CSIn In
  372. #endif
  373. )
  374. {
  375. int Out = 0;
  376. #ifdef CSIn_Defs
  377. #define DECLARE(decl)
  378. #define USE(t,v) Out += (int)In.v;
  379. CSIn_Defs
  380. #undef DECLARE
  381. #undef USE
  382. #endif
  383. #ifdef CSIn_Defs
  384. #define DECLARE(decl)
  385. #define USE(t,v) InterlockedAdd(Buf[((uint)In.v) % 256], Out);
  386. CSIn_Defs
  387. #undef DECLARE
  388. #undef USE
  389. #endif
  390. }