Table of Contents

Class ParameterReflection

Namespace
ShadowDusk.Core.Reflection
Assembly
ShadowDusk.Core.dll

A flattened effect parameter as exposed to the MonoGame runtime (the user-settable surface, e.g. via Effect.Parameters["Foo"]), with its name, optional semantic, type shape, and annotations.

public sealed record ParameterReflection : IEquatable<ParameterReflection>
Inheritance
ParameterReflection
Implements
Inherited Members

Properties

Annotations

The annotations declared on the parameter, if any.

public IReadOnlyList<AnnotationReflection>? Annotations { get; init; }

Property Value

IReadOnlyList<AnnotationReflection>

Class

The parameter's shape class (scalar, vector, matrix, object, …).

public required EffectParameterClass Class { get; init; }

Property Value

EffectParameterClass

Columns

The number of columns; 1 for scalars. See Rows for the one case it is transposed.

public required int Columns { get; init; }

Property Value

int

DefaultValue

The default value the HLSL declaration gives the parameter (float Scale = 2.0;), or null when it is unknown.

public IReadOnlyList<float>? DefaultValue { get; init; }

Property Value

IReadOnlyList<float>

Remarks

Layout. Rows * Columns * Math.Max(1, Elements) floats, array element after array element, each element in logical row-major order (the cell at row r, column c is at index r * Columns + c; a float2x3 is m00 m01 m02 m10 m11 m12, the order its constructor takes). No register padding, whatever the matrix packing, and not the order of the blob in a .mgfx (column by column, or in register order for a row_major matrix). For a row_major non-square matrix on Vulkan, whose Rows x Columns is the C x R its buffer is uploaded by, the value is still the declaration's R x C, row after row, so there the cell at row r, column c is at r * Rows + c, not r * Columns + c. The two orders have the same length and this result exposes no majorness, so a consumer can only tell that case apart by reading the HLSL declaration (a row_major modifier, or a #pragma pack_matrix(row_major) before it) and comparing its shape with Rows x Columns. Square matrices, every column-major matrix and every other target are unaffected. int values are converted to floats, uint values by their unsigned value (so uint U = 3000000000; is 3000000000, not negative), and an integer beyond 2^24 is not exactly representable. bool is 0 or 1 on every target. How a 32-bit word reads follows the HLSL declaration, not Type: reflection reports both int and uint as Int32, and on Vulkan a bool too.

MGFX and KNIFX. It is exactly the default blob the file carries for the parameter (the initializer, read off the preprocessed source and evaluated, so constructors, brace lists, folding of constants and the like all count). It is null where the file's blob is zeros the author did not write: the parameter has no initializer, or the initializer could not be evaluated (the compile then carries an SD0017 warning). Struct, texture and sampler parameters are always null.

FNA. The same source reading as MGFX. A scalar or vector it has no value for takes the compiled constant table's; a matrix or array it cannot evaluate is null, because the compiler trims that table to the registers the shader reads.

Vulkan. SPIR-V has no bool in a uniform block, so a bool there has Type Int32, exactly as in real mgfxc's Vulkan build (and in the .mgfx). Its default still reads as 0 or 1, because the value is read by the declaration's kind; a tool that needs to tell bool from int on Vulkan has only the source to go by. The file still carries the word 0xFFFFFFFF for true, so the real engine's EffectParameter.GetValueInt32() on that parameter returns -1 where this value is 1.

Why from the source. The compilers do not keep the initializer in a form reflection reads: DXC's DXIL reflection reports no default (and warns that the initializer is ignored) and DXC drops it from the SPIR-V.

Elements

The array element count; 1 when not an array.

public required int Elements { get; init; }

Property Value

int

Name

The parameter's name.

public required string Name { get; init; }

Property Value

string

Rows

The number of rows; 1 for scalars. This is the shape the effect file declares to the runtime (MonoGame uploads a matrix as Columns registers of Rows floats), which is the HLSL declaration's except for a row_major non-square matrix on Vulkan: there it is the C x R transpose of a declared R x C (see DefaultValue).

public required int Rows { get; init; }

Property Value

int

Semantic

The HLSL semantic attached to the parameter, if any.

public string? Semantic { get; init; }

Property Value

string

Type

The parameter's element type.

public required EffectParameterType Type { get; init; }

Property Value

EffectParameterType