据我了解,scalar
vulkan GLSL 中的布局限定符应该允许一个简单的 vec3 值数组起作用,显然不需要指定任何物理设备功能。我已经尝试过指定标量布局功能,例如:
VkPhysicalDeviceScalarBlockLayoutFeatures layoutfeatures = {};
layoutfeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES;
layoutfeatures.scalarBlockLayout = VK_TRUE;
VkPhysicalDeviceFeatures2 features2 = {};
features2.features = m_required_features;
features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
features2.pNext = &layoutfeatures;
VkDeviceCreateInfo create_info = {};
create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
create_info.queueCreateInfoCount = static_cast<uint32_t>(queue_create_infos.size());
create_info.pQueueCreateInfos = queue_create_infos.data();
create_info.enabledExtensionCount = static_cast<uint32_t>(enabled_extensions_names.size());
create_info.ppEnabledExtensionNames = enabled_extensions_names.data();
create_info.pEnabledFeatures = &features2 .features;
create_info.pNext = &features2 ;
create_info.flags = flags;
VkDevice device;
VUL_EXCEPT_RESULT(vkCreateDevice(physical_device, &create_info, pAllocator, &device));
但无济于事。我收到奇怪的规范失效错误。
这是示例代码:
#version 450
#extension GL_EXT_scalar_block_layout: require
#define WORKGROUP_SIZE 128
layout (local_size_x = WORKGROUP_SIZE, local_size_y = 1, local_size_z = 1) in;
layout(scalar, binding = 3) buffer MyBufferBlock{
vec3 example_array[];
};
void main(){
example_array[gl_GlobalInvocationID.x] = 0.0;
}
我收到以下 SPIR-V 验证错误:
"example.exe"
ERROR : SPEC_INVALIDATION - Message ID Number 7060244, Message ID String UNASSIGNED-CoreValidation-Shader-InconsistentSpirv:
Validation Error: [ UNASSIGNED-CoreValidation-Shader-InconsistentSpirv ] Object 0: handle = 0x6543e40, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x6bbb14 | SPIR-V module not valid: Structure id 500 decorated as BufferBlock for variable in Uniform storage class must follow relaxed storage buffer layout rules: member 0 contains an array with stride 12 not satisfying alignment to 16
%MyBufferBlock = OpTypeStruct %_runtimearr_v3float
首先,我不明白为什么它试图将我的缓冲区称为制服?显然我仍然对这完全违反规范感到困惑。