• 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
CdrTomalak

How many draw calls per frame are possible without awful performance?

10 posts in this topic

I have just completed attempts to write my own sprite batch class in C# using SlimDX, in direct response to performance problems in my game.

 

Basically I draw the game area (pacman) in tiles, with each tile drawn using a draw call to the sprite renderer object. I am now using a decent sprite renderer (http://sdxspritetext.codeplex.com/wikipage?title=Concepts%20of%20the%20SpriteRenderer) but find that my performance problem remains the same!

 

Basically I was fine with a 10x10 tile game area, but after scaling up to 30x15, the performance is terrble. Literally 5 frames per second.

 

How should I be handling the drawing of game tiles in this scenario? Or could there be something else wrong with the way in which I've got things set up?

 

My graphics device set-up code is as follows (excuse the mess):

 

		// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		// START: Method InitialiseGraphics
		// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		public void InitialiseGraphics()
		{
			bool debug=false;
			
			if(debug){MessageBox.Show( "InitialiseGraphics()...");}
			
			description = new SlimDX.DXGI.SwapChainDescription()
            {
                BufferCount = 2,
                Usage = SlimDX.DXGI.Usage.RenderTargetOutput,
                OutputHandle = this.Handle,
                IsWindowed = true,
                ModeDescription = new SlimDX.DXGI.ModeDescription(0, 0, new SlimDX.Rational(60, 1), SlimDX.DXGI.Format.R8G8B8A8_UNorm),
                SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0),
                Flags = SlimDX.DXGI.SwapChainFlags.AllowModeSwitch,
                SwapEffect = SlimDX.DXGI.SwapEffect.Discard
            };
		
			if(debug){MessageBox.Show( "InitialiseGraphics()...1");}
			
			SlimDX.Direct3D11.FeatureLevel[] featureLevels = new SlimDX.Direct3D11.FeatureLevel[] { SlimDX.Direct3D11.FeatureLevel.Level_10_1 };

			if(debug){MessageBox.Show( "InitialiseGraphics()...2");}
	
			// 02/09/12: Change constructor to enable text writing!
			SlimDX.Direct3D11.Device.CreateWithSwapChain(
				adapter1, 
				SlimDX.Direct3D11.DeviceCreationFlags.Debug, 
				featureLevels,
				description, 
				out graphics, 
				out swapChain
			);	
			
			if(debug){MessageBox.Show( "InitialiseGraphics()...3");}
			
			// create a view of our render target, which is the backbuffer of the swap chain we just created
			using (var resource = SlimDX.Direct3D11.Resource.FromSwapChain<SlimDX.Direct3D11.Texture2D>(swapChain, 0))
                renderTarget = new SlimDX.Direct3D11.RenderTargetView(graphics, resource);

				if(debug){MessageBox.Show( "InitialiseGraphics()...4");}
				
			// setting a viewport is required if you want to actually see anything
            context = graphics.ImmediateContext;
            var viewport = new SlimDX.Direct3D11.Viewport(0.0f, 0.0f, this.ClientSize.Width, this.ClientSize.Height);
            context.OutputMerger.SetTargets(renderTarget);
            context.Rasterizer.SetViewports(viewport);
			
			if(debug){MessageBox.Show( "InitialiseGraphics()...5");}
			
			bsd = new SlimDX.Direct3D11.BlendStateDescription();
			bsd.RenderTargets[0].BlendEnable = true;
			bsd.RenderTargets[0].SourceBlend = SlimDX.Direct3D11.BlendOption.SourceAlpha;
			bsd.RenderTargets[0].DestinationBlend = SlimDX.Direct3D11.BlendOption.InverseSourceAlpha;
			bsd.RenderTargets[0].BlendOperation = SlimDX.Direct3D11.BlendOperation.Add;
			bsd.RenderTargets[0].SourceBlendAlpha = SlimDX.Direct3D11.BlendOption.One;
			bsd.RenderTargets[0].DestinationBlendAlpha = SlimDX.Direct3D11.BlendOption.Zero;
			bsd.RenderTargets[0].BlendOperationAlpha = SlimDX.Direct3D11.BlendOperation.Add;
			bsd.RenderTargets[0].RenderTargetWriteMask = SlimDX.Direct3D11.ColorWriteMaskFlags.All;
			BlendState_Transparent = SlimDX.Direct3D11.BlendState.FromDescription(graphics, bsd);
			
			context.OutputMerger.BlendState = BlendState_Transparent;
			
			// ... END
			// ---------------------------------------------------------------------------------------------------------------------------
			
			if(debug){MessageBox.Show( "InitialiseGraphics()...5.5");}
			
			SlimDX.Direct3D11.RasterizerStateDescription rasterizerStateDescription = new SlimDX.Direct3D11.RasterizerStateDescription 
			{
				CullMode = SlimDX.Direct3D11.CullMode.None, 
				FillMode = SlimDX.Direct3D11.FillMode.Solid
			};
 
			context.Rasterizer.State = SlimDX.Direct3D11.RasterizerState.FromDescription(graphics, rasterizerStateDescription);
			
			if(debug){MessageBox.Show( "InitialiseGraphics()...6");}

			// load and compile the vertex shader (from the FX file)
            using (var bytecode = SlimDX.D3DCompiler.ShaderBytecode.CompileFromFile("D:\\Programming\\SharpDevelop_Projects\\SlimDX_StartOver\\BasicWindow_1\\BasicWindow_1\\triangle8.fx", "TextVS", "vs_4_0", SlimDX.D3DCompiler.ShaderFlags.None, SlimDX.D3DCompiler.EffectFlags.None))
            {
                inputSignature = SlimDX.D3DCompiler.ShaderSignature.GetInputSignature(bytecode);
                vertexShader = new SlimDX.Direct3D11.VertexShader(graphics, bytecode);
            } 
			
			if(debug){MessageBox.Show( "InitialiseGraphics()...7");}
			
			// load and compile the pixel shader (from the FX file)
            using (var bytecode = SlimDX.D3DCompiler.ShaderBytecode.CompileFromFile("D:\\Programming\\SharpDevelop_Projects\\SlimDX_StartOver\\BasicWindow_1\\BasicWindow_1\\triangle8.fx", "TextPS", "ps_4_0", SlimDX.D3DCompiler.ShaderFlags.None, SlimDX.D3DCompiler.EffectFlags.None))
                pixelShader = new SlimDX.Direct3D11.PixelShader(graphics, bytecode);
				
			if(debug){MessageBox.Show( "InitialiseGraphics()... TEXTURE CODE....2");}
			// SamplerDescription
			// GT 17/07/12: Check this against the DX11 book!!!!
			// 
			samplerDescription = new SlimDX.Direct3D11.SamplerDescription();
            samplerDescription.AddressU = SlimDX.Direct3D11.TextureAddressMode.Wrap;
            samplerDescription.AddressV = SlimDX.Direct3D11.TextureAddressMode.Wrap;
            samplerDescription.AddressW = SlimDX.Direct3D11.TextureAddressMode.Wrap;
			samplerDescription.ComparisonFunction = SlimDX.Direct3D11.Comparison.Never;
			samplerDescription.Filter = SlimDX.Direct3D11.Filter.MinPointMagMipLinear;
					
			if(debug){MessageBox.Show( "InitialiseGraphics()... TEXTURE CODE....3");}
			// SamplerState
			SlimDX.Direct3D11.SamplerState samplerState = SlimDX.Direct3D11.SamplerState.FromDescription(graphics, samplerDescription);
			
			if(debug){MessageBox.Show( "InitialiseGraphics()... TEXTURE CODE....4");}

            context.PixelShader.SetSampler(samplerState,0);
			
			if(debug){MessageBox.Show( "InitialiseGraphics()... TEXTURE CODE....7");}
			
			// 26/08/12: START
			// --------------------
			// INPUT ELEMENTS
			// ----------------------
			var elements = new[] { 
				new SlimDX.Direct3D11.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0),
				new SlimDX.Direct3D11.InputElement("TEXCOORD", 0, SlimDX.DXGI.Format.R32G32_Float, 0)
			};
			
			if(debug){MessageBox.Show( "InitialiseGraphics()... TEXTURE CODE....8");}
            
			layout = new SlimDX.Direct3D11.InputLayout(graphics, inputSignature, elements);
			
			if(debug){MessageBox.Show( "InitialiseGraphics()... TEXTURE CODE....9");}
			// --------------------------------------------------------------------------------------------------------------------
			
			// -------------------------------------------
			// INPUT ASSEMBLER: Layout & PrimitiveTopology
			// -------------------------------------------
			context.InputAssembler.InputLayout = layout;
			
			if(debug){MessageBox.Show( "InitialiseGraphics()... TEXTURE CODE....10");}

			context.InputAssembler.PrimitiveTopology = SlimDX.Direct3D11.PrimitiveTopology.TriangleStrip;
			// -----------------------------------------------------------------------
			
			if(debug){MessageBox.Show( "InitialiseGraphics()... TEXTURE CODE....11");}
			
			// Added these because of the awful crashing incident. Might fix it?
			// set the shaders
            context.VertexShader.Set(vertexShader);
            context.PixelShader.Set(pixelShader);
			
			if(debug){MessageBox.Show( "InitialiseGraphics()... TEXTURE CODE....12");}
			
			// Clear the screen...
			context.ClearRenderTargetView(renderTarget, new SlimDX.Color4(0.0f, 0.0f, 0.0f));
			// 26/08/12: END
			
			if(debug){MessageBox.Show( "InitialiseGraphics()... TEXTURE CODE....13");}
		}
		// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		// END: Method InitialiseGraphics
		// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

I'm slightly baffled, as I didn't think I'd hit this problem what with the power of hardware these days. Wierd. Clearly I'm doing something very silly.

 

blink.png

1

Share this post


Link to post
Share on other sites

Yep - initialise graphics once only at the start. The shader and buffer handling is all done via the SpriteTextRenderer library I'm using, so I'm assuming it's not the problem at the moment else I'd be doing Nico a dis-service.

 

I tend to agree with your assertion that this could be a problem with another algorithm in the game. I better get hunting for it!

0

Share this post


Link to post
Share on other sites

Something you might try is wrapping your Draw() and Update() sections with some debug timer output: find out where your time is being spent per-frame.

1

Share this post


Link to post
Share on other sites
Rather than optimizing your entire code base over the course of 3 months and then finding out that it was some esoteric compiler option why not just run a profiler?
2

Share this post


Link to post
Share on other sites

Good point. I'm not that clued up to be honest, but the profiler has revealed that the problem might be the expense of texture switching!

0

Share this post


Link to post
Share on other sites

Right then, I've just tried an experiment which results in every tile being drawn with the same texture, and this has improved the frame rate remarkably... 225 from 5!

0

Share this post


Link to post
Share on other sites

You could try sorting your tiles by texture before drawing them and seeing how that effects performance.

 

It would be helpful if you could post some of your drawing code (i.e. the bits that are called every frame) to see if there are any obvious issues in there that could be causing problems.

1

Share this post


Link to post
Share on other sites

Thanks all.

 

I have written a routine to group draw calls by texture, and this helps a massive amount. The game is now zipping along. The profiler has been really useful, and I'm a fool for not using it before!

0

Share this post


Link to post
Share on other sites

Thanks all.
 
I have written a routine to group draw calls by texture, and this helps a massive amount. The game is now zipping along. The profiler has been really useful, and I'm a fool for not using it before!

I can only speak for myself, but I wouldn't be here myself, if I wasnt a fool. smile.png
You can turn it around too, and say that any game developers that doesn't use gamedev as an awesome source of information and knowledge, is the greater fool!
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