{"record":{"id":"551f3c8fb6f8c7aa","repo":"stride3d/stride","slug":"cross-compilercreateshaderresources-compiler-resources-could","errorCode":null,"errorMessage":"{cross.CompilerCreateShaderResources(compiler, &resources)} : could not create shader resources","messagePattern":"(.+?) : could not create shader resources","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Compilers/SpirvTranslator.cs","lineNumber":114,"sourceCode":"            {\n                cross.CompilerOptionsSetUint(compilerOptions, CompilerOption.HlslShaderModel, 50);\n                cross.CompilerOptionsSetBool(compilerOptions, CompilerOption.HlslPreserveStructuredBuffers, 1);\n                // FXC rejects uninitialized loop-carried variables (from OpUndef phi inputs) with a\n                // bogus \"error X4555: cannot use casts on l-values\" when they end up assigned in a\n                // for-loop continue expression.\n                cross.CompilerOptionsSetBool(compilerOptions, CompilerOption.ForceZeroInitializedVariables, 1);\n            }\n            cross.CompilerInstallCompilerOptions(compiler, compilerOptions);\n        }\n\n        if (entryPoint != null)\n        {\n            if (cross.CompilerSetEntryPoint(compiler, entryPoint.Value.RealName, entryPoint.Value.ExecutionModel) != Result.Success)\n                throw new Exception($\"{cross.CompilerSetEntryPoint(compiler, entryPoint.Value.RealName, entryPoint.Value.ExecutionModel)} : could not set entry point\");\n        }\n\n        if (cross.CompilerCreateShaderResources(compiler, &resources) != Result.Success)\n            throw new Exception($\"{cross.CompilerCreateShaderResources(compiler, &resources)} : could not create shader resources\");\n\n        // HLSL: remove type_ prefix from cbuffer (they get names from struct instead of cbuffer variable itself)\n        if (backend == Backend.Hlsl)\n        {\n\n            ReflectedResource* resourcesList;\n            nuint resourcesCount;\n            cross.ResourcesGetResourceListForType(resources, ResourceType.UniformBuffer, &resourcesList, &resourcesCount);\n            for (uint i = 0; i < resourcesCount; ++i)\n            {\n                var resource = resourcesList[i];\n                var cbufferName = Marshal.PtrToStringAnsi((IntPtr)resource.Name)!;\n                if (cbufferName.StartsWith(\"type.\"))\n                {\n                    cbufferName = cbufferName.Substring(\"type.\".Length);\n                    cross.CompilerSetName(compiler, resource.BaseTypeId, cbufferName);\n                }\n            }","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Compilers/SpirvTranslator.cs#L96-L132","documentation":"Translate throws this when CompilerCreateShaderResources fails to reflect the shader's resource bindings (cbuffers, textures, samplers, stage inputs/outputs) from the compiled IR. Reflection is required for the subsequent HLSL renaming and vertex-attribute remap steps, so translation aborts. The message includes the non-success Result code.","triggerScenarios":"Calling Translate when the compiler holds an IR that spirv-cross cannot reflect — corrupted/degenerate IR from a borderline-valid SPIR-V module, or an internal spirv-cross state error after prior failed calls in the same pipeline.","commonSituations":"Translating SPIR-V produced by newer toolchains with resource layouts spirv-cross's version doesn't understand; IR damaged by earlier failed calls; native library version bugs in reflection code.","solutions":["Validate the SPIR-V with spirv-val; recompile the shader if invalid","Check the spirv-cross error-callback log lines emitted before the throw","Update the native spirv-cross binary to a version matching the shader toolchain","Ensure no earlier native call in the same Translate pipeline failed silently (check Result codes / logs)","Isolate with a minimal known-good SPIR-V module to separate shader issues from environment issues"],"exampleFix":"// before\nvar hlsl = translator.Translate(Backend.Hlsl, entryPoint);\n// after\ntry { var hlsl = translator.Translate(Backend.Hlsl, entryPoint); }\ncatch (Exception ex) when (ex.Message.Contains(\"could not create shader resources\"))\n{ Log.Error($\"Reflection failed for shader: {ex.Message}. Verify SPIR-V with spirv-val.\"); throw; }","handlingStrategy":"try-catch","validationCode":"// Validate SPIR-V before translation so reflection has a well-formed module:\n// spirv-val shader.spv  (offline) or check words[0] == 0x07230203 inline","typeGuard":null,"tryCatchPattern":"try { var src = translator.Translate(backend, entryPoint); } catch (Exception ex) when (ex.Message.Contains(\"could not create shader resources\")) { Log.Error($\"Resource reflection failed: {ex.Message}\"); throw; }","preventionTips":["Validate SPIR-V in the asset pipeline","Keep spirv-cross current with your shader compiler's output features","Check error-callback logs for the native cause","Avoid reusing compiler state after earlier failures — always start a fresh Translate call"],"tags":["spirv-cross","reflection","native-interop","shader-resources"],"backgroundTag":"internal-invariant-violation","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"}