Hi all,
I’m in the process of moving my lens shaders into direct callable functions as in the advanced examples Optix_Apps Lens Shaders. But when I try to create my module I get an error that it is invalid. If I add for example a raygen program to the same ptx the raygen program is identified but not the direct callables.
My project is originally based on Ingo Walds Siggraph course so I’m using that compile and embed macro to create the ptx. Not sure but maybe the compiler can’t identify the programs?
macro(cuda_compile_and_embed output_var cuda_file)
set(c_var_name ${output_var})
cuda_compile_ptx(ptx_files ${cuda_file})
list(GET ptx_files 0 ptx_file)
set(embedded_file ${ptx_file}_embedded.c)
# message("adding rule to compile and embed ${cuda_file} to \"const char ${var_name}[];\"")
add_custom_command(
OUTPUT ${embedded_file}
COMMAND ${BIN2C} -c --padd 0 --type char --name ${c_var_name} ${ptx_file} > ${embedded_file}
DEPENDS ${ptx_file}
COMMENT "compiling (and embedding ptx from) ${cuda_file}"
)
set(${output_var} ${embedded_file})
endmacro()
include_directories(${OptiX_INCLUDE})
add_definitions(-D__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__=1)
Also here’s an example of my direct callable:
extern "C" __device__ void __direct_callable__rectilinear(const uint3 launchIndex, const uint3 launchDim, vec3f & position, vec3f & rayDir)
{
const auto& viewpoint = params.viewpoint;
const auto& camera = params.camera;
const vec2f screen(vec2f(launchIndex.x + .5f, launchIndex.y + .5f) / vec2f(launchDim.x, launchDim.y));
// generate ray direction
rayDir = normalize(viewpoint.direction * camera.FoVdepth
+ (screen.x - 0.5f) * viewpoint.horizontal
+ (0.5f - screen.y) * viewpoint.vertical * camera.aspect);
position = viewpoint.position;
}
and my module creation:
OptixModuleCompileOptions moduleCompileOptions = {};
moduleCompileOptions.maxRegisterCount = 0;
moduleCompileOptions.optLevel = OPTIX_COMPILE_OPTIMIZATION_DEFAULT;
moduleCompileOptions.debugLevel = OPTIX_COMPILE_DEBUG_LEVEL_NONE;
pipelineCompileOptions.traversableGraphFlags = OPTIX_TRAVERSABLE_GRAPH_FLAG_ALLOW_SINGLE_LEVEL_INSTANCING;
pipelineCompileOptions.usesMotionBlur = false;
pipelineCompileOptions.numPayloadValues = 5;
pipelineCompileOptions.numAttributeValues = 2;
pipelineCompileOptions.exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE; //OPTIX_EXCEPTION_FLAG_DEBUG;
pipelineCompileOptions.pipelineLaunchParamsVariableName = "params";
pipelineCompileOptions.usesPrimitiveTypeFlags = OPTIX_PRIMITIVE_TYPE_FLAGS_TRIANGLE;
const std::string ptxCodeLensShaders = embedded_ptx_lensShaders;
char log[2048];
size_t sizeof_log = sizeof(log);
OPTIX_CHECK(optixModuleCreateFromPTX(optixContext,
&moduleCompileOptions,
&pipelineCompileOptions,
ptxCodeLensShaders.c_str(),
ptxCodeLensShaders.size(),
log, &sizeof_log,
&moduleDC
));
if (sizeof_log > 1) PRINT(log);