Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split D3D12MA support into ComputeSharp.D3D12MemoryAllocator #539

Merged
merged 17 commits into from
Jul 6, 2023

Conversation

Sergio0694
Copy link
Owner

Description

This PR splits off the D3D12MA support in ComputeSharp (which uses TerraFX.Interop.D3D12MemoryAllocator), into a new ComputeSharp.D3D12MemoryAllocator package. It also adds a new API to allow plugging in the new allocator into ComputeSharp. At the same time, it also adds the ability for developers to implement their own custom allocators.

API breakdown

ComputeSharp:

namespace ComputeSharp.Interop;

public static class AllocationServices
{
    public static void ConfigureAllocatorFactory(ICustomQueryInterface allocatorFactory);
}

ComputeSharp.D3D12MemoryAllocator:

namespace ComputeSharp.D3D12MemoryAllocator;

public sealed class D3D12MemoryAllocatorFactory : ICustomQueryInterface
{
    public D3D12MemoryAllocatorFactory();

    ~D3D12MemoryAllocatorFactory();

    CustomQueryInterfaceResult ICustomQueryInterface.GetInterface(ref Guid iid, out IntPtr ppv);
}

COM API breakdown

This refactoring introduces the following COM interfaces, which developers can also implement manually:

[uuid(CC1E74A7-786D-40F4-8AE2-F8B7A255587E)]
interface ID3D12MemoryAllocatorFactory : IUnknown
{
    HRESULT CreateAllocator(
        [in] const ID3D12Device* device,
        [in] const IDXGIAdapter* adapter,
        [out] ID3D12MemoryAllocator allocator);
};

[uuid(2D5E55D2-9244-431F-868E-0D90AAB6E575)]
interface ID3D12MemoryAllocator : IUnknown
{
    HRESULT AllocateResource(
        [in] const D3D12_RESOURCE_DESC* resourceDescription,
        const D3D12_HEAP_TYPE heapType,
        const D3D12_RESOURCE_STATES resourceState,
        const BOOL clearAllocation,
        [out] ID3D12Allocation** allocation);
};

[uuid(D42D5782-2DE7-4539-A817-482E3AA01E2E)]
interface ID3D12Allocation : IUnknown
{
    HRESULT GetD3D12Resource([out] ID3D12Resource** resource);
};

@Sergio0694 Sergio0694 added optimization 🚀 Performance improvement to existing APIs refactoring 🧹 Code style and architecture improvements feature 🎉 A brand new feature for ComputeSharp labels Jul 1, 2023
@Sergio0694 Sergio0694 force-pushed the dev/d3d12memoryallocator branch from 9d029ea to 91cffbe Compare July 1, 2023 20:08
@Sergio0694 Sergio0694 merged commit 285aeb4 into main Jul 6, 2023
@Sergio0694 Sergio0694 deleted the dev/d3d12memoryallocator branch July 6, 2023 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🎉 A brand new feature for ComputeSharp optimization 🚀 Performance improvement to existing APIs refactoring 🧹 Code style and architecture improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant