[2.1]Strange Bug with multiple workspaces and scene managers

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


Post Reply
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

[2.1]Strange Bug with multiple workspaces and scene managers

Post by SolarPortal »

Hey,
wow, its been a confusing couple of days with a few bugs that just don't seem to be right in the renderer. Note that all this worked fine back on 1.9 :)
It will be difficult to show code as to what's happening as we have a large code base, but i will describe the best i can.

So i have a 3 main topics in this thread:

1) Strange bugs happening when using multiple workspaces and scene managers.
I have several workspaces each with their own sceneManager. Everything is under 1 Ogre::Root as you would expect but i have tried to seperate all of them completely with their own workspace, scenemanager and renderwindows to work with.
Here is what workspace is used for:
  • Main window : This is our main WYSIWYG rendering window , it uses Items and all supporting 2.1 techniques.
  • Mesh Editor : This is a second workspace and uses a second sceneManager. This uses a v1 pipeline of entity but uses datablocks
  • GUI Editor : This is a third workspace and uses a third sceneManager. This is used to display only LibRocket only and no meshes
Some weird things happening are:
  • v2 ManualObject : A manual object is used to generate a line bounding box around meshes (one that does not adhere to AABB but OABB) in the main rendering window.
    When a second editor is opened e.g. mesh or gui with new workspace, then the manualobject ceases to be rendered again in the main renderer but does not crash.
    However, if you have a manualobject inside each workspaces scenemanager, then it renders fine in all of them... :?:
  • In the Mesh editor; if opened as the second workspace has a strange batching sort of issue. If i add 2 seperate v1 entities with their own nodes. If the second entity has an old v1 skeleton, then it attaches the previous created entity onto the character which then follows a bone and resets the material to that of the mesh. It looks as if it becomes a submesh. Strange... I can provide meshes where necessary.
  • In the GUI editor if opened as the second workspace, it has an issue with the librocket port where activating the main workspace will sometimes clear the librocket screen on the gui workspace. Just wondering if this is to do with the renderSystem->functions()
It feels like even though i have separated all the workspaces with their own scene managers, its as if they are still linked and affecting one another.
I will be making a simpler demo tomorrow that hopefully will show the same bugs and will record a video if possible, but i just had to ask and wondered if anyone had any clues to fixing this especially since this is
possibly an untested case of 2.1 where multiple workspaces with seperate sceneManagers are used.

2) Creating a workspace, adding entity, set material and write rendertarget to file. Clear up workspace after.
How can i update a workspace in the same frame to show the scene on an rendertarget when writing it to file.
I currently have to call renderOneFrame to get the rendertarget to show it correctly before writing otherwise it comes out as a black image; but if rendered the frame after it shows the model correctly.

Here is my compositor node for passing the render texture:

Code: Select all

Ogre::CompositorNodeDef * ThumbnailGenerator::getCompositorNode(std::string nodeDefName, Ogre::uint32 visFlag, Ogre::uint8 firstRQ, Ogre::uint8 lastRQ )
{
	Ogre::CompositorManager2 *compositorManager = Ogre::Root::getSingleton().getCompositorManager2();
	Ogre::CompositorNodeDef *nodeDef = NULL;

	// First create a compositor node that will render the RTT as we need
	if (!compositorManager->hasNodeDefinition(nodeDefName))
	{
		Ogre::CompositorNodeDef *nodeDef = compositorManager->addNodeDefinition(nodeDefName);

		//Input channels
		nodeDef->addTextureSourceName("texture", 0, Ogre::TextureDefinitionBase::TEXTURE_INPUT);
		nodeDef->setNumTargetPass(1);
		{
			Ogre::CompositorTargetDef *targetDef = nodeDef->addTargetPass("texture");
			targetDef->setNumPasses(2);
			{// Create the clear pass

				Ogre::CompositorPassClearDef *passClear = static_cast<Ogre::CompositorPassClearDef*>(targetDef->addPass(Ogre::PASS_CLEAR));
				passClear->mColourValue = Ogre::ColourValue(0.0, 0.0, 0.0, 1.0); // Set the target background colour
			}

			{// Now add the render scene pass and disable all overlays from being rendered.
				Ogre::CompositorPassSceneDef *passScene = static_cast<Ogre::CompositorPassSceneDef*>(targetDef->addPass(Ogre::PASS_SCENE));
				passScene->mIncludeOverlays = false;
			}
		}

		//Output channels
		nodeDef->setNumOutputChannels(0);
	}else{
		nodeDef = (Ogre::CompositorNodeDef*)compositorManager->getNodeDefinition(nodeDefName);
	}

	return nodeDef;
}

Code: Select all

Ogre::String  ThumbnailGenerator::GenerateMeshThumbnail(Ogre::String meshName, Ogre::String filePath, Ogre::String fileName, int iconSize)
{
	// Create render target texture
 
	// Create new scenemanger, camera, entity and lights

	// ======================================================================================================================
	// Render To Image and save to file
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation(filePath, "FileSystem", "EditorThumbnails");
	Ogre::CompositorNodeDef *comNodeDef = getCompositorNode("Thumnail_Mesh_RenderNode");
	Ogre::CompositorWorkspace* comWorkspace = createThumnailWorkspace("Thumnail_Mesh_Workspace", "Thumnail_Mesh_RenderNode", thumb_SceneMgr, renderCamera, renderTexture);
	
	// Render the frame to fill the rendertarget. --- |||| Need better method for this
	Ogre::Root::getSingletonPtr()->renderOneFrame();

	// Write the contents of the render target to file.
	renderTarget->writeContentsToFile(filePath + "/" + fileName);

	// Clean up - Remove workspace, entities, lights, camera, scenemanager etc...
}
Q) Is there a better method than rendering all workspaces and scene managers?

3) Changing a reflection texture of pbs HLMS is changing the SkyPostProcess...
When changing a reflection texture on some pbs materials, the SkyPostProcess material also gets written to somehow..
Also SkyPostProcess does not work in DirectX11 HLSL. Shows as black background.

Anyway, Thanks again for your time :)

Edit: Added 1 extra thing at the bottom :)
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by al2950 »

Just heading to bed, so have not taken in your full post to understand and comment. However your very last point about the sky postprocess in Dx has been fixed in one of my pull requests, but the PR will not be accepted yet as it has a number of issues, but you can see the fix here;
https://bitbucket.org/al2950/ogre-2.x-u ... 96?at=v2-1
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by SolarPortal »

@al2950, thanks. I used the code and the renderer stopped due to an error, removing it made the renderer boot again. I tried "cubic_texture" at the start with "combinedUVW" before the gamma with no results and still get a black skybox postFX. Thanks again for the help though. ;)

On the first parts i mentioned in the post, it seems swapping over to DX11 actually has fixed some of the problems i mentioned above so they must be mostly related to opengl, perhaps a shader error or memory limit...
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5588
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by dark_sylinc »

My head is spinning from trying to understand the problems. Please excuse me if I didn't get it correctly. It will probably take a while to grok everything.
SolarPortal wrote: Some weird things happening are:
  • v2 ManualObject : A manual object is used to generate a line bounding box around meshes (one that does not adhere to AABB but OABB) in the main rendering window.
    When a second editor is opened e.g. mesh or gui with new workspace, then the manualobject ceases to be rendered again in the main renderer but does not crash.
    However, if you have a manualobject inside each workspaces scenemanager, then it renders fine in all of them... :?:
Time and again I regret accepting the Pull Request that added v2 ManualObject. The v2 version of ManualObject has been a community contribution. It behaves differently from the v1 version, and is aimed at the very newcomers who could struggle on how to create a new object.

We strongly recommend generating your Vaos directly (see DynamicGeometry & CustomRenderable samples) rather than using ManualObjects.
In the past, dealing with Vertex Buffers was a convoluted PITA, so ManualObjects made sense. In Ogre 2.1; dealing with buffers is much easier, and thus there's no excuse to resort to ManualObjects.
SolarPortal wrote:
  • In the Mesh editor; if opened as the second workspace has a strange batching sort of issue. If i add 2 seperate v1 entities with their own nodes. If the second entity has an old v1 skeleton, then it attaches the previous created entity onto the character which then follows a bone and resets the material to that of the mesh. It looks as if it becomes a submesh. Strange... I can provide meshes where necessary.
That has my head spinning. Don't understand what you're doing there. It does sound though, like a problem with PBS not dealing with texture buffer offsets correctly. A video could help understanding what's going on.
If you could recreate this behavior in one of the samples that would be fantastic.
SolarPortal wrote: [*] In the GUI editor if opened as the second workspace, it has an issue with the librocket port where activating the main workspace will sometimes clear the librocket screen on the gui workspace. Just wondering if this is to do with the renderSystem->functions()[/list]
Very likely.
SolarPortal wrote: It feels like even though i have separated all the workspaces with their own scene managers, its as if they are still linked and affecting one another.
You're not wrong. For performance reasons be advance the 'frame' cursor of each dynamic buffer at the end of all compositor's updates, and we try to save the state of the API to avoid unnecessary setting again. Theoretically between two independent frames we should flush correctly the API state, but we might have missed something, or librocket could be screwing things up. Or perhaps v2 ManualObject.
The Hlms (shaders) & VaoManager (buffers) are shared by SceneManagers & Workspaces. One screw up in the middle would cascade into the subsequent workspaces/scenemanagers.
Or perhaps you triggered a hidden bug from using many workspaces (something it's not common to see).
I will be making a simpler demo tomorrow that hopefully will show the same bugs and will record a video if possible, but i just had to ask and wondered if anyone had any clues to fixing this especially since this is
possibly an untested case of 2.1 where multiple workspaces with seperate sceneManagers are used.
Very likely. I have tested multiple workspaces in the past, but I've never been too much of a fan of separate SceneManagers. That's likely the biggest suspect.
2) Creating a workspace, adding entity, set material and write rendertarget to file. Clear up workspace after.
How can i update a workspace in the same frame to show the scene on an rendertarget when writing it to file.
I currently have to call renderOneFrame to get the rendertarget to show it correctly before writing otherwise it comes out as a black image; but if rendered the frame after it shows the model correctly.
What are you trying to do? I didn't understand.
SolarPortal wrote:On the first parts i mentioned in the post, it seems swapping over to DX11 actually has fixed some of the problems i mentioned above so they must be related to opengl, perhaps a shader error or memory limit...
Could I ask you to move to v2.1-pso, commit c3e5bde1756ab9c97f789c5cc261ff8fe57bca22. It's quite stable (unless you try to use Compute Shaders, or the terrain sample). The new PSO system has fixed a lot of very edge cases where we didn't flush the API correctly, and I suspect you're running into those edge cases. Perhaps moving to the v2.1-pso branch might end up fixing most of your bugs.
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by SolarPortal »

Thanks for the reply dark_sylinc :D

I will attempt to remove all v2 ManualObjects from our codebase and move to CustomRenderables instead and see if this resolves this issue :)
That has my head spinning. Don't understand what you're doing there. It does sound though, like a problem with PBS not dealing with texture buffer offsets correctly. A video could help understanding what's going on.
If you could recreate this behavior in one of the samples that would be fantastic.
Sure, i will see if i can put something together in a sample and record a video of it happening in the engine. I don't have a lot of time this weekend but i will try my best to get it to you :)
The Hlms (shaders) & VaoManager (buffers) are shared by SceneManagers & Workspaces. One screw up in the middle would cascade into the subsequent workspaces/scenemanagers.
Or perhaps you triggered a hidden bug from using many workspaces (something it's not common to see).
Yes, this sounds like a possibility, it is strange how OpenGL suffers more from these errors than DX11, like librocket is fine in dx11 and doesnt show the same errors.
Perhaps this is the same reason changing certain reflection textures on PBS materials changes the SkyPostProcess texture at times which i find quite weird.
Very likely. I have tested multiple workspaces in the past, but I've never been too much of a fan of separate SceneManagers. That's likely the biggest suspect.
I mainly use a separate scene manager due to the the removal of the specialrenderqueues that existed from the older v1.x and i also experienced crashes when using a single one across multi workspaces
when the v2 manual object broke as described before. Which is quite clear not to use now... :lol:

In regards to topic 2) i am trying to take a thumbnail picture of a singular asset in the scene and render the texture to harddrive all in one frame.
In order for the workspaces to update the rendertarget i have to call renderoneframe to get the items(not entities lol :P) to show in the rendertarget before i write it too file as seen in the temp code, if it do not, the saved out image file returns a black background from the clear pass. It seems 2.1 requires the frame to be advanced before it will show the items in the rendertarget. It was originaly upgraded from an RTT system which worked all in one frame.
I can't show the code here, but i will pm you the code for this so you can see what happens :)
Could I ask you to move to v2.1-pso, commit c3e5bde1756ab9c97f789c5cc261ff8fe57bca22. It's quite stable (unless you try to use Compute Shaders, or the terrain sample). The new PSO system has fixed a lot of very edge cases where we didn't flush the API correctly, and I suspect you're running into those edge cases. Perhaps moving to the v2.1-pso branch might end up fixing most of your bugs.
Absolutely, i will move onto this version asap and report back to you.

Thanks again. I know some bugs may seem weird, but we are shifting a very large game engine that was stable to 2.1 and most is going well, but i am experiencing some weird issues compared to 1.9
Happy to help ironing these bugs out though as we will all benefit :D
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5588
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by dark_sylinc »

SolarPortal wrote:
Very likely. I have tested multiple workspaces in the past, but I've never been too much of a fan of separate SceneManagers. That's likely the biggest suspect.
I mainly use a separate scene manager due to the the removal of the specialrenderqueues that existed from the older v1.x and i also experienced crashes when using a single one across multi workspaces
Personally, in order to keep it as "one scene manager", to reserve yourself some RenderQueue IDs. For example RQ IDs 0-15 would be your regular scene, RQ IDs 16-31 would be your editor's, RQ ID's 32-63 would be used to render your custom geometry.

We treat RQ IDs separately. So if you've order Ogre to render ID range [0; 16); we won't have any performance degradation because you've got a hundred thousands objects in render queue 20.
In regards to topic 2) i am trying to take a thumbnail picture of a singular asset in the scene and render the texture to harddrive all in one frame.
In order for the workspaces to update the rendertarget i have to call renderoneframe to get the items(not entities lol :P) to show in the rendertarget before i write it too file as seen in the temp code, if it do not, the saved out image file returns a black background from the clear pass. It seems 2.1 requires the frame to be advanced before it will show the items in the rendertarget. It was originaly upgraded from an RTT system which worked all in one frame.
I can't show the code here, but i will pm you the code for this so you can see what happens :)
I see. Perhaps I should try to reproduce this myself. I fear some of our triple buffer scheme could be causing issues.
Thanks again. I know some bugs may seem weird, but we are shifting a very large game engine that was stable to 2.1 and most is going well, but i am experiencing some weird issues compared to 1.9
I'm glad and sad to hear that. Your engine surely is putting some stress test to our v2.1.
Let me know how the 2.1-pso turned out.
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by SolarPortal »

sorry for the late reply, been a busy weekend.

Thanks for the advice, i will try using one sceneManager and limit what is getting rendered on the amount of queues.

So i am trying out the ogre3d "v2.1-pso" branch not the latest "...-multitarget" and have encountered a couple of things so far:
1) the clone is not merged from v2.1, so this is been changed manually in source but not a big deal though lol :P

2) I have noticed that the pso has changed the hlmsCache and these functions no longer exist:

Code: Select all

        /// @See HlmsMacroblock
        virtual void _setHlmsMacroblock( const HlmsMacroblock *macroblock ) = 0;

        /// @See HlmsBlendblock
        virtual void _setHlmsBlendblock( const HlmsBlendblock *blendblock ) = 0;

        /// @See HlmsCache
        virtual void _setProgramsFromHlms( const HlmsCache *hlmsCache ) = 0;
I have changed my code to this and wanted to know if it correct. If not can you give an example.

Code: Select all

	Ogre::HlmsPso pso;
	pso.initialize();
	pso.vertexShader = vertexProgram;
	pso.pixelShader = pixelProgram;
	pso.macroblock = mMaterial->getTechnique(0)->getPass(0)->getMacroblock();
	pso.blendblock = mMaterial->getTechnique(0)->getPass(0)->getBlendblock();

	render_system->_setPipelineStateObject(&pso);

	// Bind the necessary shader settings to the Vertex Shader to send in the transform matrix information.
	Ogre::GpuProgramParametersSharedPtr vsParams = pso.vertexShader->getDefaultParameters();
	vsParams->setNamedConstant("transformMat", projection_matrix * transform);
	render_system->bindGpuProgramParameters(Ogre::GPT_VERTEX_PROGRAM, vsParams, Ogre::GPV_ALL);

	// Prepare the render system
	render_system->_render(ogre3d_geometry->render_operation);
The code used to be:

Code: Select all

	Ogre::HlmsCache hlmsCache;
	hlmsCache.vertexShader = vertexProgram;
	hlmsCache.pixelShader = pixelProgram;
	hlmsCache.type = Ogre::HlmsTypes::HLMS_LOW_LEVEL;
	render_system->_setProgramsFromHlms(&hlmsCache);

	// Bind the necessary shader settings to the Vertex Shader to send in the transform matrix information.
	Ogre::GpuProgramParametersSharedPtr vsParams = hlmsCache.vertexShader->getDefaultParameters();
	vsParams->setNamedConstant("transformMat", projection_matrix * transform);
	render_system->bindGpuProgramParameters(Ogre::GPT_VERTEX_PROGRAM, vsParams, Ogre::GPV_ALL);

	// Set the macro and blending information for the HLMS system.
	render_system->_setHlmsMacroblock(mMaterial->getTechnique(0)->getPass(0)->getMacroblock());
	render_system->_setHlmsBlendblock(mMaterial->getTechnique(0)->getPass(0)->getBlendblock());

	// Prepare the render system
	render_system->_render(ogre3d_geometry->render_operation);
There is also a change to "Ogre::v1::RenderOperation::OT_LINE_LIST" to "Ogre::OperationType::OT_LINE_LIST" and same with the other enums.
I am creating a define at many places in code to keep the older 2.1 library running too so its a bit slower to get running lol :)

Thanks again, i will keep you informed the progress and keep it up the good work! :D
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5588
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by dark_sylinc »

Hi!

Your change to PSOs is incorrect. It may just happen to run because of luck in some RenderSystems. PSOs must be initialized via _hlmsPipelineStateObjectCreated & destroyed via _hlmsPipelineStateObjectDestroyed. Of course doing this per frame would obliterate performance; so you should keep the PSO alive until it's no longer needed or until shutdown.

PSOs also want information such as the vertex format and Render Target colour depth, depth buffer format, MSAA settings, etc.

HlmsLowLevel handles a cache of PSOs (basically maps <Material, Renderable, RenderTarget> ---> PSO). Since librocket very likely uses the same vertex layout for everything, and the only thing that changes are materials & rendertargets, you may get the best hack by using HlmsLowLevel and a dummy Movable and multiple dummy Renderables (one Renderable per material).
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by SolarPortal »

ok, bit awkward since Gorilla and Librocket just got ported to v2.1 lol :P
They both used the "_setProgramsFromHlms" function so these will require to be ported to the pso branch correctly.

i will see what i can do :)

Edit: I have tested the pso branch and i experience the same errors with the multi workspaces and batching of the groundplane to the character on the second workspace.
I couldn't test the third workspace due to librocket not working on the pso branch due to a change in cache which is not a big deal, but i cannot spend anymore time on this version porting code again
as our userbase are looking forward to an alpha version of the new renderering capabilities next week or after.
So i will wait a bit on the PSO branch.

I can record a video of the same faults in the older v2-1 as it renders better imo.

The PSO branch needs some work, porting notes and is quite a radical change on the API for custom renderings. I understand that this is so we can support DX12, Vulkan etc..
but wouldn't it be better to get what we have working well (DX11, OpenGL3+) ;) I can see from being with it briefly that it is going to break many things that have already been ported to v2-1 which
could tick a few people off. Sorry for the rant but its just my 2cents :P

I have also noticed a visual difference in forward3D compared to DX11 and OpenGL3+ on both 2.1 and 2.1-pso
DX11 seems to have a strange clipping issue at distance when the camera moves up/down with a high threshhold that clips the lights.
I will make a video of this too. :)

Thanks for the continued work & support though and i will get the videos to you when possible.

Edit 2:
Changing to using 1 scenemanager in the mesh editor and main renderer but 2 renderWindows and 2 Workspaces has not fixed much.
The ManualObject v2 issues still appear in OpenGL3+ (i know, don't use V2 ManualObject lol :P) aswell as the mesh editor ground plane being batched into the character.
Again this is opengl3+ only and not DX11.

Also, with the 1 sceneManager, my directional light for the Mesh Editor is rendered in RQ 111 as are the meshes which are outside of the main rendering of RQ 0 to 100.
My Directional light for the mesh editor is being rendered in the main renderering workspace regardless of the RQID attached.
Q) Is there anything to be done for lights to render in queues seperately? I am using Forward3D also.
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by SolarPortal »

Here are the requested videos:

Video 1) Strangeness with mesh editor: (DX11 works as expected)
[youtube]OKL6z9GoD1Q[/youtube]
You can tell it is apart because the groundplane changes material and also messes up the skeleton.
The directional light that moves in the main scene shouldn't be there and is for the mesh editor.
Remember: Mesh Editor is v1 and Main Scene is v2

Video 2) This shows the descrepency between the Main Renderer and the LibRocket port on both DX11 and OpenGL3+ Again DX11 works as expected.
[youtube]QqCJreIHm5w[/youtube]

3) Forward3D errors between render systems. (OpenGL3+ works as expected)
[youtube]zjexhlO6MuA[/youtube]

You will also notice the difference in the Skybox on OpenGL3+ to DX11. (DX11 is just a black background).

Thanks, and i hope this helps.
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by SolarPortal »

ok, i have managed to replicate the same error in a smaller demo without Qt.
It happens when using two seperate render windows and use a different workspace for each, then render an entity with no skeleton followed by an entity with a skeleton. Different first entities changes how it messes up the skeleton. OpenGL is also the one at fault, however, using the normal renderwindows in DX11 crashes with:
Error Presenting surface in D3D11RenderWindowSwapChainBased::swapBuffers at OgreD3D11RenderWindow.cpp
Here is the code i was using when rendering with OpenGL3+:

Code: Select all

Ogre::CompositorManager2 *compositorManager = scene.root->getCompositorManager2();
secondCam = scene.sceneManager->createCamera("test_sceneCamera");

const Ogre::IdString workspaceName("Test_RenderScene");
sRenderWindow = scene.root->initialise(true, "AurasoftUK_sRenderWindow");
compositorManager->addWorkspace(scene.sceneManager, sRenderWindow, secondCam, workspaceName, true);
	
secondCam->setProjectionType(Ogre::ProjectionType::PT_PERSPECTIVE);
secondCam->setPosition(0, 2, 5);
secondCam->setAspectRatio(16.0f / 9.0f);
secondCam->setNearClipDistance(0.01);
secondCam->setFarClipDistance(100);
secondCam->lookAt(Ogre::Vector3(0,0,0));

// Create the old v1 GroundPlane
Ogre::SceneNode* node1 = rootNode->createChildSceneNode();
Ogre::v1::Entity* ent1 = scene.sceneManager->createEntity("BlackGridded_GroundPlane.mesh");
node1->attachObject(ent1);
node1->setPosition(Ogre::Vector3(0,0,0));

// Create the old v1 entity variant
Ogre::SceneNode* node = rootNode->createChildSceneNode();
Ogre::v1::Entity* ent = scene.sceneManager->createEntity("_3dFoin_RoyalSorceress_00_Body.mesh");
node->attachObject(ent);
node->setPosition(0, 1, 0);
animState = ent->getAnimationState("walk");
if (animState){
	animState->setEnabled(true);
	animState->setLoop(true);
}
in an update loop, i made the second camera follow the first to see the same in both render windows.
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5588
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by dark_sylinc »

SolarPortal wrote:The PSO branch needs some work, porting notes and is quite a radical change on the API for custom renderings. I understand that this is so we can support DX12, Vulkan etc..
but wouldn't it be better to get what we have working well (DX11, OpenGL3+) ;) I can see from being with it briefly that it is going to break many things that have already been ported to v2-1 which
could tick a few people off. Sorry for the rant but its just my 2cents :P
Complaints noted. I did not realize PSO change affected custom renderers so much. It sounds like custom renderers could use a PSO cache utility helper.
I agree that we should focus on DX11 & GL3+ (that's definitely what I've been doing) but while the whole PSO thing started as a way to be forward-ready with Vulkan, DX12 & Metal (don't forget Metal... it's the best way to target OS X & iOS); I found out the PSO idea is quite neat: some very edge-case bugs with OpenGL automatically got fixed (and some with D3D11! something about we no longer having to cache DepthStencilViews), code complexity went down (particularly in D3D11... the Vertex Layout and the HLSL shaders need to be indirectly aware of each other and this was causing a lot of spaghetti code. PSOs explicitly accept that these things are tied together and we can design around it), and performance went up slightly. It also made Compute Shaders easier / more robust.
So you can understand I got in love with PSOs even for D3D11 & GL. Beware, I will eventually merge 2.1-pso into 2.1. In fact it didn't happen sooner because I need to do more thorough testing. But I am now aware custom renderers need a tool for adapting to PSOs and perhaps not merge so hastily.
SolarPortal wrote:Also, with the 1 sceneManager, my directional light for the Mesh Editor is rendered in RQ 111 as are the meshes which are outside of the main rendering of RQ 0 to 100.
My Directional light for the mesh editor is being rendered in the main renderering workspace regardless of the RQID attached.
Q) Is there anything to be done for lights to render in queues seperately? I am using Forward3D also.
Déjà Vu. See my post Lights affecting only specific renderqueues.
SolarPortal wrote:ok, i have managed to replicate the same error in a smaller demo without Qt.
It happens when using two seperate render windows and use a different workspace for each, then render an entity with no skeleton followed by an entity with a skeleton. Different first entities changes how it messes up the skeleton. OpenGL is also the one at fault, however, using the normal renderwindows in DX11 crashes with:
Error Presenting surface in D3D11RenderWindowSwapChainBased::swapBuffers at OgreD3D11RenderWindow.cpp
in an update loop, i made the second camera follow the first to see the same in both render windows.
I love you. Easily reproducible bugs in small environments is what makes bugfixing easy.
For the record: So both Workspaces/Windows are supposed to show exactly the same because the 2nd camera is set at the same position & orientation as the first camera? (but obviously, they are not)

Could you send me BlackGridded_GroundPlane.mesh ? I don't want to leave anything to chance.

Regarding Forward3D: Thank you. I noticed some time ago they were not matching and then I never got to repro the problem again. Now with your simple walkthrough, I noticed I can reproduce this bug with embarrassing ease. Forward3D relies on projection matrices in its math. D3D11 & GL differ in conventions, I suspect this is very likely the problem (or could be top vs bottom sampling of the texture).

Regarding the rest of the bugs: I can notice you have many unknown variables. On experience, one bad thing can cascade into random things going wrong afterwards. For example the skybox working "right" in GL3+ while working "black" in D3D11 could just be evidence that the skybox itself is broken and manifesting problems in different ways for both APIs. Same with ManualObjects.
Removing them (i.e. commenting them out) could help narrowing down the different problems.
Though I have a feeling that this 2-workspaces-2-RenderWindows bug I now need to repro will reveal some shocking truth and an "Aha!" moment. So I will start there.

You gave me enough for the week, I think. I'll work on it when I can.
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by SolarPortal »

what you have wrote is very valid and thank you for taking it on board :)
A PSO cache utility helper will make the job a lot easier as many of us have spent plenty of time converting projects.

I think Ogre3D has a bright future :)

Thanks for the lighting tip using visibility masks, will try this after the post.
I love you. Easily reproducible bugs in small environments is what makes bugfixing easy.
lol :P We know ourselves when handling bugs from a community that it can be overwhelming and the least amount of time
having to hunt down a problem the better.
For the record: So both Workspaces/Windows are supposed to show exactly the same because the 2nd camera is set at the same position & orientation as the first camera? (but obviously, they are not)
yes, each renderwindow has its own workspace but share the same sceneManager, here are the basic rendering nodes:

Code: Select all

compositor_node AurasoftUK_BasicRenderingNode
{
	in 0 rt_renderwindow

	target rt_renderwindow
	{
		
		pass clear
		{
			colour_value 0.3 0.5 0.8 1
		}

		pass render_scene
		{
			overlays	on
			shadows		AurasoftUK_BasicShadowNode
		}
	}
}

workspace AurasoftUK_Basic_App_Workspace
{
	connect_output AurasoftUK_BasicRenderingNode 0
}


compositor_node Test_RenderSceneRenderingNode
{
	in 0 rt_renderwindow

	target rt_renderwindow
	{
		pass clear
		{
			colour_value 0.3 0.5 0.3 1
		}

		pass render_scene
		{
			overlays	off
			shadows	off
		}
	}
}

workspace Test_RenderScene
{
	connect_output Test_RenderSceneRenderingNode 0
}

The camera for the first renderwindow is a normal fly cam and in an update loop i call:

Code: Select all

	
secondCam->setPosition(camera.getCamera()->getParentSceneNode()->getPosition());
secondCam->setOrientation(camera.getCamera()->getParentSceneNode()->getOrientation());

if (animState){
	animState->addTime(0.01);
}
so they act like they are doing the same thing as you describe.
Simple answer yes, lol :P
Regarding the rest of the bugs: I can notice you have many unknown variables. On experience, one bad thing can cascade into random things going wrong afterwards.
yes, this is what i am going to do now. Remove ManualObject and replace with mesh to be sure of the issues. Although, the errors still appeared when not creating the manualObjects.
For example the skybox working "right" in GL3+ while working "black" in D3D11 could just be evidence that the skybox itself is broken and manifesting problems in different ways for both APIs.
This happens for me in the samples too. DX11 is just a black background. I shall record a video to show you.

As for the rest; i will see what i can do to eliminate problems and if anything can be reproduced, then i will let you know ;)

Edit: Here is the video to show what the demo should look like:
[youtube]t-LFJh3Q5eA[/youtube]

and the video for the Ogre3d 2.1 Skybox demo that i mentioned:
[youtube]Ircly2xWiOs[/youtube]
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by al2950 »

SolarPortal wrote:
For example the skybox working "right" in GL3+ while working "black" in D3D11 could just be evidence that the skybox itself is broken and manifesting problems in different ways for both APIs.
This happens for me in the samples too. DX11 is just a black background. I shall record a video to show you.
I have already debugged this in a fare amount of detail, what happens in Dx11 is the cubemap texture is loaded in as a TEX_TYPE_2D for some reason. (I did **EDIT NOT EDIT** look into why GL3+ deals with it correctly) On my build at least it was easy to fix as I just explicitly defined that texture as 'cubic'
https://bitbucket.org/al2950/ogre-2.x-u ... 96?at=v2-1

Now sure why that would work on my build and not yours. I just checked it again in case I made a mistake, and that 'cubic' declaration definitely fixes it for me :)
Last edited by al2950 on Wed Apr 06, 2016 12:38 pm, edited 1 time in total.
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by SolarPortal »

@al2950, I will have to try again but last time it changed nothing(maybe's i did something wrong). Thanks for the help :)
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5588
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by dark_sylinc »

I took a look at the code you provided via PM (I managed to compile it by the way). TBH I have no idea why on earth your code worked in the first place. It should've not worked at all. I'm still dazzling about that.

Your problem is in this line:

Code: Select all

sRenderWindow = scene.root->initialise(true, "AurasoftUK_sRenderWindow");
Initialize should only be called once. Calling it twice is asking for trouble. It seems D3D11 NVIDIA goes along, but AMD & Intel crash. On GL3+; it shows the same bugs you did, though I'm very surprised about that because you should not be seeing anything at all.

Anyway, the way to fix this is the following:

Code: Select all

const Ogre::IdString workspaceName( "Test_RenderScene" );
Ogre::NameValuePairList params;
static HGLRC g_glContext = wglGetCurrentContext(); //glXGetCurrentContext on Linux.
params["externalGLContext"] = Ogre::StringConverter::toString( (size_t)(g_glContext) );
params.insert( std::make_pair( "gamma", "true" ) );
sRenderWindow = scene.root->createRenderWindow( "AurasoftUK_sRenderWindow", 800, 600, false, &params );
compositorManager->addWorkspace( scene.sceneManager, sRenderWindow, secondCam, workspaceName, true );
The explanation is in this post: http://www.ogre3d.org/forums/viewtopic. ... 13#p522313
On D3D11 obviously the externalGLContext is not needed at all. On GL3+ it is needed. gamma = true is required otherwise the main render window & the secondary one will have mismatching pixel formats and thus fail (same happens with FSAA settings: They must match).

After that, all problems were fixed except for the Royal Sorceress looking mostly pink in GL, but fine in D3D11. But when I ran through RenderDoc, GL looked fine. That definitely caught my attention (normally this is symptom of padding errors when uploading data to GPU).
Your code triggers some asserts on shutdown but I didn't pay attention to it. Update: Shutting down via Alt+F4 triggers the assert, shutting via Esc key doesn't. This is simply because via Alt+F4 the render loop still thinks we need to render when the Ogre render window has been invalidated. Simple problem with a simple solution.

Update 2: The mesh uses multiple texture coordinates. This is biggest suspect right now.
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by SolarPortal »

oh, thank you very much, that fixed the demo on my machine too.
So to calrify, in my version of the demo, i have both viewports looking identical.
Also, Dx11 now loads and displays correctly in the demo. Good job finding it.

I am not too bothered on the assert triggered at the end as this demo is just a testbed to try the features in a pure ogre environment. :)
If i have time, i will fix them though.

However, looking at out our engine sourcecode, it has not got the same mistake made of initialising the Root twice.... which i admit was very of me silly lol ..... :roll:
What i am going to try is the "externalGLContext" option in the game engine to see if this eliminates the problem too and will report back after.

Edit: YES!, it fixed it in the engine. I love you man :) Jumping for joy atm :)
The errors in GL that i mostly complained about
  • Batching of ground on player in mesh editor.
  • Librocket disappearing when other renderwindow is activated.
  • Manual Objects which have not yet been replaced are working perfectly like in DX11
These are all fixed by adding the below line to each createRenderWindow params;

Code: Select all

params["externalGLContext"] = Ogre::StringConverter::toString((size_t)(wglGetCurrentContext()));
Note to others: To use the wglGetCurrentContext() function, you need to inlude "Opengl32.lib"

Also, i am using multiple sceneManagers to test again and it seems ok to me. One step closer! :)

Thanks for the continued support.

p.s. just to note for thread completeness; the only things not covered in this topic are the Forward3D(DX11) and the skybox problem.
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5588
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by dark_sylinc »

Update:
Dammit. I had disabled an assert to test your mesh, and this assert was signaling exactly the cause of the pink mesh problem.

The mesh glitches because it has diffuse colour stored as ARGB and really old code thinks GL prefers it as ABGR (honestly I think there is no difference nowadays. Needs research); and tries to automatically convert it.
But because the mesh was loaded with HBU_STATIC_WRITE_ONLY, it will read garbage. Loading the mesh like this before creating the entity:

Code: Select all

Ogre::v1::MeshManager::getSingleton().load(
                        "_3dFoin_RoyalSorceress_00_Body.mesh", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME,
                        Ogre::v1::HardwareBuffer::HBU_STATIC, Ogre::v1::HardwareBuffer::HBU_STATIC );
will workaround the problem. Another solution could be to store the mesh as ABGR since the D3D11 RenderSystem shouldn't have problems converting it.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5588
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by dark_sylinc »

I'm glad so many problems got fixed with just one line of code :)
SolarPortal wrote:p.s. just to note for thread completeness; the only things not covered in this topic are the Forward3D(DX11) and the skybox problem.
Yeah, the skybox is a known issue; and the Forward3D is now a known issue thanks to you. I'll take a look when I can. Don't know when though.
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by SolarPortal »

Excelent Work! Thanks again! :)
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5588
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by dark_sylinc »

Disappearing lights in Forward3D when using D3D11 fixed (also affected OpenGL if you were rendering to a RenderTexture instead of the RenderWindow!).

Thanks for the report.
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: [2.1]Strange Bug with multiple workspaces and scene mana

Post by SolarPortal »

That is brilliant. Thank you! :) Will be checking this out very soon!

A few other tweaks and point light shadows and we will be rolling lol :P
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
Post Reply