Contents
I have a first version working that uses a Shader Storage Buffer Object. I dispatch a thread per cell I want to update and that thread samples the SSBO 8 times to gather the cell’s neighbors. This works fine. I’m now trying to optimize this by using shared memory.
Can a global variable be declared in compute shader?
Global variables in compute shaders can be declared with the shared storage qualifier. The value of such variables are shared between all invocations within a work group. You cannot declare any opaque types as shared, but aggregates (arrays and structs) are fine. At the beginning of a work group, these values are uninitialized.
What does groupmemorybarrier do in compute shader?
The usual set of memory barriers is available to compute shaders, but they also have access to memoryBarrierShared (); this barrier is specifically for shared variable ordering. groupMemoryBarrier () acts like memoryBarrier (), ordering memory writes for all kinds of variables, but it only orders read/writes for the current work group.
How many compute shader invocations are there in OpenGL?
Therefore, if the local size of a compute shader is (128, 1, 1), and you execute it with a work group count of (16, 8, 64), then you will get 1,048,576 separate shader invocations. Each invocation will have a set of inputs that uniquely identifies that specific invocation.
How does thread size affect compute shader performance?
When using a compute shader, it is important to consider the impact of thread group size on performance. Limited register space, memory latency and SIMD occupancy each affect shader performance in different ways.
How to optimize GPU performance with large shaders?
Sebastian is going to cover an interesting problem he faced while working on Claybook: how you can optimize GPU occupancy and resource usage of compute shaders that use large thread groups. When using a compute shader, it is important to consider the impact of thread group size on performance.
What’s the maximum group size for GPGPU shaders?
Direct3D limits the amount of groupshared data a single thread group can use to 32 KiB. Thus we need to run at least two groups on each CU to fully utilize the LDS. My example shader in this article is a complex GPGPU physics solver with thread group size of 1024. This shader uses maximum group size and maximum amount of groupshared memory.
What makes compute shaders different from pixel shaders?
So the two main things that set compute shaders apart from pixel shaders are shared memory between threads and the possibility of writing anywhere in the output buffer. It’s important to think about compute shaders in terms of threads, not “pixels” or “vertices”. Threads that process data.
Every thread in a work group will now load a single cell in shared memory wait for the memory and execution barrier to resolve and then sample the shared memory 8 times to compute its cell’s state.