D3D11: Re-read the device and context on DeviceRestore

The restored draw context can be a new device, so the cached pointers
could go stale.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-09-29 13:16:59 -06:00
1 parent ba37f327b0
commit 035c98d14f
4 files changed
+23

No files matched your search

+9
View File
@@ -128,10 +128,19 @@ void DrawEngineD3D11::DestroyDeviceObjects() {
void DrawEngineD3D11::DeviceLost() {
DestroyDeviceObjects();
draw_ = nullptr;
device_ = nullptr;
context_ = nullptr;
device1_ = nullptr;
context1_ = nullptr;
}
void DrawEngineD3D11::DeviceRestore(Draw::DrawContext *draw) {
// The restored context can be a new device, so don't keep the old pointers.
draw_ = draw;
device_ = (ID3D11Device *)draw->GetNativeObject(Draw::NativeObject::DEVICE);
context_ = (ID3D11DeviceContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);
device1_ = (ID3D11Device1 *)draw->GetNativeObject(Draw::NativeObject::DEVICE_EX);
context1_ = (ID3D11DeviceContext1 *)draw->GetNativeObject(Draw::NativeObject::CONTEXT_EX);
InitDeviceObjects();
}
+3
View File
@@ -89,6 +89,9 @@ void GPU_D3D11::DeviceLost() {
}
void GPU_D3D11::DeviceRestore(Draw::DrawContext *draw) {
// The restored context can be a new device, so don't keep the old pointers.
device_ = (ID3D11Device *)draw->GetNativeObject(Draw::NativeObject::DEVICE);
context_ = (ID3D11DeviceContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);
GPUCommonHW::DeviceRestore(draw);
}
+6
View File
@@ -111,10 +111,16 @@ void ShaderManagerD3D11::DestroyDeviceObjects() {
void ShaderManagerD3D11::DeviceLost() {
DestroyDeviceObjects();
draw_ = nullptr;
device_ = nullptr;
context_ = nullptr;
}
void ShaderManagerD3D11::DeviceRestore(Draw::DrawContext *draw) {
// The restored context can be a new device, so don't keep the old pointers.
draw_ = draw;
device_ = (ID3D11Device *)draw->GetNativeObject(Draw::NativeObject::DEVICE);
context_ = (ID3D11DeviceContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);
featureLevel_ = (D3D_FEATURE_LEVEL)draw->GetNativeObject(Draw::NativeObject::FEATURE_LEVEL);
InitDeviceObjects();
}
+5
View File
@@ -178,9 +178,14 @@ void TextureCacheD3D11::DeviceLost() {
TextureCacheCommon::DeviceLost();
DestroyDeviceObjects();
draw_ = nullptr;
device_ = nullptr;
context_ = nullptr;
}
void TextureCacheD3D11::DeviceRestore(Draw::DrawContext *draw) {
// The restored context can be a new device, so don't keep the old pointers.
device_ = (ID3D11Device *)draw->GetNativeObject(Draw::NativeObject::DEVICE);
context_ = (ID3D11DeviceContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);
TextureCacheCommon::DeviceRestore(draw);
InitDeviceObjects();
}