Hello,
I have an “invalid value” error when updating my GAS with custom primitives.
I already have an Optix program which is loading triangles and throws rays on these triangles and works pretty well. This is a simple program where the GAS is generated at the initialization and there is a loop after where the triangles are moving a bit and the GAS is updated, for N frames, and then I am freeing everything and the program stop.
Now I would like to change my triangles by custom primitives.
In the GAS construction, I changed those lines:
state.triangle_input.type = OPTIX_BUILD_INPUT_TYPE_TRIANGLES;
state.triangle_input.triangleArray.vertexFormat = OPTIX_VERTEX_FORMAT_FLOAT3;
state.triangle_input.triangleArray.numVertices = static_cast<unsigned int>(nverts);
state.triangle_input.triangleArray.vertexBuffers = &state.d_temp_vertices;
state.triangle_input.triangleArray.flags = &state.triangle_flags;
state.triangle_input.triangleArray.numSbtRecords = 1;
state.triangle_input.triangleArray.indexFormat = OPTIX_INDICES_FORMAT_UNSIGNED_INT3;
state.triangle_input.triangleArray.numIndexTriplets = static_cast<unsigned int>(ntris);
state.triangle_input.triangleArray.indexBuffer = reinterpret_cast<CUdeviceptr>(devTriangles);
with those lines:
state.triangle_input.type = OPTIX_BUILD_INPUT_TYPE_CUSTOM_PRIMITIVES;
state.triangle_input.customPrimitiveArray.aabbBuffers = reinterpret_cast<CUdeviceptr*>(&d_aabb_array);
state.triangle_input.customPrimitiveArray.numPrimitives = 1;
uint32_t aabb_input_flags[1] = {OPTIX_GEOMETRY_FLAG_NONE};
state.triangle_input.customPrimitiveArray.flags = aabb_input_flags;
state.triangle_input.customPrimitiveArray.numSbtRecords = 1;
with the same code following for construction:
OptixAccelBuildOptions accel_options = {};
accel_options.buildFlags = OPTIX_BUILD_FLAG_ALLOW_UPDATE;
accel_options.operation = OPTIX_BUILD_OPERATION_BUILD;
OptixAccelBufferSizes gas_buffer_sizes;
OPTIX_CHECK( optixAccelComputeMemoryUsage(state.context, &accel_options, &state.triangle_input, 1, &gas_buffer_sizes) );
state.temp_buffer_size = gas_buffer_sizes.tempSizeInBytes;
CUDA_CHECK( cudaMalloc( reinterpret_cast<void**>(&state.d_temp_buffer), gas_buffer_sizes.tempSizeInBytes) );
// non-compact output
CUdeviceptr d_buffer_temp_output_gas_and_compacted_size;
size_t compactedSizeOffset = roundUp<size_t>(gas_buffer_sizes.outputSizeInBytes, 8ull);
CUDA_CHECK( cudaMalloc( reinterpret_cast<void**>(&d_buffer_temp_output_gas_and_compacted_size), compactedSizeOffset + 8) );
OptixAccelEmitDesc emitProperty = {};
emitProperty.type = OPTIX_PROPERTY_TYPE_AABBS;
emitProperty.result = (CUdeviceptr)((char *)d_buffer_temp_output_gas_and_compacted_size + compactedSizeOffset);
OPTIX_CHECK( optixAccelBuild(
state.context,
0,
&accel_options,
&state.triangle_input,
1,
state.d_temp_buffer,
gas_buffer_sizes.tempSizeInBytes,
d_buffer_temp_output_gas_and_compacted_size,
gas_buffer_sizes.outputSizeInBytes,
&state.gas_handle,
&emitProperty, 1)
);
state.d_gas_output_buffer = d_buffer_temp_output_gas_and_compacted_size;
state.gas_output_buffer_size = gas_buffer_sizes.outputSizeInBytes;
And, because the documentation do not seem to mention a special case about custom primitives for dynamic updates, I kept exactly the same code for updating my GAS:
void updateASFromDevice(GASstate &state) {
OptixAccelBuildOptions gas_accel_options = {};
gas_accel_options.buildFlags = OPTIX_BUILD_FLAG_ALLOW_UPDATE;
gas_accel_options.operation = OPTIX_BUILD_OPERATION_UPDATE;
OPTIX_CHECK(optixAccelBuild(
state.context,
0,
&gas_accel_options,
&state.triangle_input,
1,
state.d_temp_buffer,
state.temp_buffer_size,
state.d_gas_output_buffer,
state.gas_output_buffer_size,
&state.gas_handle,
nullptr,
0)
);
}
I added the intersection shader in the program group. My shaders are all empty except for the raygen shader and the intersection shader, which is a simple print regarding which ray interact with which AABB
The program is working really well if I am not updating the GAS and rebuilding it each frame, but when I want to update the GAS instead of rebuilding it, I have this error message during the execution:
/home/hbec/RTX-CUDA-toy/./src/rtx_functions.h:472 Optix Error: 'Invalid value'
Line 472 referring to the optixAccelBuild function in my updateASFromDevice function (see above).
I don’t understand what else do I have to change. Is there a specific case for custom primitive for the update of GAS ? And also do you know how to have more precision on the error message ?
Thank you in advance for your interest in my problem, I am at your disposal for any further information,
tintingai.