~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/bullet/src/BulletMultiThreaded/GpuSoftBodySolvers/DX11/HLSL/ComputeBounds.hlsl

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
MSTRINGIFY(
 
2
 
 
3
cbuffer ComputeBoundsCB : register( b0 )
 
4
{
 
5
        int numNodes;
 
6
        int numSoftBodies;
 
7
        int padding1;
 
8
        int padding2;
 
9
};
 
10
 
 
11
// Node indices for each link
 
12
StructuredBuffer<int> g_vertexClothIdentifier : register( t0 );
 
13
StructuredBuffer<float4> g_vertexPositions : register( t1 );
 
14
 
 
15
RWStructuredBuffer<uint4> g_clothMinBounds : register( u0 );
 
16
RWStructuredBuffer<uint4> g_clothMaxBounds : register( u1 );
 
17
 
 
18
groupshared uint4 clothMinBounds[256];
 
19
groupshared uint4 clothMaxBounds[256];
 
20
 
 
21
[numthreads(128, 1, 1)]
 
22
void 
 
23
ComputeBoundsKernel( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )
 
24
{
 
25
        const unsigned int UINT_MAX = 0xffffffff;
 
26
 
 
27
        // Init min and max bounds arrays
 
28
        if( GTid.x < numSoftBodies )
 
29
        {
 
30
                clothMinBounds[GTid.x] = uint4(UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX);
 
31
                clothMaxBounds[GTid.x] = uint4(0,0,0,0);
 
32
        }
 
33
 
 
34
        AllMemoryBarrierWithGroupSync();
 
35
 
 
36
        int nodeID = DTid.x;
 
37
        if( nodeID < numNodes )
 
38
        {       
 
39
                int clothIdentifier = g_vertexClothIdentifier[nodeID];
 
40
                if( clothIdentifier >= 0 )
 
41
                {
 
42
                        float3 position = g_vertexPositions[nodeID].xyz;
 
43
 
 
44
                        // Reinterpret position as uint
 
45
                        uint3 positionUInt = uint3(asuint(position.x), asuint(position.y), asuint(position.z));
 
46
                
 
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);
 
54
                
 
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);
 
59
 
 
60
                        InterlockedMax(clothMaxBounds[clothIdentifier].x, positionUInt.x);
 
61
                        InterlockedMax(clothMaxBounds[clothIdentifier].y, positionUInt.y);
 
62
                        InterlockedMax(clothMaxBounds[clothIdentifier].z, positionUInt.z);
 
63
                }
 
64
        }
 
65
        
 
66
        AllMemoryBarrierWithGroupSync();
 
67
 
 
68
 
 
69
        // Use global atomics to update the global versions of the data
 
70
        if( GTid.x < numSoftBodies )
 
71
        {
 
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);
 
75
 
 
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);
 
79
        }
 
80
}
 
81
 
 
82
 
 
83
);
 
 
b'\\ No newline at end of file'