Vulkan教程(14): Graphics pipeline之Fixed functions(固定管线功能)

Vulkan官方英文原文:Fixed functions - Vulkan Tutorial

对应的Vulkan技术规格说明书版本: Vulkan 1.3.2

The older graphics APIs provided default state for most of the stages of the graphics pipeline. In Vulkan you have to be explicit about most pipeline states as it'll be baked into an immutable pipeline state object. In this chapter we'll fill in all of the structures to configure these fixed-function operations.

以前的图形API为图形管线的大多数阶段提供了默认状态。在Vulkan中你必须明确大多数管线状态,因为它将被烘焙到一个不可变的图形管线状态对象中。这个章节我们将填充所有信息结构去配置固定功能的相关操作。

Dynamic state

动态状态

While most of the pipeline state needs to be baked into the pipeline state, a limited amount of the state can actually be changed without recreating the pipeline at draw time. Examples are the size of the viewport, line width and blend constants. If you want to use dynamic state and keep these properties out, then you'll have to fill in a VkPipelineDynamicStateCreateInfo structure like this:

虽然大部分图形管线状态需要被烘焙到管线状态中,但实际上可以更改有限数量的状态,而无需在绘制时重新创建图形管线。有几个相关的例子:视口大小,线宽,混合常量。假如你想应用动态状态并且保留这些属性,那你必须填充一个VkPipelineDynamicStateCreateInfo 结构体,如下所示:


std::vector<VkDynamicState> dynamicStates = {
    VK_DYNAMIC_STATE_VIEWPORT,
    VK_DYNAMIC_STATE_SCISSOR
};

VkPipelineDynamicStateCreateInfo dynamicState{};
dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
dynamicState.dynamicStateCount = static_cast<uint32_t>(dynamicStates.size());
dynamicState.pDynamicStates = dynamicStates.data();

This will cause the configuration of these values to be ignored and you will be able (and required) to specify the data at drawing time. This results in a more flexible setup and is very common for things like viewport and scissor state, which would result in a more complex setup when being baked into the pipeline state.

这将导致这些值的配置被忽略,以及你能够在绘制过程中指定(并且需要设置)相关的数据。这会让设置更灵活并且对于视口和裁剪状态是很常见的事情,当烘焙到管线状态的时候这也会让设置变得更复杂。

关于Dynamic state更多信息请见:

Vulkan Graphics pipeline Dynamic State(图形管线之动态状态)_含影的博客-优快云博客

Vertex input

顶点输入

The VkPipelineVertexInputStateCreateInfo structure describes the format of the vertex data that will be passed to the vertex shader. It describes this in roughly two ways:

  • Bindings: spacing between data and whether the data is per-vertex or per-instance (see instancing)

  • Attribute descriptions: type of the attributes passed to the vertex shader, which binding to load them from and at which offset

这个 VkPipelineVertexInputStateCreateInfo 顶点输入创建信息结构体描述将要传送到顶点shader的数据格式。大致用两种方式描述:

  • Bindings(绑定):数据之间的间距以及确定数据是每个顶点还是每个实例的

  • Attribute descriptions(属性描述):将要传入顶点shader的属性类型,绑定从哪个偏移量加载它们

Because we're hard coding the vertex data directly in the vertex shader, we'll fill in this structure to specify that there is no vertex data to load for now. We'll get back to it in the vertex buffer chapter.

由于我们是直接在顶点shader中硬编码顶点数据,因此我们填充此结构来指定没有顶点数据需要载入。我们将在顶点缓冲章节回顾它。


VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertexInputInfo.vertexBindingDescriptionCount = 0;
vertexInputInfo.pVertexBindingDescriptions = nullptr; // Optional
vertexInputInfo.vertexAttributeDescriptionCount = 0;
vertexInputInfo.pVertexAttributeDescriptions = nullptr; // Optional

The pVertexBindingDescriptions and pVertexAttributeDescriptions members point to an array of structs that describe the aforementioned details for loading vertex data. Add this structure to the createGraphicsPipeline function right after the shaderStages array.

这两个 pVertexBindingDescriptions and pVertexAttributeDescriptions 成员指向一个上述加载顶点数据的细节信息结构体数组。将这个结构添加到 createGraphicsPipeline 函数中的shaderStages 数组之后。

Input assembly

输入装配

The VkPipelineInputAssemblyStateCreateInfo struct describes two things: what kind of geometry will be drawn from the vertices and if primitive restart should be enabled. The former is specified in the topology member and can have values like:

  • VK_PRIMITIVE_TOPOLOGY_POINT_LIST: points from vertices

  • VK_PRIMITIVE_TOPOLOGY_LINE_LIST: line from every 2 vertices without reuse

  • VK_PRIMITIVE_TOPOLOGY_LINE_STRIP: the end vertex of every line is used as start vertex for the next line

  • VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: triangle from every 3 vertices without reuse

  • VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: the second and third vertex of every triangle are used as first two vertices of the next triangle

这个

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值