Skip to content

entry_point_decl should be an annotation on the function #662

Closed

Description

@litherum

Today, this is how you describe an entry point in WGSL:

void foo() {
    ...
}
... perhaps hundreds of lines later ...
entry_point compute as MyComputeEntryPoint = foo

Just like how decorations are separate statements in SPIR-V, but were moved onto the variable declaration they are decorating in WGSL, the same treatment should be done on entry points. The benefit is that related concepts should be near each other in the source code.

Here's another way to do it:

[[expose_as = "MyComputeEntryPoint"]]
compute fn foo() -> void {
    ...
}

This wouldn't actually be less expressive, it would just keep related concepts together.

Activity

  1. added
    wgsl
    on Apr 1, 2020
  2. dj2 commented on Apr 1, 2020

    @dj2
    Member

    Currently you can have multiple entry points with different names pointing at the same function. Those entry points are where, eventually, the execution modes [1] will attach.

    Moving to decorations means you're going to have to have multiple decorations for a single function which isn't as nice as separating out to the entry point call.

    Note, you could write your first example the same as the second as:

    entry_point compute as MyComputeEntryPoint = foo
    void foo() {
        ...
    }
    

    which also keeps the related points together. The entry_point can proceed the function it references.

    1- https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html#Execution_Mode

  3. litherum commented on Apr 1, 2020

    @litherum
    ContributorAuthor

    Moving to decorations means you're going to have to have multiple decorations for a single function which isn't as nice as separating out to the entry point call.

    Why? All our existing decoration facilities accept lists of decorations, so I don’t see why this one shouldn’t as well.

  4. dj2 commented on Apr 1, 2020

    @dj2
    Member

    True, that's subjective, I withdraw that objection.

    This still doesn't solve the issue of attaching execution modes that differ per entry point.

    What is the issue with writing the entry point directive above the function?

  5. kvark commented on Apr 2, 2020

    @kvark
    Contributor

    For clarity, could you provide an example where a single function would be used in different execution modes?

  6. litherum commented on Apr 3, 2020

    @litherum
    ContributorAuthor

    Right. The built-ins are all different anyway.

  7. dneto0 commented on Apr 7, 2020

    @dneto0
    Contributor

    Sorry, there's an easily confused thing going on here.

    There's execution model (e.g. fragment vs. vertex vs. compute), and execution mode (describe/modify the behaviour of the shader stage).

    Example of different execution modes:

    • the same compute shader body, but different workgroup sizes. (See LocalSize execution mode in SPIR-V)
    • the same shader stage but with different floating point behaviours (a newish Vulkan feature). See DenormPreserve, DenormFlushToZero, SignedZeroInfNanPreserve, RoundingModeRTE, and RoundingModeRTZ

    If you attach these things to the function body itself, then you can always model the differences by having an extra layer of function wrapping, and attaching these attributes to the outside wrapper.

  8. kvark commented on Apr 8, 2020

    @kvark
    Contributor

    Thank you, that makes sense! So it sounds like we could still just annotate the functions with entry point properties.

  9. grorg commented on Apr 14, 2020

    @grorg
    Contributor

    Discussed at the 2020-04-14 meeting.

    The discussion mostly focused on the syntax that @litherum was suggesting. He'll follow up here with more examples for us to discuss again.

  10. litherum commented on Apr 14, 2020

    @litherum
    ContributorAuthor

    Simple cases look something like this:

    [[ workgroupSize = [1, 2, 3] ]]
    compute void foo(...) { ... }
    

    However, if you wanted to expose the same entry point with two different workgroup sizes, you could write:

    [[ expose_as = “entryPoint1” workgroupSize = [1, 2, 3],
       expose_as = “entryPoint2” workgroupSize = [5, 6, 7] ]]
    compute void foo(...) { ... }
    

    or

    void foo(...) { ... }
    
    [[ workgroupSize = [1, 2, 3] ]]
    compute void entryPoint1(...) { foo(...) }
    
    [[ workgroupSize = [5, 6, 7] ]]
    compute void entryPoint2(...) { foo(...) }
    
  11. dneto0 commented on Apr 15, 2020

    @dneto0
    Contributor

    The multiple "expose_as" syntax is overly complex because now you have nested attributes on attributes. That's the "sublanguage" aspect I was complaining about in the meeting. That's a non-starter for me.

  12. dneto0 commented on Apr 15, 2020

    @dneto0
    Contributor

    Surveying the execution modes from SPIR-V, https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_execution_mode_a_execution_mode
    there are:

    • things for geometry shaders
    • things for tessellation shaders
    • PixelCenterInteger, for fragment shader. Not clear if WebGPU will ever use this
    • OriginUpperLeft vs. OriginLowerRight, for fragment shader. WebGPU will(has?) picked one already
    • EarlyFragmentTest, for fragment shader
    • 4 options for depth handling in fragment shaders
    • LocalSize for compute shader workgroup size
    • LocalSizeHint, a hint for code generation optimization
    • ContractionOff (Kernel), for essentially fast-math mode for kernels targeting OpenCL
    • options for subgroup control
    • options for floating point behaviour: denorms, rounding direction, preservation of signed-zero,infinities,and Nans.
    • options for other Vulkan extensions
  13. kvark commented on Apr 15, 2020

    @kvark
    Contributor

    @dneto0 I agree that having meta-language for the attributes is not desired.
    Would having separate wrapping functions (the second half of #662 (comment)) be a non-starter as well?

  14. litherum commented on Apr 18, 2020

    @litherum
    ContributorAuthor

    All popular human-writable shading languages annotate the function. No human-writable languages have standalone entry point decl statements. Somehow none of those languages have been crushed by the weight of the annotations.

    From this list, I see some which a) aren't even applicable to shaders, b) aren't implementable on MSL / HLSL, or c) are regarding features we have no plans to include in WebGPU.

  15. 4 remaining items

  16. grorg commented on Jun 23, 2020

    @grorg
    Contributor
  17. litherum commented on Jun 23, 2020

    @litherum
    ContributorAuthor

    Discussed at the 2020-06-23 Virtual F2F meeting

    I don't think it actually was. I think we discussed #644 instead.

  18. grorg commented on Jul 7, 2020

    @grorg
    Contributor

    Discussed (really! this time!) at the 2020-07-07 meeting.

  19. kainino0x commented on Jul 7, 2020

    @kainino0x
    Contributor

    compute void entryPoint1(...) { foo(...); }

    nit: there are no arguments allowed here, it will be:

    compute void entryPoint1() { foo(); }

  20. kdashg commented on Jul 7, 2020

    @kdashg
    Contributor

    We decided to do #662 (comment) with #662 (comment).

  21. dneto0 commented on Sep 2, 2020

    @dneto0
    Contributor

    Looking at this, the proposed syntax is un-WGSL-like.

    It's either

        compute fn main() -> void { }
    

    or

        fn compute main() -> void { }
    

    I prefer the first. I don't think it causes a grammar ambiguity or collision.

  22. added 6 commits that reference this issue on Sep 2, 2020
    ef037d8
    8ac6f24
    b240900
    fc3ce61
    82e0531
    0dcd8d5
  23. added a commit that references this issue on Sep 18, 2020
    9cc8d59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wgsl

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions