Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

LiveAssetIntegration

Zero-copy cross-process GPU asset sharing via Vulkan external memory.

An AI asset generator writes PNG textures into VMA-allocated GPU memory, exports the backing file descriptor via VK_KHR_external_memory_fd, and a game engine plugin in a separate process imports that FD to instantly bind the texture — no disk I/O, no CPU-side copy.

Architecture

┌─────────────────────────┐     Unix Socket (SCM_RIGHTS)   ┌─────────────────────────┐
│   AI Asset Producer     │ ──────────────────────────────► │   Game Engine Consumer  │
│                         │    FD + AssetDescriptor         │                         │
│  1. AI generates PNG    │                                 │  1. Receives FD         │
│  2. Decode to RGBA      │                                 │  2. Imports VkMemory    │
│  3. VMA allocate (ext)  │                                 │  3. Creates VkImage     │
│  4. Upload pixels       │                                 │  4. Binds as texture    │
│  5. Export FD           │                                 │  5. Hot-swaps in scene  │
│  6. Send FD + metadata  │                                 │                         │
└─────────────────────────┘                                 └─────────────────────────┘

Building

# Dependencies: Vulkan SDK (headers vendored), CMake 3.16+, Linux 4.6+
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j$(nproc)

Usage

Terminal 1 — Producer:

./build/lai_producer test_texture.png my_texture_id

Terminal 2 — Consumer:

./build/lai_consumer

The consumer connects to the producer's Unix socket, receives the GPU memory file descriptor, and imports it as a VkImage with VkImageView and VkSampler ready for rendering.

Key Vulkan Extensions

Extension Purpose
VK_KHR_external_memory_fd POSIX FD export/import of VkDeviceMemory
VK_KHR_external_semaphore_fd Cross-process GPU synchronization
VK_KHR_dedicated_allocation Required for reliable FD export

Project Structure

├── include/           # Public API headers
│   ├── lai_types.h    # AssetDescriptor, error codes
│   ├── lai_ipc.h      # Unix socket IPC layer
│   ├── lai_vulkan.h   # Vulkan context with VMA
│   ├── lai_producer.h # Export pipeline
│   └── lai_consumer.h # Import pipeline
├── src/               # Implementation
├── examples/          # Demo producer + consumer
├── third_party/       # Vendored deps (Vulkan-Headers, stb)
└── VulkanMemoryAllocator/  # AMD VMA library

Engine Integration Guide

To use LiveAssetIntegration inside a custom game engine, your engine must create the consumer context manually.

1. CMake Integration

The library supports standard CMake find_package:

find_package(LAI REQUIRED)
target_link_libraries(your_engine PRIVATE LAI::lai_core)

2. Required Engine Extensions

When your engine creates its VkDevice, you must enable these extensions:

  • VK_KHR_external_memory
  • VK_KHR_external_memory_fd
  • VK_KHR_external_semaphore
  • VK_KHR_external_semaphore_fd

3. Populating LaiVulkanContext

You do not need to create a new Vulkan context. Pass your engine's existing state using lai_consumer_create_with_context. Note that the consumer does not need a VMA allocator or command pool.

LaiVulkanContext ctx = {0};
ctx.instance = engine_instance;
ctx.physical_device = engine_physical_device;
ctx.device = engine_device;
ctx.graphics_queue = engine_queue;

// Load the import function
ctx.vkImportSemaphoreFdKHR = (PFN_vkImportSemaphoreFdKHR)vkGetDeviceProcAddr(engine_device, "vkImportSemaphoreFdKHR");

// Query device properties
vkGetPhysicalDeviceMemoryProperties(engine_physical_device, &ctx.mem_properties);

// Extract device UUID
VkPhysicalDeviceIDProperties idp = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES };
VkPhysicalDeviceProperties2 p2 = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, .pNext = &idp };
PFN_vkGetPhysicalDeviceProperties2 gp2 = (PFN_vkGetPhysicalDeviceProperties2)vkGetInstanceProcAddr(engine_instance, "vkGetPhysicalDeviceProperties2");
if (gp2) {
    gp2(engine_physical_device, &p2);
    memcpy(ctx.device_uuid, idp.deviceUUID, VK_UUID_SIZE);
}

LaiConsumer* consumer;
lai_consumer_create_with_context(&ctx, &consumer);

License

MIT

Third-Party Acknowledgements

This project dynamically fetches and builds VulkanMemoryAllocator by AMD. VulkanMemoryAllocator is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages