MCPcopy Create free account
hub / github.com/RenderKit/embree / lazyCreate

Function lazyCreate

tutorials/lazy_geometry/lazy_geometry_device.cpp:105–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105void lazyCreate(LazyGeometry* instance)
106{
107 const bool join_commit_supported = rtcGetDeviceProperty(g_device,RTC_DEVICE_PROPERTY_JOIN_COMMIT_SUPPORTED);
108 const bool parallel_commit_supported = rtcGetDeviceProperty(g_device,RTC_DEVICE_PROPERTY_PARALLEL_COMMIT_SUPPORTED);
109
110 /* one thread will switch the object from the LAZY_INVALID state to the LAZY_CREATE state */
111 if (atomic_cmpxchg((int32_t*)&instance->state,LAZY_INVALID,LAZY_CREATE) == 0)
112 {
113 /* create the geometry */
114 //printf("creating sphere %i (lazy)\n",instance->userID);
115 instance->object = rtcNewScene(g_device);
116 createTriangulatedSphere(instance->object,instance->center,instance->radius);
117
118 /* when no parallel commit mode at all is supported let only a single thread build */
119 if (!join_commit_supported && !parallel_commit_supported)
120 rtcCommitScene(instance->object);
121
122 /* now switch to the LAZY_COMMIT state */
123 __memory_barrier();
124 instance->state = LAZY_COMMIT;
125 }
126 else
127 {
128 /* wait until the geometry got created */
129 while (atomic_cmpxchg((int32_t*)&instance->state,10,11) < LAZY_COMMIT) {
130 // instead of actively spinning here, best use a condition to let the thread sleep, or let it help in the creation stage
131 }
132 }
133
134 /* if we support rtcCommit to get called from multiple threads, then this should be preferred for performance reasons */
135 if (parallel_commit_supported)
136 rtcCommitScene(instance->object);
137
138 /* otherwise we could fallback to rtcJoinCommit scene, which has lower performance */
139 else if (join_commit_supported)
140 rtcJoinCommitScene(instance->object);
141
142 /* switch to LAZY_VALID state */
143 atomic_cmpxchg((int32_t*)&instance->state,LAZY_COMMIT,LAZY_VALID);
144}
145
146void eagerCreate(LazyGeometry* instance)
147{

Callers 2

instanceIntersectFuncNFunction · 0.85
instanceOccludedFuncNFunction · 0.85

Calls 6

rtcGetDevicePropertyFunction · 0.85
atomic_cmpxchgFunction · 0.85
rtcNewSceneFunction · 0.85
rtcCommitSceneFunction · 0.85
rtcJoinCommitSceneFunction · 0.85
createTriangulatedSphereFunction · 0.70

Tested by

no test coverage detected