AskingQuestions / Shadeup

A language for WebGPU that makes writing shaders easier
https://shadeup.dev
144 stars 4 forks source link

It seems that dispatch need to take two arguments. May I know What should I write in the 2nd argument? #19

Open john012343210 opened 1 week ago

john012343210 commented 1 week ago

// Dispatches this shader. Can be called from any thread static void Dispatch( FnameOfTheShader9DispatchParams Params, TFunction<void(int OutputVal)> AsyncCallback ) { if (IsInRenderingThread()) { DispatchRenderThread(GetImmediateCommandList_ForRenderCommand(), Params, AsyncCallback); }else{ DispatchGameThread(Params, AsyncCallback); } }

// Params struct used to pass args to our compute shader FnameOfTheShader9DispatchParams Params(1, 1, 1);

// Fill in your input parameters here
Params.X = 123;

// Executes the compute shader and blocks until complete. You can place outputs in the params struct
FnameOfTheShader9Interface::Dispatch(Params);

It seems that dispatch need to take two arguments. May I know What should I write in the 2nd argument?

AskingQuestions commented 1 week ago

That would be a callback function:

FnameOfTheShader9Interface::Dispatch(Params, [](int OutputVal) {
  // Do something
});

The callback is run when the results are back from the gpu

john012343210 commented 1 week ago

@AskingQuestions

May I have your kind help for some guidance?

https://unreal.shadeup.dev/docs/compute/base I'm following this example, which just sum up the two numbers.

May I know in order to get the result Should I use the callback function?

AskingQuestions commented 1 week ago

May I know in order to get the result Should I use the callback function?

Correct, that callback function will be called with the resulting data in the buffer from the GPU.