nvpro-samples / vk_raytrace

Ray tracing glTF scene with Vulkan
Apache License 2.0
567 stars 35 forks source link

Error Compiling the Shaders #2

Closed chrisdonlan closed 3 years ago

chrisdonlan commented 3 years ago

Ran into this error compiling the shaders:

[ 53%] Linking CXX static library /home/chris/ray-tracing/bin_x64/libshared_sources.a
[ 53%] Built target shared_sources
[ 55%] Generating ../autogen/shaders/post.frag.h
/usr/bin/glslangValidator -o autogen/shaders/post.frag.h -V /home/chris/ray-tracing/vk_raytrace/shaders/post.frag --vn post_frag --target-env vulkan1.2
/home/chris/ray-tracing/vk_raytrace/shaders/post.frag
ERROR: Failed to open file: autogen/shaders/post.frag.h
[ 57%] Generating ../autogen/shaders/passthrough.vert.h
/usr/bin/glslangValidator -o autogen/shaders/passthrough.vert.h -V /home/chris/ray-tracing/vk_raytrace/shaders/passthrough.vert --vn passthrough_vert --target-env vulkan1.2
/home/chris/ray-tracing/vk_raytrace/shaders/passthrough.vert
ERROR: Failed to open file: autogen/shaders/passthrough.vert.h
[ 59%] Generating ../autogen/shaders/pathtrace.rahit.h
/usr/bin/glslangValidator -o autogen/shaders/pathtrace.rahit.h -V /home/chris/ray-tracing/vk_raytrace/shaders/pathtrace.rahit --vn pathtrace_rahit --target-env vulkan1.2
/home/chris/ray-tracing/vk_raytrace/shaders/pathtrace.rahit
ERROR: /home/chris/ray-tracing/vk_raytrace/shaders/pathtrace.rahit:88: 'ignoreIntersectionEXT' : undeclared identifier 
ERROR: /home/chris/ray-tracing/vk_raytrace/shaders/pathtrace.rahit:88: '' : compilation terminated 
ERROR: 2 compilation errors.  No code generated.

GLSL is installed:

AMDGPU Packages 
Installed Packages
glslc.x86_64  2020.4-1.fc33
Available Packages
glslc.x86_64  2020.2-1.fc33  
glslc.x86_64  2020.4-1.fc33  

GLSL Lang is @11.0

Installed Packages
glslang.x86_64 11.0.0-1.20200803.git5743eed.fc33
mklefrancois commented 3 years ago

I haven't tried on linux, but I guess the problem is showing on this line:

-o autogen/shaders/post.frag.h

The output does not have the full path and it is relative to where glslangValidator is executed. I will make an update to the CMake to include the full path. Meanwhile you can copy the generated files or add the path /home/chris/ray-tracing/vk_raytrace/ or ${CMAKE_CURRENT_SOURCE_DIR}

Should be:

COMMAND ${GLSLANGVALIDATOR} -g -o ${CMAKE_CURRENT_SOURCE_DIR}/autogen/${_OUTPUT} -V ${_SOURCE} --vn ${VAR_NAME} --target-env ${VULKAN_TARGET_ENV}
chrisdonlan commented 3 years ago

I see it; I modified line 92 of CMakeLists.txt:

[ 63%] Generating ../autogen/shaders/pathtrace.rahit.h
[ 65%] Generating ../autogen/shaders/pathtraceShadow.rmiss.h
[ 68%] Generating ../autogen/shaders/pathtrace.rmiss.h
/usr/bin/glslangValidator -o autogen/shaders/pathtrace.rgen.h -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rgen --vn pathtrace_rgen --target-env vulkan1.2
/usr/bin/glslangValidator -o autogen/shaders/passthrough.vert.h -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/passthrough.vert --vn passthrough_vert --target-env vulkan1.2
/usr/bin/glslangValidator -o autogen/shaders/post.frag.h -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/post.frag --vn post_frag --target-env vulkan1.2
/usr/bin/glslangValidator -o autogen/shaders/pathtrace.rchit.h -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rchit --vn pathtrace_rchit --target-env vulkan1.2
/usr/bin/glslangValidator -o autogen/shaders/pathtrace.rahit.h -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rahit --vn pathtrace_rahit --target-env vulkan1.2
/usr/bin/glslangValidator -o autogen/shaders/pathtraceShadow.rmiss.h -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtraceShadow.rmiss --vn pathtraceShadow_rmiss --target-env vulkan1.2
/usr/bin/glslangValidator -o autogen/shaders/pathtrace.rmiss.h -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rmiss --vn pathtrace_rmiss --target-env vulkan1.2
/home/chris/lab/ray-tracing/vk_raytrace/shaders/post.frag
ERROR: Failed to open file: /home/chris/lab/ray-tracing/vk_raytrace/autogen/shaders/post.frag.h
/home/chris/lab/ray-tracing/vk_raytrace/shaders/passthrough.vert
ERROR: Failed to open file: /home/chris/lab/ray-tracing/vk_raytrace/autogen/shaders/passthrough.vert.h
/home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtraceShadow.rmiss
ERROR: Failed to open file: /home/chris/lab/ray-tracing/vk_raytrace/autogen/shaders/pathtraceShadow.rmiss.h
/home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rahit
ERROR: /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rahit:88: 'ignoreIntersectionEXT' : undeclared identifier 
ERROR: /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rahit:88: '' : compilation terminated 
ERROR: 2 compilation errors.  No code generated.

The proj path has changed from /home/chris/ray-tracing/... -> /home/chris/lab/ray-tracing/....

It seems like [ 63%] Generating ../autogen/shaders/pathtrace.rahit.h now compiles correctly, but that there is still some issue.

chrisdonlan commented 3 years ago

Alright, narrowed it down:

[ 68%] Generating ../autogen/shaders/pathtraceShadow.rmiss.h
/usr/bin/glslangValidator -o /home/chris/lab/ray-tracing/vk_raytrace/autogen/shaders/pathtrace.rmiss.h -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rmiss --vn pathtrace_rmiss --target-env vulkan1.2
/usr/bin/glslangValidator -o /home/chris/lab/ray-tracing/vk_raytrace/autogen/shaders/pathtrace.rgen.h -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rgen --vn pathtrace_rgen --target-env vulkan1.2
/usr/bin/glslangValidator -o /home/chris/lab/ray-tracing/vk_raytrace/autogen/shaders/pathtraceShadow.rmiss.h -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtraceShadow.rmiss --vn pathtraceShadow_rmiss --target-env vulkan1.2
/home/chris/lab/ray-tracing/vk_raytrace/shaders/passthrough.vert
ERROR: Failed to open file: /home/chris/lab/ray-tracing/vk_raytrace/autogen/shaders/passthrough.vert.h
/home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rahit
ERROR: /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rahit:88: 'ignoreIntersectionEXT' : undeclared identifier 
ERROR: /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rahit:88: '' : compilation terminated 
ERROR: 2 compilation errors.  No code generated.

lines modified so far: 91-92. I included line 90 below, but that is unmodified.

Changed to:

OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/autogen/${_OUTPUT}
COMMAND echo ${GLSLANGVALIDATOR} -o ${OUTPUT} -V ${_SOURCE} --vn ${VAR_NAME} --target-env ${VULKAN_TARGET_ENV}
COMMAND ${GLSLANGVALIDATOR} -g -o ${OUTPUT} -V ${_SOURCE} --vn ${VAR_NAME} --target-env ${VULKAN_TARGET_ENV}

Yields the following new error (which may be a dependency issue on my part):

[ 68%] Generating ../autogen/shaders/pathtraceShadow.rmiss.h
/usr/bin/glslangValidator -o -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rchit --vn pathtrace_rchit --target-env vulkan1.2
/usr/bin/glslangValidator -o -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/passthrough.vert --vn passthrough_vert --target-env vulkan1.2
/usr/bin/glslangValidator -o -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rahit --vn pathtrace_rahit --target-env vulkan1.2
/usr/bin/glslangValidator -o -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rmiss --vn pathtrace_rmiss --target-env vulkan1.2
/usr/bin/glslangValidator -o -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rgen --vn pathtrace_rgen --target-env vulkan1.2
/usr/bin/glslangValidator -o -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtraceShadow.rmiss --vn pathtraceShadow_rmiss --target-env vulkan1.2
/home/chris/lab/ray-tracing/vk_raytrace/shaders/post.frag
/home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtraceShadow.rmiss
/home/chris/lab/ray-tracing/vk_raytrace/shaders/passthrough.vert
/home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rgen
/home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rmiss
/home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rahit
ERROR: /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rahit:88: 'ignoreIntersectionEXT' : undeclared identifier 
ERROR: /home/chris/lab/ray-tracing/vk_raytrace/shaders/pathtrace.rahit:88: '' : compilation terminated 
ERROR: 2 compilation errors.  No code generated.
chrisdonlan commented 3 years ago

And I've corrected the dependency errors. In order to get everything working, I did have to disable the following extension in the shaders:

ignoreIntersectionEXT

I think this error may be getting emitted in Fedora 33 because I installed glsl via yum repositories rather than the Vulkan SDK. So, I am not too worried about that.

However, the compilation ultimately fails at what looks like a build error:

[ 97%] Building CXX object CMakeFiles/vk_raytrace.dir/home/chris/lab/ray-tracing/shared_sources/imgui/imgui_camera_widget.cpp.o
[ 98%] Building CXX object CMakeFiles/vk_raytrace.dir/home/chris/lab/ray-tracing/shared_sources/imgui/imgui_impl_vk.cpp.o
/home/chris/lab/ray-tracing/vk_raytrace/offscreen.cpp:19:10: fatal error: autogen/shaders/passthrough.vert.h: No such file or directory
   19 | #include "autogen/shaders/passthrough.vert.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The #include does show up in Clion as an error, so I am going to tinker with the CMakeLists.txt file when I get a chance, and see if I can get the include to work.

mklefrancois commented 3 years ago

I think the change in the Makefile had an issue.

This is not a valid Cmake command

OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/autogen/${_OUTPUT}

That's why there is now an empty output in the log

/usr/bin/glslangValidator -o -V ... 

Can you try modifying the lines as

COMMAND echo ${GLSLANGVALIDATOR} -o ${CMAKE_CURRENT_SOURCE_DIR}/autogen/${_OUTPUT} -V ${_SOURCE} --vn ${VAR_NAME} --target-env ${VULKAN_TARGET_ENV}
COMMAND ${GLSLANGVALIDATOR} -g -o ${CMAKE_CURRENT_SOURCE_DIR}/autogen/${_OUTPUT} -V ${_SOURCE} --vn ${VAR_NAME} --target-env ${VULKAN_TARGET_ENV}

or if you want to keep the OUTPUT, the variable need to be set

set(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/autogen/${_OUTPUT})

The output of glslValidator should have a full path. You can check where that file is. Later, when compiling the project, the include directive should find.

chrisdonlan commented 3 years ago

So I rebuilt with the macro defined as:

macro(_compile_GLSL_to_header _SOURCE _OUTPUT SOURCE_LIST OUTPUT_LIST FILE_NAME)
  LIST(APPEND ${SOURCE_LIST} ${_SOURCE})
  LIST(APPEND ${OUTPUT_LIST} autogen/${_OUTPUT})
  STRING(REPLACE "." "_" VAR_NAME ${FILE_NAME})
  if(GLSLANGVALIDATOR)
    add_custom_command(
      OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/autogen/${_OUTPUT}
      COMMAND echo ${GLSLANGVALIDATOR} -o ${CMAKE_CURRENT_SOURCE_DIR}/autogen/${_OUTPUT} -V ${_SOURCE} --vn ${VAR_NAME} --target-env ${VULKAN_TARGET_ENV}
      COMMAND ${GLSLANGVALIDATOR} -g -o ${CMAKE_CURRENT_SOURCE_DIR}/autogen/${_OUTPUT} -V ${_SOURCE} --vn ${VAR_NAME} --target-env ${VULKAN_TARGET_ENV}
      MAIN_DEPENDENCY ${_SOURCE}
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
      DEPENDS ${GLSL_HEADER_FILES}
      )
  else(GLSLANGVALIDATOR)
    MESSAGE(WARNING "could not find GLSLANGVALIDATOR to compile shaders")
  endif(GLSLANGVALIDATOR)
endmacro()

But, I still wind up with the following error output:

 98%] Building CXX object CMakeFiles/vk_raytrace.dir/home/chris/lab/ray-tracing/shared_sources/imgui/imgui_camera_widget.cpp.o
/home/chris/lab/ray-tracing/vk_raytrace/rtx_pipeline.cpp:20:10: fatal error: autogen/shaders/pathtrace.rahit.h: No such file or directory
   20 | #include "autogen/shaders/pathtrace.rahit.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [CMakeFiles/vk_raytrace.dir/build.make:275: CMakeFiles/vk_raytrace.dir/rtx_pipeline.cpp.o] Error 1
gmake[2]: *** Waiting for unfinished jobs....
/home/chris/lab/ray-tracing/vk_raytrace/offscreen.cpp:19:10: fatal error: autogen/shaders/passthrough.vert.h: No such file or directory
   19 | #include "autogen/shaders/passthrough.vert.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order to fix this, I ran cmake from the root directory:

cd /home/chris/lab/ray_tracing/vk_raytracing
cmake . 
// Got the same error

// The failing command
/opt/vulkan-sdk/1.2.162.1/x86_64/bin/glslangValidator -o /home/chris/lab/ray-tracing/vk_raytrace/shaders/post.frag.h -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/post.frag --vn post_frag --target-env vulkan1.2

This was failing, so I tried the following:

mkdir -p autogen && /opt/vulkan-sdk/1.2.162.1/x86_64/bin/glslangValidator -o /home/chris/lab/ray-tracing/vk_raytrace/shaders/post.frag.h -V /home/chris/lab/ray-tracing/vk_raytrace/shaders/post.frag --vn post_frag --target-env vulkan1.2

And it worked... So I think the mistake must be that the autogen directory is not getting created. Perhaps my build process is skipping a step?

mkdir -p build/autogen
cmake -B $(pwd)/build -S $(pwd)

Currently works. I wind up here:

[ 77%] Building CXX object CMakeFiles/vk_raytrace.dir/accelstruct.cpp.o
In file included from /home/chris/lab/ray-tracing/vk_raytrace/accelstruct.hpp:18,
                 from /home/chris/lab/ray-tracing/vk_raytrace/accelstruct.cpp:28:
/home/chris/lab/ray-tracing/shared_sources/nvvk/raytraceKHR_vk.hpp:592:2: error: #error This include requires VK_KHR_ray_tracing support in the Vulkan SDK.
  592 | #error This include requires VK_KHR_ray_tracing support in the Vulkan SDK.

And follow google to this stack overflow question and this index of drivers.

Looking at these drivers, I am not sure whether they are "developer drivers" and have the RTX ray tracing enabled (meaning I download 460), or whether I need to download the latest feature branch, 455.

Either way, I am having some trouble installing both the a-la-carte developer driver, and Cuda + NV-ml (my preference is to use dnf/yum when possible -- I was able to add the cuda repo file for my system to my /etc/yum.repos.d from this index here).

Do you have any recommendations?


And want to say: once we debug this, I am happy to write up a step-by-step install script for everything it took to get the Quadro RTX 4000 working with everything installed on fedora33, and hand it off to you guys.

chrisdonlan commented 3 years ago

I fixed things by creating the following directory in the home folder of the project:

mkdir -p autogen/shaders

In addition to the recommended changes.