Table of Contents

Class ResourceArrayBindings

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

Collapses the per-element resource bindings a Shader Model 5 RDEF carries for an ARRAY of textures or samplers into the one binding per array that Shader Model 4 reflection reports, which is the view real mgfxc builds its DirectX_11 parameter table from (issue #339).

Measured 2026-10-02 with d3dcompiler_47 (/Gec /O3, mgfxc's own flags) on Texture2D Tex[2] : register(t0) sampled as Tex[0] and Tex[1]:

  • ps_4_0 (and ps_4_0_level_9_3): ONE binding Tex, BindPoint 0, BindCount 2. The BindPoint is the array's base register and the BindCount its declared size whichever elements are used: Tex[1] alone still reflects Tex t0 count 2, and Tex[0] + Tex[3] of a 4-array reflects Tex t0 count 4. An array declared at register(t1) reflects Tex t1 count 2 after the texture at t0.
  • ps_5_0: one binding PER ELEMENT, named with the index, each BindCount 1: Tex[0] t0, Tex[1] t1 (and Tex[1] t1 alone when only element 1 is read). vkd3d-shader's DXBC follows the same convention, and D3DReflect reports these records as they are stored.

mgfxc compiles a DirectX_11 shader at the model the author wrote (ps_4_0 in every MonoGame template), walks the texture bindings and makes one sampler record per binding whose parameter is named by the binding, so a texture array is ONE effect parameter (Tex) with ONE record at the array's base slot (3.8.4.1 and 3.8.5 alike). ShadowDusk compiles DirectX 11 at Shader Model 5 (Vkd3dShaderCompiler / D3DCompileRequest), so its RDEF has the per-element records; before this collapse they became parameters Tex[0], Tex[1], ... that no author ever names (effect.Parameters["Tex"] was null). The collapse reproduces the Shader Model 4 view from the Shader Model 5 records: the base name, the base slot (slot - index, the same for every element), and the element count as ArrayLength. Non-array bindings pass through untouched, so no byte of an array-free effect moves. The DXIL reflector (DirectX 12) already reports an array this way (BindCount), so the two DirectX extractors now agree.

public static class ResourceArrayBindings
Inheritance
ResourceArrayBindings
Inherited Members

Methods

Collapse(ReflectedEffect)

Returns effect with every run of per-element texture and sampler bindings collapsed into one binding per array; the same instance when it has none.

public static ReflectedEffect Collapse(ReflectedEffect effect)

Parameters

effect ReflectedEffect

A reflected shader stage (typically RdefReader output).

Returns

ReflectedEffect

IsElement(string)

True when name is spelled as an array element (Name[i]).

public static bool IsElement(string name)

Parameters

name string

Returns

bool