Skip to content

Add vk::transition_image_layout utility function #31

@SpinnerX

Description

@SpinnerX

Currently to transition image layouts has to be done manually through vk::sample_image::memory_barrier.

It would be convenient to have utility functions to perform these specific operations. These are utility because if users want to either transition image layouts they can OR they can define their own utility functions that does the transition image layouts.

As this is not the responsibility of the vk::sample_image to perform this operation.

Defining the utility function

As for the implementation, this is how I would see it be done for implementing the transition imgae layout.

Note

Prototype implementation. Does work. Most likely to change.

void transition_image_layout(VkDevice p_device, vk::sample_image& p_image, VkFormat p_format, VkImageLayout p_old, VkImageLayout p_new) {
        vk::command_params copy_command_params = {
            .levels = vk::command_levels::primary,
            .queue_index = 0,
            .flags = vk::command_pool_flags::reset,
        };
        vk::command_buffer temp_command_buffer = vk::command_buffer(p_device, copy_command_params);
        
        temp_command_buffer.begin(vk::command_usage::one_time_submit);

        p_image.memory_barrier(temp_command_buffer, p_format, p_old, p_new);

        temp_command_buffer.end();

        VkCommandBuffer handle = temp_command_buffer;
        VkSubmitInfo submit_info = {
            .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
            .commandBufferCount = 1,
            .pCommandBuffers = &handle,
        };

        uint32_t queue_family_index = 0;
        uint32_t queue_index = 0;
        VkQueue temp_graphics_queue;
        vkGetDeviceQueue(p_device, queue_family_index, queue_index, &temp_graphics_queue);

        vkQueueSubmit(temp_graphics_queue, 1, &submit_info, nullptr);
        vkQueueWaitIdle(temp_graphics_queue);

        temp_command_buffer.destroy();
    }

API Usage

transition_image_layout(logical_device, m_viewport_image, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);

Metadata

Metadata

Assignees

No one assigned

    Labels

    🚪entryTasks suitable for new contributors to the codebase. Easy to getting started.

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions