Hello,
I am trying to compute operation on a texture in a first pass then use the result in a second pass to get my final buffer.
I use the RDG to make my dispatch, everything works fine when using DirectX12 but my output texture of the first pass seems to be cleared after the pass when I use DirectX11.
Here is my code:
//1st Pass
void FBrushComputeShaderInterface::PreparePatchPass(FRDGBuilder& GraphBuilder, const FBrushComputeShaderDispatchParams& Params, FRDGTextureRef& outputTex)
{
FPatchComputeShader::bIsPainting = bIsPainting;
TShaderMapRef<FPatchComputeShader> ComputeShader(GetGlobalShaderMap(GMaxRHIFeatureLevel));
bool bIsShaderValid = ComputeShader.IsValid();
if (bIsShaderValid) {
FPatchComputeShader::FParameters* PassParameters = GraphBuilder.AllocParameters<FPatchComputeShader::FParameters>();
FRDGTextureRef patchTexture = RegisterExternalTexture(GraphBuilder, Params.RHIShape, nullptr);
PassParameters->PatchInTex = GraphBuilder.CreateSRV(patchTexture);
outputTex =
GraphBuilder.CreateTexture(
FRDGTextureDesc::Create2D(FIntPoint(Params.uPatchSize, Params.uPatchSize), EPixelFormat::PF_R8_UINT,
FClearValueBinding::Black, TexCreate_RenderTargetable | TexCreate_ShaderResource | TexCreate_UAV),
TEXT("GeneratedPatchBuffer"));
PassParameters->GeneratedPaintPatch = GraphBuilder.CreateUAV(FRDGTextureUAVDesc(outputTex));
auto GroupCount = FComputeShaderUtils::GetGroupCount(FIntVector(Params.uPatchSize, Params.uPatchSize, 1), FComputeShaderUtils::kGolden2DGroupSize);
GraphBuilder.AddPass(
RDG_EVENT_NAME("ExecutePatchComputeShader"),
PassParameters,
ERDGPassFlags::Compute,
[PassParameters, ComputeShader, GroupCount, outputTex](FRHIComputeCommandList& RHICmdList)
{
FComputeShaderUtils::Dispatch(RHICmdList, ComputeShader, *PassParameters, GroupCount);
}
);
}
}
//2nd Pass
//Here patch tex is the previous outputTex
void FBrushComputeShaderInterface::PreparePaintPass(FRDGBuilder& GraphBuilder, const FBrushComputeShaderDispatchParams& Params, FRDGBufferRef& outputBuffer,
unsigned int& NumOutputs, const FRDGTextureRef& patchTex)
{
typename FBrushComputeShader::FPermutationDomain PermutationVector;
bool bIsPainting = Params.eBrushType == EBrushOpType::PAINT;
FBrushComputeShader::bIsPainting = bIsPainting;
TShaderMapRef<FBrushComputeShader> ComputeShader(GetGlobalShaderMap(GMaxRHIFeatureLevel), PermutationVector);
bool bIsShaderValid = ComputeShader.IsValid();
if (bIsShaderValid) {
FBrushComputeShader::FParameters* PassParameters = GraphBuilder.AllocParameters<FBrushComputeShader::FParameters>();
int NumColors = Params.uPatchSize * Params.uPatchSize;
int NumPackedColors = (NumColors + 4 - 1) / 4;
NumOutputs = NumPackedColors;
int ColorSize = sizeof(unsigned int);
FRDGTextureRef DataTexture = RegisterExternalTexture(GraphBuilder, Params.RHIColors, nullptr);
PassParameters->DataInTex = GraphBuilder.CreateSRV(DataTexture);
PassParameters->GeneratedPaintPatch = GraphBuilder.CreateSRV(patchTex);
FRDGTextureDesc OutputColorDesc(TargetTexture->Desc);
OutputColorDesc.Flags |= ETextureCreateFlags::UAV;
outputBuffer =
GraphBuilder.CreateBuffer(
FRDGBufferDesc::CreateBufferDesc(ColorSize, NumPackedColors),
TEXT("OutputColorBuffer"));
PassParameters->OutputBuf = GraphBuilder.CreateUAV(FRDGBufferUAVDesc(outputBuffer, PF_R32_UINT));
auto RHISourceTex = Params.RHIColors;
auto GroupCount = FComputeShaderUtils::GetGroupCount(FIntVector(Params.uPatchSize / 4, Params.uPatchSize / 4, 1), FComputeShaderUtils::kGolden2DGroupSize);
GraphBuilder.AddPass(
RDG_EVENT_NAME("ExecuteBrushComputeShader"),
PassParameters,
ERDGPassFlags::Compute,
[PassParameters, ComputeShader, GroupCount](FRHIComputeCommandList& RHICmdList)
{
FComputeShaderUtils::Dispatch(RHICmdList, ComputeShader, *PassParameters, GroupCount);
}
);
}
}
How can I fix this ?