Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[glsl-in] Compute shader fixes and additions #955

Merged
merged 12 commits into from
Jun 9, 2021
Merged

Conversation

JCapucho
Copy link
Collaborator

@JCapucho JCapucho commented Jun 6, 2021

Contains a bunch of bug fixes and implements more parts of the parser to
finally be able to parse the collatz compute shader and other compute
shaders.

When I started working on this I thought it would be a simple thing but
it proved more complex, here’s a list of the things included in this PR

  • Add parsing for compute shader workgroup modifiers (fixes [glsl-in] Unsupported compute stage layout qualifiers #246)
  • Add support for the buffer storage class (fixes [glsl-in] buffer isn't treated as a keyword #902)
  • Add mod function and use implicit conversions for it’s arguments
  • Add implicit conversions for locals initializers
  • Add glGlobalInvocationID builtin
  • Fixes a panic when calculating global use
  • Refractor the way global and blocks are handled to reduce code
    duplication
  • Fixes unsized types being loaded
  • Fixes assignments for function arguments in validation
  • Generates the wgsl for the quad shader
  • Add the collatz shader to testing

Due to #945 the glsl snapshot folder isn’t currently generating wgsl

Also due to load expressions being cached the produced wgsl isn’t
correct but everything else looks okay, here’s the wgsl for the collatz
shader

[[block]]
struct PrimeIndices {
    indices: [[stride(4)]] array<u32>;
};

[[group(0), binding(0)]]
var<storage> global: [[access(read_write)]] PrimeIndices;
var<private> gl_GlobalInvocationID: vec3<u32>;

fn collatz_iterations(n: u32) -> u32 {
    var n1: u32;
    var i: u32;
    var local: u32;

    n1 = n;
    let _e4: u32 = n1;
    i = u32(0);
    loop {
        if (!((_e4 != u32(1)))) {
            break;
        }
        {
            if (((_e4 % u32(2)) == u32(0))) {
                {
                    n1 = (_e4 / u32(2));
                }
            } else {
                {
                    n1 = ((u32(3) * _e4) + u32(1));
                }
            }
            let _e28: u32 = i;
            local = _e28;
            i = (_e28 + 1u);
        }
    }
    return i;
}

fn main() {
    var index: u32;

    let _e6: u32 = index;
    index = gl_GlobalInvocationID.x;
    let _e12: u32 = collatz_iterations(global.indices[_e6]);
    global.indices[_e6] = _e12;
    return;
}

[[stage(compute), workgroup_size(1, 1, 1)]]
fn main1([[builtin(global_invocation_id)]] param: vec3<u32>) {
    gl_GlobalInvocationID = param;
    main();
    return;
}

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Looks sensible, I didn't inspect all the details.
Is this meant to be landed as is? Or squashed?

@JCapucho
Copy link
Collaborator Author

JCapucho commented Jun 9, 2021

I made the commits so that they would all pass validation and contain a specific fix each so I think it's better to merge it has is without squashing

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.

[glsl-in] buffer isn't treated as a keyword [glsl-in] Unsupported compute stage layout qualifiers
2 participants