Unable to use DX11

Problems building or running the engine, queries about how to use features etc.
Post Reply
caduceus
Goblin
Posts: 224
Joined: Tue May 08, 2012 6:39 am

Unable to use DX11

Post by caduceus »

I am updating my application to use DX11 render system but I am getting following exception:

Code: Select all

 OGRE EXCEPTION(3:RenderingAPIException): Attempted to render to a D3D11 device without both vertex and fragment shaders there is no fixed pipeline in d3d11 - use the RTSS or write custom shaders. in D3D11RenderSystem::_render at ....\OgreD3D11RenderSystem.cpp (line 2496)
I followed the sample browser and installed listener ShaderGeneratorTechniqueResolverListener and can see that the shaders are being created in cache folder but still I am getting exception. Please guide me as what i might be doing wrong.
amartin
Halfling
Posts: 87
Joined: Wed Aug 14, 2013 6:55 am
Location: Norway
x 13

Re: Unable to use DX11

Post by amartin »

There are some things to watch out for when working with DX11. It does work but it takes some effort to make sure that everything is using both fragment and vertex shaders.

Ogre.txt will have any errors loading shaders so check this to make sure all your shaders are loading properly.
The default material does not use shaders so you either need to make sure it never appears or use the Real Time Shader System (RTSS) to give it shaders.
Compositors also need full shaders so if you use one you'll need to make sure it has both fragment a vertex shader.
I had some issues with lazy shader creation using the RTSS so if you are using it try forcing it to create the materials you need.

Code: Select all

mShaderGenerator->createShaderBasedTechnique(...)
You are going to keep getting that exception till absolutely everything that you render has a fragment and a vertex shader. I would suggest if you are having problems figuring out what is causing the issue cut your scene back to nothing and work you're way back up till everything is in place again. Shader compile problems and missing materials were my main problems.

You can if you want setup your project to use a second scene for a while and just add one object at a time to it till you have worked through all your resources when they work swap back to the main system since it sounds like you have an existing system which might be complicated to selectively disable.
caduceus
Goblin
Posts: 224
Joined: Tue May 08, 2012 6:39 am

Re: Unable to use DX11

Post by caduceus »

Thank you amartin for your reply. I am working on big project and it is hard to go through each and every code line to find the possible issues. Is there any debug info that Ogre generated that can help to pin point the issue.
amartin
Halfling
Posts: 87
Joined: Wed Aug 14, 2013 6:55 am
Location: Norway
x 13

Re: Unable to use DX11

Post by amartin »

I'm kind of shooting blind here since I have no idea what your code looks like or does. The problem is simple you have 1 or more materials missing 1 or more shaders. The solution really depends on why they are missing shaders.

The good new is. If your project is running in dx9 then your code will be fine unless you are procedurally generating manual objects or materials. Any code that is not related to creating or adding entities to the scene graph can be ignored for debugging this.

Apart from the Ogre.txt there isn't much information output however with the debug libraries loaded you should be able to break when the exception is thrown. Once you are at that point you can go back up the call stack till you get to a level where the material name is available. This is handled pretty deep in the Dx11 render system but is possible if you get really stuck. I had to do this for a few materials.

You could probably brute force it if you want to by writing a method the checks the entire material manager to make sure all the materials are defined with shaders and output the names of any that are not so you can focus on them.

Hope that helps you'll need to find out what materials are not working and how they are being created before I can give anymore advice on this.
User avatar
tod
Troll
Posts: 1394
Joined: Wed Aug 02, 2006 9:41 am
Location: Bucharest
x 94
Contact:

Re: Unable to use DX11

Post by tod »

You could also write a small utility to parse the material files and find the materials that contain no vertex/fragment shader declaration. Material inheritance will complicate things a bit, but I think this is doable.
caduceus
Goblin
Posts: 224
Joined: Tue May 08, 2012 6:39 am

Re: Unable to use DX11

Post by caduceus »

Thank you for all the inputs, now I identified the materials which were giving me errors and rectified like this

Code: Select all

	Ogre::RTShader::ShaderGenerator::getSingleton().createShaderBasedTechnique(m_name, Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
	Ogre::RTShader::ShaderGenerator::getSingleton().validateMaterial(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, m_name);
	if(m_material->getNumTechniques() > 1)
    {
		m_material->getTechnique(0)->getPass(0)->setVertexProgram(
		m_material->getTechnique(1)->getPass(0)->getVertexProgram()->getName());
		m_material->getTechnique(0)->getPass(0)->setFragmentProgram(
		m_material->getTechnique(1)->getPass(0)->getFragmentProgram()->getName());
    }
This code will generate shaders for that and that Ogre exception that I was getting is gone but I still do not see any output on screen. Its all blank.
amartin
Halfling
Posts: 87
Joined: Wed Aug 14, 2013 6:55 am
Location: Norway
x 13

Re: Unable to use DX11

Post by amartin »

Does your program display anything at when run in Directx9? It sounds like you either don't have lighting or your shaders are not working properly.

Also why the extra check after validation where you set technique 0 to the shader from technique 1?

Edit*
Since I just remembered directx 11 works differently when clearing viewports it no longer supports partial clearing. So if you are using mutliple viewports or multiple renders per frame you might want to set.

Code: Select all

m_RenderWindow->setClearEveryFrame(false);
User avatar
Aiden
Halfling
Posts: 54
Joined: Fri Jul 14, 2017 3:16 pm
x 5

Re: Unable to use DX11

Post by Aiden »

caduceus wrote: I identified the materials which were giving me errors and rectified like this
Hi guys,
I've just ported my code to Ogre2.0. Sorry for waking this thead after a long time.
I managed to modify the code above, but it seems it crushes when setting fragment programon some techniques, is there a way to fix this ?

Code: Select all

		Ogre::MaterialManager  *matman = Ogre::MaterialManager::getSingletonPtr();
		Ogre::ResourceManager::ResourceMapIterator materialIterator = matman->getResourceIterator();
		while (materialIterator.hasMoreElements())
		{
			boost::filesystem::path p(materialIterator.peekNextValue()->getName());
			shaderGenerator.createShaderBasedTechnique(p.filename().string(), Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
			Ogre::RTShader::ShaderGenerator::getSingleton().validateMaterial(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, p.filename().string());
		
			if(!matman->getByName(p.filename().string()).isNull())
			if (matman->getByName(p.filename().string())->getNumTechniques() > 1)
			{
				std::cout << "XXXXXXXXXXX---CONVERTING:" << p.filename().string() << "---XXXXXXXXXXX" << std::endl;
				matman->getByName(p.filename().string())->getTechnique(0)->getPass(0)->setVertexProgram(
				matman->getByName(p.filename().string())->getTechnique(1)->getPass(0)->getVertexProgram()->getName());
				matman->getByName(p.filename().string())->getTechnique(0)->getPass(0)->setFragmentProgram(
				matman->getByName(p.filename().string())->getTechnique(1)->getPass(0)->getFragmentProgram()->getName());
			}
			
				materialIterator.moveNext();
		
		}
Post Reply