> For the complete documentation index, see [llms.txt](https://okzkx.gitbook.io/blogs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://okzkx.gitbook.io/blogs/game-tech/engine/gpu/vulkan/vulkan-objects.md).

# Vulkan 对象

## Concept

![img](https://image-1253155090.cos.ap-nanjing.myqcloud.com/202302230926364.png)

![img](https://image-1253155090.cos.ap-nanjing.myqcloud.com/202302230926301.jpg)

## 大概使用方式

* color\_attachment
  * desc
  * ref
* swap chain
  * swapchain helper
    * -> instance , device
  * swapchain khr
    * images
* image view
  * image -> swapchain khr images
* render pass
  * attachments
    * 1 -> color\_attachment -> subpass attachment(0)
    * 2 -> depth\_attachment -> subpass attachment(1)
  * subpass
    * -> color\_attachments -> color\_attachment\_references -> attachment(0)
    * -> depth\_stencil\_attachment -> depth\_stencil\_attachment\_references -> attachment(1)
  * dependencies (Subpass Dependency))
* Frame Buffer
  * render pass -> render pass
  * attachments -> \[color image view , depth image view]
* Graphic pipeline
  * shader stages
    * shader modules
  * -> Render pass
  * descripter set layout -> pipeline layout
* Command Buffer
  * begin render pass
    * -> render passs
    * -> frame buffer
  * bind pipeline -> graphic pipeline
  * vertex buffer
  * index buffer
  * descriptor sets
* descriptor sets (per image)
  * -> descriptor set layout
  * write descriptor set -> uniform buffer
  * pipeline\_layout
* uniform buffer
  * uniform buffer memory
    * ubo

Command buffer -> begin render passes -> frame buffer -> image view -> image (从 Swapchain 中获取或自己创建)

Command buffer -> begin render passes -> render passs -> attachments （attachments 需要和 framebuffer 格式一致）

Create Instance

Validation layer

* 从 entry 得到这个机器可以使用的 validation layers
* 检测是否具有需要的 validation layer
* 一般在 Debug build 里会开启 VK\_LAYER\_KHRONOS\_validation 用来检测是否具有 vulkan sdk

Pick phsical device

Queue Family

* 遍历所有的 Queue Family
* 找到具有 graphics 和 present 的 Queue Family Index

Device Extension

* instance 遍历每个 physical\_device 具有的所有所有拓展
* 检测每个 physical\_device 的拓展是否包含有需要的，当前只有一个 Swapchian.name
* 选择具有所需要的拓展的 physical\_device

Create Device

创建 device，需要启用

* Queue Family Index
* 所需要的 layer
* 所需要的 Extension
* 所需要的 feature，现在只有各向异性采样

使用 QueueFamily 创建对应的 Graphics Present WWqueu

* Entry
* Instance
* Swapchain
* Framebuffer
* ImageView
* Validation Layer
* Queue, Queue family
* Command pool, Command buffer
* Physical Device

Instance 添加 Validation layer 验证层

Physical Device 设备选择，需要检查，

1. queue families 是否具有 graphic 和 present 两种
2. 程序自定义的拓展字符串，是不是全部都支持
3. 对于 swapchian 的支持：获取设备的 surface capabilities 表面能力，surface format, present mode 都是有值的


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://okzkx.gitbook.io/blogs/game-tech/engine/gpu/vulkan/vulkan-objects.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
