LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.84k stars 642 forks source link

Vulkan NullPointerException on Ubuntu with AMD Radeon #751

Closed cacophany53 closed 2 years ago

cacophany53 commented 2 years ago

Version

3.3.0 (nightly)

Platform

Linux x64

JDK

openjdk version "11.0.14" 2022-01-18

Module

Vulkan

Bug description

LWJGL application running Vulkan code on Ubuntu (AMD) throws a NullPointerException here:

java.lang.NullPointerException
    at org.lwjgl.system.Checks.check(Checks.java:188)
    at org.lwjgl.vulkan.VK13.vkCmdSetDepthTestEnable(VK13.java:3011)

The exact same code runs fine on Windows 10 and 11 with Nvidia and AMD respectively. Using version 3.3.1.

It looks like it is stemming from this code in VK13.java:

public static void vkCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, @NativeType("VkBool32") boolean depthTestEnable) {
        long __functionAddress = commandBuffer.getCapabilities().vkCmdSetDepthTestEnable;
        if (CHECKS) {
            check(__functionAddress);
        }
        callPV(commandBuffer.address(), depthTestEnable ? 1 : 0, __functionAddress);
    }

Under what circumstances would commandBuffer.getCapabilities().vkCmdSetDepthTestEnable; return null?

Stacktrace or crash log output

No response

httpdigest commented 2 years ago

Your issue is somewhat inconsistent. The title says "Vulkan NullPointerException on Ubuntu with AMD Radeon" however in your text you are writing "LWJGL application running Vulkan code on Apple M1 chip (MacOS) throws a NullPointerException here". Which OS does the error occur? Linux/Ubuntu or macOS?

If macOS, then note that macOS does not provide a Vulkan 1.3 implementation natively. When you run your Vulkan/LWJGL3 application under macOS, the adaptation layer https://github.com/KhronosGroup/MoltenVK is being used, which translates Vulkan 1.1 API calls to Metal. MotelVK does not provide a Vulkan 1.3 implementation. Only Vulkan 1.1, and that also with certain restrictions. So, the MoltenVK Vulkan instance simply does not expose that function (i.e. "dynamic graphics pipelines").

cacophany53 commented 2 years ago

My apologies, that was a copy and paste error from a previous issue submission. In this case it is indeed Ubuntu (original post updated).

Thanks for the information regarding MoltenVK for MAC, as that likely applies to my other issue.

With regards to Linux, do you have any advice on this NullPointerException?

Thanks.

Spasi commented 2 years ago

Hey @cacophany53,

The most likely reason is that the AMD driver on Linux does not support Vulkan 1.3 (or did not when you tested it). When using versioned APIs like OpenGL or Vulkan, applications should examine the flags in the "capabilities" classes before using the corresponding core or extension functionality. In this case, see the VKCapabilitiesDevice.Vulkan13 flag.