Skip to content

Disallow aliasing writable resources - #2441

Merged
kvark merged 17 commits into
gpuweb:mainfrom
kainino0x:writable-binding-aliasing
Jan 13, 2022
Merged

kvark merged 17 commits into
gpuweb:mainfrom
kainino0x:writable-binding-aliasing

Conversation

@kainino0x

@kainino0x kainino0x commented Dec 21, 2021 •

Copy link
Copy Markdown
Contributor

Fixes #1842.
Revision of #2065; see commit history for substantial changes.

Co-Authored-By: @litherum


Preview | Diff

@kainino0x
kainino0x requested a review from kvark December 21, 2021 20:04
@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen when this build job started (f43af35):
WebGPU | IDL
WGSL
Explainer

@kainino0x
kainino0x force-pushed the writable-binding-aliasing branch from f43af35 to 87ca588 Compare December 21, 2021 20:10
@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen when this build job started (87ca588):
WebGPU | IDL
WGSL
Explainer

@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen when this build job started (81067f9):
WebGPU | IDL
WGSL
Explainer

Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
@kainino0x
kainino0x force-pushed the writable-binding-aliasing branch from 08b25ad to d34dccc Compare December 21, 2021 22:18
@gpuweb gpuweb deleted a comment from github-actions Bot Dec 21, 2021
@kainino0x
kainino0x force-pushed the writable-binding-aliasing branch from d34dccc to 615b618 Compare December 21, 2021 22:21
@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen when this build job started (615b618):
WebGPU | IDL
WGSL
Explainer

@gpuweb gpuweb deleted a comment from github-actions Bot Dec 21, 2021
@gpuweb gpuweb deleted a comment from github-actions Bot Dec 21, 2021
Comment thread spec/index.bs Resolved
@kainino0x
kainino0x requested a review from Kangz January 10, 2022 23:07
Comment thread spec/index.bs

**Arguments:**
<dl>
: {{GPUProgrammablePassEncoder}} |encoder|

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry to bring this up late. We need to figure out what the scope of aliasing analysis is.
There are several choices:

  1. scope is the synchronization scope, e.g. the whole render pass.
  2. scope is the draw call (i.e. the pipeline with its active bindings).
  3. scope is a single entry point and its bindings.

My understanding is that only (3) makes sense, because that's what the program in Metal is build for, and we are only talking about UB from the point of view of the shader compiler.

If we are talking about UB from the point of data races, than this has been agreed previously to be allowed, and I don't think we are going to change this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that only (3) makes sense, because that's what the program in Metal is build for, and we are only talking about UB from the point of view of the shader compiler.

This is a good point and brings some clarity to what we're doing here. I think I agree, so I can add back the foreach-stage loop.

However what I would like to understand better is what optimization the shader compiler can possibly make that results in problems when a resource is aliased in one entry point but is OK when a resource is aliased in any other way (between entry points or between draw calls).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

However what I would like to understand better is what optimization the shader compiler can possibly make that results in problems when a resource is aliased in one entry point but is OK when a resource is aliased in any other way (between entry points or between draw calls).

I don't think there's any difference (and the race from another draw if anything will be harder for the compiler to reason about), so that's why I don't think we should have this validation at all.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It makes a ton of difference from the point of view of TBAA. Consider this code:

let foo = buffer1.x;
buffer2.x = 2;
if (foo) { discard; }

If the compiler knows buffer1 and buffer2 aren't aliased, it also knows that there is no operations affecting foo result between the place it's declared and used. It can move the actual load into the if condition, for example. I.e. it clearly affects the ability of compilers to optimize.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's right, and it is a bit of a developer footgun. However if you're using read-write storage buffers in FS you already have a footgun with the data races from other shaders. So maybe it's ok and people doing fancy algorithms in storage buffers will have to be cognizant of the memory models.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right. In principle, I agree with this. But one of the major points in the atomics discussion was that the UB for compiler is strictly separate from the UB of the run-time. We keep the latter, but we can't afford the former - that's the status quo today.

@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen when this build job started (3ed52d7):
WebGPU | IDL
WGSL
Explainer

Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen when this build job started (88e5983):
WebGPU | IDL
WGSL
Explainer

@kvark

kvark commented Jan 13, 2022

Copy link
Copy Markdown
Contributor

Thank you for patience!

@kvark
kvark merged commit c68d4f5 into gpuweb:main Jan 13, 2022
github-actions Bot added a commit that referenced this pull request Jan 13, 2022
SHA: c68d4f5
Reason: push, by @kvark

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions Bot added a commit that referenced this pull request Jan 13, 2022
SHA: c68d4f5
Reason: push, by @kvark

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions Bot added a commit that referenced this pull request Jan 13, 2022
SHA: c68d4f5
Reason: push, by @kvark

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@kainino0x
kainino0x deleted the writable-binding-aliasing branch January 13, 2022 19:28
kainino0x added a commit that referenced this pull request Jan 13, 2022
I forgot to save the file before committing my last fix to #2441.
github-actions Bot added a commit that referenced this pull request Jan 13, 2022
SHA: 10935dd
Reason: push, by @kainino0x

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions Bot added a commit that referenced this pull request Jan 13, 2022
SHA: 10935dd
Reason: push, by @kainino0x

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions Bot added a commit that referenced this pull request Jan 13, 2022
SHA: 10935dd
Reason: push, by @kainino0x

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

Should the API enforce that writable storage buffer bindings don't alias each other?

4 participants