stride-shader-asset-workflow
npx skills add https://github.com/tebjan/stride-skills --skill stride-shader-asset-workflow
Agent 安装分布
Skill 文档
Stride Shader Asset Workflow
Overview
This skill defines the correct workflow for adding, updating, and debugging Stride shader files (*.sdsl) in C# projects.
It helps agents verify project setup, generated shader key files, and Stride asset compilation steps.
When To Use
- Adding a new Stride shader file (
*.sdsl) of any kind (compute, material/mixin, effect-related, or custom shader classes) - Renaming/moving shader files
- Adding/changing shader parameters and needing updated generated C# key files (
*.sdsl.cs) - Seeing Stride shader errors like
E1202 ... mixin ... is not in the module - Seeing runtime behavior that suggests a new shader is not being loaded
- Working in projects that use both
.sdpkgasset folders and explicit.csprojshader links
Default Stride Template Layout (Usual Case)
In a standard Stride game created from the template, shader files are usually placed in an Effects folder next to the platform-independent game core project (<GameName>.csproj), for example:
<SolutionRoot>/<GameName>/<GameName>.csproj<SolutionRoot>/<GameName>/Effects/*.sdsl<SolutionRoot>/<GameName>/<GameName>.sdpkg
Typical template behavior:
<GameName>.sdpkgincludesAssetFoldersfor bothAssetsandEffects- The core game
.csprojoften has no explicit shader item entries - Shader files are picked up via SDK-style default items (
None) + Stride’s default target metadata (None Update="**\*.sdsl" Generator="StrideShaderKeyGenerator")
Practical implication:
- If you are working inside a normal template game project and shaders live under the project folder (for example
Effects/), you usually do not need explicit.csprojshader link items. - The explicit linked/wildcard
.csprojpatterns in this skill are mainly for:- shared external shader folders (for example
..\..\shaders) - runner/test projects
- non-template layouts
- shared external shader folders (for example
Generated Shader Keys (Use These, Not String Keys)
Stride has a built-in shader key generator for .sdsl files:
- VS custom tool:
StrideShaderKeyGenerator - Output:
*.sdsl.cs - Generated class pattern:
<ShaderName>Keys
Use generated keys in C# when possible instead of string-based ParameterKeys.FindByName(...)/manual names.
Why:
- Prevents binding bugs from wrong names or missing qualification (for example
WidthvsMyShader.Width) - Keeps parameter bindings in sync when shader parameters change
Important Trap: None vs Content Shader Items
Stride’s default targets auto-apply the shader key generator to:
None Update="**\\*.sdsl" Generator="StrideShaderKeyGenerator"
If your project links shaders as Content items (common in runner/test projects), you might not get automatic key generation unless you set generator metadata explicitly on those linked items.
For linked shaders in a C# project (especially external/shared shader folders), prefer None items (so the default Stride metadata pattern matches), and set the generator explicitly anyway.
Preferred scalable pattern (works with subfolders):
<ItemGroup>
<None Include="..\\..\\shaders\\**\\*.sdsl"
Link="Assets\\%(RecursiveDir)%(Filename)%(Extension)"
Generator="StrideShaderKeyGenerator" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\\..\\shaders\\**\\*.sdsl.cs"
Link="Assets\\Generated\\%(RecursiveDir)%(Filename)%(Extension)"
Visible="false"
AutoGen="True"
DesignTime="True" />
</ItemGroup>
Notes:
Generator="StrideShaderKeyGenerator"is the VS/custom-tool hook that produces*.sdsl.cs.- The recursive wildcard patterns (
..\\..\\shaders\\**\\*.sdsland..\\..\\shaders\\**\\*.sdsl.cs) keep the project file small and automatically pick up new shaders/subfolders. - The
Compile Include="..\\..\\shaders\\**\\*.sdsl.cs"pattern ensures generated key files are compiled when working in CLI/agent workflows and linked shader layouts. - If a project intentionally uses
Contentfor linked shaders,Generator="StrideShaderKeyGenerator"must be set explicitly on each shader item. - This wildcard setup was validated in a Stride runner project with:
StrideAssetUpdateGeneratedFilesStrideCleanAssetStrideCompileAsset- a real GPU roundtrip run (compress + low-level decompressor fallback + verify pass)
C# Project Setup (Required for CLI/Agent Workflows)
In addition to Stride.Engine / Stride.Rendering, ensure the project has the asset compiler targets available (directly or transitively). In standalone runner/test projects, adding this package explicitly makes the CLI targets available:
<PackageReference Include="Stride.Core.Assets.CompilerApp" Version="4.3.x">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>build;buildTransitive</IncludeAssets>
</PackageReference>
Without the asset compiler targets, StrideAssetUpdateGeneratedFiles, StrideCleanAsset, and StrideCompileAsset may be unavailable.
Workflow (Do This In Order)
- Add the shader file to the repository.
- Example:
shaders/MyPass.sdsl
- Verify the Stride package includes the folder that contains the shader.
- Check
<project>.sdpkgAssetFolders. - Example valid entry:
AssetFolders:
- Path: !dir ../../shaders
- If the project also links shader files in the
.csproj, add the new shader there too.
- This is easy to miss and can cause “mixin not in module” even if
.sdpkglooks correct. - Prefer linked
Noneitems for shaders (notContent) and setGenerator="StrideShaderKeyGenerator"so*.sdsl.cskey files regenerate. - Ensure generated
*.sdsl.csfiles are compiled (prefer recursive wildcardCompile Includepattern). - Example pattern:
<None Include="..\..\shaders\**\*.sdsl"
Link="Assets\%(RecursiveDir)%(Filename)%(Extension)"
Generator="StrideShaderKeyGenerator" />
<Compile Include="..\..\shaders\**\*.sdsl.cs"
Link="Assets\Generated\%(RecursiveDir)%(Filename)%(Extension)"
Visible="false"
AutoGen="True"
DesignTime="True" />
- Refresh generated shader key files (especially in agent/CLI workflows, outside VS).
- In current Stride NuGet targets,
StrideAssetUpdateGeneratedFilesis a standalone target and may require_StridePrepareAssetCompilerfirst when invoked directly. - Run (PowerShell-safe quoted
/t:form):
dotnet msbuild src/MyStrideApp/MyStrideApp.csproj "/t:_StridePrepareAssetCompiler;StrideAssetUpdateGeneratedFiles" /p:Configuration=Debug
- Force a Stride asset rebuild (do not trust normal
dotnet buildup-to-date checks).
- Run these targets explicitly:
dotnet msbuild src/MyStrideApp/MyStrideApp.csproj /t:StrideCleanAsset /p:Configuration=Debug
dotnet msbuild src/MyStrideApp/MyStrideApp.csproj /t:StrideCompileAsset /p:Configuration=Debug
- Build and run only after the asset rebuild.
dotnet build src/MyStrideApp/MyStrideApp.csproj -c Debug
dotnet run --project src/MyStrideApp/MyStrideApp.csproj -c Debug
- If still failing, then debug shader code/runtime bindings.
- At this point, errors are more likely real shader syntax/semantics/binding issues.
Failure Signatures (Interpretation)
-
E1202: The mixin [X] ... is not in the module -
Meaning:
- Shader not included in Stride asset module yet (stale asset DB), or
- Shader file not reachable via
.sdpkgAssetFolders, or - Shader file not linked in
.csprojwhen the project relies on explicit linked shaderContent
-
Action:
- Re-run the workflow above from step 2, especially steps 3-4
-
Stride asset build says many items are
up-to-datebut new shader still missing -
Meaning:
- Up-to-date inputs did not include your new shader path (or cache state is stale)
-
Action:
- Run
StrideCleanAssetthenStrideCompileAsset
- Run
-
C# bindings suddenly stop working after shader parameter rename/addition
-
Meaning:
- Generated
*.sdsl.cskeys are stale or missing, or code is using string keys manually
- Generated
-
Action:
- Run
_StridePrepareAssetCompiler;StrideAssetUpdateGeneratedFiles - Prefer generated
<ShaderName>Keysover string key lookup
- Run
-
Generated
*.sdsl.csfails to compile on a shaderfloatdefault value -
Meaning:
- The shader default literal was written as
100.0(double-like in generated C#) and the generated key file emitsParameterKeys.NewValue<float>(100.0)
- The shader default literal was written as
-
Action:
- Write explicit float literals in SDSL defaults (for example
100.0f) - Re-run generated-file update target
- Write explicit float literals in SDSL defaults (for example
Agent Rules (Preventing Workarounds Too Early)
- Do not add low-level D3D/SharpDX shader dispatch workarounds for a newly-added shader until the explicit Stride asset rebuild workflow has been executed.
- Always inspect both:
.sdpkgAssetFolders.csprojlinked shaderContentitems (if present in that project)
- Prefer generated
*.sdsl.cskey classes for parameter binding; avoid string keys unless necessary. - When reporting results, state whether
StrideAssetUpdateGeneratedFiles,StrideCleanAsset, andStrideCompileAssetwere run.
Quick Checklist
.sdslfile exists.sdpkgasset folder includes its directory.csprojlinks the shader (if project uses linked shaderContent).csprojuses linkedNoneshader items (preferred) or explicit generator metadata on linked shader itemsGenerator="StrideShaderKeyGenerator"set on linked shader itemsCompile Include="..\\..\\shaders\\**\\*.sdsl.cs"(or equivalent) present so generated keys compile_StridePrepareAssetCompiler;StrideAssetUpdateGeneratedFilesrun after shader changesStrideCleanAssetrunStrideCompileAssetrundotnet build/dotnet runrun after asset rebuild