{"record":{"id":"ff90155fa94eefe9","repo":"stride3d/stride","slug":"bordercolor-must-be-float4-r-g-b-a","errorCode":null,"errorMessage":"BorderColor must be float4(r, g, b, a)","messagePattern":"BorderColor must be float4\\(r, g, b, a\\)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/ShaderElements.MethodOrMember.cs","lineNumber":107,"sourceCode":"                case \"MipLODBias\":\n                    mipLODBias = BitConverter.SingleToInt32Bits((float)((FloatLiteral)parameter.Value).Value);\n                    break;\n                case \"MaxAnisotropy\":\n                    maxAnisotropy = ((IntegerLiteral)parameter.Value).IntValue;\n                    break;\n                case \"ComparisonFunc\":\n                    comparisonFunc = (int)Enum.Parse<Specification.SamplerComparisonFuncSDSL>(((Identifier)parameter.Value).Name, true);\n                    break;\n                case \"MinLOD\":\n                    minLOD = BitConverter.SingleToInt32Bits((float)((FloatLiteral)parameter.Value).Value);\n                    break;\n                case \"MaxLOD\":\n                    maxLOD = BitConverter.SingleToInt32Bits((float)((FloatLiteral)parameter.Value).Value);\n                    break;\n                case \"BorderColor\":\n                    {\n                        if (parameter.Value is not VectorLiteral { TypeName.Name: \"float4\", Values: { Count: 4 } args })\n                            throw new NotSupportedException($\"BorderColor must be float4(r, g, b, a)\");\n                        borderR = BitConverter.SingleToInt32Bits((float)((NumberLiteral)args[0]).DoubleValue);\n                        borderG = BitConverter.SingleToInt32Bits((float)((NumberLiteral)args[1]).DoubleValue);\n                        borderB = BitConverter.SingleToInt32Bits((float)((NumberLiteral)args[2]).DoubleValue);\n                        borderA = BitConverter.SingleToInt32Bits((float)((NumberLiteral)args[3]).DoubleValue);\n                        break;\n                    }\n                default:\n                    throw new NotImplementedException($\"SamplerState parameter '{parameter.Name}' not implemented\");\n            }\n        }\n        // Only emit immutable sampler state when the declaration has explicit parameters.\n        // Samplers without inline state (e.g. \"stage SamplerState Sampler;\") are dynamic\n        // and set at runtime via Parameters.Set().\n        if (Parameters.Count > 0)\n        {\n            context.Add(new OpDecorate(variableId, Specification.Decoration.SamplerStateSDSL, [\n                filter, addressU, addressV, addressW, mipLODBias, maxAnisotropy, comparisonFunc, minLOD, maxLOD,\n                borderR, borderG, borderB, borderA","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/ShaderElements.MethodOrMember.cs#L89-L125","documentation":"When compiling a SamplerState declaration, the BorderColor parameter must be a float4 literal with exactly 4 numeric components. The compiler packs all four RGBA values into integers for the SPIR-V immutable sampler; anything else (wrong type, wrong type name, wrong arity) is rejected with this NotSupportedException.","triggerScenarios":"A shader declares a sampler with an inline BorderColor parameter whose value is not a VectorLiteral typed 'float4' with exactly 4 values, e.g. BorderColor(0) or BorderColor(float3(...)).","commonSituations":"Porting HLSL sampler state from FX files, hand-editing a sampler and dropping a component, or using a variable/expression instead of a literal.","solutions":["Change the BorderColor argument to a float4 literal with exactly 4 components, e.g. BorderColor(float4(0, 0, 0, 1)).","Verify the literal is parsed as a VectorLiteral with TypeName 'float4'; ensure the constructor call spells the type float4.","If a non-float4 border color is needed, set sampler state at runtime via Parameters.Set() instead of an inline declaration."],"exampleFix":"// before\nsampler2D Tex : BorderColor(0);\n// after\nsampler2D Tex : BorderColor(float4(0, 0, 0, 1));","handlingStrategy":"validation","validationCode":"if (param.Value is not VectorLiteral { TypeName.Name: \"float4\", Values: { Count: 4 } })\n    throw new ArgumentException(\"BorderColor must be float4(r, g, b, a)\");","typeGuard":"static bool IsValidBorderColor(object v) =>\n    v is VectorLiteral vl && vl.TypeName.Name == \"float4\" && vl.Values.Count == 4;","tryCatchPattern":"try { sampler.Compile(); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"BorderColor must be float4\"))\n{\n    // rewrite the BorderColor parameter as float4(r, g, b, a) and retry\n}","preventionTips":["Always write BorderColor as a float4 literal with exactly four components.","Lint sampler declarations against the supported inline parameter list before compiling."],"tags":["shader","sdsl","samplers","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}