nCine::RHI::Vulkan::VulkanDevice class

Pipeline-state and draw-call facade of the Vulkan backend (aliased as RHI::Device).

Exposes the OpenGL device's surface (blending, depth, cull, scissor, viewport, clear and the draw calls) so the backend-neutral render pipeline drives it unchanged.

The device also owns the real VkInstance, VkDevice, graphics/present VkQueue and the VkSwapchainKHR created from the SDL window (via CreateSwapchain(), called by the SDL window backend). PresentFrame() acquires a swap-chain image, blits the rendered scene into it and presents it (the buffer-swap equivalent).

Public types

struct ScissorState
struct BlendingState
struct DepthTestState
struct CullFaceState

Public static functions

static void SetBlendingEnabled(bool enabled)
static void SetBlendingFactors(nCine::BlendingFactor srcRgb, nCine::BlendingFactor dstRgb, nCine::BlendingFactor srcAlpha, nCine::BlendingFactor dstAlpha)
static auto GetBlendingState() -> BlendingState
static void SetBlendingState(const BlendingState& state)
static void SetDepthTestEnabled(bool enabled)
static void SetDepthMaskEnabled(bool enabled)
static auto GetDepthTestState() -> DepthTestState
static void SetDepthTestState(const DepthTestState& state)
static void SetCullFaceEnabled(bool enabled)
static auto GetCullFaceState() -> CullFaceState
static void SetCullFaceState(const CullFaceState& state)
static auto GetScissorState() -> ScissorState
static void SetScissorState(const ScissorState& state)
static void SetScissor(const Recti& rect)
static void SetScissorTestEnabled(bool enabled)
static auto GetViewport() -> Recti
static void SetViewport(const Recti& rect)
static void InitViewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height)
static auto GetClearColor() -> Colorf
static void SetClearColor(const Colorf& color)
static void Clear(ClearFlags flags)
static void DrawArrays(PrimitiveType primitive, std::int32_t firstVertex, std::int32_t numVertices)
static void DrawArraysInstanced(PrimitiveType primitive, std::int32_t firstVertex, std::int32_t numVertices, std::int32_t numInstances)
static void DrawElements(PrimitiveType primitive, std::uint32_t numIndices, IndexFormat indexFormat, std::uintptr_t indexOffset, std::int32_t baseVertex)
static void DrawElements(PrimitiveType primitive, std::uint32_t numIndices, std::uintptr_t indexOffset, std::int32_t baseVertex)
static void DrawElementsInstanced(PrimitiveType primitive, std::uint32_t numIndices, IndexFormat indexFormat, std::uintptr_t indexOffset, std::int32_t numInstances, std::int32_t baseVertex)
static void DrawElementsInstanced(PrimitiveType primitive, std::uint32_t numIndices, std::uintptr_t indexOffset, std::int32_t numInstances, std::int32_t baseVertex)
static auto InsertFence() -> FenceHandle
static void DeleteFence(FenceHandle& fence)
static auto ClientWaitFence(FenceHandle fence, std::uint64_t timeoutNs) -> bool
static void SetupInitialState()
static void BindProgram(VulkanShaderProgram* program)
Records the currently bound shader program.
static auto CurrentProgram() -> VulkanShaderProgram*
Returns the currently bound shader program.
static void BindTexture(std::uint32_t unit, const VulkanTexture* texture)
Records the texture bound to a texture unit.
static void UnbindTexture(const VulkanTexture* texture)
Clears a texture from every unit it is bound to (called from ~VulkanTexture to avoid a dangling pointer).
static auto GetBoundTexture(std::uint32_t unit) -> const VulkanTexture*
Returns the texture bound to a texture unit.
static void BindUniformRange(std::uint32_t index, const std::uint8_t* data, std::uint32_t size)
Records the host data range bound to a uniform binding point.
static void UnbindRenderTarget(const VulkanRenderTarget* renderTarget)
Clears a render target from the device if it is the current one (called from ~VulkanRenderTarget).
static void SetRenderTarget(VulkanRenderTarget* renderTarget)
Records the current draw render target (its color attachment 0 receives the pixels).
static void OnShaderProgramDestroyed(VulkanShaderProgram* program)
Drops any cached graphics pipelines keyed on a shader program being destroyed/reset.
static auto currentRenderTargetInternal() -> VulkanRenderTarget*
Returns the currently bound draw render target (nullptr = the screen).
static auto MaxUniformBindingsPublic() -> std::uint32_t
Number of uniform binding slots tracked by BindUniformRange().
static void GetUniformRange(std::uint32_t index, const std::uint8_t*& data, std::uint32_t& size)
Returns the host data range bound to a uniform binding slot.
static auto CreateSwapchain(void* windowHandle, std::int32_t width, std::int32_t height, bool vsync) -> bool
Creates the Vulkan instance, device and swap chain for the given SDL window.
static void DestroySwapchain()
Releases the swap chain, device and instance.
static void ResizeSwapchain(std::int32_t width, std::int32_t height)
Recreates the swap chain at the new drawable size (waits for the device to go idle first).
static void PresentFrame()
Acquires a swap-chain image, blits the rendered scene into it and presents it (the buffer-swap equivalent).
static auto GetMaxTextureDimension() -> std::int32_t
Returns the device's largest supported 2D image dimension (maxImageDimension2D); a safe default before device creation.
static auto GetUniformBufferOffsetAlignment() -> std::int32_t
Returns the device's minimum uniform-buffer bind-offset alignment in bytes (minUniformBufferOffsetAlignment).
static auto GetMaxUniformBufferRange() -> std::int32_t
Returns the device's largest allowed uniform-buffer descriptor range in bytes (maxUniformBufferRange).

Constructors, destructors, conversion operators

VulkanDevice() deleted
~VulkanDevice() deleted

Function documentation

static bool nCine::RHI::Vulkan::VulkanDevice::CreateSwapchain(void* windowHandle, std::int32_t width, std::int32_t height, bool vsync)

Creates the Vulkan instance, device and swap chain for the given SDL window.

Parameters
windowHandle The SDL_Window* (created with SDL_WINDOW_VULKAN), passed as a void* so the window backend does not need the Vulkan headers. The backend queries the required instance extensions and the presentation surface from it through the SDL Vulkan API.
width Swap-chain image width in pixels
height Swap-chain image height in pixels
vsync Whether PresentFrame() presents with vertical sync (FIFO vs. MAILBOX/IMMEDIATE)
Returns true if the instance, device and swap chain were created