Orkid FxPipeline System Reference
When answering questions about FxPipeline, render context, or shader parameter binding in orkid, consult the files below. All under ork.lev2/.
Key Files
| Component | File |
|-----------|------|
| FxPipeline / Cache / Permutation | inc/ork/lev2/gfx/fx_pipeline.h |
| FxPipeline Implementation | src/gfx/fx_pipeline.cpp |
| Shader System | inc/ork/lev2/gfx/shadman.h |
| Render Context (RCID/RCFD) | inc/ork/lev2/gfx/renderer/rendercontext.h |
| GfxMaterial Base | inc/ork/lev2/gfx/gfxmaterial.h |
| PBR Pipeline Creation | src/gfx/material/material_pbr_pipeline.cpp |
| Python Material Bindings | pyext/src/pyext_gfx_material.cpp |
| Python Shader Bindings | pyext/src/pyext_gfx_shader.cpp |
| Type Definitions | inc/ork/lev2/lev2_types.h |
Architecture Overview
GfxMaterial
└─ pipelineCache() → FxPipelineCache
└─ findPipeline(permutation) → FxPipeline
├─ _technique → FxShaderTechnique
├─ _params → { FxShaderParam* : varval_t }
├─ _uniformbuffers → { FxUniformBlock* : varval_t }
├─ _storages → { FxShaderStorageBlock* : varval_t }
└─ _statelambdas → [ (RCID) → void ]
Core Data Structures
FxPipelinePermutation (fx_pipeline.h:38–59)
Encodes rendering configuration as a 64-bit hash (genIndex(), fx_pipeline.cpp:21–39):
| Flag | Bit | Description |
|------|-----|-------------|
| _stereo | 1 | Single-pass stereo |
| _instanced | 2 | Instance rendering |
| _skinned | 3 | Skeletal animation |
| _is_picking | 4 | Picking/selection mode |
| _has_vtxcolors | 5 | Per-vertex colors |
| _is_alpha | 6 | Alpha-blend variant |
| _is_vertex_ssbo | 7 | SSBO-sourced vertices → FWD_SSBO_CUSTOM variant |
| _instanced_matrices_only | 8 | Instanced from a matrices-only dynamic block (no per-inst color) |
| _is_impostor | 9 | LOD impostor: billboard VS + atlas-sampling surface → FWD_SSBO_CUSTOM_IMPOSTOR |
| _is_mesh_shader | 10 | Geometry generated by a mesh stage → FWD_SSBO_CUSTOM_MESH variant |
| _is_sun_cookie | 11 | Cloud-shadow fill pass → alpha-only FWD_SUNCOOKIE variant |
| _rendering_model | 16+ | CRC hash (e.g., "FORWARD_PBR"_crcu) |
_forced_technique— override technique selection; its pointer value is folded into the hash too_vr_mono— VR mono mode (a member, but NOT part of the hash)
FxPipeline (fx_pipeline.h:91–143)
Active rendering state for a specific permutation:
_technique— active shader technique_params—{ fxparam_constptr_t : varval_t }parameter bindings_uniformbuffers—{ fxuniformblock_constptr_t : varval_t }UBO bindings_storages—{ fxparamstorageblock_constptr_t : varval_t }SSBO bindings (+_storage_offsetssub-range byte offsets)_statelambdas— callbacks executed duringbeginBlock()_rasterstate— blend, depth, cull state_material_ptr— parent material (raw backref; see cache eviction below)_bound_params_seen— last-syncedGfxMaterial::_bound_params_stamp(live-rebind contract)_vars— VarMap for user data
Key methods:
beginBlock(RCID)— activate pipeline, bind params, execute state lambdas, return pass countendBlock(RCID)— deactivatewrappedDrawCall(RCID, drawcall)— begin → draw → endbindParam(param, value)— bind shader parameterbindUniformBuffer(block, value)— bind UBObindStorage(block, value, byte_offset = 0)— bind SSBO; a nonzero offset binds a SUB-RANGE (descriptor reads [byte_offset, end)); the same buffer at distinct offsets resolves to distinct descriptor sets; must satisfy minStorageBufferOffsetAlignmentaddStateLambda(fn)— register per-frame binding callback_syncMaterialParams()— re-overlay the parent material's_bound_paramswhen its stamp moved (called at the top of beginBlock; O(1) compare when clean) — material rebinds AFTER pipeline creation are live on the next draw
FxPipelineCache (fx_pipeline.h:145–153)
Caches pipelines by permutation hash:
findPipeline(RCID)— derives permutation from render context, looks up or createsfindPipeline(permutation)— direct lookup by permutation hash_on_miss— factory callback for cache misses_lut—{ uint64_t : fxpipeline_ptr_t }hash table
FxPipelineCacheImpl<MtlClass> (fx_pipeline.h:155–225)
Template for per-material-class caches. Sets _on_miss to call MtlClass::_createFxPipeline(permu, material).
Eviction is MANDATORY: the map is keyed by raw material pointer and the allocator reuses addresses — every material class that instantiates this template must call removeCache(material) from its destructor, or a successor material can inherit a cache whose pipelines hold raw backrefs to the DEAD material (use-after-free surfacing as a GPU page fault at the next submit). The evicted cache is RETURNED rather than dropped so the caller controls release timing (its pipelines can hold the last shared_ptr to GPU-owning binds — route through the owning Context's delayed-destroy queue). PBRMaterial does this via _evictPbrPipelineCache (material_pbr.inl:42).
Parameter Binding Types
varval_t (= varmap::VarMap::value_type) supports:
| Type | Examples |
|------|---------|
| Scalar | float, int, bool, uint32_t |
| Vector | fvec2, fvec3, fvec4 |
| Matrix | fmtx3, fmtx4 |
| Texture | texture_ptr_t, TextureArray* |
| Buffer | FxShaderStorageBuffer*, storagebufferptr_t |
| CrcString | Named parameter provider lookup |
| Generator | varval_generator_t — deferred evaluation lambda |
Named Parameter Providers (`FxPipelineNamedParamProviders` ctor, fx_pipeline.cpp:212–680)
Key design pattern: When a CrcString is bound as a parameter value (from C++ or Python), the runtime resolves it at render time via a singleton map of name → C++ provider function. This is a declarative binding — the wiring is set up once, then the C++ runtime evaluates the provider every frame with zero scripting overhead. Engine-internal data (camera matrices, PBR environment maps, time, etc.) flows to shader parameters without the caller needing to know how that data is computed. This pattern is used throughout the engine in both C++ material setup (e.g., PBRMaterial state lambdas) and Python scene composition.
Registered providers:
| Provider Name | Returns |
|---------------|---------|
| "RCID_PickID" | Pick variant encoding |
| "RCFD_M" | Model matrix |
| "RCFD_Camera_MVP_Mono" | Model-View-Projection |
| "RCFD_Camera_MV_Mono" | Model-View |
| "RCFD_Camera_V_Mono" | View matrix |
| "RCFD_Camera_P_Mono" | Projection matrix |
| "RCFD_TIME" | Current time |
| "CPD_Rtg_Dim" | Render target dimensions |
| "RCFD_MODCOLOR" | Modifier color |
| "RCFD_MONOCAM_NEAR_FAR" | Near/far planes |
| "RCFD_EYE_POSITION" | Camera eye position |
| "RCFD_PBR_BRDF_INTEGRATION_GGX" | BRDF LUT texture (from activeRadianceMaps(), pairing it with the env textures the sibling providers bind) |
| "RCFD_PBR_ENV_SH" / "RCFD_PBR_ENV_SH_VALID" | Diffuse ambient (nine L2 coefficients via CommonStuff::envSHCoeffs + its gate) |
| "RCFD_PBR_SPECULAR_ENV" | Specular environment array (envSpecularTexture()) |
| "RCFD_PBR_SPECULAR_ENV_PREV" | The OUTGOING IBL set during a procedural refilter crossfade (envSpecularTexturePrev(); aliases the bind above whenever no fade is running) |
| "RCFD_PBR_ENV_BLEND_WEIGHT" | The crossfade blend weight (envCrossfadeWeight(), 1.0 outside a fade). The ambient has no prev twin — its crossfade is resolved on the CPU inside envSHCoeffs |
(Plus more: FBI_RTG_DIM/INVDIM, RCFD_DEPTH_MAP, RCFD_PBR_BLACK/WHITE_* fallback textures, LMGR_ACTIVE_* light counts/cookies, inverse-matrix variants — grep _providers[ in fx_pipeline.cpp for the full set.)
Stereo variants append "_Left" / "_Right" suffixes.
Render Context Data Structures
RenderContextInstData (RCID) — per-drawable (rendercontext.h:34–89)
_isSkinned,_isInstanced— permutation flags_isSSBOSourced,_isImpostor,_isMeshSourced— variant flags (FWD_SSBO_CUSTOM family)_forced_technique— technique override_pipeline_cache— material's pipeline cache_pickID— per-drawable pick ID_envmapOverride— per-drawable environment map (baked equirect)_probeOverride— per-drawable live cube probercfd()— access frame datacontext()— graphics context
RenderContextFrameData (RCFD) — per-frame (rendercontext.h:96–168)
_target— graphics context_renderingmodel— e.g.,"FORWARD_PBR"_crcu_pbrcommon— PBR environment data_passID,_subpassID— current pass identifierstopCPD()— current compositing pass dataisStereo()— single-pass stereo checkGetDB()— drawable queueuserProperties()/setUserProperty(crc, data)— per-frame CrcString-keyed side channel (e.g."renderingPROBE"_crcu)
Pipeline Execution Flow
beginBlock() (fx_pipeline.cpp:107–178)
- Get FxInterface from context
FXI->BeginBlock(technique, RCID)→ pass count- Execute all state lambdas with RCID
_syncMaterialParams()— stamp-gated overlay of material-level rebinds- Bind all parameters via type dispatch (
_set_typed_param) - Bind all storage buffers (with per-block sub-range offsets)
FXI->applyRasterState(*_rasterstate)if the pipeline carries one (the shader-stateblock interplay resolves at draw time — see below)- Return pass count
Cache Lookup (`FxPipelineCache::findPipeline`, fx_pipeline.cpp:789–831)
- Extract permutation flags from RCID/RCFD
genIndex()→ 64-bit hash- Check
_lut[hash] - On miss: call
_on_miss(permutation)→ create pipeline - Cache and return
Raster State Priority Override
Raster state is resolved via a priority_stack<rasterstate_ptr_t> (ork.core/inc/ork/kernel/priority_stack.inl). When a rasterstate is pushed onto FXI, it competes with the shader's stateblock rasterstate based on the _priority field — higher priority wins.
Resolution logic — VkFxInterface::_effectiveRasterState() (vulkan_fxi_pipelines.cpp:34–44):
rasterstate_ptr_t VkFxInterface::_effectiveRasterState() {
rasterstate_ptr_t effective_rasterstate = _rasterstate_stack.resolve(); // highest-priority pushed state
int iraspri = effective_rasterstate ? effective_rasterstate->_priority : 0;
if (_currentVKPASS && _currentVKPASS->_stateblock_rasterstate) {
auto try_rs = _currentVKPASS->_stateblock_rasterstate;
if (try_rs->_priority >= iraspri) {
effective_rasterstate = _currentVKPASS->_stateblock_rasterstate; // shader stateblock wins ties
}
}
return effective_rasterstate;
}
Called from the pipeline-state fetch/composition sites (vulkan_fxi_pipelines.cpp:88, 248, 346) and the bind path (vulkan_fxi_pipelines_bind.cpp:127), so every draw resolves the same interplay.
Usage pattern — push a higher-priority rasterstate to override the shader's stateblock:
// Override shader's blend/depth/cull for this draw call
auto RSTATE = std::make_shared<RasterState>();
RSTATE->setDepthTest(EDepthTest::OFF);
RSTATE->setCullTest(ECullTest::OFF);
RSTATE->setBlendingMacro(BlendingMacro::ALPHA);
RSTATE->_priority = 1 << 10; // higher than shader stateblock (default 0)
context->FXI()->pushRasterState(RSTATE);
// ... draw calls use this rasterstate instead of shader's ...
context->FXI()->popRasterState();
Examples in codebase:
fontman_render.cpp:111— font rendering overrides depth/cull for 2D textgfxmodel_render_skeleton.cpp:396— skeleton debug vis with_priority = 1<<10sgnode_billboard.cpp:224— billboard rendering with custom blendsgnode_manipgizmo.cpp:239+— two-pass gizmo rendering (backface then frontface)sgnode_curvepath.cpp:149— curve path line rendering- UI widgets (outliner, toolbar, textbox, etc.) — override for 2D UI rendering
Python API
from orkengine import lev2
# Permutation
permu = lev2.FxPipelinePermutation(rendermodel="FORWARD_PBR")
permu.stereo = False
permu.instanced = True
permu.skinned = False
permu.is_picking = False
# Cache lookup
cache = material.fxcache
pipeline = cache.findPipeline(permu)
# Pipeline usage
pipeline.technique = tek
pipeline.bindParam(param, 0.5) # float — stored, applied in C++ at render time
pipeline.bindParam(param, fvec4(...)) # vector — same, no Python on render path
pipeline.bindParam(param, texture) # texture — same
pipeline.bindParam(param, crcstring) # named provider — C++ resolves engine data each frame
pipeline.bindParam(param, lambda: 0.5) # Python lambda — only case where Python runs per-frame
pipeline.bindStorage(storage, ssbo) # SSBO
pipeline.wrappedDrawCall(rcid, lambda: draw())
# NOTE: All bindings except Python lambdas execute entirely in C++ at render time.
# Python sets up the wiring once; the C++ runtime evaluates it every frame.
# This means Python scene composition has zero per-frame scripting overhead
# for parameter binding — only Python lambdas invoke the interpreter.
How to Answer
- For permutation flags: check
FxPipelinePermutationinfx_pipeline.handgenIndex()infx_pipeline.cpp:21–39 - For parameter binding: check
_set_typed_param()infx_pipeline.cpp - For named providers: check the
FxPipelineNamedParamProvidersctor's_providers[...]registrations infx_pipeline.cpp - For PBR-specific pipeline creation: check
material_pbr_pipeline.cpp - For render context: check
rendercontext.h - For raster-state resolution: check
VkFxInterface::_effectiveRasterState()invulkan_fxi_pipelines.cpp - For Python: check the
FxPipelinePermutation/FxPipelineCache/FxPipelineclasses inpyext_gfx_material.cpp(from line 141)