@@ -15,24 +15,30 @@ enum StepEnum {
15
15
DISPERSE_GLOBAL ,
16
16
}
17
17
18
- // String access to StepEnum
19
18
type StepType =
19
+ // NONE: No sort step has or will occur
20
20
| 'NONE'
21
+ // FLIP_LOCAL: A sort step that performs a flip operation over indices in a workgroup's locally addressable area
22
+ // (i.e invocations * workgroup_index -> invocations * (workgroup_index + 1) - 1.
21
23
| 'FLIP_LOCAL'
24
+ // DISPERSE_LOCAL A sort step that performs a flip operation over indices in a workgroup's locally addressable area.
22
25
| 'DISPERSE_LOCAL'
26
+ // FLIP_GLOBAL A sort step that performs a flip step across a range of indices outside a workgroup's locally addressable area.
23
27
| 'FLIP_GLOBAL'
28
+ // DISPERSE_GLOBAL A sort step that performs a disperse operation across a range of indices outside a workgroup's locally addressable area.
24
29
| 'DISPERSE_GLOBAL' ;
25
30
26
31
type DisplayType = 'Elements' | 'Swap Highlight' ;
27
32
28
33
// Gui settings object
29
34
interface SettingsInterface {
30
35
'Total Elements' : number ;
31
- 'Invoke Limit' : number ;
32
36
'Grid Width' : number ;
33
37
'Grid Height' : number ;
34
38
'Grid Dimensions' : string ;
35
- Invocations : number ;
39
+ 'Workgroup Size' : number ;
40
+ 'Size Limit' : number ;
41
+ 'Workgroups Per Step' : number ;
36
42
'Hovered Cell' : number ;
37
43
'Swapped Cell' : number ;
38
44
'Current Step' : string ;
@@ -42,15 +48,14 @@ interface SettingsInterface {
42
48
'Next Step' : StepType ;
43
49
'Prev Swap Span' : number ;
44
50
'Next Swap Span' : number ;
45
- 'Total Workgroups' : number ;
46
- 'Display Mode' : DisplayType ;
47
- 'Total Swaps' : number ;
48
51
executeStep : boolean ;
49
52
'Randomize Values' : ( ) => void ;
50
53
'Execute Sort Step' : ( ) => void ;
51
54
'Log Elements' : ( ) => void ;
52
55
'Complete Sort' : ( ) => void ;
53
56
'Sort Speed' : number ;
57
+ 'Display Mode' : DisplayType ;
58
+ 'Total Swaps' : number ;
54
59
}
55
60
56
61
const getNumSteps = ( numElements : number ) => {
@@ -63,15 +68,15 @@ SampleInitFactoryWebGPU(
63
68
async ( { pageState, device, gui, presentationFormat, context, canvas } ) => {
64
69
const maxInvocationsX = device . limits . maxComputeWorkgroupSizeX ;
65
70
66
- const totalElementLengths = [ ] ;
71
+ const totalElementOptions = [ ] ;
67
72
const maxElements = maxInvocationsX * 32 ;
68
73
for ( let i = maxElements ; i >= 4 ; i /= 2 ) {
69
- totalElementLengths . push ( i ) ;
74
+ totalElementOptions . push ( i ) ;
70
75
}
71
76
72
- const totalInvocationLengths : number [ ] = [ ] ;
77
+ const sizeLimitOptions : number [ ] = [ ] ;
73
78
for ( let i = maxInvocationsX ; i >= 2 ; i /= 2 ) {
74
- totalInvocationLengths . push ( i ) ;
79
+ sizeLimitOptions . push ( i ) ;
75
80
}
76
81
77
82
const defaultGridWidth =
@@ -82,56 +87,73 @@ SampleInitFactoryWebGPU(
82
87
const defaultGridHeight = maxElements / defaultGridWidth ;
83
88
84
89
const settings : SettingsInterface = {
85
- // number of cellElements. Must equal gridWidth * gridHeight and 'Invocations' * 2
90
+ // TOTAL ELEMENT AND GRID SETTINGS
91
+ // Num of elements to be sorted. Must equal gridWidth * gridHeight || Workgroup Size * Workgroups * 2
86
92
'Total Elements' : maxElements ,
87
- // Artificially constrain the maximum number of invocations that can be executed per workgroup
88
- 'Invoke Limit' : maxInvocationsX ,
89
- // width of screen in cells.
93
+ // width of screen in cells
90
94
'Grid Width' : defaultGridWidth ,
91
95
// height of screen in cells
92
96
'Grid Height' : defaultGridHeight ,
93
97
// Grid Dimensions as string
94
98
'Grid Dimensions' : `${ defaultGridWidth } x${ defaultGridHeight } ` ,
95
- // number of invocations to execute in a workgroup ('Invocations', 1, 1)
96
- Invocations : maxInvocationsX ,
97
- // Cell in element grid mouse element is hovering over
99
+
100
+ // INVOCATION, WORKGROUP SIZE, AND WORKGROUP DISPATCH SETTINGS
101
+ // The size of a workgroup, or the number of invocations executed within each workgroup
102
+ // Determined algorithmically based on 'Size Limit', maxInvocationsX, and the current number of elements to sort
103
+ 'Workgroup Size' : maxInvocationsX ,
104
+ // An artifical constraint on the maximum workgroup size/maximumn invocations per workgroup as specified by device.limits.maxComputeWorkgroupSizeX
105
+ 'Size Limit' : maxInvocationsX ,
106
+ // Total workgroups that are dispatched per each step of the bitonic sort
107
+ 'Workgroups Per Step' : maxElements / ( maxInvocationsX * 2 ) ,
108
+
109
+ // HOVER SETTINGS
110
+ // The element/cell in the element visualizer directly beneath the mouse cursor
98
111
'Hovered Cell' : 0 ,
99
- // element the hovered cell just swapped with,
112
+ // The element/cell in the element visualizer that the hovered cell will swap with in the next execution step of the bitonic sort.
100
113
'Swapped Cell' : 1 ,
101
- // Index of current step
114
+
115
+ // STEP INDEX, STEP TYPE, AND STEP SWAP SPAN SETTINGS
116
+ // The index of the current step in the bitonic sort.
102
117
'Step Index' : 0 ,
103
- // Total steps to sort current number of elements
118
+ // The total number of steps required to sort the displayed elements.
104
119
'Total Steps' : getNumSteps ( maxElements ) ,
105
- //Step Info as string
120
+ // A string that condenses ' Step Index' and 'Total Steps' into a single GUI Controller display element.
106
121
'Current Step' : `0 of 91` ,
107
- // Previously executed step
122
+ // The category of the previously executed step. Always begins the bitonic sort with a value of 'NONE' and ends with a value of 'DISPERSE_LOCAL'
108
123
'Prev Step' : 'NONE' ,
109
- // Next step to execute
124
+ // The category of the next step that will be executed. Always begins the bitonic sort with a value of 'FLIP_LOCAL' and ends with a value of 'NONE'
110
125
'Next Step' : 'FLIP_LOCAL' ,
111
- // Max invocation span of previous block
126
+ // The maximum span of a swap operation in the sort's previous step.
112
127
'Prev Swap Span' : 0 ,
113
- // Max invocation span of next block
128
+ // The maximum span of a swap operation in the sort's upcoming step.
114
129
'Next Swap Span' : 2 ,
115
- // Workgroups to dispatch per frame,
116
- 'Total Workgroups' : maxElements / ( maxInvocationsX * 2 ) ,
117
- // The number of swap operations executed over time
118
- 'Total Swaps' : 0 ,
119
- // Whether we will dispatch a workload this frame
130
+
131
+ // ANIMATION LOOP AND FUNCTION SETTINGS
132
+ // A flag that designates whether we will dispatch a workload this frame.
120
133
executeStep : false ,
121
- 'Display Mode' : 'Elements' ,
134
+ // A function that randomizes the values of each element. When called, all relevant values are reset to their defaults at the beginning of a sort with n elements.
122
135
'Randomize Values' : ( ) => {
123
136
return ;
124
137
} ,
138
+ // A function that manually executes a single step of the bitonic sort.
125
139
'Execute Sort Step' : ( ) => {
126
140
return ;
127
141
} ,
142
+ // A function that logs the values of each element as an array to the browser's console.
128
143
'Log Elements' : ( ) => {
129
144
return ;
130
145
} ,
146
+ // A function that automatically executes each step of the bitonic sort at an interval determined by 'Sort Speed'
131
147
'Complete Sort' : ( ) => {
132
148
return ;
133
149
} ,
150
+ // The speed at which each step of the bitonic sort will be executed after 'Complete Sort' has been called.
134
151
'Sort Speed' : 50 ,
152
+
153
+ // MISCELLANEOUS SETTINGS
154
+ 'Display Mode' : 'Elements' ,
155
+ // An atomic value representing the total number of swap operations executed over the course of the bitonic sort.
156
+ 'Total Swaps' : 0 ,
135
157
} ;
136
158
137
159
// Initialize initial elements array
@@ -141,7 +163,7 @@ SampleInitFactoryWebGPU(
141
163
142
164
// Initialize elementsBuffer and elementsStagingBuffer
143
165
const elementsBufferSize =
144
- Float32Array . BYTES_PER_ELEMENT * totalElementLengths [ 0 ] ;
166
+ Float32Array . BYTES_PER_ELEMENT * totalElementOptions [ 0 ] ;
145
167
// Initialize input, output, staging buffers
146
168
const elementsInputBuffer = device . createBuffer ( {
147
169
size : elementsBufferSize ,
@@ -406,14 +428,14 @@ SampleInitFactoryWebGPU(
406
428
// i.e elements sorted, invocations per workgroup, and workgroups dispatched
407
429
const computeResourcesFolder = gui . addFolder ( 'Compute Resources' ) ;
408
430
computeResourcesFolder
409
- . add ( settings , 'Total Elements' , totalElementLengths )
431
+ . add ( settings , 'Total Elements' , totalElementOptions )
410
432
. onChange ( ( ) => {
411
433
endSortInterval ( ) ;
412
434
resizeElementArray ( ) ;
413
435
invokeLimitController . domElement . style . pointerEvents = 'auto' ;
414
436
} ) ;
415
437
const invokeLimitController = computeResourcesFolder
416
- . add ( settings , 'Invoke Limit' , totalInvocationLengths )
438
+ . add ( settings , 'Invoke Limit' , sizeLimitOptions )
417
439
. onChange ( ( ) => {
418
440
const constraint = Math . min (
419
441
settings [ 'Total Elements' ] / 2 ,
0 commit comments