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.67k stars 631 forks source link

`VkSubmitInfo.pWaitSemaphores` doesn't set `waitSemaphoreCount` #829

Closed MDZhB closed 1 year ago

MDZhB commented 1 year ago

Version

3.3.0

Platform

Windows x64

JDK

OpenJDK 19.0.1

Module

Vulkan

Bug description

VkSubmitInfo.pWaitSemaphores does not also set waitSemaphoreCount to the length of the given buffer. This is surprising, as it is inconsistent with the behaviour of pSignalSemaphores and pCommandBuffers.

    /** Unsafe version of {@link #pWaitSemaphores(LongBuffer) pWaitSemaphores}. */
    public static void npWaitSemaphores(long struct, @Nullable LongBuffer value) { memPutAddress(struct + VkSubmitInfo.PWAITSEMAPHORES, memAddressSafe(value)); }

    /** Unsafe version of {@link #pCommandBuffers(PointerBuffer) pCommandBuffers}. */
    public static void npCommandBuffers(long struct, @Nullable PointerBuffer value) { memPutAddress(struct + VkSubmitInfo.PCOMMANDBUFFERS, memAddressSafe(value)); ncommandBufferCount(struct, value == null ? 0 : value.remaining()); }

    /** Unsafe version of {@link #pSignalSemaphores(LongBuffer) pSignalSemaphores}. */
    public static void npSignalSemaphores(long struct, @Nullable LongBuffer value) { memPutAddress(struct + VkSubmitInfo.PSIGNALSEMAPHORES, memAddressSafe(value)); nsignalSemaphoreCount(struct, value == null ? 0 : value.remaining()); }

Stacktrace or crash log output

No response

Spasi commented 1 year ago

Not a bug, see this reply.

However I admit that, based on the number of issues raised about this, the decision we made back then was probably wrong. I promise to reexamine the available options when the times come to design LWJGL 4. Surprising behavior should not exist, even if the default is convenient for most use-cases.

MDZhB commented 1 year ago

Thanks for clarifying.

I'm still learning the Vulkan API. When I saw that the semaphores I passed to VkSubmitInfo had no effect, my first guess was that I had misunderstood Vulkan's synchronization mechanisms in some way. I therefore spent quite a bit of time exhausting other possibilities before I realized that my code wasn't working due to a subtlety in how the struct works.

My vote would be for consistency over convenience. Given how verbose Vulkan is already, it's not a big deal to require that we set the appropriate count field in every circumstance. It's easier to wrap one's head around, and it mirrors the C API more closely (which is what most learning materials on Vulkan are using).

Thank you for responding so quickly, and for all your work on the library.