-1

i want to create array of ubo object in my cpu update it and then upload it to the gpu in one call like that. (for the example lets say i have only two objects).

    std::vector<UniformBufferObject> ubo(m_allObject.size());

    int index = 0;
    for (RenderableObject* rendObj : m_allObject)
    {
        ubo[index].proj = m_camera->getProjection();
        ubo[index].view = m_camera->getView();
        ubo[index].model = rendObj->getTransform().getModel();
        ubo[index].proj[1][1] *= -1;
        index++;
    }

    int size = sizeof(UniformBufferObject) *m_allObject.size();
    void* data;
    m_instance->getLogicalDevice().mapMemory(ykEngine::Buffer::m_uniformBuffer.m_bufferMemory, 0, size , vk::MemoryMapFlags(), &data);
    memcpy(data, ubo.data(), size);
    m_instance->getLogicalDevice().unmapMemory(ykEngine::Buffer::m_uniformBuffer.m_bufferMemory);

i created one buffer with the size of two ubo. (the create do work because it do work with ubo in size one).

        vk::DeviceSize bufferSize = sizeof(UniformBufferObject) * 2;

        createBuffer(logicalDevice, bufferSize, vk::BufferUsageFlagBits::eUniformBuffer, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent, m_uniformBuffer.m_buffer, m_uniformBuffer.m_bufferMemory);

and than i put an offset in the descriptor set creation :

    vk::DescriptorBufferInfo bufferInfo;
    bufferInfo.buffer = uniformBuffer;
    bufferInfo.offset = offsetForUBO;
    bufferInfo.range = sizeof(UniformBufferObject);

the offset is the size of UniformBufferObject * the index of the object.

every object have is own descriptorsetLayout but the samepipline

when i try to update the descriptor set i get the error :

enter image description here

i couldnt find any aligment enum that specify that information.

if anyone know how to do that it will help alot.

thanks.

Ori Yampolsky
  • 125
  • 13

1 Answers1

2

i couldnt find any aligment enum that specify that information.

Vulkan is not OpenGL; you don't use enums to query limits. Limits are defined by the VkPhysicalDeviceLimits struct, queried via vkGetPhysicalDeviceProperties/2KHR.

The error tells you exactly which limitation you violated: minUniformBufferOffsetAlignment. Your implementation set this to 0x100, but your provided offset was insufficient for this.

Also, you should not map buffers in the middle of a frame. All mapping in Vulkan is "persistent"; map it once and leave it that way until you're ready to delete the memory.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • how can i get this alinment ? its link error with normal method and when i try to use : auto func = (PFN_vkGetPhysicalDeviceProperties2KHR)vkGetDeviceProcAddr(*this, "vkGetPhysicalDeviceProperties2KHR"); its not work either . – Ori Yampolsky Aug 20 '17 at 17:55
  • @OriYampolsky: Maybe your implementation doesn't support that extension. The core function is named `vkGetPhysicalDeviceProperties`. – Nicol Bolas Aug 20 '17 at 18:11
  • 1
    @OriYampolsky the 2KHR version needs an instance extension "VK_KHR_get_physical_device_properties2" – ratchet freak Aug 20 '17 at 18:13
  • Have a look [here](https://github.com/PacktPublishing/Vulkan-Cookbook/blob/master/Library/Source%20Files/01%20Instance%20and%20Devices/12%20Getting%20features%20and%20properties%20of%20a%20physical%20device.cpp) for an example. – Ekzuzy Aug 21 '17 at 09:31