Skip to content

Importing native objects

What it does

Natively created objects can be wrapped and used as RI objects through importMemory, importBuffer, importTexture, and importPipeline in each backend's native namespace (RI::Vk or RI::D3D12). Because native handles do not expose all of the metadata RI tracks (for example, Vulkan cannot query how a VkImage was created), you pass a description of the object alongside its native handle.

RI does not own imported objects. Destroying the RI wrapper only forgets it (for an imported texture, RI still frees the views or descriptors it created for that texture); you must destroy or release the native object yourself afterwards. Keep the native object alive while RI is using it—on D3D12, RI does not add a COM reference and holds no ownership.

writeNativeDescriptor writes a native descriptor into a resource slot of a DescriptorHeap for view types that RI does not model directly. On Vulkan, pass a VkDescriptorType (one of the heap's mutable types) together with the matching VkDescriptorImageInfo or VkDescriptorBufferInfo. On D3D12, pass a D3D12_CPU_DESCRIPTOR_HANDLE from a non-shader-visible heap, which RI copies into the shader-visible resource heap.

Rules

  • Imported textures: create the native image or resource to match desc (shape, dimensions, format, mips, layers, samples, optimal tiling on Vulkan, and the Vulkan usage flags or D3D12 resource flags that desc.usage requires), and bind it to memory on Vulkan. Before RI first uses an imported texture, transition it into native(texture).restingLayout yourself inside a native section.
  • Imported buffers: create the native buffer with the usages that desc.usage implies; on Vulkan, also include VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT and bind it to memory so RI can query gpuAddress. Pass the buffer's CPU pointer in mapped if it is mapped, or nullptr otherwise.
  • Imported memory: on Vulkan, allocate the VkDeviceMemory with VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT. Pass the CPU pointer in mapped if the memory is mapped (on D3D12, a CPU address covering the whole ID3D12Heap), or nullptr otherwise. RI can then place buffers and textures in the imported Memory just like any other Memory.
  • Imported pipelines: the native pipeline must use a layout compatible with RI's root data and heaps. On Vulkan, VkPipelineLayout must bind the resource heap at set 0, the sampler heap at set 1, and a single push-constant range covering all shader stages (VK_SHADER_STAGE_ALL) of rootDataSize bytes. On D3D12, the ID3D12RootSignature must have root parameter 0 as root constants (b0, space999) of rootDataSize bytes and use directly indexed heaps; for graphics pipelines, you can also pass the D3D_PRIMITIVE_TOPOLOGY (defaults to D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST).