• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Migi0027

DX11
DX11 Rendering an Object the fastest way

4 posts in this topic

Hi guys,

my engine has come to a stage where instancing will be required, so what i do right now is somewhat like this:

void RenderFunc(..)
{
 renderAllLights

 RenderDiffuse

 If instancing: // This one knows if I'm rendering an instance
   RenderFunc(instance);
}

 

 

Now the thing is that I'm using one render function to render all meshes, is that a bad idea? My full render function looks like this:

 

void C3DEngineObject::RenderMesh(UMesh &mesh, bool recursive)
{
	#define Passes      mesh.passes  Passes is just a class containing information for the passes

	ObjectBuffer.AmbientColor = Passes.GlobalMaterial.AmbientColor;
	
	/////////PREPARE ALPHA SETTINGS////////////
	ObjectBuffer.Alpha = 1.0f;
	
	ObjectBuffer.Alpha = Passes.getAlpha();
	if (Passes.Lighting)
	{
		ObjectBuffer.Alpha += Lights.Directional.size();
		BlendStateManager.AlphaPass(devcon);
	}

	float alphaUp = 1.0f/ObjectBuffer.Alpha;
	ObjectBuffer.Alpha = 1.0f/ObjectBuffer.Alpha;

	#define AlphaStepUp ObjectBuffer.Alpha += alphaUp

	if (!recursive) // Don't send the buffers if recursive
		mesh.SendBuffers(devcon, dev, Camera, ObjectBuffer, Bufferphase);

	/////////RENDER LIGHTING/////////////////

	if (Passes.Lighting)
	{
		//////////////////////////////////////////////////
		////      For each directional light          ////
		//////////////////////////////////////////////////

		FOREACH (Lights.Directional.safe_size())
		{
			Shaders[7].ApplyShader(dev, devcon);

			// INJECT!
			Lights.Directional[i].Inject(FrameBuffer);

			Shaders[7].UpdateObject(ObjectBuffer, devcon);
			Shaders[7].UpdateWorld(FrameBuffer, devcon);
			//Shaders[7].SendRegBuffer(FrameBuffer, 1, 0, devcon);

			Shaders[7].Render(devcon, Bufferphase);

			// Step up one alpha
			AlphaStepUp;
		}
	}

	/////////RENDER THE MESH/////////////////

	for (int p = 1; p <= Passes.options; p++) // Get all the passes
	{
		if (Passes.getAt(p) == true) // Is this pass enabled?
		{
			int relative = Passes.getRelative(p); // If so, find the mat id.
			Material* active = getMaterial(relative, Passes); // Find the mat of the id

			active->ApplyMaterial(dev, devcon);

			active->ShaderRef->UpdateObject(ObjectBuffer, devcon); // Send the object and world buffers
			active->ShaderRef->UpdateWorld(FrameBuffer, devcon);

			if (relative == BUMPMAP_SHADER) // Is this bump mapping?
			{
				MatrixBuffer.world = ObjectBuffer.Final;
				active->ShaderRef->UpdateMatrix(MatrixBuffer, devcon);
				active->ShaderRef->SendTexture(Passes.base->pTexture, 0, devcon);
				active->ShaderRef->SendTexture(Passes.bumpmap->pTexture, 1, devcon);
			}

			if (relative == TEXTURE_SHADER) // Texturing?
			{
				active->ShaderRef->SendTexture(Passes.base->pTexture, 0, devcon);
				//active->ShaderRef->SendTexture(Passes.opacityMap->pTexture, 1, devcon);
			}


			if (mesh.Instanced && !recursive) // Is this mesh instanced
			{
				FOREACH (mesh.InstancedData.size()) // For all instances
				{
					mesh.SendInstancedData(ObjectBuffer, Camera, i, Bufferphase); // Send the location, rotation and scaling of this instance.

					RenderMesh(mesh, true); // Call this function, with recursive true so the origional matrixes wont be re-sent (removing the instance loc,rot and scaling).
				}
			}

			// Render the mesh in diffuse mode
			active->Render(devcon, Bufferphase);

			// Step up one alpha
			AlphaStepUp;
		}
	}

	if (recursive)
		return;

	BlendStateManager.RestoreBlendState(devcon);
}

 

 

PS. The mesh.passes is just a class with contains the passes(e.g. Texture, shadows, Lighting).

Now if you look at my code, in each pass it checks if it is bump mapping or texturing, but is this a slow method, how could it be improved? Or even better, how can it be improved in the concept of instancing?

Also if you have time, it could be nice if you could post a good way of handling mesh rendering, or an efficient method, as I'm just following my minds advice, and not a professional persons advice.

Also, how much time does it take to check if a bool is true?

Thank You

Edited by Migi0027
0

Share this post


Link to post
Share on other sites

It seems to me like you are looking for improvements without a strong need in mind, which will make it very hard to find a solution that you are looking for.  Ultimately, you will find that normally the CPU side manipulations account for a fairly small amount of work in the grand scheme of things unless you are using lots and lots of small objects.  However, even in that case, the GPU work being done can often take up more time than the CPU side - meaning that any optimization on the CPU side won't make any difference to the end result framerate.

 

For your specific question about testing a bool - it is pretty much one of the fastest operations that exist, so you don't need to worry about changing that.  You should invest some time in learning how to use profiling tools (free or otherwise) and also tools like PIX/Graphics Debugger to learn more about the performance of your engine/app.  That will allow you to pinpoint the bottlenecks and make effective use of your optimization time.

0

Share this post


Link to post
Share on other sites

Thanks Jason Z, though I already knew of the profiling tools, I never really put any effort into it, but they(tools) actually impress me!

0

Share this post


Link to post
Share on other sites

Most of the loss of performance is /not/ the draw calls, but a Game Engine's utilization of them... 

 

From an architectural point of view, the code hint that you may not be implementing standard "Separation of Concerns" patterns, (ensuring that methods/classes don't do more than one thing, but rather responsible for doing a specialized purpose). 

 

In other words, at this stage, I believe everyone would agree that getting your engine do to what you want is more important than the performance.

 

For example, you are using a "renderfunc"  and "rendermesh" function names: Okay, I know this sounds a little out of left field for being, nitpicky, but bear with me ... Rather than, RenderScene, -> RenderEachLayout  -> RenderBufferSet -> RenderBufferPartitions ->  or some other rendering step in the context of your Game Engine's OWN Pipeline.

 

In a game engine, there is /massive/ importance on the efficient management of the associations between Modeling entities, specifically:

1. Scenes to Layouts

2. Layouts To Buffers

3. Buffers to Buffer Partitions, Shaders, etc

4. Model to: (Mesh, Behaviors, Textures, Shaders, etc)

5. Many Textures to Many Models and Meshes

6. Many Meshes to Many Models

7. and the list goes on and on and on and on.

 

The GPU operations are /fast/ ....  Managing memory, garbage collection, managing collections in memory that are hundreds of megabytes, etc, is one of the biggest game performance hits.  This is where a lot of your optimizations will need to occur.  As horrible as it sounds, use place holder shaders, textures, etc at first, (greyscale gradients, etc), to ensure your Game Engine's Framework is working right.

 

In other words, pick a game engine feature, set of features that you want, program towards them, and find out if those features are running slow or not, then performance tune them.

 

Stage 1 Features:

1. Rendering Multiple Instances of the Same Model definition.  (sidewalk squares)

2. Rendering Multiple Instances of the Same Model, but with different Shaders,  (stars, the same car but different color, etc)

3. Rendering Multiple Types of Models, (Tree, Sidewalk Square, etc)

4. Pre-Defined animations for a subset of models, (rotations, movement/translation in a circle pattern, movement along a Bezier, whatever).

5. User Driven Movement,

6. etc.

 

There are a /lot/ of design patterns that can be used to organize the complexity of the code, so that the application will scale appropriately with the features you want.

 

You may think that implementing facades, multiton, or factory design patterns are a /lot/ of overhead for a small program, but in actuality this is not the case as compilers optimize and inline what needs to be. 

 

Still, the point that I am trying to make, the use of Design Patterns, and the avoidance of Anti-Patterns in a game engine is what is going to always be what will determine your game engine's performance story.

 

Then, there are fancy shmancy GPU render operations... See, the funny thing about fancy shmancy GPU operations is that /only if/ your architecture is "sound" in the first place, can you implement GPU operations on a priority basis, (maybe ensure that that that fancy shmancy model never attempts to get rendered more than once a frame, or maybe once every two frames, (there is a LOT of overrendering in games).

 

Architectural techniques and optimizations are probably where you want to start off first when facing performance problems, and regardless, you will be able to do more with your engine anyway.

Edited by e.s.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • By YixunLiu
      Hi,
      I have a surface mesh and I want to use a cone to cut a hole on the surface mesh.
      Anybody know a fast method to calculate the intersected boundary of these two geometries?
       
      Thanks.
       
      YL
       
    • By hiya83
      Hi, I tried searching for this but either I failed or couldn't find anything. I know there's D11/D12 interop and there are extensions for GL/D11 (though not very efficient). I was wondering if there's any Vulkan/D11 or Vulkan/D12 interop?
      Thanks!
    • By lonewolff
      Hi Guys,
      I am just wondering if it is possible to acquire the address of the backbuffer if an API (based on DX11) only exposes the 'device' and 'context' pointers?
      Any advice would be greatly appreciated
    • By MarcusAseth
      bool InitDirect3D::Init() { if (!D3DApp::Init()) { return false; } //Additional Initialization //Disable Alt+Enter Fullscreen Toggle shortkey IDXGIFactory* factory; CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&factory)); factory->MakeWindowAssociation(mhWindow, DXGI_MWA_NO_WINDOW_CHANGES); factory->Release(); return true; }  
      As stated on the title and displayed on the code above, regardless of it Alt+Enter still takes effect...
      I recall something from the book during the swapChain creation, where in order to create it one has to use the same factory used to create the ID3D11Device, therefore I tested and indeed using that same factory indeed it work.
      How is that one particular factory related to my window and how come the MakeWindowAssociation won't take effect with a newly created factory?
      Also what's even the point of being able to create this Factories if they won't work,?(except from that one associated with the ID3D11Device) 
    • By ProfL
      Can anyone recommend a wrapper for Direct3D 11 that is similarly simple to use as SFML? I don't need all the image formats etc. BUT I want a simple way to open a window, allocate a texture, buffer, shader.
  • Popular Now