x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Generate Unordered Access View from UTexture2D or RenderTarget2D

Hi,

I'm wondering if anyone has figured out how write to a rendertarget or UTexture2D from a computeshader via a UAV. Where I am currently sitting is running these on the render thread:

 runOnRenderThread(
         [OutputTexture, FeatureLevel](){
             check(IsInRenderingThread());
 
             FTexture2DRHIRef RHITex = ((FTexture2DResource*)OutputTexture->Resource)->GetTexture2DRHI();
             
             GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Texture = ") + RHITex->GetName().ToString());

             /*BREAKS HERE with a DX error*/
             FUnorderedAccessViewRHIRef TextureUAV = RHICreateUnorderedAccessView(RHITex.GetReference(), 0);
             
             /* Get global RHI command list */
             FRHICommandListImmediate& RHICmdList = GRHICommandList.GetImmediateCommandList();
         
             /** Compute shader calculation */
             TShaderMapRef<FHoverComputeShader> ComputeShader(GetGlobalShaderMap(FeatureLevel));
             RHICmdList.SetComputeShader(ComputeShader->GetComputeShader());
         
             /* Set inputs/outputs and dispatch compute shader */
             ComputeShader->SetSurfaces(RHICmdList, TextureUAV);
             DispatchComputeShader(RHICmdList, *ComputeShader, RHITex->GetSizeX() / 32, RHITex->GetSizeY() / 32, 1);
             ComputeShader->UnbindBuffers(RHICmdList);
         });

OutTexture is a RenderTarget or Texture2D pointer.

I "think" this has something to do with the Flags that UTexture2D or render target pass when generating thier own FTexture2DRHI but coming from a CUDA with OpenGL inter-op I'm not super familiar with the nuances of ComputeShaders.

If anyone has any insight on this would be appreciated. I'll keep updating as I find things for posterity.

Kind Regards, Aidan

Product Version: UE 4.18
Tags:
more ▼

asked Nov 06 '17 at 03:42 AM in Rendering

avatar image

ImmortalEmperor
115 5 5 8

avatar image hausfrau87 Jan 10 '19 at 11:18 AM
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You have to provide TexCreate_UAV to the texture flags to support calling RHICreateUnorderedAccessView on it later. Presumably this is so drivers can optimize the texture layout based on how it will be accessed.

UTexture doesn't currently support a way to pass this flag to the creation. You could add a bool property which does it.

more ▼

answered Nov 06 '17 at 04:03 PM

avatar image

DanielW STAFF
1.9k 31 11 72

avatar image ImmortalEmperor Nov 07 '17 at 06:44 AM

Thought that might be the case. Ended up implementing it and have made a pull request: https://github.com/EpicGames/UnrealEngine/pull/4186

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question