stride3d/stride · error · ArgumentOutOfRangeException

Invalid ShaderStage.

Error message

Invalid ShaderStage.

What it means

When converting a Stride ShaderStage to a D3D12 ShaderVisibility for root signature parameters, only Vertex, Hull, Domain, Geometry, Pixel, and Compute (mapped to All) are handled. Any other/invalid stage value reaches the switch default and throws ArgumentOutOfRangeException naming 'stage'.

Solutions

  1. Ensure effect bindings carry valid ShaderStage values
  2. Recompile the effect so stage metadata is correct
  3. Upgrade Stride if a newly introduced stage is not yet mapped in the D3D12 backend

Example fix

// before
var stage = (ShaderStage)42; // invalid
// after
var stage = ShaderStage.Pixel;
Defensive patterns

Strategy: validation

Validate before calling

if (!Enum.IsDefined(typeof(ShaderStage), stage)) throw new InvalidOperationException($"Undefined ShaderStage: {stage}");

Type guard

bool IsValidShaderStage(ShaderStage s) => s is ShaderStage.Vertex or ShaderStage.Hull or ShaderStage.Domain or ShaderStage.Geometry or ShaderStage.Pixel or ShaderStage.Compute;

Try / catch

try { state = PipelineState.New(device, desc); } catch (ArgumentOutOfRangeException) { /* invalid ShaderStage in effect binding */ throw; }

Prevention

When it happens

Trigger: An effect binding whose ShaderStage is undefined, corrupted, or a stage not in the handled set while building the root signature in the PipelineState constructor.

Common situations: Malformed effect bytecode metadata; enum cast from an int not matching any ShaderStage; backend mismatch after adding a new stage without updating the D3D12 mapping.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/30d76d4c773984aa. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Graphics/Direct3D12/PipelineState.Direct3D12.cs:709

                throw new NotSupportedException("Static Samplers can only have opaque black, opaque white or transparent black as border color.");
            }

            //
            // Returns the Direct3D 12 Shader Visibility for a Stride's ShaderStage.
            //
            static ShaderVisibility GetShaderVisibilityForStage(ShaderStage stage)
            {
                return stage switch
                {
                    ShaderStage.Vertex => ShaderVisibility.Vertex,
                    ShaderStage.Hull => ShaderVisibility.Hull,
                    ShaderStage.Domain => ShaderVisibility.Domain,
                    ShaderStage.Geometry => ShaderVisibility.Geometry,
                    ShaderStage.Pixel => ShaderVisibility.Pixel,
                    ShaderStage.Compute => ShaderVisibility.All,

                    _ => throw new ArgumentOutOfRangeException(nameof(stage), stage, "Invalid ShaderStage.")
                };
            }
        }

        /// <inheritdoc/>
        protected internal override void OnDestroyed(bool immediately = false)
        {
            SafeRelease(ref nativeRootSignature);
            SafeRelease(ref compiledPipelineState);

            base.OnDestroyed(immediately);
        }
    }
}

#endif

View on GitHub (pinned to 96fad776d2)