// Copyright 2022 Manuel Wagner - All rights reserved

RWTexture2D<float4> OutputTexture;
Buffer<float> InputTensor;
uint TensorVolume;
// this assumes that the OutputTexture has
// the exact same dimensions as InputTensor!
uint2 TextureSize;

// DispatchThreadID corresponds to InputTensor shape dimensions not texture XY -> DispatchThreadID.X = Texture.Y
[numthreads(THREADGROUP_SIZE_X, THREADGROUP_SIZE_Y, THREADGROUP_SIZE_Z)]
void OutputTensorToSceneColorCS(in const uint3 DispatchThreadID : SV_DispatchThreadID)
{
	// note that the input tensor has shape (1, Y, X, C)
	// which is why we need to flip the indexing
	const uint TensorPixelNumber = DispatchThreadID.x * TextureSize.x + DispatchThreadID.y;
	const uint GlobalIndex = TensorPixelNumber * 3;

	if (GlobalIndex >= TensorVolume)
	{
		return;
	}

	const uint2 TextureCoords = uint2(DispatchThreadID.y, DispatchThreadID.x);
	const float4 RGBAColor = float4(
		InputTensor[GlobalIndex + 0],
		InputTensor[GlobalIndex + 1],
		InputTensor[GlobalIndex + 2],
		0.0f
	);
	OutputTexture[TextureCoords] = RGBAColor;
}

#include "/Engine/Public/Platform.ush"