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

Using the ARB_multi_draw_indirect command

13 posts in this topic

Hello,

 

Has anyone used the "ARB_multi_draw_indirect" command? Apparently it is supposed to make drawing much faster depending on the situation but I don't know how to use it.

 

My drawing code is currently a loop where I bind each item I want to draw with a VAO, send my MVP/Normal Matrix via glUniformMatrix* functions, send a UBO object with my materials/colors, and then do my glDrawElements(*) function.

 

But apparently using ARB_multi_draw_indirect is much faster.

 

Anyone have an example of it's use and how to use it correctly?

 

Thank you for your time.

 

 

0

Share this post


Link to post
Share on other sites

Thank you for your fast reply!

 

I reviewed the slides and coupled with your response this gives me a starting point.

 

The thing that immediately comes to mind for me is that I am using glDrawElements and not glDrawArrays. Should I change the code to use gl(Multi)DrawArrays or are there ways to use "ARB_multi_draw_indirect" with glDrawElements?

 

Thanks again.

0

Share this post


Link to post
Share on other sites

There's MultiDrawElements as well. You should go over the spec for the extension carefully:

https://www.opengl.org/registry/specs/ARB/multi_draw_indirect.txt

http://www.opengl.org/registry/specs/ARB/draw_indirect.txt

 

Thank you; I'll go over it. I am just so used to doing things fundamentally one way up until now and this seems much different.

 

So it is a little confusing.

 

My current code consists of:

 

*Setting up the VAO/VBO/Normals, etc*

                glGenVertexArrays(1, &Pointer_VAO);
		glBindVertexArray(Pointer_VAO);
	
		// Create Vertex Buffer Object
		glGenBuffers(1, &Vertex_VBO);

		// Save vertex attributes into GPU
		glBindBuffer(GL_ARRAY_BUFFER, Vertex_VBO);
		glBufferData(GL_ARRAY_BUFFER, TotalVertexCount * 4 * sizeof(float), Vertices, GL_STATIC_DRAW);
		glEnableVertexAttribArray(0);
		glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);

		delete[] Vertices;

		if (HasNormals)
		{
			glGenBuffers(1, &Normal_VBO);
			glBindBuffer(GL_ARRAY_BUFFER, Normal_VBO);
			glBufferData(GL_ARRAY_BUFFER, TotalVertexCount * 3 * sizeof(float), Normals, GL_STATIC_DRAW);
			glEnableVertexAttribArray(1);
			glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);

			delete[] Normals;
		}

		if (HasUVs)
		{
			glGenBuffers(1, &UV_VBO);
			glBindBuffer(GL_ARRAY_BUFFER, UV_VBO);
			glBufferData(GL_ARRAY_BUFFER, TotalVertexCount * 2 * sizeof(float), UVs, GL_STATIC_DRAW);
			glEnableVertexAttribArray(2);
			glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);

			delete[] UVs;
		}

		glGenBuffers(1, &Index_VBO);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Index_VBO);
		glBufferData(GL_ELEMENT_ARRAY_BUFFER, TotalPolygonCount * 3 * sizeof(unsigned int), Indices, GL_STATIC_DRAW);

		delete[] Indices;
		glBindVertexArray(0);

And my draw call later on in a loop, per VAO:

	glBindVertexArray(Pointer_VAO);
	glUniformMatrix3fv(CurrentOpenGLController->GetNormalMatrixID(), 1, GL_FALSE,
		glm::value_ptr(NormalMatrix));
	glUniformMatrix4fv(CurrentOpenGLController->GetUniformGlobalPositionID(), 1, GL_FALSE, glm::value_ptr(ModelViewProjectionMatrix));
	for (int i = 0; i < Materials.size(); i++) {
		glBufferData(GL_UNIFORM_BUFFER, sizeof(Materials[i].ColorProperties), Materials[i].ColorProperties, GL_DYNAMIC_DRAW);
		glDrawElements(GL_TRIANGLES, (Materials[i].TriangleCount * 3)
			, GL_UNSIGNED_INT, reinterpret_cast<const GLvoid *>(Materials[i].Offset * sizeof(unsigned int)));
	}

I am just trying to wrap my head around what needs to change.

 

But I am reading up on it.

 

Thank you for your time and assistance thus far...

0

Share this post


Link to post
Share on other sites

You won't gain anything by simply replacing each glDrawElements() call with a glMultiDrawElementsIndirect(). The whole point of glMultiDrawElementsIndirect() is to allow you to upload everything you need for all your draw calls to the GPU (using uniform buffers, texture buffers, bindless textures, sparse textures, etc) and then replace ALL your glDrawElements() calls with a single glMultiDrawElementsIndirect() call. As far as I know, glMultiDrawElementsIndirect() is not faster than glDrawElements() when simply used as a replacement for the latter.

 

I strongly recommend you take a look at this presentation http://www.slideshare.net/CassEveritt/beyond-porting which explains really well both the problems and how to solve them.

 

Thank you.

 

That's both what I figured and what I feared; I just started to understand OpenGL from the standpoint of making each draw call independently and now this comes along.

 

I apologize if I am asking many questions that seems like repeats; I am just trying to wrap my head around it as I understood it differently.

0

Share this post


Link to post
Share on other sites


then an additional ~8 ms is spent blocking on buffer swap (= waiting for the driver to complete the queued commands, e.g. C code (or something) in the driver)
As a rule of thumb, if you're blocking on swap/flip/present, you're either waiting for a vblank if you're vsyncing, or you're waiting for the GPU to catch up.

Measurements of "GPU load" are very misleading. You can be bottlenecked by the GPU without seeing it report 100% load...

0

Share this post


Link to post
Share on other sites

Remember to use timestamp queries for GPU timing. tmason, I think what you want to do is put all of your material parameters together in an array, and load it into a single buffer. Then you want to make a single MultiDraw call, and use DrawID in the shader to choose the correct material. That way you won't have that loop of calls anymore.

0

Share this post


Link to post
Share on other sites

 


then an additional ~8 ms is spent blocking on buffer swap (= waiting for the driver to complete the queued commands, e.g. C code (or something) in the driver)
As a rule of thumb, if you're blocking on swap/flip/present, you're either waiting for a vblank if you're vsyncing, or you're waiting for the GPU to catch up.

Measurements of "GPU load" are very misleading. You can be bottlenecked by the GPU without seeing it report 100% load...

 

 

Threaded optimization off:

    51 FPS

    Render time: 18.806 ms
    Swap time: 0.277 ms
    Frame time: 19.678 ms (also includes some UI rendering)
    GPU load: ~60%
 

Threaded optimization on: 

    61 FPS

    Render time: 9.185 ms
    Swap time: 5.739 ms
    Frame time: 15.727 ms

    GPU load: ~71%

 

I did not change a single line in my program. Threaded optimization on simply moves the cost of the render calls to the driver server thread (see the slides I posted above), and if the server thread lags behind it causes it to block on buffer swaps.

0

Share this post


Link to post
Share on other sites

Remember to use timestamp queries for GPU timing. tmason, I think what you want to do is put all of your material parameters together in an array, and load it into a single buffer. Then you want to make a single MultiDraw call, and use DrawID in the shader to choose the correct material. That way you won't have that loop of calls anymore.


Great, worth a shot. And this seems like something I can do even without using "ARB_multi_draw_indirect".

Of course, that command seems awesome but I can experiment slowly.
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