Skip to content

Commit ace59ec

Browse files
committed
fix: reset stale shadow map texture and use ShaderResource-only depth fallback to avoid Vulkan layout mismatch
1 parent 9308924 commit ace59ec

6 files changed

Lines changed: 11 additions & 5 deletions

File tree

sources/engine/Stride.Graphics/GraphicsDeviceExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static Texture GetSharedDepthTexture(this GraphicsDevice device)
166166
? new Texture(device, "DepthTexture")
167167
: new Texture(device);
168168

169-
var description = TextureDescription.New2D(1, 1, PixelFormat.D32_Float, TextureFlags.DepthStencil | TextureFlags.ShaderResource);
169+
var description = TextureDescription.New2D(1, 1, PixelFormat.D32_Float, TextureFlags.ShaderResource);
170170
texture.InitializeFrom(description);
171171

172172
return texture;

sources/engine/Stride.Rendering/Rendering/Shadows/LightDirectionalShadowMapRenderer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ public override void UpdateLightCount(int lightLastCount, int lightCurrentCount)
542542

543543
public override void ApplyViewParameters(RenderDrawContext context, ParameterCollection parameters, FastListStruct<LightDynamicEntry> currentLights)
544544
{
545+
shadowMapTexture = null;
545546
for (int lightIndex = 0; lightIndex < currentLights.Count; ++lightIndex)
546547
{
547548
var lightEntry = currentLights[lightIndex];
@@ -576,7 +577,7 @@ public override void ApplyViewParameters(RenderDrawContext context, ParameterCol
576577
}
577578
}
578579

579-
parameters.Set(shadowMapTextureKey, shadowMapTexture);
580+
parameters.Set(shadowMapTextureKey, shadowMapTexture ?? context.GraphicsDevice.GetSharedDepthTexture());
580581
parameters.Set(shadowMapTextureSizeKey, shadowMapTextureSize);
581582
parameters.Set(shadowMapTextureTexelSizeKey, shadowMapTextureTexelSize);
582583
parameters.Set(cascadeSplitsKey, cascadeSplits);

sources/engine/Stride.Rendering/Rendering/Shadows/LightPointShadowMapRendererCubeMap.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ public override void ApplyDrawParameters(RenderDrawContext context, ParameterCol
247247
var boundingBox2 = (BoundingBox)boundingBox;
248248
bool shadowMapCreated = false;
249249
int lightIndex = 0;
250+
shadowMapTexture = null;
250251

251252
for (int i = 0; i < currentLights.Count; ++i)
252253
{
@@ -281,7 +282,7 @@ public override void ApplyDrawParameters(RenderDrawContext context, ParameterCol
281282
}
282283
}
283284

284-
parameters.Set(shadowMapTextureKey, shadowMapTexture);
285+
parameters.Set(shadowMapTextureKey, shadowMapTexture ?? context.GraphicsDevice.GetSharedDepthTexture());
285286
parameters.Set(shadowMapTextureSizeKey, shadowMapTextureSize);
286287
parameters.Set(shadowMapTextureTexelSizeKey, shadowMapTextureTexelSize);
287288

sources/engine/Stride.Rendering/Rendering/Shadows/LightPointShadowMapRendererParaboloid.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ public override void ApplyDrawParameters(RenderDrawContext context, ParameterCol
278278
var boundingBox2 = (BoundingBox)boundingBox;
279279
bool shadowMapCreated = false;
280280
int lightIndex = 0;
281+
shadowMapTexture = null;
281282

282283
for (int i = 0; i < currentLights.Count; ++i)
283284
{
@@ -307,7 +308,7 @@ public override void ApplyDrawParameters(RenderDrawContext context, ParameterCol
307308
}
308309
}
309310

310-
parameters.Set(shadowMapTextureKey, shadowMapTexture);
311+
parameters.Set(shadowMapTextureKey, shadowMapTexture ?? context.GraphicsDevice.GetSharedDepthTexture());
311312
parameters.Set(shadowMapTextureSizeKey, shadowMapTextureSize);
312313
parameters.Set(shadowMapTextureTexelSizeKey, shadowMapTextureTexelSize);
313314

sources/engine/Stride.Rendering/Rendering/Shadows/LightSpotShadowMapRenderer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public override void ApplyDrawParameters(RenderDrawContext context, ParameterCol
215215
var boundingBox2 = (BoundingBox)boundingBox;
216216
bool shadowMapCreated = false;
217217
int lightIndex = 0;
218+
shadowMapTexture = null;
218219

219220
for (int i = 0; i < currentLights.Count; ++i)
220221
{
@@ -246,7 +247,7 @@ public override void ApplyDrawParameters(RenderDrawContext context, ParameterCol
246247
}
247248
}
248249

249-
parameters.Set(shadowMapTextureKey, shadowMapTexture);
250+
parameters.Set(shadowMapTextureKey, shadowMapTexture ?? context.GraphicsDevice.GetSharedDepthTexture());
250251
parameters.Set(shadowMapTextureSizeKey, shadowMapTextureSize);
251252
parameters.Set(shadowMapTextureTexelSizeKey, shadowMapTextureTexelSize);
252253
parameters.Set(worldToShadowCascadeUVsKey, worldToShadowCascadeUV);

sources/engine/Stride.Rendering/Rendering/Shadows/ShadowMapRenderer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ public void PrepareAtlasAsShaderResourceViews(CommandList commandList)
153153
{
154154
atlas.PrepareAsShaderResourceView(commandList);
155155
}
156+
157+
// Fallback atlas uses ShaderResource-only texture, no transition needed
156158
}
157159

158160
public void Flush(RenderDrawContext context)

0 commit comments

Comments
 (0)