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

Is GLM fast enough for games?

10 posts in this topic

So I'm starting work on a little game engine with a friend of mine. As of now I'm tasked with the graphics side of things. I am willing and able to write the proper vector, matrix and quaternion classes with SIMD/SSE but GLM seems attractive. 

 

What I would like to know is, is GLM fast? fast enough for a simple game? Are there benchmarks to compare it with someones native code?

 

Obviously if it's fast it might just be advantageous to use GLM instead of writing and debugging my own stuff. Another question is, would there be compatibility or speed issues using GLM with Direct3D?

 

 

Thanks a ton. 

0

Share this post


Link to post
Share on other sites

I have no idea what I'm talking about, but I just introduced about 6 lines of GLM to replace 30 lines of code I had, and instead of taking about 6 seconds to start up, now it takes 30+ seconds. This is in the init phase of the game. I tried using it during the game loop and it froze. I didn't wait long enough to see if it ever unfroze so I can't say for sure if the GLM was really slow or if I made a mistake with my code. Also, on my friend's computer there is never a delay no matter what I do (she has a gaming rig) so it could just be I have a crap computer. Hope that helps :-)

0

Share this post


Link to post
Share on other sites
GLM the OpenGL mathematics library?


Speed and performance are all relative. Some games will push out billions of polygons per frame. Some games will have minimal to no graphics. What is perfect for one game may be unusable in another.
0

Share this post


Link to post
Share on other sites

What is perfect for one game may be unusable in another.

 

Yeah, but when talking about vector math operations I don't think anyone has ever complained that it was "too fast".

 

Take into consideration that this engine would want to push polys at around the One hundred thousand to million range.

0

Share this post


Link to post
Share on other sites

Obviously if it's fast it might just be advantageous to use GLM instead of writing and debugging my own stuff. Another question is, would there be compatibility or speed issues using GLM with Direct3D?

GLM is a math library that tries to be close to OpenGL conventions (ie vec4 instead of float4), it doesn't depends on OpenGL calls as far as I know (it shouldn't have any reason to). Anyway, you'll have to watch out for column-major matrices and right handed coordinate system that GLM uses.

 

Here's a link I found http://msdn.microsoft.com/en-us/library/windows/desktop/bb204853(v=vs.85).aspx

 

You can check GLM sources if you're doubting their quality.

Edited by TheChubu
0

Share this post


Link to post
Share on other sites

I am using GLM, I don't know performance-wise but their API is really good and does exactly what you want and no more. I couldn't ask for a better math library.

0

Share this post


Link to post
Share on other sites

I have no idea what I'm talking about, but I just introduced about 6 lines of GLM to replace 30 lines of code I had, and instead of taking about 6 seconds to start up, now it takes 30+ seconds.

 

Possibly caused by the initialization time for the static SSE constants?

 


I tried using it during the game loop and it froze.

 

I assume that's because you're not aligning your data structures properly, and so the SSE instructions are therefore crashing the app. An easy way to tell is to look at the addresses within a debugger. If the HEX memory location ends in anything other than zero, your data structure is unaligned.

0

Share this post


Link to post
Share on other sites

The performance of glm shouldn't matter too much, relatively speaking.  A typical sequence for an object in a game might look something like this:

  • Declare a transformation matrix for the object.
  • Perform a few matrix ops (typically no more than 4 or 5).
  • Load the matrix to a shader uniform.
  • Draw hundreds or thousands of triangles.

So the actual proportion of your program where your choice of matrix library can have a measurable impact is really quite miniscule, and if it's otherwise then you may be doing something highly unusual.

0

Share this post


Link to post
Share on other sites

Unless you have a lot of experience and invest a lot of time, GLM is as good or better than anything you can write performance-wise. It's likely better than anything I could write in finite time, anyway.

 

That, and it just works, and it "looks" the same as GLSL, which is a big plus.

 

As for SSE implementations, GLM has them, at least in some places, but they don't make much of a difference anyway. SSE is good for whacking through long streams of SoA data, but it is pretty useless for doing a few dozen dot products or multiplying 3-4 matrices, or for any data that you normally have (because AoS is the natural thing, not SoA). You have to work really hard to make SSE truly useful (other than in a contrieved, artificial example).

Special applications like audio/video codecs are of course an exception, but this is not surprising, it's what SSE was made for after all.

 

If your SSE-optimized dot product saves 1-2 cycles compared to a C implementation (compiled with optimizations turned on) you can consider yourself a happy man. So what, one branch prediction gone wrong costs 7-8 times as much.

 

If your quaternion/vector multiply saves 5-6 clock cycles, you're lucky. So even if you calculate a thousand of them per frame (for skeletal animation, or whatever) that's 5,000 clocks. Big thing. If that's an issue, then don't you ever dare making a call to a D3D function, or even access the disk.

Edited by samoth
1

Share this post


Link to post
Share on other sites

In your original post you asked about compatibility issues between GLM and Direct3D. If you're going to be using Direct3D for your graphics, just use DirectXMath for your math library.

 

DirectXMath is the public version of XNA Math - the math library that's part of the Xbox 360 Dev Kit (XDK) used by game companies to develop Xbox 360 games. It already utilizes SSE and SSE2 instructions and is about as fast as you can get.

 

Cheers and good luck!

0

Share this post


Link to post
Share on other sites

It already utilizes SSE and SSE2 instructions and is about as fast as you can get.

 

*Some* of it utilizes SSE, but you'd need to use the aligned types to make the most out of it. Even then, it's not as fast as you can get, for that you'd need SOA data structures.

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