@@ -93,7 +93,7 @@ test('Computation#dispatchIndirect', async t => {
9393 usage : Buffer . STORAGE | Buffer . COPY_SRC
9494 } ) ;
9595 const dispatchBuffer = webgpuDevice . createBuffer ( {
96- data : new Uint32Array ( [ 4 , 1 , 1 ] ) ,
96+ data : new Uint32Array ( [ 4 , 1 , 1 , 1 , 1 , 1 ] ) ,
9797 usage : Buffer . INDIRECT
9898 } ) ;
9999 computation . setBindings ( { data : workBuffer } ) ;
@@ -103,11 +103,43 @@ test('Computation#dispatchIndirect', async t => {
103103 computePass . end ( ) ;
104104 webgpuDevice . submit ( ) ;
105105
106- const computedData = new Int32Array ( await workBuffer . readAsync ( ) ) ;
106+ const computedBytes = await workBuffer . readAsync ( ) ;
107+ const computedData = new Int32Array (
108+ computedBytes . buffer ,
109+ computedBytes . byteOffset ,
110+ computedBytes . byteLength / Int32Array . BYTES_PER_ELEMENT
111+ ) ;
107112 t . deepEqual ( Array . from ( computedData ) , [ 2 , 4 , 6 , 8 ] , 'GPU-written dimensions drive dispatch' ) ;
108113
114+ const offsetWorkBuffer = webgpuDevice . createBuffer ( {
115+ data : new Int32Array ( [ 1 , 2 , 3 , 4 ] ) ,
116+ usage : Buffer . STORAGE | Buffer . COPY_SRC
117+ } ) ;
118+ computation . setBindings ( { data : offsetWorkBuffer } ) ;
119+ const offsetComputePass = webgpuDevice . beginComputePass ( { } ) ;
120+ computation . dispatchIndirect (
121+ offsetComputePass ,
122+ dispatchBuffer ,
123+ 3 * Uint32Array . BYTES_PER_ELEMENT
124+ ) ;
125+ offsetComputePass . end ( ) ;
126+ webgpuDevice . submit ( ) ;
127+
128+ const offsetComputedBytes = await offsetWorkBuffer . readAsync ( ) ;
129+ const offsetComputedData = new Int32Array (
130+ offsetComputedBytes . buffer ,
131+ offsetComputedBytes . byteOffset ,
132+ offsetComputedBytes . byteLength / Int32Array . BYTES_PER_ELEMENT
133+ ) ;
134+ t . deepEqual (
135+ Array . from ( offsetComputedData ) ,
136+ [ 2 , 2 , 3 , 4 ] ,
137+ 'nonzero byte offset selects the requested dispatch record'
138+ ) ;
139+
109140 computation . destroy ( ) ;
110141 workBuffer . destroy ( ) ;
142+ offsetWorkBuffer . destroy ( ) ;
111143 dispatchBuffer . destroy ( ) ;
112144 }
113145 t . end ( ) ;
0 commit comments