Page 3 of 5

Re: Depth sharing Design

Posted: Wed Feb 24, 2010 9:47 am
by xadhoom
Noman,

Are these changes implicitly used by the Deferred Rendering Sample or would it need to adapt the Compositor scripts?

xad

Re: Depth sharing Design

Posted: Wed Feb 24, 2010 10:11 am
by masterfalcon
Noman wrote:I'm just the middle-man... It's dark_sylinc who did the real work.

Speaking of GLES/2 - I don't think they were modified. They might have some pure-virtual calls that might cause linker errors. (Can't check since I don't have a compilation environment for them).
Can you make sure that they still compile correctly?
Sure thing. I know that they both have some compilation errors right now. It's way late right now but I'll work on it tomorrow.

Re: Depth sharing Design

Posted: Sat Feb 27, 2010 9:20 pm
by dark_sylinc
Yay!! it's on trunk! :)
I've closed the SF.Net patch & tagged as accepted.
xadhoom wrote:Noman,

Are these changes implicitly used by the Deferred Rendering Sample or would it need to adapt the Compositor scripts?

xad
The Deferred Rendering Sample was slightly changed (C++ code, I think 3 lines were changed) so that shadow textures are put in a different pool. The compositors scripts weren't changed at all (an alternative solution would've been to change all compositor scripts used by that sample to use a different pool and leave the shadow textures untouched.)
masterfalcon wrote:
Noman wrote:I'm just the middle-man... It's dark_sylinc who did the real work.

Speaking of GLES/2 - I don't think they were modified. They might have some pure-virtual calls that might cause linker errors. (Can't check since I don't have a compilation environment for them).
Can you make sure that they still compile correctly?
Sure thing. I know that they both have some compilation errors right now. It's way late right now but I'll work on it tomorrow.
I didn't touch GLES/2 at all.
Probably it's the pure virtual function RenderSystem::_createDepthBufferFor()

As for implementing this for GLES/2, I usually started with new RenderSystems by creating a derived class from DepthBuffer (i.e. GLESDepthBuffer), the most vital function to overload is DepthBuffer::isCompatible()

Then _createDepthBufferFor() needs to be overloaded too so you can allocate GLESDepthBuffer.

Also not to forget to set the right RenderCapabilitiesFlags

The rest is pretty much generic code that abstractly deals with the details.

I'm glad you like it.
Thanks
Dark Sylinc

Re: Depth sharing Design

Posted: Fri Mar 05, 2010 3:18 pm
by moagames
Hi all,

I have a question regarding the changes made and the deferred shading compositor:
If I understood it correctly, the changes were made, so that the depth buffer can now be shared through different render targets, but nevertheless in the DeferredShading/ShowLit compositor the first thing that is done is, to clear the depth buffer and to rebuild it according to the GBuffer.
Couldn't we now just reuse the same depth buffer of the last compositor (DeferredShading/GBuffer) and save some shader operations ?

Thanks for clarifying.

Re: Depth sharing Design

Posted: Fri Mar 05, 2010 6:43 pm
by dark_sylinc
moagames wrote: I have a question regarding the changes made and the deferred shading compositor:
If I understood it correctly, the changes were made, so that the depth buffer can now be shared through different render targets, but nevertheless in the DeferredShading/ShowLit compositor the first thing that is done is, to clear the depth buffer and to rebuild it according to the GBuffer.
Couldn't we now just reuse the same depth buffer of the last compositor (DeferredShading/GBuffer) and save some shader operations ?

Thanks for clarifying.
I'm not deeply familiar with DeferredShading's code, but the changes made were made so that the Depth Buffer would be NOT shared between the shadow texture render targets and the Deferred shading textures. There are multiple textures that may or may not (I don't know, but at least 2 textures do) take advantage of sharing the same depth buffer, but the shadow textures won't interfere in the middle of the operations.

Before these changes, the same effect was being achieved through a hack in Ogre RenderSystem.

Re: Depth sharing Design

Posted: Fri Mar 05, 2010 7:29 pm
by Noman
moagames is right essentially. However, I haven't had the time to try to remove the depth-rebuilding part of the shader. Its also a good idea to show that it is possible to rebuild it if needed, but in the case of the deferred shading demo, it might not be needed anymore...

Re: Depth sharing Design

Posted: Sun Mar 14, 2010 12:09 am
by masterfalcon
I just realized that depth sharing was busted on GLES and I may have found a small bug which might affect the GL rendersystem too.

Code: Select all

bool GLDepthBuffer::isCompatible( RenderTarget *renderTarget ) const
{
...
				bool bSameStencil = false;

				if( !mStencilBuffer || mStencilBuffer == mDepthBuffer )
					bSameStencil = stencilFormat == GL_NONE;
				else if( bSameStencil )
					bSameStencil = stencilFormat == mStencilBuffer->getGLFormat();

...
}
Is the else if correct? It doesn't look like it should ever be possible to get in there because bSameStencil will be false initially.

Re: Depth sharing Design

Posted: Sun Mar 14, 2010 6:28 am
by dark_sylinc
Thanks!
It's a bug.

It should be:

Code: Select all

            if( !mStencilBuffer || mStencilBuffer == mDepthBuffer )
               bSameStencil = stencilFormat == GL_NONE;
            else if( mStencilBuffer )
               bSameStencil = stencilFormat == mStencilBuffer->getGLFormat();
The "else if" was supposed to prevent calling getGLFormat() since mStencilBuffer may be null.

Good job spotting it. Stencil buffers separate from Depth buffers setups are extremely rare (dunno about GLES). That buggy code could've been unnoticed for a very long time.

Thanks
Dark Sylinc

Re: Depth sharing Design

Posted: Sun Mar 14, 2010 7:33 am
by masterfalcon
Cool cool. At the moment GL ES is using separate buffers(though I haven't actually checked if it's working right).

So should it have been:

Code: Select all

            if( !mStencilBuffer || mStencilBuffer == mDepthBuffer )
               bSameStencil = stencilFormat == GL_NONE;
            else
            {
                if( mStencilBuffer )
                    bSameStencil = stencilFormat == mStencilBuffer->getGLFormat();
            }
If so, then I could make the change and check it in for all 3 GL render systems.

Re: Depth sharing Design

Posted: Mon Mar 15, 2010 3:44 pm
by sinbad
Looks right to me.

Re: Depth sharing Design

Posted: Mon Mar 15, 2010 5:18 pm
by masterfalcon
Cool. I'll check this in tonight. Gotta uncouple it from a bunch of other GL ES changes first.

Re: Depth sharing Design

Posted: Sun Mar 28, 2010 9:26 pm
by Wolfmanfx
I have updated my c# editor to the latest trunk and get an exception when i generate several windows on runtime

Code: Select all

22:20:28: D3D9: Vertex texture format supported - PF_FLOAT16_RGB
22:20:28: D3D9: Vertex texture format supported - PF_FLOAT16_RGBA
22:20:28: D3D9: Vertex texture format supported - PF_FLOAT32_RGB
22:20:28: D3D9: Vertex texture format supported - PF_FLOAT32_RGBA
22:20:28: D3D9: Vertex texture format supported - PF_FLOAT16_R
22:20:28: D3D9: Vertex texture format supported - PF_FLOAT32_R
22:20:28: D3D9: Vertex texture format supported - PF_FLOAT16_GR
22:20:28: D3D9: Vertex texture format supported - PF_FLOAT32_GR
22:25:35: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:35: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:35: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:35: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:35: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:35: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:35: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:35: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:35: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
22:25:36: OGRE EXCEPTION(3:RenderingAPIException): Failed to setDepthStencil : Invalid call in D3D9RenderSystem::_setViewport at ..\..\..\RenderSystems\Direct3D9\src\OgreD3D9RenderSystem.cpp (line 2876)
with opengl everything works.

I pass the c# window handle as externalwindow to ogre.

Re: Depth sharing Design

Posted: Mon Mar 29, 2010 12:19 pm
by sinbad
The DirectX Debug Runtime should give you some more details on the error.

Re: Depth sharing Design

Posted: Mon Mar 29, 2010 1:05 pm
by Wolfmanfx
Will make a detailed report tonight.

Re: Depth sharing Design

Posted: Mon Mar 29, 2010 11:08 pm
by Wolfmanfx
Tried debug runtime not much info gained from that i also tried this

Code: Select all

    RenderTarget::RenderTarget()
		:mPriority(OGRE_DEFAULT_RT_GROUP),
		mActive(true),
		mAutoUpdate(true),
		mHwGamma(false), 
		mFSAA(0),
		mDepthBuffer(0),
		mDepthBufferPoolId(DepthBuffer::POOL_NO_DEPTH)
anyway hints how i can track down this, i think this is related to the depth sharing feature because everything worked before just fine.

Re: Depth sharing Design

Posted: Tue Mar 30, 2010 3:45 pm
by sinbad
When you run the DirectX debug runtime (from the Dx9 SDK tools), in the Visual Studio output window you will get a dump of additional information right where the D3D error was thrown. Did you check the output window?

Re: Depth sharing Design

Posted: Tue Mar 30, 2010 9:30 pm
by Wolfmanfx
i did not (just checked the console :roll: )

Code: Select all

First-chance exception at 0x75939617 in Editor.exe: Microsoft C++ exception: Ogre::RenderingAPIException at memory location 0x004adaec..
First-chance exception at 0x75939617 in Editor.exe: Microsoft C++ exception: Ogre::Exception at memory location 0x004ae240..
Direct3D9: (ERROR) :**** The D3DUSAGE_DEPTHSTENCIL is not set on this surface.

Direct3D9: (ERROR) :**** You need to add D3DUSAGE_DEPTHSTENCIL to the Usage parameter

Direct3D9: (ERROR) :**** when creating the surface. SetDepthStencilSurface failed.

D3D9 Helper: IDirect3DDevice9::SetDepthStencilSurface failed: D3DERR_INVALIDCALL

Re: Depth sharing Design

Posted: Wed Mar 31, 2010 12:40 pm
by sinbad

Re: Depth sharing Design

Posted: Fri Apr 02, 2010 5:25 pm
by Lee04
Hi

Can the depth sharing patch be applied on to 1.7 of Ogre or do I need some special version of Ogre to use depth sharing patch?

Thanks

Lee

Re: Depth sharing Design

Posted: Fri Apr 02, 2010 5:26 pm
by sinbad
You can backport it if you like, otherwise just use the default branch from Mercurial.

Re: Depth sharing Design

Posted: Fri Apr 09, 2010 3:14 pm
by masterfalcon
I may have discovered a problem with depth sharing, not sure if it's related to wolfman's problems or not. GL ES doesn't have as many stencil or depth formats as desktop GL. As a result we usually end up with 24 bit depth and 8 bit stencil. RTT's are just blank then. I tried this in desktop GL by commenting out some formats in GLFBORenderTexture to be the same as GL ES and I got the same results. Either garbage in the buffers or just blank.

I haven't had a chance to look into why it's not working, I just figured it out late last night(or early this morning) but I thought it'd be good to get it out there to get some thoughts.

Re: Depth sharing Design

Posted: Sat Apr 10, 2010 6:16 am
by masterfalcon
Additional note: Packed formats are no longer detected.

Re: Depth sharing Design

Posted: Sat Apr 10, 2010 11:43 pm
by dark_sylinc
Whoa! I hate when phpBB3 doesn't email you about replies to your post. I came to this post again by looking at sinbad's tweets.

I haven't yet switched to Mercurial.

I'm very intrigued how a D3D9 surface ended up in a DepthBuffer class without the D3DUSAGE_DEPTHSTENCIL parameter.
anyway hints how i can track down this, i think this is related to the depth sharing feature because everything worked before just fine.
Try placing a breakpoint at file OgreD3D9RenderSystem.cpp, function D3D9RenderSystem::_setRenderTarget, line ~2872:

Code: Select all

hr = getActiveD3D9Device()->SetDepthStencilSurface( depthSurface );
If you're courageous enough, try figguring yourself what's going on ;)
If you're scared, select the "depthBuffer" variable, right click, select "QuickWatch..." expand all variables as most as possible, screendump and post it. Hopefully we may spot the bug with that

Also copy-pasting the callstack won't hurt.

Edit:
You (Wolfmanfx) said:
and get an exception when i generate several windows on runtime
Could you provide the code on how you generate those several windows?
That would definately help

Re: Depth sharing Design

Posted: Sun Apr 11, 2010 12:05 am
by dark_sylinc
@masterfalcon:
I'm not very familiar with OGL so I could have made some mistakes, but last time I checked, depth & stencil formats are enumerated and detected in GLFBOManager::detectFBOFormats(), later to be matched using GLFBOManager::getBestDepthStencil, both functions were left untouched; but calling those functions was moved from FBO's initialization (I think it was a function called from the constructor) to GLRenderSystem.

May be if you share how you modified OGL so that it behaves like in GL ES I could reproduce it too.

Re: Depth sharing Design

Posted: Sun Apr 11, 2010 1:02 am
by masterfalcon
All but the packed formats are detected right. I haven't tracked it down yet but i have a feeling that it's something like one call that's wrong.

In OgreGLFBORenderTexture.cpp:

Code: Select all

/// Stencil and depth formats to be tried
static const GLenum stencilFormats[] =
{
    GL_NONE,                    // No stencil
//    GL_STENCIL_INDEX1_EXT,
//    GL_STENCIL_INDEX4_EXT,
    GL_STENCIL_INDEX8_EXT,
//    GL_STENCIL_INDEX16_EXT
};
static const size_t stencilBits[] =
{
    0, /*1, 4*/, 8//, 16
};
#define STENCILFORMAT_COUNT (sizeof(stencilFormats)/sizeof(GLenum))

static const GLenum depthFormats[] =
{
    GL_NONE,
    GL_DEPTH_COMPONENT16,
    GL_DEPTH_COMPONENT24,    // Prefer 24 bit depth
//    GL_DEPTH_COMPONENT32,
    GL_DEPTH24_STENCIL8_EXT // packed depth / stencil
};
static const size_t depthBits[] =
{
    0,16,24,/*32,*/24
};