Rendering backends
How the command list reaches your GPU. What the engine hands over, the base class you derive from, and the backends that exist today.
The engine does not draw. A UIView turns a page into a HarrlowCommandList, and a render
context that your title provides turns that list into draws on your graphics API. This page covers
what is in the list, the base class the package gives you, and what exists today.
The command list
view.tick(deltaSeconds);
const auto& commands = view.buildCommandList();
renderContext->SubmitHarrlowCommands(commands); // renderContext: APHIRenderContext*SubmitHarrlowCommands is a public pure virtual function on
aperture::harrlow::renderpath::APHIRenderContext. Call it through that type: on
SimpleAPHIRenderContext it is protected. Give the view the same context with
setRenderPathContext(renderContext) so it can acquire off-screen targets for opacity groups,
filters, masks and blend modes (see Your own C++ host).
A HarrlowCommandList holds HarrlowDrawCommand entries, sorted by layer and then by draw order.
Each command is geometry plus the state to draw it with:
- Vertices and 16-bit indices, and the
shapeType: plain shapes, text (bitmap, signed-distance field or vector glyph), anti-aliased edges, border rings, and shapes that the fragment shader evaluates (SDFBorder,SDFBoxShadow,SDFBackground,SDFShape). Box shadows are emitted asSDFBoxShadowby default: a quad plus the shadow's parameters, which only a shader that evaluates the shape turns into a shadow. A backend that does not has the bare quad to draw. - A texture handle with UV rectangle, a scissor rectangle and rounded-corner clip, and the blend
state as a packed
blendKey. - Optional gradient parameters (up to 16 stops, linear, radial or conic), CSS filter effects, a
clip path for stencil clipping, a
mix-blend-mode, an SDF primitive description, and a 4x4 transform that the GPU applies. - A bounding box for culling.
CullOffScreen()drops commands that are outside the viewport.
The list also carries layerFilters, layerOpacity and layerBlendMode for a group that
renders into its own target and is composited back. If you derive from SimpleAPHIRenderContext
you do not read the commands yourself: the base class walks the list, batches it, handles layers
and calls your overrides.
A texture handle is not always a texture. Vector-glyph text carries none: its vertices point into
curve data that the font engine owns. Atlas text carries a pointer to a HarrlowVG::Atlas. Images,
canvases, SVG and Lottie animations carry an opaque surface handle. Video carries three YUV planes.
The base class resolves surface handles and calls your upload overrides. Glyph data is the host's
job, see Text.
What exists today
APHarrlow/RenderPath in the package holds the render interfaces (APHIRenderContext and its
resource types), supporting classes such as the scratch texture pool, and one concrete context,
SimpleAPHIRenderContext, a reference base. Its resource functions return empty objects and its
drawing functions do nothing, so it draws nothing by itself. There is no backend in the engine DLLs.
These are the backends that exist:
| Backend | Where it lives | Notes |
|---|---|---|
| Direct3D 11 | APPlayerD3D11Context, in the engine source tree | APPlayer's default. Derives from SimpleAPHIRenderContext. Layers and filters use compute shaders. It supports MSAA, stencil clipping for clip-path and draw-record batching. |
| Vulkan | APPlayerVulkanContext, in the engine source tree | APPlayer's --vulkan. Needs Vulkan 1.3 (dynamic rendering) and a Win32 surface. It is built only when the Vulkan SDK is present. Its shaders are the HLSL sources compiled to SPIR-V by slangc. |
| Unreal RHI | FApertureUIRHIBridge, in the Unreal plugin | Does not derive from SimpleAPHIRenderContext. It copies the command list and draws it with Unreal's RHI into a render target. See Unreal Engine. |
| O3DE Atom | ApertureAtomRenderContext and ApertureUIPass, in the O3DE gem | Derives from SimpleAPHIRenderContext and draws through an Atom pass. See O3DE. |
APPlayer's two contexts are reference code. They ship with the Source add-on, which gives read access to the engine source. The download does not contain them (see Your first view). Console render contexts come with console access and are not described here.
APPlayer's source also has an APPlayerD3D12Context file. Its functions are empty, Initialize
returns false, and the build does not include it. Direct3D 12 is not a backend.
Writing your own
Derive from SimpleAPHIRenderContext. These are the groups of functions the reference contexts
override, with their signatures in APHarrlow/RenderPath/Interfaces/APHIRenderPath.h:
| Group | Functions |
|---|---|
| Lifetime | Initialize(graphicsContext, contextType), Shutdown(), GetGraphicsAPIType() |
| Resources | CreateVertexBuffer, CreateIndexBuffer, CreateTexture, CreateRenderTarget, UpdateBuffer, UpdateTexture, and CreateSampler if you need samplers |
| State and draws | SetViewport, SetScissorRect, ResetScissorRect, SetBlendState, SetVertexBuffer, SetIndexBuffer, SetTexture, SetConstantBuffer, Draw, DrawIndexed |
| Layers | BindTargetTexture, ReleaseTargetTexture, ResolveTexture, CopyTexture |
| Filters | BindFilterComputeShader, DoDispatchCompute, BindComputeInputSRV, BindComputeInputSRV1, BindComputeOutputUAV, UnbindComputeResources, BindComputeConstantBuffer. Set m_supportsCompute when they work. |
| Clipping and blending | PushStencilClip, PopStencilClip, ClearStencilClips for clip-path, and CaptureBackdropForBlend for the mix-blend-mode values that need the backdrop |
| Surfaces | UploadCanvasSurface (canvas, SVG, Lottie and decoded images), UploadVideoSurface, ResolveExternalTextureHandle (glyph atlases). Vector glyphs need no surface: see Text. |
| Batching (optional) | SupportsDrawRecords, SetDrawRecords, BindTextureTable. Moves per-draw state into a structured buffer so the base class issues far fewer draws. |
#include <APHarrlow/RenderPath/Implementation/SimpleAPHIRenderContext.h>
class MyRenderContext final : public aperture::harrlow::renderpath::SimpleAPHIRenderContext
{
public:
bool Initialize(void* graphicsContext, const nsString& contextType) override;
void Shutdown() override;
nsString GetGraphicsAPIType() const override { return "MyApi"; }
nsObjectPtr<aperture::harrlow::renderpath::APHIBuffer> CreateVertexBuffer(
const void* data, size_t size, size_t stride, const nsVariantDictionary& usage) override;
nsObjectPtr<aperture::harrlow::renderpath::APHITexture> CreateTexture(
uint32_t width, uint32_t height, const nsString& format, const void* data,
uint32_t rowPitch, const nsVariantDictionary& usage) override;
void SetScissorRect(const nsRectU32& rect) override;
void Draw(uint32_t vertexCount, uint32_t startVertex, uint32_t instanceCount) override;
// ... the rest of the groups above
};Start from APPlayerD3D11Context if you have the source: it is the complete model for D3D-style
APIs, and ApertureAtomRenderContext shows the same contract on a frame-graph renderer. Ask what
the engine needs from your render target with GetRequiredResources(): a depth buffer for 3D
transforms and a stencil buffer for clip-path, as D24S8 with no multisampling by default.
SetConfig(HarrlowConfig) stores the buffer sizes and pool limits that your backend should honor,
and returns an error string when a value is out of range. Call it before Initialize.
Filters, stencil clipping and blend capture are off until you provide them:
SupportsFilterCompute() is false, the stencil functions do nothing, and layers need your
CreateTexture and CreateRenderTarget to return real objects. A first backend can draw the
plain page without them and add them one at a time.
Text
Text reaches a backend by two routes, and the default is the vector route. A backend that handles only the atlas route draws no text until it turns the vector route off.
Vector glyphs (the default). FontEngineBridge::IsVectorGlyphRenderingEnabled() is true
unless you change it, and the packaged SDKBuildInfo.h compiles the feature in. Outline glyphs
become VectorGlyphText commands. They have no texture, and their vertex colors are not colors:
they hold offsets into curve data, which the shader walks to compute coverage per pixel. The command
carries vectorGlyphTextColor, vectorGlyphCurveCount and vectorGlyphPaintCmdCount for the
shader's per-draw constants.
The backend binds that data as structured buffers at fixed registers. The shaders in the package read them there:
| Register | Contents | Where it comes from |
|---|---|---|
t5 | Curve segments, nsVectorGlyphGPUCurveSegment | GetVectorGlyphCurveBuffer(): GetData(), GetSegmentCount(), GetSizeInBytes() |
t6 | Paint commands for COLRv1 emoji, nsVectorGlyphPaintElement | GetVectorGlyphPaintEncoder(): GetCommandData(), GetCommandCount(), GetCommandSizeInBytes() |
t7 | Band directory, nsVectorGlyphGPUBandSet | the curve buffer's GetBandSetData(), GetBandSetCount(), GetBandSetSizeInBytes() |
t8 | Band indices, nsUInt32 | the curve buffer's GetBandIndexData(), GetBandIndexCount(), GetBandIndexSizeInBytes() |
#include <APHTML/Font/FontEngineBridge.h>
#include <FontEngine/FontEngine.h>
#include <FontEngine/VectorGlyphCurveBuffer.h>
#include <FontEngine/VectorGlyphPaintEncoder.h>
// Once per frame, before you submit the command list. UploadStructured is your own function:
// create or update a structured buffer and keep it bound at that register for the frame's draws.
void UpdateGlyphBuffers(MyRenderContext& context)
{
nsFontEngine* fonts = aperture::html::FontEngineBridge::Instance().GetFontEngine();
if (!fonts)
return;
if (auto* curves = fonts->GetVectorGlyphCurveBuffer())
{
if (curves->IsDirty() && curves->GetSegmentCount() > 0)
{
context.UploadStructured(5, curves->GetData(), curves->GetSizeInBytes(),
sizeof(nsVectorGlyphGPUCurveSegment));
if (curves->GetBandSetCount() > 0 && curves->GetBandIndexCount() > 0)
{
context.UploadStructured(7, curves->GetBandSetData(),
curves->GetBandSetSizeInBytes(), sizeof(nsVectorGlyphGPUBandSet));
context.UploadStructured(8, curves->GetBandIndexData(),
curves->GetBandIndexSizeInBytes(), sizeof(nsUInt32));
}
curves->ResetDirty();
}
}
if (auto* paint = fonts->GetVectorGlyphPaintEncoder())
{
if (paint->IsCommandBufferDirty() && paint->GetCommandCount() > 0)
{
context.UploadStructured(6, paint->GetCommandData(), paint->GetCommandSizeInBytes(),
sizeof(nsVectorGlyphPaintElement));
paint->ResetCommandBufferDirty();
}
}
}The band buffers are optional: without them the shader tests every curve of a glyph, which is
slower. APPlayer's D3D11 and Vulkan contexts and the Unreal bridge each upload this data. The
shader side needs the vector glyph code that UIPlayer.hlsl splices in, see Shaders.
ApertureSDK::SetSlugPrimitivesEnabled(true) (on by default in 26.08.0.1) draws rounded backgrounds and
borders as the same VectorGlyphText commands, so it needs this route and does nothing when the
route is off.
Atlas text. FontEngineBridge::SetVectorGlyphRenderingEnabled(false), called before you create
the first view, sends all text through glyph atlases instead. Those are SDFText commands, and
their texture handle is a pointer to a HarrlowVG::Atlas. Glyphs that exist only as bitmaps, such
as color emoji in CBDT or sbix fonts, take this route even while vector glyphs are on, so a backend
that binds t5 to t8 still needs it for them.
The atlas route needs two things from the host. Register a callback on the view that tells you an atlas changed, and map the atlas pointer to a texture of yours:
// OnAtlasUpdated is your own function: mark the atlas dirty, upload before the next draw.
view.setAtlasUpdateCallback([&](HarrlowVG::Atlas* atlas) { context.OnAtlasUpdated(atlas); });Override ResolveExternalTextureHandle to map the draw command's atlas pointer to your texture,
uploading the pixels you were told about. The base class returns the handle cast to a texture, which
is correct only for a handle that already is one. APEngineDLL.h calls the callback the only
atlas-upload route. To read an atlas's pixels (GetData, GetSize, IsColor, GetStride and the
dirty rectangle) include APHarrlow/VectorEngine/Core/Text.hpp, which needs the
LINAVG_DISABLE_TEXT_SUPPORT definition from
Requirements.
The 26.08.0.1 package includes UISlugCore.hlsli and UICSSBlend.hlsli with the shader
sources. Direct3D hosts can use the packaged vector coverage code; the earlier missing-include
restriction no longer applies. See Fonts.
Shaders
The package's shaders/ folder holds the sources the reference backends use:
| File | What it is |
|---|---|
UIPlayer.hlsl | The vertex and pixel shader that APPlayer's D3D11 context loads at run time. It draws shapes, text, borders, shadows, clipping and video. |
UIFilterCompute.hlsl | The CSS filter kernels the D3D11 context loads: horizontal and vertical blur, drop shadow and its compose pass, mask multiply and color matrix. |
UIGradient.hlsl, UIGradient.glsl, UIFilters.hlsl, UIFilters.glsl | Reference versions for integrators. The player contexts do not load them. |
Vulkan/ | Compiled SPIR-V: UIPlayer.vert.spv, UIPlayer.frag.spv and six UIFilter.*.spv compute shaders, built from the two live HLSL files |
Stage the entire shaders/ directory. The D3D11 reference loader replaces the
//__SLUG_CORE__ marker in UIPlayer.hlsl with the packaged UISlugCore.hlsli contents.
Resolve the accompanying UICSSBlend.hlsli include from the same directory. Compiled Vulkan
SPIR-V already contains its includes. Rebuild custom shaders when replacing the SDK.
Updating a command-list host to 26.08.0.1
Analytic coverage is enabled by default for supported solid backgrounds and transformed borders.
Standalone images also receive coverage at transformed edges. A host drawing exported command
lists must handle VectorGlyphText commands and keep the frame's curve and paint data alive
until its GPU work has completed. Copying only vertices and indices loses part of the draw data.
Bring public headers, DLLs and shaders from the same release. For the tessellated primitive
route, call ApertureSDK::SetSlugPrimitivesEnabled(false) before creating views. This setting
controls shapes; the vector-glyph font setting is separate. Verify text, color emoji, rounded
panels, transformed images, clipping and compositing in your host.