Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vma.VMA_MEMORY_USAGE_GPU_ONLY and Vma.VMA_MEMORY_USAGE_CPU_ONLY values are swapped #458

Closed
justindriggers opened this issue Apr 19, 2019 · 1 comment

Comments

@justindriggers
Copy link

Environment

  • LWJGL version: 3.2.1
  • LWJGL build #: 12
  • Java version: Oracle JDK 1.8.0_212
  • Platform: Linux (Fedora 29) / macOS (Mojave) / Windows 10
  • Module: lwjgl-vma
  • CPU: Intel Core i5-4690K
  • GPU: NVIDIA GeForce GTX 980

Description

In https://github.com/LWJGL/lwjgl3/blob/master/modules/lwjgl/vma/src/main/c/vk_mem_alloc.h the values are declared as:

VMA_MEMORY_USAGE_GPU_ONLY = 1,
VMA_MEMORY_USAGE_CPU_ONLY = 2,

But in https://github.com/LWJGL/lwjgl3/blob/master/modules/lwjgl/vma/src/generated/java/org/lwjgl/util/vma/Vma.java the values are:

VMA_MEMORY_USAGE_GPU_ONLY   = 2,
VMA_MEMORY_USAGE_CPU_ONLY   = 1,

Reproducing (Kotlin)

First discovered as I was creating a staging buffer for vertex data:

MemoryStack.stackPush().use {
    val bufferCreateInfo = VkBufferCreateInfo.callocStack(it)
        .sType(VK10.VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO)
        .size(4L * 2L * 3L) // vertex buffer for a triangle of vec2
        .usage(VK10.VK_BUFFER_USAGE_TRANSFER_SRC_BIT)

    val allocationCreateInfo = VmaAllocationCreateInfo.callocStack(it)
        .usage(Vma.VMA_MEMORY_USAGE_CPU_ONLY)

    val buffer = it.mallocLong(1)
    val allocation = it.mallocPointer(1)
    val allocationInfo = VmaAllocationInfo.mallocStack(it)

    Vma.vmaCreateBuffer(allocator, bufferCreateInfo, allocationCreateInfo, buffer, allocation, allocationInfo)
        .takeUnless { result -> result == VK10.VK_SUCCESS }
        ?.also { throw IllegalStateException("Failed to create buffer: $this") }

    val mapping = it.mallocPointer(1)

    Vma.vmaMapMemory(allocator, allocation[0], mapping)
        .takeUnless { result -> result == VK10.VK_SUCCESS }
        ?.also { throw IllegalStateException("Failed to map buffer: $this") }
}

Validation layers report:

[ERROR|VALIDATION] Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT set: mem obj 0x13. The Vulkan spec states: memory must have been created with a memory type that reports VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-vkMapMemory-memory-00682)

And the IllegalStateException is thrown: Failed to map buffer: -5 which is the error code for ERROR_MEMORY_MAP_FAILED.

Inspecting allocationInfo shows that the memory type only supports VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, and not VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT as "guaranteed" by Vma.VMA_MEMORY_USAGE_CPU_ONLY.

Simply hard-coding allocationCreateInfo.usage(2) resolves the issue.

@Spasi
Copy link
Member

Spasi commented Apr 22, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants