Skip to content

Commit 914eaeb

Browse files
committed
better docs
1 parent c194ae5 commit 914eaeb

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed

docs/computesim.html

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ <h1 class="title">src/computesim</h1>
5555
<li><a class="reference" id="parameters_toc" href="#parameters">Parameters</a></li>
5656
<li><a class="reference" id="compute-function-signature_toc" href="#compute-function-signature">Compute Function Signature</a></li>
5757
<li><a class="reference" id="example_toc" href="#example">Example</a></li>
58+
<li><a class="reference" id="glsl-builtminusin-variables_toc" href="#glsl-builtminusin-variables">GLSL Built-in Variables</a></li>
5859
<li><a class="reference" id="cuda-to-glsl-translation-table_toc" href="#cuda-to-glsl-translation-table">CUDA to GLSL Translation Table</a></li>
5960
</ul><li>
6061
<a class="reference reference-toplevel" href="#6" id="56">Imports</a>
@@ -150,6 +151,22 @@ <h2><a class="toc-backref" id="example" href="#example">Example</a></h2><p><pre
150151
<span class="Identifier">Args</span><span class="Punctuation">(</span><span class="Identifier">factor</span><span class="Punctuation">:</span> <span class="Identifier">coarseFactor</span><span class="Punctuation">)</span>
151152
<span class="Punctuation">)</span></pre></p>
152153

154+
<h2><a class="toc-backref" id="glsl-builtminusin-variables" href="#glsl-builtminusin-variables">GLSL Built-in Variables</a></h2><table border="1" class="docutils"><tr><th>GLSL Constant</th><th>Type</th><th>Description</th></tr>
155+
<tr><td>gl_WorkGroupID</td><td>UVec3</td><td>ID of the current workgroup [0..gl_NumWorkGroups)</td></tr>
156+
<tr><td>gl_WorkGroupSize</td><td>UVec3</td><td>Size of the workgroup (x, y, z)</td></tr>
157+
<tr><td>gl_NumWorkGroups</td><td>UVec3</td><td>Total number of workgroups (x, y, z)</td></tr>
158+
<tr><td>gl_NumSubgroups</td><td>uint32</td><td>Number of subgroups in the workgroup</td></tr>
159+
<tr><td>gl_SubgroupID</td><td>uint32</td><td>ID of the current subgroup [0..gl_NumSubgroups)</td></tr>
160+
<tr><td>gl_GlobalInvocationID</td><td>UVec3</td><td>Global ID of the current invocation [0..gl_NumWorkGroups * gl_WorkGroupSize)</td></tr>
161+
<tr><td>gl_LocalInvocationID</td><td>UVec3</td><td>Local ID within the workgroup [0..gl_WorkGroupSize)</td></tr>
162+
<tr><td>gl_SubgroupSize</td><td>uint32</td><td>Size of subgroups (constant across all subgroups)</td></tr>
163+
<tr><td>gl_SubgroupInvocationID</td><td>uint32</td><td>ID of the invocation within the subgroup [0..gl_SubgroupSize)</td></tr>
164+
<tr><td>gl_SubgroupEqMask</td><td>UVec4</td><td>Mask with bit set only at current invocation's index</td></tr>
165+
<tr><td>gl_SubgroupGeMask</td><td>UVec4</td><td>Mask with bits set at and above current invocation's index</td></tr>
166+
<tr><td>gl_SubgroupGtMask</td><td>UVec4</td><td>Mask with bits set above current invocation's index</td></tr>
167+
<tr><td>gl_SubgroupLeMask</td><td>UVec4</td><td>Mask with bits set at and below current invocation's index</td></tr>
168+
<tr><td>gl_SubgroupLtMask</td><td>UVec4</td><td>Mask with bits set below current invocation's index</td></tr>
169+
</table>
153170
<h2><a class="toc-backref" id="cuda-to-glsl-translation-table" href="#cuda-to-glsl-translation-table">CUDA to GLSL Translation Table</a></h2><table border="1" class="docutils"><tr><th>CUDA Concept</th><th>GLSL Equivalent</th><th>Description</th></tr>
154171
<tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">blockDim</span></span></tt></td><td><tt class="docutils literal"><span class="pre"><span class="Identifier">gl_WorkGroupSize</span></span></tt></td><td>The size of a thread block (CUDA) or work group (GLSL)</td></tr>
155172
<tr><td><tt class="docutils literal"><span class="pre"><span class="Identifier">gridDim</span></span></tt></td><td><tt class="docutils literal"><span class="pre"><span class="Identifier">gl_NumWorkGroups</span></span></tt></td><td>The size of the grid (CUDA) or the number of work groups (GLSL)</td></tr>
@@ -172,8 +189,8 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>
172189
<dd>
173190

174191

175-
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim.nim#L94" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
176-
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim.nim#L94" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
192+
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim.nim#L113" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
193+
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim.nim#L113" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
177194

178195
</dd>
179196
</div>
@@ -190,8 +207,8 @@ <h1><a class="toc-backref" href="#18">Templates</a></h1>
190207
<dd>
191208

192209

193-
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim.nim#L197" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
194-
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim.nim#L197" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
210+
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim.nim#L216" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
211+
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim.nim#L216" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
195212

196213
</dd>
197214
</div>
@@ -201,8 +218,8 @@ <h1><a class="toc-backref" href="#18">Templates</a></h1>
201218
<dd>
202219

203220

204-
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim.nim#L203" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
205-
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim.nim#L203" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
221+
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim.nim#L222" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
222+
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim.nim#L222" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
206223

207224
</dd>
208225
</div>
@@ -218,7 +235,7 @@ <h1><a class="toc-backref" href="#18">Templates</a></h1>
218235
<div class="twelve-columns footer">
219236
<span class="nim-sprite"></span>
220237
<br>
221-
<small style="color: var(--hint);">Made with Nim. Generated: 2025-01-20 16:18:11 UTC</small>
238+
<small style="color: var(--hint);">Made with Nim. Generated: 2025-01-20 16:26:58 UTC</small>
222239
</div>
223240
</div>
224241
</div>

src/computesim.nim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@
7474
## )
7575
## ```
7676
##
77+
## ## GLSL Built-in Variables
78+
##
79+
## | GLSL Constant | Type | Description |
80+
## |--------------|------|-------------|
81+
## | gl_WorkGroupID | UVec3 | ID of the current workgroup [0..gl_NumWorkGroups) |
82+
## | gl_WorkGroupSize | UVec3 | Size of the workgroup (x, y, z) |
83+
## | gl_NumWorkGroups | UVec3 | Total number of workgroups (x, y, z) |
84+
## | gl_NumSubgroups | uint32 | Number of subgroups in the workgroup |
85+
## | gl_SubgroupID | uint32 | ID of the current subgroup [0..gl_NumSubgroups) |
86+
## | gl_GlobalInvocationID | UVec3 | Global ID of the current invocation [0..gl_NumWorkGroups * gl_WorkGroupSize) |
87+
## | gl_LocalInvocationID | UVec3 | Local ID within the workgroup [0..gl_WorkGroupSize) |
88+
## | gl_SubgroupSize | uint32 | Size of subgroups (constant across all subgroups) |
89+
## | gl_SubgroupInvocationID | uint32 | ID of the invocation within the subgroup [0..gl_SubgroupSize) |
90+
## | gl_SubgroupEqMask | UVec4 | Mask with bit set only at current invocation's index |
91+
## | gl_SubgroupGeMask | UVec4 | Mask with bits set at and above current invocation's index |
92+
## | gl_SubgroupGtMask | UVec4 | Mask with bits set above current invocation's index |
93+
## | gl_SubgroupLeMask | UVec4 | Mask with bits set at and below current invocation's index |
94+
## | gl_SubgroupLtMask | UVec4 | Mask with bits set below current invocation's index |
95+
##
7796
## ## CUDA to GLSL Translation Table
7897
##
7998
## | CUDA Concept | GLSL Equivalent | Description |

src/computesim/core.nim

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,20 @@ type
8686
groupMemoryBarrier, reconverge, invalid:
8787
discard
8888

89-
BarrierHandle* = object
90-
x: ptr Barrier
91-
9289
WorkGroupContext* = object
93-
gl_WorkGroupID*: UVec3 ## ID of the current workgroup [0..gl_NumWorkGroups)
94-
gl_WorkGroupSize*: UVec3 ## Size of the workgroup (x, y, z)
95-
gl_NumWorkGroups*: UVec3 ## Total number of workgroups (x, y, z)
96-
gl_NumSubgroups*: uint32 ## Number of subgroups in the workgroup
97-
gl_SubgroupID*: uint32 ## ID of the current subgroup [0..gl_NumSubgroups)
90+
gl_WorkGroupID*: UVec3
91+
gl_WorkGroupSize*: UVec3
92+
gl_NumWorkGroups*: UVec3
93+
gl_NumSubgroups*: uint32
94+
gl_SubgroupID*: uint32
9895

9996
ThreadContext* = object
100-
gl_GlobalInvocationID*: UVec3 ## Global ID of the current invocation [0..gl_NumWorkGroups*gl_WorkGroupSize)
101-
gl_LocalInvocationID*: UVec3 ## Local ID within the workgroup [0..gl_WorkGroupSize)
102-
gl_SubgroupInvocationID*: uint32 ## ID of the invocation within the subgroup [0..gl_SubgroupSize)
97+
gl_GlobalInvocationID*: UVec3
98+
gl_LocalInvocationID*: UVec3
99+
gl_SubgroupInvocationID*: uint32
100+
101+
BarrierHandle* = object
102+
x: ptr Barrier
103103

104104
proc toValue*[T](val: T): RawValue {.noinit.} =
105105
cast[ptr T](addr result.data)[] = val

0 commit comments

Comments
 (0)