@@ -15,24 +15,30 @@ enum StepEnum {
1515 DISPERSE_GLOBAL ,
1616}
1717
18- // String access to StepEnum
1918type StepType =
19+ // NONE: No sort step has or will occur
2020 | '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.
2123 | 'FLIP_LOCAL'
24+ // DISPERSE_LOCAL A sort step that performs a flip operation over indices in a workgroup's locally addressable area.
2225 | '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.
2327 | '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.
2429 | 'DISPERSE_GLOBAL' ;
2530
2631type DisplayType = 'Elements' | 'Swap Highlight' ;
2732
2833// Gui settings object
2934interface SettingsInterface {
3035 'Total Elements' : number ;
31- 'Invoke Limit' : number ;
3236 'Grid Width' : number ;
3337 'Grid Height' : number ;
3438 'Grid Dimensions' : string ;
35- Invocations : number ;
39+ 'Workgroup Size' : number ;
40+ 'Size Limit' : number ;
41+ 'Workgroups Per Step' : number ;
3642 'Hovered Cell' : number ;
3743 'Swapped Cell' : number ;
3844 'Current Step' : string ;
@@ -42,15 +48,14 @@ interface SettingsInterface {
4248 'Next Step' : StepType ;
4349 'Prev Swap Span' : number ;
4450 'Next Swap Span' : number ;
45- 'Total Workgroups' : number ;
46- 'Display Mode' : DisplayType ;
47- 'Total Swaps' : number ;
4851 executeStep : boolean ;
4952 'Randomize Values' : ( ) => void ;
5053 'Execute Sort Step' : ( ) => void ;
5154 'Log Elements' : ( ) => void ;
5255 'Complete Sort' : ( ) => void ;
5356 'Sort Speed' : number ;
57+ 'Display Mode' : DisplayType ;
58+ 'Total Swaps' : number ;
5459}
5560
5661const getNumSteps = ( numElements : number ) => {
@@ -63,15 +68,15 @@ SampleInitFactoryWebGPU(
6368 async ( { pageState, device, gui, presentationFormat, context, canvas } ) => {
6469 const maxInvocationsX = device . limits . maxComputeWorkgroupSizeX ;
6570
66- const totalElementLengths = [ ] ;
71+ const totalElementOptions = [ ] ;
6772 const maxElements = maxInvocationsX * 32 ;
6873 for ( let i = maxElements ; i >= 4 ; i /= 2 ) {
69- totalElementLengths . push ( i ) ;
74+ totalElementOptions . push ( i ) ;
7075 }
7176
72- const totalInvocationLengths : number [ ] = [ ] ;
77+ const sizeLimitOptions : number [ ] = [ ] ;
7378 for ( let i = maxInvocationsX ; i >= 2 ; i /= 2 ) {
74- totalInvocationLengths . push ( i ) ;
79+ sizeLimitOptions . push ( i ) ;
7580 }
7681
7782 const defaultGridWidth =
@@ -82,56 +87,73 @@ SampleInitFactoryWebGPU(
8287 const defaultGridHeight = maxElements / defaultGridWidth ;
8388
8489 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
8692 '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
9094 'Grid Width' : defaultGridWidth ,
9195 // height of screen in cells
9296 'Grid Height' : defaultGridHeight ,
9397 // Grid Dimensions as string
9498 '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
98111 '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.
100113 '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.
102117 'Step Index' : 0 ,
103- // Total steps to sort current number of elements
118+ // The total number of steps required to sort the displayed elements.
104119 '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.
106121 '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'
108123 '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'
110125 '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.
112127 '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.
114129 '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.
120133 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.
122135 'Randomize Values' : ( ) => {
123136 return ;
124137 } ,
138+ // A function that manually executes a single step of the bitonic sort.
125139 'Execute Sort Step' : ( ) => {
126140 return ;
127141 } ,
142+ // A function that logs the values of each element as an array to the browser's console.
128143 'Log Elements' : ( ) => {
129144 return ;
130145 } ,
146+ // A function that automatically executes each step of the bitonic sort at an interval determined by 'Sort Speed'
131147 'Complete Sort' : ( ) => {
132148 return ;
133149 } ,
150+ // The speed at which each step of the bitonic sort will be executed after 'Complete Sort' has been called.
134151 '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 ,
135157 } ;
136158
137159 // Initialize initial elements array
@@ -141,7 +163,7 @@ SampleInitFactoryWebGPU(
141163
142164 // Initialize elementsBuffer and elementsStagingBuffer
143165 const elementsBufferSize =
144- Float32Array . BYTES_PER_ELEMENT * totalElementLengths [ 0 ] ;
166+ Float32Array . BYTES_PER_ELEMENT * totalElementOptions [ 0 ] ;
145167 // Initialize input, output, staging buffers
146168 const elementsInputBuffer = device . createBuffer ( {
147169 size : elementsBufferSize ,
@@ -406,14 +428,14 @@ SampleInitFactoryWebGPU(
406428 // i.e elements sorted, invocations per workgroup, and workgroups dispatched
407429 const computeResourcesFolder = gui . addFolder ( 'Compute Resources' ) ;
408430 computeResourcesFolder
409- . add ( settings , 'Total Elements' , totalElementLengths )
431+ . add ( settings , 'Total Elements' , totalElementOptions )
410432 . onChange ( ( ) => {
411433 endSortInterval ( ) ;
412434 resizeElementArray ( ) ;
413435 invokeLimitController . domElement . style . pointerEvents = 'auto' ;
414436 } ) ;
415437 const invokeLimitController = computeResourcesFolder
416- . add ( settings , 'Invoke Limit' , totalInvocationLengths )
438+ . add ( settings , 'Invoke Limit' , sizeLimitOptions )
417439 . onChange ( ( ) => {
418440 const constraint = Math . min (
419441 settings [ 'Total Elements' ] / 2 ,
0 commit comments