DirectX 11 render system - work-in-progress

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
User avatar
boyamer
Orc
Posts: 459
Joined: Sat Jan 24, 2009 11:16 am
Location: Italy
x 6

Re: DirectX 11 render system - work-in-progress

Post by boyamer »

I've resolved the _setCullingMode in DX11 in this way:

Code: Select all

//---------------------------------------------------------------------
	void D3D11RenderSystem::_setCullingMode( CullingMode mode )
	{
		mCullingMode = mode;

		bool flip = ((mActiveRenderTarget->requiresTextureFlipping() && !mInvertVertexWinding) ||
					(!mActiveRenderTarget->requiresTextureFlipping() && mInvertVertexWinding));

		mRasterizerDesc.CullMode = static_cast<D3D11_CULL_MODE>(mode);
		mRasterizerDesc.FrontCounterClockwise = flip;
	}
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: DirectX 11 render system - work-in-progress

Post by Mind Calamity »

First - I apologize if this counts as cross-posting, but since my problem of getting D3D9 HLSL Shaders to work with D3D11 is related to this thread, I though I'd post a link, since Asaaf, our D3D11 "guru" (quotation marks because of the guru myth ;)) hangs around this thread most of the time, as most people knowledgeable of the new render system do as well.

BTW - If the moderators here think I'm breaking the rules - you're free to delete this post. :)
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: DirectX 11 render system - work-in-progress

Post by Assaf Raman »

That is fine. Don't worry about it.
Regarding the issue - well - I really worked hard on it when I started this render system and couldn't get it to work.
If it did work - it would have saved me lots of time (not writing new shaders), but don't think it can be done.
Watch out for my OGRE related tweets here.
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: DirectX 11 render system - work-in-progress

Post by Mind Calamity »

Assaf Raman wrote:That is fine. Don't worry about it.
Regarding the issue - well - I really worked hard on it when I started this render system and couldn't get it to work.
If it did work - it would have saved me lots of time (not writing new shaders), but don't think it can be done.
If this post was referring to my issue:

You mean normal HLSL shaders don't work with D3D11 ?

If so any resources on writing D3D11-compatible shaders ?

BTW - What exactly is needed to make an application compatible with the D3D11 renderer ?

Writing shaders is a must, I got that because there is no Fixed Function Pipeline, but what else, and how should we go about doing that ?

Sorry to storm you with questions, but I've never once have been able to get an application running with this renderer, no matter how simple it was, but I'm still interested in helping out (and to do that I need to have a place to start at the very least).
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: DirectX 11 render system - work-in-progress

Post by Assaf Raman »

You need to write shader model 4.0 and up.
Regarding fixed pipeline - well - the RTSS have full fixed pipeline emulation.
Regarding resources about writing shader model 4.0 shaders - the dx sdk.
Watch out for my OGRE related tweets here.
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: DirectX 11 render system - work-in-progress

Post by Mind Calamity »

Thanks, Asaaf, the DX SDK is really interesting (I never knew what it had except for D3D itself).

Also, I sort of updated my shader to work with vs/ps_4_0, but well.... It doesn't, it gives me this exception:

Code: Select all

11:42:06: OGRE EXCEPTION(3:RenderingAPIException): D3D11 device cannot draw indexed
Error Description:ID3D11DeviceContext::DrawIndexed: Rasterization Unit is enabled (PixelShader is not NULL or Depth/Stencil test is enabled and RasterizedStream is not D3D11_SO_NO_RASTERIZED_STREAM) but position is not provided by the last shader before the Rasterization Unit.
 in D3D11RenderSystem::_render at D:\Libraries\ogre\RenderSystems\Direct3D11\src\OgreD3D11RenderSystem.cpp (line 2194)
And I don't see any compile errors or something like that.

Code: Select all

but position is not provided by the last shader before the Rasterization Unit.
How/where exactly do I need to provide the position, and position of what ? The vertices ?
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: DirectX 11 render system - work-in-progress

Post by Assaf Raman »

Watch out for my OGRE related tweets here.
Shtuka
Greenskin
Posts: 146
Joined: Mon Jan 10, 2011 7:39 pm
x 9

Re: DirectX 11 render system - work-in-progress

Post by Shtuka »

DirectX 10/11 doesn't use a fixed function pipeline anymore, but a programmable with shaders. Doesn't this mean that not only the DirectX RenderSystem has to be re-programmed, but also the RenderSystem of OgreMain?
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: DirectX 11 render system - work-in-progress

Post by Mind Calamity »

Thanks for the useful link, Asaaf, changing the POSITION semantics into SV_Position did the trick, and I have my first Direct3D11 Application YAY! (Even though it just renders an orange ogre head :lol: )
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: DirectX 11 render system - work-in-progress

Post by Assaf Raman »

Shtuka wrote:DirectX 10/11 doesn't use a fixed function pipeline anymore, but a programmable with shaders. Doesn't this mean that not only the DirectX RenderSystem has to be re-programmed, but also the RenderSystem of OgreMain?
Not really.
BTW: we have full fixed function pipeline emulation using the RTSS.
Watch out for my OGRE related tweets here.
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: DirectX 11 render system - work-in-progress

Post by Mind Calamity »

Assaf Raman wrote:
Shtuka wrote:DirectX 10/11 doesn't use a fixed function pipeline anymore, but a programmable with shaders. Doesn't this mean that not only the DirectX RenderSystem has to be re-programmed, but also the RenderSystem of OgreMain?
Not really.
BTW: we have full fixed function pipeline emulation using the RTSS.
The RT Shader System sounds like a monster, and I've witnessed the awesome things it can do in the sample, but I'm sure that's nothing near the power it's hiding. :D

I tried implementing it once in my earlier days of using OGRE, failed and gave up, I might just try to do it again, sounds like it's worth it.

BTW - Thanks, Asaaf I solved my problem with that link. :)

And I made a wiki article to help anyone who has the same problem/question as me.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
JDX_John
Gnome
Posts: 397
Joined: Sat Nov 08, 2008 1:59 pm
x 2

Re: DirectX 11 render system - work-in-progress

Post by JDX_John »

Assaf Raman wrote:You need to write shader model 4.0 and up.
Hold up, so D3D11 broke back-compatibility?
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: DirectX 11 render system - work-in-progress

Post by Assaf Raman »

Yes, this is nothing new, D3D11 is as different from D3D9 as OpenGL is different from D3D9.
Watch out for my OGRE related tweets here.
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Re: DirectX 11 render system - work-in-progress

Post by Crashy »

I've just sumbitted a small patch adding support for separate scene blending :)
Follow la Moustache on Twitter or on Facebook
Image
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: DirectX 11 render system - work-in-progress

Post by Assaf Raman »

I will have a look in the weekend
Watch out for my OGRE related tweets here.
LBDude
Gnome
Posts: 389
Joined: Mon Jul 26, 2010 10:53 pm
x 22

Re: DirectX 11 render system - work-in-progress

Post by LBDude »

anyone know why it crashes on

Code: Select all

D3D11Texture * D3D11HardwarePixelBuffer::getParentTexture() const
	{
		return mParentTexture;
	}
this happens when I do this

Code: Select all

_gBufferMRTT->getViewport(0)->clear(Ogre::FBT_COLOUR | Ogre::FBT_DEPTH);
_gBufferMRTT is a multiple render target. I have two textures attached to it. Works fine in DX9.

Now all my code uses shaders but when I run in DX9 without fixed function enabled it crashes and tells me that I can't use fixed function. So to debug this tomorrow I will start a new simple project and try to get it working there.

Edit: I forgot to update to latest from main repo. Not sure if I'm ready up-to-date or not, will try that.

Edit2: forgot to mention that every shader that I'm currently using have been ported to vs_4_0. I have one or two shaders not attached to anything not ported yet.

Edit3: I got the latest from repo and still crashing at the same spot. I disabled the first clear and now it's crashing here:

Code: Select all

bool D3D11DepthBuffer::isCompatible
I will look at it some more to see if I can resolve this.
My blog here.
Game twitter here
LBDude
Gnome
Posts: 389
Joined: Mon Jul 26, 2010 10:53 pm
x 22

Re: DirectX 11 render system - work-in-progress

Post by LBDude »

Hey I found a potential problem with "bool D3D11DepthBuffer::isCompatible( RenderTarget *renderTarget ) const" for a MultipleRenderTarget:

Code: Select all

bool D3D11DepthBuffer::isCompatible( RenderTarget *renderTarget ) const
	{
		//TODO:
		//Urgh! This bit of "isTexture" is a bit ugly and potentially unsafe
		bool isTexture = true;
		renderTarget->getCustomAttribute( "isTexture", &isTexture );

		ID3D11Texture2D *D3D11texture;
		if( isTexture )
		{
			D3D11HardwarePixelBuffer *pBuffer;
			renderTarget->getCustomAttribute( "BUFFER", &pBuffer );
			D3D11texture = static_cast<ID3D11Texture2D*>( pBuffer->getParentTexture()->getTextureResource() );
		}
		else
		{
			renderTarget->getCustomAttribute( "ID3D11Texture2D", &D3D11texture );
		}

		D3D11_TEXTURE2D_DESC BBDesc;
		D3D11texture->GetDesc( &BBDesc );

		//TODO: Needs to check format too!
		if( mFsaa == BBDesc.SampleDesc.Count &&
			mMultiSampleQuality == BBDesc.SampleDesc.Quality &&
			this->getWidth() == renderTarget->getWidth() &&
			this->getHeight() == renderTarget->getHeight() )
		{
			return true;
		}

		return false;
	}
But OgreDX11MultiRenderTarget::getCustomAttribute provides a valid output only for a single input which is "DDBACKBUFFER".

Code: Select all

void D3D11MultiRenderTarget::getCustomAttribute(const String& name, void *pData)
	{
		if(name == "DDBACKBUFFER")
		{
			ID3D11Texture2D ** pSurf = (ID3D11Texture2D **)pData;
			/// Transfer surfaces
			for(size_t x=0; x<OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x)
			{
				if(targets[x])
					pSurf[x] = targets[x]->getParentTexture()->GetTex2D();
			}
			return;
		}
	}
My blog here.
Game twitter here
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Re: DirectX 11 render system - work-in-progress

Post by Crashy »

I've done a few things on this, I'll make a patch tomorrow, just remind me to do it by mp, maybe it will fix your problem.
Follow la Moustache on Twitter or on Facebook
Image
LBDude
Gnome
Posts: 389
Joined: Mon Jul 26, 2010 10:53 pm
x 22

Re: DirectX 11 render system - work-in-progress

Post by LBDude »

Thanks. I've gotten pass that part by doing:

Code: Select all

void D3D11MultiRenderTarget::getCustomAttribute(const String& name, void *pData)
	{
		if(name == "DDBACKBUFFER")
		{
			ID3D11Texture2D ** pSurf = (ID3D11Texture2D **)pData;
			/// Transfer surfaces
			for(size_t x=0; x<OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x)
			{
				if(targets[x])
					pSurf[x] = targets[x]->getParentTexture()->GetTex2D();
			}
			return;
		}
		else if(name == "BUFFER")
		{
			D3D11HardwarePixelBuffer **pBuffer = (D3D11HardwarePixelBuffer**)pData;
			for(size_t x = 0; x < OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x)
			{
				if(targets[x])
					pBuffer[x] = targets[x];
			}
		}
	}
I've no problem with clearing the buffer on MRTT after this modification. But it turns out my shaders aren't 100% ported to dx11, in the middle of fixing that right now.
My blog here.
Game twitter here
User avatar
ahmedismaiel
OGRE Contributor
OGRE Contributor
Posts: 217
Joined: Wed Jan 25, 2006 11:16 pm
Location: Redmond,WA

Re: DirectX 11 render system - work-in-progress

Post by ahmedismaiel »

Hi guys ,
i'm working on supporting d3d11 in StuntRally http://code.google.com/p/vdrift-ogre/ and appreciate it if you can consider the fixes in the path below
https://skydrive.live.com/redir.aspx?ci ... 5HaWFfQJrY

here is a screenshot our game with d3d11 plugin:
https://skydrive.live.com/redir.aspx?ci ... aPA1bp6psw

here is a one line description for each change ,feel free to ask me for more details
1-cache FilterOptions per texture unit so we can add filter comparison
2-remove mDepth==1 as the assert can fail when the depth buffer is for a cube map render target (which is pretty common is reflections)
3- add a valid D3D11_FILTER_* for comparison and aniso mip linear
4-return a valid DXGI format for RGB16 (important in compositors using that texture format)
5-check for null textures before touching them (copied the check from d3d9)
6- cube map render targets to have 1 mipmap to prevent sampling artifact when looking up a black mipmap and match d3d9
7-set the texture units to the hardware all at once even when some of them are null so they match the shader texture binding other wise an error will occur
8- fixed a crash when loading a 8x8 2d texture where the hardware is not able to do more mips than requested

there is still a few more fixes that i'm considering to do once we get all of functionality of the game working first ,so i might be bugging you again
Thanks alot
Ahmed
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: DirectX 11 render system - work-in-progress

Post by Assaf Raman »

Nice work!
Watch out for my OGRE related tweets here.
LBDude
Gnome
Posts: 389
Joined: Mon Jul 26, 2010 10:53 pm
x 22

Re: DirectX 11 render system - work-in-progress

Post by LBDude »

I just want to ask something real quick regarding ManualObjects and D3D11VertexDeclaration::getD3DVertexDeclaration (I will look into this further myself just want to ask on the forum also):

Basically it was crashing on me in D3DVertexDeclaration::getILayoutByShader->getD3DVertexDeclaration. I'm doing this uber-shader thing where I have two preprocessor defines that generate two separate vertex shader inputs. It's crashing on this:

Code: Select all

....
#if TEXTURE_ATLAS
struct VS_IN
{
  float4 position : POSITION;
  float4 colour : COLOR0;
  float4 uv1 : TEXCOORD0;
};
....
#endif
specifically boundVertexProgram->getNumInputs returns 5 but I have only 3 defined and it crashes on TANGENT but not on NORMAL. In Dx9 this worked fine. I'm also using ManualObject and I only call vertex(), color(), and texCoord() on it.

Maybe I'm doing something derpy but when I add both a normal and a tangent input to VS_IN it no longer crashes.

Edit: Not sure this works in DX9 or not because i didn't use struct declares in DX9 but defined them as argument on the function signature.
My blog here.
Game twitter here
LBDude
Gnome
Posts: 389
Joined: Mon Jul 26, 2010 10:53 pm
x 22

Re: DirectX 11 render system - work-in-progress

Post by LBDude »

hey I looked at OgreD3D11HLSLProgram::analizeMicrocode() and the D3D reflection stuff returns 5 input parameters instead of 3 like I defined. I'm not sure why it's doing that, it's almost like it's not parsing my second #defines and is using the input parameters from the first #define it sees. Of course I have to read the D3D docs to see if the minimum required number of input parameters is 5. Also another weird thing is if I disabled the normal and tangent part for the first #define the shader refuses to compile. Anyway this is probably very confusing to you guys and not that important. I mean I can get my program / shaders to run in DX11 now without crashing, so it's pretty much working for me. Just wondering why it doesn't like it when I only define 3 input parameters. Oh yeah I also traced ManualObject and it doesn't seem like it's doing anything wrong, I mean its' creating right numbers (3) for the hardware buffer declarations. I haven't looked at it closely tho.
My blog here.
Game twitter here
LBDude
Gnome
Posts: 389
Joined: Mon Jul 26, 2010 10:53 pm
x 22

Re: DirectX 11 render system - work-in-progress

Post by LBDude »

hey the above code I've posted should be:

Code: Select all

if( isTexture )
      {
         D3D11HardwarePixelBuffer *pBuffer[OGRE_MAX_RENDER_TARGETS];
         memset(pBuffer, 0, sizeof(pBuffer)); //set to null ptr, eg: std:fill(pBuffer, pBuffer + OGRE_MAX_RENDER_TARGETS, nullptr)
         renderTarget->getCustomAttribute( "BUFFER", &pBuffer );
         D3D11texture = static_cast<ID3D11Texture2D*>( pBuffer->getParentTexture()->getTextureResource() );
      }
Because you can't assume a renderTarget getCustomAttribute has only one render targets. I saw in DX9 some code such as the DepthBuffer code take this into account while other places it doesn't.
My blog here.
Game twitter here
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Re: DirectX 11 render system - work-in-progress

Post by Crashy »

As LBDude asked for it, here is the patch for MRT Support:

https://sourceforge.net/tracker/?func=d ... tid=302997

Tortoise Hg made some weird things whith the diff, I suspect some line ending character differences, but it should be fine. I'm not sure it's the best way to do MRT, but it's working like a charm on my side since a lot of weeks.
Follow la Moustache on Twitter or on Facebook
Image
Post Reply