Skip to content

Commit

Permalink
Add RenderSystem::isDeviceLost()
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Golushkov committed Dec 26, 2024
1 parent f08ef1d commit a3df89c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
19 changes: 17 additions & 2 deletions OgreMain/include/OgreRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,23 @@ namespace Ogre
*/
virtual void shutdown();

/** Some render systems have moments when GPU device is temporarily unavailable,
for example when D3D11 device is lost, or when iOS app is in background, etc.
/** Returns true if device was lost and the application should destroy and recreate
the device and all device depended resources using validateDevice() call. Note,
that initial device lost condition detection is asynchronous, and can be reported
by any 3D API call, resulting in RenderingApiException that should be catched.
Device lost conditions are reported by 3D APIs as
- Direct3D 9: D3DERR_DEVICELOST
- Direct3D 10+: DXGI_ERROR_DEVICE_REMOVED/_RESET/_HUNG/etc
- Vulkan: VK_ERROR_DEVICE_LOST
- OpenGL[ES]: GL_CONTEXT_LOST
- Metal: MTLCommandBufferErrorDeviceRemoved/AccessRevoked, MTLDeviceWasRemovedNotification
*/
virtual bool isDeviceLost() { return false; }

/** Checks if device was lost and recreates it with all depended resources.
Optionally elects best physical device even if current device was not lost.
Without forceDeviceElection param this function is pretty lightweight
and is automatically called by Ogre on start of each frame.
*/
virtual bool validateDevice( bool forceDeviceElection = false ) { return true; }

Expand Down
1 change: 1 addition & 0 deletions RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ namespace Ogre

void reinitialise() override;
void shutdown() override;
bool isDeviceLost() override;
bool validateDevice( bool forceDeviceElection = false ) override;
void handleDeviceLost();
void setShadingType( ShadeOptions so );
Expand Down
2 changes: 2 additions & 0 deletions RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,8 @@ namespace Ogre
StringConverter::toString( passedTime ) + "ms" );
}
//---------------------------------------------------------------------
bool D3D11RenderSystem::isDeviceLost() { return !mDevice.isNull() && mDevice.IsDeviceLost(); }
//---------------------------------------------------------------------
bool D3D11RenderSystem::validateDevice( bool forceDeviceElection )
{
if( mDevice.isNull() )
Expand Down
1 change: 1 addition & 0 deletions RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ namespace Ogre
void shutdown() override;
const FastArray<VulkanPhysicalDevice> &getVulkanPhysicalDevices() const;
const VulkanPhysicalDevice &getActiveVulkanPhysicalDevice() const { return mActiveDevice; }
bool isDeviceLost() override;
bool validateDevice( bool forceDeviceElection = false ) override;
void handleDeviceLost();

Expand Down
2 changes: 2 additions & 0 deletions RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,8 @@ namespace Ogre
{
return mInstance->mVulkanPhysicalDevices;
}
//---------------------------------------------------------------------
bool VulkanRenderSystem::isDeviceLost() { return mDevice && mDevice->isDeviceLost(); }
//-------------------------------------------------------------------------
bool VulkanRenderSystem::validateDevice( bool forceDeviceElection )
{
Expand Down

0 comments on commit a3df89c

Please sign in to comment.