# Error in Computer Shader "Accessing the RHI resource at this time is not allowed" (5.4.2)

**URL:** <https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634>\
**Category:** Rendering\
**Tags:** unreal-engine, Rendering, CPP, question, Global-Shaders\
**Created:** [June 25, 2024, 5:02am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634 "2024-06-25T05:02:07Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Myxcil](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/myxcil/32/952596_2.png) [@Myxcil](https://forums.unrealengine.com/u/Myxcil)\
**Post date:** [June 25, 2024, 5:02am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/1 "2024-06-25T05:02:07Z")

</div>

Hi,

I have a problem with a compute shader.  
I try to run a pass several times for a fluid simulation but I keep getting the following error:

```auto
Assertion failed: DebugData->bAllowRHIAccess || GRDGAllowRHIAccess [File:D:\build\++UE5\Sync\Engine\Source\Runtime\RenderCore\Private\RenderGraphValidation.cpp] [Line: 56] 
Accessing the RHI resource of Pressure0 at this time is not allowed. If you hit this check in pass, that is due to this resource not being referenced in the parameters of your pass.

```

Pressure0 (and Pressure1) being the two FRDGTextureRefs created beforehand. Here is the paragraph in question:  
[FireSimulation.cpp](https://github.com/Myxcil/UETestProject/blob/fe47d1f0a71bebc3d185d0927d110f3e92c6495b/Plugins/FireSimulation/Source/FireSimulation/Private/FireSimulation.cpp#L484)

If I comment this block out, everything runs fine as far as I can tell. Anyone has an idea, what I’m doing wrong?

Cheers,  
Markus

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [June 25, 2024, 7:31am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/2 "2024-06-25T07:31:34Z")

</div>

Neither “current velocity state” or “divergence result” are valid parameters.  
a) you cannot have spaces in your variable names  
b) there is nothing even resembling these variables carrying any type of value.

Are they some sort of temporary descriptive variables for parameters that are planned for implementation?

---

<div class="post-metadata">

**Author:** ![Myxcil](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/myxcil/32/952596_2.png) [@Myxcil](https://forums.unrealengine.com/u/Myxcil)\
**Post date:** [June 25, 2024, 7:49am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/3 "2024-06-25T07:49:25Z")

</div>

No, they are just comments to indicate which results are currently stored in the temporary textures that I need in the previous passes.

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [June 25, 2024, 9:49am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/4 "2024-06-25T09:49:49Z")

</div>

How can I check if the function works correctly? What can I expect to see?

The system was constantly complaining about parameters not being ready. So I decided to push the allocation out of the loop and do it once.

```auto
						FFireShaderPressureCS::FParameters* Params = GraphBuilder.AllocParameters<FFireShaderPressureCS::FParameters>();

						for(int32 I=1; I < Config.NumPressureIterations; ++I)
						{							
							
							Params->VelocityBounds = Velocity.Bounds;							
							Params->obstaclesIn = GraphBuilder.CreateSRV(ObstaclesTexture);
							Params->divergenceIn = GraphBuilder.CreateSRV(Divergence);
							
							Params->pressureIn = GraphBuilder.CreateSRV(Pressure[SourceIndex]);							
							Params->outputFloat = GraphBuilder.CreateUAV(Pressure[DestIndex]);
																					
							GraphBuilder.AddPass(
								RDG_EVENT_NAME("Pressure"),
								Params,
								ERDGPassFlags::AsyncCompute,								
								[&Params, Shader, GroupCount,I](FRHIComputeCommandList& RHICmdList)
								{																													
UE_LOG(LogTemp, Warning, TEXT("pressureIn: %d"), Params->pressureIn);
										FComputeShaderUtils::Dispatch(RHICmdList, Shader, *Params, GroupCount);																			
								});
							
							Swap(SourceIndex, DestIndex);

						}
					}
				}
			}

```

I’m getting the following readings

 ![presure](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/9/8/79888f4fac1d98e86b6a4f215061f070cb16518a.png)  
Are they within the range of expected parameters for pressure?

---

<div class="post-metadata">

**Author:** ![glitchered](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/glitchered/32/768299_2.png) [@glitchered](https://forums.unrealengine.com/u/glitchered)\
**Post date:** [June 25, 2024, 10:27am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/5 "2024-06-25T10:27:41Z")

</div>

that looks normal. the log output is the pointer of the pressure srv. you should display this in hex, not decimal.

btw the loop should be

> for(int32 I=1; I \<= Config.NumPressureIterations; I++)

to get the 8 iterations.

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [June 25, 2024, 10:41am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/6 "2024-06-25T10:41:35Z")

</div>

Needs to start from 0 because it’s comparing less than and not less than even to get full 8 loops

```auto
for(int32 I=0; I < Config.NumPressureIterations; I++)
{							
}

```

I was mostly addressing the crash though

Not really sure if you can even output FRDGTextureSRVRef properly.

---

<div class="post-metadata">

**Author:** ![Myxcil](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/myxcil/32/952596_2.png) [@Myxcil](https://forums.unrealengine.com/u/Myxcil)\
**Post date:** [June 26, 2024, 8:21am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/7 "2024-06-26T08:21:08Z")

</div>

Actually not because the first iteration is already done in the prepare pass which fills the Pressure[0] texture.

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [June 26, 2024, 8:28am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/8 "2024-06-26T08:28:14Z")

</div>

Did moving the allocation above the loop fix the crash? Does it work as intended?

---

<div class="post-metadata">

**Author:** ![Myxcil](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/myxcil/32/952596_2.png) [@Myxcil](https://forums.unrealengine.com/u/Myxcil)\
**Post date:** [June 26, 2024, 8:32am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/9 "2024-06-26T08:32:59Z")

</div>

I’m not sure the paramters are stored somewhere, so wouldn’t that change the params from the earlier passes?

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [June 26, 2024, 8:35am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/10 "2024-06-26T08:35:25Z")

</div>

They are assigned on a per loop basis and automatically dispatched in the next line, so I don’t think so. If they were in the loop they would be destroyed anyway because of how scopes work.

---

<div class="post-metadata">

**Author:** ![Myxcil](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/myxcil/32/952596_2.png) [@Myxcil](https://forums.unrealengine.com/u/Myxcil)\
**Post date:** [June 26, 2024, 8:53am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/11 "2024-06-26T08:53:33Z")

</div>

As it turns out, the parameters are created on the heap and managed by the GraphBuilder.  
So modifying the Params struct after it got sent to the Pass is a no-no. Scope has nothing to do with it.

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [June 26, 2024, 10:16am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/12 "2024-06-26T10:16:52Z")

</div>

After a little more experimenting I noticed that if you remove the swap command Swap(SourceIndex, DestIndex); the project works.

Upon re-enabling it I think that the problem is that the pressure textures assigned in

```auto
Params->pressureIn = GraphBuilder.CreateSRV(PressureTemp[SourceIndex]);
Params->outputFloat = GraphBuilder.CreateUAV(PressureTemp[DestIndex]);

```

are marked as used and become unusable inside of the loop as their resources are probably released after assignment or locked as they have been sent in dispatch.

Changed code

```auto
for(int32 I=1; I < Config.NumPressureIterations; ++I)
{
				FFireShaderPressureCS::FParameters* Params = GraphBuilder.AllocParameters<FFireShaderPressureCS::FParameters>();

				const FRDGTextureRef PressureTemp[2] =
				{
					GraphBuilder.CreateTexture(CreateTextureDesc(Velocity.Resolution, false), TEXT("Pressure0")),
					GraphBuilder.CreateTexture(CreateTextureDesc(Velocity.Resolution, false), TEXT("Pressure1"))
				};
											
				Params->VelocityBounds = Velocity.Bounds;							
				Params->pressureIn = GraphBuilder.CreateSRV(PressureTemp[SourceIndex]);
				Params->divergenceIn = GraphBuilder.CreateSRV(Divergence);
				Params->obstaclesIn = GraphBuilder.CreateSRV(ObstaclesTexture);
				Params->outputFloat = GraphBuilder.CreateUAV(PressureTemp[DestIndex]);

				GraphBuilder.AddPass(
					RDG_EVENT_NAME("Pressure"),
					Params,
					ERDGPassFlags::AsyncCompute,
					[&Params, Shader, GroupCount, I](FRHIComputeCommandList& RHICmdList)
					{																		
						FComputeShaderUtils::Dispatch(RHICmdList, Shader, *Params, GroupCount);
					}
				);
				
				Swap(SourceIndex, DestIndex);														
}

```

It stops the RHI error, but it does trigger a single MarkAsConsumed error.

If could be due to persure0 being empty during the first pass

Edit:

As a further optimization the descriptions themselves can be pulled out of the loop, they don’t seem to loose the RHI as I think it might be generated and assigned from within GraphBuilder.CreateTexture()

```auto
FRDGTextureDesc p0 = CreateTextureDesc(Velocity.Resolution, false);
FRDGTextureDesc p1 = CreateTextureDesc(Velocity.Resolution, false);

for(int32 I=0; I < Config.NumPressureIterations; I++)
{
				FFireShaderPressureCS::FParameters* Params = GraphBuilder.AllocParameters<FFireShaderPressureCS::FParameters>();

				const FRDGTextureRef PressureTemp[2] =
				{
					GraphBuilder.CreateTexture(p0, TEXT("Pressure0")),
					GraphBuilder.CreateTexture(p1, TEXT("Pressure1"))
				};
/// rest of code 
}

```

---

<div class="post-metadata">

**Author:** ![Myxcil](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/myxcil/32/952596_2.png) [@Myxcil](https://forums.unrealengine.com/u/Myxcil)\
**Post date:** [June 26, 2024, 11:45am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/13 "2024-06-26T11:45:13Z")

</div>

But that doesn’t make any sense anymore. The shader needs the output from the previous pass:

1. PressureCS Input: Pressure0, Output: Pressure1
2. PressureCS Input: Pressure1, Output: Pressure0
3. PressureCS Input: Pressure0, Output: Pressure1  
…

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [June 26, 2024, 11:58am UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/14 "2024-06-26T11:58:46Z")

</div>

perhaps you need to make it sharable for it to not become invalidated?

```auto
TSharedPtr<FRDGTextureRef> SharedPressure = MakeShareable(Pressure);

```

---

<div class="post-metadata">

**Author:** ![glitchered](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/glitchered/32/768299_2.png) [@glitchered](https://forums.unrealengine.com/u/glitchered)\
**Post date:** [June 26, 2024, 12:02pm UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/15 "2024-06-26T12:02:14Z")

</div>

how async is the compute? i mean you have to wait for the result of one iteration before you do the next. this will not run in parallel. the resources are locked while it does one compute pass. if you would tile the resources you could run the algorithm in parallel per tile. in the end you have to wait for the entire loop to finish, anyway. given it runs at full compute speed it will not be faster either way.

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [June 26, 2024, 12:03pm UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/16 "2024-06-26T12:03:56Z")

</div>

you can just switch to ERDGPassFlags::Compute not that fixes the situation.

---

<div class="post-metadata">

**Author:** ![Myxcil](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/myxcil/32/952596_2.png) [@Myxcil](https://forums.unrealengine.com/u/Myxcil)\
**Post date:** [June 26, 2024, 2:52pm UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/17 "2024-06-26T14:52:44Z")

</div>

But why does it work with the previous passes?  
There are quite a lot of output textures that are used as input in the next pass.

---

<div class="post-metadata">

**Author:** ![Myxcil](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/myxcil/32/952596_2.png) [@Myxcil](https://forums.unrealengine.com/u/Myxcil)\
**Post date:** [June 26, 2024, 2:53pm UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/18 "2024-06-26T14:53:38Z")

</div>

I’m not sure that this works as the FRDGTexture is managed by the GraphBuilder and valid throughout it’s lifetime.

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [June 26, 2024, 4:19pm UTC](https://forums.unrealengine.com/t/error-in-computer-shader-accessing-the-rhi-resource-at-this-time-is-not-allowed-5-4-2/1915634/19 "2024-06-26T16:19:45Z")

</div>

Perhaps you should somehow push this to a buffer first and then assigned in the loop

I’ve noticed that the engine has  
FRDGBufferSRVRef  
FRDGBufferSRV

This might not cause direct access errors.
