100 boxes at 50fps?

Started by
13 comments, last by Dragon_Strike 16 years ago
shader isnt anything special...

matrix Projection;extern Texture2D baseTexture;SamplerState samLinear{    Filter = MIN_MAG_MIP_LINEAR;    AddressU = Wrap;    AddressV = Wrap;};// PS_INPUT - input variables to the pixel shader// This struct is created and fill in by the // vertex shaderstruct PS_INPUT{	float4 Pos : SV_POSITION;    float4 Color : COLOR0;    float2 TexCoord : TEXCOORD0;};////////////////////////////////////////////////// Vertex Shader - Main Function///////////////////////////////////////////////PS_INPUT VS(float4 Pos : POSITION, float2 TexCoord : TEXCOORD){	PS_INPUT psInput;		// Pass through both the position and the color    psInput.Pos = mul( Pos, Projection );	psInput.Color = float4(TexCoord,0.0,1.0);	psInput.TexCoord = TexCoord;    return psInput;}///////////////////////////////////////////////// Pixel Shader///////////////////////////////////////////////float4 PS(PS_INPUT psInput) : SV_Target{    return baseTexture.Sample( samLinear, psInput.TexCoord );}// Define the techniquetechnique10 Render{    pass P0    {        SetVertexShader( CompileShader( vs_4_0, VS() ) );        SetGeometryShader( NULL );        SetPixelShader( CompileShader( ps_4_0, PS() ) );    }}


and yea i set the shader and texture once... however i just noticed i set the input layout once for each box...


EDIT: fixed that... no big differance

EDIT2: removed texture sampling... no differance

[Edited by - Dragon_Strike on April 23, 2008 8:26:36 AM]
Advertisement
Some time ago, I also made a simple room with a lot of boxes at exactly the same place. It also gave me a serious fps-drop when those boxes where occupiing a great part of the screen. It is just a depth buffer issue. Every box gets drawn. so 100 boxes, each say 1280x1024 would use a lot of pixel processing power.
Someone who uses a, euhm..., delta!?
Poeple often underestimate the cost of overdraw...rendering a hundred boxes in the same place is drawing the same pixels 100 times because the default z-function testing is LessEqual.

The easy fix for this (if for some reason you really want to have 100s of objects in the same place) is to change the z-function to Less.

*40-50fps?? You're very close to 60hz. Are you sure Vsync is turned off? (and that the driver doesn't override that option?)

*Screen resolution?
It's not the same to draw 3600 vertices at 2500x2500 than 640x480

*And as said, you might be CPU limited. Try rendering the 100 cubes in one render call.

*I suppose the cubes are without textures.

Also... big thing: You're using D3D10 therefore, Win Vista. Win Vista uses 512MB only for kernel stuff.
Check that you're not low of RAM (you should have much more than 1gb to run Vista)
Laptops usually come in 512/1gb editions. Though, your's must be good since it comes with a 8600 gs

Cheers
Dark Sylinc
well i actually just noticed i dont ahve any depth testing whatsoever...

what am i doing wrong?

this is my renderdevice code..

#include "D3D10RenderDevice.hpp"#include "D3D10Exception.hpp"#include <iostream>namespace drone{    namespace d3d10{struct RenderDevice::Implementation{	Implementation(application::win32::WindowPtr window)	{		// Create the clear the DXGI_SWAP_CHAIN_DESC structure		DXGI_SWAP_CHAIN_DESC swapChainDesc;		ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));		// Fill in the needed values		swapChainDesc.BufferCount = 1;		swapChainDesc.BufferDesc.Width = 0;		swapChainDesc.BufferDesc.Height = 0;		swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;		swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;		swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;		swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;		swapChainDesc.OutputWindow = window->Wnd();		swapChainDesc.SampleDesc.Count = 1;		swapChainDesc.SampleDesc.Quality = 0;		swapChainDesc.Windowed = window->Windowed();		// Create the D3D device and the swap chain		HRESULT hr = D3D10CreateDeviceAndSwapChain(NULL, 												D3D10_DRIVER_TYPE_HARDWARE, 												NULL, 												0,												D3D10_SDK_VERSION, 												&swapChainDesc,												&pSwapChain_, 												&pD3DDevice_);		if(FAILED(hr))					throw Exception(L"Failed to create D3D10 device.", hr);				onWindowResize();	}	void onWindowResize()	{		////////////////////////////////		//	Create SwapChain		////////////////////////////////		DXGI_SWAP_CHAIN_DESC swapChainDesc;		pSwapChain_->GetDesc(&swapChainDesc);		pSwapChain_->ResizeBuffers( swapChainDesc.BufferCount, 0, 0, swapChainDesc.BufferDesc.Format, 0);		pSwapChain_->GetDesc(&swapChainDesc);		////////////////////////////////		//	Create Render Target View		////////////////////////////////				ID3D10Texture2DPtr pBackBuffer;		HRESULT hr = pSwapChain_->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);		if (FAILED(hr))				  throw Exception(L"Failed to get backbuffer.", hr);				// create the render target view		hr = pD3DDevice_->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView_);		if (FAILED(hr))					throw Exception(L"Failed to create render target view.", hr);				////////////////////////////////		//	Create a Depth-Stencil Resource		////////////////////////////////		ID3D10Texture2DPtr pDepthStencil;		D3D10_TEXTURE2D_DESC descDepth;		descDepth.Width = swapChainDesc.BufferDesc.Width;		descDepth.Height = swapChainDesc.BufferDesc.Height;		descDepth.MipLevels = 1;		descDepth.ArraySize = 1;		descDepth.Format = DXGI_FORMAT_D32_FLOAT;		descDepth.SampleDesc.Count = 1;		descDepth.SampleDesc.Quality = 0;		descDepth.Usage = D3D10_USAGE_DEFAULT;		descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;		descDepth.CPUAccessFlags = 0;		descDepth.MiscFlags = 0;		hr = pD3DDevice_->CreateTexture2D( &descDepth, NULL, &pDepthStencil );		if (FAILED(hr))					throw Exception(L"Failed to create depthstencil.", hr);		////////////////////////////////		//	Create Depth-Stencil State		////////////////////////////////		D3D10_DEPTH_STENCIL_DESC dsDesc;		// Depth test parameters		dsDesc.DepthEnable = true;		dsDesc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;		dsDesc.DepthFunc = D3D10_COMPARISON_LESS;		// Stencil test parameters		dsDesc.StencilEnable = true;		dsDesc.StencilReadMask = 0xFFFFFFFF;		dsDesc.StencilWriteMask = 0xFFFFFFFF;		// Stencil operations if pixel is front-facing		dsDesc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;		dsDesc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_INCR;		dsDesc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;		dsDesc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;		// Stencil operations if pixel is back-facing		dsDesc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;		dsDesc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_DECR;		dsDesc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;		dsDesc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;		// Create depth stencil state		ID3D10DepthStencilStatePtr pDSState;		pD3DDevice_->CreateDepthStencilState(&dsDesc, &pDSState);		////////////////////////////////		//	Create Depth Stencil		////////////////////////////////					// Bind depth stencil state		pD3DDevice_->OMSetDepthStencilState(pDSState, 1);		/*		D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;		descDSV.Format = DXGI_FORMAT_D32_FLOAT;//		descDSV.ResourceType = D3D10_RESOURCE_TEXTURE2D;//		descDSV.Texture2D.FirstArraySlice = 0;//		descDSV.Texture2D.ArraySize = 1;		descDSV.Texture2D.MipSlice = 0;*/				// Create the depth stencil view		hr = pD3DDevice_->CreateDepthStencilView( pDepthStencil, // Depth stencil texture												  NULL, // Depth stencil desc												  &pDepthStencilView_ );  // [out] Depth stencil view		if (FAILED(hr))					throw Exception(L"Failed to create depthstencil view.", hr);		// Bind the render target and depth stencil view		pD3DDevice_->OMSetRenderTargets( 1,          // One rendertarget view										 &pRenderTargetView_,      // Render target view, created earlier										 pDepthStencilView_ );     // Depth stencil view for the render target		////////////////////////////////		//	Create and set the viewport		////////////////////////////////		D3D10_VIEWPORT viewPort;		viewPort.Width = swapChainDesc.BufferDesc.Width;		viewPort.Height = swapChainDesc.BufferDesc.Height;		viewPort.MinDepth = 0.0f;		viewPort.MaxDepth = 1.0f;		viewPort.TopLeftX = 0;		viewPort.TopLeftY = 0;		pD3DDevice_->RSSetViewports(1, &viewPort);				////////////////////////////////		//	Create and set rasterizer state		////////////////////////////////		D3D10_RASTERIZER_DESC rasterDesc;		rasterDesc.FillMode = D3D10_FILL_SOLID;		rasterDesc.CullMode = D3D10_CULL_BACK;		rasterDesc.FrontCounterClockwise = true;		rasterDesc.DepthBias = false;		rasterDesc.DepthBiasClamp = 0;		rasterDesc.SlopeScaledDepthBias = 0;		rasterDesc.DepthClipEnable = false;		rasterDesc.ScissorEnable = false;		rasterDesc.MultisampleEnable = false;		rasterDesc.AntialiasedLineEnable = false;		ID3D10RasterizerStatePtr rasterstate;		pD3DDevice_->CreateRasterizerState(&rasterDesc, &rasterstate);		pD3DDevice_->RSSetState(rasterstate.get());		}	ID3D10DevicePtr            pD3DDevice_;	IDXGISwapChainPtr          pSwapChain_;	ID3D10RenderTargetViewPtr  pRenderTargetView_;	ID3D10DepthStencilViewPtr  pDepthStencilView_;}; RenderDevice::RenderDevice(application::win32::WindowPtr window) : pImpl_(new Implementation(window)){ 	 	std::wcout << ">> Created RenderDevice. (D3D10)\n";	}ID3D10Device*			RenderDevice::Device()			{ return pImpl_->pD3DDevice_.get();		}IDXGISwapChain*			RenderDevice::SwapChain()		{ return pImpl_->pSwapChain_.get();		}ID3D10RenderTargetView*	RenderDevice::RenderTarget()	{ return pImpl_->pRenderTargetView_.get();}ID3D10DepthStencilView*	RenderDevice::DepthStencil()	{ return pImpl_->pDepthStencilView_.get();}void RenderDevice::onWindowResize(){	pImpl_->onWindowResize();}HRESULT RenderDevice::BeginRendering(){	return Clear();}void RenderDevice::EndRendering(){	SwapChain()->Present(0,0);}HRESULT RenderDevice::Clear(bool pixel, bool depth, bool stencil){	if (pixel)		Device()->ClearRenderTargetView(RenderTarget(), D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f));	if (depth)		Device()->ClearDepthStencilView(DepthStencil(), D3D10_CLEAR_DEPTH, 1.0, 0); 	if (stencil)		Device()->ClearDepthStencilView(DepthStencil(), D3D10_CLEAR_STENCIL, 1.0, 0); 	return S_OK;}    } // d3d10} // drone

This topic is closed to new replies.

Advertisement