Good afternoon all. I’ve been reading about the Render Dependency Graph this weekend, and one thing that seems to be lacking is an example of how to assign a UTexture to a shader’s FRDGTexture* parameter slot.
In DirectX12 this would involve calling GetCopyableFootprints to obtain the size needed for the resource’s format and mip chain requirements, creating an intermediate buffer in the resource heap and copying the data to it, and then issuing a command to copy from that intermediate resource to the destination.
That last bit looks like it would be covered with a Copy Texture pass (from the documentation), but I can’t figure out how to get the UTexture’s data to serve as the copy source…
1 Like
Ah ok, so this is an external texture. Well, thanks to this guy for posting his code. For a UTexture*, this seems to work for me:
//UTexture2D* InputTexture = a UPROPERTY'd UTexture2D* attached to an AActor
FSceneRenderTargetItem TextureItem;
TextureItem.TargetableTexture = InputTexture->GetResource()->GetTexture2DRHI();
TextureItem.ShaderResourceTexture = InputTexture->GetResource()->GetTexture2DRHI();
FPooledRenderTargetDesc RenderTargetDesc = FPooledRenderTargetDesc::Create2DDesc(FIntPoint(InputTexture->GetSizeX(), InputTexture->GetSizeY()), InputTexture->GetPixelFormat(), FClearValueBinding::None, TexCreate_None, TexCreate_ShaderResource | TexCreate_UAV, false);
TRefCountPtr<IPooledRenderTarget> PooledRenderTarget;
GRenderTargetPool.CreateUntrackedElement(RenderTargetDesc, PooledRenderTarget, TextureItem);
FRDGTextureRef RenderTargetRDG = GraphBuilder.RegisterExternalTexture(PooledRenderTarget, TEXT("InputTexture"));
// My shader Parameters struct has an entry of:
// SHADER_PARAMETER_RDG_TEXTURE(Texture2D<FVector4>, InputTexture)
TestParams->InputTexture = RenderTargetRDG;
2 Likes