RHI (Render Hardware Interface)¶
The RHI layer abstracts the graphics API (e.g. Vulkan) and provides a stable interface for the rest of the engine: resource creation and lifecycle, command recording and submission, and swap chain / presentation.
Scope¶
- Public API: Texture, buffer, sampler handles and create/destroy; command list recording; frame begin/end and present.
- Backends: Vulkan (primary); additional backends may be added later.
- Ownership: Engine module
Visera.RHI; implementation underEngine/Runtime/RHI/.
Key concepts¶
- Handles:
FRHITextureHandle,FRHIBufferHandle,FRHISamplerHandle,FRHIDescriptorSetHandle— opaque IDs for resources managed by the RHI. Descriptor set layout is not exposed at the RHI API: the user providesFRHIDescriptorSetCreateDesc(bindings); RHI derives and caches the layout internally. - Descriptor sets: Create a set with
CreateDescriptorSet(FRHIDescriptorSetCreateDesc)— the create desc carriesBindings(binding, type, count, stages). RHI builds/caches the layout from bindings and returnsFRHIDescriptorSetHandle. Update bindings viaUpdateDescriptorSet(handle, binding, ...)overloads (texture, sampler, buffer). Destroy withDestroyDescriptorSet(handle)(transient or deferred). - Command list: Record draw and transfer commands; submit once per frame (or as needed).
- Frame lifecycle: BeginFrame → record commands → Submit → EndFrame → Present.
Usage (high level)¶
- Obtain the global
FRHIservice (e.g. viaIGlobalService/EName::RHI). - Create resources via
CreateTexture,CreateBuffer,CreateSampler; destroy with the correspondingDestroy*when no longer needed. - For shader resources: fill
FRHIDescriptorSetCreateDescwithFRHIDescriptorSetBindingentries, thenauto setHandle = CreateDescriptorSet(createDesc). CallUpdateDescriptorSet(setHandle, binding, ...)(texture/sampler/buffer overloads). Destroy withDestroyDescriptorSet(setHandle). Layout is managed internally by RHI (cached by bindings hash). - Record commands into an
FRHICommandListand callSubmit(I_CommandList)beforeEndFrame(). - Call
Present()afterEndFrame()to present the swap chain (or omit in offscreen mode).
(This document is maintained by the RHI Engineer agent; expand with API details, backend notes, and examples as the RHI evolves.)