Vertex Post-processing Stage
記事にあるGraphics pipeline diagramのVertex Post-processing stageでは、いわゆるClip and Cullの処理が行われる。
aqoole-hateena.hatenablog.com
Clip and Cullとはworld座標から画面に表示される範囲を抽出することである。
座標変換
Vertex Post-processing StageではClip SpaceからScreen Spaceへの変換を行う。Clip SpaceはNormal Device Coordinatesともよばれ、Screen SpaceはWindow Coordinatesともよばれる。

出典:LearnOpenGL - Coordinate Systems
※図はOpenGLのもののため、y軸の向きが逆向きになっている。
Vertex Post-processingの処理はVkPipelineViewportStateCreateInfoに記述する。
VkPipelineViewportStateCreateInfo
VkPipelineViewportStateCreateInfo - Structure specifying parameters of a newly created pipeline viewport state
// Provided by VK_VERSION_1_0 typedef struct VkPipelineViewportStateCreateInfo { VkStructureType sType; const void* pNext; VkPipelineViewportStateCreateFlags flags; uint32_t viewportCount; const VkViewport* pViewports; uint32_t scissorCount; const VkRect2D* pScissors; } VkPipelineViewportStateCreateInfo;
- pViewports is a pointer to an array of VkViewport structures, defining the viewport transforms. If the viewport state is dynamic, this member is ignored.
- pScissors is a pointer to an array of VkRect2D structures defining the rectangular bounds of the scissor for the corresponding viewport. If the scissor state is dynamic, this member is ignored.
VkViewportとVkRect2Dの情報が必要。VkViewportは座標変換の内のviewport transformsに必要で、VkRect2Dはviewportの領域の境界を指定するのに必要。
VkViewport
VkViewport - Structure specifying a viewport
// Provided by VK_VERSION_1_0 typedef struct VkViewport { float x; float y; float width; float height; float minDepth; float maxDepth; } VkViewport;
- x and y are the viewport’s upper left corner (x,y).
- width and height are the viewport’s width and height, respectively.
- minDepth and maxDepth are the depth range for the viewport.
window coordinatesは通常、左上を(0, 0)とし、pixelの数だけwidthとheightをもつ座標系である。
swapchainで作成しているwindow全体をviewportとする場合の具体例
VkViewport viewports{ .x = 0, .y = 0, .width = (float)displaySize.width, .height = (float)displaySize.height, .minDepth = 0.0f, .maxDepth = 1.0f, };
VkRect2D
VkRect2D - Structure specifying a two-dimensional subregion.
Rectangles are used to describe a specified rectangular region of pixels within an image or framebuffer.
// Provided by VK_VERSION_1_0 typedef struct VkRect2D { VkOffset2D offset; VkExtent2D extent; } VkRect2D;
- offset is a VkOffset2D specifying the rectangle offset.
- extent is a VkExtent2D specifying the rectangle extent.
offsetとextentをそれぞれ構造体で定義する。
VkOffset2D
// Provided by VK_VERSION_1_0 typedef struct VkOffset2D { int32_t x; int32_t y; } VkOffset2D;
- x is the x offset.
- y is the y offset.
VkExtent2D
// Provided by VK_VERSION_1_0 typedef struct VkExtent2D { uint32_t width; uint32_t height; } VkExtent2D;
- width is the width of the extent.
- height is the height of the extent.
extentとは「広さ、範囲」の意味。
extentの意味・使い方・読み方 | Weblio英和辞書