Skip to content

Add a chapter on Compute Shaders#366

Merged
spencer-lunarg merged 11 commits intoKhronosGroup:mainfrom
spencer-lunarg:spencer-lunarg-compute
Mar 22, 2026
Merged

Add a chapter on Compute Shaders#366
spencer-lunarg merged 11 commits intoKhronosGroup:mainfrom
spencer-lunarg:spencer-lunarg-compute

Conversation

@spencer-lunarg
Copy link
Contributor

Rendered view

Kind review @jeffbolznv - mainly around the shared memory races and any other stuff you think would be useful

SaschaWillems
SaschaWillems previously approved these changes Mar 15, 2026
Copy link
Collaborator

@SaschaWillems SaschaWillems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a chapter explaining basic compute terms is a great addition 👍🏻

----
shared uint my_var;
void main() {
// All the invocations in the workgroup are going to try to write to the same memory.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's confusing to lead with this example, and would be better to start with examples of cross-thread communication and using barrier() first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you provide some GLSL snippets here (in the comment), I know you are more of an expert in this area and probably better at providing some better examples to provide

Copy link

@jeffbolznv jeffbolznv Mar 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use a reduction as a simple example of cross-thread communication:

    shared float temp[BLOCK_SIZE];

    temp[tid] = x;
    [[unroll]] for (uint s = BLOCK_SIZE / 2; s > 0; s >>= 1) {
        barrier();
        float other = temp[tid ^ s];
        barrier();
        temp[tid] += other;
    }

shared float my_var[BLOCK_SIZE];

void reduction(float x) {
    uint tid = gl_GlobalInvocationID;

    my_var[tid] = x;
    for (uint s = BLOCK_SIZE / 2; s > 0; s >>= 1) {
        barrier();
        float other = my_var[tid ^ s];
        barrier();
        my_var[tid] += other;
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, we can add this in a follow up, this example makes is confusing... was is suppose to be an example of having a race condition?

Copy link
Contributor

@gpx1000 gpx1000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chapter is a solid addition and fills a clear gap in the guide!

Copy link
Contributor

@charles-lunarg charles-lunarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of grammar nits & suggestions of things that can be improved.

gpx1000 and others added 10 commits March 20, 2026 14:34
Co-authored-by: Charles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Co-authored-by: Charles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Co-authored-by: Charles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Co-authored-by: Charles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Co-authored-by: Charles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Co-authored-by: Charles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Co-authored-by: Charles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Co-authored-by: Charles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Co-authored-by: Charles Giessen <46324611+charles-lunarg@users.noreply.github.com>
@spencer-lunarg spencer-lunarg merged commit fa7e472 into KhronosGroup:main Mar 22, 2026
1 check passed
@spencer-lunarg spencer-lunarg deleted the spencer-lunarg-compute branch March 22, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants