Shadeup icon indicating copy to clipboard operation
Shadeup copied to clipboard

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

Open john012343210 opened this issue 1 year ago • 3 comments

// 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?

john012343210 avatar Oct 18 '24 15:10 john012343210

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

AskingQuestions avatar Oct 18 '24 16:10 AskingQuestions

@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?

john012343210 avatar Oct 19 '24 13:10 john012343210

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.

AskingQuestions avatar Oct 19 '24 19:10 AskingQuestions