描述符集与资源绑定
描述符集与资源绑定:让shader资源声明、descriptor与pipeline layout逐项一致,以章专属交互与可重放证据独立重写。
学习目标
- 能说明“描述符集与资源绑定”中的让shader资源声明、descriptor与pipeline layout逐项一致,并给出对应对象、状态或概率边界
- 能用正常基线与“descriptor类型或数组长度与shader不符,或push constant范围越界”反例定位SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID中的首个差异
- 能操作三个章专属实验,让shader、descriptor set、descriptor set layout、pipeline layout、push constant、sampler具备解释、视觉和练习证据
- 能修改最小实现、固定输入重放,并判断“描述符集与资源绑定的输入、状态、输出与恢复结果可用同一证据包重放”是否恢复
从一个可推翻的运行假设开始
“描述符集与资源绑定”先固定一个问题:如何证明让shader资源声明、descriptor与pipeline layout逐项一致?先写下预期对象、状态或像素,再运行正常基线;若SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID不能指出第一个分叉,最终画面看起来正确也不能通过。
本页不变量是:描述符集与资源绑定的输入、状态、输出与恢复结果可用同一证据包重放。故障模式“descriptor类型或数组长度与shader不符,或push constant范围越界”每次只改变一个条件,正常、故障、恢复三次运行必须共享输入与版本。
来源、版本与课程边界
“描述符集与资源绑定”以Khronos Vulkan Guide latest这套持续更新的官方完整指南为主,并由Vulkan规范和官方Samples核对VUID、对象合同与可运行路径。课程的16页是教学聚合,不宣称它们是官方固定章节。
六个检查词
在“描述符集与资源绑定”的六词核对中,↡shader在“描述符集与资源绑定”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中用于让shader资源声明、descriptor与pipeline layout逐项一致;应由SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID确认。、↡descriptor set在“描述符集与资源绑定”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中用于让shader资源声明、descriptor与pipeline layout逐项一致;应由SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID确认。、↡descriptor set layout在“描述符集与资源绑定”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中用于让shader资源声明、descriptor与pipeline layout逐项一致;应由SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID确认。、↡pipeline layout在“描述符集与资源绑定”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中用于让shader资源声明、descriptor与pipeline layout逐项一致;应由SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID确认。、↡push constant在“描述符集与资源绑定”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中用于让shader资源声明、descriptor与pipeline layout逐项一致;应由SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID确认。、↡sampler在“描述符集与资源绑定”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中用于让shader资源声明、descriptor与pipeline layout逐项一致;应由SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID确认。。术语只有进入公式、交互状态、代码和可重放输出,才算真正覆盖。
正式单元与机制解释
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找到第一个分叉。
先预测,再操作三个章专属实验
1. 对象与执行路径
选择任一正式坐标,沿真实对象、状态、队列或像素路径查看因果关系。
Vulkan 提交与执行时间线
描述符集与资源绑定
把“让shader资源声明、descriptor与pipeline layout逐项一致”放到host、command buffer、queue与resource时间线上。
正式坐标
Shaders, Descriptors, Push Constants, and Resource Mapping
descriptor set layout定义每个binding的类型、数量和stage可见性,pipeline layout组合set layout与push constant范围。写descriptor只更新资源引用,绑定时还要满足动态偏移、数组索引和图像layout合同。
提交合同
ShaderInterface=PipelineLayout=BoundSets探针:SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID
最小可重现实验
VkDescriptorSet set = allocateSet(pool, layout);
updateBufferBinding(set, 0, uniformBuffer, range);
updateImageBinding(set, 1, imageView, sampler, SHADER_READ_ONLY_OPTIMAL);
bindAndValidate(cmd, pipelineLayout, set);运行“描述符集与资源绑定”时记录API/规范版本、设备或浏览器能力、固定输入、关键中间状态与输出摘要。不得用一次漂亮截图替代对象合同、验证消息、时间戳或像素差异。
练习与答案
练习
问题 1:公式边界。 在“描述符集与资源绑定”中,如何用一个可手算样本验证 ,并标明每个量属于哪一对象、stage、空间或时间点?
问题 2:正式坐标。 在“描述符集与资源绑定”中,shader、descriptor set、descriptor set layout、pipeline layout、push constant、sampler如何进入可操作验证?
问题 3:恢复证据。 怎样证明“descriptor类型或数组长度与shader不符,或push constant范围越界”已真正修复?
本章回顾
掌握“描述符集与资源绑定”意味着能把“让shader资源声明、descriptor与pipeline layout逐项一致”落到具体对象、状态与输出,能制造“descriptor类型或数组长度与shader不符,或push constant范围越界”,还能凭SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID恢复同输入结果。
名词解释
本章出现的专业名词,用大白话再讲一遍。
- shader
shader在“描述符集与资源绑定”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中用于让shader资源声明、descriptor与pipeline layout逐项一致;应由SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID确认。
- descriptor set
descriptor set在“描述符集与资源绑定”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中用于让shader资源声明、descriptor与pipeline layout逐项一致;应由SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID确认。
- descriptor set layout
descriptor set layout在“描述符集与资源绑定”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中用于让shader资源声明、descriptor与pipeline layout逐项一致;应由SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID确认。
- pipeline layout
pipeline layout在“描述符集与资源绑定”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中用于让shader资源声明、descriptor与pipeline layout逐项一致;应由SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID确认。
- push constant
push constant在“描述符集与资源绑定”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中用于让shader资源声明、descriptor与pipeline layout逐项一致;应由SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID确认。
- sampler
sampler在“描述符集与资源绑定”的“Shaders, Descriptors, Push Constants, and Resource Mapping”检查中用于让shader资源声明、descriptor与pipeline layout逐项一致;应由SPIR-V反射、set/binding、layout、写入资源、动态偏移和VUID确认。