| 481 | #endif |
| 482 | |
| 483 | bool host_buffer::create_shared_buffer(const bool copy_host_data) { |
| 484 | if (shared_buffer != nullptr && host_shared_buffer == nullptr) { |
| 485 | // wrapping an existing Metal/Vulkan buffer |
| 486 | return true; |
| 487 | } |
| 488 | |
| 489 | // get the render/graphics context so that we can create a buffer (TODO: allow specifying a different context?) |
| 490 | auto render_ctx = floor::get_render_context(); |
| 491 | if (has_flag<COMPUTE_MEMORY_FLAG::METAL_SHARING>(flags)) { |
| 492 | if (render_ctx->get_compute_type() != COMPUTE_TYPE::METAL) { |
| 493 | log_error("Host/Metal buffer sharing failed: render context is not Metal"); |
| 494 | return false; |
| 495 | } |
| 496 | } else if (has_flag<COMPUTE_MEMORY_FLAG::VULKAN_SHARING>(flags)) { |
| 497 | if (render_ctx->get_compute_type() != COMPUTE_TYPE::VULKAN) { |
| 498 | log_error("Host/Vulkan buffer sharing failed: render context is not Vulkan"); |
| 499 | return false; |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | // get the device and its default queue where we want to create the buffer on/in |
| 504 | // NOTE: we never have a corresponding device here, so simply use the fastest device |
| 505 | const compute_device* render_dev = render_ctx->get_device(compute_device::TYPE::FASTEST); |
| 506 | if (render_dev == nullptr) { |
| 507 | log_error("Host <-> Metal/Vulkan buffer sharing failed: failed to find a Metal/Vulkan device"); |
| 508 | return false; |
| 509 | } |
| 510 | |
| 511 | // create the underlying Metal/Vulkan buffer |
| 512 | auto default_queue = render_ctx->get_device_default_queue(*render_dev); |
| 513 | auto shared_buffer_flags = compute_memory::make_host_shared_memory_flags(flags, *render_dev, copy_host_data); |
| 514 | host_shared_buffer = (host_data.data() != nullptr ? |
| 515 | render_ctx->create_buffer(*default_queue, host_data, shared_buffer_flags) : |
| 516 | render_ctx->create_buffer(*default_queue, size, shared_buffer_flags)); |
| 517 | if (!host_shared_buffer) { |
| 518 | log_error("Host <-> Metal/Vulkan buffer sharing failed: failed to create the underlying shared Metal/Vulkan buffer"); |
| 519 | return false; |
| 520 | } |
| 521 | host_shared_buffer->set_debug_label("host_shared_buffer"); |
| 522 | shared_buffer = host_shared_buffer.get(); |
| 523 | |
| 524 | return true; |
| 525 | } |
| 526 | |
| 527 | decltype(aligned_ptr<uint8_t>{}.get()) host_buffer::get_host_buffer_ptr_with_sync() const { |
| 528 | #if !defined(FLOOR_NO_METAL) || !defined(FLOOR_NO_VULKAN) |
nothing calls this directly
no test coverage detected