Create an image view

In order to use textures within a shader or as a render target, haiku provides hk_view_t and associated utility functions in haiku/graphics.h.

hk_view_t is used for bindgroups and render targets while hk_image_t is used in barriers, copy, resolve and blit commands.

hk_image_t my_texture = hkgfx_image_create(device, &(hk_gfx_image_desc){
    .type = HK_IMAGE_TYPE_2D,
    .extent = {.width = texture_width, .height = texture_height},
    .levels = 1,
    .usage_flags  = HK_IMAGE_USAGE_TRANSFER_DST_BIT | HK_IMAGE_USAGE_SAMPLED_BIT,
    .memory_type  = HK_MEMORY_TYPE_GPU_ONLY
});
/* [...] */
hk_view_t my_texture_view = hkgfx_view_create(device, &(hk_gfx_view_desc){
    .src_image      = my_texture_view,
    .type           = HK_IMAGE_TYPE_2D,
    .aspect_flags   = HK_IMAGE_ASPECT_COLOR_BIT, 
});

Usecase: bindgroup

    hk_bindgroup_t mybindgroup = hkgfx_bindgroup_create(device,&(hk_gfx_bindgroup_desc){
        .layout = my_pipeline_layout,
        .images = {
            {.image_view = my_texture_view, .sampler = my_texture_sampler }
        }
    });

Usecase: render target

hkgfx_context_render_begin(rendering_context, &(hk_gfx_render_targets_params){
    .layer_count = 1,
    .color_count = 1,
    .render_area = { .extent = {app_frame_width, app_frame_height} },
    .color_attachments = { 
        {.target_render = my_texture_view, .clear_color = {.value_f32 = {0.2f,0.2f,0.2f,1.f}}} 
    },
});

hkgfx_context_set_pipeline(rendering_context, mypipeline);
hkgfx_context_set_bindings(rendering_context, mypipeline, 0, mybindgroup);
hkgfx_context_draw(rendering_context, 3, 1, 0, 0);
hkgfx_context_render_end(rendering_context);