Changed the `EditorState` class to use a timeout in the `WaitForGPUReady` method for improved responsiveness. Changed the `nativeDebugging` setting in `launchSettings.json` to `false` for the "Ghost.Editor (Package)" profile. Changed the `D3D12Renderer` class to set the swap chain only for the composition target type and replaced back buffer reset with dispose. Changed the mapping of resources in `D3D12Resource` to use a pointer for improved safety and clarity. Changed the `Mesh` class's upload buffer creation to not use the `true` flag for better memory management. Added a new `Vertex` struct with a `StructLayout` attribute for improved interoperability with unmanaged code. Refactored the `GraphicsPipeline` class to replace `IsGpuReady` with `WaitForGPUReady`, including a timeout parameter. Added a constant buffer to the HLSL source code in `MeshRenderPass` for passing transformation matrices to the vertex shader. Expanded the `UnitTestAppWindow` class to include event handlers for window activation and size changes for better resource management. Updated the XAML for `UnitTestAppWindow` to include a `SwapChainPanel` and corrected the XML declaration for formatting consistency.
76 lines
1.8 KiB
C#
76 lines
1.8 KiB
C#
using Ghost.Core;
|
|
using Ghost.Graphics.Contracts;
|
|
using System.Runtime.CompilerServices;
|
|
using Win32;
|
|
using Win32.Graphics.Direct3D12;
|
|
|
|
namespace Ghost.Graphics.D3D12;
|
|
|
|
public unsafe class D3D12Resource : IResource
|
|
{
|
|
private ComPtr<ID3D12Resource> _nativeResource
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
private string _name = string.Empty;
|
|
|
|
internal ConstPtr<ID3D12Resource> NativeResource => new(_nativeResource.Get());
|
|
|
|
public ulong GPUAddress => _nativeResource.Get()->GetGPUVirtualAddress();
|
|
|
|
public string Name
|
|
{
|
|
get => _name;
|
|
set
|
|
{
|
|
_name = value;
|
|
_nativeResource.Get()->SetName(_name);
|
|
}
|
|
}
|
|
|
|
public bool TempResource
|
|
{
|
|
get;
|
|
}
|
|
|
|
internal D3D12Resource(ComPtr<ID3D12Resource> nativeResource, bool temp)
|
|
{
|
|
_nativeResource = nativeResource;
|
|
TempResource = temp;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public void SetData<T>(Span<T> data)
|
|
where T : unmanaged
|
|
{
|
|
var size = (uint)(data.Length * sizeof(T));
|
|
var range = new Win32.Graphics.Direct3D12.Range(0, size);
|
|
|
|
fixed (T* ptr = data)
|
|
{
|
|
void* mappedPtr;
|
|
var hr = _nativeResource.Get()->Map(0, &range, &mappedPtr);
|
|
if (hr.Failure)
|
|
{
|
|
var message = hr.ToString();
|
|
throw new InvalidOperationException($"Failed to map resource: {message}");
|
|
}
|
|
Unsafe.CopyBlock(mappedPtr, ptr, size);
|
|
_nativeResource.Get()->Unmap(0, &range);
|
|
}
|
|
}
|
|
|
|
internal void DisposeInternal()
|
|
{
|
|
var c = _nativeResource.Reset();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (!TempResource)
|
|
{
|
|
DisposeInternal();
|
|
}
|
|
}
|
|
} |