I’m writing an optix program that doesn’t render. All I have to do is check if ray hits. I made two objects into GAS and traced them according to the gas handle in the kernel as shown below.
// build GAS1
uint32_t triangleInputFlags[1] = { };
CUdeviceptr vertexBufferPointer;
if (n_triangle == 0) return;
OptixBuildInput triangleInput = {};
vertexBufferPointer = reinterpret_cast<CUdeviceptr>(vertexData1);
triangleInput.type = OPTIX_BUILD_INPUT_TYPE_TRIANGLES;
triangleInput.triangleArray.vertexBuffers = &vertexBufferPointer;
triangleInput.triangleArray.numVertices = static_cast<uint32_t>(n_triangleSize * 3)
triangleInput.triangleArray.vertexFormat = OPTIX_VERTEX_FORMAT_FLOAT3;
triangleInput.triangleArray.vertexStrideInBytes = sizeof(float3);
triangleInput.triangleArray.flags = triangleInputFlags;
triangleInput.triangleArray.numSbtRecords = 1;
OptixAccelBuildOptions accelOptions = {};
accelOptions.buildFlags = OPTIX_BUILD_FLAG_NONE | OPTIX_BUILD_FLAG_PREFER_FAST_TRACE;
accelOptions.operation = OPTIX_BUILD_OPERATION_BUILD;
OPTIX_CHECK(optixAccelComputeMemoryUsage(
parameterContext,
&accelOptions,
&triangleInput,
1,
&m_gasBufferSizes
));
m_tempBuffer.allocIfRequired(m_gasBufferSizes.tempSizeInBytes, false, OptixStream);
m_outputBuffer.allocIfRequired(m_gasBufferSizes.outputSizeInBytes, false, OptixStream);
OPTIX_CHECK(optixAccelBuild(
parameterContext,
0,
&accelOptions,
&triangleInput,
1,
m_tempBuffer.get(),
m_gasBufferSizes.tempSizeInBytes,
m_outputBuffer.get(),
m_gasBufferSizes.outputSizeInBytes,
&gas_handle1,
nullptr,
0
));
,
// build GAS2
uint32_t triangleInputFlags2[1] = { };
CUdeviceptr vertexBufferPointer2;
if (n_triangle == 0) return;
OptixBuildInput triangleInput2 = {};
vertexBufferPointer = reinterpret_cast<CUdeviceptr>(vertexData2);
triangleInput2.type = OPTIX_BUILD_INPUT_TYPE_TRIANGLES;
triangleInput2.triangleArray.vertexBuffers = &vertexBufferPointer2;
triangleInput2.triangleArray.numVertices = static_cast<uint32_t>(n_triangleSize * 3)
triangleInput2.triangleArray.vertexFormat = OPTIX_VERTEX_FORMAT_FLOAT3;
triangleInput2.triangleArray.vertexStrideInBytes = sizeof(float3);
triangleInput2.triangleArray.flags = triangleInputFlags2;
triangleInput2.triangleArray.numSbtRecords = 1;
OptixAccelBuildOptions accelOptions2 = {};
accelOptions2.buildFlags = OPTIX_BUILD_FLAG_NONE | OPTIX_BUILD_FLAG_PREFER_FAST_TRACE;
accelOptions2.operation = OPTIX_BUILD_OPERATION_BUILD;
OPTIX_CHECK(optixAccelComputeMemoryUsage(
parameterContext,
&accelOptions2,
&triangleInput2,
1,
&m_gasBufferSizes2
));
m_tempBuffer2.allocIfRequired(m_gasBufferSizes2.tempSizeInBytes, false, OptixStream);
m_outputBuffer2.allocIfRequired(m_gasBufferSize2s.outputSizeInBytes, false, OptixStream);
OPTIX_CHECK(optixAccelBuild(
parameterContext,
0,
&accelOptions2,
&triangleInput2,
1,
m_tempBuffer2.get(),
m_gasBufferSizes2.tempSizeInBytes,
m_outputBuffer2.get(),
m_gasBufferSizes2.outputSizeInBytes,
&gas_handle2,
nullptr,
0
));
…
set sbt and set handles to params and so on
…
In kernel,
optixTrace(
gas_handle1, //(gas_handle2)
ray_origin, ray_direction,
tmin,
tmax,
0.0f, // rayTime
OptixVisibilityMask(1),
OPTIX_RAY_FLAG_NONE,
0,
1,
0,
u0);
i only just traced and do nothing with hit result (CH,AH,MISS)
And I measured the time after launch.
GAS1 is composed of 10 million triangles, GAS2 is composed of 1,000 triangles, and ray(launch width) is 10 million. However, even if trace with gas2 handle, the time was the same as trace with gas1 handle.
So I made only one GAS with 1,000 triangles and launched. In this case, I got very smaller time compare with upper case.
I think something wrong and gas2 handle maybe also traverse GAS1.
Is it because i didn’t use IAS? Of course, they synchronized after launch.
I want to know the reason …
Thankyou very much for reading this