Skip to content

Commit

Permalink
[util] Add a buffer placement workaround for MCO
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall authored and AlpyneDreams committed Apr 22, 2023
1 parent af053be commit c815aa8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/d3d8/d3d8_d3d9_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

#include "d3d8_include.h"
#include "d3d8_format.h"
#include "d3d8_options.h"

#include <utility>

namespace dxvk {


// Remap certain vertex and index buffers to different pools.
inline std::pair<DWORD, d3d9::D3DPOOL> ChooseBufferPool(DWORD Usage, D3DPOOL Pool8) {
inline std::pair<DWORD, d3d9::D3DPOOL> ChooseBufferPool(DWORD Usage, D3DPOOL Pool8, const D3D8Options& options) {

d3d9::D3DPOOL Pool = d3d9::D3DPOOL(Pool8);

Expand All @@ -26,7 +27,7 @@ namespace dxvk {
// due to differences in the behavior of NOOVERWRITE that will
// make apps write over in-use buffers that they expect to wait for.
// - D3D9DeviceEx::LockBuffer will ignored DISCARD and NOOVERWRITE for us
if (Pool8 == D3DPOOL_DEFAULT) {
if (Pool8 == D3DPOOL_DEFAULT && options.managedBufferPlacement) {
Pool = d3d9::D3DPOOL_MANAGED;
Usage &= ~D3DUSAGE_DYNAMIC;
}
Expand Down
4 changes: 2 additions & 2 deletions src/d3d8/d3d8_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ namespace dxvk {
InitReturnPtr(ppVertexBuffer);
Com<d3d9::IDirect3DVertexBuffer9> pVertexBuffer9 = nullptr;

auto [usage, realPool] = ChooseBufferPool(Usage, Pool);
auto [usage, realPool] = ChooseBufferPool(Usage, Pool, m_d3d8Options);
HRESULT res = GetD3D9()->CreateVertexBuffer(Length, usage, FVF, realPool, &pVertexBuffer9, NULL);

if (!FAILED(res))
Expand All @@ -289,7 +289,7 @@ namespace dxvk {
InitReturnPtr(ppIndexBuffer);
Com<d3d9::IDirect3DIndexBuffer9> pIndexBuffer9 = nullptr;

auto [usage, realPool] = ChooseBufferPool(Usage, Pool);
auto [usage, realPool] = ChooseBufferPool(Usage, Pool, m_d3d8Options);
HRESULT res = GetD3D9()->CreateIndexBuffer(Length, usage, d3d9::D3DFORMAT(Format), realPool, &pIndexBuffer9, NULL);

if (!FAILED(res))
Expand Down
5 changes: 5 additions & 0 deletions src/d3d8/d3d8_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ namespace dxvk {
/// Also emulates hardware shadow filtering using a bilinear 2x2 PCF.
bool useShadowBuffers = false;

/// Remap DEFAULT pool vertex buffers to MANAGED in order to optimize
/// performance in cases where applications perform read backs
bool managedBufferPlacement = true;

D3D8Options() {}
D3D8Options(const Config& config) {
useShadowBuffers = config.getOption("d3d8.useShadowBuffers", useShadowBuffers);
managedBufferPlacement = config.getOption("d3d8.managedBufferPlacement", managedBufferPlacement);
}

};
Expand Down
1 change: 1 addition & 0 deletions src/util/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ namespace dxvk {
/* Motor City Online */
{ R"(\\MCity_d\.exe$)", {{
{ "d3d9.apitraceMode", "True" },
{ "d3d8.managedBufferPlacement", "False" },
}} },
}};

Expand Down

0 comments on commit c815aa8

Please sign in to comment.