Skip to content

Commit

Permalink
[d3d8] Remove managedBufferPlacement workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall committed Feb 25, 2024
1 parent 26de615 commit 58c89ee
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 36 deletions.
22 changes: 0 additions & 22 deletions src/d3d8/d3d8_d3d9_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,6 @@

namespace dxvk {


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

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

// TODO: Optimize carefully which buffers go in which pools.
// - WRITEONLY DYNAMIC buffers might get performance gains in DEFAULT if not misused

// Remap DEFAULT pool vertex buffers to MANAGED.
// - This avoids direct buffer mapping which can cause apps to misbehave
// 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 && Length >= options.managedBufferPlacement) {
Pool = d3d9::D3DPOOL_MANAGED;
Usage &= ~D3DUSAGE_DYNAMIC;
}

return {Usage, Pool};
}

// (8<-9) D3DCAPSX: Writes to D3DCAPS8 from D3DCAPS9
inline void ConvertCaps8(const d3d9::D3DCAPS9& caps9, D3DCAPS8* pCaps8) {

Expand Down
8 changes: 3 additions & 5 deletions src/d3d8/d3d8_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ namespace dxvk {

Com<d3d9::IDirect3DVertexBuffer9> pVertexBuffer9 = nullptr;

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

if (!FAILED(res))
*ppVertexBuffer = ref(new D3D8VertexBuffer(this, std::move(pVertexBuffer9), Pool, Usage));
Expand All @@ -381,13 +380,12 @@ namespace dxvk {
InitReturnPtr(ppIndexBuffer);
Com<d3d9::IDirect3DIndexBuffer9> pIndexBuffer9 = nullptr;

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

if (!FAILED(res))
*ppIndexBuffer = ref(new D3D8IndexBuffer(this, std::move(pIndexBuffer9), Pool, Usage));

return res;

}

HRESULT STDMETHODCALLTYPE D3D8Device::CreateRenderTarget(
Expand Down
9 changes: 0 additions & 9 deletions src/d3d8/d3d8_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
namespace dxvk {
struct D3D8Options {

/// Remap DEFAULT pool vertex and index buffers above this size to the MANAGED pool
/// to improve performance by avoiding waiting for games that frequently lock (large) buffers.
///
/// This implicitly disables direct buffer mapping. Some applications may need this option
/// disabled for certain (smaller) buffers to keep from overwriting in-use buffer regions.
uint32_t managedBufferPlacement = 0;

/// Some games rely on undefined behavior by using undeclared vertex shader inputs.
/// The simplest way to fix them is to simply modify their vertex shader decl.
///
Expand All @@ -30,8 +23,6 @@ namespace dxvk {

D3D8Options() {}
D3D8Options(const Config& config) {
int32_t minManagedSize = config.getOption<int32_t> ("d3d8.managedBufferPlacement", managedBufferPlacement);
managedBufferPlacement = config.getOption<bool> ("d3d8.managedBufferPlacement", true) ? minManagedSize : UINT32_MAX;
auto forceVsDeclStr = config.getOption<std::string>("d3d8.forceVsDecl", "");
batching = config.getOption<bool> ("d3d8.batching", batching);

Expand Down

0 comments on commit 58c89ee

Please sign in to comment.