Skip to content

Commit

Permalink
[Vk] added VulkanWindowNull, that could be used as fake initial windo…
Browse files Browse the repository at this point in the history
…w or for headless operations
  • Loading branch information
eugenegff committed Jun 3, 2022
1 parent 1871a53 commit 10e32c8
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 64 deletions.
1 change: 1 addition & 0 deletions RenderSystems/Vulkan/include/OgreVulkanPrerequisites.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ namespace Ogre
class VulkanTextureGpuManager;
class VulkanVaoManager;
class VulkanWindow;
class VulkanWindowSwapChainBased;
class VulkanDiscardBuffer;
class VulkanDiscardBufferManager;

Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Vulkan/include/OgreVulkanQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace Ogre
RefCountedFenceMap mRefCountedFences;

public:
FastArray<VulkanWindow *> mWindowsPendingSwap;
FastArray<VulkanWindowSwapChainBased *> mWindowsPendingSwap;

protected:
FastArray<VkCommandBuffer> mPendingCmds;
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Vulkan/include/OgreVulkanTextureGpuManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace Ogre
VulkanDevice *device, bool bCanRestrictImageViewUsage );
~VulkanTextureGpuManager() override;

TextureGpu *createTextureGpuWindow( VulkanWindow *window );
TextureGpu *createTextureGpuWindow( VulkanWindowSwapChainBased *window );
TextureGpu *createWindowDepthBuffer();

VkImage getBlankTextureVulkanName( TextureTypes::TextureTypes textureType ) const;
Expand Down
4 changes: 2 additions & 2 deletions RenderSystems/Vulkan/include/OgreVulkanTextureGpuWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Ogre
{
class _OgreVulkanExport VulkanTextureGpuWindow final : public VulkanTextureGpuRenderTarget
{
VulkanWindow *mWindow;
VulkanWindowSwapChainBased *mWindow;

uint32 mCurrentSwapchainIdx;

Expand All @@ -48,7 +48,7 @@ namespace Ogre
VulkanTextureGpuWindow( GpuPageOutStrategy::GpuPageOutStrategy pageOutStrategy,
VaoManager *vaoManager, IdString name, uint32 textureFlags,
TextureTypes::TextureTypes initialType,
TextureGpuManager *textureManager, VulkanWindow *window );
TextureGpuManager *textureManager, VulkanWindowSwapChainBased *window );
~VulkanTextureGpuWindow() override;

void setTextureType( TextureTypes::TextureTypes textureType ) override;
Expand Down
46 changes: 35 additions & 11 deletions RenderSystems/Vulkan/include/OgreVulkanWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,49 @@ namespace Ogre
{
class VulkanWindow : public Window
{
protected:
VulkanDevice *mDevice;

public:
VulkanWindow( const String &title, uint32 width, uint32 height, bool fullscreenMode );

void _setDevice( VulkanDevice *device );
void _initialize( TextureGpuManager *textureGpuManager ) override;
virtual void _initialize( TextureGpuManager *textureGpuManager,
const NameValuePairList *miscParams ) = 0;
};

class VulkanWindowNull : public VulkanWindow
{
public:
VulkanWindowNull( const String &title, uint32 width, uint32 height, bool fullscreenMode );

void destroy() override;
void reposition( int32 leftPt, int32 topPt ) override;
bool isClosed() const override;
void _setVisible( bool visible ) override;
bool isVisible() const override;
void setHidden( bool hidden ) override;
bool isHidden() const override;
void _initialize( TextureGpuManager *textureGpuManager,
const NameValuePairList *miscParams ) override;
void swapBuffers() override;
};

class VulkanWindowSwapChainBased : public VulkanWindow
{
public:
enum Backend
{
BackendX11 = 1u << 0u
};
enum SwapchainStatus
{
/// We already called VulkanWindow::acquireNextSwapchain.
/// We already called VulkanWindowSwapChainBased::acquireNextSwapchain.
///
/// Can only go into this state if we're coming from SwapchainReleased
SwapchainAcquired,
/// We already called VulkanWindow::getImageAcquiredSemaphore.
/// We already called VulkanWindowSwapChainBased::getImageAcquiredSemaphore.
/// Further calls to getImageAcquiredSemaphore will return null.
/// Ogre is rendering or intends to into this swapchain.
///
Expand All @@ -66,8 +97,6 @@ namespace Ogre
bool mHwGamma;
bool mClosed;

VulkanDevice *mDevice;

VkSurfaceKHR mSurfaceKHR;
VkSwapchainKHR mSwapchain;
FastArray<VkImage> mSwapchainImages;
Expand All @@ -89,16 +118,11 @@ namespace Ogre
void acquireNextSwapchain();

public:
VulkanWindow( const String &title, uint32 width, uint32 height, bool fullscreenMode );
~VulkanWindow() override;
VulkanWindowSwapChainBased( const String &title, uint32 width, uint32 height, bool fullscreenMode );
~VulkanWindowSwapChainBased() override;

void destroy() override;

void _setDevice( VulkanDevice *device );
void _initialize( TextureGpuManager *textureGpuManager ) override;
virtual void _initialize( TextureGpuManager *textureGpuManager,
const NameValuePairList *miscParams ) = 0;

/// Returns null if getImageAcquiredSemaphore has already been called during this frame
VkSemaphore getImageAcquiredSemaphore();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct ANativeWindow;

namespace Ogre
{
class _OgreVulkanExport VulkanAndroidWindow final : public VulkanWindow
class _OgreVulkanExport VulkanAndroidWindow final : public VulkanWindowSwapChainBased
{
ANativeWindow *mNativeWindow;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef uint32_t xcb_atom_t;

namespace Ogre
{
class _OgreVulkanExport VulkanXcbWindow : public VulkanWindow
class _OgreVulkanExport VulkanXcbWindow : public VulkanWindowSwapChainBased
{
xcb_connection_t *mConnection;
xcb_screen_t *mScreen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Copyright (c) 2000-present Torus Knot Software Ltd

namespace Ogre
{
class VulkanWin32Window final : public VulkanWindow
class VulkanWin32Window final : public VulkanWindowSwapChainBased
{
private:
HWND mHwnd; // Win32 Window handle
Expand Down
23 changes: 20 additions & 3 deletions RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,13 +954,30 @@ namespace Ogre
bool fullScreen,
const NameValuePairList *miscParams )
{
String windowType;
if( miscParams )
{
// Get variable-length params
NameValuePairList::const_iterator opt = miscParams->find( "windowType" );
if( opt != miscParams->end() )
windowType = opt->second;
}

VulkanWindow *win = nullptr;
if( windowType == "Null" )
{
win = OGRE_NEW VulkanWindowNull( name, width, height, fullScreen );
}
else
{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
VulkanWindow *win = OGRE_NEW VulkanWin32Window( name, width, height, fullScreen );
win = OGRE_NEW VulkanWin32Window( name, width, height, fullScreen );
#elif OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
VulkanWindow *win = OGRE_NEW VulkanAndroidWindow( name, width, height, fullScreen );
win = OGRE_NEW VulkanAndroidWindow( name, width, height, fullScreen );
#else
VulkanWindow *win = OGRE_NEW VulkanXcbWindow( name, width, height, fullScreen );
win = OGRE_NEW VulkanXcbWindow( name, width, height, fullScreen );
#endif
}
mWindows.insert( win );

if( !mInitialized )
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Vulkan/src/OgreVulkanTextureGpuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ namespace Ogre
}
}
//-----------------------------------------------------------------------------------
TextureGpu *VulkanTextureGpuManager::createTextureGpuWindow( VulkanWindow *window )
TextureGpu *VulkanTextureGpuManager::createTextureGpuWindow( VulkanWindowSwapChainBased *window )
{
return OGRE_NEW VulkanTextureGpuWindow( GpuPageOutStrategy::Discard, mVaoManager,
"RenderWindow", //
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Vulkan/src/OgreVulkanTextureGpuWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace Ogre
VulkanTextureGpuWindow::VulkanTextureGpuWindow(
GpuPageOutStrategy::GpuPageOutStrategy pageOutStrategy, VaoManager *vaoManager, IdString name,
uint32 textureFlags, TextureTypes::TextureTypes initialType, TextureGpuManager *textureManager,
VulkanWindow *window ) :
VulkanWindowSwapChainBased *window ) :
VulkanTextureGpuRenderTarget( pageOutStrategy, vaoManager, name, textureFlags, initialType,
textureManager ),
mWindow( window ),
Expand Down
Loading

0 comments on commit 10e32c8

Please sign in to comment.