Commit Graph

167 Commits

Author SHA1 Message Date
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
Mikhail Paulyshka c63d4361a0 Add MSVC support (#123)
* [utils] fixes for MSVC

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

* [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.

* [dxbc] fixes for MSVC

*added missing header

* [dxgi] fixes for MSVC

* user __declspec(uuid()) instead of _mingw_uuidof()

* [d3d11] fixes for MSVC

* replace WINBOOL with BOOL
* do not declare D3D11 structs

* [meson] fix build scripts for MSVC

* change cpp version from 1z to 17 for MSVC
* set -DOMINMAX definition for MSVC
* disable test and wine_utils for MSVC
* use .def files instead of __declspec(dllexport) (bypass 'C2375: redefinition; different linkage' error)
2018-03-05 14:28:51 +01:00
Philip Rebohle b469cfac0b
[d3d11] Implemented FinishCommandList/ExecuteCommandList 2018-03-03 20:59:17 +01:00
Philip Rebohle e89c7e9276 [d3d11] Added test case for occlusion queries and small improvements 2018-02-19 11:27:14 +01:00
Philip Rebohle 78c46f444a
[d3d11] Added missing CS thread sync for non-discard Map() 2018-01-31 16:39:47 +01:00
Philip Rebohle 3148155c35
[d3d11] Implemented CS chunk submission for deferred contexts
Changes were necessary due to the fact that chunks in deferred
contexts are not directly submitted to the CS thread.
2018-01-23 12:03:26 +01:00
Philip Rebohle 5b1311b71e
[d3d11] Added stubs for deferred contexts and command lists 2018-01-23 09:23:31 +01:00
Philip Rebohle 07f5a7f069
[d3d11] Synchronize with CS thread before present
Fixes flickering by synchronizing with the presenter. This has
to do for now, a more efficient solution can be added later.
2018-01-21 18:04:22 +01:00
Philip Rebohle 7c3a9beb22
[dxvk] Recycle CS chunks 2018-01-21 12:59:43 +01:00
Philip Rebohle 51e89f00be
[d3d11] Fixed flush order 2018-01-21 02:21:38 +01:00
Philip Rebohle b7a00e32ec
[dxvk] Limit size of the CS command queue
Prevents memory leaks and fixes stuttering in Heaven.
2018-01-21 00:49:07 +01:00
Philip Rebohle 6ab7897127
[d3d11] Enabled command stream thread 2018-01-20 23:12:03 +01:00
Philip Rebohle 7d7cc1ceda
[d3d11] Record commands into a CS chunk 2018-01-20 22:52:18 +01:00
Philip Rebohle aaf7b05625
[d3d11] Use EmitCs for buffer mapping 2018-01-20 22:28:15 +01:00
Philip Rebohle f25b3c8b32
[d3d11] Use EmitCs for resource updates 2018-01-20 21:42:11 +01:00
Philip Rebohle 4d17b1752f
[d3d11] Use EmitCs for general setup and synchronization methods 2018-01-20 18:01:43 +01:00
Philip Rebohle 62a43cbdbe
[d3d11] Add EmitCs method to D3D11DeviceContext
Subsequently, all calls into the DXVK context will be
replaced by calls to the EmitCs method with a lambda.
2018-01-20 15:29:10 +01:00
Philip Rebohle 0b426a0942
[d3d11] Added new D3D11ImmediateContext class
Initial prep work for both CSMT and Deferred Contexts.
2018-01-20 13:22:44 +01:00