• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DemoBytom / DemoEngine / 23769862947

30 Mar 2026 10:01PM UTC coverage: 30.548% (+0.007%) from 30.541%
23769862947

push

coveralls.net

DemoBytom
Drawing Mandlebrot fractal

1276 of 4177 relevant lines covered (30.55%)

0.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Demo.Engine.Platform.DirectX12/ForwardPlusRenderer/PostProcessService.cs
1
// Copyright © Michał Dembski and contributors.
2
// Distributed under MIT license. See LICENSE file in the root for more information.
3

4
using System.Diagnostics.CodeAnalysis;
5
using System.Runtime.InteropServices;
6
using Demo.Engine.Platform.DirectX12.Shaders;
7
using Microsoft.Extensions.Logging;
8
using Vortice.Direct3D;
9
using Vortice.Direct3D12;
10
using Vortice.DXGI;
11

12
namespace Demo.Engine.Platform.DirectX12.ForwardPlusRenderer;
13

14
internal sealed class PostProcessService(
×
15
    ILogger<PostProcessService> logger,
×
16
    ID3D12RenderingEngine renderingEngine,
×
17
    IGPassService gPassService,
×
18
    IEngineShaderManager engineShaderManager)
×
19
    : IPostProcessService,
20
      IDisposable
21
{
22
    private bool _disposedValue;
23

24
    private ID3D12RootSignature? _rootSignature = null;
25
    private ID3D12PipelineState? _pipelineStateObject = null;
26

27
    [MemberNotNullWhen(true,
28
        nameof(_rootSignature),
29
        nameof(_pipelineStateObject))]
30
    public bool Initialize()
31
        => CreateFxPsoAndRootSignature()
×
32
        ;
33

34
    /// <summary>
35
    /// Post process method
36
    /// </summary>
37
    /// <param name="commandList">command list to execute on</param>
38
    /// <param name="targetRTV">target render target view</param>
39
    public void PostProcess(
40
        ID3D12GraphicsCommandList commandList,
41
        CpuDescriptorHandle targetRTV)
42
    {
43
        commandList.SetGraphicsRootSignature(_rootSignature);
×
44
        commandList.SetPipelineState(_pipelineStateObject);
×
45

46
        commandList.SetGraphicsRoot32BitConstant(
×
47
            rootParameterIndex: (int)RootParametersIndices.RootConstants,
×
48
            srcData: (uint)gPassService.MainBuffer.SRV.Index,
×
49
            destOffsetIn32BitValues: 0);
×
50
        commandList.SetGraphicsRootDescriptorTable(
×
51
            rootParameterIndex: (int)RootParametersIndices.DescriptorTable,
×
52
            //                                                      TODO NRT!
×
53
            baseDescriptor: renderingEngine.SRVHeapAllocator.GPU_Start!.Value);
×
54
        commandList.IASetPrimitiveTopology(PrimitiveTopology.TriangleList);
×
55
        commandList.OMSetRenderTargets(1, targetRTV);
×
56
        commandList.DrawInstanced(
×
57
            vertexCountPerInstance: 3,
×
58
            instanceCount: 1,
×
59
            startVertexLocation: 0,
×
60
            startInstanceLocation: 0);
×
61
    }
×
62

63
    [MemberNotNullWhen(true,
64
        nameof(_rootSignature),
65
        nameof(_pipelineStateObject))]
66
    private bool CreateFxPsoAndRootSignature()
67
    {
68
        if (_rootSignature is not null)
×
69
        {
70
            throw new InvalidOperationException("Root signature already created!");
×
71
        }
72
        if (_pipelineStateObject is not null)
×
73
        {
74
            throw new InvalidOperationException("Pipeline state object already created!");
×
75
        }
76

77
        var range = new DescriptorRange1(
×
78
            rangeType: DescriptorRangeType.ShaderResourceView,
×
79
            numDescriptors: D3D12.DescriptorRangeOffsetAppend,
×
80
            baseShaderRegister: 0,
×
81
            registerSpace: 0,
×
82
            flags: DescriptorRangeFlags.DescriptorsVolatile);
×
83

84
        var parameters = new RootParameter1[(int)RootParametersIndices.Count];
×
85

86
        parameters[(int)RootParametersIndices.RootConstants] = RootParameter1
×
87
            .ConstantsRootParameter(
×
88
                numConstants: 1,
×
89
                visibility: ShaderVisibility.Pixel,
×
90
                shaderRegister: 1);
×
91
        parameters[(int)RootParametersIndices.DescriptorTable] = RootParameter1
×
92
            .DescriptorTableRootParameter(
×
93
                visibility: ShaderVisibility.Pixel,
×
94
                range);
×
95

96
        //const RootSignatureFlags ROOT_SIGNATURE_FLAGS =
97
        //   RootSignatureFlags.AllowInputAssemblerInputLayout
98
        //   | RootSignatureFlags.DenyAmplificationShaderRootAccess
99
        //   | RootSignatureFlags.DenyDomainShaderRootAccess
100
        //   | RootSignatureFlags.DenyGeometryShaderRootAccess
101
        //   | RootSignatureFlags.DenyHullShaderRootAccess
102
        //   | RootSignatureFlags.DenyMeshShaderRootAccess
103
        //   ;
104

105
        _rootSignature = renderingEngine.Device.CreateRootSignature(
×
106
            new RootSignatureDescription1(
×
107
                //ROOT_SIGNATURE_FLAGS,
×
108
                RootSignatureExtensions.DenyAll
×
109
                & ~RootSignatureFlags.DenyPixelShaderRootAccess,
×
110
                parameters));
×
111

112
        _rootSignature.NameObject(
×
113
            "Post Process FX root signature",
×
114
            logger);
×
115

116
        var vertexShader = engineShaderManager.GetShader(ShaderId.FullscreenTriangleVS);
×
117
        var pixelShader = engineShaderManager.GetShader(ShaderId.PostProcessPS);
×
118
        var primitiveTopology = PrimitiveTopologyType.Triangle;
×
119
        var renderTagetFormats = new Format[] { Common.DEFAULT_BACK_BUFFER_FORMAT };
×
120

121
        PipelineStateStream stream = new()
×
122
        {
×
123

×
124
            RootSignature = new(_rootSignature),
×
125
            VertexShader = new(vertexShader.ShaderBlob.Span),
×
126
            PixelShader = new(pixelShader.ShaderBlob.Span),
×
127
            PrimitiveTopology = new(primitiveTopology),
×
128
            RenderTargetFormats = new(renderTagetFormats),
×
129
            Rasterizer = new(RasterizerDescription.CullNone), // no culling
×
130
        };
×
131

132
        _pipelineStateObject = renderingEngine.Device.CreatePipelineState(stream);
×
133
        _pipelineStateObject.NameObject(
×
134
            "Post Process FX pipeline state object",
×
135
            logger);
×
136

137
        return true;
×
138
    }
139

140
    [StructLayout(LayoutKind.Sequential)]
141
    private readonly struct PipelineStateStream
142
    {
143
        public required PipelineStateSubObjectTypeRootSignature RootSignature { get; init; }
144
        public required PipelineStateSubObjectTypeVertexShader VertexShader { get; init; }
145
        public required PipelineStateSubObjectTypePixelShader PixelShader { get; init; }
146
        public required PipelineStateSubObjectTypePrimitiveTopology PrimitiveTopology { get; init; }
147
        public required PipelineStateSubObjectTypeRenderTargetFormats RenderTargetFormats { get; init; }
148
        public required PipelineStateSubObjectTypeRasterizer Rasterizer { get; init; }
149
    }
150

151
    private void Dispose(bool disposing)
152
    {
153
        if (!_disposedValue)
×
154
        {
155
            if (disposing)
×
156
            {
157
                _rootSignature?.Dispose();
×
158
                _pipelineStateObject?.Dispose();
×
159
            }
160

161
            _disposedValue = true;
×
162
        }
163
    }
×
164

165
    public void Dispose()
166
    {
167
        // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
168
        Dispose(disposing: true);
×
169
        GC.SuppressFinalize(this);
×
170
    }
×
171

172
    private enum RootParametersIndices
173
    {
174
        RootConstants,
175
        DescriptorTable,
176

177
        // MUST BE LAST! :)
178
        Count,
179
    }
180
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc