|
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) |
2 | 2 | // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. |
3 | 3 |
|
4 | 4 | using System; |
|
8 | 8 | using Stride.Core.Mathematics; |
9 | 9 | using Stride.Rendering; |
10 | 10 |
|
11 | | -namespace Stride.Graphics.Tests |
| 11 | +namespace Stride.Graphics.Tests; |
| 12 | + |
| 13 | +public class TestFramebufferAttachmentGuard : GraphicTestGameBase |
12 | 14 | { |
13 | | - public class TestFramebufferAttachmentGuard : GraphicTestGameBase |
| 15 | + private struct Vertex |
14 | 16 | { |
15 | | - private struct Vertex |
16 | | - { |
17 | | - public Vector3 Position; |
18 | | - public Vector2 TexCoords; |
19 | | - } |
| 17 | + public Vector3 Position; |
| 18 | + public Vector2 TexCoords; |
| 19 | + } |
20 | 20 |
|
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 => |
28 | 30 | { |
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."); |
33 | 33 |
|
34 | | - var device = game.GraphicsDevice; |
35 | | - var commandList = game.GraphicsContext.CommandList; |
| 34 | + var device = game.GraphicsDevice; |
| 35 | + var commandList = game.GraphicsContext.CommandList; |
36 | 36 |
|
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); |
40 | 40 |
|
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); |
44 | 44 |
|
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); |
49 | 49 |
|
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; |
56 | 56 |
|
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(); |
61 | 61 |
|
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); |
67 | 67 |
|
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); |
70 | 70 |
|
71 | | - sampledTexture.Dispose(); |
72 | | - extraTarget.Dispose(); |
73 | | - }); |
74 | | - } |
| 71 | + sampledTexture.Dispose(); |
| 72 | + extraTarget.Dispose(); |
| 73 | + }); |
75 | 74 | } |
76 | 75 | } |
0 commit comments