Aqoole_Hateenaの技術日記

vulkan+raytraceで色々描いてます

ImageViewの作成について

vkCreateImageView

ImageViewはvkCreateImageView()で作成できるが、作成にはVkImageViewCreateInfo構造体に必要な情報をインプットする必要がある。
vkCreateImageView(3)

VkImageViewCreateInfo


VkImageViewCreateInfo - Structure specifying parameters of a newly created image view

// Provided by VK_VERSION_1_0
typedef struct VkImageViewCreateInfo {
    VkStructureType            sType;
    const void*                pNext;
    VkImageViewCreateFlags     flags;
    VkImage                    image;
    VkImageViewType            viewType;
    VkFormat                   format;
    VkComponentMapping         components;
    VkImageSubresourceRange    subresourceRange;
} VkImageViewCreateInfo;

  • components is a VkComponentMapping structure specifying a remapping of color components (or of depth or stencil components after they have been converted into color components).

VkImageViewCreateInfo(3)

componentsについて、説明文にremappingとあるのでimageのRGBAの並びを変更することができる。

VkComponentMapping


VkComponentMapping - Structure specifying a color component mapping

// Provided by VK_VERSION_1_0
typedef struct VkComponentMapping {
    VkComponentSwizzle    r;
    VkComponentSwizzle    g;
    VkComponentSwizzle    b;
    VkComponentSwizzle    a;
} VkComponentMapping;

VkComponentMapping(3)
構造体をたらい回しにされているが、VkComponentSwizzleのメンバにて要素を指定する。

VkComponentSwizzle


VkComponentSwizzle - Specify how a component is swizzled

// Provided by VK_VERSION_1_0
typedef enum VkComponentSwizzle {
    VK_COMPONENT_SWIZZLE_IDENTITY = 0,
    VK_COMPONENT_SWIZZLE_ZERO = 1,
    VK_COMPONENT_SWIZZLE_ONE = 2,
    VK_COMPONENT_SWIZZLE_R = 3,
    VK_COMPONENT_SWIZZLE_G = 4,
    VK_COMPONENT_SWIZZLE_B = 5,
    VK_COMPONENT_SWIZZLE_A = 6,
} VkComponentSwizzle;

VkComponentSwizzle(3)
swizzleについて、weblioで意味を調べると


To permute bits, or elements of a vector.
ビットまたはベクトルの要素を並べ替えます。

ということなので、RGBA要素の入れ替えについてのパラメータ。
また、VK_COMPONENT_SWIZZLE_IDENTITYは同じ位置のパラメータを指定する。つまり 各ComponentにVK_COMPONENT_SWIZZLE_IDENTITYを指定した場合、以下の値が指定される。

Component Identity Mapping
components.r VK_COMPONENT_SWIZZLE_R
components.g VK_COMPONENT_SWIZZLE_G
components.b VK_COMPONENT_SWIZZLE_B
components.a VK_COMPONENT_SWIZZLE_A