Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit 131313e

Browse files
dneto0zoddicus
authored andcommitted
Restrict OpControlBarrier, OpMemoryBarrier (#31)
- Refactor description of Memory Semantics bits, describing subsets of mask bits for: Order, Storage Class, and Propagation. - Make a new subsections for sets of instructions that need further qualification, grouped according to SPIR-V instruction sections. - Move restrictions of control barrier, memory barrier, and atomics to their own corresponding sections. - Update Memory Semantics and Scope restrictions reflect decisions in #28: - OpMemoryBarrier is only used for intra-invocation fence Fixes #28
1 parent e8240d8 commit 131313e

File tree

1 file changed

+83
-26
lines changed

1 file changed

+83
-26
lines changed

execution-env.md

Lines changed: 83 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -373,41 +373,48 @@ Each block **_B_** in a function must satisfy one of the following rules:
373373

374374
**Scope** when used for memory must be one of:
375375

376-
377376
[//]: # (No **Device** since that's optional for Vulkan memory model. In single-device configurations QueueFamilyKHR is the same as Device)
378377

379378
* **Workgroup**
380-
* **Subgroup**
379+
* **Invocation**
381380
* **QueueFamilyKHR**
382381

383382
**Scope** when used for execution must be one of:
384383

385-
386-
387384
* **Workgroup**
388-
* **Subgroup**
389-
390-
391-
#### Memory Semantics
392-
393-
Among mask bits up to and including 0x10 (SequentiallyConsistent), only the following may be set
394-
for an **OpControlBarrier** or **OpMemoryBarrier** instruction:
395-
396-
* **AcquireRelease**
397385

398-
No mask bits up to and including 0x10 (SequentiallyConsistent) may be set for an atomic instruction (**OpAtomic**\*).
399-
That is, atomic operations use **Relaxed** ordering.
386+
[//]: # (Vulkan limits execution scope to Workgroup and Subgroup, but WebGPU MVP does not have subgroup ops)
400387

388+
Individual SPIR-V instructions may further restrict valid values.
401389

402-
The following mask bits may be used in any combination:
403-
404-
* **UniformMemory**
405-
* **WorkgroupMemory**
406-
* **ImageMemory**
407-
* **OutputMemoryKHR**
408-
* **MakeAvailableKHR**
409-
* **MakeVisibleKHR**
390+
#### Memory Semantics
410391

392+
A Memory Semantics operand is expressed in a single word,
393+
using mask bits in grouped into three sets:
394+
395+
* _Memory Semantics Order bits_ are mask bits with value between 1 through 0x10:
396+
* 0x1 _Reserved_
397+
* 0x2 **Acquire**
398+
* 0x4 **Release**
399+
* 0x8 **AcquireRelease**
400+
* 0x10 **SequentiallyConsistent**
401+
* _Memory Semantics Storage Class bits_ are mask bits with value between 0x20 through 0x1000:
402+
* 0x20 _Reserved_
403+
* 0x40 **UniformMemory**
404+
* 0x80 **SubgroupMemory**
405+
* 0x100 **WorkgroupMemory**
406+
* 0x200 **CrossWorkgroupMemory**
407+
* 0x400 **AtomicCounterMemory**
408+
* 0x800 **ImageMemory**
409+
* 0x1000 **OutputMemoryKHR**
410+
* _Memory Semantics Propagation bits_ are mask bits with value between 0x2000 through 0x4000:
411+
* 0x2000 **MakeAvailableKHR**
412+
* 0x4000 **MakeVisibleKHR**
413+
414+
Individual SPIR-V instructions may further restrict valid values for a _Memory Semantics
415+
operand_.
416+
The restrictions are expressed in terms of the order, storage class, and propagation
417+
sets of bits.
411418

412419
#### Memory Access
413420

@@ -449,13 +456,63 @@ Fusing and reassociation of floating point operations is allowed when those inst
449456

450457
### Instructions
451458

459+
Supported OpCodes are listed in [Appendix A](#a-supported-opcodes).
452460

461+
The following sections describe differences from specific SPIR-V instructions.
453462

454-
* OpUndef is not allowed.
455-
* OpVectorShuffle may not have a component literal with value 0xFFFFFFFF.
463+
#### Miscellaneous instructions
464+
465+
* **OpUndef** is not allowed.
456466

457-
Supported OpCodes are iterated in [Appendix A](#a-supported-opcodes).
467+
#### Constant creation instructions
468+
469+
* **OpSpecConstantOp**:
470+
* Opcode **OpVectorShuffle** may not have a component literal with value 0xFFFFFFFF.
471+
472+
#### Composite instructions
473+
474+
* OpVectorShuffle may not have a component literal with value 0xFFFFFFFF.
458475

476+
#### Atomic instructions
477+
478+
* Atomic instructions (**OpAtomic**\*) are restricted:
479+
* The _Memory_ scope operand must be **QueueFamilyKHR**
480+
* The _Semantics_ operand must be zero:
481+
* Must not set any Memory Semantics Order bits.
482+
* Must not set any Memory Semantics Storage Class bits.
483+
* Must not set any Memory Semantics Propagation bits.
484+
485+
Note: In terms from other standards, **OpAtomic**\* instructions are _Relaxed_.
486+
487+
Note: In the memory model, atomic operations automatically include
488+
availability and visibility semantics.
489+
490+
#### Barrier instructions
491+
492+
* **OpControlBarrier**\* restrictions:
493+
* The _Execution_ scope operand must be **Workgroup**
494+
* The _Memory_ scope operand must be **Workgroup**
495+
* The _Semantics_ operand:
496+
* Memory Semantics Order bits: Must set the **AcquireRelease** bit, and no other bits.
497+
* Memory Semantics Storage Class bits: Must set the **WorkgroupMemory** bit, and no other bits.
498+
* Must not set any Memory Semantics Propagation bits.
499+
500+
Note: To ensure propagation of **Workgroup** writes to readers,
501+
individual accesses of **Workgroup** memory should use availability
502+
and visibility semantics:
503+
**MakePointerAvailableKHR** with **Workgroup** scope on writes,
504+
**MakePointerVisibleKHR** with **Workgroup** scope on reads,
505+
and **NonPrivatePointerKHR** on both.
506+
507+
* **OpMemoryBarrier**\* restrictions:
508+
* The _Memory_ scope operand must be **Workgroup**
509+
* The _Semantics_ operand:
510+
* Must not set any Memory Semantics Order bits.
511+
* Memory Semantics Storage Class bits: Must set the **ImageMemory** bit, and no other bits.
512+
* Must not set any Memory Semantics Propagation bits.
513+
514+
Note: **OpMemoryBarrier** is only used to order reads and writes by the same
515+
invocation to the same locations in image memory.
459516

460517
## Data Types and Layouts
461518

0 commit comments

Comments
 (0)