File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed
apps/typegpu-docs/src/examples/algorithms/genetic-racing Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -441,17 +441,24 @@ function frame() {
441441 }
442442
443443 const stepsToRun = Math . min ( stepsPerFrame , stepsPerGeneration - steps ) ;
444- const innerSteps = Math . min ( stepsToRun , STEPS_PER_DISPATCH ) ;
445- params . writePartial ( { stepsPerDispatch : innerSteps } ) ;
446- const dispatchCount = Math . ceil ( stepsToRun / innerSteps ) ;
444+ if ( stepsToRun <= 0 ) {
445+ pendingEvolve = true ;
446+ } else {
447+ const innerSteps = Math . min ( stepsToRun , STEPS_PER_DISPATCH ) ;
448+ params . writePartial ( { stepsPerDispatch : innerSteps } ) ;
449+ const dispatchCount = Math . ceil ( stepsToRun / innerSteps ) ;
450+
451+ const simEncoder = root . device . createCommandEncoder ( ) ;
452+ for ( let dispatch = 0 ; dispatch < dispatchCount ; dispatch ++ ) {
453+ simulatePipeline
454+ . with ( simBindGroups [ ga . current ] )
455+ . with ( simEncoder )
456+ . dispatchThreads ( population ) ;
457+ }
458+ root . device . queue . submit ( [ simEncoder . finish ( ) ] ) ;
447459
448- const simEncoder = root . device . createCommandEncoder ( ) ;
449- for ( let dispatch = 0 ; dispatch < dispatchCount ; dispatch ++ ) {
450- simulatePipeline . with ( simBindGroups [ ga . current ] ) . with ( simEncoder ) . dispatchThreads ( population ) ;
460+ steps += dispatchCount * innerSteps ;
451461 }
452- root . device . queue . submit ( [ simEncoder . finish ( ) ] ) ;
453-
454- steps += dispatchCount * innerSteps ;
455462
456463 if ( steps >= stepsPerGeneration ) {
457464 pendingEvolve = true ;
You can’t perform that action at this time.
0 commit comments