使用纹理与采样器

使用纹理与采样器:把buffer/image需求匹配到内存类型、绑定、传输与所有权;让shader资源声明、descriptor与pipeline layout逐项一致;用attachment layout与load/store合同控制渲染内容生命周期,以章专属交互与可重放证据独立重写。

学习目标

  • 能说明“使用纹理与采样器”中的把buffer/image需求匹配到内存类型、绑定、传输与所有权;让shader资源声明、descriptor与pipeline layout逐项一致;用attachment layout与load/store合同控制渲染内容生命周期,并给出对应对象、状态或概率边界
  • 能用正常基线与“只按属性标志挑内存却忽略memoryTypeBits,或跨队列使用未转移所有权;descriptor类型或数组长度与shader不符,或push constant范围越界;需要旧颜色却使用DONT_CARE,或后续采样前未转换layout与访问范围”反例定位requirements、memory type、绑定偏移、copy范围、layout和owner family、SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID、初末layout、load/store、clear值、附件范围和后续读者中的首个差异
  • 能操作三个章专属实验,让memory allocation、vkbuffer、vkimage、staging、memory type、queue family ownership、shader、descriptor set、descriptor set layout、pipeline layout、push constant、sampler、attachment、image layout、loadop、storeop、render pass、subpass具备解释、视觉和练习证据
  • 能修改最小实现、固定输入重放,并判断“使用纹理与采样器的输入、状态、输出与恢复结果可用同一证据包重放”是否恢复

从一个可推翻的运行假设开始

“使用纹理与采样器”先固定一个问题:如何证明把buffer/image需求匹配到内存类型、绑定、传输与所有权;让shader资源声明、descriptor与pipeline layout逐项一致;用attachment layout与load/store合同控制渲染内容生命周期?先写下预期对象、状态或像素,再运行正常基线;若requirements、memory type、绑定偏移、copy范围、layout和owner family、SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID、初末layout、load/store、clear值、附件范围和后续读者不能指出第一个分叉,最终画面看起来正确也不能通过。

本页不变量是:使用纹理与采样器的输入、状态、输出与恢复结果可用同一证据包重放。故障模式“只按属性标志挑内存却忽略memoryTypeBits,或跨队列使用未转移所有权;descriptor类型或数组长度与shader不符,或push constant范围越界;需要旧颜色却使用DONT_CARE,或后续采样前未转换layout与访问范围”每次只改变一个条件,正常、故障、恢复三次运行必须共享输入与版本。

来源、版本与课程边界

“使用纹理与采样器”以Khronos Vulkan Guide latest这套持续更新的官方完整指南为主,并由Vulkan规范官方Samples核对VUID、对象合同与可运行路径。课程的16页是教学聚合,不宣称它们是官方固定章节。

六个检查词

在“使用纹理与采样器”的六词核对中,。术语只有进入公式、交互状态、代码和可重放输出,才算真正覆盖。

正式单元与机制解释

Memory Allocation, Buffers, Images, Transfers, and Ownership

在“使用纹理与采样器”的“Memory Allocation, Buffers, Images, Transfers, and Ownership”检查中,VkBuffer和VkImage先声明用途,再查询memory requirements并绑定满足memoryTypeBits的分配。在“使用纹理与采样器”的“Memory Allocation, Buffers, Images, Transfers, and Ownership”检查中,staging路径把host写入与device-local消费分开;跨queue family使用还需明确ownership transfer。

在“使用纹理与采样器”本页,正式坐标是memory allocation、vkbuffer、vkimage、staging、memory type、queue family ownership。在“使用纹理与采样器”的反例核对中,反事实为“只按属性标志挑内存却忽略memoryTypeBits,或跨队列使用未转移所有权”;应从requirements、memory type、绑定偏移、copy范围、layout和owner family找到第一个分叉。

typeBitsproperties0typeBits\land properties\ne 0

Shaders, Descriptors, Push Constants, and Resource Mapping

在“使用纹理与采样器”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中,descriptor set layout定义每个binding的类型、数量和stage可见性,pipeline layout组合set layout与push constant范围。在“使用纹理与采样器”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中,写descriptor只更新资源引用,绑定时还要满足动态偏移、数组索引和图像layout合同。

在“使用纹理与采样器”本页,正式坐标是shader、descriptor set、descriptor set layout、pipeline layout、push constant、sampler。在“使用纹理与采样器”的反例核对中,反事实为“descriptor类型或数组长度与shader不符,或push constant范围越界”;应从SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID找到第一个分叉。

ShaderInterface=PipelineLayout=BoundSetsShaderInterface=PipelineLayout=BoundSets

Rendering Attachments, Layouts, Load Store, and Legacy Render Passes

在“使用纹理与采样器”的“Rendering Attachments, Layouts, Load Store, and Legacy Render Passes”检查中,attachment在渲染前后具有明确image layout;loadOp决定是否保留、清除或丢弃旧内容,storeOp决定pass后内容是否可继续读取。在“使用纹理与采样器”的“Rendering Attachments, Layouts, Load Store, and Legacy Render Passes”检查中,legacy render pass把这些关系和subpass依赖预声明,dynamic rendering则在命令中表达。

在“使用纹理与采样器”本页,正式坐标是attachment、image layout、loadop、storeop、render pass、subpass。在“使用纹理与采样器”的反例核对中,反事实为“需要旧颜色却使用DONT_CARE,或后续采样前未转换layout与访问范围”;应从初末layout、load/store、clear值、附件范围和后续读者找到第一个分叉。

Contentafter=Store(Render(Load(Contentbefore)))Content_{after}=Store(Render(Load(Content_{before})))

先预测,再操作三个章专属实验

分步1 / 3

1. 对象与执行路径

选择任一正式坐标,沿真实对象、状态、队列或像素路径查看因果关系。

Vulkan 提交与执行时间线

使用纹理与采样器

把“把buffer/image需求匹配到内存类型、绑定、传输与所有权;让shader资源声明、descriptor与pipeline layout逐项一致;用attachment layout与load/store合同控制渲染内容生命周期”放到host、command buffer、queue与resource时间线上。

正式坐标

Hostt0Record当前事件Submitt2Executet3Signalt4graphics / memory allocation

Memory Allocation, Buffers, Images, Transfers, and Ownership

VkBuffer和VkImage先声明用途,再查询memory requirements并绑定满足memoryTypeBits的分配。staging路径把host写入与device-local消费分开;跨queue family使用还需明确ownership transfer。

提交合同

typeBits\land properties\ne 0 ; ShaderInterface=PipelineLayout=BoundSets ; Content_{after}=Store(Render(Load(Content_{before})))

探针:requirements、memory type、绑定偏移、copy范围、layout和owner family

事实边界:Khronos Vulkan Guide。时间线与hazard矩阵必须由规范、VUID和同输入重放共同验证。

最小可重现实验

uploadImage(staging, texture);
transition(texture, TRANSFER_DST_OPTIMAL, SHADER_READ_ONLY_OPTIMAL);
writeCombinedImageSampler(set, binding, textureView, sampler);
validateDescriptorImageLayout(set);

运行“使用纹理与采样器”时记录API/规范版本、设备或浏览器能力、固定输入、关键中间状态与输出摘要。不得用一次漂亮截图替代对象合同、验证消息、时间戳或像素差异。

练习与答案

练习

问题 1:公式边界。 在“使用纹理与采样器”中,如何用一个可手算样本验证 typeBitsproperties0typeBits\land properties\ne 0,并标明每个量属于哪一对象、stage、空间或时间点?

问题 2:正式坐标。 在“使用纹理与采样器”中,memory allocation、vkbuffer、vkimage、staging、memory type、queue family ownership、shader、descriptor set、descriptor set layout、pipeline layout、push constant、sampler、attachment、image layout、loadop、storeop、render pass、subpass如何进入可操作验证?

问题 3:恢复证据。 怎样证明“只按属性标志挑内存却忽略memoryTypeBits,或跨队列使用未转移所有权;descriptor类型或数组长度与shader不符,或push constant范围越界;需要旧颜色却使用DONT_CARE,或后续采样前未转换layout与访问范围”已真正修复?

本章回顾

掌握“使用纹理与采样器”意味着能把“把buffer/image需求匹配到内存类型、绑定、传输与所有权;让shader资源声明、descriptor与pipeline layout逐项一致;用attachment layout与load/store合同控制渲染内容生命周期”落到具体对象、状态与输出,能制造“只按属性标志挑内存却忽略memoryTypeBits,或跨队列使用未转移所有权;descriptor类型或数组长度与shader不符,或push constant范围越界;需要旧颜色却使用DONT_CARE,或后续采样前未转换layout与访问范围”,还能凭requirements、memory type、绑定偏移、copy范围、layout和owner family、SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID、初末layout、load/store、clear值、附件范围和后续读者恢复同输入结果。

名词解释

本章出现的专业名词,用大白话再讲一遍。

memory allocation

memory allocation在“使用纹理与采样器”的“Memory Allocation, Buffers, Images, Transfers, and Ownership”检查中用于把buffer/image需求匹配到内存类型、绑定、传输与所有权;应由requirements、memory type、绑定偏移、copy范围、layout和owner family确认。

vkbuffer

vkbuffer在“使用纹理与采样器”的“Memory Allocation, Buffers, Images, Transfers, and Ownership”检查中用于把buffer/image需求匹配到内存类型、绑定、传输与所有权;应由requirements、memory type、绑定偏移、copy范围、layout和owner family确认。

vkimage

vkimage在“使用纹理与采样器”的“Memory Allocation, Buffers, Images, Transfers, and Ownership”检查中用于把buffer/image需求匹配到内存类型、绑定、传输与所有权;应由requirements、memory type、绑定偏移、copy范围、layout和owner family确认。

staging

staging在“使用纹理与采样器”的“Memory Allocation, Buffers, Images, Transfers, and Ownership”检查中用于把buffer/image需求匹配到内存类型、绑定、传输与所有权;应由requirements、memory type、绑定偏移、copy范围、layout和owner family确认。

memory type

memory type在“使用纹理与采样器”的“Memory Allocation, Buffers, Images, Transfers, and Ownership”检查中用于把buffer/image需求匹配到内存类型、绑定、传输与所有权;应由requirements、memory type、绑定偏移、copy范围、layout和owner family确认。

queue family ownership

queue family ownership在“使用纹理与采样器”的“Memory Allocation, Buffers, Images, Transfers, and Ownership”检查中用于把buffer/image需求匹配到内存类型、绑定、传输与所有权;应由requirements、memory type、绑定偏移、copy范围、layout和owner family确认。

阅读导航

← 绘制几何体 · 描述符集与资源绑定 →

资料与写作方式声明

本章以Khronos Vulkan Guide权威目录界定学习范围,并结合正文列出的技术资料独立重写;不宣称复现原书正文,也不沿用原作表述。

原作版权归作者与出版社所有;本站原创教学结构与表述仅供学习交流。

讨论

评论区加载中…