NVIDIA / gvdb-voxels

Sparse volume compute and rendering on NVIDIA GPUs
Other
672 stars 144 forks source link

VolumeGVDB::RenderKernel ERROR: an illegal memory access was encountered #142

Open vsheihu opened 1 year ago

vsheihu commented 1 year ago

This interesting problem always occurs during my rotation of the view, and the detailed error report is as follows:

GVDB CUDA ERROR: Launch status: an illegal memory access was accounted for Kernel status: no error Caller: VolumeGVDB::RenderKernel Call: cuLaunch Args: (user kernel) Error Application will exit.

Currently, I have found a temporary solution and need to modify the cuda_gvdb_raycast.cuh, the original code for the file rayCast function was: device void rayCast ( VDBInfo* gvdb, uchar chan, float3 pos, float3 dir, float3& hit, float3& norm, float4& clr, gvdbBrickFunc_t brickFunc ) { ...

for (iter=0; iter < MAX_ITER && lev > 0 && lev <= gvdb->top_lev && dda.p.x >=0 && dda.p.y >=0 && dda.p.z >=0 && dda.p.x <= gvdb->res[lev] && dda.p.y <= gvdb->res[lev] && dda.p.z <= gvdb->res[lev]; iter++ ) {

    ...

    // node active test
    b = (((int(dda.p.z) << gvdb->dim[lev]) + int(dda.p.y)) << gvdb->dim[lev]) + int(dda.p.x);   // bitmaskpos
    if ( isBitOn ( gvdb, node, b ) ) {                      // check vdb bitmask for voxel occupancy                        
        ...
    } else {
        // empty voxel, step DDA
        dda.Step();
    }
    ...
}   

}

The modified code is as follows: device void rayCast ( VDBInfo* gvdb, uchar chan, float3 pos, float3 dir, float3& hit, float3& norm, float4& clr, gvdbBrickFunc_t brickFunc ) { ...

for (iter=0; iter < MAX_ITER && lev > 0 && lev <= gvdb->top_lev && dda.p.x >=0 && dda.p.y >=0 && dda.p.z >=0 && dda.p.x <= gvdb->res[lev] && dda.p.y <= gvdb->res[lev] && dda.p.z <= gvdb->res[lev]; iter++ ) {

    ...

    // node active test
    b = (((int(dda.p.z) << gvdb->dim[lev]) + int(dda.p.y)) << gvdb->dim[lev]) + int(dda.p.x);   // bitmaskpos
    int vox = gvdb->res[node->mLev] * gvdb->res[node->mLev] * gvdb->res[node->mLev];
    if (b < vox && isBitOn ( gvdb, node, b ) ) {                        // check vdb bitmask for voxel occupancy                        
        ...
    } else {
        // empty voxel, step DDA
        dda.Step();
    }
    ...
}   

}

The problem has been resolved and can be filed as your modification.

Through Cuda Nsight Debug, it was found that the direct reason was that the bit parameter in isBitOn exceeded the current node size. As for why the bit exceeded the node range, forgive my clumsiness, i haven't discovered it yet.