Files
UnrealEngineUWP/Engine/Shaders/UpdateTextureShaders.usf
Marcus Wassmer f698ca0d9e Fix Texture updating shaders for PS4
#codereview Lee.Clark

[CL 2590800 by Marcus Wassmer in Main branch]
2015-06-17 16:02:34 -04:00

51 lines
2.2 KiB
Plaintext

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
/*=============================================================================
UpdateTextureShaders.usf: Compute shaders for copying and updating textures.
=============================================================================*/
#include "Common.usf"
Buffer<int> SrcBuffer;
RWTexture2D<int4> DestTexture;
uint2 SrcPitch; //x = number of SrcBuffer elements in a row of the source area, y = Number of components per texel in the source.
uint4 DestPosSize; // xy = pos, zw = Size of the destination sub rect
[numthreads(8,8,1)]
void UpdateTexture2DSubresourceCS( uint2 ThreadId : SV_DispatchThreadID )
{
if( all( ThreadId.xy < DestPosSize.zw ) )
{
int2 TexturePixelOffset = ThreadId.xy + DestPosSize.xy;
//supports textures with 1-4 components. Textures with < 4 components will simply ignore writes to the extra components via channel masking.
int BufferOffset = (ThreadId.x * SrcPitch.y) + (ThreadId.y * SrcPitch.x);
DestTexture[TexturePixelOffset] = int4(SrcBuffer[BufferOffset].x, SrcBuffer[BufferOffset + 1].x, SrcBuffer[BufferOffset + 2].x, SrcBuffer[BufferOffset + 3].x);
}
}
RWTexture3D<int4> DestTexture3D;
uint SrcDepthPitch; //number of SrcBuffer entries between z slices of the source volume
uint4 DestPos; // xyz = starting offset in destination volume texture
uint4 DestSize; //syz = size of the volume to update
[numthreads(8, 8, 1)]
void UpdateTexture3DSubresourceCS(uint3 ThreadId : SV_DispatchThreadID)
{
if (all(ThreadId.xyz < DestSize.xyz))
{
int3 TexturePixelOffset = ThreadId.xyz + (int3)DestPos.xyz;
//supports textures with 1-4 components. Textures with < 4 components will simply ignore writes to the extra components via channel masking.
int BufferOffset = (ThreadId.x * SrcPitch.y) + (ThreadId.y * SrcPitch.x) + (ThreadId.z * SrcDepthPitch);
DestTexture3D[TexturePixelOffset] = int4(SrcBuffer[BufferOffset].x, SrcBuffer[BufferOffset + 1].x, SrcBuffer[BufferOffset + 2].x, SrcBuffer[BufferOffset + 3].x);
}
}
Texture2D<int4> SrcTexture;
[numthreads(8,8,1)]
void CopyTexture2DCS( uint3 ThreadId : SV_DispatchThreadID )
{
DestTexture[ThreadId.xy] = SrcTexture.Load(int3(ThreadId.x, ThreadId.y, 0));
}