Hi
I tried to enable exceptions in my program to see if silent errors occured, and stumbled upon the following behaviour : I first setup all my scene and parameters, and launch the engine. All seems OK.
Then, I setup some sampler again (because its contents could have been modified since last launch call), and call launch again. This is when RT_EXCEPTION_TEXTURE_ID_INVALID appears.
The following code reproduces the problem (based on “device_exception” SDK sample code)
device_exception.cpp :
#include <optixu/optixpp_namespace.h>
#include <sutil.h>
#define LAUNCH_SIZE (10)
#define STRING_LENGTH (512)
#if _WIN32
# define snprintf _snprintf
#endif
optix::TextureSampler updateSampler(optix::Context & context)
{
optix::TextureSampler sampler = context->createTextureSampler();
sampler->setWrapMode(0, RT_WRAP_MIRROR);
sampler->setFilteringModes(RT_FILTER_NEAREST, RT_FILTER_NEAREST, RT_FILTER_NEAREST);
sampler->setIndexingMode(RT_TEXTURE_INDEX_NORMALIZED_COORDINATES);
sampler->setReadMode(RT_TEXTURE_READ_ELEMENT_TYPE);
sampler->setMipLevelCount(1);
sampler->setArraySize(1);
optix::Buffer d_texture_contents = context->createBuffer(RT_BUFFER_INPUT_OUTPUT, RT_FORMAT_FLOAT, 1);
d_texture_contents->setSize(10);
sampler->setBuffer(0, 0, d_texture_contents);
context["sampler_id"]->setInt(sampler->getId());
return sampler;
}
int main(int argc, char* argv[])
{
//
char path_to_ptx[STRING_LENGTH];
if (snprintf( path_to_ptx, STRING_LENGTH, "%s/%s", sutilSamplesPtxDir(), "device_exceptions_generated_device_exceptions.cu.ptx" ) >= STRING_LENGTH) {
sutilReportError("PTX filename size is too large.\n");
}
//
optix::Context context = optix::Context::create();
// Context-level configuration
context->setEntryPointCount(1);
context->setRayTypeCount(1);
context->setRayGenerationProgram(0, context->createProgramFromPTXFile(path_to_ptx, "raygen"));
context->setMissProgram(0, context->createProgramFromPTXFile(path_to_ptx, "miss"));
context["result_buffer"]->setBuffer(context->createBuffer(RT_BUFFER_INPUT_OUTPUT, RT_FORMAT_FLOAT, LAUNCH_SIZE));
// Create dummy scene graph
optix::Geometry geometry = context->createGeometry();
geometry->setBoundingBoxProgram(context->createProgramFromPTXFile(path_to_ptx, "bounding_box"));
geometry->setIntersectionProgram(context->createProgramFromPTXFile(path_to_ptx, "intersection"));
geometry->setPrimitiveCount(1);
optix::Material material = context->createMaterial();
material->setClosestHitProgram(0, context->createProgramFromPTXFile(path_to_ptx, "closest_hit"));
optix::GeometryInstance geometry_instance = context->createGeometryInstance();
geometry_instance->setGeometry(geometry);
geometry_instance->setMaterialCount(1);
geometry_instance->setMaterial(0, material);
optix::GeometryGroup geometry_group = context->createGeometryGroup();
geometry_group->setChildCount(1);
geometry_group->setChild(0, geometry_instance);
optix::Acceleration acceleration = context->createAcceleration("NoAccel", "NoAccel");
geometry_group->setAcceleration(acceleration);
context["dummy_object"]->set(geometry_group);
// Exceptions
context->setExceptionProgram(0, context->createProgramFromPTXFile(path_to_ptx, "exception"));
context->setExceptionEnabled(RT_EXCEPTION_ALL, true);
context->setPrintEnabled(true);
// Sampler
optix::TextureSampler sampler = updateSampler(context);
RTresult compilation_result = rtContextCompile(context->get());
if( compilation_result != RT_SUCCESS) {
std::string err_msg = context->getErrorString(compilation_result);
fprintf(stderr, "%s\n", err_msg.c_str());
}
else
{
// first pass
fprintf(stderr, "pass 1...\n");
context->launch(0, LAUNCH_SIZE, 1, 1);
// update sampler
sampler->destroy();
sampler = updateSampler(context);
// second pass
fprintf(stderr, "pass 2...\n");
context->launch(0, LAUNCH_SIZE, 1, 1);
}
return 0;
}
device_exception.cu :
#include <optix.h>
#include <optixu/optixu_aabb_namespace.h>
#include <optixu/optixu_math_namespace.h>
// optix variables
rtDeclareVariable(uint3, launch_index, rtLaunchIndex, );
rtDeclareVariable(rtObject, dummy_object, , );
rtDeclareVariable(int, sampler_id, , );
rtBuffer<float, 1> result_buffer;
// raygen
RT_PROGRAM void raygen()
{
unsigned int dummy_payload;
optix::Ray ray = optix::make_Ray(make_float3(0,0,0), make_float3(0,0,0), 0, 0, RT_DEFAULT_MAX);
rtTrace(dummy_object, ray, dummy_payload);
}
// miss
RT_PROGRAM void miss()
{
}
// BBox
RT_PROGRAM void bounding_box(int primIdx, float result[6])
{
optix::Aabb* aabb = (optix::Aabb*)result;
aabb->set(make_float3(-1.0f), make_float3(1.0f));
}
// intersection test
RT_PROGRAM void intersection(int primIdx)
{
rtPotentialIntersection(0.f);
rtReportIntersection(0);
}
// closest hit
RT_PROGRAM void closest_hit()
{
const float fetch_result = optix::rtTex1D<float>(sampler_id, .5f);
result_buffer[launch_index.x] = fetch_result;
}
// exception
RT_PROGRAM void exception()
{
rtPrintExceptionDetails();
}
How to get rid of this exception ?
thanks
edit :
Windows 7
Optix 3.7 beta 2, 32bit
CUDA 6.0
GTX 580, driver 340.52