nvpro-samples / vk_raytracing_tutorial_KHR

Ray tracing examples and tutorials using VK_KHR_ray_tracing
Apache License 2.0
1.34k stars 142 forks source link

Invalid trace opcode. #18

Closed frustum closed 3 years ago

frustum commented 3 years ago

Driver wrongly uses SpvOpTraceNV opcode instead of SpvOpTraceRayKHR.

SpvOpTraceRayKHR opcode causes driver crash:
#0  0x00007ffff1f0bc08 in ?? () from /usr/lib/x86_64-linux-gnu/libnvidia-glvkspirv.so.455.46.02
#1  0x00007ffff1dc9600 in ?? () from /usr/lib/x86_64-linux-gnu/libnvidia-glvkspirv.so.455.46.02
#2  0x00007ffff1dcdac5 in ?? () from /usr/lib/x86_64-linux-gnu/libnvidia-glvkspirv.so.455.46.02

It looks like the SPIR-V compiler generates an invalid opcode for traceRayKHR().

mklefrancois commented 3 years ago

This should be fixed with the release of yesterday’s drivers. Could you please try with driver version 460.xx?

frustum commented 3 years ago

I have checked the Windows 460.89-desktop-win10-64bit driver. The crash is the same:

Exception thrown at 0x00007FFBA36314D7 (nvoglv64.dll) in main.exe: 0xC0000005: Access violation reading location 0x0000000000000000. nvoglv64.dll!00007ffba36314d7() Unknown nvoglv64.dll!00007ffba247b1de() Unknown nvoglv64.dll!00007ffba24756f0() Unknown

But everything is fine when the opcode is SpvOpTraceNV (5337) instead of SpvOpTraceRayKHR (4445): if(name == "traceRayEXT") opcode = SpvOpTraceNV; It cannot be an error in that line. Moreover, I removed all references to ray_trace_NV extension from the compiler. The only error from the latest (1.2.162) debug runtime is that the opcode is incorrect:

Validation 0: Validation Error: [ UNASSIGNED-CoreValidation-Shader-InconsistentSpirv ] Object 0: handle = 0x14e7728, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x6bbb14 | SPIR-V module not valid: Opcode TraceNV re quires one of these capabilities: RayTracingNV OpTraceNV %204 %uint_4 %int_255 %int_0 %int_0 %int_0 %207 %float_0 %208 %float_1 %int_0

Thank you!

frustum commented 3 years ago

There are links to *.spv files: https://www.icloud.com/... https://www.icloud.com/... Spirv validator reports zero errors. Disassembler prints NV mnemonics because KHR and NV extensions share many symbols.

Thank you!

mklefrancois commented 3 years ago

This sounds like the wrong validation layer DLL is used. Maybe there is two SDK on the system and it is picking up an older version.

To force Vulkan to use the proper layers, you can set the environment variable VK_LAYER_PATH.

Here is how all environment variables should be set

VULKAN_SDK=C:\VulkanSDK\1.2.162.0
VK_LAYER_PATH=C:\VulkanSDK\1.2.162.0\Bin
VK_SDK_PATH=C:\VulkanSDK\1.2.162.0
frustum commented 3 years ago

Oops, it was my error. SpvOpTraceNV and SpvOpTraceRayKHR receives different arguments. The first one requires a payload index as an argument. The second one requires payload as a reference to the payload variable. The validation layer doesn't check that. Moreover, the new glslangValidator magically converts the payload index to the payload variable reference. Thank you!