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 thatdesc.usagerequires), and bind it to memory on Vulkan. Before RI first uses an imported texture, transition it intonative(texture).restingLayoutyourself inside a native section. - Imported buffers: create the native buffer with the usages that
desc.usageimplies; on Vulkan, also includeVK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BITand bind it to memory so RI can querygpuAddress. Pass the buffer's CPU pointer inmappedif it is mapped, ornullptrotherwise. - Imported memory: on Vulkan, allocate the
VkDeviceMemorywithVK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT. Pass the CPU pointer inmappedif the memory is mapped (on D3D12, a CPU address covering the wholeID3D12Heap), ornullptrotherwise. RI can then place buffers and textures in the importedMemoryjust like any otherMemory. - Imported pipelines: the native pipeline must use a layout compatible with RI's root data and
heaps. On Vulkan,
VkPipelineLayoutmust 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) ofrootDataSizebytes. On D3D12, theID3D12RootSignaturemust have root parameter 0 as root constants (b0, space999) ofrootDataSizebytes and use directly indexed heaps; for graphics pipelines, you can also pass theD3D_PRIMITIVE_TOPOLOGY(defaults toD3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST).