Porting Gorilla

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


User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5586
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: Porting Gorilla

Post by dark_sylinc »

N0vember wrote: Mattias, would that be a bug ? I'm a bit lost here but it feels a bit like something in the old materials got broken and no one noticed because Hlms is the way forward.
Yes, there's a high chance there are bugs since low level materials have been rather left unattended.

Btw. SceneManager::setPass isn't handling blendblocks because the RenderQueue is. May be you're not using the RenderQueue directly? (in such case then yeah, just set the blendblock manually yourself).
N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am
x 24

Re: Porting Gorilla

Post by N0vember »

dark_sylinc wrote: Btw. SceneManager::setPass isn't handling blendblocks because the RenderQueue is. May be you're not using the RenderQueue directly? (in such case then yeah, just set the blendblock manually yourself).
I am using a custom pass and calling _render from the custom pass. But I'm not touching the RenderQueue. Yeah maybe I should have mentioned that !
User avatar
Thyrion
Goblin
Posts: 224
Joined: Wed Jul 31, 2013 1:58 pm
Location: germany
x 8

Re: Porting Gorilla

Post by Thyrion »

so this is ok? we don't need the hlms here? (seems to be very lightwight, what i like)
just to be sure this will work in future, too. :)

the only things we need to update are this?
  • RenderOperation-> VertexArrayObject
  • HardwareBufferManager-> VaoManager
HardwareBufferManager and RenderOperation will be obsolete?
Gdlk
Halfling
Posts: 53
Joined: Mon Dec 05, 2011 9:43 pm
x 1

Re: Porting Gorilla

Post by Gdlk »

Hi!

Gorilla is working for Ogre 2.1?

If so, can you share the code?? (would be nice =D )

Thanks!!

Regards!!
N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am
x 24

Re: Porting Gorilla

Post by N0vember »

My modified version is here : (Gorilla.h and Gorilla.cpp)
https://github.com/novembermonk/kiog/tr ... Og/Gorilla
However it has a bunch of modifications that I personally needed
You will also need the materials and shaders which are here
https://github.com/novembermonk/kiog/tr ... illashader
Gdlk
Halfling
Posts: 53
Joined: Mon Dec 05, 2011 9:43 pm
x 1

Re: Porting Gorilla

Post by Gdlk »

N0vember wrote:My modified version is here : (Gorilla.h and Gorilla.cpp)
https://github.com/novembermonk/kiog/tr ... Og/Gorilla
However it has a bunch of modifications that I personally needed
You will also need the materials and shaders which are here
https://github.com/novembermonk/kiog/tr ... illashader
Really thanks =D
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 169

Re: Porting Gorilla

Post by xrgo »

Thank you very much N0vember!
I was testing your Gorilla for Ogre 2.1, and I have some problems:

First, I replaced my on screen debug info (fps, times, etc) that I had implemented using Ogre Overlays, with Gorilla. It worked!! but I noticed that FPS dropped from 32 to 27, and! shadows where gone =(.
FPS decrease I assume that it is because its not using Hlms, the shadow problem.. no idea... I don't care much about this, I just simply returned to Ogre Overlays, since I was happy with it, I was just testing.

Then I tried to use the Gorilla 3D, because this is the one a really need, and I see nothing :( , this is the code I am using:

Code: Select all

    Gorilla::ScreenRenderable* gorillaScreen;
    Gorilla::Layer* gorillaLayer;
    Gorilla::Caption* fpsCaption;

    Gorilla::Silverback* silverBack = new Gorilla::Silverback();
    silverBack->loadAtlas( "Prototype" );
    gorillaScreen = silverBack->createScreenRenderable( sceneManager, Ogre::Vector2(1,1), "Prototype" );

    gorillaScreen->getParentSceneNode()->setPosition(0,0,0);
    gorillaScreen->getParentSceneNode()->setScale(100,100,100);

    gorillaLayer = gorillaScreen->createLayer();

    fpsCaption = gorillaLayer->createCaption(40, 0, 0, "TEST TEXT");
My "Prototype" Font does exists in size 40, it was working as Gorilla 2D.

am I missing some step? what is a good value for maxSize?
Many thanks in advance!
N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am
x 24

Re: Porting Gorilla

Post by N0vember »

Well sadly I never found why 3D screens don't render in 2.1.
So it just doesn't work for now.
I'm lost here, since I don't know enough the differences between 2.0 and 2.1 that would cause this renderable not to be rendered.
I would need more knowledge to at least have an idea where to look.

I have two builds side to side, doing exactly the same in both. The ScreenRenderable in 2.1 just doesn't work.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 169

Re: Porting Gorilla

Post by xrgo »

N0vember wrote:Well sadly I never found why 3D screens don't render in 2.1.
So it just doesn't work for now.
I'm lost here, since I don't know enough the differences between 2.0 and 2.1 that would cause this renderable not to be rendered.
I would need more knowledge to at least have an idea where to look.

I have two builds side to side, doing exactly the same in both. The ScreenRenderable in 2.1 just doesn't work.
ohhh I see, thats sad. Thanks
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: Porting Gorilla

Post by SolarPortal »

Hi, Thanks for porting this :D
At first i was having problems with getting the Gorilla UI to work in 2.1 using DX11 since the shaders were out of date for the hlsl and it did not render on screen; in fact it crashed a lot lol :P.
OpenGl3+ was working fine though, so in order to make it work with DX11, I had to make these changes.

Here is the new hlsl shader for gorilla2D.hlsl

Code: Select all

struct VS_INPUT
{
	float4 vertex	: POSITION;
	float2 uv		: TEXCOORD0;
	float4 color	: COLOR0;
};

struct PS_INPUT
{
	float4 gl_Position	: SV_Position;
	float2 uv 			: TEXCOORD0;
	float4 color 		: TEXCOORD1;
};

PS_INPUT main_vp( 	VS_INPUT input,
					uniform matrix worldViewProj )
{
	PS_INPUT outVs;

	outVs.gl_Position = mul(worldViewProj, input.vertex);
	outVs.uv = input.uv;
	outVs.color = input.color;
	
	return outVs;
}

Texture2D atlas	: register(t0);
SamplerState samplerState : register(s0);

float4 main_fp(	PS_INPUT inPs) : SV_Target
{
	return atlas.Sample(samplerState, inPs.uv) * inPs.color;	
}

For the material, i changed the profiles being used to a more modern profile setup :)
Gorilla2D.material

Code: Select all

vertex_program gorilla2DVPHLSL hlsl
{
 	source gorilla2D.hlsl
	entry_point main_vp
	target vs_5_0 vs_4_0 vs_4_0_level_9_1 vs_4_0_level_9_3
} 

fragment_program gorilla2DFPHLSL hlsl
{
	source gorilla2D.hlsl
	entry_point main_fp
	target ps_5_0 ps_4_0 ps_4_0_level_9_1 ps_4_0_level_9_3
}

vertex_program gorilla2DVPGLSL glsl
{
 	source gorilla2DVP.glsl
} 

fragment_program gorilla2DFPGLSL glsl
{
	source gorilla2DFP.glsl
}

vertex_program gorilla2DVPGLSLES glsles
{
 	source gorilla2DVP.glsles
} 

fragment_program gorilla2DFPGLSLES glsles
{
	source gorilla2DFP.glsles
}

// Unified definition
vertex_program gorilla2DVP unified
{
	delegate gorilla2DVPGLSLES
	delegate gorilla2DVPHLSL
	delegate gorilla2DVPGLSL 
}
fragment_program gorilla2DFP unified
{
	delegate gorilla2DFPGLSLES
	delegate gorilla2DFPHLSL
	delegate gorilla2DFPGLSL 
}

material Gorilla2D21
{
	technique
	{
		pass
		{
			depth_check off
			depth_write off
			diffuse vertexcolour
			scene_blend alpha_blend
			
			vertex_program_ref gorilla2DVP
			{
			}

			fragment_program_ref gorilla2DFP
			{
			}
		}
	}
}

Changing the shader alone did not help as it crashed due a "Null Program Bound". I got around this by first loading the "Gorilla2D21" material before cloning.

(File) Gorilla.cpp - (Function) void TextureAtlas::_create2DMaterial()

Code: Select all

	void  TextureAtlas::_create2DMaterial()
	{
		Ogre::MaterialPtr baseMat = Ogre::MaterialManager::getSingletonPtr()->getByName("Gorilla2D21");
		if (!baseMat->isLoaded()) baseMat->load();

		std::string matName = "Gorilla2D." + mTexture->getName();
		m2DMaterial = baseMat->clone(matName);
		m2DPass = m2DMaterial->getTechnique(0)->getPass(0);

		Ogre::TextureUnitState* texUnit = m2DPass->createTextureUnitState();
		m2DPass->setVertexColourTracking(Ogre::TVC_DIFFUSE);
		m2DPass->getTextureUnitState(0)->setTexture(mTexture);
	}
Still it wasn't loading :? I ended up looking into CEGUI and found they used a hlms cache to drop the shaders into the rendersystem manually, so i adapted this into Gorilla and managed to make DX11 render from using it.
The snippet was creating a hlms cache that is set into the rendersystem using the vertex and fragment program setup in the material. It worked in both OpenGL and DX11.

Here is the full function:
(File) Gorilla.cpp - (Function) void Screen::_prepareRenderSystem()

Code: Select all

	void Screen::_prepareRenderSystem()
	{
		mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
		mRenderSystem->_setProjectionMatrix(Ogre::Matrix4::IDENTITY);
		mRenderSystem->_setViewMatrix(Ogre::Matrix4::IDENTITY);
		mSceneMgr->_setPass(mAtlas->get2DPass());
#ifdef GORILLA_V21
		mRenderSystem->_setHlmsBlendblock(mAtlas->get2DPass()->getBlendblock());

		// Create a hlmscache and drop the shaders into the hlms manually.
		Ogre::HlmsCache hlmsCache;
		hlmsCache.vertexShader = mAtlas->get2DPass()->getVertexProgram();
		hlmsCache.pixelShader = mAtlas->get2DPass()->getFragmentProgram();
		
		mRenderSystem->_setProgramsFromHlms(&hlmsCache);
#endif
	}
After putting these together, i ended up with gorilla working in 2.1 with both GL and DX11. I am quite happy with the result even if it isn't completely correct but it works great :)

Thanks again for porting this in the first place and i hope this helps a few who are having DX11 issues with Gorilla and Ogre3D 2.1 :)

Please bear in mind that i am not running the Gorilla Compositor system and have it built into my own compositor chain using:

Code: Select all

pass custom Gorilla
{
}
p.s. the shaders for the 3D gorilla will need the worldprojview matrix, but it is essentially the same. I haven't used the 3D version of gorilla yet and have heard there are some issues related to it being viewed, so maybe the code above may help.
Also, Here is the entire shaders folder to help some people :D
gorillashader.zip
(4.91 KiB) Downloaded 224 times
Thanks again :D

Edit: Fixed some messed up bbcodes :P
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: Porting Gorilla - 2-1 - pso branch

Post by SolarPortal »

Hi, we recently moved onto the PSO branch of 2-1 and had to get the Gorilla GUI's working again since we want to use the new terra system for our engine.

NOTE: we are using a define called OGRE_PSO to seperate our code for (2-1) and (2-1-pso) branches which allows us to step between the 2 versions.
You could replace the code and not use the defines if you want :)

The first edit to be made is at: Gorrila.cpp

(File:) Gorrila.cpp (Function:) void LayerContainer::_createVertexBuffer()
replace:

Code: Select all

 mRenderOpPtr->operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
with:

Code: Select all

#ifdef OGRE_PSO
		mRenderOpPtr->operationType = Ogre::OperationType::OT_TRIANGLE_LIST;
#else
		mRenderOpPtr->operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
#endif
Next, we need to edit the render system preparation:
(File:) Gorrila.cpp (Function:) void Screen::_prepareRenderSystem()

Code: Select all

#ifdef OGRE_PSO
	void Screen::_prepareRenderSystem(Ogre::RenderOperation &renderOp)
#else
	void Screen::_prepareRenderSystem()
#endif	
	{
		mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
		mRenderSystem->_setProjectionMatrix(Ogre::Matrix4::IDENTITY);
		mRenderSystem->_setViewMatrix(Ogre::Matrix4::IDENTITY);

#ifdef OGRE_PSO
		mRenderSystem->_setTexture(0, true, mAtlas->get2DPass()->getTextureUnitState(0)->getTextureName());
	#ifndef _DEBUG		
		Ogre::HlmsSamplerblock sampler;
		sampler.setAddressingMode(Ogre::TextureAddressingMode::TAM_CLAMP);
		sampler.setFiltering(Ogre::TextureFilterOptions::TFO_TRILINEAR);
		mRenderSystem->_setHlmsSamplerblock(0, &sampler);

		mRenderSystem->_disableTextureUnitsFrom(1);
	#endif

		// Destroy the last pso created before making a new one.
		if (hasPSO){
			mRenderSystem->_hlmsPipelineStateObjectDestroyed(&pso);
		}

		// Create the PSO for the current render of the GUI
		pso.initialize();
		pso.operationType = Ogre::OT_TRIANGLE_LIST;
		pso.vertexShader = mAtlas->get2DPass()->getVertexProgram();
		pso.pixelShader = mAtlas->get2DPass()->getFragmentProgram();
		pso.macroblock = mAtlas->get2DPass()->getMacroblock();
		pso.blendblock = mAtlas->get2DPass()->getBlendblock();

		pso.vertexElements = renderOp.vertexData->vertexDeclaration->convertToV2(); // Required by DX11 or it will crash! :D

		// Create & Set the PSO to the render system
		mRenderSystem->_hlmsPipelineStateObjectCreated(&pso);
		mRenderSystem->_setPipelineStateObject(&pso);

		// Send the render through. Ogre::v1::CbRenderOp cmd is needed for DX11. 
		// A straight renderOperation passed in _render will work in OpenGL.
		Ogre::v1::CbRenderOp cmd = Ogre::v1::CbRenderOp(renderOp);
		mRenderSystem->_setRenderOperation(&cmd);

		hasPSO = true;
#else
		mSceneMgr->_setPass(mAtlas->get2DPass());
#ifdef GORILLA_V21
		mRenderSystem->_setHlmsBlendblock(mAtlas->get2DPass()->getBlendblock());

		Ogre::HlmsCache hlmsCache;
		hlmsCache.vertexShader = mAtlas->get2DPass()->getVertexProgram();
		hlmsCache.pixelShader = mAtlas->get2DPass()->getFragmentProgram();
		mRenderSystem->_setProgramsFromHlms(&hlmsCache);

#endif
#endif
	}
Next is another operationtype change.
(File:) Gorrila.cpp (Function:) void Viewport::_writeRenderOp()
replace:

Code: Select all

mRenderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
with:

Code: Select all

#ifdef OGRE_PSO
		mRenderOp.operationType = Ogre::OperationType::OT_TRIANGLE_LIST;
#else
		mRenderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
#endif	
The final part to change in the cpp file is the _render function, the _setPass() needs wrapped in a define as it does not exist in the pso branch.
(File:) Gorrila.cpp (Function:) void Viewport::_render()

Code: Select all

	void Viewport::_render()
	{
		//mSceneMgr->getCurrentViewport()->getTarget();

#ifndef OGRE_PSO
		mSceneMgr->_setPass(mMaterial->getTechnique(0)->getPass(0));
#endif
		
		mRenderSystem->_render(mRenderOp);
	}
To finish up, lets head over to the Gorrila.h file:
Approximately around line 1040, you should find the prototype for the _prepareRenderSystem() function:
(File:) Gorrila.h (Function:) approx line 1040
replace:

Code: Select all

void _prepareRenderSystem();
with:

Code: Select all

// Internal -- Prepares RenderSystem for rendering.
#ifdef OGRE_PSO
		void _prepareRenderSystem(Ogre::RenderOperation &renderOp);
		Ogre::HlmsPso pso;
		bool hasPSO;
#else
		void _prepareRenderSystem();
#endif
Compile the Gorrila code and it should display the GUI in both DX11 and OpenGL.

p.s. This still requires the previous posts about the shaders etc....

Hope this helps :D

Also, if you get compile errors with CbRenderOp. See this post on the changes: http://www.ogre3d.org/forums/viewtopic.php?f=25&t=88797
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
xin2525xin2
Gnoblar
Posts: 6
Joined: Fri Aug 19, 2016 12:45 pm

Re: Porting Gorilla

Post by xin2525xin2 »

hi
I replace the code as you said, but I still have some problems, can you share the file Gorilla.cpp?

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

Re: Porting Gorilla

Post by SolarPortal »

I will post it later :)
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
xin2525xin2
Gnoblar
Posts: 6
Joined: Fri Aug 19, 2016 12:45 pm

Re: Porting Gorilla

Post by xin2525xin2 »

Thank you very much, and I am looking forward to it!
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: Porting Gorilla

Post by SolarPortal »

Here is the Gorilla.cpp and Gorilla.h code set.
(SGE) Ogre3D - Gorrila 2-1pso.zip
(30.26 KiB) Downloaded 203 times
Please bear in mind it is using our "custom pass provider" on the camera to pass the gorilla screen around. See this post for a pass provider example: http://www.ogre3d.org/forums/viewtopic. ... 25#p515236
Then replace the code in Gorrila.cpp(line 841-854) & Gorilla.h( line 1113-1141 )

This is what is then defined in the workspace as seen in a previous post. :)

Code: Select all

pass custom Gorilla
{
}
This does require the shaders from before also :)

Hope this helps :D
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
xin2525xin2
Gnoblar
Posts: 6
Joined: Fri Aug 19, 2016 12:45 pm

Re: Porting Gorilla

Post by xin2525xin2 »

Thank you for sharing you code, SolarPortal! :D
Now, it worked well on the computer of my workmate, sadly ,it can't work on my computer.. :(
There is an ogre exception when I run it.

Code: Select all

 void Screen:;_prepareRenderSystem(Ogre::RenderOperation &renderOp) 
      {
          ...
          mRenderSytem->_setPipelineStateObject(&pso);   //crashed here,  and the informatin is Line 2188, OgreD3dRenderSsytem.cpp
      }
 
rujialiu
Goblin
Posts: 296
Joined: Mon May 09, 2016 8:21 am
x 35

Re: Porting Gorilla

Post by rujialiu »

dear SolarPortal,
xin2525xin2 wrote:Thank you for sharing you code, SolarPortal! :D
Now, it worked well on the computer of my workmate, sadly ,it can't work on my computer.. :(
I am xin2525xin2's workmate mentioned above, and just now I've confirmed that our project will crash at that point with D3D11 but works good for GL3+. It's a bit surprising, because its seems that you're using D3D11 too, as one of your comment says "this is required in DX11 otherwise it'll crash"...

I'll look into this tomorrow, but It'll be great if you have some quick thoughts. Thanks!
rujialiu
Goblin
Posts: 296
Joined: Mon May 09, 2016 8:21 am
x 35

Re: Porting Gorilla

Post by rujialiu »

dear SolarPortal,

The bug causing crash was in our own app code. We accidentally unloaded the HLSL shader because all gorilla resources were loaded in a wrong resource group. It's surprising that GL3+ RS didn't crash. It seems to automatically reload the shaders again before rendering Gorilla?

However, after I fixed that, I'm still unable to make it work. I'm re-posting the most crucial part of your code so that everyone who's not familiar with Gorilla can take a look:

Code: Select all

void Screen::_prepareRenderSystem(Ogre::RenderOperation &renderOp)
{
    mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
    mRenderSystem->_setProjectionMatrix(Ogre::Matrix4::IDENTITY);
    mRenderSystem->_setViewMatrix(Ogre::Matrix4::IDENTITY);
 
    std::string textureName = mAtlas->get2DPass()->getTextureUnitState(0)->getTextureName();
    mRenderSystem->_setTexture(0, true, textureName);
 
#ifndef _DEBUG       
    Ogre::HlmsSamplerblock sampler;
    sampler.setAddressingMode(Ogre::TextureAddressingMode::TAM_CLAMP);
    sampler.setFiltering(Ogre::TextureFilterOptions::TFO_TRILINEAR);
    mRenderSystem->_setHlmsSamplerblock(0, &sampler);
 
    mRenderSystem->_disableTextureUnitsFrom(1);
#endif
 
    // Destroy the last pso created before making a new one.
    if (hasPSO){
        mRenderSystem->_hlmsPipelineStateObjectDestroyed(&pso);
    }
 
    // Create the PSO for the current render of the GUI
    pso.initialize();
    pso.operationType = Ogre::OT_TRIANGLE_LIST;
    pso.vertexShader = mAtlas->get2DPass()->getVertexProgram();
    pso.pixelShader = mAtlas->get2DPass()->getFragmentProgram();
    pso.macroblock = mAtlas->get2DPass()->getMacroblock();
    pso.blendblock = mAtlas->get2DPass()->getBlendblock();
 
    pso.vertexElements = renderOp.vertexData->vertexDeclaration->convertToV2(); // Required by DX11 or it will crash! :D
 
    // Create & Set the PSO to the render system
    mRenderSystem->_hlmsPipelineStateObjectCreated(&pso);
    mRenderSystem->_setPipelineStateObject(&pso);
 
    // Send the render through. Ogre::v1::CbRenderOp cmd is needed for DX11.
    // A straight renderOperation passed in _render will work in OpenGL.
    Ogre::v1::CbRenderOp cmd = Ogre::v1::CbRenderOp(renderOp);
    mRenderSystem->_setRenderOperation(&cmd);
 
    hasPSO = true;
}
Note that there is a #ifndef part which is only compiled in Release mode.

Then our app in Debug mode will trigger the following D3D11 exception:
D3D11 device cannot draw
Error Description:ID3D11DeviceContext::Draw: The Pixel Shader unit expects a Sampler to be set at Slot 0, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults.
In Line 3513, OgreD3D11RenderSystem.cpp, when reading without indexes (just after calling _prepareRenderSystem() above, and call mRenderSystem->_render()).

If I remove #ifndef (i.e. compile that part also in Debug mode), the following assersion will fail:

Code: Select all

void D3D11RenderSystem::_setHlmsSamplerblock( uint8 texUnit, const HlmsSamplerblock *samplerblock )
{
    assert( samplerblock->mRsData &&
            "The block must have been created via HlmsManager::getSamplerblock!" );
Any thoughts will be helpful. Thanks!
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5586
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: Porting Gorilla

Post by dark_sylinc »

I'm not familiar with Gorilla but I did spot this:
rujialiu wrote:

Code: Select all

#ifndef _DEBUG       
    Ogre::HlmsSamplerblock sampler;
    sampler.setAddressingMode(Ogre::TextureAddressingMode::TAM_CLAMP);
    sampler.setFiltering(Ogre::TextureFilterOptions::TFO_TRILINEAR);
    mRenderSystem->_setHlmsSamplerblock(0, &sampler);
 
    mRenderSystem->_disableTextureUnitsFrom(1);
#endif
This is invalid code as samplerblocks must be created (and ideally cached) via hlmasManager->getSamplerblock();
One (probably inefficient) solution would be:

Code: Select all

    Ogre::HlmsSamplerblock sampler;
    sampler.setAddressingMode(Ogre::TextureAddressingMode::TAM_CLAMP);
    sampler.setFiltering(Ogre::TextureFilterOptions::TFO_TRILINEAR);
    Ogre::HlmsSamplerblock *finalSampler = hlmsManager->getSamplerblock( sampler );
    mRenderSystem->_setHlmsSamplerblock(0, finalSampler);

    //After rendering...
    hlmsManager->destroySamplerblock( finalSampler );
    finalSampler = 0;
rujialiu
Goblin
Posts: 296
Joined: Mon May 09, 2016 8:21 am
x 35

Re: Porting Gorilla

Post by rujialiu »

dark_sylinc wrote: This is invalid code as samplerblocks must be created (and ideally cached) via hlmasManager->getSamplerblock();
One (probably inefficient) solution would be:

Code: Select all

    Ogre::HlmsSamplerblock sampler;
    sampler.setAddressingMode(Ogre::TextureAddressingMode::TAM_CLAMP);
    sampler.setFiltering(Ogre::TextureFilterOptions::TFO_TRILINEAR);
    Ogre::HlmsSamplerblock *finalSampler = hlmsManager->getSamplerblock( sampler );
    mRenderSystem->_setHlmsSamplerblock(0, finalSampler);

    //After rendering...
    hlmsManager->destroySamplerblock( finalSampler );
    finalSampler = 0;
Thanks! After I incorporated your suggested change (by adding "const" in front of Ogre::HlmsSamplerblock* finalSampler), I got a new exception:
ID3D11DeviceContext::Draw: The Shader Resource View dimension declared in the shader code (BUFFER) does not match the view type bound to slot 0 of the Vertex Shader unit (TEXTURE2D). This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching).
Here is the HLSL shader code for your info:

Code: Select all

struct VS_INPUT
{
    float4 vertex    : POSITION;
    float4 uv        : TEXCOORD0;
    float4 color    : COLOR0;
};
 
struct PS_INPUT
{
    float4 gl_Position    : SV_POSITION;
    float4 uv             : TEXCOORD0;
    float4 color         : TEXCOORD1;
};
 
PS_INPUT main_vp( VS_INPUT input )
{
    PS_INPUT outVs;
 
    outVs.gl_Position = input.vertex;
    outVs.uv = input.uv;
    outVs.color = input.color;
     
    return outVs;
}
 
Texture2D atlasTex : register(t0);
SamplerState atlas : register(s0);
 
float4 main_fp(    PS_INPUT inPs ) : SV_Target
{
    return atlasTex.Sample(atlas, inPs.uv.xy) * inPs.color;   
}
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: Porting Gorilla

Post by SolarPortal »

hi, I am sorry you are having problems with this. We tend to run OpenGL3+ as it feels more stable than the DX11 port when it comes to certain things.
We are also running and testing in release mode which may be why i haven't encountered those problems yet.... perhaps its still unported for debug mode?


The code was tested on a GTX560ti, GTX460, Intel HD 4000 & GT710m cards and worked well on both Renderer's using release mode.
When i get time, i will see about changing the samplerblock, but apart from that i don't really know what to suggest as it did take a lot of shoehorning in to get it right :)

The biggest problem we had with DX11 was a strange rendering that happens when this code is not in:

Code: Select all

     
      // Send the render through. Ogre::v1::CbRenderOp cmd is needed for DX11. 
      // A straight renderOperation passed in _render will work in OpenGL.
      Ogre::v1::CbRenderOp cmd = Ogre::v1::CbRenderOp(renderOp);
      mRenderSystem->_setRenderOperation(&cmd);
Perhaps its a driver error? Maybe dark_sylinc can shed more light on the matter :)

What specs are you running it on by any chance?
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5586
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: Porting Gorilla

Post by dark_sylinc »

Calling:

Code: Select all

const v1::CbRenderOp cmd( op );
rs->_setRenderOperation( &cmd );
is required.

Something that could be missing is that perhaps at the beginning of the Gorilla pass you should probably call:

Code: Select all

rs->_startLegacyV1Rendering();
The function RenderQueue::renderSingleObject is a good example of the whole setup.

The errors rujialiu posted suggest to me there is something wrong either before or after Gorilla starts/ends rendering, such as some state not completely clearing up or some other mess up. Sometimes this could even happen on the 2nd frame (i.e. 1st frame goes ok, 2nd frame begins incorrectly).
Walking up the callstack where the error actually happens could help diagnose what part of the system is being confused. A RenderDoc capture may also shed a lot of light.
rujialiu
Goblin
Posts: 296
Joined: Mon May 09, 2016 8:21 am
x 35

Re: Porting Gorilla

Post by rujialiu »

dark_sylinc wrote: Something that could be missing is that perhaps at the beginning of the Gorilla pass you should probably call:

Code: Select all

rs->_startLegacyV1Rendering();
The function RenderQueue::renderSingleObject is a good example of the whole setup.
Sadly, it doesn't help. D3D11 RS didn't override _startLegacyV1Rendering so it actually does nothing...
Anyway, I managed to make it working under Debug mode.

It seems that rendering Gorilla::Viewport lacks some kind of cleanup/initialization code, resulting the unmatched Resource View Dimension exception, so I removed Gorilla::Viewport from my Gorilla::Screen and it worked in Debug mode.

However, in Release mode, the graphics card driver crashed :( It recovered a few secs later, but after that, the program is unable to render anything.
It's quite confusing because after enabling Gorilla, at least the first 20~30 frames didn't caush driver crash: I added a breakpoint just before Gorilla's rendering, and I hit F5 at least 20 times. Then I remove the breakpoint, hit F5 again, then the program hangs for a few seconds and I see a message saying the driver crashed and recovered. Can it be some kind of resource leak/overflow?
dark_sylinc wrote: The errors rujialiu posted suggest to me there is something wrong either before or after Gorilla starts/ends rendering, such as some state not completely clearing up or some other mess up. Sometimes this could even happen on the 2nd frame (i.e. 1st frame goes ok, 2nd frame begins incorrectly).
Walking up the callstack where the error actually happens could help diagnose what part of the system is being confused. A RenderDoc capture may also shed a lot of light.
Yeah, very likely. But as a RenderDoc novice, after playing around it a bit, I can only manage to capture one frame by hitting F2, or in it's UI. But I don't know exactly the frame number when the driver crashes. Can RenderDoc capture continuous frames over a period of time (e.g. 10 seconds)?
rujialiu
Goblin
Posts: 296
Joined: Mon May 09, 2016 8:21 am
x 35

Re: Porting Gorilla

Post by rujialiu »

rujialiu wrote: However, in Release mode, the graphics card driver crashed :( It recovered a few secs later, but after that, the program is unable to render anything.
It's quite confusing because after enabling Gorilla, at least the first 20~30 frames didn't caush driver crash: I added a breakpoint just before Gorilla's rendering, and I hit F5 at least 20 times. Then I remove the breakpoint, hit F5 again, then the program hangs for a few seconds and I see a message saying the driver crashed and recovered. Can it be some kind of resource leak/overflow?
Finally made it work. When I found my problem in Debug mode (put gorilla shaders in a wrong resource group so it's getting unloaded unexceptedly), I only fixed the configuration file for Debug mode. Today I'm changing the configuration file for some other reason and suddenly found the mistake.

I'm posting this just to tell the community that one more person is getting Gorilla run perfeclty under 2.1-pso.
Many thanks to SolarPortal and dark_sylinc!
User avatar
SolarPortal
OGRE Contributor
OGRE Contributor
Posts: 203
Joined: Sat Jul 16, 2011 8:29 pm
Location: UK
x 51
Contact:

Re: Porting Gorilla

Post by SolarPortal »

I am happy that you have it running now :) Good job!
Lead developer of the Skyline Game Engine: https://aurasoft-skyline.co.uk
Post Reply