Update RenderingContext and D3D12Renderer to use new API.

This commit is contained in:
2025-11-06 04:13:20 +00:00
parent b3eeb8d366
commit 15aca9aefb
17 changed files with 184 additions and 195 deletions

View File

@@ -397,7 +397,7 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
// _commandList.Get()->DispatchRays();
}
public void Upload<T>(Handle<GraphicsBuffer> buffer, ReadOnlySpan<T> data)
public void UploadBuffer<T>(Handle<GraphicsBuffer> buffer, ReadOnlySpan<T> data)
where T : unmanaged
{
ThrowIfDisposed();
@@ -422,7 +422,7 @@ internal unsafe class D3D12CommandBuffer : ICommandBuffer
_commandList.Get()->CopyBufferRegion(pResource, 0, pUploadResource, 0, sizeInBytes);
}
public void Upload(Handle<Texture> texture, params ReadOnlySpan<SubResourceData> subresources)
public void UploadTexture(Handle<Texture> texture, params ReadOnlySpan<SubResourceData> subresources)
{
ThrowIfDisposed();
ThrowIfNotRecording();

View File

@@ -9,7 +9,7 @@ internal unsafe class D3D12GraphicsEngine : IGraphicsEngine
#endif
private readonly D3D12RenderDevice _device;
private readonly D3D12PipelineLibrary _stateController;
private readonly D3D12PipelineLibrary _pipelineLibrary;
private readonly D3D12DescriptorAllocator _descriptorAllocator;
private readonly D3D12ResourceDatabase _resourceDatabase;
@@ -17,13 +17,11 @@ internal unsafe class D3D12GraphicsEngine : IGraphicsEngine
private readonly D3D12CommandBuffer _copyCommandBuffer;
public IRenderDevice Device => _device;
public IPipelineLibrary PipelineLibrary => _pipelineLibrary;
public IResourceDatabase ResourceDatabase => _resourceDatabase;
public IResourceAllocator ResourceAllocator => _resourceAllocator;
public IPipelineLibrary PipelineStateController => _stateController;
public D3D12GraphicsEngine(RenderSystem renderSystem)
{
#if DEBUG
@@ -35,10 +33,10 @@ internal unsafe class D3D12GraphicsEngine : IGraphicsEngine
_resourceDatabase = new(_descriptorAllocator);
_resourceAllocator = new(renderSystem, _device, _descriptorAllocator, _resourceDatabase);
_stateController = new(_device, _resourceDatabase, null);
_pipelineLibrary = new(_device, _resourceDatabase);
_copyCommandBuffer = new(
_device,
_stateController,
_pipelineLibrary,
_resourceDatabase,
_resourceAllocator,
_descriptorAllocator,
@@ -59,7 +57,7 @@ internal unsafe class D3D12GraphicsEngine : IGraphicsEngine
{
return new D3D12CommandBuffer(
_device,
_stateController,
_pipelineLibrary,
_resourceDatabase,
_resourceAllocator,
_descriptorAllocator,
@@ -84,7 +82,7 @@ internal unsafe class D3D12GraphicsEngine : IGraphicsEngine
public void Dispose()
{
_copyCommandBuffer.Dispose();
_stateController.Dispose();
_pipelineLibrary.Dispose();
_resourceAllocator.Dispose();
_resourceDatabase.Dispose();
@@ -97,4 +95,4 @@ internal unsafe class D3D12GraphicsEngine : IGraphicsEngine
GC.SuppressFinalize(this);
}
}
}

View File

@@ -184,7 +184,21 @@ internal unsafe class D3D12Renderer : IRenderer
{
var clearColor = new Color128 { r = 1.0f, g = 0.0f, b = 1.0f, a = 1.0f };
cmd.BeginRenderPass(target, Handle<Texture>.Invalid, clearColor);
Span<PassRenderTargetDesc> rtDesc = stackalloc PassRenderTargetDesc[1];
rtDesc[0] = new PassRenderTargetDesc
{
texture = target,
clearColor = clearColor,
};
var depthDesc = new PassDepthStencilDesc
{
texture = Handle<Texture>.Invalid,
clearDepth = 1.0f,
clearStencil = 0,
};
cmd.BeginRenderPass(rtDesc, depthDesc, false);
var viewport = new ViewportDesc { width = _currentSize.x, height = _currentSize.y, minDepth = 0, maxDepth = 1 };
var scissor = new RectDesc { right = _currentSize.x, bottom = _currentSize.y };
@@ -213,17 +227,12 @@ internal unsafe class D3D12Renderer : IRenderer
// For now, we'll do a simple copy operation
// In a real implementation, you would use a blit shader for post-processing
// TODO: Implement proper blit operation with shader
// FIX: Implement proper blit operation with shader
// This is a placeholder - in D3D12, you would typically:
// 1. Set render target to the destination
// 2. Use a full-screen quad/triangle with a shader that samples from the source
// 3. Apply post-processing effects (tone mapping, gamma correction, etc.)
// For now, just clear the destination (this should be replaced with actual blit)
var clearColor = new Color128 { r = 0.0f, g = 0.0f, b = 0.0f, a = 1.0f };
cmd.BeginRenderPass(destination, Handle<Texture>.Invalid, clearColor);
cmd.EndRenderPass();
// Handle swap chain back buffer transitions if needed
if (_swapChain != null)
{

View File

@@ -90,12 +90,6 @@ internal class D3D12ResourceDatabase : IResourceDatabase, IDisposable
}
}
private struct Slot<T>
{
public T value;
public bool occupied;
}
private readonly D3D12DescriptorAllocator _descriptorAllocator;
private UnsafeSlotMap<ResourceRecord> _resources;

View File

@@ -1,11 +1,9 @@
using Ghost.Core;
using Ghost.Core.Utilities;
using Ghost.Graphics.D3D12.Utilities;
using Ghost.Graphics.RHI;
using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.LowLevel.Collections;
using Misaki.HighPerformance.LowLevel.Utilities;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
@@ -204,11 +202,11 @@ internal static unsafe class D3D12ShaderCompiler
using ComPtr<IDxcIncludeHandler> includeHandler = default;
// Create DXC compiler and utils
var pDxcCompiler = (Guid*)Unsafe.AsPointer(in CLSID.CLSID_DxcCompiler);
var pDxcUtils = (Guid*)Unsafe.AsPointer(in CLSID.CLSID_DxcUtils);
var dxccID = CLSID.CLSID_DxcCompiler;
var dxcuID = CLSID.CLSID_DxcUtils;
ThrowIfFailed(DxcCreateInstance(pDxcCompiler, compiler.IID(), compiler.PPV()));
ThrowIfFailed(DxcCreateInstance(pDxcUtils, utils.IID(), utils.PPV()));
ThrowIfFailed(DxcCreateInstance(&dxccID, compiler.IID(), compiler.PPV()));
ThrowIfFailed(DxcCreateInstance(&dxcuID, utils.IID(), utils.PPV()));
//includeHandler.Get()->LoadSource();
utils.Get()->CreateDefaultIncludeHandler(includeHandler.GetAddressOf());
@@ -299,9 +297,9 @@ internal static unsafe class D3D12ShaderCompiler
}
// Create DXC utils to parse reflection data
var pDxcUtils = (Guid*)Unsafe.AsPointer(in CLSID.CLSID_DxcUtils);
var dxcuID = CLSID.CLSID_DxcUtils;
using ComPtr<IDxcUtils> utils = default;
ThrowIfFailed(DxcCreateInstance(pDxcUtils, utils.IID(), utils.PPV()));
ThrowIfFailed(DxcCreateInstance(&dxcuID, utils.IID(), utils.PPV()));
// Create reflection interface from blob
var reflectionBuffer = new DxcBuffer