Table of Contents

Class KnifxWriter

Namespace
ShadowDusk.Core
Assembly
ShadowDusk.Core.dll

Serializes a ShadowDusk ShaderIR into KNI's KNIFX v11 effect container, the additive newer format KNI v4.02+ loads (signature "KNIF"). This is the KNIFX analogue of MgfxWriter: it carries the same MojoShader-dialect GLSL body ShadowDusk already produces for MGFX v10 (KNIFX is a container over a still-MojoShader body), re-serialized into KNIFX's binary layout.

Byte format reverse-engineered from KNI's own KNIFXWriter11 + the runtime Effect reader (full spec: plan/PHASE-35-appendix/knifx-format-spec.md). The headline deltas vs MGFX v10:

  • A multi-backend directory header (one .knifx can carry several backend bodies; the runtime picks the match). This writer emits one backend.
  • Counts and most indices are written as packed ints (zigzag + 7-bit).
  • New fields: a per-shader ShaderVersion, a Stage byte (with a compute slot), and a columnsActual byte on parameters.

The pass render-state blocks are byte-identical to v10, so MgfxWriter's writers are reused verbatim. Default product output stays MGFX v10; KNIFX is additive.

public sealed class KnifxWriter
Inheritance
KnifxWriter
Inherited Members

Fields

KnifxSignature

KNIFX 4-byte signature (ASCII "KNIF"), per KNI's KNIFXWriter11.

public const string KnifxSignature = "KNIF"

Field Value

string

KnifxVersion

The default KNIFX container version (v11). Loads on KNI 4.2.x clean and on 4.3.x with a "needs to be rebuilt" console warning, so it stays the default until 4.2.x is old enough to drop (see the tracking issue linked from project_decisions.md).

public const short KnifxVersion = 11

Field Value

short

KnifxVersionNewest

The newest KNIFX container version (v12, KNI 4.3.x). Opt-in via KniGL_4_03 (--target-runtime kni-knifx-v12); KNI 4.2.x rejects it. The body layout is identical to v11 (KNI's KNIFXReader12 is KNIFXReader11 under a new name), so only the header version differs.

public const short KnifxVersionNewest = 12

Field Value

short

Methods

Write(ShaderIR, KnifxWriterOptions)

Serializes ir into the binary KNIFX (v11) container bytes for the backend named in options.

public Result<byte[], ShaderError> Write(ShaderIR ir, KnifxWriterOptions options)

Parameters

ir ShaderIR

The fully assembled effect IR to serialize.

options KnifxWriterOptions

The KNIFX backend (and thus integer-as-float decoding) to emit for.

Returns

Result<byte[], ShaderError>

The KNIFX bytes on success, or a ShaderError on failure.