Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:49:32

0001 #!/usr/bin/env python
0002 """
0003 CSGOptiXInstancesTest.py
0004 
0005 
0006      530 typedef struct OptixInstance
0007      531 {
0008      532     /// affine world-to-object transformation as 3x4 matrix in row-major layout
0009      533     float transform[12];
0010      534 
0011      535     /// Application supplied ID. The maximal ID can be queried using OPTIX_DEVICE_PROPERTY_LIMIT_MAX_INSTANCE_ID.
0012      536     unsigned int instanceId;
0013      537 
0014      538     /// SBT record offset.  Will only be used for instances of geometry acceleration structure (GAS) objects.
0015      539     /// Needs to be set to 0 for instances of instance acceleration structure (IAS) objects. The maximal SBT offset
0016      540     /// can be queried using OPTIX_DEVICE_PROPERTY_LIMIT_MAX_INSTANCE_SBT_OFFSET.
0017      541     unsigned int sbtOffset;
0018      542 
0019      543     /// Visibility mask. If rayMask & instanceMask == 0 the instance is culled. The number of available bits can be
0020      544     /// queried using OPTIX_DEVICE_PROPERTY_LIMIT_NUM_BITS_INSTANCE_VISIBILITY_MASK.
0021      545     unsigned int visibilityMask;
0022      546 
0023      547     /// Any combination of OptixInstanceFlags is allowed.
0024      548     unsigned int flags;
0025      549 
0026      550     /// Set with an OptixTraversableHandle.
0027      551     OptixTraversableHandle traversableHandle;
0028      552 
0029      553     /// round up to 80-byte, to ensure 16-byte alignment
0030      554     unsigned int pad[2];
0031      555 } OptixInstance;
0032 
0033 
0034 ::
0035 
0036     12 + 1 + 1 + 1 + 1 + 2 + 2 = 20 
0037 
0038 
0039 In [16]: np.unique( traversableHandle, return_counts=True ) 
0040 Out[16]: 
0041 (array([140735712067594, 140735808176138, 140735808178698, 140735808181770, 140735808184842, 140735808187402, 140735808189962, 140735808192522, 140735808195082, 140735808207370], dtype=uint64),
0042  array([    1, 25600, 12615,  4997,  2400,   590,   590,   590,   590,   504]))
0043 
0044 
0045 """
0046 
0047 import numpy as np
0048 from opticks.ana.fold import Fold
0049 
0050 
0051 class OptixInstance(object):
0052     def __init__(self, i):
0053         """
0054         :param i: instances
0055         """
0056         transform = i.view(np.float32)[:,:12].reshape(-1,3,4)
0057         instanceId = i[:,12]   
0058         sbtOffset = i[:,13]
0059         visibilityMask = i[:,14]
0060         flags = i[:,15]
0061         traversableHandle = i.view(np.uint64)[:,8]  # double size, so half idx  
0062         pad = i[:,18:20]
0063         assert( np.all(pad == 0 ) )
0064 
0065         self.i = i 
0066 
0067         self.transform = transform
0068         self.instanceId = instanceId 
0069         self.sbtOffset = sbtOffset  
0070         self.visibilityMask = visibilityMask
0071         self.flags = flags
0072         self.traversableHandle = traversableHandle
0073         self.pad = pad
0074 
0075 
0076 if __name__ == '__main__':
0077     f = Fold.Load(symbol="f")
0078     print(repr(f))
0079     i = OptixInstance(f.instances)
0080 
0081     u_iid, n_iid = np.unique( i.instanceId, return_counts=True )  
0082     assert n_iid[1:].max() == 1  # should only be 1 of each instanceId other than 0  
0083 
0084 
0085 
0086 
0087 pass