Skip to content

Commit 1ad580a

Browse files
committed
style: address review feedback (headers, file-scoped namespaces, xmldoc)
1 parent 0b74e2e commit 1ad580a

3 files changed

Lines changed: 99 additions & 99 deletions

File tree

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
1+
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net)
22
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
33

44
using Xunit;
@@ -8,53 +8,52 @@
88
using Stride.Rendering;
99
using Stride.Rendering.Compositing;
1010

11-
namespace Stride.Engine.Tests
11+
namespace Stride.Engine.Tests;
12+
13+
public class ForwardRendererTransparentTargetsTest : GameTestBase
1214
{
13-
public class ForwardRendererTransparentTargetsTest : GameTestBase
15+
/// <summary>
16+
/// Verifies the ForwardRenderer binds only as many render targets as the transparent stage declares it
17+
/// outputs, dropping surplus opaque MRT targets (e.g. those Local Reflections adds). See #3251.
18+
/// </summary>
19+
[Fact]
20+
public void BindsOnlyTransparentStageDeclaredTargets()
1421
{
15-
/// <summary>
16-
/// Verifies the ForwardRenderer binds only as many render targets as the transparent stage declares it
17-
/// outputs, dropping surplus opaque MRT targets (e.g. those Local Reflections adds). See #3251.
18-
/// </summary>
19-
[Fact]
20-
public void BindsOnlyTransparentStageDeclaredTargets()
22+
PerformDrawTest((game, context) =>
2123
{
22-
PerformDrawTest((game, context) =>
24+
var device = game.GraphicsDevice;
25+
var commandList = context.CommandList;
26+
27+
var transparentStage = new RenderStage("Transparent", "Main")
2328
{
24-
var device = game.GraphicsDevice;
25-
var commandList = context.CommandList;
26-
27-
var transparentStage = new RenderStage("Transparent", "Main")
28-
{
29-
Output = new RenderOutputDescription(PixelFormat.R8G8B8A8_UNorm, PixelFormat.D24_UNorm_S8_UInt),
30-
};
31-
var forwardRenderer = new ForwardRenderer { TransparentRenderStage = transparentStage };
32-
33-
// Formats are irrelevant here (only the target count matters); use a widely supported one.
34-
var color = Texture.New2D(device, 16, 16, PixelFormat.R8G8B8A8_UNorm, TextureFlags.RenderTarget);
35-
var normal = Texture.New2D(device, 16, 16, PixelFormat.R8G8B8A8_UNorm, TextureFlags.RenderTarget);
36-
var specular = Texture.New2D(device, 16, 16, PixelFormat.R8G8B8A8_UNorm, TextureFlags.RenderTarget);
37-
var depth = Texture.New2D(device, 16, 16, PixelFormat.D24_UNorm_S8_UInt, TextureFlags.DepthStencil);
38-
39-
// Opaque stage left 3 color targets + depth bound, as SSLR would.
40-
commandList.SetRenderTargets(depth, color, normal, specular);
41-
Assert.Equal(3, commandList.RenderTargetCount);
42-
43-
forwardRenderer.SetTransparentStageRenderTargets(context);
44-
45-
Assert.Equal(1, commandList.RenderTargetCount);
46-
Assert.Equal(color, commandList.RenderTargets[0]);
47-
Assert.Equal(depth, commandList.DepthStencilBuffer);
48-
49-
// Already matching the declared count: no change.
50-
forwardRenderer.SetTransparentStageRenderTargets(context);
51-
Assert.Equal(1, commandList.RenderTargetCount);
52-
53-
color.Dispose();
54-
normal.Dispose();
55-
specular.Dispose();
56-
depth.Dispose();
57-
}, takeSnapshot: false);
58-
}
29+
Output = new RenderOutputDescription(PixelFormat.R8G8B8A8_UNorm, PixelFormat.D24_UNorm_S8_UInt),
30+
};
31+
var forwardRenderer = new ForwardRenderer { TransparentRenderStage = transparentStage };
32+
33+
// Formats are irrelevant here (only the target count matters); use a widely supported one.
34+
var color = Texture.New2D(device, 16, 16, PixelFormat.R8G8B8A8_UNorm, TextureFlags.RenderTarget);
35+
var normal = Texture.New2D(device, 16, 16, PixelFormat.R8G8B8A8_UNorm, TextureFlags.RenderTarget);
36+
var specular = Texture.New2D(device, 16, 16, PixelFormat.R8G8B8A8_UNorm, TextureFlags.RenderTarget);
37+
var depth = Texture.New2D(device, 16, 16, PixelFormat.D24_UNorm_S8_UInt, TextureFlags.DepthStencil);
38+
39+
// Opaque stage left 3 color targets + depth bound, as SSLR would.
40+
commandList.SetRenderTargets(depth, color, normal, specular);
41+
Assert.Equal(3, commandList.RenderTargetCount);
42+
43+
forwardRenderer.SetTransparentStageRenderTargets(context);
44+
45+
Assert.Equal(1, commandList.RenderTargetCount);
46+
Assert.Equal(color, commandList.RenderTargets[0]);
47+
Assert.Equal(depth, commandList.DepthStencilBuffer);
48+
49+
// Already matching the declared count: no change.
50+
forwardRenderer.SetTransparentStageRenderTargets(context);
51+
Assert.Equal(1, commandList.RenderTargetCount);
52+
53+
color.Dispose();
54+
normal.Dispose();
55+
specular.Dispose();
56+
depth.Dispose();
57+
}, takeSnapshot: false);
5958
}
6059
}

sources/engine/Stride.Engine/Rendering/Compositing/ForwardRenderer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,10 @@ private Texture ResolveDepthAsSRV(RenderDrawContext context)
809809
return depthStencilSRV;
810810
}
811811

812-
// Binds only as many targets as the transparent stage outputs; extra opaque MRT targets left bound by
813-
// post-effects (e.g. SSLR) would exceed its render pass' attachment count and lose the device (#3251).
812+
/// <summary>
813+
/// Binds only the render targets the transparent stage outputs, dropping any surplus opaque targets left
814+
/// bound by post-effects (e.g. Local Reflections) so the framebuffer matches the transparent render pass.
815+
/// </summary>
814816
internal void SetTransparentStageRenderTargets(RenderDrawContext drawContext)
815817
{
816818
if (TransparentRenderStage == null)
Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
1+
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net)
22
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
33

44
using System;
@@ -8,69 +8,68 @@
88
using Stride.Core.Mathematics;
99
using Stride.Rendering;
1010

11-
namespace Stride.Graphics.Tests
11+
namespace Stride.Graphics.Tests;
12+
13+
public class TestFramebufferAttachmentGuard : GraphicTestGameBase
1214
{
13-
public class TestFramebufferAttachmentGuard : GraphicTestGameBase
15+
private struct Vertex
1416
{
15-
private struct Vertex
16-
{
17-
public Vector3 Position;
18-
public Vector2 TexCoords;
19-
}
17+
public Vector3 Position;
18+
public Vector2 TexCoords;
19+
}
2020

21-
/// <summary>
22-
/// The Vulkan backend's debug guard turns a framebuffer/render-pass attachment-count mismatch into a clear
23-
/// exception instead of a device loss. Verify it fires when more render targets are bound than the active
24-
/// pipeline's render pass declares.
25-
/// </summary>
26-
[SkippableFact]
27-
public void ThrowsWhenBoundTargetsExceedPipelineRenderPass()
21+
/// <summary>
22+
/// The Vulkan backend's debug guard turns a framebuffer/render-pass attachment-count mismatch into a clear
23+
/// exception instead of a device loss. Verify it fires when more render targets are bound than the active
24+
/// pipeline's render pass declares.
25+
/// </summary>
26+
[SkippableFact]
27+
public void ThrowsWhenBoundTargetsExceedPipelineRenderPass()
28+
{
29+
PerformTest(game =>
2830
{
29-
PerformTest(game =>
30-
{
31-
// The guard lives in the Vulkan backend (and needs the debug device, which GraphicTestGameBase sets).
32-
Skip.IfNot(GraphicsDevice.Platform == GraphicsPlatform.Vulkan, "Attachment guard is Vulkan-only.");
31+
// The guard lives in the Vulkan backend (and needs the debug device, which GraphicTestGameBase sets).
32+
Skip.IfNot(GraphicsDevice.Platform == GraphicsPlatform.Vulkan, "Attachment guard is Vulkan-only.");
3333

34-
var device = game.GraphicsDevice;
35-
var commandList = game.GraphicsContext.CommandList;
34+
var device = game.GraphicsDevice;
35+
var commandList = game.GraphicsContext.CommandList;
3636

37-
var backBuffer = device.Presenter.BackBuffer;
38-
var depth = device.Presenter.DepthStencilBuffer;
39-
var extraTarget = Texture.New2D(device, backBuffer.Width, backBuffer.Height, backBuffer.Format, TextureFlags.RenderTarget);
37+
var backBuffer = device.Presenter.BackBuffer;
38+
var depth = device.Presenter.DepthStencilBuffer;
39+
var extraTarget = Texture.New2D(device, backBuffer.Width, backBuffer.Height, backBuffer.Format, TextureFlags.RenderTarget);
4040

41-
var declaration = new VertexDeclaration(VertexElement.Position<Vector3>(), VertexElement.TextureCoordinate<Vector2>());
42-
var vertexBuffer = Buffer.Vertex.New(device, new Vertex[3], GraphicsResourceUsage.Default);
43-
var sampledTexture = Texture.New2D(device, 4, 4, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource);
41+
var declaration = new VertexDeclaration(VertexElement.Position<Vector3>(), VertexElement.TextureCoordinate<Vector2>());
42+
var vertexBuffer = Buffer.Vertex.New(device, new Vertex[3], GraphicsResourceUsage.Default);
43+
var sampledTexture = Texture.New2D(device, 4, 4, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource);
4444

45-
var effect = new EffectInstance(new Effect(device, SpriteEffect.Bytecode));
46-
effect.Parameters.Set(TexturingKeys.Texture0, sampledTexture);
47-
effect.Parameters.Set(TexturingKeys.Sampler, device.SamplerStates.LinearClamp);
48-
effect.UpdateEffect(device);
45+
var effect = new EffectInstance(new Effect(device, SpriteEffect.Bytecode));
46+
effect.Parameters.Set(TexturingKeys.Texture0, sampledTexture);
47+
effect.Parameters.Set(TexturingKeys.Sampler, device.SamplerStates.LinearClamp);
48+
effect.UpdateEffect(device);
4949

50-
var pipelineState = new MutablePipelineState(device);
51-
pipelineState.State.SetDefaults();
52-
pipelineState.State.RootSignature = effect.RootSignature;
53-
pipelineState.State.EffectBytecode = effect.Effect.Bytecode;
54-
pipelineState.State.InputElements = declaration.CreateInputElements();
55-
pipelineState.State.PrimitiveType = PrimitiveType.TriangleList;
50+
var pipelineState = new MutablePipelineState(device);
51+
pipelineState.State.SetDefaults();
52+
pipelineState.State.RootSignature = effect.RootSignature;
53+
pipelineState.State.EffectBytecode = effect.Effect.Bytecode;
54+
pipelineState.State.InputElements = declaration.CreateInputElements();
55+
pipelineState.State.PrimitiveType = PrimitiveType.TriangleList;
5656

57-
// Capture the pipeline Output with a single color + depth bound: its render pass declares 2 attachments.
58-
commandList.SetRenderTargetAndViewport(depth, backBuffer);
59-
pipelineState.State.Output.CaptureState(commandList);
60-
pipelineState.Update();
57+
// Capture the pipeline Output with a single color + depth bound: its render pass declares 2 attachments.
58+
commandList.SetRenderTargetAndViewport(depth, backBuffer);
59+
pipelineState.State.Output.CaptureState(commandList);
60+
pipelineState.Update();
6161

62-
// Now bind two color targets + depth: the framebuffer would have 3 attachments, mismatching the pass.
63-
commandList.SetRenderTargets(depth, backBuffer, extraTarget);
64-
commandList.SetPipelineState(pipelineState.CurrentState);
65-
commandList.SetVertexBuffer(0, vertexBuffer, 0, declaration.VertexStride);
66-
effect.Apply(game.GraphicsContext);
62+
// Now bind two color targets + depth: the framebuffer would have 3 attachments, mismatching the pass.
63+
commandList.SetRenderTargets(depth, backBuffer, extraTarget);
64+
commandList.SetPipelineState(pipelineState.CurrentState);
65+
commandList.SetVertexBuffer(0, vertexBuffer, 0, declaration.VertexStride);
66+
effect.Apply(game.GraphicsContext);
6767

68-
var exception = Assert.Throws<InvalidOperationException>(() => commandList.Draw(3));
69-
Assert.Contains("render pass", exception.Message);
68+
var exception = Assert.Throws<InvalidOperationException>(() => commandList.Draw(3));
69+
Assert.Contains("render pass", exception.Message);
7070

71-
sampledTexture.Dispose();
72-
extraTarget.Dispose();
73-
});
74-
}
71+
sampledTexture.Dispose();
72+
extraTarget.Dispose();
73+
});
7574
}
7675
}

0 commit comments

Comments
 (0)