rtcore_scene.isph 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // ======================================================================== //
  2. // Copyright 2009-2018 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #ifndef __RTC_SCENE_ISPH__
  17. #define __RTC_SCENE_ISPH__
  18. #include "rtcore_device.isph"
  19. /* Forward declarations for ray structures */
  20. struct RTCRayHit;
  21. struct RTCRayHitNp;
  22. /* Scene flags */
  23. enum RTCSceneFlags
  24. {
  25. RTC_SCENE_FLAG_NONE = 0,
  26. RTC_SCENE_FLAG_DYNAMIC = (1 << 0),
  27. RTC_SCENE_FLAG_COMPACT = (1 << 1),
  28. RTC_SCENE_FLAG_ROBUST = (1 << 2),
  29. RTC_SCENE_FLAG_CONTEXT_FILTER_FUNCTION = (1 << 3)
  30. };
  31. /* Creates a new scene. */
  32. RTC_API RTCScene rtcNewScene(RTCDevice device);
  33. /* Retains the scene (increments the reference count). */
  34. RTC_API void rtcRetainScene(RTCScene scene);
  35. /* Releases the scene (decrements the reference count). */
  36. RTC_API void rtcReleaseScene(RTCScene scene);
  37. /* Attaches the geometry to a scene. */
  38. RTC_API uniform unsigned int rtcAttachGeometry(RTCScene scene, RTCGeometry geometry);
  39. /* Attaches the geometry to a scene using the specified geometry ID. */
  40. RTC_API void rtcAttachGeometryByID(RTCScene scene, RTCGeometry geometry, uniform unsigned int geomID);
  41. /* Detaches the geometry from the scene. */
  42. RTC_API void rtcDetachGeometry(RTCScene scene, uniform unsigned int geomID);
  43. /* Gets a geometry handle from the scene. */
  44. RTC_API RTCGeometry rtcGetGeometry(RTCScene scene, uniform unsigned int geomID);
  45. /* Commits the scene. */
  46. RTC_API void rtcCommitScene(RTCScene scene);
  47. /* Commits the scene from multiple threads. */
  48. RTC_API void rtcJoinCommitScene(RTCScene scene);
  49. /* Progress monitor callback function */
  50. typedef unmasked uniform bool (*uniform RTCProgressMonitorFunction)(void* uniform ptr, uniform double n);
  51. /* Sets the progress monitor callback function of the scene. */
  52. RTC_API void rtcSetSceneProgressMonitorFunction(RTCScene scene, RTCProgressMonitorFunction progress, void* uniform ptr);
  53. /* Sets the build quality of the scene. */
  54. RTC_API void rtcSetSceneBuildQuality(RTCScene scene, uniform RTCBuildQuality quality);
  55. /* Sets the scene flags. */
  56. RTC_API void rtcSetSceneFlags(RTCScene scene, uniform RTCSceneFlags flags);
  57. /* Returns the scene flags. */
  58. RTC_API uniform RTCSceneFlags rtcGetSceneFlags(RTCScene scene);
  59. /* Returns the axis-aligned bounds of the scene. */
  60. RTC_API void rtcGetSceneBounds(RTCScene scene, uniform RTCBounds* uniform bounds_o);
  61. /* Returns the linear axis-aligned bounds of the scene. */
  62. RTC_API void rtcGetSceneLinearBounds(RTCScene scene, uniform RTCLinearBounds* uniform bounds_o);
  63. /* Intersects a single ray with the scene. */
  64. RTC_API void rtcIntersect1(RTCScene scene, uniform RTCIntersectContext* uniform context, uniform RTCRayHit* uniform rayhit);
  65. /* Intersects a packet of 4 rays with the scene. */
  66. RTC_API void rtcIntersect4(const int* uniform valid, RTCScene scene, const RTCIntersectContext* uniform context, void* uniform rayhit);
  67. /* Intersects a packet of 8 rays with the scene. */
  68. RTC_API void rtcIntersect8(const int* uniform valid, RTCScene scene, const RTCIntersectContext* uniform context, void* uniform rayhit);
  69. /* Intersects a packet of 16 rays with the scene. */
  70. RTC_API void rtcIntersect16(const int* uniform valid, RTCScene scene, const RTCIntersectContext* uniform context, void* uniform rayhit);
  71. /* Intersects a varying ray with the scene. */
  72. RTC_FORCEINLINE void rtcIntersectV(RTCScene scene, uniform RTCIntersectContext* uniform context, varying RTCRayHit* uniform rayhit)
  73. {
  74. varying bool mask = __mask;
  75. unmasked {
  76. varying int imask = mask ? -1 : 0;
  77. }
  78. if (sizeof(varying float) == 16)
  79. rtcIntersect4((uniform int* uniform)&imask, scene, context, rayhit);
  80. else if (sizeof(varying float) == 32)
  81. rtcIntersect8((uniform int* uniform)&imask, scene, context, rayhit);
  82. else if (sizeof(varying float) == 64)
  83. rtcIntersect16((uniform int* uniform)&imask, scene, context, rayhit);
  84. }
  85. /* Intersects a stream of M rays with the scene. */
  86. RTC_API void rtcIntersect1M(RTCScene scene, uniform RTCIntersectContext* uniform context, uniform RTCRayHit* uniform rayhit, uniform unsigned int M, uniform uintptr_t byteStride);
  87. /* Intersects a stream of pointers to M rays with the scene. */
  88. RTC_API void rtcIntersect1Mp(RTCScene scene, uniform RTCIntersectContext* uniform context, uniform RTCRayHit** uniform rayhit, uniform unsigned int M);
  89. /* Intersects a stream of M ray packets of size N in SOA format with the scene. */
  90. RTC_API void rtcIntersectNM(RTCScene scene, uniform RTCIntersectContext* uniform context, struct RTCRayHitN* uniform rayhit, uniform unsigned int N, uniform unsigned int M, uniform uintptr_t byteStride);
  91. /* Intersects a stream of M ray packets of native packet size with the scene. */
  92. RTC_FORCEINLINE void rtcIntersectVM(RTCScene scene, uniform RTCIntersectContext* uniform context, varying RTCRayHit* uniform rayhit, uniform unsigned int M, uniform uintptr_t byteStride) {
  93. rtcIntersectNM(scene, context, (struct RTCRayHitN*)rayhit, sizeof(varying float)/4, M, byteStride);
  94. }
  95. /* Intersects a stream of M ray packets of size N in SOA format with the scene. */
  96. RTC_API void rtcIntersectNp(RTCScene scene, uniform RTCIntersectContext* uniform context, uniform RTCRayHitNp* uniform rayhit, uniform unsigned int N);
  97. /* Tests a single ray for occlusion with the scene. */
  98. RTC_API void rtcOccluded1(RTCScene scene, uniform RTCIntersectContext* uniform context, uniform RTCRay* uniform ray);
  99. /* Tests a packet of 4 rays for occlusion occluded with the scene. */
  100. RTC_API void rtcOccluded4(const uniform int* uniform valid, RTCScene scene, const RTCIntersectContext* uniform context, void* uniform ray);
  101. /* Tests a packet of 8 rays for occlusion occluded with the scene. */
  102. RTC_API void rtcOccluded8(const uniform int* uniform valid, RTCScene scene, const RTCIntersectContext* uniform context, void* uniform ray);
  103. /* Tests a packet of 16 rays for occlusion occluded with the scene. */
  104. RTC_API void rtcOccluded16(const uniform int* uniform valid, RTCScene scene, const RTCIntersectContext* uniform context, void* uniform ray);
  105. /* Tests a varying ray for occlusion with the scene. */
  106. RTC_FORCEINLINE void rtcOccludedV(RTCScene scene, uniform RTCIntersectContext* uniform context, varying RTCRay* uniform ray)
  107. {
  108. varying bool mask = __mask;
  109. unmasked {
  110. varying int imask = mask ? -1 : 0;
  111. }
  112. if (sizeof(varying float) == 16)
  113. rtcOccluded4((uniform int* uniform)&imask, scene, context, ray);
  114. else if (sizeof(varying float) == 32)
  115. rtcOccluded8((uniform int* uniform)&imask, scene, context, ray);
  116. else if (sizeof(varying float) == 64)
  117. rtcOccluded16((uniform int* uniform)&imask, scene, context, ray);
  118. }
  119. /* Tests a stream of M rays for occlusion with the scene. */
  120. RTC_API void rtcOccluded1M(RTCScene scene, uniform RTCIntersectContext* uniform context, uniform RTCRay* uniform ray, uniform unsigned int M, uniform uintptr_t byteStride);
  121. /* Tests a stream of pointers to M rays for occlusion with the scene. */
  122. RTC_API void rtcOccluded1Mp(RTCScene scene, uniform RTCIntersectContext* uniform context, uniform RTCRay** uniform ray, uniform unsigned int M);
  123. /* Tests a stream of M ray packets of size N in SOA format for occlusion with the scene. */
  124. RTC_API void rtcOccludedNM(RTCScene scene, uniform RTCIntersectContext* uniform context, struct RTCRayN* uniform ray, uniform unsigned int N, uniform unsigned int M, uniform uintptr_t byteStride);
  125. /* Tests a stream of M ray packets of native size in SOA format for occlusion with the scene. */
  126. RTC_FORCEINLINE void rtcOccludedVM(RTCScene scene, uniform RTCIntersectContext* uniform context, varying RTCRay* uniform ray, uniform unsigned int M, uniform uintptr_t byteStride) {
  127. rtcOccludedNM(scene, context, (struct RTCRayN*)ray, sizeof(varying float)/4, M, byteStride);
  128. }
  129. /* Tests a stream of M ray packets of size N in SOA format for occlusion with the scene. */
  130. RTC_API void rtcOccludedNp(RTCScene scene, uniform RTCIntersectContext* uniform context, uniform RTCRayNp* uniform ray, uniform unsigned int N);
  131. #endif