MCPcopy Create free account
hub / github.com/evilsocket/cake / alloc_mapped_buffer

Method alloc_mapped_buffer

cake-core/src/backends/vulkan/mod.rs:472–517  ·  view source on GitHub ↗
(
        device: &ash::Device,
        allocator: &mut gpu_allocator::vulkan::Allocator,
        size: u64,
        usage: vk::BufferUsageFlags,
        _uma_memory_type: Option<u32>,
    )

Source from the content-addressed store, hash-verified

470 // ── Buffer allocation ────────────────────────────────────────────
471
472 fn alloc_mapped_buffer(
473 device: &ash::Device,
474 allocator: &mut gpu_allocator::vulkan::Allocator,
475 size: u64,
476 usage: vk::BufferUsageFlags,
477 _uma_memory_type: Option<u32>,
478 ) -> std::result::Result<MappedBuffer, String> {
479 let buf_ci = vk::BufferCreateInfo::default()
480 .size(size.max(256))
481 .usage(usage)
482 .sharing_mode(vk::SharingMode::EXCLUSIVE);
483 let buffer = unsafe {
484 device
485 .create_buffer(&buf_ci, None)
486 .map_err(|e| format!("create_buffer: {e}"))?
487 };
488 let requirements = unsafe { device.get_buffer_memory_requirements(buffer) };
489
490 let allocation = allocator
491 .allocate(&gpu_allocator::vulkan::AllocationCreateDesc {
492 name: "cake-buf",
493 requirements,
494 location: gpu_allocator::MemoryLocation::CpuToGpu,
495 linear: true,
496 allocation_scheme: gpu_allocator::vulkan::AllocationScheme::GpuAllocatorManaged,
497 })
498 .map_err(|e| format!("allocate: {e}"))?;
499
500 unsafe {
501 device
502 .bind_buffer_memory(buffer, allocation.memory(), allocation.offset())
503 .map_err(|e| format!("bind_buffer_memory: {e}"))?;
504 }
505
506 let mapped_ptr = allocation
507 .mapped_ptr()
508 .ok_or("buffer not mapped — UMA required")?
509 .as_ptr() as *mut u8;
510
511 Ok(MappedBuffer {
512 buffer,
513 allocation,
514 mapped_ptr,
515 size: size.max(256),
516 })
517 }
518
519 fn alloc_output(&self, count: usize) -> MappedBuffer {
520 let bytes = (count * 4) as u64;

Callers

nothing calls this directly

Calls 1

as_ptrMethod · 0.80

Tested by

no test coverage detected