这是indexloc提供的服务,不要输入任何密码
Skip to content

Add break N instead of continue and continuing. #642

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

Closed
wants to merge 2 commits into from

Conversation

kdashg
Copy link
Contributor

@kdashg kdashg commented Mar 25, 2020

No description provided.

@kdashg kdashg added the wgsl WebGPU Shading Language Issues label Mar 25, 2020

Note: This is *proposed* but not in the [SHORTNAME] spec yet

The `for(var i : i32 = 0; i < 4; i = i + 1) {}` statement is syntactic sugar on
The `for(var i : i32 = 0; i < 4; i = i + 1) {CODE}` statement is syntactic sugar on
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean the for-loop no longer supports continue (i.e. you have to express it with a nested loop as with loop)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could add it, but this is "proposed possibilities", as for isn't a real WGSL thing yet.

Copy link
Contributor

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

OK with me as long as the generalized break N concept can translate to SPIR-V.

A super simple once { ...; } sugar for loop { ...; break; } could be appealing.


<div class='example' heading="General [SHORTNAME] Loop Form">
<xmp>
A
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrap this whole thing in {} to contain the scope of A?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yeah, that would be more precise.

@Kangz
Copy link
Contributor

Kangz commented Mar 26, 2020

AFAIK the break N construct cannot be expressed in SPIR-V because of the structured control flow rules that says:

the only blocks in a construct that can branch outside the construct are:

  • ...
  • a break block for the innermost loop it is nested inside of

. +CC @dj2 and @dneto0

@kdashg
Copy link
Contributor Author

kdashg commented Mar 26, 2020

Hmm, suspicious. "a block branching to the construct’s merge block " satisfies some requirements, but I'll have to think it over.

Co-Authored-By: Kai Ninomiya <kainino1@gmail.com>
@dneto0
Copy link
Contributor

dneto0 commented Mar 27, 2020

The literal count is error prone. I'd rather label-name the loops, then have break label.

The translation from this more general construct requires, in general, synthesis of extra state variables to track mulit-level escape. That adds complexity to translation, and is in conflict with the developer understanding (by counting) the register pressure on an invocation.

@kainino0x
Copy link
Contributor

Removing approval since it sounds like this can't translate to SPIR-V (directly).

@kainino0x kainino0x self-requested a review March 27, 2020 18:28
@kdashg
Copy link
Contributor Author

kdashg commented Mar 31, 2020

Ok, I agree that it would require non-zero-cost translation in the general case.

SPIR-V structured control flow branching rules:

the only blocks in a construct that can branch outside the construct are
* a block branching to the construct’s merge block
* a block branching from one case construct to another, for the same OpSwitch
* a back-edge block
* a continue block for the innermost loop it is nested inside of
* a break block for the innermost loop it is nested inside of
* a return block

@kdashg kdashg closed this Mar 31, 2020
@kdashg
Copy link
Contributor Author

kdashg commented Mar 31, 2020

In particular it would be temping to write:

let a = 0;
let y = 0;
loop {
  if (y >= H) break;
  let x = 0;
  loop {
    if (x >= W) break;
    a = foo(x,y);
    if (a) break 2;
    x += 1;
  }
  y += 1;
}

However, I believe there's no valid SPIR-V zero-cost equivalent.

ben-clayton pushed a commit to ben-clayton/gpuweb that referenced this pull request Sep 6, 2022
gpuweb#642)

This test creates a texture and uses it as both sampled and storage.
Storage textures cannot be multisampled, so that case is invalid.

Bug: crbug.com/dawn/990
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wgsl WebGPU Shading Language Issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants