| 147 | } |
| 148 | |
| 149 | void run() override { |
| 150 | try { |
| 151 | vulkan_cmd_completion_handler::cmd_t cmd {}; |
| 152 | for (uint32_t run = 0; ; ++run) { |
| 153 | { |
| 154 | // wait until we have new work, |
| 155 | // time out after 500ms in case everything is being shut down or halted |
| 156 | std::unique_lock<std::mutex> work_lock_guard(handler.work_cv_lock); |
| 157 | if (run == 0) { |
| 158 | // if this is the first run/iteration, we haven't completed any work/cmd yet |
| 159 | if (handler.work_cv.wait_for(work_lock_guard, 500ms) == std::cv_status::timeout) { |
| 160 | return; // -> return to thread_base and (potentially) run again |
| 161 | } |
| 162 | } |
| 163 | // else: run 1+: just completed work, immediately retry to get new work w/o waiting on the CV |
| 164 | |
| 165 | // get work/cmd if there is any, otherwise return and retry |
| 166 | if (!handler.has_work()) { |
| 167 | return; |
| 168 | } |
| 169 | cmd = handler.get_work(); |
| 170 | } |
| 171 | |
| 172 | // wait on cmd |
| 173 | vulkan_complete_cmd_buffer(*cmd.pool, *cmd.vk_dev, std::move(cmd.cmd_buffer), cmd.work_sema, cmd.work_sema_signal_value, |
| 174 | std::move(cmd.completion_handler)); |
| 175 | } |
| 176 | } catch (std::exception& exc) { |
| 177 | log_error("exception during $ work execution: $", thread_name, exc.what()); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | void start() { |
| 182 | thread_base::start(); |