Skip to content

Commit a85b0dc

Browse files
committed
dev merge to main
2 parents a55c830 + d8b3742 commit a85b0dc

File tree

4 files changed

+179
-3
lines changed

4 files changed

+179
-3
lines changed

source/Application/VulkanTriangle.rst

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Vulkan 三角形
77

88
* 2024/11/7 增加该文章
99
* 2024/11/8 更新该文章
10+
* 2024/11/15 更新该文章。增加编译流程说明和 ``MacOS`` 适配。
1011

1112
.. sidebar::
1213

@@ -41,6 +42,39 @@ Vulkan 三角形
4142

4243
* ``Windows``
4344
* ``Linux``
45+
* ``MacOS``
46+
47+
0. 配置环境
48+
49+
.. tab-set::
50+
51+
.. tab-item:: Windows
52+
53+
``Visual Studio``
54+
55+
.. tab-item:: Linux
56+
57+
命令行中执行如下指令:
58+
59+
.. code-block:: console
60+
61+
sudo apt-get install libxrandr-dev
62+
sudo apt-get install libxinerama-dev
63+
sudo apt-get install libxcursor-dev
64+
sudo apt-get install libxi-dev
65+
sudo apt-get install freeglut3-dev
66+
67+
.. tab-item:: MacOS
68+
69+
命令行中执行如下指令:
70+
71+
.. code-block:: console
72+
73+
brew install libxrandr
74+
brew install libxinerama
75+
brew install libxcursor
76+
brew install libxi
77+
brew install freeglut
4478
4579
1. 下载并解压
4680
2. 在同级目录下创建 ``build`` 文件夹
@@ -59,14 +93,22 @@ Vulkan 三角形
5993

6094
.. tab-set::
6195

62-
.. tab-item:: Visual Studio
96+
.. tab-item:: Windows
6397

64-
打开 ``build`` 文件夹下的 ``.sln`` 文件,编译执行即可。
98+
使用 ``Visual Studio`` 打开 ``build`` 文件夹下的 ``.sln`` 文件,编译执行即可。
6599

66100
.. tab-item:: Linux
67101

68102
命令行中执行如下指令即可:
69103

70104
.. code-block:: console
71105
72-
make
106+
make
107+
108+
.. tab-item:: MacOS
109+
110+
命令行中执行如下指令即可:
111+
112+
.. code-block:: console
113+
114+
cmake --build .

source/Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
此更新日志为纵览更新,对于具体文章的更新位于每个文章的开头的 `更新记录` 中。
55
```
66

7+
## 2024/11/15
8+
9+
>* 更新`Vulkan 三角形`工程文档
10+
711
## 2024/11/8
812

913
>* 更新`Vulkan 三角形`工程文档

source/Memory.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,11 @@ VkMemoryPropertyFlagBits
927927

928928
具体如何进行内存同步将会在之后的章节进行讲解。
929929

930+
..
931+
Vulkan 标准要求
932+
* 必须有一个内存类型同时包含 HOST_VISIBLE 和 HOST_COHERENT
933+
* 必须有一个内存类型包含 DEVICE_LOCAL
934+
930935
惰性内存
931936
^^^^^^^^^^^^^^^^^^^^
932937

source/memo.rst

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
备忘录
2+
=========
3+
4+
``vkGetPhysicalDeviceMemoryProperties``
5+
6+
* 必须有一个内存类型同时包含 HOST_VISIBLE 和 HOST_COHERENT
7+
* 必须有一个内存类型包含 DEVICE_LOCAL
8+
9+
---
10+
11+
``VkMemoryHeapFlagBits`` 除了 ``Vulkan 1.0`` 的 ``DEVICE_LOCAL`` 外,还有一个 ``MULTI_INSTANCE`` ,表示:一个逻辑设备 ``VkDevice`` 代表多个物理设备,每一个物理设备的堆内存都会有一个这个 ``instance`` ,默认情况下,在这样的其中一个设备内存堆上分配,将会在每一个设备堆上都进行相同的操作。
12+
13+
---
14+
15+
memory_properties
16+
17+
* VK_MEMORY_PROPERTY_HOST_CACHED_BIT 缓存是存在 ``host`` 端的,非缓存内存访问比缓存内存慢。缓存内存速度 > 费缓存。然而非缓存内存 ``总是`` ``host coherent`` (同步)的
18+
* VK_MEMORY_PROPERTY_LAZILY_BIT 表示只有 物理设备 可以访问该内存。拥有了该类型的内存 ``不可能`` 被 ``host`` 端访问了(HOST_VISIBLE、HOST_COHERENT 和 HOST_CACHED不可能出现了)。
19+
* VK_MEMORY_PROPERTY_PROTECTED_BIT 表示只有 物理设备 可以访问该内存,并且只有 保护队列 可操作该内存。拥有了该类型的内存 ``不可能`` 被 ``host`` 端访问了(HOST_VISIBLE、HOST_COHERENT 和 HOST_CACHED不可能出现了)。
20+
21+
---
22+
23+
BufferView
24+
25+
.. code:: c++
26+
27+
// Provided by VK_VERSION_1_0
28+
typedef struct VkBufferViewCreateInfo {
29+
VkStructureType sType;
30+
const void* pNext;
31+
VkBufferViewCreateFlags flags;
32+
VkBuffer buffer;
33+
VkFormat format;
34+
VkDeviceSize offset;
35+
VkDeviceSize range;
36+
} VkBufferViewCreateInfo;
37+
38+
``VkBuffer`` 必须创建于 ``VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT`` 和 ``VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT`` 最少是这两个中的一个,要么就两个都是。
39+
40+
``buffer`` 包含 ``VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT`` 创建的话, ``format`` 的 ``feature`` 必须包含 ``VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT`` ( ``vkGetPhysicalDeviceFormatProperties(...) VkFormatProperties::bufferFeatures`` )
41+
``buffer`` 包含 ``VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT`` 创建的话, ``format`` 的 ``feature`` 必须包含 ``VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT`` ( ``vkGetPhysicalDeviceFormatProperties(...) VkFormatProperties::bufferFeatures`` )
42+
43+
* 如果 ``buffer`` 不是 ``稀疏`` 资源的话,则他需要完全连续的绑定到一个单一的 ``VkDeviceMemory`` 对象上。
44+
* 如果 ``texelBufferAlignment`` 特性没有激活的话, ``offset`` 必须是 ``VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment`` 的倍数。
45+
* 如果 ``texelBufferAlignment`` 特性激活,并且 ``buffer`` 中包含 ``VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT`` 的话,
46+
``offset`` 必须是 ``VkPhysicalDeviceLimits::storageTexelBufferOffsetAlignmentBytes`` 或 在 ``VkPhysicalDeviceTexelBufferAlignmentProperties::storageTexelBufferOffsetSingleTexelAlignment`` 为 ``VK_TRUE`` 的条件下,
47+
格式要求的 ``texel`` 大小中的较小值。如果 ``texel`` 的大小是 ``3 byte`` 倍数,则使用格式中单组件(通道?)的大小?
48+
49+
* 如果 ``texelBufferAlignment`` 特性激活,并且 ``buffer`` 中包含 ``VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT`` 的话,
50+
``offset`` 必须是 ``VkPhysicalDeviceLimits::uniformTexelBufferOffsetAlignmentBytes`` 或 在 ``VkPhysicalDeviceTexelBufferAlignmentProperties::uniformTexelBufferOffsetSingleTexelAlignment`` 为 ``VK_TRUE`` 的条件下,
51+
格式要求的 ``texel`` 大小中的较小值。如果 ``texel`` 的大小是 ``3 byte`` 倍数,则使用格式中单组件(通道?)的大小?
52+
53+
BufferView 文档阅读完毕
54+
55+
.. code-block:: glsl
56+
57+
// Texture Buffer(Uniform Texel Buffers)
58+
layout(set=m, binding=n) uniform textureBuffer myUniformTexelBuffer;
59+
60+
// Texture Buffer(Storage Texel Buffers)
61+
layout(set=m, binding=n, r32f) uniform imageBuffer myStorageTexelBuffer;
62+
63+
---
64+
65+
VkImageCreateInfo::arrayLayers
66+
67+
``RTX 3070`` 显卡中 ``VkPhysicalDeviceLimits::maxImageArrayLayers`` 为 ``2048`` (标准要求最小为 ``256`` ,如果满足 ``Roadmap 2022`` 则最小为 ``2048``)
68+
69+
* ``arrayLayers`` 必须要大于 ``0`` (不能为 ``0`` )
70+
* ``arrayLayers`` 必须小于等于 ``imageCreateMaxArrayLayers``
71+
* 如果 ``imageType`` 是 ``3D`` , ``arrayLayers`` 必须是 ``1``
72+
73+
如果 ``tiling`` 是 ``LINEAR`` 的话,有如下要求:
74+
75+
* ``imageType`` 是 ``2D``
76+
* ``format`` 不能是 ``depth/stencil`` 格式
77+
* ``mipLevel`` 是 ``1``
78+
* ``arrayLayers`` 是 ``1``
79+
* ``samples`` 是 ``COUNT_1_BIT``
80+
* ``usage`` 只能是 ``TRANSFER_SRC_BIT`` 和/或 ``TRANSFER_DST_BIT``
81+
82+
如果格式是 ``Y'CBCR`` ,有如下要求:
83+
84+
* ``imageType`` 是 ``2D``
85+
* ``mipLevel`` 是 ``1``
86+
* ``arrayLayers`` 是 ``1`` ,要么就是 ``VkImageFormatProperties::maxArrayLayers``
87+
* ``samples`` 是 ``COUNT_1_BIT``
88+
89+
如果 ``flags`` 包含 ``VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT`` ,有如下要求:
90+
91+
* ``mipLevels`` 必须是 ``1``
92+
* ``arrayLayers`` 必须是 ``1``
93+
* ``imageType`` 必须是 ``VK_IMAGE_TYPE_2D``
94+
* ``imageCreateMaybeLinear`` 必须是 ``VK_FALSE``
95+
96+
---
97+
98+
VkPhysicalDeviceLiits::maxFramebufferWidth
99+
VkPhysicalDeviceLiits::maxFramebufferHeight
100+
101+
---
102+
103+
# VkImageView
104+
105+
View 的 usage 是继承自 Image 的:
106+
107+
* 如果 View 设置了 ``VkImageViewUsageCreateInfo`` 的话(pNext),可以覆写该 View 的 usage ,但必须是 image 的 usage 的子集。
108+
* 如果 image 是 depth-stencil 格式,并且使用 ``VkImageStencilUsageCreateInfo`` 创建的 image,View 的 usage 是依据 ``subresource.aspectMask`` 确定:
109+
* 如果 ``aspectMask`` 只包含 ``VK_IMAGE_ASPECT_STENCILE_BIT`` ,这意味着 usage 使用 ``VkImageStencilUsageCreateInfo::stencilUsage`` 的配置
110+
* 如果 ``aspectMask`` 只包含 ``VK_IMAGE_ASPECT_DEPTH_BIT`` ,这意味着 usage 使用 ``VkImageCreateInfo::usage`` 的配置
111+
* 如果 ``aspectMask`` 中上述两个都包含,这意味着 usage 使用 ``VkImageCreateInfo::usage`` 和 ``VkImageStencilUsageCreateInfo::stencilUsage``
112+
113+
如果 image 创建的时候指定了 ``VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT`` ,并且 ``format`` 不是 ``multi-planar`` 的话, view 的 format 可以和 image 的 format 不同,
114+
此外如果 image 没有使用 ``VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT`` 创建的话,view 的 format 可以和 image 的 format 不同,但需要 ``兼容`` 。
115+
116+
* ``VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT`` 表示 image 使用的压缩格式,并且该压缩格式可在 View 端进行解压缩
117+
118+
相互兼容格式的 View 将会在 纹素坐标-内存地址 之间具有相同的映射,这仅仅是二进制解释样式发生了改变。
119+
120+
如果 image 使用 ``VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT`` 创建的话, View 的 format 必须与 image 的 format 相兼容,要么 view 的 format 必须是压缩格式,且必须是 size-comatible (大小相兼容的)。在这种情况下,
121+
获取到的 view 的 texel 维度 = 四舍五入((选择的 mip 等级 / 压缩的 texel 块大小))
122+
123+
## VkImageView ComponentMap
124+
125+
如果 view 用于 storage image/ input attachment / framebuffer attachment 和与 Y'CbCr 采样器相结合的 View,必须使用 一致性排列 (identify swizzle,也就是 ``VkComponentSwizzle::VK_COMPONENT_SWIZZLE_IDENTITY``)。

0 commit comments

Comments
 (0)