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

totally confused on branching

4 posts in this topic

[size="3"]Hi, everyone, I need some help on how tohandle branching in shaders. I searched some articles and threads about thisissue, however still confused.[/size]

[size="3"] [/size]

[size="3"]1. People always say modern GPUs “Avoidlatency stalls by interleaving execution of many groups of fragments”, whatdoes that exactly mean?[/size]

[size="3"] [/size]

[size="3"]2. After SM3.0 shaders can “support truedynamic branching”. I thought with the “true dynamic branching”, the brancheswill be executed just like on CPU. But it turns out not true. I read lotsarticles say that “both branches of if and else will be executed (is this theso called “branch predication”?)”, why? [/size]

[size="3"] [/size]

[size="3"]3. Besides of branch predication, any othermethod to handle branches on now days GPU?[/size]

[size="3"] [/size]

[size="3"]3. Lots of articles talking about SIMDprogramming is about CUDA, can these information about CUDA be applied onshaders such as GLSL.[/size]

[size="3"] [/size]

[size="3"]4. A snippet of pseudo code like this:[/size]

[size="3"]for( int i=0; i<15; i++ )[/size]

[size="3"]{[/size]

[size="3"] …..[/size]

[size="3"] If(In.color > val1 )[/size]

[size="3"] val2 = a;[/size]

[size="3"]else[/size]

[size="3"] val2 = b;[/size]

[size="3"] [/size]

[size="3"] …..[/size]

[size="3"] val3= function1();[/size]

[size="3"]}[/size]

[size="3"]function1()[/size]

[size="3"]{[/size]

[size="3"] …….[/size]

[size="3"] somebranches…..[/size]

[size="3"] …….[/size]

[size="3"]}[/size]

[size="3"]The branching in this code is a verylightweight one, which I am told need not to be cared and the compiler can kickin. But this is also a “branching inside inner loops”, the most case should beavoid in program. So what should to be done to this kind of branching? [/size]

[size="3"]And there are some branches inside thefunction function1() ,should these branches be considered “branching insideinner loops” or not?[/size]

[size="3"] [/size]

[size="3"]5. Cg compiler with GLSL profile can outputthe assembly of GLSL, are this assembly worthy enough to indicate the way howthe GPU execute it? I want to see how the GPU handle branches from theseassemblies, is that possible? since the assembly still is a middle language.[/size]

[size="3"] [/size]

[size="3"]6. Where can Igrab some information on this branching question and GPU architecture? And somebasic skills to optimize them? Could you offer me some links?[/size]

[size="3"] [/size]

[size="3"]Maybe too may whys…..I am a greener on GPUprogram, any suggestion will be appreciated. Hope my poor English did notbother you.[/size]

[size="3"]Thanks in advance![/size]
0

Share this post


Link to post
Share on other sites
There is a quite cool app from AMD it's called GPU ShaderAnalyzer.
With this Tool u can analyze your shader code and it will show u the assembly code of your shader but also how much cycles it takes to compute.
And because of branching there is an MIN MAX and AVG number of cycles in the output which will show u the worst and best case of your branching code.(another feature is that it shows u if your shader is ALU-operation or texture sample bound etc)

This tool does only simulate AMD graphic cards so u won't know how your shader will perform on NVidia, but I think that nvidia was a bit badder with branching on their older cards then ATI.


1

Share this post


Link to post
Share on other sites
GPUs are not good at branching. They process fragments in groups and if one of those fragments need to take a different branch, the whole fragment processing for that group stalls.
SM 3 GPU process in groups of 4 (2x2 fragments). SM 4 GPUs (I don't if it is all of them) process groups of 16 (4x4 fragments).

Branch prediction? There is no such thing in GLSL.
I do remember reading lot of articles about Intel and branch prediction in their CPUs and how AMD designed a better CPU with their brand new Athlon.

"Lots of articles talking about SIMD programming is about CUDA, can these information about CUDA be applied on shaders such as GLSL."
If the articles is about GPUs, then yes. GLSL is just a shading language and there isn't anything about GPU design in the GLSL specification.

As for your code, you can get rid of the "if""else" with the mix() function. Look at your GLSL manual.

If you are interested in using the GPU as a CPU, read about CUDA or OpenCL (Compute Library).
1

Share this post


Link to post
Share on other sites
[quote name='V-man' timestamp='1310343792' post='4833530']
GPUs are not good at branching. They process fragments in groups and if one of those fragments need to take a different branch, the whole fragment processing for that group stalls.
SM 3 GPU process in groups of 4 (2x2 fragments). SM 4 GPUs (I don't if it is all of them) process groups of 16 (4x4 fragments).

Branch prediction? There is no such thing in GLSL.
I do remember reading lot of articles about Intel and branch prediction in their CPUs and how AMD designed a better CPU with their brand new Athlon.

"Lots of articles talking about SIMD programming is about CUDA, can these information about CUDA be applied on shaders such as GLSL."
If the articles is about GPUs, then yes. GLSL is just a shading language and there isn't anything about GPU design in the GLSL specification.

As for your code, you can get rid of the "if""else" with the mix() function. Look at your GLSL manual.

If you are interested in using the GPU as a CPU, read about CUDA or OpenCL (Compute Library).
[/quote]

thanks for your reply. i meant branch predication, not branch prediction. i read some methods to better handle branching by mean of "regroup the the threads across warps" , is this a implementation of "dynamic branching"?



0

Share this post


Link to post
Share on other sites
I'm assuming you are talking the articles that were about CUDA (threads and all that).

I can't answer your question because I'm a GL and GLSL user. I'm more interested in games and 2D graphics.
I have never touched CUDA nor OpenCL.
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