microsoft / DirectXTK12

The DirectX Tool Kit (aka DirectXTK12) is a collection of helper classes for writing DirectX 12 code in C++
https://walbourn.github.io/directx-tool-kit-for-directx-12/
MIT License
1.47k stars 393 forks source link

Consider allowing a computer or copy queue to be provided to ResourceUploadBatch #70

Closed john-h-k closed 4 years ago

john-h-k commented 4 years ago

Currently providing a ID3D12CommandQueue* to ResourceUploadBatch::End generates an error if the queue is not of type D3D12_COMMAND_LIST_TYPE_DIRECT;

    void Begin()
    {
        if (mInBeginEndBlock)
            throw std::exception("Can't Begin: already in a Begin-End block.");

        ThrowIfFailed(mDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_GRAPHICS_PPV_ARGS(mCmdAlloc.ReleaseAndGetAddressOf())));

        SetDebugObjectName(mCmdAlloc.Get(), L"ResourceUploadBatch");

        ThrowIfFailed(mDevice->CreateCommandList(1, D3D12_COMMAND_LIST_TYPE_DIRECT, mCmdAlloc.Get(), nullptr, IID_GRAPHICS_PPV_ARGS(mList.ReleaseAndGetAddressOf())));

        SetDebugObjectName(mList.Get(), L"ResourceUploadBatch");

        mInBeginEndBlock = true;
    }

This can just be changed to

    void Begin(D3D12_COMMAND_LIST_TYPE commandType = D3D12_COMMAND_LIST_TYPE_DIRECT)
    {
        if (mInBeginEndBlock)
            throw std::exception("Can't Begin: already in a Begin-End block.");

        ThrowIfFailed(mDevice->CreateCommandAllocator(commandType, IID_GRAPHICS_PPV_ARGS(mCmdAlloc.ReleaseAndGetAddressOf())));

        SetDebugObjectName(mCmdAlloc.Get(), L"ResourceUploadBatch");

        ThrowIfFailed(mDevice->CreateCommandList(1, commandType, mCmdAlloc.Get(), nullptr, IID_GRAPHICS_PPV_ARGS(mList.ReleaseAndGetAddressOf())));

        SetDebugObjectName(mList.Get(), L"ResourceUploadBatch");

        mInBeginEndBlock = true;
    }

and this is now all fixed. Would be useful

walbourn commented 4 years ago

That's a great suggestion. That said, I think only D3D12_COMMAND_LIST_TYPE_DIRECT, D3D12_COMMAND_LIST_TYPE_BUNDLE, or D3D12_COMMAND_LIST_TYPE_COPY would actually work. The class issues copy commands on the command-list, so D3D12_COMMAND_LIST_TYPE_COMPUTE wouldn't work.

walbourn commented 4 years ago

The ResourceUploadBatch can also not use a D3D12_COMMAND_LIST_TYPE_COPY command-list when generating mipmaps.

walbourn commented 4 years ago

And there are a few challenges with the implicit resource barrier.

john-h-k commented 4 years ago

The ResourceUploadBatch can also not use a D3D12_COMMAND_LIST_TYPE_COPY command-list when generating mipmaps.

I guess the easiest way to go around this is check if mGenMipsResources isn't null in End, and if it isn't, then throw an exception?

walbourn commented 4 years ago

Here's a PR for the library:

https://github.com/microsoft/DirectXTK12/pull/71

Here's a PR for the test suite:

https://github.com/walbourn/directxtk12test/pull/17

Please take a look at these instructions to try it out yourself as I can use some help in testing this on more systems.