RDShaderFile
Named SPIR-V variants, errors and shader-resource serialization.
RDShaderFile is a Resource containing named SPIR-V variants and a file-level parsing error. It is neither a spatial/canvas Shader for ShaderMaterial nor a GPU RID. SetBytecode stores a reference rather than compiling source text; RenderingDevice creates a GPU shader separately. Use RDShaderSource for source text.
The version parameter names a variant inside the file, such as zeta, not an engine release. Omitting it selects the empty name. It does not mean “first available variant”: GetSpirV with a missing key emits a native error and returns null. GetVersionList returns a separate list sorted by name; check the required key first. A new RDShaderFile contains no versions.
Check three independent things: file BaseError, the selected RDShaderSpirV stage error and that stage’s bytecode presence. Empty BaseError does not mean success. This executed helper extracts only Compute from the selected version and creates a caller-owned GPU shader:
using System;
using System.Collections.Generic;
using Reckfell;
public static class ShaderVersions
{
// Creates an owned GPU shader containing only the selected compute stage.
// Use the device's valid call context; free the RID on the same device.
public static Rid CreateCompute(RenderingDevice device, RDShaderFile file, string version = "")
{
ArgumentNullException.ThrowIfNull(device);
ArgumentNullException.ThrowIfNull(file);
ArgumentNullException.ThrowIfNull(version);
if (!string.IsNullOrEmpty(file.BaseError))
throw new InvalidOperationException(file.BaseError);
using var name = new StringName(version);
var names = file.GetVersionList();
using var namesOwner = (Reckfell.Collections.Array)names;
if (!names.Contains(name)) throw new KeyNotFoundException("Shader version is absent.");
var stored = file.GetSpirV(name); // Borrowed shared resource: do not Dispose.
if (!string.IsNullOrEmpty(stored.CompileErrorCompute))
throw new InvalidOperationException(stored.CompileErrorCompute);
byte[] bytes = stored.BytecodeCompute;
if (bytes.Length == 0) throw new InvalidOperationException("Compute bytecode is empty.");
using var computeOnly = new RDShaderSpirV { BytecodeCompute = bytes };
Rid shader = device.ShaderCreateFromSpirV(computeOnly);
if (!shader.IsValid) throw new InvalidOperationException("GPU shader creation failed.");
return shader;
}
}The helper loads no file and compiles no GLSL. Supply an existing RDShaderFile and a valid RenderingDevice. It excludes other stages when creating computeOnly; it is not a graphics/ray-tracing pipeline validator. After success, create a ComputePipeline and uniform set matching this shader layout. Full dispatch/readback cycle: compute and data.
GetSpirV returns a shared object that multiple names can reference. Do not Dispose it as an independent copy or edit stage errors/bytecode accidentally when changing one variant. Create a separate RDShaderSpirV for an independent variant. The _Versions getter copies the dictionary, not its value objects; this is an internal serialization property, not the recommended editing interface. SetBytecode replaces a matching key and emits Changed. SetBaseError also emits Changed even when writing the same string.
The file descriptor owns no GPU RIDs. ShaderCreateFromSpirV creates a separate resource belonging to one device; free it through the same FreeRid after work completes. The main RenderingDevice is borrowed and must not be freed by your code; the creating component manages a local device and its resources. Use the device’s correct thread/call context.
Installed Windows/Vulkan Forward+ checks covered shared bytecode, variant names/replacement, Changed, container copies, .rdata save/reload and the exact helper. Real compute doubled the original storage buffer after loading. RDUniform edits after UniformSetCreate changed no existing GPU binding; freeing the bound buffer invalidated the dependent set while a copied RID remained nonzero. The Vulkan loader warning remains. Text shader-file importing, graphics/ray stages, other drivers/platforms, images and performance were not tested.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
RDShaderFileConstructor
public RDShaderFile();Creates a Resource with empty BaseError and no bytecode versions. Not yet a valid GPU shader: an empty error string establishes neither stage data nor successful compilation.
Properties2
BaseErrorProperty
public string BaseError { get; set; }File-level parsing error, initially empty. The setter only stores text and emits Changed, even for the same value. Clears no versions, per-stage errors or bytecode; setting an empty string neither compiles nor repairs a shader.
_VersionsProperty
public Reckfell.Collections.Dictionary _Versions { get; set; }Internal serialization dictionary: name → shared RDShaderSpirV. The getter creates a new container with shared values. The setter clears old versions and rebuilds the map; unsuitable values are skipped with native errors. Not the ordinary editing interface: prefer SetBytecode/GetVersionList/GetSpirV.
Methods5
GetBaseErrorstring
public string GetBaseError();Returns the stored file-level error. An empty string does not replace checking CompileErrorCompute/other stages and actual bytecode in the selected version.
stringStored file-level error; an empty string alone does not mean success.
GetSpirVRDShaderSpirV
public RDShaderSpirV GetSpirV(StringName version = null);Returns the requested version’s shared RDShaderSpirV, not an independent copy. Do not Dispose the borrowed result or mutate it accidentally: multiple versions can share one object. An omitted version selects the empty key; a missing key emits a native error and returns null without selecting another version. Check GetVersionList first.
| Name | Type | Default |
|---|---|---|
version | StringName | null |
versionExact shader-variant name. An omitted value selects the empty name, not a Reckfell product version.
RDShaderSpirVBorrowed shared RDShaderSpirV; null and a native error for a missing name.
GetVersionListReckfell.Collections.Array<StringName>
public Reckfell.Collections.Array<StringName> GetVersionList();Returns a new container of names sorted by name. The empty name denotes the default version and appears only if stored. The list can be empty; order is not SetBytecode insertion order. Editing the container does not edit the file.
Reckfell.Collections.Array<StringName>Separate Array<StringName> of sorted names, possibly empty.
SetBaseErrorvoid
public void SetBaseError(string error);Stores the file-level error and emits Changed without comparing the old string. Records diagnostics; does not compile, clear stage errors or recreate a GPU shader.
| Name | Type | Default |
|---|---|---|
error | string | — |
errorFile-level error text to store; an empty string clears only this field.
SetBytecodevoid
public void SetBytecode(RDShaderSpirV bytecode, StringName version = null);Stores an RDShaderSpirV reference under the requested name; replaces an existing key and emits Changed. The bytecode object must be nonnull, but this method validates neither stages nor errors. Compiles no text and creates no GPU RID. Different names can share one object.
| Name | Type | Default |
|---|---|---|
bytecode | RDShaderSpirV | — |
version | StringName | null |
bytecodeNonnull RDShaderSpirV stored by reference; this setter rejects neither stage errors nor missing stages.
versionExact shader-variant name. An omitted value selects the empty name, not a Reckfell product version.