Update rendering and resource management
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.
This commit is contained in:
@@ -130,7 +130,7 @@ internal unsafe class D3D12Renderer : IRenderer
|
||||
case SwapChainPresenter.TargetType.Hwnd:
|
||||
var swapChainFullscreenDesc = new SwapChainFullscreenDescription
|
||||
{
|
||||
Windowed = false,
|
||||
Windowed = true,
|
||||
};
|
||||
|
||||
_graphicsDevice.DXGIFactory.Ptr->CreateSwapChainForHwnd(
|
||||
@@ -150,7 +150,10 @@ internal unsafe class D3D12Renderer : IRenderer
|
||||
throw new InvalidOperationException("Failed to create IDXGISwapChain4 interface.");
|
||||
}
|
||||
|
||||
_swapChainPresenter.SwapChainPanelNative.SetSwapChain((IntPtr)_swapChain.Get());
|
||||
if (_swapChainPresenter.Type == SwapChainPresenter.TargetType.Composition)
|
||||
{
|
||||
_swapChainPresenter.SwapChainPanelNative.SetSwapChain((IntPtr)_swapChain.Get());
|
||||
}
|
||||
_backBufferIndex = _swapChain.Get()->GetCurrentBackBufferIndex();
|
||||
}
|
||||
|
||||
@@ -221,7 +224,7 @@ internal unsafe class D3D12Renderer : IRenderer
|
||||
ref var frameResource = ref _frameResources[i];
|
||||
if (frameResource.backBuffer.Get() is not null)
|
||||
{
|
||||
frameResource.backBuffer.Reset();
|
||||
frameResource.backBuffer.Dispose();
|
||||
_rtvHeap.ReleaseDescriptor(frameResource.backBufferDescriptorIndexes);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,12 +49,14 @@ public unsafe class D3D12Resource : IResource
|
||||
|
||||
fixed (T* ptr = data)
|
||||
{
|
||||
var hr = _nativeResource.Get()->Map(0, &range, (void**)&ptr);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user