Vixen
02b45cc4
csharp
public sealed class SpirvModule

A SPIR-V module under construction. Instructions go into the sections the spec's logical layout demands (§2.4) rather than into one list, because the order between sections is fixed and the order within one is not.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Ids are allocated from one counter for the whole module, and types, constants and pointer types are interned: emitting f32 twice must yield the same id, both because the spec requires type uniqueness and because duplicated aggregates would fail validation.

Fields and properties (5)

  • public const uint MagicNumber

    The word every SPIR-V binary starts with.

  • public uint Version

    The SPIR-V version word, e.g. 0x00010000 for 1.0.

  • public uint EffectiveVersion

    The version actually written into the header: the configured one, raised to 1.4 when the module declares ray query.

  • public uint Bound

    One past the highest id used — the binary header's bound.

  • public IEnumerable<SpirvInstruction> Instructions

    Every instruction, in the spec's logical layout order.

Methods (17)

  • public SpirvModule(uint version)
  • public uint AllocateId()
  • public void AddCapability(SpirvCapability capability)
  • public void AddExtension(string name)

    Declares an OpExtension, once however many things ask for it.

  • public uint AddExtendedInstructionSet(string name)
  • public void SetMemoryModel(SpirvAddressingModel addressing, SpirvMemoryModel memory)
  • public void AddEntryPoint(SpirvExecutionModel model, uint function, string name, IEnumerable<uint> interface)
  • public void AddExecutionMode(uint function, SpirvExecutionMode mode, params uint[] literals)
  • public void AddName(uint target, string name)

    Names a result, for a debugger and for whatever cross-compiles this.

  • public void AddMemberName(uint target, int member, string name)

    Names one member of a struct, on the same terms.

  • public void Decorate(uint target, SpirvDecoration decoration, params SpirvOperand[] extra)
  • public void DecorateMember(uint target, int member, SpirvDecoration decoration, params SpirvOperand[] extra)
  • public uint AddDeclaration(SpirvOp op, uint? resultType, params SpirvOperand[] operands)

    Adds a type, constant or global variable to the declarations section.

  • public uint Intern(string key, Func<uint> create)

    Adds a declaration once per key. The key is the caller's structural identity for the thing — "vec f32 3", say.

  • public void AddFunctionInstruction(SpirvInstruction instruction)
  • public byte[] ToBytes()

    The binary module: the five-word header followed by the instruction stream.

  • public string ToAssembly()

    The module as an assembly listing, in the shape spirv-dis prints. It is rendered from the same instructions the binary is encoded from, so a golden file over it cannot drift from what actually shipped.

Used by (4)

  • SpirvBackendVixen.Raven
  • SpirvBackendTestsVixen.Raven.Tests
  • SpirvEmitterVixen.Raven
  • SpirvTypesVixen.Raven