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

Resizing buffers -> Out of memory

14 posts in this topic

Hello

 

After the loss of the d3d11 path in my engine i am currently reimplementing all the features.Right now im facing some issues when resizing my buffers which i never encountered before. The code im using for resize events (on WM_SIZE) is:

	void GxDeviceD3D11::onResize(uint32 w, uint32 h) {
		if (!mIsInitialized) {
			return;
		}

		mTargetHeight = h;
		mTargetWidth = w;
		mViewport.Height = static_cast<float>(mTargetHeight);
		mViewport.Width = static_cast<float>(mTargetWidth);

		mContext->OMSetRenderTargets(0, nullptr, nullptr);

		mMainRenderTargetView->Release();
		mMainDepthBufferView->Release();

		assert(SUCCEEDED(mSwapChain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0)));

		ID3D11Texture2D* backBuffer = nullptr;
		assert(SUCCEEDED(mSwapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer))));

		assert(SUCCEEDED(mDevice->CreateRenderTargetView(backBuffer, nullptr, &mMainRenderTargetView)));

		backBuffer->Release();

		mDepthBufferDesc.Height = mTargetHeight;
		mDepthBufferDesc.Width = mTargetWidth;

		mMainDepthTexture->Release();
		assert(SUCCEEDED(mDevice->CreateTexture2D(&mDepthBufferDesc, nullptr, &mMainDepthTexture)));

		memset(&mDepthViewDesc, 0, sizeof(mDepthViewDesc));

		mDepthViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
		mDepthViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;

		assert(SUCCEEDED(mDevice->CreateDepthStencilView(mMainDepthTexture, &mDepthViewDesc, &mMainDepthBufferView)));

		mContext->OMSetRenderTargets(1, &mMainRenderTargetView, mMainDepthBufferView);

		mContext->RSSetViewports(1, &mViewport);
	}

And the error i get:

D3D11 ERROR: ID3D11Device::RemoveDevice: Device removal has been triggered for the following reason (E_OUTOFMEMORY: The application tried to use more adapter memory than the Device can simultaneously accommodate. As a result, the TDR (Timeout Detection and Recovery) mechanism has been triggered. The current Device Context was executing commands when exhaustion occurred. The application needs to make less aggressive use of the display memory, perhaps by leveraging ClearState to ensure large Resources do not stay bound to the pipeline, or by leveraging information, such as DXGI_ADAPTER_DESC::DedicatedVideoMemory.). [ EXECUTION ERROR #378: DEVICE_REMOVAL_PROCESS_AT_FAULT]

Neither is the windows size very big nor are the values wrong.

 

If i comment out the ResizeBuffers and let the depth buffer its old size everything works fine, but as soon as im using ResizeBuffers and resize the window (when i let go of the window) it first halts for a while and then prints the error. If i only resize it a little it freezes for a second or two and then continues, but if i resize it more it freezes longer until i get the error message stated above. What could be the reason for that?

 

Greetings

Plerion

0

Share this post


Link to post
Share on other sites

I can't speak to why you're getting the error. I suspect it is related to releasing/resizing/etc. hundreds of times. If you call OnResize for every WM_SIZE message, that can be hundreds of times for a single frame resize drag. For small resizes, you're getting maybe only 10 or 15 calls, and you recover. For longer drags, maybe 100s of WM_SIZE messages. You only need to resize the buffers when:

 

a. You maximize the window (a single WM_SIZE message)

b. You restore the window from a maximized state (a single WM_SIZE message)

c. A WM_EXITSIZEMOVE message is received. That's sent only after the drag is complete. Here "drag" means either a drag-resize, or completion of moving the entire window via the title bar.

 

Try changing your message procedure something like this to see if it relieves the condition:


LRESULT YourEngine::MsgProc(...)
{
   static bool wasMaximized = false; // ASSUMING you don't start maximized!
   ...
    case WM_SIZE: // resize only if maximized, or restored from maximized - no WM_EXITSIZEMOVE sent in those cases
        if (wParam == SIZE_MAXIMIZED)
        {
            OnResize(...);
            wasMaximized = true;
        }
        else
        {
            if (wasMaximized) OnResize(...);
            wasMaximized = false;
        }
        return DefWindowProc(hWnd, message, wParam, lParam); // Windows may still need to play with the frame
    case WM_EXITSIZEMOVE: // the drag is complete.
        OnResize(...);
        break; // or return 0;

For a very minor efficiency, your OnResize should check if the window was, indeed, resized. I.e., the client rect size differs from the backbuffer size. If you move the window with a title bar drag, no need to resize.

Edited by Buckeye
0

Share this post


Link to post
Share on other sites

Hello all

 

Thanks for your replies. Ive checked again, nothing i create in the resize function is not released. As the error also appeared when all i had in the application was a texture, a pixel shader, a vertex shader, a 4 element vertex buffer and a 6 element index buffer i wasnt sure where to look for the memory leak (ClearState didnt change anything). As i understood resizing in d3d11 i dont have to release and recreate those like in d3d9. 

 

Now i checked mhagains first suggestion and changed onResize to:
 

void onResize(uint32 w, uint32 h) { mTargetHeight = h; mTargetWidth = w; mResizeRequested = true; }

and added a new function doResize which mainly does what has been in onResize before and after Present i call doResize. Right now the problem is gone, tho im now a bit worried if i just "covered" the real problem.

 

Greetings

Plerion

0

Share this post


Link to post
Share on other sites

That was a typo, sorry. After Present i call doResize.

 

I have also double checked, the shader resource view from the texture gets released.

0

Share this post


Link to post
Share on other sites

After Present i call doResize.

 

Why? Do you really need to change the buffer size (or check if it needs to be changed) every frame?

Edited by Buckeye
0

Share this post


Link to post
Share on other sites

 


After Present i call doResize.

 

Why? Do you really need to change the buffer size (or check if it needs to be changed) every frame?

 

 

Ok, third attempt: After Present if mRequestResize is true i call doResize.

0

Share this post


Link to post
Share on other sites
So did you fix the memory leak or just hide it?
I would suggest actually fixing it, especially now while it is manageable. If you move on to the next task you will never know what bug is lying in wait underneath all your code. You can never trust your foundation, and thus you can never trust anything you make with it.

It will crash that one time you send it to a company when you apply for a job.
Fix it now. Top priority.


L. Spiro
0

Share this post


Link to post
Share on other sites

Hello L. Spiro

 

The leak was hidden, if i move back to instantly resizing it crashes again. I dont know what i can release more, i have the following:

-> release render target view

-> no reference to the Texture2D of the backbuffer is held

-> all shader resource views are released

-> depth buffer view is released

-> depth buffer texture is released

-> ClearState is called

 

Not released are:

-> 1 Vertex & 1 Pixel shader

-> the Texture2D object in the textures (the view is recreated after resize)

-> depth stencil states

-> blend states

-> rasterizer states

-> sampler states

-> 1 Vertex buffer

-> 1 Index buffer

-> 1 Input layout

 

Greetings

Plerion

0

Share this post


Link to post
Share on other sites

A little updated:

Ive switched back to the one resize per frame approach and did a reportliveobjects at entersizemove and exitsizemove. This is what i get after resizing the window for over a minute (several thousand frames):

http://pastebin.com/Ekv4Wg54

 

The only thing odd are the 4500 references on the pixel shader. But the amount of objects seems reasonable.

0

Share this post


Link to post
Share on other sites

I had a similar issue with resizing my backbuffer on D3D11, perhaps its the same thing.  Does it only occur when you click and drag to resize your window?

 

Here's a little test to check if it's the same problem I had:

 

1. Open task manager in windows and go to the Performance tab, make you sure can see the current memory committed (e.g. 3.5/12GB or whatever it happens to be).

 

2. Run your app and click and [b]hold[/b] to resize the window, slowly move the mouse around without releasing the button and watch the commit amount in task manager.  As you move the mouse around, the commit amount should steadily climb a few GB quite rapidly until your app crashes with E_OUTOFMEMORY.

 

3. Run your app again, this time click and hold to resize the window less than required to crash it, but enough to increase the commit, while watching the memory commit amount, then release the mouse button.  When you release the button the commit amount should drop back to where it began, roughly.

 

If it's the same thing let me know and i'll write a longer post about what was causing it for me.

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