porting helper functions from dx11bvh