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

Document how to do D3D12-style command buffer management in Vulkan #15

Open
Tobski opened this issue Jan 8, 2020 · 4 comments
Open
Labels
documentation Improvements or additions to documentation

Comments

@Tobski
Copy link

Tobski commented Jan 8, 2020

There's a particular usage pattern for dynamically recorded command buffers which DX12 applications make use of DX12's ability to free-associate command buffers with command allocators, which is not how things naturally work in Vulkan.

Whilst this might not be the ideal method for managing command buffers in all cases, it works, and is natural for anyone porting D3D12 content.

After discussion in the Vulkan WG, we agreed that the following advice is the right way to achieve the same in Vulkan, with no expected perf implications vs DX12:

  • Allocate command pools with VK_COMMAND_POOL_CREATE_TRANSIENT_BIT
  • Treat VkCommandPool objects the same as ID3D12CommandAllocator objects
    • I.e. they are externally synchronized command allocators
  • Don't pre-allocate command buffers
  • Allocate command buffers when you want to begin recording, then begin them
  • When the command buffer is no longer in use, free the command buffer
    • Ideally along with all others associated with the same pool

It would be useful to turn this porting advice into a section of the Vulkan-Guide, possibly alongside other porting advice.

@Tobski
Copy link
Author

Tobski commented Jan 8, 2020

I would also note that there's interaction between command buffer management and semaphore management here - timeline semaphores kind of round out the whole package if you want to truly emulate the same style of command buffer management developers are used to in D3D12. These pieces can be written separately, but eventually should be part of the same guide section.

@Tobski
Copy link
Author

Tobski commented Jan 10, 2020

One additional thing to mention which I kind of didn't call out explicitly, in the same way that in D3D12 you would need to call ID3D12CommandAllocator::Reset to reclaim memory, you should be calling vkResetCommandPool - ideally once per frame. If we're going to document this properly as command buffer management advice, we should be clear to include that. Not doing this can result in an eventual OOM condition.

See https://docs.microsoft.com/en-us/windows/win32/direct3d12/recording-command-lists-and-bundles for useful info on how d3d12 command lists are used.

@Tobski
Copy link
Author

Tobski commented Jan 10, 2020

One other comment is that this doesn't represent the only way you might use command lists in D3D12 - it seems perfectly possible to use them in the same way as Vulkan. This is specifically addressing a common pattern in D3D12 applications where the command lists are created and submitted on a per-frame basis, but then they are individually reset to use a new command allocator - this indicates the best way to accomplish that.

@marty-johnson59
Copy link
Contributor

Might be worth a whole chapter on moving to Vulkan if you're coming form D3D12?

@marty-johnson59 marty-johnson59 added the documentation Improvements or additions to documentation label Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants