3
cbuffer ComputeBoundsCB : register( b0 )
11
// Node indices for each link
12
StructuredBuffer<int> g_vertexClothIdentifier : register( t0 );
13
StructuredBuffer<float4> g_vertexPositions : register( t1 );
15
RWStructuredBuffer<uint4> g_clothMinBounds : register( u0 );
16
RWStructuredBuffer<uint4> g_clothMaxBounds : register( u1 );
18
groupshared uint4 clothMinBounds[256];
19
groupshared uint4 clothMaxBounds[256];
21
[numthreads(128, 1, 1)]
23
ComputeBoundsKernel( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )
25
const unsigned int UINT_MAX = 0xffffffff;
27
// Init min and max bounds arrays
28
if( GTid.x < numSoftBodies )
30
clothMinBounds[GTid.x] = uint4(UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX);
31
clothMaxBounds[GTid.x] = uint4(0,0,0,0);
34
AllMemoryBarrierWithGroupSync();
37
if( nodeID < numNodes )
39
int clothIdentifier = g_vertexClothIdentifier[nodeID];
40
if( clothIdentifier >= 0 )
42
float3 position = g_vertexPositions[nodeID].xyz;
44
// Reinterpret position as uint
45
uint3 positionUInt = uint3(asuint(position.x), asuint(position.y), asuint(position.z));
47
// Invert sign bit of positives and whole of negatives to allow comparison as unsigned ints
48
//positionUInt.x ^= uint((-int(positionUInt.x >> 31) | 0x80000000));
49
//positionUInt.y ^= uint((-int(positionUInt.y >> 31) | 0x80000000));
50
//positionUInt.z ^= uint((-int(positionUInt.z >> 31) | 0x80000000));
51
positionUInt.x ^= (1+~(positionUInt.x >> 31) | 0x80000000);
52
positionUInt.y ^= (1+~(positionUInt.y >> 31) | 0x80000000);
53
positionUInt.z ^= (1+~(positionUInt.z >> 31) | 0x80000000);
55
// Min/max with the LDS values
56
InterlockedMin(clothMinBounds[clothIdentifier].x, positionUInt.x);
57
InterlockedMin(clothMinBounds[clothIdentifier].y, positionUInt.y);
58
InterlockedMin(clothMinBounds[clothIdentifier].z, positionUInt.z);
60
InterlockedMax(clothMaxBounds[clothIdentifier].x, positionUInt.x);
61
InterlockedMax(clothMaxBounds[clothIdentifier].y, positionUInt.y);
62
InterlockedMax(clothMaxBounds[clothIdentifier].z, positionUInt.z);
66
AllMemoryBarrierWithGroupSync();
69
// Use global atomics to update the global versions of the data
70
if( GTid.x < numSoftBodies )
72
InterlockedMin(g_clothMinBounds[GTid.x].x, clothMinBounds[GTid.x].x);
73
InterlockedMin(g_clothMinBounds[GTid.x].y, clothMinBounds[GTid.x].y);
74
InterlockedMin(g_clothMinBounds[GTid.x].z, clothMinBounds[GTid.x].z);
76
InterlockedMax(g_clothMaxBounds[GTid.x].x, clothMaxBounds[GTid.x].x);
77
InterlockedMax(g_clothMaxBounds[GTid.x].y, clothMaxBounds[GTid.x].y);
78
InterlockedMax(g_clothMaxBounds[GTid.x].z, clothMaxBounds[GTid.x].z);
b'\\ No newline at end of file'