Skip to content

Commit

Permalink
[dxvk] Introduce GetContext method to retrieve immediate context.
Browse files Browse the repository at this point in the history
Bypasses vtable hooks when retrieving the immediate context internally.
Remaining uses of GetImmediateContext are fine since those only interact
with public methods.
  • Loading branch information
doitsujin committed Apr 18, 2023
1 parent 990a720 commit e074d83
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 26 deletions.
6 changes: 5 additions & 1 deletion src/d3d11/d3d11_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,11 @@ namespace dxvk {
D3D10Device* GetD3D10Interface() const {
return m_d3d10Device;
}


D3D11ImmediateContext* GetContext() const {
return m_context.ptr();
}

bool Is11on12Device() const;

static D3D_FEATURE_LEVEL GetMaxFeatureLevel(
Expand Down
5 changes: 1 addition & 4 deletions src/d3d11/d3d11_gdi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,8 @@ namespace dxvk {
HRESULT D3D11GDISurface::CreateReadbackResource() {
auto tex = GetCommonTexture(m_resource);

Com<ID3D11Device> device;
Com<ID3D11DeviceContext> context;

Com<ID3D11Device> device;
m_resource->GetDevice(&device);
device->GetImmediateContext(&context);

D3D11_RESOURCE_DIMENSION dim = { };
m_resource->GetType(&dim);
Expand Down
12 changes: 3 additions & 9 deletions src/d3d11/d3d11_interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,15 @@ namespace dxvk {
const VkImageSubresourceRange* pSubresources,
VkImageLayout OldLayout,
VkImageLayout NewLayout) {
Com<ID3D11DeviceContext> deviceContext = nullptr;
m_device->GetImmediateContext(&deviceContext);

auto immediateContext = static_cast<D3D11ImmediateContext*>(deviceContext.ptr());

auto immediateContext = m_device->GetContext();

immediateContext->TransitionSurfaceLayout(
pSurface, pSubresources, OldLayout, NewLayout);
}


void STDMETHODCALLTYPE D3D11VkInterop::FlushRenderingCommands() {
Com<ID3D11DeviceContext> deviceContext = nullptr;
m_device->GetImmediateContext(&deviceContext);

auto immediateContext = static_cast<D3D11ImmediateContext*>(deviceContext.ptr());
auto immediateContext = m_device->GetContext();
immediateContext->Flush();
immediateContext->SynchronizeCsThread(DxvkCsThread::SynchronizeAll);
}
Expand Down
10 changes: 2 additions & 8 deletions src/d3d11/d3d11_on_12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ namespace dxvk {
Com<ID3D12DXVKInteropDevice> interopDevice;
m_d3d12Device->QueryInterface(__uuidof(ID3D12DXVKInteropDevice), reinterpret_cast<void**>(&interopDevice));

Com<ID3D11DeviceContext> context;
m_device->GetImmediateContext(&context);

for (uint32_t i = 0; i < ResourceCount; i++) {
D3D11_ON_12_RESOURCE_INFO info;

Expand All @@ -125,7 +122,7 @@ namespace dxvk {

VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
interopDevice->GetVulkanImageLayout(info.Resource.ptr(), info.OutputState, &layout);
static_cast<D3D11ImmediateContext*>(context.ptr())->Release11on12Resource(ppResources[i], layout);
m_device->GetContext()->Release11on12Resource(ppResources[i], layout);
}
}

Expand All @@ -136,9 +133,6 @@ namespace dxvk {
Com<ID3D12DXVKInteropDevice> interopDevice;
m_d3d12Device->QueryInterface(__uuidof(ID3D12DXVKInteropDevice), reinterpret_cast<void**>(&interopDevice));

Com<ID3D11DeviceContext> context;
m_device->GetImmediateContext(&context);

for (uint32_t i = 0; i < ResourceCount; i++) {
D3D11_ON_12_RESOURCE_INFO info;

Expand All @@ -149,7 +143,7 @@ namespace dxvk {

VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
interopDevice->GetVulkanImageLayout(info.Resource.ptr(), info.InputState, &layout);
static_cast<D3D11ImmediateContext*>(context.ptr())->Acquire11on12Resource(ppResources[i], layout);
m_device->GetContext()->Acquire11on12Resource(ppResources[i], layout);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/d3d11/d3d11_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,8 @@ namespace dxvk {


HRESULT D3D11SwapChain::PresentImage(UINT SyncInterval) {
Com<ID3D11DeviceContext> deviceContext = nullptr;
m_parent->GetImmediateContext(&deviceContext);

// Flush pending rendering commands before
auto immediateContext = static_cast<D3D11ImmediateContext*>(deviceContext.ptr());
auto immediateContext = m_parent->GetContext();
immediateContext->EndFrame();
immediateContext->Flush();

Expand Down

0 comments on commit e074d83

Please sign in to comment.