RavEngine
Loading...
Searching...
No Matches
DySolverControl.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef DY_SOLVER_CONTROL_H
30#define DY_SOLVER_CONTROL_H
31
32#include "DySolverCore.h"
33#include "DySolverConstraintDesc.h"
34
35namespace physx
36{
37
38namespace Dy
39{
40
41struct FsData;
42
43inline void BusyWaitState(volatile PxU32* state, const PxU32 requiredState)
44{
45 while(requiredState != *state );
46}
47
48inline void WaitBodyRequiredState(PxU32* state, const PxU32 requiredState)
49{
50 if(*state != requiredState)
51 {
52 BusyWaitState(state, requiredState);
53 }
54}
55
56inline void BusyWaitStates(volatile PxU32* stateA, volatile PxU32* stateB, const PxU32 requiredStateA, const PxU32 requiredStateB)
57{
58 while(*stateA != requiredStateA);
59 while(*stateB != requiredStateB);
60}
61
62
64{
65public:
66 PxConstraintBatchHeader* constraintBatchHeaders;
67 PxU32 mSize;
68 PxU32 mCurrentIndex;
69
70 BatchIterator(PxConstraintBatchHeader* _constraintBatchHeaders, PxU32 size) : constraintBatchHeaders(_constraintBatchHeaders),
71 mSize(size), mCurrentIndex(0)
72 {
73 }
74
75 PX_FORCE_INLINE const PxConstraintBatchHeader& GetCurrentHeader(const PxU32 constraintIndex)
76 {
77 PxU32 currentIndex = mCurrentIndex;
78 while((constraintIndex - constraintBatchHeaders[currentIndex].startIndex) >= constraintBatchHeaders[currentIndex].stride)
79 currentIndex = (currentIndex + 1)%mSize;
80 PxPrefetchLine(&constraintBatchHeaders[currentIndex], 128);
81 mCurrentIndex = currentIndex;
82 return constraintBatchHeaders[currentIndex];
83 }
84private:
85 BatchIterator& operator=(const BatchIterator&);
86};
87
88
89inline void SolveBlockParallel (PxSolverConstraintDesc* PX_RESTRICT constraintList, const PxI32 batchCount, const PxI32 index,
90 const PxI32 headerCount, SolverContext& cache, BatchIterator& iterator,
91 SolveBlockMethod solveTable[],
92 const PxI32 iteration
93 )
94{
95 const PxI32 indA = index - (iteration * headerCount);
96
97 const PxConstraintBatchHeader* PX_RESTRICT headers = iterator.constraintBatchHeaders;
98
99 const PxI32 endIndex = indA + batchCount;
100 for(PxI32 i = indA; i < endIndex; ++i)
101 {
102 const PxConstraintBatchHeader& header = headers[i];
103
104 const PxI32 numToGrab = header.stride;
105 PxSolverConstraintDesc* PX_RESTRICT block = &constraintList[header.startIndex];
106
107 PxPrefetch(block[0].constraint, 384);
108
109 for(PxI32 b = 0; b < numToGrab; ++b)
110 {
111 PxPrefetchLine(block[b].bodyA);
112 PxPrefetchLine(block[b].bodyB);
113 }
114
115 //OK. We have a number of constraints to run...
116 solveTable[header.constraintType](block, PxU32(numToGrab), cache);
117 }
118}
119
121{
122public:
123 bool frictionEveryIteration;
124 static SolverCoreGeneral* create(bool fricEveryIteration);
125
126 // Implements SolverCore
127 virtual void destroyV();
128
129 virtual PxI32 solveVParallelAndWriteBack
130 (SolverIslandParams& params, Cm::SpatialVectorF* Z, Cm::SpatialVectorF* deltaV) const;
131
132 virtual void solveV_Blocks
133 (SolverIslandParams& params) const;
134
135 virtual void writeBackV
136 (const PxSolverConstraintDesc* PX_RESTRICT constraintList, const PxU32 constraintListSize, PxConstraintBatchHeader* contactConstraintBatches, const PxU32 numBatches,
137 ThresholdStreamElement* PX_RESTRICT thresholdStream, const PxU32 thresholdStreamLength, PxU32& outThresholdPairs,
138 PxSolverBodyData* atomListData, WriteBackBlockMethod writeBackTable[]) const;
139
140private:
141
142 //~Implements SolverCore
143};
144
145#define SOLVEV_BLOCK_METHOD_ARGS SolverCore* solverCore, SolverIslandParams& params
146
147void solveVBlock(SOLVEV_BLOCK_METHOD_ARGS);
148
149SolveBlockMethod* getSolveBlockTable();
150
151SolveBlockMethod* getSolverConcludeBlockTable();
152
153SolveWriteBackBlockMethod* getSolveWritebackBlockTable();
154
155}
156
157}
158
159#endif
Definition DySolverControl.h:64
Definition DySolverControl.h:121
Definition DySolverCore.h:217
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_FORCE_INLINE void PxPrefetch(const void *ptr, uint32_t count=1)
Definition PxUnixIntrinsics.h:91
PX_FORCE_INLINE void PxPrefetchLine(const void *ptr, uint32_t offset=0)
Definition PxUnixIntrinsics.h:83
Definition CmSpatialVector.h:134
Definition DySolverContext.h:42
Definition DySolverCore.h:155
Definition DyThresholdTable.h:52
A header that defines the size of a specific batch of constraints (of same type and without dependenc...
Definition PxSolverDefs.h:98
Struct that the solver uses to store the state and other properties of a body.
Definition PxSolverDefs.h:74
Constraint descriptor used inside the solver.
Definition PxSolverDefs.h:108