Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:33

0001 #pragma once
0002 /**
0003 SCUDA_Mesh.h : uploads SMesh tri and holds SCU_Buf 
0004 =====================================================
0005 
0006 Try following the pattern of SGLFW_Mesh.h 
0007 
0008 **/
0009 
0010 #include "SMesh.h"
0011 #include "SCU.h"
0012 
0013 struct SCUDA_Mesh
0014 {
0015     static constexpr const int INST_ELEM = 4*4 ; 
0016 
0017     SCU_Buf<float> vtx = {} ;
0018     SCU_Buf<int>   idx = {} ;  
0019     SCU_Buf<float> ins = {} ; 
0020 
0021     SCUDA_Mesh(const SMesh* mesh ) ; 
0022 
0023     CUdeviceptr vtx_pointer(int item=0) const ; 
0024     CUdeviceptr idx_pointer(int item=0) const ; 
0025     size_t vtx_num(int item=0) const ;
0026     size_t idx_num(int item=0) const ;
0027  
0028     void free();   // on device buffers 
0029  
0030     void set_inst(const NP* _inst );
0031     void set_inst(int _inst_num, const float* _inst_values );
0032     bool has_inst() const ;
0033 
0034     std::string desc() const ; 
0035 }; 
0036 
0037 inline SCUDA_Mesh::SCUDA_Mesh(const SMesh* mesh )
0038     :
0039     vtx(SCU::UploadBuf<float>( mesh->vtx->cvalues<float>(),   mesh->vtx->num_values(), "vtx" )),
0040     idx(SCU::UploadBuf<int>(   mesh->tri->cvalues<int>(),     mesh->tri->num_values(), "idx" ))
0041 {
0042 }
0043 
0044 CUdeviceptr SCUDA_Mesh::vtx_pointer(int item) const 
0045 {   
0046     assert( item == 0 ); 
0047     return vtx.pointer(); 
0048 } 
0049 
0050 size_t SCUDA_Mesh::vtx_num(int item) const 
0051 {   
0052     assert( item == 0 ); 
0053     return vtx.num_item ; 
0054 } 
0055 
0056 CUdeviceptr SCUDA_Mesh::idx_pointer(int item) const 
0057 {   
0058     assert( item == 0 ); 
0059     return idx.pointer(); 
0060 } 
0061 size_t SCUDA_Mesh::idx_num(int item) const 
0062 {   
0063     assert( item == 0 ); 
0064     return idx.num_item ; 
0065 } 
0066 
0067 
0068 
0069 
0070 
0071 inline void SCUDA_Mesh::free()
0072 {
0073     vtx.free(); 
0074     idx.free();
0075     ins.free(); 
0076 }
0077 
0078 inline void SCUDA_Mesh::set_inst(const NP* _inst )
0079 {
0080     if(_inst == nullptr) return ; 
0081     assert( _inst->uifc == 'f' ); 
0082     assert( _inst->ebyte == 4 ); 
0083     assert( _inst->has_shape(-1,4,4)); 
0084     set_inst( _inst->num_items(), _inst->cvalues<float>() ); 
0085 }
0086 
0087 inline void SCUDA_Mesh::set_inst(int _inst_num, const float* _inst_values )
0088 {
0089     ins = SCU::UploadBuf<float>( _inst_values, _inst_num*INST_ELEM, "ins" ); 
0090 }
0091 
0092 inline bool SCUDA_Mesh::has_inst() const
0093 {
0094     return ins.ptr != nullptr ; 
0095 }
0096 
0097 inline std::string SCUDA_Mesh::desc() const
0098 {
0099     std::stringstream ss ; 
0100     ss << "[ SCUDA_Mesh::desc" << std::endl ; 
0101     ss 
0102         << vtx.desc() 
0103         << std::endl
0104         << idx.desc() 
0105         << std::endl
0106         << ins.desc()
0107         << std::endl
0108         ;
0109     ss << "] SCUDA_Mesh::desc" << std::endl ; 
0110     std::string str = ss.str() ; 
0111     return str ; 
0112 }
0113 
0114