Download

Dispatch to differents entryPoint/Kernel in shader

Hi,
I’m using compute shaders, using the RDG graphBuilder, and I need to call a sequence of functions (for simulations purposes) on the shader

So my goal is to have something like :

for (int x=0; x < NSubSteps; ++x)
{
    //Call ComputeShader EntryPointFunc1, let's say #AddVelocity
    FComputeShaderUtils::AddPass(GraphBuilder, evtName, ComputeShader, PassParams, GrpCount, EntryPointFunc1);
    //Call ComputeShader EntryPointFunc2 let's say #SolveCollisions
    FComputeShaderUtils::AddPass(GraphBuilder, evtName, ComputeShader, PassParams, GrpCount, EntryPointFunc2);
}

In Unity the equivalent is to add before each shader entryPoint: #pragma kernel kernelName
and then use Dispatch(_shader.FindKernel("funcname"))

Basically I’d like to specify the shader entrypoint into the AddPass function, or something equivalent but I can’t find any documentation about it. Because my buffers will stay the same accross all my calls of compute shaders (AddVelocity, SolveCollisions), it would be very handy to have all my shaders functions in the same file, and not having to redeclare multiple times the Shader class definition

I would apreciate some tips here,
Thanks :slight_smile:

PS: Also, little nested question: A simple compute shader call

	FRenderCommandFence Fence;
	ENQUEUE_RENDER_COMMAND(ComputeShader)(
		[
			ComputeShader,
			&Vertices,
			Dt
		](FRHICommandListImmediate& RHICmdList)
		{
			
			FRDGBuilder GraphBuilder(RHICmdList);
			FComputeShaderExampleCS::FParameters* PassParameters;
			PassParameters = GraphBuilder.AllocParameters<FComputeShaderExampleCS::FParameters>();
			FRDGBufferRef VerticesInBuffer = CreateStructuredBuffer(
				GraphBuilder,
				TEXT("Vertices_StructuredBuffer"),
				sizeof(float),
				Vertices.Num(),
				Vertices.GetData(),
				sizeof(float) * Vertices.Num()
			);
			FRDGBufferSRVRef VerticesInSRV = GraphBuilder.CreateSRV(VerticesInBuffer);
			FRDGBufferRef VerticesOutBuffer = CreateStructuredBuffer(
				GraphBuilder,
				TEXT("Vertices_StructuredBuffer"),
				sizeof(float),
				Vertices.Num(),
				Vertices.GetData(),
				sizeof(float) * Vertices.Num()
			);
			auto VerticesOutUAV = GraphBuilder.CreateUAV(VerticesOutBuffer);

			PassParameters->InVertices = VerticesInSRV;
			PassParameters->OutVertices = VerticesOutUAV;
			PassParameters->Dt = Dt;
			FComputeShaderUtils::AddPass(GraphBuilder, RDG_EVENT_NAME("Compute Pass"), ComputeShader, PassParameters, FIntVector(64, 1, 1));
			TRefCountPtr<FRDGPooledBuffer> PooledComputeTarget;
			GraphBuilder.QueueBufferExtraction(VerticesOutBuffer, &PooledComputeTarget);
			GraphBuilder.Execute();
			TRefCountPtr<FRDGPooledBuffer> test = PooledComputeTarget;
			CopyBuffer(RHICmdList, PooledComputeTarget, (void*) Vertices.GetData(), sizeof(float) * Vertices.Num());
		});
	Fence.BeginFence();
	Fence.Wait();

It takes around 0.015s to execute, which is more than a render frame length, is it something to expect with gpu communication ? It seems way longer than it should

I think you’ll get better answers in the Rendering section of the forum