| 131 | } |
| 132 | |
| 133 | void run() override { |
| 134 | try { |
| 135 | vulkan_cmd_completion_handler::cmd_t cmd {}; |
| 136 | for (uint32_t run = 0; ; ++run) { |
| 137 | { |
| 138 | // wait until we have new work, |
| 139 | // time out after 500ms in case everything is being shut down or halted |
| 140 | unique_lock<mutex> work_lock_guard(handler.work_cv_lock); |
| 141 | if (run == 0) { |
| 142 | // if this is the first run/iteration, we haven't completed any work/cmd yet |
| 143 | if (handler.work_cv.wait_for(work_lock_guard, 500ms) == cv_status::timeout) { |
| 144 | return; // -> return to thread_base and (potentially) run again |
| 145 | } |
| 146 | } |
| 147 | // else: run 1+: just completed work, immediately retry to get new work w/o waiting on the CV |
| 148 | |
| 149 | // get work/cmd if there is any, otherwise return and retry |
| 150 | if (!handler.has_work()) { |
| 151 | return; |
| 152 | } |
| 153 | cmd = handler.get_work(); |
| 154 | } |
| 155 | |
| 156 | // wait on cmd |
| 157 | vulkan_complete_cmd_buffer(*cmd.pool, *cmd.vk_dev, std::move(cmd.cmd_buffer), cmd.fence, std::move(cmd.completion_handler)); |
| 158 | } |
| 159 | } catch (exception& exc) { |
| 160 | log_error("exception during $ work execution: $", thread_name, exc.what()); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | void start() { |
| 165 | thread_base::start(); |