1315 Commits

Author SHA1 Message Date
Giovanni Mascellani
5b2d62e59a vkd3d: Explicitly call the appropriate waiting function in the fence worker.
Avoid using an indirect call that makes the code less clear for no
real advantage.
2025-01-21 14:09:29 +01:00
Giovanni Mascellani
22d0841412 vkd3d: Support signalling a fence once all outstanding work is submitted to Vulkan.
When the client acquires the Vulkan queue it has to ensure that
it is not submitting work before other work it depends on already
submitted through the Direct3D 12 API but currently in the internal
vkd3d queue. Currently we suggest to enqueue signalling a fence and
than wait for it before acquiring the Vulkan queue, which is
correct but excessive: it will wait not just for the work currently
in the queue to be submitted, but for it to be executed too,
introducing useless dependencies.

By adding a way to enqueue signalling a fence on the CPU side we
allow the client to wait for the currently outstanding work to
be submitted to Vulkan, but nothing more.
2025-01-21 14:02:22 +01:00
Giovanni Mascellani
bdb8291f6c vkd3d: Release queued fences when stopping the fence worker. 2025-01-21 13:45:33 +01:00
Giovanni Mascellani
ed7a846e2e vkd3d: Only call d3d12_fence_garbage_collect_vk_semaphores_locked() when using binary semaphores.
The function is specific to binary semaphores, and will unconditionally
access the "u.binary" field of struct vkd3d_signaled_semaphore.
2025-01-21 13:45:27 +01:00
Conor McCarthy
10edcec030 vkd3d: Do not require the ALLOW_DEPTH_STENCIL flag for depth/stencil formats in GetCopyableFootprints(). 2025-01-20 14:37:13 +01:00
Conor McCarthy
e99906f05d vkd3d: Return correctly aligned depth/stencil sizes from GetCopyableFootprints(). 2025-01-20 13:59:46 +01:00
Conor McCarthy
1a4dedbc8d vkd3d: Return the correct depth/stencil plane format from GetCopyableFootprints(). 2025-01-20 13:45:16 +01:00
Giovanni Mascellani
17adde7f73 vkd3d: Describe DXGI_UNKNOWN as having one plane.
We're explicitly replacing zero with one in the only place where the
plane count being zero or one makes a difference. It also make sense:
UNKNOWN is used for buffers, which for all intents and purposes have one
plane.
2025-01-20 13:43:36 +01:00
Giovanni Mascellani
c7e173a1ff vkd3d: Log the requested feature levels for D3D12_FEATURE_FEATURE_LEVELS. 2025-01-13 16:41:53 +01:00
Francisco Casas
7b23cd4d3c vkd3d-shader: Avoid passing NULL to qsort(). (ubsan)
Otherwise ubsan reports runtime errors such as:

    libs/vkd3d-shader/ir.c:4731:5: runtime error: null pointer passed as argument 1, which is declared to never be null
2025-01-10 19:51:55 +01:00
Henri Verbeet
bbeecfc835 vkd3d: Drop smaller pools in d3d12_command_allocator_reset_descriptor_pool_array().
Effectively consolidating them.
2024-12-09 16:10:22 +01:00
Giovanni Mascellani
239c88e8d3 vkd3d: Do not use more than a few million descriptors in Vulkan heap set layouts.
Currently, when using Vulkan heaps, we create descriptor set
layouts with as many descriptors as allowed by the Vulkan
implementation limits. For some implementations this can mean
hundreds of millions of descriptors or more, which is wasteful,
given that even on the best resource binding tier Direct3D 12
applications should not expect to have more than a million usable
descriptors.

Recently this began being a problem, because since Mesa 24.2.7
the Intel driver advertises more than 200 million descriptors,
but pipeline compilation takes linear RAM in the number of
descriptors declared in the pipeline layout. This means that
compiling even a simple shader requires 10-20 GB of RAM.

In order to avoid using too much memory, with this commit we clamp
the number of descriptors declared in the set layouts to how many
we actually need to guarantee tier 3 resource binding support.
2024-12-05 21:00:03 +01:00
Conor McCarthy
a43f6a6600 vkd3d: Create descriptor pools of geometrically increasing size.
Creating a pool of 16k descriptors is wasteful if an allocator only uses
a fraction of them, so start at 1k and double for each subsequent
allocation until 16k is reached.
2024-12-05 20:54:45 +01:00
Conor McCarthy
e729ceeb1a vkd3d: Create separate descriptor pools for each vkd3d descriptor type.
Now that our Vulkan descriptor sets contain only a single vkd3d
descriptor type, we're able to create descriptor pools containing only a
single vkd3d descriptor type as well. This avoids wasting unallocated
descriptors of one type when we run out of descriptors of another type.
2024-12-05 20:54:45 +01:00
Henri Verbeet
a97c7c1fda vkd3d: Introduce d3d12_descriptor_set_layout_init(). 2024-12-05 20:54:45 +01:00
Conor McCarthy
19c6df1adb vkd3d: Introduce vkd3d_vk_descriptor_pool_array_destroy_pools(). 2024-12-05 20:54:45 +01:00
Conor McCarthy
8dc9fe725a vkd3d: Introduce vkd3d_vk_descriptor_pool_array_pop(). 2024-12-05 20:54:45 +01:00
Conor McCarthy
9d46a1863b vkd3d: Introduce vkd3d_vk_descriptor_pool_array_push(). 2024-12-05 20:54:45 +01:00
Conor McCarthy
7c0ce25bb7 vkd3d: Introduce vkd3d_vk_descriptor_pool_array_push_array(). 2024-12-05 20:54:45 +01:00
Conor McCarthy
3c620e88a0 vkd3d: Introduce struct vkd3d_vk_descriptor_pool_array. 2024-12-05 20:54:45 +01:00
Conor McCarthy
4a94bfc2f6 vkd3d: Store only a single vkd3d descriptor type in each Vulkan descriptor set.
We currently create statically sized descriptor pools, shared among
different descriptor types. Once we're unable to allocate a descriptor
set from a pool, we create a new pool. The unfortunate but predictable
consequence is that when we run out of descriptors of one type, we waste
any unallocated descriptors of the other types.

Dynamically adjusting the pool sizes could mitigate the issue, but it
seems non-trivial to handle all the edge cases, particularly in
situations where the descriptor count ratios change significantly
between frames. Instead, by storing only a single vkd3d descriptor type
in each Vulkan descriptor set we're able to create separate descriptor
pools for each vkd3d descriptor type, which also avoids the issue.

The main drawback of using separate descriptor sets for each descriptor
type is that we can no longer pack all bounded descriptor ranges into a
single descriptor set, potentially leaving fewer descriptor sets
available for unbounded ranges. That seems worth it, but we may end up
having to switch to a more complicated strategy if this ends up being a
problem on Vulkan implementations with a very limited number of
available descriptor sets.
2024-12-05 20:54:45 +01:00
Henri Verbeet
5c00766eff Release 1.14. 2024-11-21 12:35:55 +01:00
Giovanni Mascellani
72394d9ae3 vkd3d: Use WARN rather than ERR in vkd3d_instance_init().
ERR is used to indicate internal inconsistencies in vkd3d. Here that's
not the case, we simply have to forward the error condition to the
caller.

This fixes failures on the CI with llvmpipe, because the build we use is
compiled without support for VK_KHR_surface and related extensions.
2024-11-14 14:09:04 +01:00
Conor McCarthy
76fd1388d8 vkd3d: Check the IASetVertexBuffers() view count against the device limits.
For example, current MoltenVK only supports 31 vertex buffers.
2024-11-06 21:43:32 +01:00
Elizabeth Figura
a595b96f62 vkd3d: Initialize vk_extensions in vk_init_device_caps().
Without LTO, gcc doesn't know that hresult_from_vk_result() will always return a
failure HRESULT for a failure VkResult, and so thinks that we might exit from
vkd3d_check_device_extensions() with a success HRESULT but without initializing
vk_extensions.
2024-10-28 18:01:06 +01:00
Giovanni Mascellani
a1f712d100 vkd3d: Incorporate mutable descriptors in the push descriptor disabling logic.
The computation is also written in the code now instead of in
the comments.
2024-10-23 16:12:50 +02:00
Giovanni Mascellani
bc2b137df9 vkd3d: Only put the mutable descriptor set once in the pipeline layout.
Currently the mutable descriptor set is repeated many times in the
pipeline layout in order to cover the indices for all the
descriptor types that would be present if mutable descriptors were
not used. This is useless and wasteful, but was necessary before
the descriptor sets backing the SRV-UAV-CBV heap were moved at the
end of the allocation table because descriptor set indices are
currently a compile-time constant in many places.

Now this is not needed any more and we can just avoid putting
many copies of the mutable descriptor set in the pipeline layout,
making it easier to meet Vulkan implementation limits.
2024-10-23 16:12:06 +02:00
Giovanni Mascellani
96b324c156 vkd3d: Move descriptor sets backing the SRV-UAV-CBV heap at the end.
So that when mutable descriptors are in use we can avoid putting
the other descriptor sets backing the SRV-UAV-CBV descriptor heap
in the pipeline layout altogether.
2024-10-23 16:07:54 +02:00
Giovanni Mascellani
8d030718ae vkd3d: Introduce an enumerant for the mutable descriptor set.
So we avoid hardcoding that it is number zero. There are two
goals here: first making the code easier to understand and
second allow reshuffling the descriptor set allocation in a
later commit.
2024-10-23 16:07:36 +02:00
Conor McCarthy
4889c71857 vkd3d: Zero the pipeline state UAV counter view array when the state is invalidated. (Valgrind)
Otherwise a comparison with uninitialised data occurs in
d3d12_command_list_update_descriptor_table() if virtual heaps are used.
2024-10-22 20:42:06 +02:00
Giovanni Mascellani
ae772d40cf vkd3d: Disable push descriptors when that's helpful to stay within 8 descriptor sets. 2024-10-21 18:22:15 +02:00
Giovanni Mascellani
3bf114f3c3 vkd3d/device: Trace which descriptor heap implementation is being used.
The descriptor heap implementation is a rather central behavior element
in vkd3d, so it's useful to have all the relevant information logged
in a single place.
2024-10-21 18:22:15 +02:00
Giovanni Mascellani
a3b8aaf679 vkd3d: Allow overriding the device capabilities. 2024-10-21 18:06:06 +02:00
Henri Verbeet
8943999bd2 vkd3d: Slightly simplify the SRV/UAV logic in vk_write_descriptor_set_from_d3d12_desc(). 2024-10-17 17:28:52 +02:00
Conor McCarthy
bfaab9700d vkd3d: Lay out virtual descriptor heap buffer and image bindings consecutively instead of interleaving them.
Slightly simplifies descriptor write addressing, and makes layouts
essentially the same as array layouts, differing only in the binding
details, and therefore easier to understand. This also simplifies the
addition of storage buffer bindings, which can all be added onto the end.
2024-10-17 17:28:46 +02:00
Giovanni Mascellani
0b8a53d75d vkd3d: Create Vulkan bindings in d3d12_root_signature_append_vk_binding(). 2024-10-17 17:23:04 +02:00
Conor McCarthy
74da9ed6fe vkd3d: Create a separate Vulkan descriptor binding array for each descriptor set.
Allows descriptor set layouts to be created after all bindings are
mapped. This is less complex and fragile than the current scheme, and in
a future patch it will support separating descriptor types into different
sets. Descriptors on virtual heaps are currently allocated from pools
which contain an equal number of each descriptor type used by vkd3d, and
this can waste a significant amount of device memory.
2024-10-17 17:23:04 +02:00
Giovanni Mascellani
b5c56a50b5 vkd3d: Use vk_binding_array_add_binding() in d3d12_root_signature_init_root_descriptors(). 2024-10-17 17:23:04 +02:00
Giovanni Mascellani
3aec841a9f vkd3d: Use vk_binding_array_add_binding() in d3d12_root_signature_init_static_samplers(). 2024-10-17 17:23:04 +02:00
Giovanni Mascellani
416ce575f6 vkd3d: Introduce a helper function to add bindings to struct vk_binding_array. 2024-10-17 17:23:04 +02:00
Conor McCarthy
eca344ff56 vkd3d: Introduce a separate structure for storing Vulkan descriptor binding arrays. 2024-10-17 17:23:04 +02:00
Conor McCarthy
3f98ca53ca vkd3d: Access the current range via the declared pointer in d3d12_root_signature_init_root_descriptor_tables(). 2024-10-17 17:23:04 +02:00
Conor McCarthy
91475c684f vkd3d: Clear the output pointer on failure in vkd3d_create_versioned_root_signature_deserializer(). 2024-09-24 13:34:40 +02:00
Conor McCarthy
945e8a9024 vkd3d: Sort bounded descriptor ranges after unbounded ones of equal offset.
Enables the bounded range to be mapped to the unbounded one, instead of
being mapped to a separate binding which will be populated from the same
d3d12 descriptors as the unbounded one.
2024-09-23 15:45:26 +02:00
Andrey Gusev
2ac7f650a1 vkd3d: Recognise VK_QUEUE_VIDEO_ENCODE_BIT_KHR in debug_vk_queue_flags(). 2024-09-20 17:21:44 +02:00
Anna (navi) Figueiredo Gomes
127ae6cf12 vkd3d: Implement d3d12_command_list_OMSetDepthBounds().
Based on the design document, "The runtime will not clamp or validate
the input, but implementations may clamp to the range [0,1] if necessary.",
so we test for the EXT_depth_range_unrestricted extension, and only clamp if
it's not available (thus, necessary to do so).

NaNs are converted to zero as per "NaNs must be treated as 0, but the runtime
will convert NaNs to 0 on behalf of the implementation.", and a default bounds
are set to 0.0 and 1.0.
2024-09-11 14:53:33 +02:00
Giovanni Mascellani
d71966c77e vkd3d: Do not keep track of descriptor heaps when using virtual heaps.
Descriptors only need flushing when using Vulkan heaps, so let's avoid
uselessly scanning an array and taking and releasing a mutex if we're not.
2024-09-10 21:47:38 +02:00
Giovanni Mascellani
05a5bd620d vkd3d: Directly call the function to update descriptors.
For better code clarity.
2024-09-10 21:46:46 +02:00
Anna (navi) Figueiredo Gomes
5ebbba6fff vkd3d/state: Replace ERR with WARN in vkd3d_validate_descriptor_set_count(). 2024-09-10 21:42:47 +02:00
Henri Verbeet
0e72aba0bc Release 1.13. 2024-08-29 12:08:46 +02:00