GPU#

namespace gpu#

Typedefs

using CudaStreamHandle = void*#

Opaque handle representing a native CUDA execution stream (cudaStream_t).

Enums

enum class VulkanShaderCompilerMode#

Compiler front-end selection mode when compiling HLSL shaders targeting Vulkan SPIR-V.

Values:

enumerator Auto#

Automatically select DXC if available, falling back to glslang.

enumerator ForceDefault#

Force legacy default compiler (glslang).

enumerator ForceDXC#

Force DirectX Shader Compiler (DXC).

enum class GpuBackend#

Underlying graphics API backend implemented by the GPU device.

Values:

enumerator Null#

Null / mock headless backend for CPU-only testing.

enumerator D3D12#

Direct3D 12 backend (Windows only).

enumerator Vulkan#

Vulkan 1.2+ cross-platform backend (Linux / Windows).

enum class GpuRenderTargetUpdateResult#

Result status returned after updating or recreating offscreen render targets.

Values:

enumerator Failed#

Allocation or configuration failed.

enumerator Unchanged#

Existing render target matched descriptor; no recreation occurred.

enumerator Recreated#

Render target dimensions, formats, or flags changed and textures were recreated.

enum class GpuRenderTargetTexturePlane#

Identifies whether a texture operation targets the color or depth plane of a render target.

Values:

enumerator Color#

Color attachment texture.

enumerator Depth#

Depth/stencil attachment texture.

enum class RenderOutputMode#

Output routing mode for render passes.

Values:

enumerator ManagedPrimary#

Render ColorDepth output to a renderer-managed offscreen target; a chosen camera may then be resolved to the presentation swapchain.

enumerator ExplicitSurface#

Render to an explicitly bound offscreen target surface.

Functions

std::unique_ptr<GpuDevice> createGpuDevice()#

Factory function creating an uninitialized GpuDevice instance.

Returns:

Unique pointer to GpuDevice.

constexpr Diligent::Uint64 contextMaskForId(std::uint32_t contextId) noexcept#

Generates a 64-bit bitmask corresponding to a specific device context identifier.

Parameters:

contextId – Zero-based context index.

Pre:

contextId is less than 64.

Returns:

64-bit bitmask with bit contextId set.

class CudaExternalTimelineSemaphore#
#include <cuda_interop.h>

External timeline semaphore bridging Vulkan/D3D12 GPU timeline fences with CUDA stream synchronization.

Public Functions

CudaExternalTimelineSemaphore()#

Default constructor.

~CudaExternalTimelineSemaphore()#

Destructor releasing fence and semaphore handles.

CudaExternalTimelineSemaphore(const CudaExternalTimelineSemaphore&) = delete#
CudaExternalTimelineSemaphore &operator=(const CudaExternalTimelineSemaphore&) = delete#
bool initialize(Diligent::IRenderDevice *renderDevice, const char *name)#

Allocates an exportable graphics timeline fence on the render device.

Parameters:
  • renderDevice – Graphics device interface.

  • name – Debug identifier for the semaphore.

Returns:

True on success.

void reset()#

Releases the underlying fence and imported CUDA semaphore.

bool isInitialized() const noexcept#

Checks if the timeline semaphore has been allocated on the graphics device.

Returns:

True if initialized.

bool isImportedIntoCuda() const noexcept#

Checks if the external semaphore has been imported into the CUDA driver.

Returns:

True if imported.

bool importIntoCuda()#

Imports the exported native OS handle into the CUDA driver as an external semaphore.

Returns:

True on success.

bool signalOnDeviceContext(Diligent::IDeviceContext *context, std::uint64_t value)#

Queues a graphics-side fence signal on the specified device context.

Parameters:
  • context – Device context executing the signal.

  • value – Monotonically increasing 64-bit value to signal.

Returns:

True on success.

bool waitOnDeviceContext(Diligent::IDeviceContext *context, std::uint64_t value)#

Queues a graphics-side fence wait on the specified device context.

Parameters:
  • context – Device context waiting on the fence.

  • value – 64-bit timeline value to wait for.

Returns:

True on success.

bool signalOnCudaStream(CudaStreamHandle stream, std::uint64_t value)#

Queues a CUDA-side external semaphore signal on the given CUDA stream.

Parameters:
  • stream – Target CUDA stream.

  • value – 64-bit timeline value to signal.

Returns:

True on success.

bool waitOnCudaStream(CudaStreamHandle stream, std::uint64_t value)#

Queues a CUDA-side external semaphore wait on the given CUDA stream.

Parameters:
  • stream – Target CUDA stream.

  • value – 64-bit timeline value to wait for.

Returns:

True on success.

Diligent::IFence *fence() const noexcept#

Gets the underlying Diligent timeline fence pointer.

Returns:

Pointer to Diligent::IFence.

void *cudaSemaphoreHandle() const noexcept#

Gets the imported CUDA external semaphore handle (cudaExternalSemaphore_t).

Returns:

Pointer to CUDA semaphore handle.

Public Static Functions

static bool supportsCudaInteropBuild() noexcept#

Checks if CUDA interop build support is available.

Returns:

True if supported.

class CudaSharedBuffer#
#include <cuda_interop.h>

Imported CUDA device memory view wrapping an exported graphics buffer.

Public Functions

CudaSharedBuffer()#

Default constructor.

~CudaSharedBuffer()#

Destructor releasing imported CUDA memory mappings.

CudaSharedBuffer(const CudaSharedBuffer&) = delete#
CudaSharedBuffer &operator=(const CudaSharedBuffer&) = delete#
bool importFromSharedExportBuffer(const SharedExportBuffer &buffer)#

Imports an exportable graphics buffer into CUDA device memory space.

Parameters:

buffer – Source exportable shared graphics buffer.

Returns:

True on success.

void reset()#

Unmaps and releases the imported CUDA memory.

bool isImported() const noexcept#

Checks if the buffer is currently imported and mapped into CUDA.

Returns:

True if imported.

void *devicePointer() const noexcept#

Retrieves the CUDA linear device memory pointer.

Returns:

Raw device pointer (void *) accessible by CUDA kernels.

std::uint64_t sizeBytes() const noexcept#

Retrieves the size of the mapped device memory in bytes.

Returns:

Buffer size in bytes.

std::int32_t deviceOrdinal() const noexcept#

Retrieves the CUDA device ordinal index hosting the buffer.

Returns:

Zero-based CUDA device index, or -1 when the mapped pointer cannot be queried.

Public Static Functions

static bool supportsCudaInteropBuild() noexcept#

Checks if CUDA interop build support is available.

Returns:

True if supported.

class CudaSharedBufferBridge#
#include <cuda_interop.h>

High-level synchronization bridge managing shared graphics/CUDA buffers, streams, and timeline fences.

Public Functions

CudaSharedBufferBridge()#

Default constructor.

~CudaSharedBufferBridge()#

Destructor releasing bridge resources.

CudaSharedBufferBridge(const CudaSharedBufferBridge&) = delete#
CudaSharedBufferBridge &operator=(const CudaSharedBufferBridge&) = delete#
bool initialize(Diligent::IRenderDevice *renderDevice, const char *name)#

Initializes synchronization timeline semaphores on the graphics device.

Parameters:
  • renderDevice – Graphics device interface.

  • name – Debug identifier.

Returns:

True on success.

void reset()#

Resets bridge state and releases imported buffers and streams.

bool isInitialized() const noexcept#

Checks if the bridge is initialized.

Returns:

True if initialized.

bool bindSharedBuffer(const SharedExportBuffer &buffer)#

Binds and maps an exportable shared graphics buffer into this bridge.

Parameters:

buffer – Source shared export buffer.

Returns:

True on success.

bool synchronizeToDeviceContext(Diligent::IDeviceContext *context)#

Performs a device-wide CUDA synchronization, then signals a fence that graphics waits on.

This conservative synchronization covers CUDA/Torch writes on streams not known to the bridge.

Parameters:

context – Device context to synchronize.

Returns:

True on success.

bool synchronizeFromDeviceContext(Diligent::IDeviceContext *context)#

Signals graphics completion and queues a wait on CUDA’s default stream.

Parameters:

context – Device context executing the graphics work.

Returns:

True on success.

bool copyDeviceToHostAsync(void *dst, const void *src, std::uint64_t sizeBytes)#

Asynchronously copies from the specified CUDA device pointer to host memory via the internal CUDA stream.

Parameters:
  • dst – Destination host memory pointer.

  • src – Source CUDA device pointer.

  • sizeBytes – Transfer size in bytes.

Returns:

True on success.

bool synchronizeStream()#

Synchronizes the internal CUDA stream until all pending CUDA commands complete.

Returns:

True on success.

CudaStreamHandle streamHandle() const noexcept#

Retrieves the internal CUDA stream handle.

Returns:

CUDA stream handle.

void *devicePointer() const noexcept#

Retrieves the CUDA device memory pointer for the bound buffer.

Returns:

Device pointer (void *).

std::uint64_t sizeBytes() const noexcept#

Retrieves the bound buffer size in bytes.

Returns:

Size in bytes.

std::int32_t deviceOrdinal() const noexcept#

Retrieves the CUDA device ordinal hosting the buffer.

Returns:

CUDA device index, or -1 when the mapped pointer cannot be queried.

Public Static Functions

static bool supportsCudaInteropBuild() noexcept#

Checks if CUDA interop is supported in this build.

Returns:

True if supported.

class CudaStream#
#include <cuda_interop.h>

Wrapper encapsulating a CUDA asynchronous stream and execution queue.

Public Functions

CudaStream()#

Default constructor.

~CudaStream()#

Destructor releasing CUDA stream resources.

CudaStream(const CudaStream&) = delete#
CudaStream &operator=(const CudaStream&) = delete#
bool initialize()#

Creates and initializes the underlying CUDA stream.

Returns:

True on success, false on failure or if CUDA interop is unsupported.

void reset()#

Destroys and resets the active CUDA stream.

bool isInitialized() const noexcept#

Checks if the CUDA stream has been successfully initialized.

Returns:

True if initialized.

CudaStreamHandle handle() const noexcept#

Retrieves the raw native CUDA stream handle.

Returns:

Pointer to native cudaStream_t or nullptr.

bool synchronize()#

Blocks the host CPU thread until all queued stream work completes.

Returns:

True on success.

bool copyDeviceToHostAsync(void *dst, const void *src, std::uint64_t sizeBytes)#

Queues an asynchronous device-to-host memory copy on this stream.

Parameters:
  • dst – Destination host memory buffer pointer.

  • src – Source CUDA device memory pointer.

  • sizeBytes – Number of bytes to transfer.

Returns:

True if copy successfully enqueued.

Public Static Functions

static bool supportsCudaInteropBuild() noexcept#

Checks whether the current build configuration supports CUDA interop.

Returns:

True if CUDA interop features are compiled in.

struct GpuBufferBinding#
#include <gpu_compute_pass.h>

Binding descriptor mapping a GPU buffer to a named compute shader resource variable.

Public Members

const char *variableName#

Shader HLSL resource variable name (e.g. g_Positions).

Diligent::IBuffer *buffer = nullptr#

Pointer to target GPU buffer.

Diligent::BUFFER_VIEW_TYPE viewType#

Buffer view type (BUFFER_VIEW_SHADER_RESOURCE or BUFFER_VIEW_UNORDERED_ACCESS).

struct GpuComputeBackendContext#
#include <gpu_types.h>

Hardware compute context bundle passed into asynchronous or immediate compute passes.

Public Members

Diligent::IRenderDevice *renderDevice = nullptr#

Underlying Diligent graphics device.

Diligent::IDeviceContext *computeContext = nullptr#

Active compute device context.

std::uint32_t contextId = 0#

Zero-based context index.

Diligent::COMMAND_QUEUE_TYPE queueType#

Hardware queue category.

class GpuComputePass#
#include <gpu_compute_pass.h>

Wrapper managing a compute pipeline state object (PSO) and reusable shader resource binding (SRB) variants.

Public Functions

bool initialize(GpuDevice &device, Diligent::IShaderSourceInputStreamFactory *streamFactory, Diligent::Uint64 immediateContextMask, const GpuComputePassDefinition &definition)#

Compiles the shader and initializes the compute pipeline state object.

Parameters:
  • device – GPU device reference.

  • streamFactory – Shader file stream provider factory.

  • immediateContextMask – Bitmask of device contexts that can execute this pass.

  • definition – Pass definition containing shader source paths, macros, and variable layouts.

Returns:

False unless exactly one shader source is supplied, streamFactory is non-null, shader/PSO creation succeeds, and the initial SRB can be created.

bool createVariant()#

Creates an additional shader resource binding (SRB) variant for concurrent/distinct parameter sets.

Returns:

True on success.

bool createVariants(std::size_t totalVariantCount)#

Ensures at least a specified total number of SRB variants are allocated.

Parameters:

totalVariantCount – Minimum total number of variants.

Returns:

True on success.

bool forceRecreateAllVariants()#

Forces recreation of all allocated SRB variant instances from the parent PSO.

Returns:

True on success.

inline Diligent::IPipelineState *pipelineState() const#

Retrieves the raw Diligent pipeline state object.

Returns:

Pointer to Diligent::IPipelineState.

inline Diligent::IShaderResourceBinding *defaultSrb() const#

Retrieves the default (index 0) shader resource binding.

Returns:

Pointer to Diligent::IShaderResourceBinding or nullptr.

Diligent::IShaderResourceBinding *variantSrb(std::size_t index) const#

Retrieves the shader resource binding for a specific variant index.

Parameters:

index – Zero-based variant index.

Returns:

Pointer to Diligent::IShaderResourceBinding or nullptr.

template<std::size_t N>
bool bindVariant(std::size_t variantIndex, const std::array<GpuBufferBinding, N> &bindings)#

Binds an array of buffer variables to an SRB variant without dispatching.

Template Parameters:

N – Number of buffer bindings.

Parameters:
  • variantIndex – Target SRB variant index.

  • bindings – Array of buffer bindings.

Returns:

True on success.

template<std::size_t N>
bool dispatch(Diligent::IDeviceContext *computeContext, std::size_t variantIndex, const std::array<GpuBufferBinding, N> &bindings, std::uint32_t groupCountX, std::uint32_t groupCountY = 1u, std::uint32_t groupCountZ = 1u)#

Binds buffer resources and dispatches compute threadgroups.

Template Parameters:

N – Number of buffer bindings.

Parameters:
  • computeContext – Device context to execute dispatch on.

  • variantIndex – SRB variant index.

  • bindings – Array of buffer bindings.

  • groupCountX – Number of threadgroups in X dimension.

  • groupCountY – Number of threadgroups in Y dimension.

  • groupCountZ – Number of threadgroups in Z dimension.

Returns:

True on success.

template<std::size_t N>
bool dispatchIndirect(Diligent::IDeviceContext *computeContext, std::size_t variantIndex, const std::array<GpuBufferBinding, N> &bindings, Diligent::IBuffer *indirectArgsBuffer, Diligent::Uint64 indirectArgsOffset = 0u)#

Binds buffer resources and dispatches indirect compute threadgroups from GPU argument buffer.

Template Parameters:

N – Number of buffer bindings.

Parameters:
  • computeContext – Device context executing dispatch.

  • variantIndex – SRB variant index.

  • bindings – Array of buffer bindings.

  • indirectArgsBuffer – GPU buffer containing dispatch argument counts.

  • indirectArgsOffset – Byte offset into indirect argument buffer.

Returns:

True on success.

template<std::size_t NB, std::size_t NT>
bool dispatchResources(Diligent::IDeviceContext *computeContext, std::size_t variantIndex, const std::array<GpuBufferBinding, NB> &bufferBindings, const std::array<GpuTextureBinding, NT> &textureBindings, std::uint32_t groupCountX, std::uint32_t groupCountY = 1u, std::uint32_t groupCountZ = 1u)#

Binds both buffer and texture resources, committing and dispatching compute threadgroups.

Template Parameters:
  • NB – Number of buffer bindings.

  • NT – Number of texture bindings.

Parameters:
  • computeContext – Device context executing dispatch.

  • variantIndex – SRB variant index.

  • bufferBindings – Array of buffer bindings.

  • textureBindings – Array of texture bindings.

  • groupCountX – Number of threadgroups in X dimension.

  • groupCountY – Number of threadgroups in Y dimension.

  • groupCountZ – Number of threadgroups in Z dimension.

Returns:

True on success.

struct GpuComputePassDefinition#
#include <gpu_compute_pass.h>

Blueprint descriptor for compiling and creating a compute pipeline state object.

Public Members

const char *shaderPath = nullptr#

HLSL file path; set exactly one of this and shaderSource.

const char *shaderName = nullptr#

Debug identifier for the compiled compute shader.

const char *psoName = nullptr#

Debug identifier for the compute pipeline state.

const Diligent::ShaderResourceVariableDesc *variables#

Array of dynamic/mutable shader variable descriptors.

std::size_t variableCount = 0u#

Number of variable descriptors.

const Diligent::ShaderMacro *macros = nullptr#

Preprocessor macro definitions array.

std::size_t macroCount = 0u#

Number of macro definitions.

const char *entryPoint = nullptr#

Entry point function name (e.g. “main” or “CSMain”).

const char *shaderSource = nullptr#

Alternative in-memory HLSL source; mutually exclusive with shaderPath.

class GpuDevice#
#include <gpu_device.h>

Hardware graphics and compute device interface managing resources, contexts, and pipelines.

Public Functions

virtual ~GpuDevice() = default#

Virtual destructor.

virtual bool initialize(const GpuDeviceDesc &desc) = 0#

Initializes the hardware device, creates graphics contexts, and initializes swapchain if enabled.

Parameters:

desc – Initialization descriptor.

Returns:

True on success, false on failure.

virtual void shutdown() = 0#

Destroys all GPU resources and cleanly shuts down the graphics backend.

virtual void beginFrame(const common::FrameContext &frameContext) = 0#

Begins a new rendering and simulation frame.

Note

A second call while a frame is active is ignored.

Parameters:

frameContext – Temporal frame context state.

virtual void endFrame(const common::FrameContext &frameContext) = 0#

Ends the current frame, executing presentation and completing queued readbacks.

Note

A call without a matching beginFrame() is ignored.

Parameters:

frameContext – Temporal frame context state.

virtual GpuRenderTargetSystem &renderTargetSystem() = 0#

Retrieves the offscreen render target management system.

Returns:

Reference to GpuRenderTargetSystem.

virtual GpuBackend backend() const = 0#

Retrieves the active graphics API backend enum.

Returns:

GpuBackend.

virtual bool tryGetGraphicsBackendContext(GpuGraphicsBackendContext &outContext) = 0#

Retrieves the hardware graphics backend context and command queue bundle.

Parameters:

outContext – Output reference to populate.

Returns:

True if graphics context is available.

virtual bool tryGetPhysicsBackendContext(GpuComputeBackendContext &outContext) = 0#

Retrieves the hardware compute backend context dedicated to physics simulation.

Parameters:

outContext – Output reference to populate.

Returns:

True if physics compute context is available.

virtual bool waitForPhysicsOnGraphics() = 0#

Inserts a GPU barrier or semaphore wait synchronizing graphics commands after physics compute commands.

Returns:

True on success.

virtual bool waitForGraphicsOnPhysics() = 0#

Inserts a GPU barrier or semaphore wait synchronizing physics compute commands after graphics commands.

Returns:

True on success.

virtual bool tryGetDefaultRenderTargetDesc(GpuRenderTargetDesc &outDesc) const = 0#

Queries the default render target descriptor configured on this device.

Parameters:

outDesc – Output descriptor to populate.

Returns:

True on success.

virtual bool tryGetPresentationTargetDesc(GpuPresentationTargetDesc &outDesc) = 0#

Queries the geometry and format of the active presentation swapchain.

Parameters:

outDesc – Output descriptor to populate.

Returns:

True if presentation swapchain is active.

virtual GpuPresentationReadbackRequest requestPresentationReadback() = 0#

Enqueues a deferred readback request for the primary presentation frame.

Returns:

Tracking request handle, or an invalid handle when no presentation swapchain is active.

virtual bool tryGetPresentationReadback(GpuPresentationReadbackRequest request, GpuPresentationReadbackEvent &outEvent) = 0#

Attempts to retrieve and consume pixel data for a previously enqueued presentation readback request.

Parameters:
  • request – Tracking handle.

  • outEvent – Output readback event data to populate.

Returns:

True if a completed event was available; false if invalid, incomplete, or already consumed.

virtual bool supportsNativePhysicsFloatAtomics() const = 0#

Checks whether the hardware device supports native floating-point atomic operations in compute shaders.

Returns:

True if native float atomics supported.

virtual const std::string &shaderSourceDirectory() const = 0#

Retrieves the root directory path containing entry-point shaders.

Returns:

String reference to shader directory path.

inline virtual ShaderSourceConfig shaderSourceConfig() const#

Retrieves the active shader source and include paths configuration.

Returns:

ShaderSourceConfig struct.

virtual bool createShader(const Diligent::ShaderCreateInfo &createInfo, Diligent::IShader **shader) = 0#

Compiles and creates a shader object.

Parameters:
  • createInfo – Shader compilation descriptor.

  • shader – Output pointer to receive created shader.

Returns:

True on success.

virtual bool createGraphicsPipelineState(const Diligent::GraphicsPipelineStateCreateInfo &createInfo, Diligent::IPipelineState **pipelineState) = 0#

Creates a graphics pipeline state object (PSO).

Parameters:
  • createInfo – Pipeline state creation descriptor.

  • pipelineState – Output pointer to receive created PSO.

Returns:

True on success.

virtual bool createComputePipelineState(const Diligent::ComputePipelineStateCreateInfo &createInfo, Diligent::IPipelineState **pipelineState) = 0#

Creates a compute pipeline state object (PSO).

Parameters:
  • createInfo – Compute pipeline creation descriptor.

  • pipelineState – Output pointer to receive created compute PSO.

Returns:

True on success.

struct GpuDeviceDesc#
#include <gpu_device.h>

Configuration descriptor for initializing the GPU device and window presentation system.

Public Members

GpuBackend preferredBackend = GpuBackend::Vulkan#

Requested graphics API backend.

bool enableValidation = true#

Enable graphics API debug and validation layers.

GpuRenderTargetDesc defaultRenderTargetDesc = {}#

Default descriptor applied to offscreen rendering passes.

PresentationDesc presentation = {}#

Presentation window and swapchain settings.

VulkanShaderCompilerMode vulkanShaderCompilerMode#

Shader compiler choice for Vulkan.

std::string shaderDirectory#

Root directory for shader source assets (empty resolves build-time default).

std::vector<std::filesystem::path> shaderIncludeDirectories#

Additional ordered search paths for HLSL #include headers.

struct PresentationDesc#
#include <gpu_device.h>

Window swapchain and display presentation configuration.

Public Members

bool enabled = false#

Whether to create and attach a presentation swapchain.

std::uint32_t syncInterval = 1#

Vertical synchronization interval (1 = V-Sync enabled, 0 = immediate presentation).

Diligent::TEXTURE_FORMAT preferredColorFormat#

Preferred swapchain surface color format (TEX_FORMAT_UNKNOWN chooses default).

void *nativeWindow#

Platform native window pointer (HWND on Windows, NSView* on macOS).

std::uint64_t nativeWindowId#

Platform native window ID (Window for X11, xcb_window_t for XCB).

void *nativeDisplay = nullptr#

Platform native display connection (Display* for X11).

void *nativeConnection#

Platform native connection (xcb_connection_t* for XCB).

struct GpuGraphicsBackendContext#
#include <gpu_types.h>

Hardware render context bundle passed into graphics pipeline execution passes.

Public Members

Diligent::IRenderDevice *renderDevice = nullptr#

Underlying Diligent graphics device.

Diligent::IDeviceContext *graphicsContext = nullptr#

Active graphics device context.

Diligent::ISwapChain *primarySwapChain = nullptr#

Primary window presentation swapchain.

std::uint32_t contextId = 0u#

Zero-based context index.

Diligent::COMMAND_QUEUE_TYPE queueType#

Hardware queue category.

GpuRenderTargetBinding activeRenderTargetBinding = {}#

Currently bound offscreen target binding.

bool hasActiveRenderTarget = false#

True if an offscreen target is bound.

bool activeRenderTargetHasDepth = false#

True if bound target has a depth attachment.

Diligent::TEXTURE_FORMAT activeRenderTargetColorFormat#

Bound color format.

struct GpuPresentationReadbackEvent#
#include <gpu_types.h>

Event payload containing pixel data captured from the primary presentation window swapchain.

Public Members

std::uint64_t frameIndex = 0#

Frame index of capture.

Diligent::TEXTURE_FORMAT colorFormat = Diligent::TEX_FORMAT_UNKNOWN#

Color texture format.

std::uint32_t width = 0#

Framebuffer width in pixels.

std::uint32_t height = 0#

Framebuffer height in pixels.

std::uint32_t rowStrideBytes = 0#

Byte stride per scanline row.

std::vector<std::uint8_t> colorBytes = {}#

Raw color bytes encoded according to colorFormat.

struct GpuPresentationReadbackRequest#
#include <gpu_types.h>

Tracking handle for a deferred presentation-swapchain readback request.

Public Members

std::uint64_t id = 0#

Monotonically assigned request identifier.

struct GpuPresentationTargetDesc#
#include <gpu_types.h>

Geometry and format description of the primary presentation swapchain.

Public Members

std::uint32_t width = 0#

Swapchain width in pixels.

std::uint32_t height = 0#

Swapchain height in pixels.

Diligent::TEXTURE_FORMAT colorFormat#

Swapchain color format.

Diligent::TEXTURE_FORMAT depthFormat#

Swapchain depth format.

bool hasDepth = false#

Whether a presentation depth buffer is attached.

struct GpuRenderPassBeginDesc#
#include <gpu_types.h>

Clear values and flags applied when beginning a render pass.

Public Members

bool clearColor = true#

Whether to clear the color attachment upon begin.

bool clearDepth = true#

Whether to clear the depth attachment upon begin.

float clearColorValue[4] = {0.0f, 0.0f, 0.0f, 1.0f}#

RGBA clear color values.

float clearDepthValue = 1.0f#

Depth clear value (typically 1.0 for standard depth).

struct GpuRenderTargetBinding#
#include <gpu_types.h>

Target attachment binding specifying an offscreen target and optional 2D texture array layer range.

Public Functions

inline bool isValid() const noexcept#

Checks whether this binding is structurally valid.

This does not verify that the target exists or that the selected layer range is in bounds.

Returns:

True when the target ID is non-invalid and the layer count is non-zero.

inline bool operator==(const GpuRenderTargetBinding &rhs) const noexcept#

Checks equality between two render target bindings.

Parameters:

rhs – Right-hand side binding to compare.

Returns:

True if both handles and layer ranges match.

Public Members

GpuRenderTargetHandle target = {}#

Bound render target resource handle.

std::uint32_t firstLayer = 0u#

Zero-based index of the first texture array layer.

std::uint32_t layerCount = 1u#

Number of consecutive texture array layers to bind.

struct GpuRenderTargetDesc#
#include <gpu_types.h>

Configuration descriptor for allocating offscreen 2D or 2D-array render targets.

Public Members

std::uint32_t width = 0#

Pixel width (0 uses 1280 for direct target allocation; managed camera outputs resolve it from their destination size).

std::uint32_t height = 0#

Pixel height (0 uses 720 for direct target allocation; managed camera outputs resolve it from their destination size).

std::uint32_t arraySize#

Number of 2D texture array slices (e.g. for multi-camera batched rendering).

bool color = true#

Whether to allocate a color attachment texture.

bool depth = true#

Whether to allocate a depth/stencil attachment texture.

bool layeredRendering#

Enable single-pass multi-layer rendering via geometry/mesh shaders.

Diligent::TEXTURE_FORMAT colorFormat#

Color texture format (TEX_FORMAT_UNKNOWN uses default RGBA16_FLOAT).

Diligent::TEXTURE_FORMAT depthFormat#

Depth texture format.

bool shaderReadable#

Enables shader resource views (SRVs) for sampling in subsequent passes.

bool unorderedAccess#

Enables unordered access views (UAVs) for compute shader writeback.

std::string debugName#

Optional debug name assigned to the GPU texture objects.

struct GpuRenderTargetHandle#
#include <gpu_types.h>

Opaque per-device resource handle for an allocated offscreen render target.

Public Members

common::ResourceId id = common::kInvalidResourceId#

Unique numeric resource identifier.

struct GpuRenderTargetReadbackEvent#
#include <gpu_types.h>

Event payload containing downloaded pixel data copied from an offscreen render target.

Public Members

GpuRenderTargetBinding binding = {}#

Source render target binding.

std::uint64_t frameIndex = 0#

Frame counter at the time of readback capture.

Diligent::TEXTURE_FORMAT colorFormat#

Format of color pixel buffer.

std::uint32_t colorWidth = 0#

Width of color image in pixels.

std::uint32_t colorHeight = 0#

Height of color image in pixels.

std::uint32_t colorRowStrideBytes = 0#

Stride between consecutive rows in bytes.

std::vector<std::uint8_t> colorBytes = {}#

Raw downloaded color byte buffer.

std::uint32_t width = 0#

Legacy alias for color width.

std::uint32_t height = 0#

Legacy alias for color height.

std::uint32_t rowStrideBytes = 0#

Legacy alias for color row stride.

Diligent::TEXTURE_FORMAT depthFormat#

Format of depth pixel buffer.

std::uint32_t depthWidth = 0#

Width of depth image in pixels.

std::uint32_t depthHeight = 0#

Height of depth image in pixels.

std::uint32_t depthRowStrideBytes = 0#

Row stride of depth buffer in bytes.

std::vector<std::uint8_t> depthBytes = {}#

Raw downloaded depth byte buffer.

struct GpuRenderTargetReadbackRequest#
#include <gpu_types.h>

Tracking handle for a deferred offscreen render target readback request.

Public Members

std::uint64_t id = 0#

Monotonically assigned request identifier.

class GpuRenderTargetSystem#
#include <gpu_render_target_system.h>

Subsystem managing offscreen render targets, multi-layer attachments, viewports, and pixel readbacks.

Public Functions

virtual ~GpuRenderTargetSystem() = default#

Virtual destructor.

virtual GpuRenderTargetHandle createRenderTarget(const GpuRenderTargetDesc &desc) = 0#

Allocates an offscreen render target texture set based on the provided descriptor.

Parameters:

desc – Target geometry and texture format specification.

Returns:

Allocated render target handle, or an invalid handle if allocation fails.

virtual GpuRenderTargetUpdateResult resizeRenderTarget(GpuRenderTargetHandle target, std::uint32_t width, std::uint32_t height) = 0#

Resizes an existing render target’s pixel dimensions.

Parameters:
  • target – Handle of the target to resize.

  • width – New width in pixels; zero preserves the current width.

  • height – New height in pixels; zero preserves the current height.

Returns:

GpuRenderTargetUpdateResult status code.

virtual GpuRenderTargetUpdateResult reconfigureRenderTarget(GpuRenderTargetHandle target, const GpuRenderTargetDesc &desc) = 0#

Reconfigures all properties (formats, flags, layers, dimensions) of a render target.

Parameters:
  • target – Handle of the target to reconfigure.

  • desc – Updated target descriptor.

Returns:

GpuRenderTargetUpdateResult status code.

virtual void destroyRenderTarget(GpuRenderTargetHandle target) = 0#

Destroys and deallocates an offscreen render target.

Pending readbacks for the target become completed events with empty pixel payloads.

Parameters:

target – Handle of target to destroy.

virtual bool isValidRenderTarget(GpuRenderTargetHandle target) const = 0#

Checks whether the given target handle refers to an allocated, active render target.

Parameters:

target – Target handle to check.

Returns:

True if valid.

virtual bool tryGetRenderTargetDesc(GpuRenderTargetHandle target, GpuRenderTargetDesc &outDesc) const = 0#

Queries the configuration descriptor of an active render target.

Parameters:
  • target – Handle to inspect.

  • outDesc – Output descriptor to populate.

Returns:

True on success.

virtual void setRenderTargetViewport(const GpuRenderTargetBinding &binding, const GpuRenderViewport &viewport) = 0#

Sets the normalized viewport for subsequent rendering operations targeting this binding.

Parameters:
  • binding – Target binding and layer range.

  • viewport – Normalized viewport rectangle.

virtual void beginRenderTarget(const GpuRenderTargetBinding &binding, const common::FrameContext &frameContext, const GpuRenderPassBeginDesc &beginDesc) = 0#

Binds the render target attachments to the active graphics context and applies clear values.

Parameters:
  • binding – Target binding and layer range.

  • frameContext – Temporal frame context.

  • beginDesc – Clear flags and values.

virtual void endRenderTarget(const GpuRenderTargetBinding &binding, const common::FrameContext &frameContext) = 0#

Unbinds the render target attachments.

Subsequent consumers perform any required resource-state transitions.

Parameters:
  • binding – Target binding.

  • frameContext – Temporal frame context.

virtual GpuRenderTargetReadbackRequest requestRenderTargetReadback(const GpuRenderTargetBinding &binding) = 0#

Queues a render-target readback request. The copy is submitted when the target or frame is ended, and the completed event is materialized during frame finalization.

Parameters:

binding – Target binding to read back.

Returns:

Monotonic tracking request handle, or an invalid handle if the target is unknown or the binding does not select exactly one layer.

virtual bool tryGetRenderTargetReadback(GpuRenderTargetReadbackRequest request, GpuRenderTargetReadbackEvent &outEvent) = 0#

Retrieves and consumes the completed event for a readback request.

Parameters:
  • request – Tracking handle.

  • outEvent – Output readback event payload to populate.

Returns:

True if a completed event was available; false if the request is invalid, unknown, already consumed, or not yet complete.

virtual bool tryGetRenderTargetColorTexture(GpuRenderTargetHandle target, Diligent::ITexture *&outTexture) = 0#

Retrieves the raw Diligent texture pointer for the target’s color attachment.

Parameters:
  • target – Render target handle.

  • outTexture – Output texture reference.

Returns:

True if target has a color attachment.

virtual bool tryGetRenderTargetDepthTexture(GpuRenderTargetHandle target, Diligent::ITexture *&outTexture) = 0#

Retrieves the raw Diligent texture pointer for the target’s depth attachment.

Parameters:
  • target – Render target handle.

  • outTexture – Output texture reference.

Returns:

True if target has a depth attachment.

virtual bool tryGetRenderTargetShaderResourceView(const GpuRenderTargetBinding &binding, GpuRenderTargetTexturePlane plane, Diligent::ITextureView *&outView) = 0#

Retrieves the Diligent shader resource view (SRV) for sampling this target in later passes.

Parameters:
  • binding – Target binding and layer slice.

  • plane – Texture plane (Color or Depth).

  • outView – Output texture view reference.

Returns:

True if SRV is available.

struct GpuRenderViewport#
#include <gpu_types.h>

Normalized viewport rectangle defining the active rendering subregion.

Public Members

float x = 0.0f#

Normalized horizontal origin [0..1] relative to the target width.

float y = 0.0f#

Normalized vertical origin [0..1] relative to the target height.

float width = 1.0f#

Normalized viewport width [0..1].

float height = 1.0f#

Normalized viewport height [0..1].

struct GpuTextureBinding#
#include <gpu_compute_pass.h>

Binding descriptor mapping a GPU texture view to a named compute shader variable.

Public Members

const char *variableName = nullptr#

Shader HLSL variable name.

Diligent::ITextureView *view = nullptr#

Pointer to texture view (SRV or UAV).

struct RenderOutputBinding#
#include <gpu_types.h>

Composite binding pairing an output mode with its associated target binding.

Public Members

RenderOutputMode mode = RenderOutputMode::ManagedPrimary#

Routing destination mode.

GpuRenderTargetBinding binding = {}#

Offscreen target binding (used when mode == ExplicitSurface).

struct ShaderSourceConfig#
#include <shader_source_provider.h>

Configuration settings controlling shader source file paths and #include search roots.

Public Members

std::filesystem::path sourceDirectory#

Root directory containing entry-point shader files.

bool includeSourceDirectory = true#

Automatically adds <sourceDirectory>/include and its subdirectories to include paths.

std::vector<std::filesystem::path> includeDirectories#

Additional search directories checked in order when resolving shader header includes.

class ShaderSourceProvider#
#include <shader_source_provider.h>

Service providing filesystem-backed input stream factories for Diligent shader compilation.

Public Functions

explicit ShaderSourceProvider(ShaderSourceConfig config)#

Constructs a shader source provider using full path configuration.

Parameters:

config – Shader source and include directory configuration.

explicit ShaderSourceProvider(std::string shaderDirectory)#

Compatibility shorthand constructor configuring <shaderDirectory>/include as the include search root.

Parameters:

shaderDirectory – Path string to base shader directory.

~ShaderSourceProvider()#

Destructor.

ShaderSourceProvider(ShaderSourceProvider &&other) noexcept#

Move constructor.

Parameters:

other – Source provider to move from.

ShaderSourceProvider &operator=(ShaderSourceProvider &&other) noexcept#

Move assignment operator.

Parameters:

other – Source provider to move from.

Returns:

Reference to this.

ShaderSourceProvider(const ShaderSourceProvider&) = delete#
ShaderSourceProvider &operator=(const ShaderSourceProvider&) = delete#
Diligent::IShaderSourceInputStreamFactory *streamFactory()#

Retrieves the Diligent input stream factory for compiling shaders with nested includes.

Returns:

Pointer to Diligent::IShaderSourceInputStreamFactory, or nullptr if the source or configured include directories cannot be resolved.

std::filesystem::path sourceDirectory()#

Gets the resolved root directory from which entry-point shaders are loaded.

Returns:

Empty path if source-directory resolution fails.

class SharedExportBuffer#
#include <shared_export_buffer.h>

Structured GPU buffer that attempts native OS-handle sharing across API boundaries.

If native shared allocation is unavailable or fails, allocation falls back to an engine-only Diligent buffer; inspect isExportable() before attempting CUDA import.

Public Functions

SharedExportBuffer()#

Default constructor.

~SharedExportBuffer()#

Destructor releasing the underlying buffer resource.

SharedExportBuffer(const SharedExportBuffer&) = delete#
SharedExportBuffer &operator=(const SharedExportBuffer&) = delete#
bool ensureStructuredBuffer(Diligent::IRenderDevice *renderDevice, const char *name, std::uint32_t elementStride, std::uint32_t requiredElementCount, std::uint32_t minimumCapacity, Diligent::BIND_FLAGS bindFlags, Diligent::USAGE usage, Diligent::CPU_ACCESS_FLAGS cpuAccess, Diligent::Uint64 immediateContextMask, const std::uint32_t *queueFamilyIndices = nullptr, std::uint32_t queueFamilyIndexCount = 0u)#

Ensures a structured buffer of at least the specified element capacity exists, allocating or reallocating if needed.

When the existing buffer already has sufficient capacity and the same element stride, all other creation parameters are retained and the buffer is not recreated.

Parameters:
  • renderDevice – Graphics device interface.

  • name – Debug identifier for the buffer.

  • elementStride – Stride of an individual element in bytes.

  • requiredElementCount – Minimum required element count.

  • minimumCapacity – Capacity floor for power-of-two growth.

  • bindFlags – Buffer binding flags (e.g. BIND_UNORDERED_ACCESS | BIND_SHADER_RESOURCE).

  • usage – Buffer memory usage (e.g. USAGE_DEFAULT).

  • cpuAccess – Allowed CPU access flags.

  • immediateContextMask – Bitmask of device contexts that can access this buffer.

  • queueFamilyIndices – Optional array of Vulkan queue family indices for concurrent sharing.

  • queueFamilyIndexCount – Number of queue family indices.

Returns:

False only when allocation fails or renderDevice/ is invalid. A successful fallback allocation may still be non-exportable.

void reset()#

Releases the underlying GPU buffer.

Diligent::IBuffer *buffer() const noexcept#

Retrieves the raw Diligent buffer pointer.

Returns:

Pointer to Diligent::IBuffer.

const Diligent::RefCntAutoPtr<Diligent::IBuffer> &bufferRef() const noexcept#

Retrieves the reference-counted Diligent buffer smart pointer.

Returns:

Const reference to RefCntAutoPtr<Diligent::IBuffer>.

std::uint32_t capacity() const noexcept#

Retrieves the allocated element capacity.

Returns:

Element capacity.

std::uint32_t elementStride() const noexcept#

Retrieves the element stride in bytes.

Returns:

Byte stride per element.

std::uint64_t sizeBytes() const noexcept#

Retrieves the total buffer size in bytes.

Returns:

Total byte size.

bool isExportable() const noexcept#

Checks if the buffer was created with OS export flags enabled.

Returns:

True if exportable.

bool usesNativeSharedAllocation() const noexcept#

Checks if native shared allocation memory was used.

Returns:

True if native shared allocation active.

Diligent::RENDER_DEVICE_TYPE nativeRenderDeviceType() const noexcept#

Retrieves the native rendering device type hosting this buffer.

Returns:

Diligent::RENDER_DEVICE_TYPE.

namespace interop#
struct NativeHandle#
#include <cuda_interop_types.h>

Platform-specific operating system handle for exported GPU memory sharing.

Public Members

int fd = -1#

POSIX file descriptor for Vulkan memory handle sharing (Opaque Fd).