Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
john012343210 opened this issue Oct 18, 2024 · 3 comments

Comments

@john012343210
Copy link

// 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
Copy link
Owner

AskingQuestions commented Oct 18, 2024

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
Copy link
Author

@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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants