| 103 | } |
| 104 | |
| 105 | void 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 | |
| 146 | void eagerCreate(LazyGeometry* instance) |
| 147 | { |
no test coverage detected