apparent bug in D3D11RenderSystem Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


jwwalker
Goblin
Posts: 248
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 18

apparent bug in D3D11RenderSystem

Post by jwwalker »

In OgreD3D11RenderSystem.cpp, the first time you create a window, it sets a member variable mPrimaryWindow and then initializes some things like the hardware buffer manager. If you destroy that window, mPrimaryWindow get cleared. So the next time you try to create a window, the initialization tasks are done again, but that's a problem because the hardware buffer manager is supposed to be a singleton. Compare that to the Metal render system, which sets a member mInitialized the first time you create a window, and never clears it. I'd hesitate to try to concoct a pull request to fix it, as I know little about Ogre internals and nothing about Direct3D.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5436
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1343

Re: apparent bug in D3D11RenderSystem

Post by dark_sylinc »

"Working as intended".

Due to historical reasons back to D3D7 & GL; the first render window is special, so you can't easily destroy it as those APIs assume windows are tied to GPU devices.

D3D11, Metal & Vulkan went away with those assumptions but GL still does (except when using EGL headless extension only well supported on Linux).

Because D3D11 was based in our older D3D9 (which we no longer support); it has these oddities even though the underlying API doesn't have it anymore.

Because I wrote Metal from scratch, it seems like it survives destroying the first render window; but this isn't thoroughly tested.
As a rule of thumb try to keep the first render window alive at all times. This will ensure the highest cross platform, cross API compatibility.

A common workaround if this rule is problematic, is to created a 1x1 render window and then immediately hide it.

Eventually we'll fix this behavior (i.e. for GL we could implement the 1x1 hidden window ourselves as a workaround, and let the other APIs work fine) but it's not priority for us.

Cheers