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

Mesh : 0.3sec pause in game on first render

3 posts in this topic

Help! - I get around a 0.3 second processing pause in my game when a Mesh first becomes visible and is fine thereafter. The problem disappears when I comment out the m_mesh->DrawSubSet(s); line but otherwise leave everything unchanged (including all the mesh creation, pre and post render processing). Nothing is flagged up using Directx9 debug output.

Initiation:
D3DXCreateMesh (m_meshData.m_attributes.size(),num_verts,D3DXMESH_MANAGED | D3DXMESH_WRITEONLY, elems, gd3dDevice, &m_mesh);

Optimization (same problem with or without):
m_mesh->GenerateAdjacency(EPSILON,NULL);
m_mesh->OptimizeInplace(D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE,NULL,NULL,NULL,NULL);

Rendered using an effect (unique to this mesh) created by:
D3DXCreateEffectFromFile(gd3dDevice, file, 0, 0, D3DXSHADER_DEBUG | D3DXSHADER_PREFER_FLOW_CONTROL, pool, &m_fx, &errors);

Could this be something happening on the GPU (eg. buffer locking issue... or somesuch)?- I show the various Directx9 usage flags....

Thanks for any help/ideas,
0

Share this post


Link to post
Share on other sites
Using the managed pool, you've got 2 copies of each vertex buffer and index buffer (and a D3DX mesh is really just vertex buffers and index buffers behind the scenes) - one stored in system memory and the other stored in video memory. When you first load a mesh (or any other managed pool resource) the system memory copy is what is loaded, so when you first use one for drawing with, the video memory copy needs to be brought up to date before the draw can occur. Hence the stall.

The solution is to get access to the vertex and index buffers behind the mesh and call [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb205884%28v=vs.85%29.aspx"]IDirect3DResource9::Preload[/url] on them, which - per the documentation - "indicates that the application will need this managed resource shortly" - i.e. load it directly into the video RAM copy and avoid the stall on first draw.

Sample code to do this might look something like this (warning: written off the top of my head and untested so please don't just copy/paste it):

[code]void PreloadMesh (ID3DXMesh *mesh)
{
IDirect3DVertexBuffer9 *meshVB = NULL;
IDirect3DIndexBuffer9 *meshIB = NULL;

if (SUCCEEDED (mesh->GetVertexBuffer (&meshVB)))
{
meshVB->PreLoad ();
meshVB->Release ();
}

if (SUCCEEDED (mesh->GetIndexBuffer (&meshIB)))
{
meshIB->PreLoad ();
meshIB->Release ();
}
}[/code]

(Additional note/disclaimer: it's not stated in the documentation but I'm assuming here that GetVertexBuffer and GetIndexBuffer will AddRef the buffers and therefore also require a Release - I don't use the ID3DXMesh interface myself so I don't have confirmation of this). Edited by mhagain
1

Share this post


Link to post
Share on other sites
What mhagain said. D3DX needs a copy for itself in case your device is lost.

Also if you happen to own an ATI Radeon HD 4000 to 7000, the drivers apparently do some black magic inside regarding storing the index buffers into system memory (rather than GPU memory) and introduce a small hiccup. You may experience this happens with all games that don't pre-render a few frames before showing actual input to give the drivers time to "warm up" (particularly, it's quite obvious in LA. Noire for these cards) as well in some SDK demos with heavy vertex & index count.

[b]Edit:[/b] Also, you do realise that you're passing D3DXSHADER_DEBUG to generate your shaders? (which isn't bad, but may explain the initial slowdown) Edited by Matias Goldberg
1

Share this post


Link to post
Share on other sites
Thanks Guys - what you say makes absolute sense to me. However - calling Preload() on the mesh buffers upon mesh creation (and OnRestore() for good measure) seems to make no difference - I understand that under some circumstance the GPU can ignore the Preload() command?... Also, there are no textures with the mesh - just geometry. My next step is to refactor my Mesh Class so that it manages the buffers itself... Will post progress. Also, the idea of doing a dummy initial render of all the objects to ensure they are fully loaded may be the way to go...

Update: It actually seems to be the ID3DXEffect resource causing the stall (the effect is unique to the mesh). If I render a dummy mesh initially using an identical effect (but duplicated), I still get the stall - but if I render the dummy mesh using the same effect resource I do not get the stall when my real mesh in the game first becomes visible. There doesn't seem to be a PreLoad() equivalent for ID3DXEffect... perhaps the only easy answer is to render all initially in some dummy frames (as suggested). Edited by Chris_J_H
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