| 294 | } |
| 295 | |
| 296 | Status Runtime::PrepareForExecution() { |
| 297 | if (shared_readonly_buffer_ && !shared_readonly_buffer_->empty()) { |
| 298 | GlBuffer shared_buffer; |
| 299 | RETURN_IF_ERROR( |
| 300 | shared_readonly_buffer_->CreateSharedGlBuffer(&shared_buffer)); |
| 301 | shared_readonly_buffer_.reset(nullptr); |
| 302 | RETURN_IF_ERROR(const_objects_.RegisterBuffer(next_const_id_++, |
| 303 | std::move(shared_buffer))); |
| 304 | } |
| 305 | |
| 306 | if (options_.reuse_internal_objects) { |
| 307 | // Analyze internal objects and make a pool of shared objects to be re-used |
| 308 | // by them. These shared objects need to be allocated upfront. |
| 309 | std::vector<Object> shared_objects; |
| 310 | RETURN_IF_ERROR(AssignInternalObjects(&shared_objects)); |
| 311 | for (const Object& object : shared_objects) { |
| 312 | RETURN_IF_ERROR(AllocateInternalObject(object)); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | // Allocate all internal objects and create bindings for them. |
| 317 | for (auto& program : programs_) { |
| 318 | for (auto& object : program.refs) { |
| 319 | // Check whether it is created already. |
| 320 | BindFunc binding; |
| 321 | ObjectRef ref = GetRef(object); |
| 322 | Status status = MakeBindingFunc(object, ref, internal_objects_, &binding); |
| 323 | if (!status.ok()) { |
| 324 | if (status.code() != StatusCode::kNotFound) { |
| 325 | return status; |
| 326 | } |
| 327 | RETURN_IF_ERROR(AllocateInternalObject(object)); |
| 328 | RETURN_IF_ERROR( |
| 329 | MakeBindingFunc(object, ref, internal_objects_, &binding)); |
| 330 | } |
| 331 | program.bindings.push_back(std::move(binding)); |
| 332 | } |
| 333 | program.refs.clear(); |
| 334 | } |
| 335 | return OkStatus(); |
| 336 | } |
| 337 | |
| 338 | namespace { |
| 339 |
no test coverage detected