Repository navigation
Add a memory model mapping to Vulkan - #2055
Conversation
dneto0
left a comment
There was a problem hiding this comment.
This is great!
I just have minor editorial feedback.
|
Pinging @RobinMorisset (for some reason we can't add you as a GitHub reviewer). |
| ### Program order (within an invocation) ### {#program-order} | ||
|
|
||
| Each statement in a [SHORTNAME] program may be executed zero or more times during | ||
| execution. |
There was a problem hiding this comment.
Does this need saying? The only numbers of times executed it excludes are negative values?
There was a problem hiding this comment.
I was just trying to specifically call out that not all statements will necessarily be executed.
WGSL meeting minutes 2021-09-21
|
|
Pinging @RobinMorisset again. |
|
Sorry for taking so long to look at this. Starting to review it. |
RobinMorisset
left a comment
There was a problem hiding this comment.
Thanks for writing this much needed section.
I've added a few comments and suggestions for clarifications inline, but it generally LGTM.
| Expression nesting defines data dependencies which must be satisfied to | ||
| complete evaluation. | ||
| That is, a nested expression must be evaluated before the enclosing expression | ||
| can be evaluated. |
There was a problem hiding this comment.
I don't see anything here about the order of execution of various sub-expressions.
e.g. f()+g(), is f() guaranteed to execute before g() ?
It might be written elsewhere, but it sounds like it should at least be repeated in this section.
There was a problem hiding this comment.
No, f() is not guaranteed to execute before g(). But in f(g()), g() must execute before f().
There was a problem hiding this comment.
Do we already have an issue about this? It is something that I'd like to discuss (but can be done independently from this PR.
|
|
||
| Each module-scope variable in [SHORTNAME] forms a unique [memory model | ||
| reference](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#memory-model-references) | ||
| for the lifetime of a given entry point. |
There was a problem hiding this comment.
Looking at the Vulkan memory model, I saw the following quote which I don't fully understand:
A single common reference for all variables with Workgroup storage class that point to a block-decorated type.
It looks like several variables may share a single reference in this particular case. Is it something that may happen in WGSL?
There was a problem hiding this comment.
No, this is not possible in WGSL. That feature describes an extension (VK_KHR_workgroup_memory_explicit_layout) to Vulkan that allows explicit workgroup memory layouts and aliasing. For WGSL's purposes, each workgroup variable is independent from all other workgroup variables.
| is: | ||
| * `Workgroup` if the atomic pointer is in the [=storage classes/workgroup=] | ||
| storage class | ||
| * `Device`/`QueueFamily` if the atomic pointer is in the [=storage |
There was a problem hiding this comment.
Can you explain when it should be Device and when it should be QueueFamily? These two scopes don't seem to be one and the same from my reading of the Vulkan memory model.
There was a problem hiding this comment.
Prior to the Vulkan memory model (e.g. Vulkan 1.0 with no extensions), there was no concept of queue family, but device actually meant queue family. So it is queue family, but if you are generating SPIR-V without OpMemoryModel Logical Vulkan then you must generate it as Device. If you generate SPIR-V with OpMemoryModel Logical Vulkan then you would use QueueFamily.
Maybe it would be clearer if I just called it QueueFamily and added a note about generating earlier versions of SPIR-V.
| [scope](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#memory-model-scope) | ||
| is: | ||
| * `Workgroup` for `workgroupBarrier` | ||
| * `Device`/`QueueFamily` for `storageBarrier` |
| Note: No atomic or synchronization built-in functions use `MakeAvailable` or | ||
| `MakeVisible` semantics. | ||
|
|
||
| ## Private vs Non-Private ## {#private-vs-non-private} |
There was a problem hiding this comment.
I had a very interesting discussion with @dneto0 in March 2019, on whether the mapping should make all read/write accesses be MakePointerVisible/MakePointerAvailable (the approach you've taken in this section, let's call it approach 1), or whether all barriers should have MakeAvailable/MakeVisible semantics (let's call it approach 2).
My (definitely fuzzy at this point) understanding is that both approaches work, and are probably equivalent in their results (but we don't have any proof at this stage). Approach 1 is what SPIRV-Tools does when converting "Coherent" annotations to the more modern Vulkan memory model, whereas approach 2 has the benefit of allowing some significant simplifications of the model. David also said at the time:
Stepping back, the reason the Vulkan memory model has both per-op AV/VIS ops and also the bulk ones at synchronization points is that different workloads can perform better with one pattern vs. the other.
Considering how subtle this issue is, and how it is independent from the rest of the memory model, I intend to open a separate issue for it. It would at least ensure that all of the information on the topic is publicly on GitHub and no longer locked in email threads, and ideally we may get numbers on the perf impact of picking one approach over the other.
I'm fine with this PR landing with the current approach as waiting for a full discussion and consensus on this particular point may take a long while, I just want to make sure we don't forget about it.
|
|
||
| In general, [SHORTNAME] follows the [[!VulkanMemoryModel|Vulkan Memory Model]]. | ||
| The remainder of this section describes how [SHORTNAME] programs map to the | ||
| Vulkan Memory Model. |
There was a problem hiding this comment.
Maybe add a link to https://github.com/KhronosGroup/Vulkan-MemoryModel/blob/master/alloy/spirv.als for the formal model, as well as to the spec (which is already linked to in later sections)?
There was a problem hiding this comment.
The !VulkanMemoryModel is the link to the spec. I could add a link to the alloy model in a note perhaps.
Fixes gpuweb#670 * Defines WGSL's memory model in terms of a translation to Vulkan's memory model
* clarify mappings: * read access -> read operation * write access -> write operation * read and/or write access -> memory operation * clarify non-private access mappings
* State that WGSL does not guarantee the order that operands of an expression are evaluated * Replace `Device`/`QueueFamily` with just `QueueFamily` and add a note describing that `Device` should be used if the `Vulkan` memory model is not specified * Add a link to the formal Alloy model * Specify that RMW atomics are a single memory operation
bd43442 to
16c8965
Compare
|
Addressed @RobinMorisset's feedback and rebased on main. |
RobinMorisset
left a comment
There was a problem hiding this comment.
LGTM, except for a missing word.
Thanks for taking the time to write this section!
| The remainder of this section describes how [SHORTNAME] programs map to the | ||
| Vulkan Memory Model. | ||
|
|
||
| Note: The Vulkan Memory Model is textual version of a [formal Alloy |
There was a problem hiding this comment.
Nit: is textual => is a textual
| Expression nesting defines data dependencies which must be satisfied to | ||
| complete evaluation. | ||
| That is, a nested expression must be evaluated before the enclosing expression | ||
| can be evaluated. |
There was a problem hiding this comment.
Do we already have an issue about this? It is something that I'd like to discuss (but can be done independently from this PR.
I don't believe so, but we do have spec text in the function call section that says:
Feel free to open the issue for discussion. |
WGSL meeting minutes 2021-11-02
|
Fixes #670
memory model