RavEngine
Loading...
Searching...
No Matches
GuBV4_Slabs_KajiyaNoOrder.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 GU_BV4_SLABS_KAJIYA_NO_ORDER_H
30#define GU_BV4_SLABS_KAJIYA_NO_ORDER_H
31
32#include "GuBVConstants.h"
33
34#ifdef REMOVED
35 // Kajiya, no sort
36 template<int inflateT, class LeafTestT, class ParamsT>
37 static PxIntBool BV4_ProcessStreamKajiyaNoOrder(const BVDataPacked* PX_RESTRICT node, PxU32 initData, ParamsT* PX_RESTRICT params)
38 {
39 const BVDataPacked* root = node;
40
41 PxU32 nb=1;
42 PxU32 stack[GU_BV4_STACK_SIZE];
43 stack[0] = initData;
44
46
47 Vec4V fattenAABBsX, fattenAABBsY, fattenAABBsZ;
48 if(inflateT)
49 {
50 Vec4V fattenAABBs4 = V4LoadU_Safe(&params->mOriginalExtents_Padded.x);
51 fattenAABBs4 = V4Add(fattenAABBs4, epsInflateFloat4); // US2385 - shapes are "closed" meaning exactly touching shapes should report overlap
52 fattenAABBsX = V4SplatElement<0>(fattenAABBs4);
53 fattenAABBsY = V4SplatElement<1>(fattenAABBs4);
54 fattenAABBsZ = V4SplatElement<2>(fattenAABBs4);
55 }
56
58
59 SLABS_INIT
60
61#ifdef GU_BV4_QUANTIZED_TREE
62 const Vec4V minCoeffV = V4LoadA_Safe(&params->mCenterOrMinCoeff_PaddedAligned.x);
63 const Vec4V maxCoeffV = V4LoadA_Safe(&params->mExtentsOrMaxCoeff_PaddedAligned.x);
64 const Vec4V minCoeffxV = V4SplatElement<0>(minCoeffV);
65 const Vec4V minCoeffyV = V4SplatElement<1>(minCoeffV);
66 const Vec4V minCoeffzV = V4SplatElement<2>(minCoeffV);
67 const Vec4V maxCoeffxV = V4SplatElement<0>(maxCoeffV);
68 const Vec4V maxCoeffyV = V4SplatElement<1>(maxCoeffV);
69 const Vec4V maxCoeffzV = V4SplatElement<2>(maxCoeffV);
70#endif
71
72 do
73 {
74 const PxU32 childData = stack[--nb];
75 node = root + getChildOffset(childData);
76
77 const BVDataSwizzled* tn = reinterpret_cast<const BVDataSwizzled*>(node);
78
79#ifdef GU_BV4_QUANTIZED_TREE
80 Vec4V minx4a;
81 Vec4V maxx4a;
82 OPC_DEQ4(maxx4a, minx4a, mX, minCoeffxV, maxCoeffxV)
83
84 Vec4V miny4a;
85 Vec4V maxy4a;
86 OPC_DEQ4(maxy4a, miny4a, mY, minCoeffyV, maxCoeffyV)
87
88 Vec4V minz4a;
89 Vec4V maxz4a;
90 OPC_DEQ4(maxz4a, minz4a, mZ, minCoeffzV, maxCoeffzV)
91#else
92 Vec4V minx4a = V4LoadA(tn->mMinX);
93 Vec4V miny4a = V4LoadA(tn->mMinY);
94 Vec4V minz4a = V4LoadA(tn->mMinZ);
95
96 Vec4V maxx4a = V4LoadA(tn->mMaxX);
97 Vec4V maxy4a = V4LoadA(tn->mMaxY);
98 Vec4V maxz4a = V4LoadA(tn->mMaxZ);
99#endif
100 if(inflateT)
101 {
102 maxx4a = V4Add(maxx4a, fattenAABBsX); maxy4a = V4Add(maxy4a, fattenAABBsY); maxz4a = V4Add(maxz4a, fattenAABBsZ);
103 minx4a = V4Sub(minx4a, fattenAABBsX); miny4a = V4Sub(miny4a, fattenAABBsY); minz4a = V4Sub(minz4a, fattenAABBsZ);
104 }
105
106 SLABS_TEST
107
108 SLABS_TEST2
109
110#define DO_LEAF_TEST(x) \
111 {if(tn->isLeaf(x)) \
112 { \
113 if(LeafTestT::doLeafTest(params, tn->getPrimitive(x))) \
114 return 1; \
115 } \
116 else \
117 stack[nb++] = tn->getChildData(x);}
118
119 const PxU32 nodeType = getChildType(childData);
120 if(!(code&8) && nodeType>1)
121 DO_LEAF_TEST(3)
122
123 if(!(code&4) && nodeType>0)
124 DO_LEAF_TEST(2)
125
126 if(!(code&2))
127 DO_LEAF_TEST(1)
128
129 if(!(code&1))
130 DO_LEAF_TEST(0)
131
132 }while(nb);
133
134 return 0;
135 }
136#undef DO_LEAF_TEST
137#endif
138
139
140#define DO_LEAF_TEST(x) \
141 {if(tn->isLeaf(x)) \
142 { \
143 if(LeafTestT::doLeafTest(params, tn->getPrimitive(x))) \
144 return 1; \
145 } \
146 else \
147 stack[nb++] = tn->getChildData(x);}
148
149
150 // Kajiya, no sort
151 template<int inflateT, class LeafTestT, class ParamsT>
152 static PxIntBool BV4_ProcessStreamKajiyaNoOrderQ(const BVDataPackedQ* PX_RESTRICT node, PxU32 initData, ParamsT* PX_RESTRICT params)
153 {
154 const BVDataPackedQ* root = node;
155
156 PxU32 nb=1;
157 PxU32 stack[GU_BV4_STACK_SIZE];
158 stack[0] = initData;
159
161
162 Vec4V fattenAABBsX, fattenAABBsY, fattenAABBsZ;
163 if(inflateT)
164 {
165 Vec4V fattenAABBs4 = V4LoadU_Safe(&params->mOriginalExtents_Padded.x);
166 fattenAABBs4 = V4Add(fattenAABBs4, epsInflateFloat4); // US2385 - shapes are "closed" meaning exactly touching shapes should report overlap
167 fattenAABBsX = V4SplatElement<0>(fattenAABBs4);
168 fattenAABBsY = V4SplatElement<1>(fattenAABBs4);
169 fattenAABBsZ = V4SplatElement<2>(fattenAABBs4);
170 }
171
173
174 SLABS_INIT
175
176 const Vec4V minCoeffV = V4LoadA_Safe(&params->mCenterOrMinCoeff_PaddedAligned.x);
177 const Vec4V maxCoeffV = V4LoadA_Safe(&params->mExtentsOrMaxCoeff_PaddedAligned.x);
178 const Vec4V minCoeffxV = V4SplatElement<0>(minCoeffV);
179 const Vec4V minCoeffyV = V4SplatElement<1>(minCoeffV);
180 const Vec4V minCoeffzV = V4SplatElement<2>(minCoeffV);
181 const Vec4V maxCoeffxV = V4SplatElement<0>(maxCoeffV);
182 const Vec4V maxCoeffyV = V4SplatElement<1>(maxCoeffV);
183 const Vec4V maxCoeffzV = V4SplatElement<2>(maxCoeffV);
184
185 do
186 {
187 const PxU32 childData = stack[--nb];
188 node = root + getChildOffset(childData);
189
190 const BVDataSwizzledQ* tn = reinterpret_cast<const BVDataSwizzledQ*>(node);
191
192 Vec4V minx4a;
193 Vec4V maxx4a;
194 OPC_DEQ4(maxx4a, minx4a, mX, minCoeffxV, maxCoeffxV)
195
196 Vec4V miny4a;
197 Vec4V maxy4a;
198 OPC_DEQ4(maxy4a, miny4a, mY, minCoeffyV, maxCoeffyV)
199
200 Vec4V minz4a;
201 Vec4V maxz4a;
202 OPC_DEQ4(maxz4a, minz4a, mZ, minCoeffzV, maxCoeffzV)
203
204 if(inflateT)
205 {
206 maxx4a = V4Add(maxx4a, fattenAABBsX); maxy4a = V4Add(maxy4a, fattenAABBsY); maxz4a = V4Add(maxz4a, fattenAABBsZ);
207 minx4a = V4Sub(minx4a, fattenAABBsX); miny4a = V4Sub(miny4a, fattenAABBsY); minz4a = V4Sub(minz4a, fattenAABBsZ);
208 }
209
210 SLABS_TEST
211
212 SLABS_TEST2
213
214 const PxU32 nodeType = getChildType(childData);
215 if(!(code&8) && nodeType>1)
216 DO_LEAF_TEST(3)
217
218 if(!(code&4) && nodeType>0)
219 DO_LEAF_TEST(2)
220
221 if(!(code&2))
222 DO_LEAF_TEST(1)
223
224 if(!(code&1))
225 DO_LEAF_TEST(0)
226
227 }while(nb);
228
229 return 0;
230 }
231
232
233 // Kajiya, no sort
234 template<int inflateT, class LeafTestT, class ParamsT>
235 static PxIntBool BV4_ProcessStreamKajiyaNoOrderNQ(const BVDataPackedNQ* PX_RESTRICT node, PxU32 initData, ParamsT* PX_RESTRICT params)
236 {
237 const BVDataPackedNQ* root = node;
238
239 PxU32 nb=1;
240 PxU32 stack[GU_BV4_STACK_SIZE];
241 stack[0] = initData;
242
244
245 Vec4V fattenAABBsX, fattenAABBsY, fattenAABBsZ;
246 if(inflateT)
247 {
248 Vec4V fattenAABBs4 = V4LoadU_Safe(&params->mOriginalExtents_Padded.x);
249 fattenAABBs4 = V4Add(fattenAABBs4, epsInflateFloat4); // US2385 - shapes are "closed" meaning exactly touching shapes should report overlap
250 fattenAABBsX = V4SplatElement<0>(fattenAABBs4);
251 fattenAABBsY = V4SplatElement<1>(fattenAABBs4);
252 fattenAABBsZ = V4SplatElement<2>(fattenAABBs4);
253 }
254
256
257 SLABS_INIT
258
259 do
260 {
261 const PxU32 childData = stack[--nb];
262 node = root + getChildOffset(childData);
263
264 const BVDataSwizzledNQ* tn = reinterpret_cast<const BVDataSwizzledNQ*>(node);
265
266 Vec4V minx4a = V4LoadA(tn->mMinX);
267 Vec4V miny4a = V4LoadA(tn->mMinY);
268 Vec4V minz4a = V4LoadA(tn->mMinZ);
269
270 Vec4V maxx4a = V4LoadA(tn->mMaxX);
271 Vec4V maxy4a = V4LoadA(tn->mMaxY);
272 Vec4V maxz4a = V4LoadA(tn->mMaxZ);
273
274 if(inflateT)
275 {
276 maxx4a = V4Add(maxx4a, fattenAABBsX); maxy4a = V4Add(maxy4a, fattenAABBsY); maxz4a = V4Add(maxz4a, fattenAABBsZ);
277 minx4a = V4Sub(minx4a, fattenAABBsX); miny4a = V4Sub(miny4a, fattenAABBsY); minz4a = V4Sub(minz4a, fattenAABBsZ);
278 }
279
280 SLABS_TEST
281
282 SLABS_TEST2
283
284 const PxU32 nodeType = getChildType(childData);
285 if(!(code&8) && nodeType>1)
286 DO_LEAF_TEST(3)
287
288 if(!(code&4) && nodeType>0)
289 DO_LEAF_TEST(2)
290
291 if(!(code&2))
292 DO_LEAF_TEST(1)
293
294 if(!(code&1))
295 DO_LEAF_TEST(0)
296
297 }while(nb);
298
299 return 0;
300 }
301
302
303#undef DO_LEAF_TEST
304
305#endif // GU_BV4_SLABS_KAJIYA_NO_ORDER_H
#define PX_RESTRICT
Definition PxPreprocessor.h:355