Vulkan 实例图层在枚举属性时返回 VK_ERROR_LAYER_NOT_PRESENT 的情况
来源:stackoverflow
时间:2024-03-22 12:16:28 286浏览 收藏
你在学习Golang相关的知识吗?本文《Vulkan 实例图层在枚举属性时返回 VK_ERROR_LAYER_NOT_PRESENT 的情况》,主要介绍的内容就涉及到,如果你想提升自己的开发能力,就不要错过这篇文章,大家要知道编程理论基础和实战操作都是不可或缺的哦!
我正在使用 vulkan-go 绑定来处理 vulkan。我成功枚举了验证层并确认 vk_layer_khronos_validation 位于该列表中。然后,我将其作为验证层(也是唯一的验证层)传递给我的创建实例调用。它返回 vk_error_layer_not_present。
我已验证我的注册表正确无误,并且所有层都有正确的条目。 我已验证条目中的文件存在 在撰写本文时,我正在使用 lunarg 的最新 sdk (1.1.114.0) 我正在使用 vulkan-go 中的 go 绑定,但这似乎不是问题,因为它是对 c 的调用返回错误,并且错误是 vulkan 响应代码。 对于枚举图层属性中返回的任何其他图层也会发生这种情况 扩展工作正常,使用相同的枚举策略等
枚举(输出 12 层,包括问题中提到的层):
// findavailableinstancevalidationlayers returns a list of available validation layers on your device
func (vkctx *vulkancontext) findavailableinstancevalidationlayers() ([]string, error) {
var count uint32
if res := vk.enumerateinstancelayerproperties(&count, nil); res != vk.success {
dbg.error("failed to get instance validation layer count!")
return nil, errors.new("failed to get instance validation layer count")
}
properties := make([]vk.layerproperties, count, count)
if res := vk.enumerateinstancelayerproperties(&count, properties); res != vk.success {
dbg.error("failed to enumerate instance validation layers!")
return nil, errors.new("failed to get instance validation layer count")
}
var layers []string
for _, prop := range properties {
prop.deref()
name := string(bytes.trim(prop.layername[:], "\x00"))
layers = append(layers, name)
}
return layers, nil
}
// returns => [vk_layer_nv_optimus vk_layer_valve_steam_overlay vk_layer_valve_steam_fossilize vk_layer_lunarg_api_dump vk_layer_lunarg_assistant_layer vk_layer_lunarg_core_validation vk_layer_lunarg_device_simulation vk_layer_khronos_validation vk_layer_lunarg_monitor vk_layer_lunarg_object_tracker vk_layer_lunarg_screenshot vk_layer_lunarg_standard_validation vk_layer_lunarg_parameter_validation vk_layer_google_threading vk_layer_google_unique_objects vk_layer_lunarg_vktrace]
创建实例调用:
// declare app info
appinfo := &vk.ApplicationInfo{
SType: vk.StructureTypeApplicationInfo,
PApplicationName: "Stack Overflow Example",
ApplicationVersion: vk.MakeVersion(1, 0, 0),
PEngineName: "no engine",
EngineVersion: vk.MakeVersion(1, 0, 0),
ApiVersion: vk.ApiVersion11,
}
// declare create info (supported layers contains correct string)
createinfo := &vk.InstanceCreateInfo{
SType: vk.StructureTypeInstanceCreateInfo,
PApplicationInfo: appinfo,
EnabledExtensionCount: uint32(2),
PpEnabledExtensionNames: []string{ "VK_KHR_surface", "VK_KHR_win32_surface" },
EnabledLayerCount: uint32(1),
PpEnabledLayerNames: []string{ "VK_LAYER_KHRONOS_validation" },
}
// create the instance
inst := new(vk.Instance)
if result := vk.CreateInstance(createinfo, nil, inst); result != vk.Success {
// result => vk.ErrorLayerNotPresent
dbg.Error("Failed to create vulkan instance!")
return nil, errors.New("vulkan instance creation failed")
}
我期望 createinstance 通过(或因其他原因失败),但它进入 if 语句,并且“result”变量设置为 vk_error_layer_not_present。它使用可用层列表中的相同字符串,因此毫无疑问它是相同的。这是唯一的一层。如果我使用任何其他层(例如 vk_layer_lunarg_core_validation),那么它将具有相同的结果。无论枚举中列出的是哪个层。
解决方案
今天我自己也遇到了同样的问题,由于这是 google 中此问题的最高结果,但没有提供答案,所以我将分享我发现的内容。
vulkan 希望 ppenabledlayernames 和 ppenabledextensionnames(以及一般情况)中提供的字符串以 null 结尾,目前使用 vulkan-go 时必须手动完成此操作。
在您的代码示例中,您通过修剪 vulkan 提供的字符串中的所有 null 字节来隐藏问题
name := string(bytes.trim(prop.layername[:], "\x00"))
值得一提的是,vulkan-go 提供了一个函数来进行上述转换,ToString(),但它也有同样的问题。如果您想在使用 createinstance 或类似工具之前测试字符串,则必须保留至少一个 null 字节:
terminus := bytes.IndexByte(prop.LayerName[:], 0) // Find null terminator name := string(prop.LayerName[:terminus+1]) // Include single NULL byte
或者简单地比较不带空终止符的字符串,然后记住在比较后添加它。 .
今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~
-
502 收藏
-
502 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
Golang · Go问答 | 4天前 | 并发 · channel · Mutex · 性能优化 · Go问答 · benchmark · Goroutine channel Mutex 并发性能 锁等待 benchmark Go问答268 收藏
-
Golang · Go问答 | 4天前 | 并发 · map · RWMutex · sync.Map · Go问答 · 数据竞争 RWMutex sync.Map map并发读写 Go问答 concurrent map read and map write291 收藏
-
Golang · Go问答 | 4天前 | 并发 · channel · range · Close · Go问答 · 并发退出 Channel关闭 Go问答 close channel range退出 发送方关闭427 收藏
-
Golang · Go问答 | 4天前 | goroutine · HTTP · Context · 超时控制 · Go问答 · WithTimeout Go问答 context取消 QueryContext HTTP请求取消 goroutine退出120 收藏
-
Golang · Go问答 | 4天前 | goroutine · pprof · Go问答 · 线上排查 · 性能调优 · pprof goroutine泄漏 服务告警 Go问答 context取消 Go线上排查374 收藏
-
Golang · Go问答 | 4天前 | goroutine · Context · 超时控制 · Go问答 · 协程泄漏 · Go Goroutine 超时控制 context.WithTimeout 取消信号 协程泄漏 ctx.Done147 收藏
-
Golang · Go问答 | 4天前 | 闭包 · go · Go问答 · 循环变量 · Go1.22 · 代码迁移 · 闭包 循环变量 go vet Go问答 Go 1.22 for range loopclosure356 收藏
-
127 收藏
-
449 收藏
-
Golang · Go问答 | 4天前 | sync.Pool · reset · 对象复用 · Go问答 · 线上排查 · Go sync.Pool Go问答 sync.Pool串数据 Reset清理 对象池复用342 收藏
-
Golang · Go问答 | 5天前 | 标准库 · 文件读取 · io.Reader · Go问答 · io.EOF · Go read io.Reader io.EOF Go问答 n err 读取循环486 收藏
-
181 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 543次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 516次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 500次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 485次学习