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

OpenGL
Programming OpenGL using Assembly ASM

20 posts in this topic

Hi I have been writing OpenGL using C++ for a long while. Now I want to write faster applications, so I have decided to go for a lower level programming language so I have enquired about Assembly. I have the ASM code for various APIs, except OpenGL, so can someone recommend OpenGL programming tutorials using ASM, from beginners to advanced level will suffice. Nehe doesnt seem to have many features on ASM coding. Helping me with finding good links will help me in a big way.Thank you for now and forever Regards
0

Share this post


Link to post
Share on other sites
As stated by my previous post, i dont need general OpenGL tutorial as I stated clearly Nehe doesnt have the details that I need. Read the message as i clearly need Assembly tutorials or information that strictly which deals with openGL.
Thanks anyway...
0

Share this post


Link to post
Share on other sites
Why on Earth would you want to program OpenGL with assembly? I doubt that you'll be able to make faster applications that way. Dealing with OpenGL mostly just involves a bunch of function calls anyway, coding them manually in assembly won't improve performance at all.
If you're doing some heavy computations on the CPU then you might want to use SSE instructions, but that doesn't really have much to do with OpenGL.
0

Share this post


Link to post
Share on other sites
Well im taking the word of experienced Demo programmers who swear that by programming in assembly, improves performance as the lower the level of language, the faster the execution and the smaller the final executable will be. Assembly is used my most if not all top level graphics and application programmers (especially console game programmers, who always point out the importance of using low-level machine code in their apps). I am far away from that level of experience as im more of an enthusiast. I like to see which ways can improve the performance if possible. I am not saying it will 100% guarantee a faster program, but i want to see if these tutorials exist so I can see for myself...
0

Share this post


Link to post
Share on other sites
Hmm it's possible you misunderstood slightly [smile]

Assembler is usefull for optermising certain parts of the code AFTER profiling, however in the majority of cases the code will be done in something like C or C++ first. Ofcourse the exception to this rule are the demo scene coders who are making small apps (64k intros and the like).

Seriously, apart from certain parts of a program where profiling and detailed knowledge of whats going on with the data can help you tune the code, most of the time the C or C++ compiler is going to produce MUCH better code than you can buy hand. CPU's these days are VERY complex beasties, you can infact end up doing things much slower if you dont know what you are doing.

That all said, if you want to go down that road then using OpenGL from Assembler is much like using it from C, C++ or any other language, you are just making function calls, infact i'm pretty certain modern assembler compilers can perform C-style function calls for you, without you having to worry about the ins and outs of it, you'll have to look that up in the docs for your tool of choice.

Nehe does have the tutorial code converted to assembler, at least in the first case and if you are serious about working on such a low level then you need to get into the habbit of solving these things for yourself anyways, so its probably a good time to start.
0

Share this post


Link to post
Share on other sites
What he said.

Don't go down that road, it's not worth it. At least know that if you do it, what you gain will not be performance, but additional knowledge(knowing ASM never hurt anybody). Do you think the Doom3 engine for example(and any other top-notch game) is coded in assembly? Nope, it's C/C++. I really doubt even if 64K(an artificial boundary) demo coders use assembly*. For the most parts, they could just use a really lightweight C compiler.

Quote:

...improves performance as the lower the level of language, the faster the execution and the smaller the final executable will be.


I would argue that, the better the programmer is, the faster the execution and the better the program mechanics will be. There is absolutely no need to write an entire program in assembly. You can use C/C++ or other higher level languanges and use the inline assembler for the most critical parts of the code.
In any case, the choise of languange has very little to do with the execution speed of OpenGL itself, which resides in the drivers and the GPU, not in your code.

*Proof: Taken directly from the .kkreiger faq(the FPS game in 96KB, made by the same guys who developed .the .product demo):

Quote:

In general, if you have any technical questions concerning .kkrieger, either refer to our
web site or contact us via email. However past experience shows that there are some rumours
and misunderstandings about our work that are very hard to correct, so we'll state the truth
here, in written form, for all the world to see :)

-We do .not. have some kind of magical data compression machine that is able to squeeze
hundreds of megabytes of mesh/texture and sound data into 96k. We merely store the
individual steps employed by the artists to produce their textures and meshes, in a very
compact way. This allows us to get .much. higher data density than is achievable with
normal data compression techniques, at some expense in artistic freedom and loading times.

- .kkrieger is not written in 100% assembler/machine language. Not even nearly. Like the
vast majority of game projects being developed today, .kkrieger was mostly written in
C++, with some tiny bits of assembler where it is actually advantageous (notably, there
are a lot of MMX optimisations in the texture generator).

- A kilobyte is, historically, defined to be 1024 (2^10) bytes, not 1000. Thus .kkrieger is
a game in 96k even though it's actually 98304 bytes.
- The concept of the texture/mesh generators was developed by fiver2. We do .not. want to
claim that the techniques we used to develop .kkrieger are new inventions. It´s rather a
selection of useful operations and their parameters to optimise the results.


[Edited by - mikeman on October 12, 2005 7:36:41 AM]
0

Share this post


Link to post
Share on other sites
Thanks Phantom and Mikeman. Your views are more than appreciated as you are right about the function calls of openGL. It wont hurt learning from here and learning a little assembly. I might just first of all learn how to write inline asembly inside my C++ code. It wont possibly make much difference if any. As i am trying to find alternate ways to push that extra bit of power out of my application. It looks like all you guys who have replied are right. Stick to what i know best - C++, as it is still the best programming language there is available.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom

Seriously, apart from certain parts of a program where profiling and detailed knowledge of whats going on with the data can help you tune the code, most of the time the C or C++ compiler is going to produce MUCH better code than you can buy hand. CPU's these days are VERY complex beasties,


I get tired of hearing this kind of exaggerated claim of compiler efficacy and quality. It has never been true and it is not going to be true. The reason is that CPU instruction sets keep changing and by the time someone's starting to bother to utilize CPU-specific optimizations, another CPU has come out and the whole thing starts all over again. It is, seemingly, too much work for the industry to keep up with. A lot of markets aren't driven by compiler performance, but rather by IDE GUI builder niceties, so this is another part of why the Any Good Compiler of academic legend never exists in industrial practice.

That said, yes you can waste your time writing ASM code for things that are pointless / no faster than what the compiler will produce. It's important to know what kind of ASM code your compiler will produce and what it won't. And, um, don't fear the 'complexity' of the CPUs. It's just a learning curve same as any other stupid API in industry. Just as funky and just as pedestrian once you finally know all the details.
0

Share this post


Link to post
Share on other sites
Don't forget that good optimizing compilers will usually be able to produce very good assembly code out of your C++ code, many times at least as fast as yours. Use assembly only when your assembly is faster than the compiler generated code, usually where the code can benefit from SSE/MMX instructions.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by vanevery0
Quote:
Original post by phantom

Seriously, apart from certain parts of a program where profiling and detailed knowledge of whats going on with the data can help you tune the code, most of the time the C or C++ compiler is going to produce MUCH better code than you can buy hand. CPU's these days are VERY complex beasties,


I get tired of hearing this kind of exaggerated claim of compiler efficacy and quality. It has never been true and it is not going to be true. The reason is that CPU instruction sets keep changing and by the time someone's starting to bother to utilize CPU-specific optimizations, another CPU has come out and the whole thing starts all over again. It is, seemingly, too much work for the industry to keep up with. A lot of markets aren't driven by compiler performance, but rather by IDE GUI builder niceties, so this is another part of why the Any Good Compiler of academic legend never exists in industrial practice.

That said, yes you can waste your time writing ASM code for things that are pointless / no faster than what the compiler will produce. It's important to know what kind of ASM code your compiler will produce and what it won't. And, um, don't fear the 'complexity' of the CPUs. It's just a learning curve same as any other stupid API in industry. Just as funky and just as pedestrian once you finally know all the details.


I think when phantom said "much better code than you" meant the OP, as a beginner or even medium-level in assembly, which is the majority of the already limited crowd that even know anything about ASM. Modern compilers are in fact more than able to achieve great optimizations, but there's no doubt that proficient programmers in ASM can produce specialized code even better than that. The point is to know where it will make a difference and where it will not.

As for the complexity of the CPUs, I only partly agree. Learning ASM is not that much difficult, but after a certain point, getting the best performance out of the pipeline(by rearranging the order of instructions that do not affect each other for example) can be very tricky, and you can't always obtain easily the info you need about the hardware.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by mikeman

I think when phantom said "much better code than you" meant the OP, as a beginner or even medium-level in assembly, which is the majority of the already limited crowd that even know anything about ASM.


Hadn't thought of that. Wouldn't think of that, as it's a defeatist attitude. All we can do is learn, yes? Otherwise, I think we agree on the pitfalls of assembly coding. Drove me to bankruptcy, actually. $82K worth. Thank goodness it's over now, as of this week. Now I get to start fresh on new mistakes!

0

Share this post


Link to post
Share on other sites
@mikeman
I stand corrected on the 64k issue and you're quite right about where I was going on the assembler issue.

Infact, I did mention profiling as to when you would apply assembler language [smile] (directed at vanevery0)
0

Share this post


Link to post
Share on other sites
real world example
within a couple of months of releasing quake3 a function written with asm was actually slower than the plain c version.
with a higher language to get the benifits of a new compiler or new hardware u just need to recompile it with asm youre buggered u need to rewrite it
0

Share this post


Link to post
Share on other sites
Quote:
Original post by WillPash
Hi I have been writing OpenGL using C++ for a long while. Now I want to write faster applications, so I have decided to go for a lower level programming language so I have enquired about Assembly. I have the ASM code for various APIs, except OpenGL, so can someone recommend OpenGL programming tutorials using ASM, from beginners to advanced level will suffice. Nehe doesnt seem to have many features on ASM coding.

Helping me with finding good links will help me in a big way.Thank you for now and forever
Regards


I think that macro assembly has superior clarity over C++ code. If you'd like to forget about object dealocations and CPU specific code, use Java, if you need to do allocation/dealocation by hand anyway try to find some reasonable macroassemblers. You would at least get rid of majority of {} and ; .
Look at http://www.masmforum.com/simple/index.php



Of course the main problem in assembly is too much typing. Also comments in the source code are neccessity. On the other hand we have copy and paste, and assembly tends to work well with the copy and paste.

I don't know why anyone pretends like Assembly ended, it has not. Tools even without support of a larger companies becomed better, and CPUs rather standardizated itself into a common set of features. 64 bit assembly is actually nice because you could have all that freaking 14 registers (big improvement from 6). If you need just call OpenGL from an assembly it's as easy to write as from C++. Espacially with a macro assembler, and a prepared list of constants. The main slowdown is driver anyway so the main advantage of such dll linked with rest of your program would be small size.

To sum it up. There is nothing wrong with learning assembly and trying to create a small (or kinda large) OpenGL program. Programmers that don't have any experience with pure assembly/macroassembly are missing important experience that could increase theirs understanding about current CPUs. Direct experience is best. (And experience with messing up seemingly unrelated things in rest of the program is even better.)


BTW the biggest problems with creating programs in assembly are windoze internals and lack of documentation (Intel syntax assembly related) on linux. I always tended to write things first in Java, then if there was time add also JNI library done in assembly. There is no doubt that carry flag is accessible anly from assembly, and proper registry utilization, and variable chaching is hard to be done by compiler. There is also some (minor) programming language overhead, and some compilers tends to add a few unnecessary instructions. (If you'd like to know why look at optimalizing compiler design and try to imagine result of theirs work from distance.)

0

Share this post


Link to post
Share on other sites
Quote:
Original post by Raghar
then if there was time add also JNI library done in assembly.


What's JNI?

0

Share this post


Link to post
Share on other sites
Quote:
Original post by V-man
Quote:
Original post by Raghar
then if there was time add also JNI library done in assembly.


What's JNI?


Java Native Interface: a bridge from Java to DLLs
0

Share this post


Link to post
Share on other sites
If someone wants to learn assembly, let him learn assembly.

If that someone thinks that his assembly program will run faster, let him. If he actually cares, he'll write both versions and profile them, and the profiler will tell him whether it's true or not.

In general, a program's run time is dependent first on the algorithmic complexity (N-squared vs N-log-N vs N vs O(1)); second on its memory behavior (how many cache misses and TLB misses); and only third on its instruction selection. Thus, you can only optimize something in assembly if you already have optimal algorithmic choices and optimal memory behavior.

When it comes to calling OpenGL, calling OpenGL from assembly is exactly the same as calling any other standard API. You push the arguments, and call the function, just like you would call, say, CreateWindowW(). (Note the __stdcall calling convention if you're on Windows). Thus, you don't need an asm-specific OpenGL tutorial.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by blueshogun96
Maybe he's not writing a game. Maybe he wants wo write a sega saturn emulator or something, where speed counts.


Assembly does not equate to speed. More often than not, it equates to slower code. Reasons assembly is legitimately used in projects, such as emulators:
1) MMX/SSE optimizations are big in that arena.
2) A lot of the mature emulator projects started a long time ago, well before optimizing compilers reached the level of sophistication that they are at today.
3) Using instructions that the compiler doens't necessarily know about, but the assembler does, or that the compiler simply can't apply very well.
4) Occasionally, the programmer can legitimately exploit something about a particular CPU architecture to gain speed. This is generally restricted to 1 or 2 specific processors, e.g. Pentium 4s based off the Northwood core or something.
0

Share this post


Link to post
Share on other sites
Quote:
so this is another part of why the Any Good Compiler of academic legend never exists in industrial practice.

Amen, brother!

Quote:
I really doubt even if 64KB(an artificial boundary) demo coders use assembly*.

Correct - with 64KB, the focus is on procedural content generation and compression. 64KB would be a friggin' lot of code - call it 25KLOC assuming 2.5 bytes/instruction (reasonable if optimized for size).
It gets more interesting with 512B or 4K - there, every instruction counts. For reference, a minimal Win32 program is 160B (in fact this isn't PE conformant, but all Windows versions deign to give it a PID); OpenGL init takes about 300B; a chess demo with this kind of graphics and playing back a famous game fits in 1500B.

Quote:
Infact, I did mention profiling as to when you would apply assembler language (directed at vanevery0)

"Assembly language". Yes, that's one place to apply it, but don't forget optimizing for size. Ever written a bootloader? If you haven't practiced with "silly" stuff like this, you won't be able to!

Quote:
well before optimizing compilers reached the level of sophistication that they are at today.

Gotta chuckle every time this is said. It is true, but really all it means is that compilers were even worse before. VC7's optimizer is still a glorified pattern matcher (no experience with VC8 yet); and aliasing totally kills you.

[hm, it's 0430.. pardon the semi-rant]
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

  • Similar Content

    • By mapra99
      Hello

      I am working on a recent project and I have been learning how to code in C# using OpenGL libraries for some graphics. I have achieved some quite interesting things using TAO Framework writing in Console Applications, creating a GLUT Window. But my problem now is that I need to incorporate the Graphics in a Windows Form so I can relate the objects that I render with some .NET Controls.

      To deal with this problem, I have seen in some forums that it's better to use OpenTK instead of TAO Framework, so I can use the glControl that OpenTK libraries offer. However, I haven't found complete articles, tutorials or source codes that help using the glControl or that may insert me into de OpenTK functions. Would somebody please share in this forum some links or files where I can find good documentation about this topic? Or may I use another library different of OpenTK?

      Thanks!
    • By Solid_Spy
      Hello, I have been working on SH Irradiance map rendering, and I have been using a GLSL pixel shader to render SH irradiance to 2D irradiance maps for my static objects. I already have it working with 9 3D textures so far for the first 9 SH functions.
      In my GLSL shader, I have to send in 9 SH Coefficient 3D Texures that use RGBA8 as a pixel format. RGB being used for the coefficients for red, green, and blue, and the A for checking if the voxel is in use (for the 3D texture solidification shader to prevent bleeding).
      My problem is, I want to knock this number of textures down to something like 4 or 5. Getting even lower would be a godsend. This is because I eventually plan on adding more SH Coefficient 3D Textures for other parts of the game map (such as inside rooms, as opposed to the outside), to circumvent irradiance probe bleeding between rooms separated by walls. I don't want to reach the 32 texture limit too soon. Also, I figure that it would be a LOT faster.
      Is there a way I could, say, store 2 sets of SH Coefficients for 2 SH functions inside a texture with RGBA16 pixels? If so, how would I extract them from inside GLSL? Let me know if you have any suggestions ^^.
    • By KarimIO
      EDIT: I thought this was restricted to Attribute-Created GL contexts, but it isn't, so I rewrote the post.
      Hey guys, whenever I call SwapBuffers(hDC), I get a crash, and I get a "Too many posts were made to a semaphore." from Windows as I call SwapBuffers. What could be the cause of this?
      Update: No crash occurs if I don't draw, just clear and swap.
      static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format 32, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 24, // 24Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; if (!(hDC = GetDC(windowHandle))) return false; unsigned int PixelFormat; if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) return false; if (!SetPixelFormat(hDC, PixelFormat, &pfd)) return false; hRC = wglCreateContext(hDC); if (!hRC) { std::cout << "wglCreateContext Failed!\n"; return false; } if (wglMakeCurrent(hDC, hRC) == NULL) { std::cout << "Make Context Current Second Failed!\n"; return false; } ... // OGL Buffer Initialization glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glBindVertexArray(vao); glUseProgram(myprogram); glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, (void *)indexStart); SwapBuffers(GetDC(window_handle));  
    • By Tchom
      Hey devs!
       
      I've been working on a OpenGL ES 2.0 android engine and I have begun implementing some simple (point) lighting. I had something fairly simple working, so I tried to get fancy and added color-tinting light. And it works great... with only one or two lights. Any more than that, the application drops about 15 frames per light added (my ideal is at least 4 or 5). I know implementing lighting is expensive, I just didn't think it was that expensive. I'm fairly new to the world of OpenGL and GLSL, so there is a good chance I've written some crappy shader code. If anyone had any feedback or tips on how I can optimize this code, please let me know.
       
      Vertex Shader
      uniform mat4 u_MVPMatrix; uniform mat4 u_MVMatrix; attribute vec4 a_Position; attribute vec3 a_Normal; attribute vec2 a_TexCoordinate; varying vec3 v_Position; varying vec3 v_Normal; varying vec2 v_TexCoordinate; void main() { v_Position = vec3(u_MVMatrix * a_Position); v_TexCoordinate = a_TexCoordinate; v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0)); gl_Position = u_MVPMatrix * a_Position; } Fragment Shader
      precision mediump float; uniform vec4 u_LightPos["+numLights+"]; uniform vec4 u_LightColours["+numLights+"]; uniform float u_LightPower["+numLights+"]; uniform sampler2D u_Texture; varying vec3 v_Position; varying vec3 v_Normal; varying vec2 v_TexCoordinate; void main() { gl_FragColor = (texture2D(u_Texture, v_TexCoordinate)); float diffuse = 0.0; vec4 colourSum = vec4(1.0); for (int i = 0; i < "+numLights+"; i++) { vec3 toPointLight = vec3(u_LightPos[i]); float distance = length(toPointLight - v_Position); vec3 lightVector = normalize(toPointLight - v_Position); float diffuseDiff = 0.0; // The diffuse difference contributed from current light diffuseDiff = max(dot(v_Normal, lightVector), 0.0); diffuseDiff = diffuseDiff * (1.0 / (1.0 + ((1.0-u_LightPower[i])* distance * distance))); //Determine attenuatio diffuse += diffuseDiff; gl_FragColor.rgb *= vec3(1.0) / ((vec3(1.0) + ((vec3(1.0) - vec3(u_LightColours[i]))*diffuseDiff))); //The expensive part } diffuse += 0.1; //Add ambient light gl_FragColor.rgb *= diffuse; } Am I making any rookie mistakes? Or am I just being unrealistic about what I can do? Thanks in advance
    • By yahiko00
      Hi,
      Not sure to post at the right place, if not, please forgive me...
      For a game project I am working on, I would like to implement a 2D starfield as a background.
      I do not want to deal with static tiles, since I plan to slowly animate the starfield. So, I am trying to figure out how to generate a random starfield for the entire map.
      I feel that using a uniform distribution for the stars will not do the trick. Instead I would like something similar to the screenshot below, taken from the game Star Wars: Empire At War (all credits to Lucasfilm, Disney, and so on...).

      Is there someone who could have an idea of a distribution which could result in such a starfield?
      Any insight would be appreciated
  • Popular Now