Vulkan Graphics pipeline basics

2025-05-15 · 约 5 分钟 · 标签: Vulkan , Rendering Pipeline , GPU Programming , Shader Stages , Computer Graphics
![Toronto](/static/images/vulkan-002-pipeline-basic.png)

Vulkan Graphics pipeline basics

Input Assembler fixed-function stages

  • Collects raw vertex data from specified buffers
  • Optionally uses an index buffer to reuse elements without duplication

Vertex Shader programmable stages

  • Executed for every vertex
  • Performs:
    • Model space → Screen space transformations
    • Passes per-vertex data downstream

Tessellation Shaders (Optional) programmable stages

  • Subdivides geometry based on rules
  • Common uses:
    • Enhancing surface detail (e.g. brick walls, stairs)
    • Dynamic LOD adjustments

Geometry Shader (Optional) programmable stages

  • Processes each primitive (triangle/line/point)
  • Capabilities:
    • Discard primitives
    • Emit additional primitives
  • Performance note:
    • Generally inefficient on discrete GPUs
    • Better supported on Intel integrated graphics

Rasterization fixed-function stages

  • Discretizes primitives into fragments (potential pixels)
  • Key operations:
    • Viewport culling (discards off-screen fragments)
    • Attribute interpolation (across fragments)
    • Early depth/stencil testing

Fragment Shader programmable stages

  • Executed for every surviving fragment
  • Determines:
    • Framebuffer write targets
    • Final color/depth values
  • Uses interpolated vertex data:
    • Texture coordinates
    • Normals (for lighting)

Color Blending fixed-function stages

  • Combines fragments mapping to same framebuffer pixel
  • Blend modes:
    • Overwrite
    • Additive
    • Alpha blending
    • Custom programmable blending

Attention: 在Vulkan中,图形管线几乎完全不可变,所以如果你想更改着色器、绑定不同的帧缓冲区或改变混合函数,就必须从头重新创建管线。这样做的缺点是,你必须创建多个管线,来代表你在渲染操作中想要使用的所有不同状态组合。然而,由于在管线中要进行的所有操作都是预先可知的,驱动程序能够对其进行更优的优化。

评论
评论功能尚未配置:在 GitHub 仓库开启 Discussions,并按项目 README 里的步骤填好 src/consts.ts 即可启用(基于 Giscus,评论需要 GitHub 账号)。