ConvertToGPU and Arrays

JoshJJoshJ Posts: 3
edited March 20 in KL Programming

Good afternoon!

I am working on a canvas node that would allow more complex polygonMesh[] data to be converted to using GPU computing. Digging through any documentation only talks about individual pieces to swapped to GPU, but I am using multiple meshes brought in with Alembic load to create the asset. Is there anyway the convertToGPU() function can be applied to any type of array?

Tagged:

Comments

  • jcgagnonjcgagnon Fabric Employee Posts: 92 Fabric Employee

    Hi Josh,

    Built-in conversion to GPU (convertToGPU) is only not supported for Object (like PolygonMesh), or arrays of Object. The PolygonMesh has a "convertToGPU" method which moves to the GPU its most important internal arrays (the mesh structure and attribute sharing cannot be modified on the GPU), but not all its data. The GPU methods that use the PolygonMesh must actually be called on its "PolygonMeshTopology topology" member. Also, GeometryAttributes cannot be used directly on the GPU, but rather their internal data array (which can be moved to the GPU with their convertToGPU method). These restrictions make it hard to work on meshes on the GPU using Canvas nodes, since only PolygonMeshTopology methods can then be used (and existing nodes take a PolygonMesh type). But in KL there are some possibilities.

    A supported way would be to convert a finite number of meshes to the GPU, and call a function that takes topology args, but it cannot be a dynamic array:

    operator GPUFunc<<>>( PolygonMeshTopology meshTopo1, PolygonMeshTopology meshTopo2, ... );

    Another way that seems to work, but is sort of a workaround, is to do:

    require Geometry;
    
    operator test<<<index>>>( PolygonMeshTopology topologies[] ) {
      report(topologies[0].pointCount());
    }
    
    operator entry(){
    
    PolygonMesh mesh1();
    mesh1.addSphere(Xfo(), 1, 5, 5, true, true);
    
    PolygonMesh mesh2();
    mesh2.addSphere(Xfo(), 1, 5, 5, true, true);
    
    PolygonMeshTopology topologies[];
    topologies.push(mesh1.topology);
    topologies.push(mesh2.topology);
    
    topologies.convertToGPU();// the array must also be converted. This is done on behalf of the mesh, but is the only way that works.
    
    test<<<1@true>>>(topologies);
    
    // convert back to CPU if you need to reuse the meshes in any way on the CPU. The mesh still "thinks" it is on the CPU...
    topologies.convertToCPU();// the array must also be converted
    }
    

    KL makes it easier to use the GPU, but in cases like this it still requires to adapt the code unfortunately.

    Jerome Couture-Gagnon

Sign In or Register to comment.