How to raycast octree for closest leaf node?

So I need to raycast a octree for closest leaf node as efficient as possible. I will be doing it on compute shader (hlsl), but I think it doesn’t matter because first I need to understand the approach and math behind this process in general.

My struct looks like this:

struct OctreeNode {     uint  size; // size of cubic node          uint posX; // center of node     uint posY; // center of node     uint posZ; // center of node          uint childExists;     uint isLeaf;     uint isChild;      uint parentIndex; //Parent node index in structured buffer     uint minchildIndex; // Node child min index in structured buffer (+1 is next child, etc)        uint index; //Index in structured buffer }; 

Octree is rather big, so I guess I can’t afford to raycast everything and then compare distances. I have been looking into , but I do not understand the answer (especially HLSL one with hitbox what is unknow thing).

Any hints, code, directions highly appreciated.