Hello Guest

Vulkan shader creation crash

  • 2 Replies
  • 143 Views
Vulkan shader creation crash
« on: June 14, 2019, 08:59:13 »
Hi

I get a full crash when trying to create my shaders in vulkan

Stack: [0x00007ff574677000,0x00007ff574778000],  sp=0x00007ff574773fe8,  free space=1011k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libVkLayer_khronos_validation.so+0x7d35e4]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.lwjgl.system.JNI.callPPPPI(JJJJJ)I+0
j  org.lwjgl.vulkan.VK10.nvkCreateShaderModule(Lorg/lwjgl/vulkan/VkDevice;JJJ)I+39
j  org.lwjgl.vulkan.VK10.vkCreateShaderModule(Lorg/lwjgl/vulkan/VkDevice;Lorg/lwjgl/vulkan/VkShaderModuleCreateInfo;Lorg/lwjgl/vulkan/VkAllocationCallbacks;Ljava/nio/LongBuffer;)I+24
j  mycode.VkShader.createShaderStages()V+108

I have successfully compiled my shader using glslangValidator -V and this is my code to load the shader

Code: [Select]
       LongBuffer shaderModuleBuffer = memAllocLong(1);
        shaderStages = VkPipelineShaderStageCreateInfo.calloc(shaderInfo.shaderCount());

        VkShaderModuleCreateInfo createInfoShaderModuleVertex = VkShaderModuleCreateInfo.calloc()
                .sType(VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO)
                .pCode(shaderInfo.getVertexShaderBuffer())
                .flags(0);
        errorCheck("", vkCreateShaderModule(logicalDevice.getLogicalDevice(), createInfoShaderModuleVertex, null, shaderModuleBuffer));

The byte buffer with the pCode matches the size of whats on the os (so giving confidence its the same), it is also flipped correctly. The toString of it is "java.nio.HeapByteBuffer[pos=0 lim=2436 cap=2436]". Other parts of the vulkan code are working fine (like image creation,  validation, swap chain creation etc)

When turning off the validation layers I get

Stack: [0x00007fd111ce6000,0x00007fd111de7000],  sp=0x00007fd111de4e48,  free space=1019k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libc.so.6+0x189291]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.lwjgl.system.JNI.callPPPPI(JJJJJ)I+0
j  org.lwjgl.vulkan.VK10.nvkCreateShaderModule(Lorg/lwjgl/vulkan/VkDevice;JJJ)I+39
j  org.lwjgl.vulkan.VK10.vkCreateShaderModule(Lorg/lwjgl/vulkan/VkDevice;Lorg/lwjgl/vulkan/VkShaderModuleCreateInfo;Lorg/lwjgl/vulkan/VkAllocationCallbacks;Ljava/nio/LongBuffer;)I+24
j  mycode.VkShader.createShaderStages()V+108

Do you have any ideas what is going wrong? Would incorrect byte data cause the crash?

*

Offline spasi

  • *****
  • 2132
    • WebHotelier
Re: Vulkan shader creation crash
« Reply #1 on: June 14, 2019, 09:09:18 »
The problem is java.nio.HeapByteBuffer. LWJGL requires direct/off-heap buffers everywhere.

Re: Vulkan shader creation crash
« Reply #2 on: June 14, 2019, 09:41:21 »
Thanks, that was a bit of a school boy error! I had a ByteBuffer.wrap somewhere which needed fixing.