Editor crashes when attempting to create RHIUnorderedAccessView

Hi,
I’m attempting to write into the InstanceBuffer of the InstancedStaticMesh Component, in order to use a compute shader to directly write positions into the buffer from the GPU, without needing to go through the CPU.
In order to write the positions from an existing buffer that already has new positions given by a compute shader, I’m using another compute shader to update the ISM’s positions.
For that, I’m attempting to create an RHIUnorderedAccessView from the ISM origins buffer, which is a VertexBuffer.
However, when attempting to execute the code, the program crashes, giving the following assertion failure:
Error: Direct3DDevice->CreateUnorderedAccessView(VertexBuffer->Resource,&UAVDesc,(ID3D11UnorderedAccessView**)UnorderedAccessView.GetInitReference()) failed
at D:/Build/++UE4/Sync/Engine/Source/Runtime/Windows/D3D11RHI/Private/D3D11UAV.cpp:139
with error E_INVALIDARG

The relevant code is here: (HISM is a reference to a Hierarcical Static Mesh Component)

Hism->SetSimulatePhysics(false);
Hism->SetMobility(EComponentMobility::Movable);
Hism->SetCollisionEnabled(ECollisionEnabled::NoCollision);
Hism->SetCanEverAffectNavigation(false);
Hism->SetCollisionProfileName(TEXT(“NoCollision”));

auto render_data = Hism->PerInstanceRenderData;
auto originBuffer = render_data->InstanceBuffer.GetInstanceOriginBuffer();
auto transformBuffer = render_data->InstanceBuffer.GetInstanceTransformBuffer();

uint8 theFormat = PF_A32B32G32R32F;
UE_LOG(LogTemp, Log, TEXT(“Attempting to RHICreateUnorderedAccessView first time…”));
FRHIVertexBuffer* positionsVertexBuffer = originBuffer.GetReference();
FUnorderedAccessViewRHIRef positionsUAV = RHICreateUnorderedAccessView(positionsVertexBuffer, theFormat);

If anyone has any idea how to solve this, I would be grateful.

1 Like