Vulkan规范:第一章

部署运行你感兴趣的模型镜像

1. 简介

本章,除了“术语”、“规范化参考”小节,都是介绍性的信息。

这份文档,被称为“Vulkan 规范”或者此后仅称为“规范”,描述了Vulkan图形系统: 它是什么,它怎么行动,和实现它需要做什么。我们假设读者对计算机图形学有基础的 了解。这表示要对计算机图形学算法、术语,和现代化的GPU(Graphic Processing Units)熟悉。

官方版本的规范在Vulkan注册机构可获取,在下面的链接中

1.1. Vulkan图形系统是什么?

Vulkan是一个图形和计算硬件的API(Application Programming Interface)。 这个API由很多命令组成,它们允许程序员指定着色器程序,计算内核,对象和操作 产生高质量的图像,特别是三维对象的彩色图像。

1.1.1. 程序员的视角看Vulkan

对程序员来讲,Vulkan是一些命令的集合,允许内核或者着色器,和shader执行的外部 Vulkan aspect控制,使用着色器程序或者着色器和数据。 通常,数据是指二维或者三维几何物体和纹理图像,着色器和内核控制数据的处理, 几何物体的光栅化,光栅化产生的光照和阴影的片段,及最终把几何对象渲染到帧缓冲区。

一个典型的Vulkan程序以调用系统函数打开窗口或者准备程序绘制显示的设备为开始。 然后,调用命令打开队列,并向其提交命令缓冲区。 命令缓冲区包含一系列命令,它们将会被底层的硬件执行。 应用程序能够做到:分配设备内存,关联内存和资源,从命令缓冲区中引用这些资源。 绘制命令可调用应用程序的着色器程序,然而使用资源里的数据并产生图像。 为了展示结果图像,一些平台相关的命令需要把结果图像转移到显示设备或者窗口。

1.1.2. 实现者的角度看Vulkan

对于实现者,Vulkan是一系列命令的集合,它允许构造命令缓冲区并提交到设备。 现代化的设备几乎对所有Vulkan操作都加速了,把数据和帧缓冲区存储在高速内存, 在专用的GPU上执行着色器。 实现者的任务是在主机端提供软件lib,它实现了Vulkan API,把每一个Vulkan命令适当的 映射到图形硬件以利用物理设备的能力。

1.1.3. 我们的视角看Vulkan

我们把Vulkan看作拥有绘制操作可调用的可编程阶段和状态驱动固定阶段的管线。 我们期待这个模型可产生一个规范,满足程序员和Vulkan实现者的需要。 然而,它并不提供如何实现的模型。Vulkan实现必须产生符合这些特定方法产生的结果,但是, 可以执行比指定方法更加高效率的计算方法。

1.2. Bug报告

Issues with and bug reports on the Vulkan Specification and the API Registry can be filed in the Khronos Vulkan GitHub repository, located at URL

Please tag issues with appropriate labels, such as “Specification”, “Ref Pages” or “Registry”, to help us triage and assign them appropriately. Unfortunately, GitHub does not currently let users who do not have write access to the repository set GitHub labels on issues. In the meantime, they can be added to the title line of the issue set in brackets, e.g. ''[Specification]''.

1.3. 术语

The key words mustrequiredshall shouldrecommendmay, and optional in this document are to be interpreted as described in RFC 2119:

must

When used alone, this word, or the term required, means that the definition is an absolute requirement of the specification. When followed by not (“must not” ), the phrase means that the definition is an absolute prohibition of the specification.

should

When used alone, this word, or the adjective recommended, means that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course. When followed by not (“should not”), the phrase means that there may exist valid reasons in particular circumstances when the particular behavior is acceptable or even useful, but the full implications shouldbe understood and the case carefully weighed before implementing any behavior described with this label.

may

This word, or the adjective optional, means that an item is truly optional. One vendor may choose to include the item because a particular marketplace requires it or because the vendor feels that it enhances the product while another vendor may omit the same item. An implementation which does not include a particular option must be prepared to interoperate with another implementation which does include the option, though perhaps with reduced functionality. In the same vein an implementation which does include a particular option must be prepared to interoperate with another implementation which does not include the option (except, of course, for the feature the option provides).

The additional terms can and cannot are to be interpreted as follows:

can

This word means that the particular behavior described is a valid choice for an application, and is never used to refer to implementation behavior.

cannot

This word means that the particular behavior described is not achievable by an application. For example, an entry point does not exist, or shader code is not capable of expressing an operation.

Note

There is an important distinction between cannot and must not, as used in this Specification. Cannotmeans something the application literally is unable to express or accomplish through the API, while must not means something that the application is capable of expressing through the API, but that the consequences of doing so are undefined and potentially unrecoverable for the implementation.

editing-note

TODO (Jon) - We might need to augment the RFC 2119 definition of must not to include some of the previous note, since at present it is defined solely in terms of implementation behavior. See Gitlab issue #9.

1.4. Normative References

Normative references are references to external documents or resources to which implementers of Vulkan must comply.

IEEE Standard for Floating-Point Arithmetic, IEEE Std 754-2008, http://dx.doi.org/10.1109/IEEESTD.2008.4610935, August, 2008.

A. Garrard, Khronos Data Format Specification, version 1.1,https://www.khronos.org/registry/dataformat/specs/1.1/dataformat.1.1.html, June, 2016.

J. Kessenich, SPIR-V Extended Instructions for GLSL, Version 1.00https://www.khronos.org/registry/spir-v/, February 10, 2016.

J. Kessenich and B. Ouriel, The Khronos SPIR-V Specification, Version 1.00https://www.khronos.org/registry/spir-v/, February 10, 2016.

J. Leech and T. Hector, Vulkan Documentation and Extensions: Procedures and Conventions,https://www.khronos.org/registry/vulkan/, July 11, 2016

您可能感兴趣的与本文相关的镜像

Wan2.2-I2V-A14B

Wan2.2-I2V-A14B

图生视频
Wan2.2

Wan2.2是由通义万相开源高效文本到视频生成模型,是有​50亿参数的轻量级视频生成模型,专为快速内容创作优化。支持480P视频生成,具备优秀的时序连贯性和运动推理能力

<think>我们正在处理一个关于Vulkan中YCbCr采样的技术问题。用户要求教程或实现指南。 由于这是一个具体的技术主题,我们需要提供关于如何在Vulkan中设置和使用YCbCr采样的指导。 关键点: 1. Vulkan中YCbCr采样的核心是使用`VkSamplerYcbcrConversion`对象。 2. 这需要VK_KHR_sampler_ycbcr_conversion扩展(或Vulkan 1.1,其中该扩展成为核心的一部分)。 3. 步骤包括创建Ycbcr转换对象,创建使用该转换的采样器,然后使用该采样器对多平面图像进行采样。 我们将分步骤解释,并注意代码示例(伪代码或类似C++的代码,因为Vulkan是C API)。 注意:由于我们无法提供完整的教程(篇幅限制),但可以给出关键步骤和概念。 步骤: 1. 检查设备支持:确保设备支持所需的扩展(VK_KHR_sampler_ycbcr_conversion)和特性。 2. 创建VkSamplerYcbcrConversion对象:需要填充VkSamplerYcbcrConversionCreateInfo结构。 3. 创建使用Ycbcr转换的采样器:在VkSamplerCreateInfo中指定pNext链,指向VkSamplerYcbcrConversionInfo。 4. 创建多平面图像(VkImage)和图像视图(VkImageView):需要将图像创建为多平面格式(如VK_FORMAT_G8_B8R8_2PLANE_420_UNORM)。 5. 在描述符集中使用该采样器和图像视图,然后在着色器中采样。 着色器方面:通常使用一个sampler2D(如果使用组合采样器)来采样,但要注意,YCbCr转换后的采样结果已经是RGB(或类似)了。 由于用户要求教程或实现指南,我们应尽可能提供指导性内容。 注意:Vulkan的YCbCr支持非常复杂,涉及硬件支持,因此需要谨慎处理。 我们将按照以下结构组织回答: 1. 简介 2. 前提条件(扩展和特性) 3. 创建Ycbcr转换对象 4. 创建采样器 5. 创建多平面图像和图像视图 6. 描述符设置和采样 7. 清理 然后生成相关问题。 由于是中文回答,所有内容使用中文。 注意:在回答中,我们可能会引用一些外部资源(如Vulkan规范),但因为我们没有具体的引用源,所以将避免添加引用标识(除非我们确实引用了某个特定部分)。但是,根据系统指令,我们应自然地添加引用标识。由于没有提供引用,我们可能不添加,或者如果提到常见知识(如Vulkan规范)则添加通用引用。 由于没有具体的引用源,我们将在需要的地方使用[^spec]来表示Vulkan规范。 开始回答:</think>### Vulkan YCbCr采样实现指南 在Vulkan中实现YCbCr采样涉及硬件加速的色彩空间转换,主要用于视频处理。以下是关键步骤和实现要点: #### 1. **前提条件** - 启用扩展:`VK_KHR_sampler_ycbcr_conversion`(Vulkan 1.1+已内置) - 检查设备支持: ```cpp VkPhysicalDeviceSamplerYcbcrConversionFeatures ycbcrFeatures{}; ycbcrFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES; vkGetPhysicalDeviceFeatures2(physicalDevice, &ycbcrFeatures); ``` - 使用多平面格式(如`VK_FORMAT_G8_B8R8_2PLANE_420_UNORM`) #### 2. **创建YCbCr转换对象** ```cpp VkSamplerYcbcrConversionCreateInfo conversionInfo{ .sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO, .format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, .ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709, .ycbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_NARROW, .components = { .r = VK_COMPONENT_SWIZZLE_IDENTITY, .g = VK_COMPONENT_SWIZZLE_IDENTITY, .b = VK_COMPONENT_SWIZZLE_IDENTITY, .a = VK_COMPONENT_SWIZZLE_IDENTITY }, .xChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN, .yChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN, .chromaFilter = VK_FILTER_LINEAR, .forceExplicitReconstruction = VK_FALSE }; VkSamplerYcbcrConversion ycbcrConversion; vkCreateSamplerYcbcrConversion(device, &conversionInfo, nullptr, &ycbcrConversion); ``` #### 3. **配置采样器** ```cpp VkSamplerYcbcrConversionInfo conversionInfoChain{ .sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO, .conversion = ycbcrConversion }; VkSamplerCreateInfo samplerInfo{ .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .pNext = &conversionInfoChain, .magFilter = VK_FILTER_LINEAR, .minFilter = VK_FILTER_LINEAR, .mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR }; vkCreateSampler(device, &samplerInfo, nullptr, &sampler); ``` #### 4. **图像与内存绑定** - 使用`VK_IMAGE_CREATE_DISJOINT_BIT`创建多平面图像 - 为每个平面(Y、Cb、Cr)单独绑定内存: ```cpp VkBindImageMemoryInfo bindInfos[2]; bindInfos[0] = { /* Y平面绑定 */ }; bindInfos[1] = { /* UV平面绑定 */ }; vkBindImageMemory2(device, 2, bindInfos); ``` #### 5. **着色器采样** GLSL示例: ```glsl #version 450 layout(set=0, binding=0) uniform sampler2D ycbcrSampler; layout(location=0) out vec4 outColor; void main() { vec3 yuv = texture(ycbcrSampler, texCoord).rgb; // 转换YUV到RGB(硬件自动完成) outColor = vec4(yuv, 1.0); } ``` #### 6. **资源清理** ```cpp vkDestroySampler(device, sampler, nullptr); vkDestroySamplerYcbcrConversion(device, ycbcrConversion, nullptr); ``` #### 关键注意事项: 1. **格式支持**:使用`vkGetPhysicalDeviceFormatProperties`验证格式支持 2. **色度对齐**:根据内容选择`VK_CHROMA_LOCATION_COSITED_EVEN`或`MIDPOINT` 3. **性能优化**:优先使用硬件支持的转换矩阵[^1] 4. **多平面分离**:Android等平台需使用`VkBindImagePlaneMemoryInfo` 完整实现参考: - Vulkan规范第26章:YCbCr操作[^spec] - Khronos官方示例:https://github.com/KhronosGroup/Vulkan-Samples
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值