Specs: GTX 1080
This question probably falls under OpenGL too, but I’m developing for Vulkan right now.
I’m trying to call findMSB on a 64 bit uint in a compute shader. I checked that shaderInt64 is TRUE from vkGetPhysicalDeviceFeatures and set it to TRUE in VkDeviceCreateInfo::pEnabledFeatures. I also made sure to enable 64 bit int support in the shader with:
#extension GL_ARB_gpu_shader_int64 : require
The shader compiles fine, but at runtime (pipeline creation) I get:
(0) : fatal error C9999: Can't convert to expr: findMSB
The offending dummy code is:
uint64_t num = 1 << 35; int res = findMSB(num);
If useful, here is the spirv output:
Store 1053(num) 1054 1056: 11(int) Load 1053(num) 1057: 49(int) ExtInst 1(GLSL.std.450) 75(FindUMsb) 1056 Store 1055(res) 1057
I tried the same code for findLSB which failed in the same way. But interestingly, when I tried another bitfield operation like bitfieldReverse, the shader compiler (glslangValidator from VulkanSDK 188.8.131.52) fails:
error : ..\data\shaders\test.comp:296: 'bitfieldReverse' : no matching overloaded function found error : ..\data\shaders\test.comp:296: '=' : cannot convert from ' const float' to ' temp uint64_t'
After reading https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_gpu_shader_int64.txt it looks like findMSB is not explicitly supported. Does this mean the shader compiler should have detected invalid usage for findMSB? Or does it mean it’s up to the GPU vendor to support it? And why is there a difference for bitfieldReverse?
For now I will use workaround code (if there’s a faster way to do this let me know):
uint64_t num = 1 << 35; int msbFar = findMSB(uint(num >> 32); int msbFinal = (msbFar == -1) ? findMSB(uint(num)) : msbFar + 32;