Skip to content

Commit

Permalink
[DX12] Initial placeholder root signature implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Syncaidius committed Dec 28, 2023
1 parent b10babb commit a08f74b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
3 changes: 1 addition & 2 deletions Molten.Graphics.DX11/Shaders/ShaderPassDX11.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Silk.NET.Core.Native;
using Silk.NET.Direct3D11;
using Silk.NET.Direct3D11;

namespace Molten.Graphics.DX11
{
Expand Down
10 changes: 4 additions & 6 deletions Molten.Graphics.DX12/Pipeline/CommandAllocatorDX12.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@

namespace Molten.Graphics.DX12
{
internal unsafe class CommandAllocatorDX12 : GraphicsObject
internal unsafe class CommandAllocatorDX12 : GraphicsObject<DeviceDX12>
{
ID3D12CommandAllocator* _handle;
ThreadedList<CommandListDX12> _allocated;
DeviceDX12 _device;

public CommandAllocatorDX12(DeviceDX12 device, CommandListType type) : base(device)
{
_device = device;
Guid guid = ID3D12CommandAllocator.Guid;
Type = type;

void* ptr = null;
HResult hr = device.Ptr->CreateCommandAllocator(CommandListType.Direct, &guid, &ptr);
HResult hr = Device.Ptr->CreateCommandAllocator(CommandListType.Direct, &guid, &ptr);
if (!device.Log.CheckResult(hr, () => "Failed to create command allocator"))
hr.Throw();

Expand All @@ -29,8 +27,8 @@ public CommandAllocatorDX12(DeviceDX12 device, CommandListType type) : base(devi
where T : unmanaged
{
void* ptr = null;
HResult hr = _device.Ptr->CreateCommandList(0, Type, _handle, pInitialState, &guid, &ptr);
if (!_device.Log.CheckResult(hr, () => $"Failed to allocate {Type} command list"))
HResult hr = Device.Ptr->CreateCommandList(0, Type, _handle, pInitialState, &guid, &ptr);
if (!Device.Log.CheckResult(hr, () => $"Failed to allocate {Type} command list"))
hr.Throw();

return (T*)ptr;
Expand Down
48 changes: 43 additions & 5 deletions Molten.Graphics.DX12/Pipeline/RootSignatureDX12.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
namespace Molten.Graphics.DX12.Pipeline
using Silk.NET.Core.Native;
using Silk.NET.Direct3D12;

namespace Molten.Graphics.DX12
{
internal class RootSignatureDX12 : GraphicsObject<DeviceDX12>
internal unsafe class RootSignatureDX12 : GraphicsObject<DeviceDX12>
{
public RootSignatureDX12(DeviceDX12 device) : base(device)
ID3D12RootSignature* _handle;

internal RootSignatureDX12(DeviceDX12 device/*, ShaderPassDX12 pass*/) : base(device)
{
// TODO Check device feature support for root signature max version.

RootParameter1* parameters = EngineUtil.AllocArray<RootParameter1>(1); // TODO Get the correct size based on the provided pass.
RootSignatureDesc1 rootSignatureDesc1 = new()
{
Flags = RootSignatureFlags.None,
NumParameters = 0, // TODO Get this from the number of input parameters (textures, constant buffers, etc) required by the shader pass.
PParameters = parameters,
NumStaticSamplers = 0,
PStaticSamplers = null,
};

EngineUtil.Free(ref parameters);

// TODO build based on input resources, output resources and samplers of the provided shader pass.
// TODO Note for Vulkan: Shaders only operate on a set number of render target outputs, so we'll always know how many should be bound based on this.
// Example 1: If a shader only outputs to a single render target, then we know that only 1 render target will always need to be bound.
// Example 2: If a deferred shader (GBuffer, normals, depth, etc) outputs to 3 render targets, then we know that 3 render targets will always need to be bound.
// This also means we can perform validation for missing render targets if they are required.

// Serialize the root signature.
ID3D10Blob* signature = null;
ID3D10Blob* error = null;
RendererDX12 renderer = device.Renderer as RendererDX12;
HResult hr = renderer.Api.SerializeRootSignature((RootSignatureDesc*)&rootSignatureDesc1, D3DRootSignatureVersion.Version11, &signature, &error);
if(!device.Log.CheckResult(hr, () => "Failed to serialize root signature"))
hr.Throw();

// Create the root signature.
Guid guid = ID3D12RootSignature.Guid;
void* ptr = null;
hr = device.Ptr->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), &guid, &ptr);
if (!device.Log.CheckResult(hr, () => "Failed to create root signature"))
hr.Throw();
}

protected override void OnGraphicsRelease()
{

throw new NotImplementedException();
SilkUtil.ReleasePtr(ref _handle);
}
}
}
3 changes: 3 additions & 0 deletions Molten.Graphics.DX12/RendererDX12.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected override unsafe GraphicsManager OnInitializeDisplayManager(GraphicsSet
_debug->EnableDebugLayer();
}

_api->SEr
Builder = new DeviceBuilderDX12(_api, this);
_displayManager = new GraphicsManagerDXGI(CreateDevice, Builder.GetCapabilities);
return _displayManager;
Expand Down Expand Up @@ -68,6 +69,8 @@ protected override void OnDisposeBeforeRender()

protected override DxcCompiler Compiler { get; }

internal D3D12 Api => _api;

internal ID3D12Debug6* Debug => _debug;
}
}
7 changes: 1 addition & 6 deletions Molten.Graphics.DX12/Shaders/HlslDx12Compiler.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using Molten.Graphics.Dxc;
using Silk.NET.Core.Native;
using Silk.NET.Direct3D.Compilers;
Expand Down

0 comments on commit a08f74b

Please sign in to comment.