Page 1 of 1

Can I use Vulkan/DirectX Directly?

Posted: Tue Mar 19, 2024 10:05 pm
by kariem2k

If I have a library that uses Vulkan and DirectX. Until I port it to ogre. Can I use these libraries to render directly to Vulkan or DirectX within Ogre?

I see this but is it intended for that usage?

https://github.com/OGRECave/ogre-next/b ... ternal.cpp

Thanks


Re: Can I use Vulkan/DirectX Directly?

Posted: Thu Mar 21, 2024 3:14 pm
by dark_sylinc

Hi!

Yes, you can.
And no, the sample there is meant for cases where you have multiple libraries, and that library insists on creating the Vulkan device (thus you give OgreNext that device instead of having OgreNext create another one).

As to how to use D3D11/Vk directly:

Code: Select all

// To get the proper typedef for ID3D11DeviceN
#include <OgreD3D11Prerequisites.h>
// To get VulkanQueue struct which contains everything you need to interact w/ Vulkan directly
#include <OgreVulkanDevice.h>

ID3D11DeviceN *d3d11Device = 0;
renderSystem->getCustomAttribute( "D3DDEVICE", &d3d11Device );

// Vulkan
VulkanQueue *vulkanQueue = 0;
renderSystem->getCustomAttribute( "VulkanQueue", &vulkanQueue );

There's also various other parts that have their own getCustomAttribute you can retrieve.

For example TextureGpu::getCustomAttribute( TextureGpu::msFinalTextureBuffer, &res ) can be used to retrieve the internal D3D11Resource or VkImage.

Working with Vulkan directly may be harder than with D3D11, because Vulkan has explicit synchronization and you must make sure you issued the proper barriers and resources are in the proper layout. Vulkan Validation layers can help you with that, but after all it is a hard topic.


Re: Can I use Vulkan/DirectX Directly?

Posted: Thu Mar 21, 2024 3:33 pm
by kariem2k

Thank you very much for your reply. Yeah, maybe I will just start with DX. Are there any calls that I need to make to invalidate any sort of cached states, before I issue my rendering?

Thanks


Re: Can I use Vulkan/DirectX Directly?

Posted: Thu Mar 21, 2024 3:45 pm
by dark_sylinc

Hi!

I just updated my answer with Vulkan counterparts (I just fixed it for 3.0 and master branches).

kariem2k wrote: Thu Mar 21, 2024 3:33 pm

Are there any calls that I need to make to invalidate any sort of cached states, before I issue my rendering?

We don't do state caching in OgreNext since we moved to PSOs in OgreNext 2.2.

Having that said, Vulkan for example won't actually submit anything to GPU until mActiveDevice->commitAndNextCommandBuffer( SubmissionType::FlushOnly /* or greater */ ); gets called, which you can force with renderSystem->flushCommands().

The details with each API can vary based on what you're doing.

Normally OgreNext has the following anatomy:

Code: Select all

renderSystem->_beginFrameOnce();
renderSystem->_beginUpdate( true );
for( every workspace )
{
  renderSystem->_beginFrame();
  // render stuff
  renderSystem->_endFrame();
}
renderSystem->_update();
// Swap all windows
renderSystem->_endFrameOnce();

Thus what you want to do is probably right before/after _endFrame() or before/after_endFrameOnce().


Re: Can I use Vulkan/DirectX Directly?

Posted: Fri Mar 22, 2024 6:15 pm
by kariem2k

That was fast.

Thank you very much