1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-20 10:54:16 +01:00

[d3d11] Revert index buffer optimization

This causes some problems when the app uses a combination of index
buffer offset and StartIndexLocation that overflows 32-bit integers.

In my testing, there haven't been many games benefitting from this
optimization anyway, so just reverting it should not have tangible
effects on performance.
This commit is contained in:
Philip Rebohle 2021-03-04 15:44:36 +01:00
parent e44a1e614b
commit 049fda9218
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
3 changed files with 3 additions and 53 deletions

View File

@ -1465,7 +1465,6 @@ namespace dxvk {
UINT StartIndexLocation,
INT BaseVertexLocation) {
D3D10DeviceLock lock = LockContext();
StartIndexLocation += m_state.ia.indexBuffer.firstIndex;
EmitCs([=] (DxvkContext* ctx) {
ctx->drawIndexed(
@ -1500,7 +1499,6 @@ namespace dxvk {
INT BaseVertexLocation,
UINT StartInstanceLocation) {
D3D10DeviceLock lock = LockContext();
StartIndexLocation += m_state.ia.indexBuffer.firstIndex;
EmitCs([=] (DxvkContext* ctx) {
ctx->drawIndexed(
@ -1675,12 +1673,6 @@ namespace dxvk {
if (needsUpdate)
m_state.ia.indexBuffer.buffer = newBuffer;
if (likely(m_state.ia.indexBuffer.optimized)) {
uint32_t shift = Format == DXGI_FORMAT_R16_UINT ? 1 : 2;
m_state.ia.indexBuffer.firstIndex = Offset >> shift;
Offset = 0;
}
needsUpdate |= m_state.ia.indexBuffer.offset != Offset
|| m_state.ia.indexBuffer.format != Format;
@ -1740,12 +1732,8 @@ namespace dxvk {
if (pFormat != nullptr)
*pFormat = m_state.ia.indexBuffer.format;
if (pOffset != nullptr) {
uint32_t shift = m_state.ia.indexBuffer.format == DXGI_FORMAT_R16_UINT ? 1 : 2;
*pOffset = m_state.ia.indexBuffer.optimized
? m_state.ia.indexBuffer.firstIndex << shift
: m_state.ia.indexBuffer.offset;
}
if (pOffset != nullptr)
*pOffset = m_state.ia.indexBuffer.offset;
}
@ -3401,13 +3389,7 @@ namespace dxvk {
void D3D11DeviceContext::BindFramebuffer() {
DxvkRenderTargets attachments;
// Re-enable index buffer optimization here. Some games will
// use indirect draws for actual scene rendering, but then
// use direct draws for things like the user interface.
if (!m_state.ia.indexBuffer.optimized)
SetIndexBufferOptimized(true);
// D3D11 doesn't have the concept of a framebuffer object,
// so we'll just create a new one every time the render
// target bindings are updated. Set up the attachments.
@ -3602,39 +3584,12 @@ namespace dxvk {
}
void D3D11DeviceContext::SetIndexBufferOptimized(
BOOL Enable) {
uint32_t shift = m_state.ia.indexBuffer.format == DXGI_FORMAT_R16_UINT ? 1 : 2;
if (Enable) {
m_state.ia.indexBuffer.firstIndex = m_state.ia.indexBuffer.offset >> shift;
m_state.ia.indexBuffer.offset = 0;
} else {
m_state.ia.indexBuffer.offset += m_state.ia.indexBuffer.firstIndex << shift;
m_state.ia.indexBuffer.firstIndex = 0;
}
m_state.ia.indexBuffer.optimized = Enable;
BindIndexBuffer(
m_state.ia.indexBuffer.buffer.ptr(),
m_state.ia.indexBuffer.offset,
m_state.ia.indexBuffer.format);
}
void D3D11DeviceContext::SetDrawBuffers(
ID3D11Buffer* pBufferForArgs,
ID3D11Buffer* pBufferForCount) {
auto argBuffer = static_cast<D3D11Buffer*>(pBufferForArgs);
auto cntBuffer = static_cast<D3D11Buffer*>(pBufferForCount);
// Bind index buffer with the actual offset since otherwise the
// first index members of the indirect draw structures would be
// incorrect.
if (unlikely(m_state.ia.indexBuffer.optimized))
SetIndexBufferOptimized(false);
if (m_state.id.argBuffer != argBuffer
|| m_state.id.cntBuffer != cntBuffer) {
m_state.id.argBuffer = argBuffer;

View File

@ -786,9 +786,6 @@ namespace dxvk {
ID3D11Resource* pResource,
UINT Subresource);
void SetIndexBufferOptimized(
BOOL Enable);
void SetDrawBuffers(
ID3D11Buffer* pBufferForArgs,
ID3D11Buffer* pBufferForCount);

View File

@ -103,8 +103,6 @@ namespace dxvk {
Com<D3D11Buffer> buffer = nullptr;
UINT offset = 0;
DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;
UINT firstIndex = 0;
BOOL optimized = true;
};