Commit Graph

51 Commits

Author SHA1 Message Date
Hans-Kristian Arntzen 6335e411bb vkd3d: Rewrite submission logic for wait fences.
D3D12 has some unfortunate rules around CommandQueue::Wait().
It's legal to release the fence early, before the fence actually
completes its wait operation.

The behavior on D3D12 is just to release all waiters.
For out of order signal/wait, we hold off submissions,
so we can implement this implicitly through CPU signal to UINT64_MAX
on fence release. If we have submitted a wait which depends on the
fence, it will complete in finite time, so it still works fine.

We cannot release the semaphores early in Vulkan, so we must hold on
to a private reference of the ID3D12Fence object until we have observed
that the wait is complete.

To make this work, we refactor waits to use the vkd3d_queue wait list.
On other submits, we resolve the wait. This is a small optimization
since we don't have to perform dummy submits that only performs the wait.
At that time, we signal a timeline semaphore and queue up a d3d12_fence_dec_ref().

Since we're also adding this system where normal submissions signal
timelines, handle the submission counters more correctly by deferring
the decrements until we have waited for the submission itself.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-07-18 19:00:25 +02:00
Hans-Kristian Arntzen 233ff38175 vkd3d: Force LINEAR images to be allocated as committed resources.
We have no way of expressing size / alignment requirements to
applications since the API query does not provide us with heap
information. Reuse the fallback path for promoting placed to committed.

Guardians of the Galaxy hits a case where it tries to place 3x
host-visible 3D images in one heap, and they end up overlapping in
memory due to a 16x16x80 3D texture taking up far less space in optimal
tiling compared to linear tiling on AMD.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-07-11 14:59:24 +02:00
Hans-Kristian Arntzen cecb8d6ebc vkd3d: Don't suballocate scratch buffers.
Scratch buffers are 1 MiB blocks which will end
up being suballocated. This was not intended and a fallout from the
earlier change where VA_SIZE was bumped to 2 MiB for Elden Ring.

Introduce a memory allocation flag INTERNAL_SCRATCH which disables
suballocation and VA map insert.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-06-23 14:39:22 +02:00
Hans-Kristian Arntzen 2f6a9e0d55 vkd3d: Do not attempt to clear dedicated memory allocations.
We rely on zerovram behavior in drivers. Opt-in to this path where we
know implementation does what we want (backed up by testing).

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-06-17 11:53:28 +02:00
Hans-Kristian Arntzen 365dd05557 vkd3d: Add breadcrumbs support.
AMD path for this commit.
Idea is that we can automatically instrument markers with command list
information we can make some sense of in vkd3d-proton.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-11 13:07:56 +01:00
Hans-Kristian Arntzen 8a46c21254 vkd3d: Add VKD3D_CONFIG to skip memory allocator clears.
For cases where games spam committed allocations and don't use
NOT_ZEROED. We still rely on zerovram behavior for initial backing which
should be enough in most cases.

Strictly speaking however, we are forced to clear the allocations every
time if application does not use the flag correctly.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-02-24 12:52:05 +01:00
Hans-Kristian Arntzen 76ca492a39 vkd3d: Add some debug logging for when clear passes happen.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-02-24 12:52:05 +01:00
Samuel Pitoiset 870dda927d vkd3d: Use VK_KHR_bind_memory2
Mesa RADV translates these legacy entrypoints to the 2 variants. Using
them directly will cost a bit less CPU cycles.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
2022-01-12 12:06:06 +01:00
Philip Rebohle 3b6a4ab988 vkd3d: Implement ID3D12Device8 and ID3D12Resource2.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-11-19 14:57:51 +01:00
Hans-Kristian Arntzen 385c3dc012 vkd3d: Add bug reference for split fallback types.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-10-07 15:32:54 +02:00
Hans-Kristian Arntzen 26dc9e7da5 vkd3d: Allow CreateHeap to fail in certain fallback situations.
If we deduce that fallback heap allocation is impossible, we will accept
this, and defer allocation to CreatePlacedResource() instead where we make a committed resource.
This breaks aliasing, but in practice, this situation will only arise for render
targets, and it's not like we have a choice in the matter here on NV :\

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-10-07 15:32:54 +02:00
Hans-Kristian Arntzen 7ee8eac818 vkd3d: Add allocation flag for DEDICATED.
When allocating dedicated memory, ignore heap_flag requirements we
deduce from memory info. Any memory type is allowed. This is important
on NV when allocating fallback render targets.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-10-07 15:32:54 +02:00
Hans-Kristian Arntzen cddb98acc6 vkd3d: Consider that we might attempt to free NULL memory.
For deferred heaps, we will accept NULL allocations.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-10-07 15:32:54 +02:00
Hans-Kristian Arntzen 4075809a91 vkd3d: Make error message more precise when failing to allocate memory.
There are situations where we cannot fallback to system memory, so don't
log that we're going to do so.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-10-07 15:32:54 +02:00
Hans-Kristian Arntzen 9065f312d5 vkd3d: Refactor out validation of CUSTOM heap types.
Don't attempt to enter memory allocation when we can invalidate a heap
allocation up front. Avoids some dumb edge cases later.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-10-07 15:32:54 +02:00
Hans-Kristian Arntzen 9415191111 vkd3d: Add LOG_MEMORY_BUDGET logging for non-budget as well.
Useful to be able to debug which allocations happen.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-10-07 15:32:54 +02:00
Hans-Kristian Arntzen 0c2ddb89cd vkd3d: Add CONFIG for forced CACHED memory.
Very useful for capturing. Speeds up a ton.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-09-27 14:48:26 +02:00
Hans-Kristian Arntzen a8f623e60d vkd3d: Negate upload_hvv config.
Enable resizable BAR style allocations by default, and add option to
disable it.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-09-16 16:10:57 +02:00
Hans-Kristian Arntzen 12066a2b67 vkd3d: Add debug config to log resizable BAR allocations.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-09-16 16:10:57 +02:00
Hans-Kristian Arntzen 710fa98918 vkd3d: Setup resizable bar budget.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-09-16 16:10:57 +02:00
Hans-Kristian Arntzen abdaeb136d vkd3d: Add a memory budget per memory type.
For resizable BAR, we don't want to endlessly promote UPLOAD heaps to
BAR since VRAM is precious. The aim is to set a fixed budget where we
can keep allocating until full, at which point we fall back to plain HOST.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-09-16 16:10:57 +02:00
Hans-Kristian Arntzen e0451bb541 vkd3d: Handle fallbacks properly in suballocator.
With BAR budgets, what will happen is that
- Small allocation is requested
- A new chunk is requested
- try_suballocate_memory will end up calling allocate_memory, which
  allocates a fallback memory type
- Subsequent small allocators will always end up allocating a new
  fallback memory block, never reusing existing blocks.
- System memory is rapidly exhausted once apps start hitting against
  budget.

The fix is to add flags which explicitly do not attempt to fallback
allocate. This makes it possible to handle fallbacks at the appropriate
level in try_suballocate_memory instead.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-09-16 16:10:57 +02:00
Hans-Kristian Arntzen 426cdc9218 vkd3d: Destroy GLOBAL_BUFFER for some early error out paths.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-09-16 16:10:57 +02:00
Hans-Kristian Arntzen 69d4f55219 vkd3d: Refactor VkDeviceMemory allocation to keep track of type/size.
We will need to consider some form of budgeting, so make sure that all
allocation and freeing is done in a central place.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-09-16 16:10:57 +02:00
Hans-Kristian Arntzen 41295eff6c vkd3d: Consider CPU availibility when selecting memory types.
Need to consider that based on host visibility requirements, we need to
select either LINEAR or OPTIMAL image types, and those tiling modes can
have different memory requirements.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-09-16 15:35:57 +02:00
Joshua Ashton 1b957a1f74 vkd3d: Add config to use host-visible vram for UPLOAD heap
Adds the "upload_hvv" config flag, which will make D3D12_HEAP_TYPE_UPLOAD attempt to use host-visible VRAM for allocations.

This takes advantage of large or resizable BAR if available.

I see a perf delta of 83-84 -> 92-94 (~12%) when using this in Horizon Zero Dawn.

Signed-off-by: Joshua Ashton <joshua@froggi.es>
2021-08-23 13:24:43 +02:00
Hans-Kristian Arntzen 05e31bfba9 vkd3d: Ensure we do not fallback device allocations to BAR.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-08-23 13:24:43 +02:00
Hans-Kristian Arntzen abe0995e88 vkd3d: Use correct allocation size for memory block.
We cannot use the memory requirement output, since we will zero-clear
memory with a size that might be larger than the VkBuffer size.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-06-10 14:16:01 +02:00
Hans-Kristian Arntzen a256a9266e vkd3d: Rewrite descriptor QA.
Adds support for GPU-assisted validation of descriptor usage in the
CBV_SRV_UAV heap.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-05-26 17:26:01 +02:00
Joshua Ashton 258173a0a7 vkd3d: Fix return value when WRITE_WATCH is forbidden
Signed-off-by: Joshua Ashton <joshua@froggi.es>
2021-03-18 16:10:05 +01:00
Joshua Ashton aa12817ccf vkd3d: Implement D3D12_HEAP_TYPE_WRITE_WATCH
Needed for D3D12 APITrace

Closes: #373
Signed-off-by: Joshua Ashton <joshua@froggi.es>
2021-03-18 14:41:46 +01:00
Philip Rebohle 0e4ef88d18 vkd3d: Don't broadcast semaphore waits when zeroing memory.
Instead, let queues wait on demand.

Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-03-15 12:52:00 +01:00
Philip Rebohle 1e3c91579e vkd3d: Create one vkd3d queue per Vulkan device queue.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-03-15 12:52:00 +01:00
Hans-Kristian Arntzen 3353ed14de vkd3d: Implement RTAS object creation.
When building acceleration structures, we need to have an
VkAccelerationStructureKHR object, but the D3D12 API just uses a plain
VA = ID3D12Resource::GetGPUVA() + offset.

For this to work, we need to resolve the VA back to VkBuffer + offset.
The only VkBuffer we can lookup is the original backing memory
allocation in the VA map, and that allocation itself must own a view
map, since we cannot tie the VA to any specific ID3D12Resource.

Since creating an RTAS is not the common path, we allocate the view map
on-demand with CAS.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2021-02-25 16:14:16 +01:00
Philip Rebohle 1d7e424c44 vkd3d: Mask certain heap flags when suballocating memory.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-19 20:18:24 +01:00
Philip Rebohle be080edc7f vkd3d: Remove vkd3d_allocate_resource_memory.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-19 19:51:44 +01:00
Philip Rebohle a1e5b78bc4 vkd3d: Suballocate committed images if possible and if supported by the driver.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-19 19:51:44 +01:00
Philip Rebohle a1ffea1800 vkd3d: Fix integer underflow when checking for suitable free ranges.
The difference between a range's offset and the aligned
offset may be greater than the size of that range.

Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-19 18:11:36 +01:00
Philip Rebohle 6a34d3d204 vkd3d: Remove _2 suffix from memory allocation functions.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-18 14:17:22 +01:00
Philip Rebohle 6f8bb2a4c0 vkd3d: Use vkd3d_allocate_device_memory_2 for sparse metadata.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-18 14:17:22 +01:00
Philip Rebohle 12f0c11c7f vkd3d: Simplify vkd3d_allocate_image_memory helper.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-18 14:17:22 +01:00
Philip Rebohle ab2c190da5 vkd3d: Simplify vkd3d_allocate_buffer_memory helper.
This is still useful as a low-level memory allocation function when
we don't want to bother with buffer offsets or D3D12 validation.

Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-18 14:17:22 +01:00
Philip Rebohle 6fc8b67576 vkd3d: Fix incorrect chunk assignment for chunk allocations.
Our clear code assume that this is NULL for allocations owned
by a chunk, so we should actually do it that way. Fixes some
issues where we do not wait for clears to complete if a chunk
gets destroyed.

Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-17 16:38:47 +01:00
Philip Rebohle a39bab95a1 vkd3d: Clear suballocated memory to zero.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-16 16:06:26 +01:00
Philip Rebohle 668a4e1f2c vkd3d: Do not suballocate small image-only heaps.
We have no way to manually reset these.

Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-16 16:06:26 +01:00
Philip Rebohle 4d68130be7 vkd3d: Add functionality to clear newly allocated memory.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-16 16:06:26 +01:00
Philip Rebohle 6e1867b001 vkd3d: Add some more debug output to memory allocation functions.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-15 17:04:52 +01:00
Philip Rebohle 5e54c1fc5d vkd3d: Register allocation cookie for descriptor debugging.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-15 17:04:52 +01:00
Philip Rebohle 8f6e94dc30 vkd3d: Suballocate small allocations from larger chunks.
This is necessary to keep the amount of allocated memory manageable
in games that allocate a lot of small heaps or committed resources.

Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-15 16:38:16 +01:00
Philip Rebohle d65363b6b6 vkd3d: Add VA map to memory allocator.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2021-02-15 15:19:11 +01:00