How to pass Texture2D to compute shader

I’m working on a compute shader plugin. It works fine – until I try to add a texture2d shader parameter.

In my shader CPP I declare the paramter blocks like this:

	DECLARE_GLOBAL_SHADER(FComputeShaderExampleCS);
	SHADER_USE_PARAMETER_STRUCT(FComputeShaderExampleCS, FGlobalShader);

	BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
		SHADER_PARAMETER_UAV(RWTexture2D<uint>, OutputTexture)
		SHADER_PARAMETER(FVector2D, TextureSize) // Metal doesn't support GetDimensions(), so we send in this data via our parameters.
		SHADER_PARAMETER(float, SimulationState)
		SHADER_PARAMETER_TEXTURE(Texture2D, TestTexture)
	END_SHADER_PARAMETER_STRUCT()

and in the corresponding USF file I have this:

RWTexture2D<uint> OutputTexture;
float2 TextureSize;
float SimulationState;
float Dummy;
Texture2D TestTexture;

However when I activate the shader, I get the following check exception:

Assertion failed: Bindings.StructureLayoutHash == ParametersMetadata->GetLayoutHash() 

I’m not actually changing the bound texture (at least, not intentionally). Converting SHADER_PARAMETER_TEXTURE(Texture2D, TestTexture) to SHADER_PARAMETER_UAV(Texture2D, TestTexture) avoids the exception but doesn’t work (calling Load() on the texture always returns (0,0,0,0), or perhaps (NAN,NAN,NAN,NAN))

What’s the expected method for passing a Texture2D Parameter to a compute shader?

You need to use SetShaderTexture/SetShaderResourceViewParameter/SetUAVParameter RHI commands.

It’s generating the error inside the ValidateShaderParameters() that’s called in SetShaderParameters() before it gets to the call to RHICmdList.SetShaderTexture()

Commenting out ValidateShaderParameters() let’s it work as expected… but I don’t like doing that kind of hack. I’d like to understand where the Bindings.StructureLayoutHash → ParametersMetadata->GetLayoutHash delta comes from

the SetShaderTexture function takes a FRHITexture as input.
Though i didn’t find anything about how to create a FRHITexture from a UTexture2D.
Do you know if and how this that is possible?