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

simple compute shader question

4 posts in this topic

Hi,
I've recently started using compute shaders, I understand the basics. I wrote a code for blurring 1D texture and it works. The problem is that now i want this texture to have 2k size. With 1k it was simple: [b]Dispatch(1, 1, 1 ), [numthreads(1024, 1, 1)], SV_GroupThreadID [/b]for indexing. Maximum number of threads in group is 1024 so i must use two groups, but i'can't synchronize thread groups? Can someone explain how an algorithm for bluring 1d texture with 2 (or more) groups should look like (in compute shader)? Two passes?

TIA
Przemek Edited by quaikohc2
0

Share this post


Link to post
Share on other sites
Hi,

You can use groupshared variables to make them syncronized

Example: groupshared float4 gCache[2048];

And if u need to work with specific computed data from an other thread just call GroupMemoryBarrierWithGroupSync(); so the data for the group is synced.

You can imagine the (1, 1, 1) as 3 axes (or 3D Array), If you have 1024, 1, 1 its 1024*1*1. If u need 2048 u can for example use Dispatch(1024, 2, 1) or what ever combination you want.

Regards
0

Share this post


Link to post
Share on other sites
[quote name='~Helgon' timestamp='1356008650' post='5012781']
You can use groupshared variables to make them syncronized
[/quote]

No he can't. The keyword [i]groupshared [/i]allows multiple threads inside a thread group to share data, not between the different thread groups. It's this way, because the thread groups might get executed by different streaming multiprocessors, while a single thread group is executed on a single streaming multiprocessor, where all the threads can use specialized on-chip memory to efficiently share data.

It actually depends on your implementation. A normal shader for blurring doesn't really require synchronization between the individual threads, since every thread just needs to gather its data. A better implementation might be, that you want to use groupshared memory as some kind of cache for the row of the texture, so that every thread only needs to perform a single texture fetch. Since groupshared memory is only available inside a thread group, you can only use up to 1024 threads. The only solution would be to convert your algorithm into a more iterative algorithm. Just work on 2 pixels per thread and use a groupshared array with 2048 elements. This works and is not even slower, since a thread group is not what the actual hardware executes in parallel. The driver splits your thread group into units of 32 or 64 threads called Warps or Wavefronts that get executed [i]iteratively[/i] (clarification: all the threads of a warp get executed in parallel, but the different warps get executed iteratively). So 2 thread groups of 1024 would be executed as 32 wavefronts or 64 warps in an iterative manner. My solution of just a single thread group and 1024 threads per thread group gets converted into just 16 wavefronts or 32 warps, but they all do the twice the amount of work. So in the end your algorithm is just as parallel, as it would be if you would use 2 thread groups. As long as a thread group consists of at least 8 warps (recommendation of NVIDIA) you can always remove some of your parallelisation without a decrease in performance. As far as I understand NVIDIA's Kepler architecture, they now begin to execute multiple warps in parallel (6, if I'm correct), so this solution might not be the best for the future. But it's as good as it can get with DirectX 11 unfortunately.

If you would actually want to work on more than 2048 pixels, you would need to use register memory to cache your pixels, since you would need more than the maximum of 32 KB group shared memory. Let's say you would want to work with 4096 pixels. You could store 4 pixels per thread inside its registers and always expose 2 of them in the group shared memory. You just need to synchronize the threads and always expose the pixels you want to access from other threads. Groupshared memory is just a way to share data. Register memory is way larger than just 32 KB. Edited by CryZe
2

Share this post


Link to post
Share on other sites
Assuming you're using shared memory to cache values from nearby texels, then you only need synchronization/sharing between threads that are N texels apart (where N is the radius of your blur kernel). So for instance if your blur samples 10 texels to the left or right, then a given thread only needs to sync/communicate with the 10 threads to its left and the 10 threads to its right. This means that your thread group doesn't need to span the entire texture, it just needs to be large enough for any one thread to access its neighbors in shared memory. So for instance if your thread group is 256 threads, thread 128 can safely access the data threads 118-127 and 129-137 using shared memory and thread group synchronization. The only issue comes at the edge of your thread group. Take thread 255: it can access 245-254 just fine, but it can't communicate with the threads to its right because they're in a different thread group. There are 2 common ways of solving this problem:

1. Add "dummy" threads to your thread group that don't actually output anything, but instead just sample the N texels past the edge of your thread group (these texels are often referred to as an "apron")

2. Have the N threads at the start of the group sample both their own texel as well as the N texels to the left, then do the same for N threads at the end of the group

You might want to have a read through [url="http://developer.download.nvidia.com/compute/cuda/1.1-Beta/x86_64_website/projects/convolutionSeparable/doc/convolutionSeparable.pdf"]this paper[/url] as well as [url="http://developer.amd.com/wordpress/media/2012/10/DirectCompute%20Accelerated%20Separable%20Filters.pps"]this presentation[/url] for more info.
2

Share this post


Link to post
Share on other sites
I would only use the apron solution for non-seperable kernels or kernels that are too large to fit into groupshared memory, since the apron pixels are getting sampled multiple times from the different thread groups. So you're losing performance there, which is not the case in the solution where every thread simply calculates multiple pixels. Edited by CryZe
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