Earlier feedback for syntax errors in shaders


First of all, thank you for the great work put into OptiX (and for making it available!).

I am testing the 7.5 release, and I noticed a small (usability) issue. I imagine that this has been solved already (or that I am missing something), so I hope someone here can help me.

As mentioned in the title, I would like to get earlier feedback if/when there is a problem with the shader code.

For example, if we take the optixWhitted sample and introduce a syntax error (say, comment a variable declaration in camera.cu), the compilation succeeds (no build errors), although the corresponding optixir file is not generated.

If, on the other file, I try to generate the optixir file manually by invoking nvcc, I get a clear error-message (as expected).

Somewhere in the CMake set-up for the SDK nvcc is invoked (CMake even announces that the optixir file is about to be generated), but when this step fails the errors are ignored.

Is there a way to un-ignore such errors?


Works for me. ;-)

I just compiled the OptiX SDK 7.5.0 example optixWhitted successfully and then added an error (missing semicolon) into camera.cu and got the exact error and location from NVCC.

extern "C" __global__ void __raygen__pinhole_camera()
    float blub // error: missing semicolon
    const uint3 idx = optixGetLaunchIndex();

and this is the output (without my local SDK paths) when using MSVS 2022 and CUDA 11.7:

2>------ Build started: Project: optixWhitted, Configuration: Debug x64 ------
2>Building NVCC optixir file lib/ptx/Debug/optixWhitted_generated_camera.cu.optixir
2>optixWhitted\camera.cu(43): error : expected a ";"
2>optixWhitted\camera.cu(48): error : identifier "idx" is undefined
2>optixWhitted\camera.cu(42): warning #177-D: variable "blub" was declared but never referenced
2>2 errors detected in the compilation of "optixWhitted/camera.cu".

Could you clarify a little more what exactly you changed?

Just to be sure, you have the CMake variable CUDA_NVRTC_ENABLED set to off?
Because that would generate PTX code at application runtime and no *.optixir files.

If that’s not it, what’s your OS version, CUDA Toolkit version used inside the OptiX SDK samples compilation and what is the host compiler?

Somewhere in the CMake set-up for the SDK nvcc is invoked (CMake even announces that the optixir file is about to be generated), but when this step fails the errors are ignored.

CMake is generating custom build rules for the *.cu files which will then be executed by the build process.
If this is with MSVS, you can increase the verbosity of MSBuild in the menu Tools → Options → Projects and Solutions → Build and Run.
The MSBuild verbosity is normally set to “Minimal”. You cannot actually suppress the error messages there, but if you want to see the exact custom build rule command lines, you can increase the output to “Detailed” and look at what NVCC command was executed.

Thank you for the quick reply!

About my setup: I am working on Linux (Ubuntu 20.04), with CUDA 11.7 (GCC 9.4.0).

Maybe this problem only shows up on Linux platforms?

I checked, and CUDA_NVRTC_ENABLED is set to off. This is further confirmed by the fact that *.optixir filed are created when there is no syntax error.

OK, thanks.
No idea how GCC handles errors from custom build rules.
I’ll ask around internally if someone has a matching setup.

Maybe one more thing: Is the same happening when not targeting OptiX IR but PTX?

This turned out to be a small error inside a CMake script which slipped into the OptiX SDK 7.5.0 release but can easily be resolved locally.
It’s going to be fixed in the upcoming OptiX SDK release.

Inside CMake/cuda/FindCUDA/run_nvcc.cmake you replace these two lines:

function(cuda_execute_process status command) 


macro(cuda_execute_process status command)

That does it, thank you very much!