XII Release 0.1.0
Loading...
Searching...
No Matches
xiiRenderContext Class Reference

Provides an interface for issuing GPU rendering and compute commands within a single rendering scope. More...

#include <RenderContext.h>

Public Types

enum class  RenderContextScope : xiiUInt8 { None = 0 , Graphics = 1 , Compute = 2 }
 Specifies the context scope in which rendering commands can be issued. More...
 

Public Member Functions

 xiiRenderContext (xiiSharedPtr< xiiGALCommandList > pCommandList)
 Initializes the render context with a command list.
 
 ~xiiRenderContext ()
 Cleans up stateful bindings.
 
void BeginRendering (const xiiRenderingSetup &renderingSetup, const xiiRectFloat &viewport, xiiStringView sName={}, bool bStereoRendering=false)
 Begins a graphics render pass with the given setup and viewport.
 
void EndRendering ()
 Ends the current rendering scope.
 
void BeginCompute (xiiStringView sName={})
 Begins a compute dispatch scope.
 
void EndCompute ()
 Ends the current compute dispatch scope.
 
void SetShaderPermutationVariable (xiiStringView sName, const xiiTempHashedString &sValue)
 Sets a shader permutation variable (string-based).
 
void SetShaderPermutationVariable (const xiiHashedString &sName, const xiiHashedString &sValue)
 Sets a shader permutation variable (hashed key).
 
void BindConstantBuffer (const xiiTempHashedString &sSlotName, xiiSharedPtr< xiiGALBuffer > pConstantBuffer)
 Binds a constant buffer to a shader slot.
 
void BindBufferView (const xiiTempHashedString &sSlotName, xiiSharedPtr< xiiGALBufferView > pBufferView)
 Binds a buffer view as a shader resource.
 
void BindTextureView (const xiiTempHashedString &sSlotName, xiiSharedPtr< xiiGALTextureView > pTextureView)
 Binds a texture view as a shader resource.
 
void BindSampler (const xiiTempHashedString &sSlotName, xiiSharedPtr< xiiGALSampler > pSampler)
 Binds a sampler state to a shader slot.
 
void BindBufferViewUAV (const xiiTempHashedString &sSlotName, xiiSharedPtr< xiiGALBufferView > pBufferView)
 Binds a buffer view as an unordered access view (UAV).
 
void BindTextureViewUAV (const xiiTempHashedString &sSlotName, xiiSharedPtr< xiiGALTextureView > pTextureView)
 Binds a texture view as an unordered access view (UAV).
 
void BindTexture2D (const xiiTempHashedString &sSlotName, const xiiTexture2DResourceHandle &hTexture, xiiResourceAcquireMode acquireMode=xiiResourceAcquireMode::AllowLoadingFallback)
 Binds a 2D texture resource to a shader slot.
 
void BindTexture3D (const xiiTempHashedString &sSlotName, const xiiTexture3DResourceHandle &hTexture, xiiResourceAcquireMode acquireMode=xiiResourceAcquireMode::AllowLoadingFallback)
 Binds a 3D texture resource to a shader slot.
 
void BindTextureCube (const xiiTempHashedString &sSlotName, const xiiTextureCubeResourceHandle &hTexture, xiiResourceAcquireMode acquireMode=xiiResourceAcquireMode::AllowLoadingFallback)
 Binds a cube texture resource to a shader slot.
 
void BindMaterial (const xiiMaterialResourceHandle &hMaterial)
 Binds a material, including shader and its parameters.
 
void BindShader (const xiiShaderResourceHandle &hShader, xiiBitflags< xiiShaderBindFlags > flags=xiiShaderBindFlags::Default)
 Sets the shader for the next rendering or compute call.
 
void SetBlendState (xiiSharedPtr< xiiGALBlendState > pBlendState)
 Sets the blend state for the graphics pipeline.
 
void SetDepthStencilState (xiiSharedPtr< xiiGALDepthStencilState > pDepthStencilState)
 Sets the depth-stencil state for the graphics pipeline to control depth and stencil testing behavior..
 
void SetRasterizerState (xiiSharedPtr< xiiGALRasterizerState > pRasterizerState)
 Sets the rasterizer state for the graphics pipeline.
 
void BindMeshBuffer (const xiiDynamicMeshBufferResourceHandle &hDynamicMeshBuffer)
 Binds a dynamic mesh buffer for rendering.
 
void BindMeshBuffer (const xiiMeshBufferResourceHandle &hMeshBuffer)
 Binds a static mesh buffer for rendering.
 
void BindMeshBuffer (xiiSharedPtr< xiiGALBuffer > pVertexBuffer0, xiiSharedPtr< xiiGALBuffer > pIndexBuffer, const xiiInputLayoutInfo *pInputLayoutInfo, xiiEnum< xiiGALPrimitiveTopology > topology, xiiUInt32 uiPrimitiveCount, xiiArrayPtr< xiiSharedPtr< xiiGALBuffer > > pVertexBuffers={})
 Binds raw GPU buffers with custom vertex/index layout.
 
xiiResult DrawMeshBuffer (xiiUInt32 uiPrimitiveCount=0xFFFFFFFFU, xiiUInt32 uiFirstPrimitive=0U, xiiUInt32 uiInstanceCount=1U)
 Issues a draw call for the currently bound mesh buffer.
 
xiiResult Dispatch (xiiUInt32 uiThreadGroupCountX, xiiUInt32 uiThreadGroupCountY=1U, xiiUInt32 uiThreadGroupCountZ=1U)
 Dispatches a compute shader with the given thread group counts.
 
xiiResult ApplyContextStates (bool bForce=false)
 Applies all currently bound states to the GPU context.
 
void ResetContextState ()
 Resets all context bindings and internal states.
 
XII_ALWAYS_INLINE xiiGALCommandListGetCommandList () const
 Returns the command list in use by this render context.
 
XII_ALWAYS_INLINE RenderContextScope GetRenderContextScope () const
 Returns the current render context scope.
 
XII_ALWAYS_INLINE xiiGlobalConstants * GetGlobalConstants () const
 Returns the global constant buffer that is used to store this render context global state.
 
XII_ALWAYS_INLINE bool GetAllowAsyncShaderLoading () const
 Returns async shader loading. During runtime all shaders should be preloaded so this is off by default.
 
XII_ALWAYS_INLINE void SetAllowAsyncShaderLoading (bool bAllow)
 Enables or disables asynchronous shader loading.
 
XII_ALWAYS_INLINE void BindBuffer (const xiiTempHashedString &sSlotName, xiiSharedPtr< xiiGALBuffer > pBuffer)
 Binds a buffer to the specified shader slot as a shader resource view (SRV).
 
XII_ALWAYS_INLINE void BindTexture (const xiiTempHashedString &sSlotName, xiiSharedPtr< xiiGALTexture > pTexture)
 Binds a texture to the specified shader slot as a shader resource view (SRV).
 
XII_ALWAYS_INLINE void BindBufferUAV (const xiiTempHashedString &sSlotName, xiiSharedPtr< xiiGALBuffer > pBuffer)
 Binds a buffer to the specified shader slot as an unordered access view (UAV).
 
XII_ALWAYS_INLINE void BindTextureUAV (const xiiTempHashedString &sSlotName, xiiSharedPtr< xiiGALTexture > pTexture)
 Binds a texture to the specified shader slot as an unordered access view (UAV).
 
XII_ALWAYS_INLINE void BindNullMeshBuffer (xiiEnum< xiiGALPrimitiveTopology > topology, xiiUInt32 uiPrimitiveCount)
 Binds a null mesh buffer to the pipeline for procedural or indirect drawing.
 

Static Public Member Functions

static xiiGALSamplerCreationDescription GetDefaultSamplerDescription (xiiBitflags< xiiDefaultSamplerFlags > flags)
 Retrieves a default sampler creation description based on the given flags.
 

Detailed Description

Provides an interface for issuing GPU rendering and compute commands within a single rendering scope.

The render context encapsulates a command list and simplifies binding resources, setting up shaders, and issuing draw or dispatch commands.

Typical usage:

xiiRenderContext context(pCommandList);
context.BeginRendering(setup, viewport);
context.BindShader(hShader);
context.BindMaterial(hMaterial);
context.DrawMeshBuffer();
context.EndRendering();
xiiRenderContext(xiiSharedPtr< xiiGALCommandList > pCommandList)
Initializes the render context with a command list.
Definition RenderContext.cpp:15

Member Enumeration Documentation

◆ RenderContextScope

enum class xiiRenderContext::RenderContextScope : xiiUInt8
strong

Specifies the context scope in which rendering commands can be issued.

Used to distinguish whether a render context is currently being used for graphics rendering, compute work, or is inactive. This allows the renderer to enforce valid command usage based on scope.

Enumerator
None 

No rendering scope is active. Commands are not currently allowed.

Graphics 

Graphics pipeline scope. Allows drawing, shading, and general render operations.

Compute 

Compute pipeline scope. Allows compute shader dispatch and related GPU work.

Member Function Documentation

◆ ApplyContextStates()

xiiResult xiiRenderContext::ApplyContextStates ( bool bForce = false)

Applies all currently bound states to the GPU context.

Parameters
bForceForces binding even if the state hasn't changed.

◆ BeginCompute()

void xiiRenderContext::BeginCompute ( xiiStringView sName = {})

Begins a compute dispatch scope.

Parameters
sNameOptional debug label.

◆ BeginRendering()

void xiiRenderContext::BeginRendering ( const xiiRenderingSetup & renderingSetup,
const xiiRectFloat & viewport,
xiiStringView sName = {},
bool bStereoRendering = false )

Begins a graphics render pass with the given setup and viewport.

Parameters
renderingSetupDefines attachments and render pass config.
viewportDefines the screen space region to render to.
sNameOptional debug label.
bStereoRenderingWhether stereo viewports are used.

◆ BindBuffer()

XII_ALWAYS_INLINE void xiiRenderContext::BindBuffer ( const xiiTempHashedString & sSlotName,
xiiSharedPtr< xiiGALBuffer > pBuffer )
inline

Binds a buffer to the specified shader slot as a shader resource view (SRV).

Internally retrieves the default shader resource view from the buffer and passes it to BindBufferView().

Parameters
sSlotName- The name of the shader slot.
pBuffer- The buffer to bind.

◆ BindBufferUAV()

XII_ALWAYS_INLINE void xiiRenderContext::BindBufferUAV ( const xiiTempHashedString & sSlotName,
xiiSharedPtr< xiiGALBuffer > pBuffer )
inline

Binds a buffer to the specified shader slot as an unordered access view (UAV).

Internally retrieves the default UAV view from the buffer and passes it to BindBufferViewUAV().

Parameters
sSlotName- The name of the shader slot.
pBuffer- The buffer to bind as UAV.

◆ BindMeshBuffer()

void xiiRenderContext::BindMeshBuffer ( xiiSharedPtr< xiiGALBuffer > pVertexBuffer0,
xiiSharedPtr< xiiGALBuffer > pIndexBuffer,
const xiiInputLayoutInfo * pInputLayoutInfo,
xiiEnum< xiiGALPrimitiveTopology > topology,
xiiUInt32 uiPrimitiveCount,
xiiArrayPtr< xiiSharedPtr< xiiGALBuffer > > pVertexBuffers = {} )

Binds raw GPU buffers with custom vertex/index layout.

Allows procedural or non-resource-backed geometry.

◆ BindNullMeshBuffer()

XII_ALWAYS_INLINE void xiiRenderContext::BindNullMeshBuffer ( xiiEnum< xiiGALPrimitiveTopology > topology,
xiiUInt32 uiPrimitiveCount )
inline

Binds a null mesh buffer to the pipeline for procedural or indirect drawing.

Useful when drawing primitives without explicit vertex/index buffers, such as fullscreen passes.

Parameters
topology- The type of primitive topology to use.
uiPrimitiveCount- The number of primitives to render.

◆ BindShader()

void xiiRenderContext::BindShader ( const xiiShaderResourceHandle & hShader,
xiiBitflags< xiiShaderBindFlags > flags = xiiShaderBindFlags::Default )

Sets the shader for the next rendering or compute call.

Parameters
hShader- The shader to bind.
flags- Optional binding flags.

◆ BindTexture()

XII_ALWAYS_INLINE void xiiRenderContext::BindTexture ( const xiiTempHashedString & sSlotName,
xiiSharedPtr< xiiGALTexture > pTexture )
inline

Binds a texture to the specified shader slot as a shader resource view (SRV).

Internally retrieves the default shader resource view from the texture and passes it to BindTextureView().

Parameters
sSlotName- The name of the shader slot.
pTexture- The texture to bind.

◆ BindTextureUAV()

XII_ALWAYS_INLINE void xiiRenderContext::BindTextureUAV ( const xiiTempHashedString & sSlotName,
xiiSharedPtr< xiiGALTexture > pTexture )
inline

Binds a texture to the specified shader slot as an unordered access view (UAV).

Internally retrieves the default UAV view from the texture and passes it to BindTextureViewUAV().

Parameters
sSlotName- The name of the shader slot.
pTexture- The texture to bind as UAV.

◆ DrawMeshBuffer()

xiiResult xiiRenderContext::DrawMeshBuffer ( xiiUInt32 uiPrimitiveCount = 0xFFFFFFFFU,
xiiUInt32 uiFirstPrimitive = 0U,
xiiUInt32 uiInstanceCount = 1U )

Issues a draw call for the currently bound mesh buffer.

Parameters
uiPrimitiveCountOptional override for draw range.
uiFirstPrimitiveStarting primitive index.
uiInstanceCountNumber of instances to render.

◆ GetDefaultSamplerDescription()

xiiGALSamplerCreationDescription xiiRenderContext::GetDefaultSamplerDescription ( xiiBitflags< xiiDefaultSamplerFlags > flags)
static

Retrieves a default sampler creation description based on the given flags.

This utility function returns commonly used sampler settings such as filtering and addressing modes, derived from the specified flags.

Parameters
flagsBitflags that define the characteristics of the sampler.
Returns
A sampler creation description that matches the requested features.

◆ SetAllowAsyncShaderLoading()

XII_ALWAYS_INLINE void xiiRenderContext::SetAllowAsyncShaderLoading ( bool bAllow)
inline

Enables or disables asynchronous shader loading.

During runtime, all shaders should ideally be preloaded. Enabling async shader loading allows shaders to be loaded in the background. This is disabled by default for stability and predictability.

Parameters
bAllow- If true, asynchronous shader loading is enabled; otherwise, it is disabled.

◆ SetBlendState()

void xiiRenderContext::SetBlendState ( xiiSharedPtr< xiiGALBlendState > pBlendState)

Sets the blend state for the graphics pipeline.

Parameters
pBlendState- A shared pointer to the blend state object to be used.

◆ SetDepthStencilState()

void xiiRenderContext::SetDepthStencilState ( xiiSharedPtr< xiiGALDepthStencilState > pDepthStencilState)

Sets the depth-stencil state for the graphics pipeline to control depth and stencil testing behavior..

Parameters
pDepthStencilState- A shared pointer to the depth-stencil state object to be used.

◆ SetRasterizerState()

void xiiRenderContext::SetRasterizerState ( xiiSharedPtr< xiiGALRasterizerState > pRasterizerState)

Sets the rasterizer state for the graphics pipeline.

Parameters
pRasterizerState- A shared pointer to the rasterizer state object to be used.

The documentation for this class was generated from the following files: