Commit Graph

167 Commits

Author SHA1 Message Date
Philip Rebohle 7184b75f8f
[d3d11] Use GetSubresourceLayout for image maps on the immediate context 2021-05-30 19:42:44 +02:00
Philip Rebohle e87aa08fd2
[d3d11] Implement basic video processor blitting 2021-05-30 19:42:43 +02:00
Philip Rebohle 969ac59667
[d3d11] Add ID3D11VideoContext stub 2021-05-30 19:42:43 +02:00
Philip Rebohle 86542248df
[dxvk] Support multi-plane formats in copyBufferToImage 2021-05-30 19:42:43 +02:00
Joshua Ashton 742b52bbb5 [d3d11] Fix device child refs properly 2021-01-15 23:47:48 +01:00
Philip Rebohle a9b6421f60
[d3d11] Support signaling event in Flush1 2020-03-19 23:38:28 +01:00
Philip Rebohle ba213c1fa0 [dxvk] Factor out waiting for resource to become idle
And use the new generic spin function to reduce syscall spam.
2020-03-15 03:43:04 +01:00
Philip Rebohle a57dc75247
[d3d11] Implicitly begin scoped queries in End if necessary
Matches (undocumented) D3D11 behaviour. Warriors Orochi 4 runs into
this because it does not begin some of its timestamp disjoint queries
before ending them and retrieving data.
2020-01-22 04:17:13 +01:00
Joshua Ashton 7e3142b2ed [d3d11] Hook up platform-specific clock
See 89dfa2bc22
2019-11-26 01:52:58 +01:00
Philip Rebohle c24dad75dc
[d3d11] Remove allowMapFlagNoWait option 2019-11-15 11:09:11 +01:00
Philip Rebohle a6483e02fe
[d3d11] Submit stalling event queries before flushing
Otherwise, instead of preventing syncs, this would actually
have the opposite effect.
2019-11-14 22:57:30 +01:00
Philip Rebohle d96c22be05
[d3d11] Do not synchronize with CS thread in GetData
Instead, use a counter to determine whether there are any
pending operation for the query on the CS thread.
2019-11-02 17:53:17 +01:00
Philip Rebohle 0924bb469c
[d3d11] Move query state tracking to immediate context implementation 2019-11-02 17:53:17 +01:00
Philip Rebohle be5dc234c1
[d3d11] Move common Begin/End implementation to immediate context 2019-11-02 13:48:03 +01:00
Philip Rebohle 41f04ffb61
[d3d11] Fix incorrect AddRef return value 2019-10-25 21:36:21 +02:00
Philip Rebohle 1282c2b99e
[d3d11] Fix immediate context reference counting
Fixes various wine test failures.
2019-10-14 01:56:34 +02:00
Philip Rebohle bd58f1a913
[d3d11] Don't sync CS thread if resource to map is already in use
SynchronizeCsThread can only update the in-use state from available
to in-use, so doing this on a resource that is already in-use is not
necessary. May improve performance in combination with DO_NOT_WAIT.
2019-10-14 00:14:00 +02:00
Philip Rebohle e9fcf64a8c
[dxvk] Only wait for writes when mapping with D3D11_MAP_READ 2019-09-20 01:44:02 +02:00
Philip Rebohle e764f05a1a
[d3d11] Allow pMappedResource to be null when mapping images
This is required to implement mapping default textures correctly.
2019-09-17 23:39:06 +02:00
Philip Rebohle f9d9307a28
[d3d11] Implement ID3D11DeviceContext4 2019-09-16 13:41:31 +02:00
Philip Rebohle 0599a82dee
[d3d11] Implement ID3D11DeviceContext3 2019-09-16 13:41:31 +02:00
Philip Rebohle 6b2f4f93cc [d3d11] Fix incorrect tracking of mapped image subresources
When returnig DXGI_ERROR_WAS_STILL_DRAWING, we should not mark
the subresource as mapped, and instead ignore subsequent calls
to Unmap.
2019-08-03 19:11:19 +02:00
Philip Rebohle 140a2c1017 Revert "[d3d11] Return error when mapping an already mapped image"
This reverts commit 1cc531eaf8.

Even though an FFXIV apitrace clearly indicates that mapping an
already mapped subresource returns E_OUTOFMEMORY in that game,
this doesn't always seem to be correct behaviour.

Fixes #1148, #1149.
2019-08-03 19:08:22 +02:00
Philip Rebohle b6c395c013
[dxvk] Don't track command count in CS chunks
We weren't using this at all, and it's not necessary
to check whether the chunk is empty either.
2019-07-17 12:52:25 +02:00
Philip Rebohle ad8fdcac07
[dxvk] Don't mark queries as stalling if DONOTFLUSH is set 2019-07-16 01:19:02 +02:00
Philip Rebohle 1cc531eaf8
[d3d11] Return error when mapping an already mapped image
Final Fantasy XIV does this. Should avoid some unnecessary work.
2019-07-05 10:25:06 +02:00
Philip Rebohle 2f64f5b4e7
[dxvk] Check whether CS thread is busy before synchronizing with it
Reduces unnecessary locking overhead, which may be relevant if this
function gets called frequently by GetData or WaitForResource.
2019-07-04 21:37:17 +02:00
Philip Rebohle 684355dfca
[d3d11] Fix GetData parameter validation
We're supposed to return an error if a null pointer is
passed along with a non-zero DataSize. Fixes more wine
test failures.
2019-06-16 19:24:44 +02:00
Philip Rebohle e4e82007b1 [d3d11] Fix inconsistencies in Map/Unmap on immediate/deferred contexts
Should save a few CPU cycles, and also fixes incorrect behaviour when an
application passes null pointers to Map on a deferred context.
2019-06-03 15:31:13 +02:00
Philip Rebohle 754cf6da30
[d3d11] Validate subresource index in MapImage
Fixes crashes when passing an invalid subresource index.
2019-05-20 19:27:27 +02:00
Philip Rebohle 3168626f4b
[d3d11] Support mapping multiple image subresources at the same time
Fixes #1066.
2019-05-20 19:27:11 +02:00
Philip Rebohle e1610f81dc
Revert "[d3d11] Use STDMETHODCALLTYPE for private virtual method"
For some reason, this produces broken binaries for some Gentoo
users. Fixes #1067.

This reverts commit e5fa55cbb5.
2019-05-19 13:22:04 +02:00
Philip Rebohle 8e9e7963a2
[d3d11] Update mapped buffers of staging textures immediately
Improves performance in Lords of the Fallen and The Surge.
Closes #1049.

Co-authored-by: Robin <robin.kertels@outlook.com>
2019-05-17 12:44:36 +02:00
Philip Rebohle e5fa55cbb5
[d3d11] Use STDMETHODCALLTYPE for private virtual method
Improves code generation on some compilers.
2019-05-15 22:01:19 +02:00
Philip Rebohle a54548dae9
[d3d11] Flush more aggressively when CPU bound
Submitting GPU work early is especially important if there is
a CPU<>GPU synchronization point somewhere.
2019-05-09 18:04:36 +02:00
Philip Rebohle 45be1dfb53
[d3d11] Flush more aggressively on stalling Event queries
Increases GPU utilization in Quake Champions.
2019-05-09 18:04:36 +02:00
Philip Rebohle af45f810b2
[dxvk] Change flushing behaviour of immediate context methods
Should fix some inappropriate flushing, while flushing more
aggressively on render target changes.

We still keep the flush on UpdateSubresource since some games
use it to update large quantities of data.
2019-05-09 18:04:36 +02:00
Philip Rebohle f733d082f4
[d3d11] Implement D3D11DeviceContext::SwapDeviceContextState 2019-05-04 15:57:57 +02:00
Philip Rebohle e6eef1d1ec
[d3d11] Minor Map/Unmap optimizations
Avoid unnecessary LockContext call when unmapping a buffer.
This may actually improve performance if the context has
multithreaded protection enabled (e.g. D3D10).
2019-05-01 03:01:36 +02:00
Philip Rebohle 97d77fa508
[d3d11] Implement depth-stencil mapping on the immediate context 2019-03-26 18:04:56 +01:00
Philip Rebohle 8c3900c533
[d3d11] Use new GPU events for D3D11 Event queries 2019-03-14 21:16:41 +01:00
Philip Rebohle e56710e64f
[d3d11] Add option to disable write-after-write barriers 2019-02-07 19:39:05 +01:00
Philip Rebohle 8d493d9445
[d3d11] Minor map optimization on immediate contexts
We should make the fast path as fast as possible.
2019-02-04 10:24:30 +01:00
Philip Rebohle 8b5db80fbd
[dxvk] Reimplement DxvkBuffer
Avoids the DxvkPhysicalBuffer indirection and keeps all buffer
objects alive until the DxvkBuffer itself gets destroyed.
2019-01-09 18:04:46 +01:00
Robin 1750b14c2a [d3d11] Lock in SynchronizeCsThread
This prevents fixes threading issues with D3D10 games when
Present() gets called.

Fixes #567.
2018-12-30 21:08:52 +01:00
Philip Rebohle cf21111401
[d3d11] Implement ID3D11Multithread for D3D11 contexts 2018-11-30 11:38:00 +01:00
Philip Rebohle ad5688764c
[d3d11] Use single-use submission mode for CS chunks where possible 2018-11-20 10:44:04 +01:00
Philip Rebohle ab3ba776e0
[d3d11] Do not re-upload mapped image if it was mapped for reading 2018-11-08 18:51:53 +01:00
Philip Rebohle 4d103aad5d
[d3d11] Allow mapping depth-stencil images for reading
This may be needed for The Surge and Lords of the Fallen.
2018-11-08 18:51:47 +01:00
Philip Rebohle d5481ac013
[d3d11] Remove redundant D3D11Buffer::GetSize method 2018-11-02 15:43:46 +01:00
Philip Rebohle 8054e4a772
[dxvk] Add DXVK context method to transparently flush the command list
This is identical to what the D3D11 function did, but having it in this
place will allow us to potentially implement better flush heuristics
based on work done on the CS thread.
2018-11-01 13:24:42 +01:00
Philip Rebohle 5a30110d0f
Revert "[d3d11] Remove some flush points"
This reverts commit 5ab6f691ae.

Apparently this leads to extremely bad frame times on some Nvidia setups.
2018-10-25 20:55:37 +02:00
Philip Rebohle 5124fd87d5
[d3d11] Implicitly flush when queueing an event query
Significantly improves GPU utilization in Quake Champions.
2018-10-17 17:28:47 +02:00
Philip Rebohle 5ecfbd8425
[d3d11] Do not use QueryInterface to get query pointers
We're not going to implement counters anyway, so this is
unnecessary overhead.
2018-10-17 17:28:47 +02:00
Philip Rebohle 5ab6f691ae
[d3d11] Remove some flush points
These aren't as useful as they may look like since they occur
at render pass boundaries anyway.
2018-10-17 17:28:47 +02:00
Philip Rebohle 11b269efd1
[d3d11] Save a few CPU cycles in Map/MapBuffer 2018-10-16 12:29:04 +02:00
Philip Rebohle 6c889c0005
Revert "[d3d11] Avoid unnecessary buffer slice copy when mapping buffer"
This reverts commit 72106a02cb.

Breaks things for some reason. Doesn't have much of an impact anyway.
2018-09-17 23:08:00 +02:00
Philip Rebohle 72106a02cb
[d3d11] Avoid unnecessary buffer slice copy when mapping buffer 2018-09-17 22:04:31 +02:00
Philip Rebohle 19408f0ebe
[d3d11] Fix reported RowPitch/DepthPitch for mapped buffers
Some games rely on this being the exact buffer size.
2018-09-17 07:45:05 +02:00
Philip Rebohle 09948a3495
[d3d11] Synchronize CS thread after flush when waiting for resource
In some rare cases, the flush operation itself may add new references
which we need to see while spinning on the resource's usage counter.
2018-09-01 21:25:39 +02:00
Philip Rebohle f1b075c0f3 [dxvk] Add CS chunk pool
Reduces the number of dynamic memory allocations for CS chunks by
recycling them once they are no longer needed. Also fixes a potential
issue with chunks that are dispatched multiple times.
2018-08-27 16:07:38 +02:00
Philip Rebohle dc31be7118
[d3d11] Use global user config for D3D11 options 2018-08-07 14:59:09 +02:00
Philip Rebohle ace8e42213
[d3d11] Move BufferInfo struct into D3D11Buffer 2018-08-05 18:24:01 +02:00
Philip Rebohle adadf362a3
[d3d11] Optimize WaitForResource behaviour when resource is already idle
We don't have to flush everything in this case, just flushing the current
CS chunk is enough to determine if the resource is in use by the GPU.
2018-07-23 16:08:01 +02:00
Jacek Caban c934d85b85 [d3d11] Move D3D11ImmediateContext constexpr values to .cpp file
In my winelib builds, I get unresolved dxvk::D3D11ImmediateContext::MinFlushIntervalUs symbol. I'm not sure why it doesn't inline this constexpr, but it doesn't seem useful to expose that in header anyway.
2018-07-19 08:55:34 +02:00
Jacek Caban 6d16bb4c87 Don't use std::thread.
Wine needs to setup each thread that has an access to Windows APIs. It means that in winelib builds, we can't let standard C++ library create threads and need to use Wine for that instead. I wrote a thin wrapper around Windows thread functions so that the rest of code just has to use new dxvk::thread class instead of std::thread.
2018-07-19 08:55:34 +02:00
Philip Rebohle 87b5161b2a
[d3d11] Reset implicit flush timer only when actually flushing
In some situations, calling Flush without any commands that
could be flushed would unnecessarily prevent the implicit
flush heuristic from kicking in properly.
2018-07-09 20:31:54 +02:00
Philip Rebohle 9fee253d09
[d3d11] Add more implicit flush points
All these methods will implicitly spill the active render pass and
are typically not called very often, so we can try to keep the GPU
busy.
2018-06-27 18:34:17 +02:00
Philip Rebohle f5d73842b2
[d3d11] Do not flush on every call to GetData
There are several scenarios when flushing can have
a significant negative impact on performance:
1. When the query result is already available
2. When the game scatters GetData calls when rendering

Frostpunk hits both issues at the same time, which led to
over 120 queue submissions per frame. This patch reduces
that to 3 submissions per frame when the game is GPU-bound.
2018-06-19 14:34:15 +02:00
Philip Rebohle 1e7a05c796
[d3d11] Remove GetData do-not-flush workaround for Fallout 4
Not needed anymore due to the implicit flush.
2018-06-08 13:13:42 +02:00
Philip Rebohle d4cb5115e7
[d3d11] Flush implicitly when GetData returns S_FALSE
Keeps the GPU busy when spinning on a query and ensures that we're
flushing at some point. Replaces the Fallout 4 hang workaround.
2018-06-08 13:11:24 +02:00
Philip Rebohle c716372941
[d3d11] Move GetData implementation to D3D11ImmediateContext
It is illegal to call this method on a deferred context, so we should
filter out those calls. This allows the implementation to make use of
features specific to the immediate context.
2018-06-08 12:29:24 +02:00
Philip Rebohle 4a0c81276f
[d3d11] Implement new auto-flush heuristic 2018-06-04 23:31:49 +02:00
Philip Rebohle 99813a7778 [d3d11] Use const ref pointer for device parameter
Closes #323.
2018-04-28 14:17:52 +02:00
Philip Rebohle f71f527b4d
[d3d11] Prevent mapping of depth-stencil textures
We currently don't support this, and copying data back and forth
with the wrong image aspect set crashes the RADV driver.
2018-04-21 20:34:41 +02:00
Philip Rebohle a6767ebd52
[d3d11] Improved debug output of D3D11DeviceContext methods 2018-04-14 11:45:31 +02:00
Philip Rebohle 7de27d4fd8 [d3d11] Flush immediate context on command list execution
This optimization may help keep the GPU busy in case there's
a large number of draw calls pending at the time a command
list from a deferred context is submitted for execution.
2018-04-03 19:53:37 +02:00
Philip Rebohle 77010d96e4 [dxgi/d3d11] Set returned pointers to nullptr before returning
May solve issues with applications which check whether the returned
pointer is null rather than checking a function's return value.
2018-04-02 12:04:20 +02:00
Philip Rebohle 4e84a77896
[d3d11] Disable DO_NOT_WAIT flag by default
Apparently this breaks Elder Scrolls Online as well, so we'll
just enable it explicitly for games which benefit from this
optimization and disable it by default.
2018-03-25 00:54:42 +01:00
Philip Rebohle bd69e843c2
[d3d11] Added D3D11Options
Includes a per-app knob for Witcher 3 to disable D3D11_MAP_FLAG_DO_NOT_WAIT.
2018-03-24 17:02:24 +01:00
Philip Rebohle 0a2fa590f5
[d3d11] Reset busy flag after emitting the Flush command
Fixes a general performance regression in games
that call WaitForResources a lot.
2018-03-23 11:54:19 +01:00
Philip Rebohle 085fd6a959
[d3d11] Remove unnecessary Map() check 2018-03-22 19:28:00 +01:00
Philip Rebohle d9b1995cf0
[d3d11] Do not forward D3D11_MAP_FLAG_DO_NOT_WAIT for mapped images
Workaround for a regression in The Witcher 3 that was introduced
in commit 53d557c2db. May have a
significant negative impact on performance in some games.
2018-03-22 14:12:43 +01:00
Philip Rebohle b3aff7cd2e
[d3d11] Fix immediate context initialization
The old initialization code did not take either CSMT or
Deferred Contexts into account and could lead to illegal
calls to beginRecording.

Fixes a hang encountered in Dishonored 2.
2018-03-22 13:40:45 +01:00
Philip Rebohle 7f6c8dff95
[d3d11] Fix flush condition and CS thread synchronization
If chunks have been sent to the CS thread, we need to
flush even if the current chunk is empty.
2018-03-22 12:58:26 +01:00
Philip Rebohle 53d557c2db
[d3d11] Implement D3D11_MAP_FLAG_DO_NOT_WAIT
Improves framerate in Dishonored 2 by up to 50%.
2018-03-22 11:02:14 +01:00
Philip Rebohle 493ad66d91
[d3d11] Remove obsolete acquire/release pair
This is no longer needed with the universally
thread-safe slice allocator.
2018-03-19 17:56:26 +01:00
Philip Rebohle f1c3b59e87
[d3d11] Implemented buffer mapping on deferred contexts
Allows the MultiThreadedRendering demo from the Microsoft SDK to run.
2018-03-19 03:19:13 +01:00
Philip Rebohle 1af52abb67
[d3d11] Move OMSetRenderTargets optimization to D3D11ImmediateContext
We cannot call Flush() on deferred contexts anyway, so the command
submission optimization should only be applied to immediate contexts.
2018-03-17 14:09:16 +01:00
Philip Rebohle 3b20c71894
[d3d11] Re-implement direct image mapping (disabled by default)
We cannot enable this by default yet because it may break some games.
2018-03-14 16:40:28 +01:00
Philip Rebohle 0ba3337289
[d3d11] Refactored Map/Unmap methods 2018-03-14 14:40:09 +01:00
Philip Rebohle 56df0bcccb
[d3d11] Refactoring texture classes: Remove D3D11TextureInfo 2018-03-14 00:45:07 +01:00
Philip Rebohle 06cff50453
[d3d11] Flush CS chunks when executing/finalizing command lists
Fixes rendering issues and validation errors in Kingdom Come: Deliverance.
2018-03-12 23:36:55 +01:00
Mikhail Paulyshka f94ff7db4f [d3d11] add check for pResource against nullptr in D3D11ImmediateContext::Map() 2018-03-12 03:18:44 +03:00
Philip Rebohle 4eacff21e9
[dxvk] Flush initialization context unconditionally
An application might need to wait for a resource to become available
just after it has been created, in which case  its initialization
commands might not have been dispatched yet. If no rendering commands
were issued on the immediate context prior to the wait operation,
WaitForResource would stall indefinitely.
2018-03-11 20:25:09 +01:00
Philip Rebohle d3e89b20dd
[d3d11] Allocate host-readable images on host-visible memory
Not having to wait for an image->buffer copy to finish on the
GPU allows for more efficient synchronization. Significantly
improves performance in The Witcher 3.
2018-03-10 23:32:15 +01:00
Philip Rebohle b494bb2ac1
[d3d11] Fixed potential sync issue in Map() 2018-03-07 10:37:27 +01:00
Mikhail Paulyshka 9deb73a2a7 Add support for MSVC, attempt 3 (#130)
* [dxvk] fixes for MSVC

* nullptr -> int is illegal conversion for MSVC. nullptr was replaced with VK_NULL_HANDLE
* MSVC does not support source code strings longer than 65535 chars. String was replaced with array of chars.

* [utils] fixes for MSVC

* __mingw_uuidof() does not exists in MSVC
* apply GCC pragma only for GCC
* added missing header

* [dxbc] fixes for MSVC

*added missing header

* [dxgi] fixes for MSVC

* user __declspec(uuid()) instead of _mingw_uuidof()
* do not use DLLEXPORT macro for MSVC

* [d3d11] fixes for MSVC

* replace WINBOOL with BOOL
* do not declare D3D11 structs for MSVC
* do not use DLLEXPORT macro for MSVC

* [meson] fix build scripts for MSVC

* change cpp version from c++1z to c++latest for MSVC
* set -DOMINMAX definition for MSVC
* disable test and wine_utils for MSVC
* use .def files instead of __declspec(dllexport) for MSVC (bypass 'C2375: redefinition; different linkage' error)
* fix .def files for MinGW
* add --enable-stdcall-fixup linker flag for MinGW
2018-03-06 18:34:34 +01:00
Philip Rebohle 13331a463f
[d3d11] Re-implement check for mapping device-local images 2018-03-06 11:35:12 +01:00
Philip Rebohle 1cbe6829eb
Revert "Add MSVC support (#123)"
This reverts commit c63d4361a0.
2018-03-05 14:32:28 +01:00