| 412 | #endif |
| 413 | |
| 414 | bool host_buffer::create_shared_buffer(const bool copy_host_data) { |
| 415 | if (shared_buffer != nullptr && host_shared_buffer == nullptr) { |
| 416 | // wrapping an existing Metal/Vulkan buffer |
| 417 | return true; |
| 418 | } |
| 419 | |
| 420 | // get the render/graphics context so that we can create a buffer (TODO: allow specifying a different context?) |
| 421 | auto render_ctx = floor::get_render_context(); |
| 422 | if (has_flag<MEMORY_FLAG::METAL_SHARING>(flags)) { |
| 423 | if (render_ctx->get_platform_type() != PLATFORM_TYPE::METAL) { |
| 424 | log_error("Host/Metal buffer sharing failed: render context is not Metal"); |
| 425 | return false; |
| 426 | } |
| 427 | } else if (has_flag<MEMORY_FLAG::VULKAN_SHARING>(flags)) { |
| 428 | if (render_ctx->get_platform_type() != PLATFORM_TYPE::VULKAN) { |
| 429 | log_error("Host/Vulkan buffer sharing failed: render context is not Vulkan"); |
| 430 | return false; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | // get the device and its default queue where we want to create the buffer on/in |
| 435 | // NOTE: we never have a corresponding device here, so simply use the fastest device |
| 436 | const device* render_dev = render_ctx->get_device(device::TYPE::FASTEST); |
| 437 | if (render_dev == nullptr) { |
| 438 | log_error("Host <-> Metal/Vulkan buffer sharing failed: failed to find a Metal/Vulkan device"); |
| 439 | return false; |
| 440 | } |
| 441 | |
| 442 | // create the underlying Metal/Vulkan buffer |
| 443 | auto default_queue = render_ctx->get_device_default_queue(*render_dev); |
| 444 | auto shared_buffer_flags = device_memory::make_host_shared_memory_flags(flags, *render_dev, copy_host_data); |
| 445 | host_shared_buffer = (host_data.data() != nullptr ? |
| 446 | render_ctx->create_buffer(*default_queue, host_data, shared_buffer_flags) : |
| 447 | render_ctx->create_buffer(*default_queue, size, shared_buffer_flags)); |
| 448 | if (!host_shared_buffer) { |
| 449 | log_error("Host <-> Metal/Vulkan buffer sharing failed: failed to create the underlying shared Metal/Vulkan buffer"); |
| 450 | return false; |
| 451 | } |
| 452 | host_shared_buffer->set_debug_label("host_shared_buffer"); |
| 453 | shared_buffer = host_shared_buffer.get(); |
| 454 | |
| 455 | return true; |
| 456 | } |
| 457 | |
| 458 | decltype(aligned_ptr<uint8_t>{}.get()) host_buffer::get_host_buffer_ptr_with_sync() const { |
| 459 | #if !defined(FLOOR_NO_METAL) || !defined(FLOOR_NO_VULKAN) |
nothing calls this directly
no test coverage detected