Skip to content

Commit

Permalink
Merge branch 'vulkan-external-device'
Browse files Browse the repository at this point in the history
  • Loading branch information
darksylinc committed Jul 11, 2022
2 parents 3359ea1 + cce9a6a commit e1d6d13
Show file tree
Hide file tree
Showing 34 changed files with 1,072 additions and 74 deletions.
5 changes: 4 additions & 1 deletion OgreMain/include/OgrePlugin.h
Expand Up @@ -41,6 +41,9 @@ namespace Ogre

struct AbiCookie;

/// Name / value parameter pair (first = name, second = value)
typedef StdMap<String, String> NameValuePairList;

/** Class defining a generic OGRE plugin.
@remarks
OGRE is very plugin-oriented and you can customise much of its behaviour
Expand Down Expand Up @@ -99,7 +102,7 @@ namespace Ogre
operations that would create rendersystem-specific objects at this stage,
that should be done in initialise().
*/
virtual void install() = 0;
virtual void install( const NameValuePairList *options ) = 0;

/** Perform any tasks the plugin needs to perform on full system
initialisation.
Expand Down
6 changes: 4 additions & 2 deletions OgreMain/include/OgreRoot.h
Expand Up @@ -728,8 +728,10 @@ namespace Ogre
It should also implement dllStopPlugin (see Root::unloadPlugin)
@param pluginName Name of the plugin library to load
@param bOptional When true, we will skip it if it fails to initialize
@param options Options to pass onto the loading plugin. Can be nullptr
*/
void loadPlugin( const String &pluginName, const bool bOptional );
void loadPlugin( const String &pluginName, const bool bOptional,
const NameValuePairList *options );

/** Manually unloads a Plugin contained in a DLL / DSO.
@remarks
Expand All @@ -752,7 +754,7 @@ namespace Ogre
loadPlugin, since the DLL function dllStartPlugin should call this
method when the DLL is loaded.
*/
void installPlugin( Plugin *plugin );
void installPlugin( Plugin *plugin, const NameValuePairList *options );

/** Uninstall an existing plugin.
@remarks
Expand Down
15 changes: 8 additions & 7 deletions OgreMain/src/OgreRoot.cpp
Expand Up @@ -127,7 +127,7 @@ namespace Ogre
return ( *msSingleton );
}

typedef void ( *DLL_START_PLUGIN )();
typedef void ( *DLL_START_PLUGIN )( const NameValuePairList * );
typedef void ( *DLL_STOP_PLUGIN )();

//-----------------------------------------------------------------------
Expand Down Expand Up @@ -1206,15 +1206,15 @@ namespace Ogre
const StringVector pluginList = cfg.getMultiSetting( "PluginOptional" );
for( StringVector::const_iterator it = pluginList.begin(); it != pluginList.end(); ++it )
{
loadPlugin( pluginDir + ( *it ), true );
loadPlugin( pluginDir + ( *it ), true, nullptr );
}
}
{
// Then load non-optional plugins (which tend to depend on RenderSystems)
const StringVector pluginList = cfg.getMultiSetting( "Plugin" );
for( StringVector::const_iterator it = pluginList.begin(); it != pluginList.end(); ++it )
{
loadPlugin( pluginDir + ( *it ), false );
loadPlugin( pluginDir + ( *it ), false, nullptr );
}
}
}
Expand Down Expand Up @@ -1411,7 +1411,7 @@ namespace Ogre
return success;
}
//---------------------------------------------------------------------
void Root::installPlugin( Plugin *plugin )
void Root::installPlugin( Plugin *plugin, const NameValuePairList *options )
{
LogManager::getSingleton().logMessage( "Installing plugin: " + plugin->getName() );

Expand All @@ -1421,7 +1421,7 @@ namespace Ogre
if( testAbiCookie( abiCookie, false ) )
{
mPlugins.push_back( plugin );
plugin->install();
plugin->install( options );

// if rendersystem is already initialised, call rendersystem init too
if( mIsInitialised )
Expand Down Expand Up @@ -1451,7 +1451,8 @@ namespace Ogre
LogManager::getSingleton().logMessage( "Plugin successfully uninstalled" );
}
//-----------------------------------------------------------------------
void Root::loadPlugin( const String &pluginName, const bool bOptional )
void Root::loadPlugin( const String &pluginName, const bool bOptional,
const NameValuePairList *options )
{
#if OGRE_PLATFORM != OGRE_PLATFORM_EMSCRIPTEN
// Load plugin library
Expand Down Expand Up @@ -1481,7 +1482,7 @@ namespace Ogre
try
{
// This must call installPlugin
pFunc();
pFunc( options );
}
catch( Exception &e )
{
Expand Down
2 changes: 1 addition & 1 deletion PlugIns/ParticleFX/include/OgreParticleFXPlugin.h
Expand Up @@ -44,7 +44,7 @@ namespace Ogre
const String &getName() const override;

/// @copydoc Plugin::install
void install() override;
void install( const NameValuePairList *options ) override;

/// @copydoc Plugin::initialise
void initialise() override;
Expand Down
5 changes: 3 additions & 2 deletions PlugIns/ParticleFX/src/OgreParticleFX.cpp
Expand Up @@ -38,10 +38,11 @@ namespace Ogre
{
static ParticleFXPlugin *plugin;
//-----------------------------------------------------------------------
extern "C" void _OgreParticleFXExport dllStartPlugin( void ) noexcept( false )
extern "C" void _OgreParticleFXExport
dllStartPlugin( const NameValuePairList *options ) noexcept( false )
{
plugin = OGRE_NEW ParticleFXPlugin();
Root::getSingleton().installPlugin( plugin );
Root::getSingleton().installPlugin( plugin, options );
}
//-----------------------------------------------------------------------
extern "C" void _OgreParticleFXExport dllStopPlugin( void )
Expand Down
2 changes: 1 addition & 1 deletion PlugIns/ParticleFX/src/OgreParticleFXPlugin.cpp
Expand Up @@ -56,7 +56,7 @@ namespace Ogre
//---------------------------------------------------------------------
const String &ParticleFXPlugin::getName() const { return sPluginName; }
//---------------------------------------------------------------------
void ParticleFXPlugin::install()
void ParticleFXPlugin::install( const NameValuePairList * )
{
// -- Create all new particle emitter factories --
ParticleEmitterFactory *pEmitFact;
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Direct3D11/include/OgreD3D11Plugin.h
Expand Up @@ -43,7 +43,7 @@ namespace Ogre
const String &getName() const override;

/// @copydoc Plugin::install
void install() override;
void install( const NameValuePairList *options ) override;

/// @copydoc Plugin::initialise
void initialise() override;
Expand Down
8 changes: 2 additions & 6 deletions RenderSystems/Direct3D11/src/OgreD3D11EngineDll.cpp
Expand Up @@ -34,14 +34,10 @@ namespace Ogre
{
static D3D11Plugin *plugin;

# if __cplusplus >= 201103L
extern "C" void _OgreD3D11Export dllStartPlugin( void ) noexcept( false )
# else
extern "C" void _OgreD3D11Export dllStartPlugin( void ) throw( Exception )
# endif
extern "C" void _OgreD3D11Export dllStartPlugin( const NameValuePairList *options ) noexcept( false )
{
plugin = new D3D11Plugin();
Root::getSingleton().installPlugin( plugin );
Root::getSingleton().installPlugin( plugin, options );
}

extern "C" void _OgreD3D11Export dllStopPlugin( void )
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Direct3D11/src/OgreD3D11Plugin.cpp
Expand Up @@ -38,7 +38,7 @@ namespace Ogre
//---------------------------------------------------------------------
const String &D3D11Plugin::getName() const { return sPluginName; }
//---------------------------------------------------------------------
void D3D11Plugin::install()
void D3D11Plugin::install( const NameValuePairList * )
{
// Create the DirectX 11 rendering api
mRenderSystem = new D3D11RenderSystem();
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/GL3Plus/include/OgreGL3PlusPlugin.h
Expand Up @@ -43,7 +43,7 @@ namespace Ogre
const String &getName() const override;

/// @copydoc Plugin::install
void install() override;
void install( const NameValuePairList *options ) override;

/// @copydoc Plugin::initialise
void initialise() override;
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/GL3Plus/include/OgreGL3PlusRenderSystem.h
Expand Up @@ -192,7 +192,7 @@ namespace Ogre

public:
// Default constructor / destructor
GL3PlusRenderSystem();
GL3PlusRenderSystem( const NameValuePairList *options );
~GL3PlusRenderSystem() override;

friend class ShaderGeneratorTechniqueResolverListener;
Expand Down
5 changes: 3 additions & 2 deletions RenderSystems/GL3Plus/src/OgreGL3PlusEngineDll.cpp
Expand Up @@ -35,10 +35,11 @@ namespace Ogre
{
static GL3PlusPlugin *plugin;

extern "C" void _OgreGL3PlusExport dllStartPlugin( void ) noexcept( false )
extern "C" void _OgreGL3PlusExport
dllStartPlugin( const NameValuePairList *options ) noexcept( false )
{
plugin = OGRE_NEW GL3PlusPlugin();
Root::getSingleton().installPlugin( plugin );
Root::getSingleton().installPlugin( plugin, options );
}

extern "C" void _OgreGL3PlusExport dllStopPlugin( void )
Expand Down
4 changes: 2 additions & 2 deletions RenderSystems/GL3Plus/src/OgreGL3PlusPlugin.cpp
Expand Up @@ -39,9 +39,9 @@ namespace Ogre
//---------------------------------------------------------------------
const String &GL3PlusPlugin::getName() const { return sPluginName; }
//---------------------------------------------------------------------
void GL3PlusPlugin::install()
void GL3PlusPlugin::install( const NameValuePairList *options )
{
mRenderSystem = OGRE_NEW GL3PlusRenderSystem();
mRenderSystem = OGRE_NEW GL3PlusRenderSystem( options );

Root::getSingleton().addRenderSystem( mRenderSystem );
}
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/GL3Plus/src/OgreGL3PlusRenderSystem.cpp
Expand Up @@ -158,7 +158,7 @@ namespace Ogre
ogreGlObjectLabel( identifier, name, (GLsizei)label.size(), label.c_str() );
}

GL3PlusRenderSystem::GL3PlusRenderSystem() :
GL3PlusRenderSystem::GL3PlusRenderSystem( const NameValuePairList *options ) :
mBlendChannelMask( HlmsBlendblock::BlendChannelAll ),
mDepthWrite( true ),
mScissorsEnabled( false ),
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Metal/include/OgreMetalPlugin.h
Expand Up @@ -46,7 +46,7 @@ namespace Ogre
const String &getName() const override;

/// @copydoc Plugin::install
void install() override;
void install( const NameValuePairList *options ) override;

/// @copydoc Plugin::initialise
void initialise() override;
Expand Down
8 changes: 2 additions & 6 deletions RenderSystems/Metal/src/OgreMetalEngineDll.mm
Expand Up @@ -37,14 +37,10 @@ of this software and associated documentation files (the "Software"), to deal
{
static MetalPlugin *plugin;

# if __cplusplus >= 201103L
extern "C" void _OgreMetalExport dllStartPlugin() noexcept( false )
# else
extern "C" void _OgreMetalExport dllStartPlugin() throw( Exception )
# endif
extern "C" void _OgreMetalExport dllStartPlugin( const NameValuePairList *options ) noexcept( false )
{
plugin = OGRE_NEW MetalPlugin();
Root::getSingleton().installPlugin( plugin );
Root::getSingleton().installPlugin( plugin, options );
}

extern "C" void _OgreMetalExport dllStopPlugin()
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Metal/src/OgreMetalPlugin.mm
Expand Up @@ -44,7 +44,7 @@ of this software and associated documentation files (the "Software"), to deal
//---------------------------------------------------------------------
const String &MetalPlugin::getName() const { return sPluginName; }
//---------------------------------------------------------------------
void MetalPlugin::install()
void MetalPlugin::install( const NameValuePairList * )
{
mRenderSystem = OGRE_NEW MetalRenderSystem();

Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/NULL/include/OgreNULLPlugin.h
Expand Up @@ -44,7 +44,7 @@ namespace Ogre
const String &getName() const override;

/// @copydoc Plugin::install
void install() override;
void install( const NameValuePairList *options ) override;

/// @copydoc Plugin::initialise
void initialise() override;
Expand Down
4 changes: 2 additions & 2 deletions RenderSystems/NULL/src/OgreNULLEngineDll.cpp
Expand Up @@ -36,10 +36,10 @@ namespace Ogre
{
static NULLPlugin *plugin;

extern "C" void _OgreNULLExport dllStartPlugin( void ) noexcept( false )
extern "C" void _OgreNULLExport dllStartPlugin( const NameValuePairList *options ) noexcept( false )
{
plugin = OGRE_NEW NULLPlugin();
Root::getSingleton().installPlugin( plugin );
Root::getSingleton().installPlugin( plugin, options );
}

extern "C" void _OgreNULLExport dllStopPlugin( void )
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/NULL/src/OgreNULLPlugin.cpp
Expand Up @@ -39,7 +39,7 @@ namespace Ogre
//---------------------------------------------------------------------
const String &NULLPlugin::getName() const { return sPluginName; }
//---------------------------------------------------------------------
void NULLPlugin::install()
void NULLPlugin::install( const NameValuePairList * )
{
mRenderSystem = OGRE_NEW NULLRenderSystem();

Expand Down
40 changes: 40 additions & 0 deletions RenderSystems/Vulkan/include/OgreVulkanDevice.h
Expand Up @@ -39,6 +39,38 @@ THE SOFTWARE.

namespace Ogre
{
/// Use it to pass an external instance
///
/// We will verify if the layers and extensions you claim
/// were enabled are actually supported.
///
/// This is so because in Qt you can request these layers/extensions
/// but you get no feedback from Qt whether they were present and
/// thus successfully enabled.
///
/// However if the instance actually supports the layer/extension
/// you requested but the third party library explicitly chose not to
/// enable it for any random reason, then we will wrongly think
/// it's enabled / present.
struct VulkanExternalInstance
{
VkInstance instance;
FastArray<VkLayerProperties> instanceLayers;
FastArray<VkExtensionProperties> instanceExtensions;
};

/// Use it to pass an external device
///
/// See VulkanExternalInstance on extensions verification.
struct VulkanExternalDevice
{
VkPhysicalDevice physicalDevice;
VkDevice device;
FastArray<VkExtensionProperties> deviceExtensions;
VkQueue graphicsQueue;
VkQueue presentQueue;
};

struct _OgreVulkanExport VulkanDevice
{
struct SelectedQueue
Expand Down Expand Up @@ -88,6 +120,8 @@ namespace Ogre

uint32 mSupportedStages;

bool mIsExternal;

static void destroyQueues( FastArray<VulkanQueue> &queueArray );

void findGraphicsQueue( FastArray<uint32> &inOutUsedQueueCount );
Expand All @@ -99,6 +133,8 @@ namespace Ogre

public:
VulkanDevice( VkInstance instance, uint32 deviceIdx, VulkanRenderSystem *renderSystem );
VulkanDevice( VkInstance instance, const VulkanExternalDevice &externalDevice,
VulkanRenderSystem *renderSystem );
~VulkanDevice();

protected:
Expand All @@ -111,8 +147,12 @@ namespace Ogre
PFN_vkDebugReportCallbackEXT debugCallback,
RenderSystem *renderSystem );

static void addExternalInstanceExtensions( FastArray<VkExtensionProperties> &extensions );

protected:
void createPhysicalDevice( uint32 deviceIdx );

public:
void createDevice( FastArray<const char *> &extensions, uint32 maxComputeQueues,
uint32 maxTransferQueues );

Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Vulkan/include/OgreVulkanPlugin.h
Expand Up @@ -43,7 +43,7 @@ namespace Ogre
const String &getName() const override;

/// @copydoc Plugin::install
void install() override;
void install( const NameValuePairList *options ) override;

/// @copydoc Plugin::initialise
void initialise() override;
Expand Down
1 change: 1 addition & 0 deletions RenderSystems/Vulkan/include/OgreVulkanQueue.h
Expand Up @@ -210,6 +210,7 @@ namespace Ogre
~VulkanQueue();

void setQueueData( VulkanDevice *owner, QueueFamily family, uint32 familyIdx, uint32 queueIdx );
void setExternalQueue( VulkanDevice *owner, QueueFamily family, VkQueue queue );

void init( VkDevice device, VkQueue queue, VulkanRenderSystem *renderSystem );
void destroy();
Expand Down

0 comments on commit e1d6d13

Please sign in to comment.