Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 /**
0003 SOPTIX_BuildInput_CPA
0004 ======================
0005 
0006 As SCSGPrimSpec are passed around by value do not assume long lived pointer addresses
0007 back in the  SCSGPrimSpec.
0008 
0009 Because the buildInputCPA.aabbBuffers requires a host array pointer to device pointers 
0010 it is necessary to keep instances of this struct alive until at least Acceleration structure
0011 creation. 
0012 
0013 **/
0014 
0015 #include "SCSGPrimSpec.h"
0016 #include "SCU.h"
0017 #include "SOPTIX_BuildInput.h"
0018 
0019 struct SOPTIX_BuildInput_CPA : public SOPTIX_BuildInput
0020 {
0021     static constexpr const char* NAME = "BuildInputCustomPrimitiveArray" ; 
0022     CUdeviceptr d_aabb ;    
0023     CUdeviceptr d_sbt_index ;
0024     unsigned*   flags ; 
0025 
0026     SOPTIX_BuildInput_CPA( const SCSGPrimSpec& ps ); 
0027 };
0028 
0029  
0030 inline SOPTIX_BuildInput_CPA::SOPTIX_BuildInput_CPA( const SCSGPrimSpec& ps )
0031     :
0032     SOPTIX_BuildInput(NAME),
0033     d_aabb(SCU::DevicePointerCast<float>( ps.aabb )),
0034     d_sbt_index(SCU::DevicePointerCast<unsigned>( ps.sbtIndexOffset )),
0035     flags(new unsigned[ps.num_prim])
0036 {
0037     for(unsigned i=0 ; i < ps.num_prim ; i++) flags[i] = OPTIX_GEOMETRY_FLAG_DISABLE_ANYHIT ; 
0038 
0039     buildInput.type = OPTIX_BUILD_INPUT_TYPE_CUSTOM_PRIMITIVES;
0040     OptixBuildInputCustomPrimitiveArray& buildInputCPA = buildInput.customPrimitiveArray ;   
0041 
0042     buildInputCPA.aabbBuffers = &d_aabb ;   
0043     buildInputCPA.numPrimitives = ps.num_prim  ;   
0044     buildInputCPA.strideInBytes = ps.stride_in_bytes ;
0045     buildInputCPA.flags = flags;                                     // flags per sbt record
0046     buildInputCPA.numSbtRecords = ps.num_prim ;                      // number of sbt records available to sbt index offset override. 
0047     buildInputCPA.sbtIndexOffsetBuffer  = d_sbt_index ;              // Device pointer to per-primitive local sbt index offset buffer, Every entry must be in range [0,numSbtRecords-1]
0048     buildInputCPA.sbtIndexOffsetSizeInBytes  = sizeof(unsigned);     // Size of type of the sbt index offset. Needs to be 0,1,2 or 4    
0049     buildInputCPA.sbtIndexOffsetStrideInBytes = ps.stride_in_bytes ; // Stride between the index offsets. If set to zero, the offsets are assumed to be tightly packed.
0050     buildInputCPA.primitiveIndexOffset = ps.primitiveIndexOffset ;   // Primitive index bias, applied in optixGetPrimitiveIndex() see OptiX7Test.cu:__closesthit__ch
0051 }
0052 
0053