Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
fixed typos
Source Link
Pikalek
  • 13.4k
  • 5
  • 49
  • 54

enter image description here

Why these numbers  ?? I have created a dynamic ubo and two objects  , one for view and proj and the other for model.

Here I update the objects:

Render::UniformBufferObject ubo{};
        Render::UniformBufferObject2 ubo2{};
        

        ubo2.model = &model_transform.GetWorldMatrix();
        
        ubo.view =  &EditorCamera_transform.GetWorldMatrix().Inverse();
          
        ubo.proj = &current_camera->GetProjectionMatrix();

        // map memory without a staging buffer
        void* data;
        auto memory = uniform_buffer->get_ubo_memory();
        Render::VulkanMemoryAllocator::get_instance()->map_buffer_allocation(memory[current_image], &data);
        memcpy(data, &ubo, sizeof(ubo));
        memcpy(data, &ubo2, sizeof(ubo2));
        Render::VulkanMemoryAllocator::get_instance()->unmap_buffer_allocation(memory[current_image]); 

Here binding and draw command:

std::array<uint32_t, 2> dynamicOffsets =
            { i * static_cast<uint32_t>(Render::StandardUniformBuffer::required_alignment(sizeof(Maths::Matrix4)*2)),
              i* static_cast<uint32_t>(Render::StandardUniformBuffer::required_alignment(sizeof(Maths::Matrix4)))
            };

            cmd.bindDescriptorSets(
                vk::PipelineBindPoint::eGraphics,
                *pipeline->get_pipeline_layout(),
                0,
                2,
                descriptor_set->get_descriptor_sets()->data(),
                2,
                dynamicOffsets.data());

            cmd.drawIndexed(static_cast<uint32_t>(index_buffer->get_primative_indices_size()), 1, 0, 0, 0);

enter image description here

Why these numbers  ?? I have created a dynamic ubo and two objects  , one for view and proj and the other for model.

Here I update the objects:

Render::UniformBufferObject ubo{};
        Render::UniformBufferObject2 ubo2{};
        

        ubo2.model = &model_transform.GetWorldMatrix();
        
        ubo.view =  &EditorCamera_transform.GetWorldMatrix().Inverse();
          
        ubo.proj = &current_camera->GetProjectionMatrix();

        // map memory without a staging buffer
        void* data;
        auto memory = uniform_buffer->get_ubo_memory();
        Render::VulkanMemoryAllocator::get_instance()->map_buffer_allocation(memory[current_image], &data);
        memcpy(data, &ubo, sizeof(ubo));
        memcpy(data, &ubo2, sizeof(ubo2));
        Render::VulkanMemoryAllocator::get_instance()->unmap_buffer_allocation(memory[current_image]); 

Here binding and draw command:

std::array<uint32_t, 2> dynamicOffsets =
            { i * static_cast<uint32_t>(Render::StandardUniformBuffer::required_alignment(sizeof(Maths::Matrix4)*2)),
              i* static_cast<uint32_t>(Render::StandardUniformBuffer::required_alignment(sizeof(Maths::Matrix4)))
            };

            cmd.bindDescriptorSets(
                vk::PipelineBindPoint::eGraphics,
                *pipeline->get_pipeline_layout(),
                0,
                2,
                descriptor_set->get_descriptor_sets()->data(),
                2,
                dynamicOffsets.data());

            cmd.drawIndexed(static_cast<uint32_t>(index_buffer->get_primative_indices_size()), 1, 0, 0, 0);

enter image description here

Why these numbers?? I have created a dynamic ubo and two objects, one for view and proj and the other for model.

Here I update the objects:

Render::UniformBufferObject ubo{};
        Render::UniformBufferObject2 ubo2{};
        

        ubo2.model = &model_transform.GetWorldMatrix();
        
        ubo.view =  &EditorCamera_transform.GetWorldMatrix().Inverse();
          
        ubo.proj = &current_camera->GetProjectionMatrix();

        // map memory without a staging buffer
        void* data;
        auto memory = uniform_buffer->get_ubo_memory();
        Render::VulkanMemoryAllocator::get_instance()->map_buffer_allocation(memory[current_image], &data);
        memcpy(data, &ubo, sizeof(ubo));
        memcpy(data, &ubo2, sizeof(ubo2));
        Render::VulkanMemoryAllocator::get_instance()->unmap_buffer_allocation(memory[current_image]); 

Here binding and draw command:

std::array<uint32_t, 2> dynamicOffsets =
            { i * static_cast<uint32_t>(Render::StandardUniformBuffer::required_alignment(sizeof(Maths::Matrix4)*2)),
              i* static_cast<uint32_t>(Render::StandardUniformBuffer::required_alignment(sizeof(Maths::Matrix4)))
            };

            cmd.bindDescriptorSets(
                vk::PipelineBindPoint::eGraphics,
                *pipeline->get_pipeline_layout(),
                0,
                2,
                descriptor_set->get_descriptor_sets()->data(),
                2,
                dynamicOffsets.data());

            cmd.drawIndexed(static_cast<uint32_t>(index_buffer->get_primative_indices_size()), 1, 0, 0, 0);
Source Link

Vulkan dynamic UBO weird numbers

enter image description here

Why these numbers ?? I have created a dynamic ubo and two objects , one for view and proj and the other for model.

Here I update the objects:

Render::UniformBufferObject ubo{};
        Render::UniformBufferObject2 ubo2{};
        

        ubo2.model = &model_transform.GetWorldMatrix();
        
        ubo.view =  &EditorCamera_transform.GetWorldMatrix().Inverse();
          
        ubo.proj = &current_camera->GetProjectionMatrix();

        // map memory without a staging buffer
        void* data;
        auto memory = uniform_buffer->get_ubo_memory();
        Render::VulkanMemoryAllocator::get_instance()->map_buffer_allocation(memory[current_image], &data);
        memcpy(data, &ubo, sizeof(ubo));
        memcpy(data, &ubo2, sizeof(ubo2));
        Render::VulkanMemoryAllocator::get_instance()->unmap_buffer_allocation(memory[current_image]); 

Here binding and draw command:

std::array<uint32_t, 2> dynamicOffsets =
            { i * static_cast<uint32_t>(Render::StandardUniformBuffer::required_alignment(sizeof(Maths::Matrix4)*2)),
              i* static_cast<uint32_t>(Render::StandardUniformBuffer::required_alignment(sizeof(Maths::Matrix4)))
            };

            cmd.bindDescriptorSets(
                vk::PipelineBindPoint::eGraphics,
                *pipeline->get_pipeline_layout(),
                0,
                2,
                descriptor_set->get_descriptor_sets()->data(),
                2,
                dynamicOffsets.data());

            cmd.drawIndexed(static_cast<uint32_t>(index_buffer->get_primative_indices_size()), 1, 0, 0, 0);