Skip to content

Commit

Permalink
[D3D11] Always prefer UpdateSubresource1() over emulated offset update (
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBanana committed Feb 8, 2025
1 parent bc21854 commit 1209132
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
5 changes: 4 additions & 1 deletion sources/Renderer/Direct3D11/Buffer/D3D11Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void D3D11Buffer::WriteSubresource(ID3D11DeviceContext* context, const void* dat
{
/* Update subresource region of buffer */
const D3D11_BOX dstBox{ offset, 0, 0, offset + dataSize, 1, 1 };
if (offset != 0 && needsCommandListEmulation && context->GetType() == D3D11_DEVICE_CONTEXT_DEFERRED)
if (offset != 0 && context->GetType() == D3D11_DEVICE_CONTEXT_DEFERRED)
{
#if LLGL_D3D11_ENABLE_FEATURELEVEL >= 1
ComPtr<ID3D11DeviceContext1> context1;
Expand All @@ -138,6 +138,7 @@ void D3D11Buffer::WriteSubresource(ID3D11DeviceContext* context, const void* dat
}
else
#endif
if (needsCommandListEmulation)
{
/*
Update subresource region of buffer with adjusted source pointer to workaround limitation of emulated command lists.
Expand All @@ -146,6 +147,8 @@ void D3D11Buffer::WriteSubresource(ID3D11DeviceContext* context, const void* dat
const char* dataWithOffset = static_cast<const char*>(data) - offset;
context->UpdateSubresource(GetNative(), 0, &dstBox, dataWithOffset, 0, 0);
}
else
context->UpdateSubresource(GetNative(), 0, &dstBox, data, 0, 0);
}
else
context->UpdateSubresource(GetNative(), 0, &dstBox, data, 0, 0);
Expand Down
6 changes: 0 additions & 6 deletions sources/Renderer/Direct3D11/RenderState/D3D11StateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ namespace LLGL
{


#if LLGL_D3D11_ENABLE_FEATURELEVEL >= 1

/*
Returns true if the D3D runtime supports command lists natively.
Otherwise, they will be emulated by the D3D runtime and all *SetConstantBuffers1() functions need a workaround as described here:
Expand All @@ -32,8 +30,6 @@ static bool D3DSupportsDriverCommandLists(ID3D11Device* device)
return (SUCCEEDED(hr) && threadingCaps.DriverCommandLists != FALSE);
}

#endif

/*
Note:
Maximum size for D3D11 cbuffer is 'D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * 4 * sizeof(float)'
Expand All @@ -43,9 +39,7 @@ static constexpr UINT g_cbufferChunkSize = 4096u;

D3D11StateManager::D3D11StateManager(ID3D11Device* device, const ComPtr<ID3D11DeviceContext>& context) :
context_ { context },
#if LLGL_D3D11_ENABLE_FEATURELEVEL >= 1
needsCommandListEmulation_ { !D3DSupportsDriverCommandLists(device) },
#endif
stagingCbufferPool_
{
device,
Expand Down
7 changes: 2 additions & 5 deletions sources/Renderer/Direct3D11/RenderState/D3D11StateManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ class D3D11StateManager
// This is true if the D3D device does not natively support command lists.
inline bool NeedsCommandListEmulation() const
{
#if LLGL_D3D11_ENABLE_FEATURELEVEL >= 1
return needsCommandListEmulation_;
#else
return true;
#endif
}

private:
Expand Down Expand Up @@ -155,9 +151,10 @@ class D3D11StateManager

#if LLGL_D3D11_ENABLE_FEATURELEVEL >= 1
ComPtr<ID3D11DeviceContext1> context1_;
const bool needsCommandListEmulation_ = false;
#endif

const bool needsCommandListEmulation_ = false;

D3D11StagingBufferPool stagingCbufferPool_;

D3DInputAssemblyState inputAssemblyState_;
Expand Down

0 comments on commit 1209132

Please sign in to comment.