ConvertToGPU and Arrays

JoshJJoshJ Posts: 4
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: 122 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

  • JoshJJoshJ Posts: 4

    So in order to push an polymesh array to be converted to GPU computing, it would need to create a retopology for each mesh and then would convert over to GPU?

    As a follow up, are curves and points the only thing that is native to canvas to convertToGPU?

  • jcgagnonjcgagnon Fabric Employee Posts: 122 Fabric Employee

    What I've written above isn't a retopology, but it's selecting the "internal" portion of the PolygonMesh object which can be move to the GPU. KL objects can't be moved to the GPU, only struct and arrays.

    For curves and points it's the same; these are Objects so they can't be moved to the GPU. Only their internal arrays or structures can, or geometry attributes' internal arrays (geometry attributes are KL objects too). Canvas probably moves to the GPU only methods that are labled as GPU-compatible (no KL Objects in its args or local variables).

    Jerome

Sign In or Register to comment.