Need help understanding why optixLaunch is failing

After adding this:

#include <algorithm>
#include <iostream>
#include <mutex>

static std::mutex g_mutexLogger;

static void callbackLogger(unsigned int level, const char* tag, const char* message, void* cbdata)
{
  std::lock_guard<std::mutex> lock(g_mutexLogger);

  std::cerr << tag  << " (" << level << "): " << ((message) ? message : "(no message)") << '\n';
}

and this

  OptixDeviceContextOptions options = {};

  options.logCallbackFunction = &callbackLogger;
  options.logCallbackData     = nullptr;
  options.logCallbackLevel    = 4;
  options.validationMode      = OPTIX_DEVICE_CONTEXT_VALIDATION_MODE_ALL;

the OptiX validation output says:

ERROR (2): "sbt->exceptionRecord" points to a memory area which is not correctly aligned
OPTIX_ERROR_INVALID_VALUE : Invalid value

which is fixed by default-initializing the sbt variable:

	OptixShaderBindingTable sbt = {};

Please always default initialize all OptiX structures like this throughout all your code.
Sometimes a new OptiX SDK version adds fields to some API structures and usually the default value is 0 and that initialization makes sure that is always the case when switching OptiX SDKs, or like in this case.

I would also not handle OptiX IR code as std::string. It contains null bytes.
See this thread for pure binary data handling example code: https://forums.developer.nvidia.com/t/embedding-optix-ir/273199/2

1 Like