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 only KNIFX container version KNI defines today.

public const short KnifxVersion = 11

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.