runtime.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. #include <stddef.h>
  2. static const int STACK_SIZE_IN_BYTES = 1024;
  3. typedef float float3 __attribute__((vector_size(3*sizeof(float))));
  4. typedef float float4 __attribute__((vector_size(4*sizeof(float))));
  5. typedef float float12 __attribute__((vector_size(12*sizeof(float))));
  6. typedef float (M3x4)[12];
  7. typedef int (StackType)[STACK_SIZE_IN_BYTES/sizeof(int)];
  8. typedef unsigned char byte;
  9. typedef struct RuntimeDataStruct
  10. {
  11. int DispatchRaysIndex[2];
  12. int DispatchRaysDimensions[2];
  13. float RayTMin;
  14. float RayTCurrent;
  15. unsigned RayFlags;
  16. float WorldRayOrigin[3];
  17. float WorldRayDirection[3];
  18. float ObjectRayOrigin[3];
  19. float ObjectRayDirection[3];
  20. M3x4 ObjectToWorld;
  21. M3x4 WorldToObject;
  22. unsigned PrimitiveIndex;
  23. unsigned InstanceIndex;
  24. unsigned InstanceID;
  25. unsigned HitKind;
  26. unsigned ShaderRecordOffset;
  27. // Pending hit values - accessed in anyHit and intersection shaders before a hit has been committed
  28. float PendingRayTCurrent;
  29. unsigned PendingPrimitiveIndex;
  30. unsigned PendingInstanceIndex;
  31. unsigned PendingInstanceID;
  32. unsigned PendingHitKind;
  33. unsigned PendingShaderRecordOffset;
  34. int GroupIndex;
  35. int AnyHitResult;
  36. int AnyHitStateId; // Originally temporary. We needed to avoid resource usage
  37. // in ReportHit() because of linking issues so weset the value here first.
  38. // May be worth retaining to cache the value when fetching the intersection
  39. // stateId (fetch them both at once).
  40. int PayloadOffset;
  41. int CommittedAttrOffset;
  42. int PendingAttrOffset;
  43. int StackOffset; // offset from the start of the stack
  44. StackType* Stack;
  45. } RuntimeData;
  46. typedef RuntimeData* RuntimeDataType;
  47. typedef struct TraceRaySpills_ClosestHit
  48. {
  49. float RayTMin;
  50. float RayTCurrent;
  51. unsigned RayFlags;
  52. float WorldRayOrigin[3];
  53. float WorldRayDirection[3];
  54. float ObjectRayOrigin[3];
  55. float ObjectRayDirection[3];
  56. unsigned PrimitiveIndex;
  57. unsigned InstanceIndex;
  58. unsigned InstanceID;
  59. unsigned HitKind;
  60. unsigned ShaderRecordOffset;
  61. } TraceRaySpills_ClosestHit;
  62. typedef struct TraceRaySpills_Miss
  63. {
  64. float RayTMin;
  65. float RayTCurrent;
  66. unsigned RayFlags;
  67. float WorldRayOrigin[3];
  68. float WorldRayDirection[3];
  69. unsigned ShaderRecordOffset;
  70. } TraceRaySpills_Miss;
  71. #define REF(x) (runtimeData->x)
  72. #define REF_FLT(x) (runtimeData->x)
  73. #define REF_STACK(offset) ((*runtimeData->Stack)[runtimeData->StackOffset + offset])
  74. #define REF_FLT_OFS(x, offset) (runtimeData->x[offset])
  75. // Return next stateID
  76. int rewrite_dispatch(RuntimeDataType runtimeData, int stateID);
  77. void* rewrite_setLaunchParams(RuntimeDataType runtimeData, unsigned dimx, unsigned dimy);
  78. unsigned rewrite_getStackSize(void);
  79. StackType* rewrite_createStack(void);
  80. void stackInit(RuntimeDataType runtimeData, StackType* theStack, unsigned stackSize)
  81. {
  82. REF(Stack) = theStack;
  83. REF(StackOffset) = stackSize/sizeof(int) - 1;
  84. REF(PayloadOffset) = 1111; // recognizable bogus values
  85. REF(CommittedAttrOffset) = 2222;
  86. REF(PendingAttrOffset) = 3333;
  87. }
  88. void stackFramePush(RuntimeDataType runtimeData, int size)
  89. {
  90. REF(StackOffset) -= size;
  91. }
  92. void stackFramePop(RuntimeDataType runtimeData, int size)
  93. {
  94. REF(StackOffset) += size;
  95. }
  96. int stackFrameOffset(RuntimeDataType runtimeData)
  97. {
  98. return REF(StackOffset);
  99. }
  100. int payloadOffset(RuntimeDataType runtimeData)
  101. {
  102. return REF(PayloadOffset);
  103. }
  104. int committedAttrOffset(RuntimeDataType runtimeData)
  105. {
  106. return REF(CommittedAttrOffset);
  107. }
  108. int pendingAttrOffset(RuntimeDataType runtimeData)
  109. {
  110. return REF(PendingAttrOffset);
  111. }
  112. int* stackIntPtr(RuntimeDataType runtimeData, int baseOffset, int offset)
  113. {
  114. return &(*runtimeData->Stack)[baseOffset + offset];
  115. }
  116. void traceFramePush(RuntimeDataType runtimeData, int attrSize)
  117. {
  118. // Save the old payload and attribute offsets
  119. REF_STACK(-1) = REF(CommittedAttrOffset);
  120. REF_STACK(-2) = REF(PendingAttrOffset);
  121. // Set new offsets
  122. REF(CommittedAttrOffset) = REF(StackOffset) - 2 - attrSize;
  123. REF(PendingAttrOffset) = REF(StackOffset) - 2 - 2 * attrSize;
  124. }
  125. void traceFramePop(RuntimeDataType runtimeData)
  126. {
  127. // Restore the old attribute offsets
  128. REF(CommittedAttrOffset) = REF_STACK(-1);
  129. REF(PendingAttrOffset) = REF_STACK(-2);
  130. }
  131. void traceRaySave_ClosestHit(RuntimeDataType runtimeData, TraceRaySpills_ClosestHit* spills)
  132. {
  133. spills->RayFlags = REF(RayFlags);
  134. spills->RayTCurrent = REF_FLT(RayTCurrent);
  135. spills->RayTMin = REF_FLT(RayTMin);
  136. spills->WorldRayOrigin[0] = REF_FLT(WorldRayOrigin[0]);
  137. spills->WorldRayOrigin[1] = REF_FLT(WorldRayOrigin[1]);
  138. spills->WorldRayOrigin[2] = REF_FLT(WorldRayOrigin[2]);
  139. spills->WorldRayDirection[0] = REF_FLT(WorldRayDirection[0]);
  140. spills->WorldRayDirection[1] = REF_FLT(WorldRayDirection[1]);
  141. spills->WorldRayDirection[2] = REF_FLT(WorldRayDirection[2]);
  142. spills->ObjectRayOrigin[0] = REF_FLT(ObjectRayOrigin[0]);
  143. spills->ObjectRayOrigin[1] = REF_FLT(ObjectRayOrigin[1]);
  144. spills->ObjectRayOrigin[2] = REF_FLT(ObjectRayOrigin[2]);
  145. spills->ObjectRayDirection[0] = REF_FLT(ObjectRayDirection[0]);
  146. spills->ObjectRayDirection[1] = REF_FLT(ObjectRayDirection[1]);
  147. spills->ObjectRayDirection[2] = REF_FLT(ObjectRayDirection[2]);
  148. spills->PrimitiveIndex = REF(PrimitiveIndex);
  149. spills->InstanceIndex = REF(InstanceIndex);
  150. spills->InstanceID = REF(InstanceID);
  151. spills->HitKind = REF(HitKind);
  152. spills->ShaderRecordOffset = REF(ShaderRecordOffset);
  153. }
  154. void traceRayRestore_ClosestHit(RuntimeDataType runtimeData, TraceRaySpills_ClosestHit* spills)
  155. {
  156. REF(RayFlags) = spills->RayFlags;
  157. REF_FLT(RayTCurrent) = spills->RayTCurrent;
  158. REF_FLT(RayTMin) = spills->RayTMin;
  159. REF_FLT(WorldRayOrigin[0]) = spills->WorldRayOrigin[0];
  160. REF_FLT(WorldRayOrigin[1]) = spills->WorldRayOrigin[1];
  161. REF_FLT(WorldRayOrigin[2]) = spills->WorldRayOrigin[2];
  162. REF_FLT(WorldRayDirection[0]) = spills->WorldRayDirection[0];
  163. REF_FLT(WorldRayDirection[1]) = spills->WorldRayDirection[1];
  164. REF_FLT(WorldRayDirection[2]) = spills->WorldRayDirection[2];
  165. REF_FLT(ObjectRayOrigin[0]) = spills->ObjectRayOrigin[0];
  166. REF_FLT(ObjectRayOrigin[1]) = spills->ObjectRayOrigin[1];
  167. REF_FLT(ObjectRayOrigin[2]) = spills->ObjectRayOrigin[2];
  168. REF_FLT(ObjectRayDirection[0]) = spills->ObjectRayDirection[0];
  169. REF_FLT(ObjectRayDirection[1]) = spills->ObjectRayDirection[1];
  170. REF_FLT(ObjectRayDirection[2]) = spills->ObjectRayDirection[2];
  171. REF(PrimitiveIndex) = spills->PrimitiveIndex;
  172. REF(InstanceIndex) = spills->InstanceIndex;
  173. REF(InstanceID) = spills->InstanceID;
  174. REF(HitKind) = spills->HitKind;
  175. REF(ShaderRecordOffset) = spills->ShaderRecordOffset;
  176. }
  177. void traceRaySave_Miss(RuntimeDataType runtimeData, TraceRaySpills_Miss* spills)
  178. {
  179. spills->RayFlags = REF(RayFlags);
  180. spills->RayTCurrent = REF_FLT(RayTCurrent);
  181. spills->RayTMin = REF_FLT(RayTMin);
  182. spills->WorldRayOrigin[0] = REF_FLT(WorldRayOrigin[0]);
  183. spills->WorldRayOrigin[1] = REF_FLT(WorldRayOrigin[1]);
  184. spills->WorldRayOrigin[2] = REF_FLT(WorldRayOrigin[2]);
  185. spills->WorldRayDirection[0] = REF_FLT(WorldRayDirection[0]);
  186. spills->WorldRayDirection[1] = REF_FLT(WorldRayDirection[1]);
  187. spills->WorldRayDirection[2] = REF_FLT(WorldRayDirection[2]);
  188. spills->ShaderRecordOffset = REF(ShaderRecordOffset);
  189. }
  190. void traceRayRestore_Miss(RuntimeDataType runtimeData, TraceRaySpills_Miss* spills)
  191. {
  192. REF(RayFlags) = spills->RayFlags;
  193. REF_FLT(RayTCurrent) = spills->RayTCurrent;
  194. REF_FLT(RayTMin) = spills->RayTMin;
  195. REF_FLT(WorldRayOrigin[0]) = spills->WorldRayOrigin[0];
  196. REF_FLT(WorldRayOrigin[1]) = spills->WorldRayOrigin[1];
  197. REF_FLT(WorldRayOrigin[2]) = spills->WorldRayOrigin[2];
  198. REF_FLT(WorldRayDirection[0]) = spills->WorldRayDirection[0];
  199. REF_FLT(WorldRayDirection[1]) = spills->WorldRayDirection[1];
  200. REF_FLT(WorldRayDirection[2]) = spills->WorldRayDirection[2];
  201. REF(ShaderRecordOffset) = spills->ShaderRecordOffset;
  202. }
  203. //////////////////////////////////////////////////////////////////////////
  204. //
  205. // Intrinsics for the fallback layer
  206. //
  207. //////////////////////////////////////////////////////////////////////////
  208. void fb_Fallback_Scheduler(int initialStateId, unsigned dimx, unsigned dimy)
  209. {
  210. StackType* theStack = rewrite_createStack();
  211. RuntimeData theRuntimeData;
  212. RuntimeDataType runtimeData = &theRuntimeData;
  213. rewrite_setLaunchParams(runtimeData, dimx, dimy);
  214. if(REF(DispatchRaysIndex[0]) >= REF(DispatchRaysDimensions[0]) ||
  215. REF(DispatchRaysIndex[1]) >= REF(DispatchRaysDimensions[1]))
  216. {
  217. return;
  218. }
  219. // Set final return stateID into reserved area at stack top
  220. unsigned stackSize = rewrite_getStackSize();
  221. stackInit(runtimeData, theStack, stackSize);
  222. int stackFrameOffs = stackFrameOffset(runtimeData);
  223. *stackIntPtr(runtimeData, stackFrameOffs, 0) = -1;
  224. int stateId = initialStateId;
  225. int count = 0;
  226. while( stateId >= 0 )
  227. {
  228. stateId = rewrite_dispatch(runtimeData, stateId);
  229. }
  230. }
  231. void fb_Fallback_SetLaunchParams(RuntimeDataType runtimeData, unsigned DTidx, unsigned DTidy, unsigned dimx, unsigned dimy, unsigned groupIndex)
  232. {
  233. REF(DispatchRaysIndex[0]) = DTidx;
  234. REF(DispatchRaysIndex[1]) = DTidy;
  235. REF(DispatchRaysDimensions[0]) = dimx;
  236. REF(DispatchRaysDimensions[1]) = dimy;
  237. REF(GroupIndex) = groupIndex;
  238. }
  239. int fb_Fallback_TraceRayBegin(RuntimeDataType runtimeData, unsigned rayFlags, float ox, float oy, float oz, float tmin, float dx, float dy, float dz, float tmax, int newPayloadOffset)
  240. {
  241. REF(RayFlags) = rayFlags;
  242. REF_FLT(WorldRayOrigin[0]) = ox;
  243. REF_FLT(WorldRayOrigin[1]) = oy;
  244. REF_FLT(WorldRayOrigin[2]) = oz;
  245. REF_FLT(WorldRayDirection[0]) = dx;
  246. REF_FLT(WorldRayDirection[1]) = dy;
  247. REF_FLT(WorldRayDirection[2]) = dz;
  248. REF_FLT(RayTCurrent) = tmax;
  249. REF_FLT(RayTMin) = tmin;
  250. int oldOffset = REF(PayloadOffset);
  251. REF(PayloadOffset) = newPayloadOffset;
  252. return oldOffset;
  253. }
  254. void fb_Fallback_TraceRayEnd(RuntimeDataType runtimeData, int oldPayloadOffset)
  255. {
  256. REF(PayloadOffset) = oldPayloadOffset;
  257. }
  258. void fb_Fallback_SetPendingTriVals(RuntimeDataType runtimeData, unsigned shaderRecordOffset, unsigned primitiveIndex, unsigned instanceIndex, unsigned instanceID, float t, unsigned hitKind)
  259. {
  260. REF(PendingShaderRecordOffset) = shaderRecordOffset;
  261. REF(PendingPrimitiveIndex) = primitiveIndex;
  262. REF(PendingInstanceIndex) = instanceIndex;
  263. REF(PendingInstanceID) = instanceID;
  264. REF_FLT(PendingRayTCurrent) = t;
  265. REF(PendingHitKind) = hitKind;
  266. }
  267. void fb_Fallback_SetPendingCustomVals(RuntimeDataType runtimeData, unsigned shaderRecordOffset, unsigned primitiveIndex, unsigned instanceIndex, unsigned instanceID)
  268. {
  269. REF(PendingShaderRecordOffset) = shaderRecordOffset;
  270. REF(PendingPrimitiveIndex) = primitiveIndex;
  271. REF(PendingInstanceIndex) = instanceIndex;
  272. REF(PendingInstanceID) = instanceID;
  273. }
  274. void fb_Fallback_CommitHit(RuntimeDataType runtimeData)
  275. {
  276. REF_FLT(RayTCurrent) = REF_FLT(PendingRayTCurrent);
  277. REF(ShaderRecordOffset) = REF(PendingShaderRecordOffset);
  278. REF(PrimitiveIndex) = REF(PendingPrimitiveIndex);
  279. REF(InstanceIndex) = REF(PendingInstanceIndex);
  280. REF(InstanceID) = REF(PendingInstanceID);
  281. REF(HitKind) = REF(PendingHitKind);
  282. int PendingAttrOffset = REF(PendingAttrOffset);
  283. REF(PendingAttrOffset) = REF(CommittedAttrOffset);
  284. REF(CommittedAttrOffset) = PendingAttrOffset;
  285. }
  286. int fb_Fallback_RuntimeDataLoadInt(RuntimeDataType runtimeData, int offset)
  287. {
  288. return (*runtimeData->Stack)[offset];
  289. }
  290. void fb_Fallback_RuntimeDataStoreInt(RuntimeDataType runtimeData, int offset, int val)
  291. {
  292. (*runtimeData->Stack)[offset] = val;
  293. }
  294. unsigned fb_dxop_dispatchRaysIndex(RuntimeDataType runtimeData, byte i)
  295. {
  296. return REF(DispatchRaysIndex[i]);
  297. }
  298. unsigned fb_dxop_dispatchRaysDimensions(RuntimeDataType runtimeData, byte i)
  299. {
  300. return REF(DispatchRaysDimensions[i]);
  301. }
  302. float fb_dxop_rayTMin(RuntimeDataType runtimeData)
  303. {
  304. return REF_FLT(RayTMin);
  305. }
  306. float fb_Fallback_RayTMin(RuntimeDataType runtimeData)
  307. {
  308. return REF_FLT(RayTMin);
  309. }
  310. void fb_Fallback_SetRayTMin(RuntimeDataType runtimeData, float t)
  311. {
  312. REF_FLT(RayTMin) = t;
  313. }
  314. float fb_dxop_rayTCurrent(RuntimeDataType runtimeData)
  315. {
  316. return REF_FLT(RayTCurrent);
  317. }
  318. float fb_Fallback_RayTCurrent(RuntimeDataType runtimeData)
  319. {
  320. return REF_FLT(RayTCurrent);
  321. }
  322. void fb_Fallback_SetRayTCurrent(RuntimeDataType runtimeData, float t)
  323. {
  324. REF_FLT(RayTCurrent) = t;
  325. }
  326. unsigned fb_dxop_rayFlags(RuntimeDataType runtimeData)
  327. {
  328. return REF(RayFlags);
  329. }
  330. unsigned fb_Fallback_RayFlags(RuntimeDataType runtimeData)
  331. {
  332. return REF(RayFlags);
  333. }
  334. void fb_Fallback_SetRayFlags(RuntimeDataType runtimeData, unsigned flags)
  335. {
  336. REF(RayFlags) = flags;
  337. }
  338. float fb_dxop_worldRayOrigin(RuntimeDataType runtimeData, byte i)
  339. {
  340. return REF_FLT(WorldRayOrigin[i]);
  341. }
  342. float fb_Fallback_WorldRayOrigin(RuntimeDataType runtimeData, byte i)
  343. {
  344. return REF_FLT(WorldRayOrigin[i]);
  345. }
  346. void fb_Fallback_SetWorldRayOrigin(RuntimeDataType runtimeData, float x, float y, float z)
  347. {
  348. REF_FLT(WorldRayOrigin[0]) = x;
  349. REF_FLT(WorldRayOrigin[1]) = y;
  350. REF_FLT(WorldRayOrigin[2]) = z;
  351. }
  352. float fb_dxop_worldRayDirection(RuntimeDataType runtimeData, byte i)
  353. {
  354. return REF_FLT(WorldRayDirection[i]);
  355. }
  356. float fb_Fallback_WorldRayDirection(RuntimeDataType runtimeData, byte i)
  357. {
  358. return REF_FLT(WorldRayDirection[i]);
  359. }
  360. void fb_Fallback_SetWorldRayDirection(RuntimeDataType runtimeData, float x, float y, float z)
  361. {
  362. REF_FLT(WorldRayDirection[0]) = x;
  363. REF_FLT(WorldRayDirection[1]) = y;
  364. REF_FLT(WorldRayDirection[2]) = z;
  365. }
  366. float fb_dxop_objectRayOrigin(RuntimeDataType runtimeData, byte i)
  367. {
  368. return REF_FLT(ObjectRayOrigin[i]);
  369. }
  370. float fb_Fallback_ObjectRayOrigin(RuntimeDataType runtimeData, byte i)
  371. {
  372. return REF_FLT(ObjectRayOrigin[i]);
  373. }
  374. void fb_Fallback_SetObjectRayOrigin(RuntimeDataType runtimeData, float x, float y, float z)
  375. {
  376. REF_FLT(ObjectRayOrigin[0]) = x;
  377. REF_FLT(ObjectRayOrigin[1]) = y;
  378. REF_FLT(ObjectRayOrigin[2]) = z;
  379. }
  380. float fb_dxop_objectRayDirection(RuntimeDataType runtimeData, byte i)
  381. {
  382. return REF_FLT(ObjectRayDirection[i]);
  383. }
  384. float fb_Fallback_ObjectRayDirection(RuntimeDataType runtimeData, byte i)
  385. {
  386. return REF_FLT(ObjectRayDirection[i]);
  387. }
  388. void fb_Fallback_SetObjectRayDirection(RuntimeDataType runtimeData, float x, float y, float z)
  389. {
  390. REF_FLT(ObjectRayDirection[0]) = x;
  391. REF_FLT(ObjectRayDirection[1]) = y;
  392. REF_FLT(ObjectRayDirection[2]) = z;
  393. }
  394. float fb_dxop_objectToWorld(RuntimeDataType runtimeData, int r, byte c)
  395. {
  396. int i = r * 4 + c;
  397. return REF_FLT_OFS(ObjectToWorld, i);
  398. }
  399. void fb_Fallback_SetObjectToWorld(RuntimeDataType runtimeData, float12 M)
  400. {
  401. REF_FLT_OFS(ObjectToWorld, 0) = M[0];
  402. REF_FLT_OFS(ObjectToWorld, 1) = M[1];
  403. REF_FLT_OFS(ObjectToWorld, 2) = M[2];
  404. REF_FLT_OFS(ObjectToWorld, 3) = M[3];
  405. REF_FLT_OFS(ObjectToWorld, 4) = M[4];
  406. REF_FLT_OFS(ObjectToWorld, 5) = M[5];
  407. REF_FLT_OFS(ObjectToWorld, 6) = M[6];
  408. REF_FLT_OFS(ObjectToWorld, 7) = M[7];
  409. REF_FLT_OFS(ObjectToWorld, 8) = M[8];
  410. REF_FLT_OFS(ObjectToWorld, 9) = M[9];
  411. REF_FLT_OFS(ObjectToWorld, 10) = M[10];
  412. REF_FLT_OFS(ObjectToWorld, 11) = M[11];
  413. }
  414. float fb_dxop_worldToObject(RuntimeDataType runtimeData, int r, byte c)
  415. {
  416. int i = r * 4 + c;
  417. return REF_FLT_OFS(WorldToObject, i);
  418. }
  419. void fb_Fallback_SetWorldToObject(RuntimeDataType runtimeData, float12 M)
  420. {
  421. REF_FLT_OFS(WorldToObject, 0) = M[0];
  422. REF_FLT_OFS(WorldToObject, 1) = M[1];
  423. REF_FLT_OFS(WorldToObject, 2) = M[2];
  424. REF_FLT_OFS(WorldToObject, 3) = M[3];
  425. REF_FLT_OFS(WorldToObject, 4) = M[4];
  426. REF_FLT_OFS(WorldToObject, 5) = M[5];
  427. REF_FLT_OFS(WorldToObject, 6) = M[6];
  428. REF_FLT_OFS(WorldToObject, 7) = M[7];
  429. REF_FLT_OFS(WorldToObject, 8) = M[8];
  430. REF_FLT_OFS(WorldToObject, 9) = M[9];
  431. REF_FLT_OFS(WorldToObject, 10) = M[10];
  432. REF_FLT_OFS(WorldToObject, 11) = M[11];
  433. }
  434. unsigned fb_dxop_primitiveID(RuntimeDataType runtimeData)
  435. //unsigned fb_dxop_primitiveIndex(RuntimeDataType runtimeData)
  436. {
  437. return REF(PrimitiveIndex);
  438. }
  439. unsigned fb_Fallback_PrimitiveIndex(RuntimeDataType runtimeData)
  440. {
  441. return REF(PrimitiveIndex);
  442. }
  443. void fb_Fallback_SetPrimitiveIndex(RuntimeDataType runtimeData, unsigned i)
  444. {
  445. REF(PrimitiveIndex) = i;
  446. }
  447. unsigned fb_Fallback_ShaderRecordOffset(RuntimeDataType runtimeData)
  448. {
  449. return REF(ShaderRecordOffset);
  450. }
  451. void fb_Fallback_SetShaderRecordOffset(RuntimeDataType runtimeData, unsigned shaderRecordOffset)
  452. {
  453. REF(ShaderRecordOffset) = shaderRecordOffset;
  454. }
  455. unsigned fb_dxop_instanceIndex(RuntimeDataType runtimeData)
  456. {
  457. return REF(InstanceIndex);
  458. }
  459. unsigned fb_Fallback_InstanceIndex(RuntimeDataType runtimeData)
  460. {
  461. return REF(InstanceIndex);
  462. }
  463. void fb_Fallback_SetInstanceIndex(RuntimeDataType runtimeData, unsigned i)
  464. {
  465. REF(InstanceIndex) = i;
  466. }
  467. unsigned fb_dxop_instanceID(RuntimeDataType runtimeData)
  468. {
  469. return REF(InstanceID);
  470. }
  471. unsigned fb_Fallback_InstanceID(RuntimeDataType runtimeData)
  472. {
  473. return REF(InstanceID);
  474. }
  475. void fb_Fallback_SetInstanceID(RuntimeDataType runtimeData, unsigned i)
  476. {
  477. REF(InstanceID) = i;
  478. }
  479. unsigned fb_dxop_hitKind(RuntimeDataType runtimeData)
  480. {
  481. return REF(HitKind);
  482. }
  483. unsigned fb_Fallback_HitKind(RuntimeDataType runtimeData)
  484. {
  485. return REF(HitKind);
  486. }
  487. void fb_Fallback_SetHitKind(RuntimeDataType runtimeData, unsigned i)
  488. {
  489. REF(HitKind) = i;
  490. }
  491. float fb_dxop_pending_rayTCurrent(RuntimeDataType runtimeData)
  492. {
  493. return REF_FLT(PendingRayTCurrent);
  494. }
  495. void fb_Fallback_SetPendingRayTCurrent(RuntimeDataType runtimeData, float t)
  496. {
  497. REF_FLT(PendingRayTCurrent) = t;
  498. }
  499. unsigned fb_dxop_pending_primitiveID(RuntimeDataType runtimeData)
  500. //unsigned fb_dxop_pending_primitiveIndex(RuntimeDataType runtimeData)
  501. {
  502. return REF(PendingPrimitiveIndex);
  503. }
  504. unsigned fb_Fallback_PendingShaderRecordOffset(RuntimeDataType runtimeData)
  505. {
  506. return REF(PendingShaderRecordOffset);
  507. }
  508. unsigned fb_dxop_pending_instanceIndex(RuntimeDataType runtimeData)
  509. {
  510. return REF(PendingInstanceIndex);
  511. }
  512. unsigned fb_dxop_pending_instanceID(RuntimeDataType runtimeData)
  513. {
  514. return REF(PendingInstanceID);
  515. }
  516. unsigned fb_dxop_pending_hitKind(RuntimeDataType runtimeData)
  517. {
  518. return REF(PendingHitKind);
  519. }
  520. void fb_Fallback_SetPendingHitKind(RuntimeDataType runtimeData, unsigned i)
  521. {
  522. REF(PendingHitKind) = i;
  523. }
  524. unsigned fb_Fallback_GroupIndex(RuntimeDataType runtimeData)
  525. {
  526. return REF(GroupIndex);
  527. }
  528. int fb_Fallback_AnyHitResult(RuntimeDataType runtimeData)
  529. {
  530. return REF(AnyHitResult);
  531. }
  532. void fb_Fallback_SetAnyHitResult(RuntimeDataType runtimeData, int result)
  533. {
  534. REF(AnyHitResult) = result;
  535. }
  536. int fb_Fallback_AnyHitStateId(RuntimeDataType runtimeData)
  537. {
  538. return REF(AnyHitStateId);
  539. }
  540. void fb_Fallback_SetAnyHitStateId(RuntimeDataType runtimeData, int id)
  541. {
  542. REF(AnyHitStateId) = id;
  543. }