Repository navigation
Disallow aliasing writable resources - #2441
Conversation
Co-authored-by: Kai Ninomiya <[email protected]>
Co-authored-by: Kai Ninomiya <[email protected]>
f43af35 to
87ca588
Compare
08b25ad to
d34dccc
Compare
d34dccc to
615b618
Compare
|
|
||
| **Arguments:** | ||
| <dl> | ||
| : {{GPUProgrammablePassEncoder}} |encoder| |
There was a problem hiding this comment.
Sorry to bring this up late. We need to figure out what the scope of aliasing analysis is.
There are several choices:
- scope is the synchronization scope, e.g. the whole render pass.
- scope is the draw call (i.e. the pipeline with its active bindings).
- 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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Thank you for patience! |
SHA: 10935dd Reason: push, by @kainino0x Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
SHA: 10935dd Reason: push, by @kainino0x Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
SHA: 10935dd Reason: push, by @kainino0x Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Fixes #1842.
Revision of #2065; see commit history for substantial changes.
Co-Authored-By: @litherum
Preview | Diff