SPIRV-Reflect将单个BDA推送常量大小识别为16字节而非8字节的问题
SPIRV-Reflect将含单个BDA的推送常量评估为16字节的原因
在使用LunarG Vulkan SDK(v1.3.275.0)中的SPIRV-Reflect时,遇到一个问题:包含单个Buffer Device Address(BDA)类型的推送常量,被评估为16字节,而预期应为8字节(BDA作为指针,64位系统下大小为8字节)。
着色器代码
layout(buffer_reference, scalar, buffer_reference_align = 4) readonly buffer CameraData { mat4 view; mat4 proj; mat4 view_proj; vec3 position; }; layout(push_constant) uniform PushContants { CameraData camera; } pc;
反射代码
uint32 push_constant_range_count = 0; spvReflectEnumeratePushConstantBlocks(&reflect_module, &push_constant_range_count, nullptr); std::vector<SpvReflectBlockVariable*> reflect_push_constant_ranges(push_constant_range_count); spvReflectEnumeratePushConstantBlocks(&reflect_module, &push_constant_range_count, reflect_push_constant_ranges.data()); for (auto& reflect_range : reflect_push_constant_ranges) { push_constant_range.size += reflect_range->size; push_constant_range.offset = 0; push_constant_range.stageFlags = VK_SHADER_STAGE_ALL; }
注:上述反射代码存在局限性,若不同着色器阶段使用多个推送常量范围会出错,但本次仅用于测试场景,且仅在顶点阶段使用单个推送常量范围。
调试信息
- 反射得到的推送常量数据显示,
PushConstants的总大小为16字节 PushConstants结构体中camera成员的描述显示,其类型为CameraData(buffer reference),自身大小为16字节
请问该现象的原因是什么?
内容的提问来源于stack exchange,提问作者DaniilV
相关产品推荐
相关产品推荐

