Skip to content

Commit

Permalink
Merge branch 'ajaus/ignore-buffer-bounds-option' into 'main'
Browse files Browse the repository at this point in the history
Add option to always copy entire index and vertex buffers on an unlock instead...

See merge request lightspeedrtx/bridge-remix-nv!12
  • Loading branch information
nv-ajaus committed May 25, 2023
2 parents 0572e7b + 7ce702c commit 1a05374
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
10 changes: 10 additions & 0 deletions bridge.conf
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,13 @@
# Supported values: True, False

# useShadowMemoryForDynamicBuffers = False

# If this is set, the bridge will ignore the bounds set during a lock for
# any non-dynamic (static) index and vertex buffers.
# This is useful for when a game writes outside of the bounds set in
# a lock call for it's buffers and expects them to still exist after
# the call to unlock. This can manifest as entire pieces of geometry being missing.
#
# Supported values: True, False

# alwaysCopyEntireStaticBuffer = False
20 changes: 17 additions & 3 deletions src/client/lockable_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class LockableBuffer: public Direct3DResource9_LSS<T> {
protected:
const DescType m_desc;
SharedHeap::AllocId m_bufferId = SharedHeap::kInvalidId;
bool m_sendWhole = false;

LockableBuffer(T* const pD3dBuf, BaseDirect3DDevice9Ex_LSS* const pDevice, const DescType& desc)
: Direct3DResource9_LSS<T>(pD3dBuf, pDevice)
Expand All @@ -86,6 +87,10 @@ class LockableBuffer: public Direct3DResource9_LSS<T> {
if (!m_bUseSharedHeap) {
initShadowMem();
}

if ((m_desc.Usage & D3DUSAGE_DYNAMIC) == 0 && GlobalOptions::getAlwaysCopyEntireStaticBuffer()) {
m_sendWhole = true;
}
}

~LockableBuffer() {
Expand Down Expand Up @@ -145,19 +150,28 @@ class LockableBuffer: public Direct3DResource9_LSS<T> {
}
// Get most recent locked buffer and grab data before we unlock
const auto& lockInfo = m_lockInfos.front();
const size_t size = (lockInfo.sizeToLock == 0) ? m_desc.Size : lockInfo.sizeToLock;
size_t size = (lockInfo.sizeToLock == 0) ? m_desc.Size : lockInfo.sizeToLock;
uint32_t offset = lockInfo.offsetToLock;
void* ptr = lockInfo.pbData;

if (m_sendWhole) {
size = m_desc.Size;
offset = 0;
ptr = m_shadow.get();
}

// If this is a read only access then don't bother sending
if ((lockInfo.flags & D3DLOCK_READONLY) == 0) {
{
// Send the buffer lock parameters and handle
ClientMessage c(UnlockCmd, getId(), m_bUseSharedHeap ? Commands::FlagBits::DataInSharedHeap : 0);
c.send_many(lockInfo.offsetToLock, size, lockInfo.flags);
c.send_many(offset, size, lockInfo.flags);

if (m_bUseSharedHeap) {
c.send_data(lockInfo.bufferId);
} else {
// Now send the buffer bytes
c.send_data(size, lockInfo.pbData);
c.send_data(size, ptr);
}
}
if (lockInfo.discardedBufferId != SharedHeap::kInvalidId) {
Expand Down
9 changes: 9 additions & 0 deletions src/util/config/global_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ class GlobalOptions {
bridge_util::Logger::debug(bridge_util::format_string("Global settings are being applied from flags value %d", flags));
}

static const bool getAlwaysCopyEntireStaticBuffer() {
return get().alwaysCopyEntireStaticBuffer;
}

private:
GlobalOptions() = default;

Expand Down Expand Up @@ -311,6 +315,10 @@ class GlobalOptions {

// Thread-safety policy: 0 - use client's choice, 1 - force thread-safe, 2 - force non-thread-safe
threadSafetyPolicy = bridge_util::Config::getOption<uint32_t>("threadSafetyPolicy", 0);

// If set and a buffer is not dynamic, vertex and index buffer lock/unlocks will ignore the bounds set during the lock call
// and the brifge will copy the entire buffer. This means
alwaysCopyEntireStaticBuffer = bridge_util::Config::getOption<bool>("alwaysCopyEntireStaticBuffer", false);
}

void initSharedHeapPolicy();
Expand Down Expand Up @@ -350,4 +358,5 @@ class GlobalOptions {
uint32_t sharedHeapChunkSize;
uint32_t sharedHeapFreeChunkWaitTimeout;
uint32_t threadSafetyPolicy;
bool alwaysCopyEntireStaticBuffer;
};

0 comments on commit 1a05374

Please sign in to comment.