福尔康:什么是S型的VK * CreateInfo结构的地步? [英] Vulkan: What is the point of sType in vk*CreateInfo structs?

查看:186
本文介绍了福尔康:什么是S型的VK * CreateInfo结构的地步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所有的创建信息结构的( VK * CreateInfo )的新福尔康API中,总有一个 .sType 成员。这是为什么存在,如果该值只能是一件事?另外,福尔康规范是非常明确的,你只能使用 VK * CreateInfo 结构作为参数,其对应的 vkCreate * 功能。这似乎有点多余。我可以看到,如果司机被路过这个结构直奔GPU,你可能需要把它(我注意到它总是第一个成员)。但是,这似乎是为应用程序做到这一点,因为如果司机做了它,应用程序会更容易出错一个非常糟糕的主意,和prepending一个int一个struct不似乎是一个非常低效的计算操作。我只是不明白为什么它的存在。

In all of the create info structs (vk*CreateInfo) in the new Vulkan API, there is ALWAYS a .sType member. Why is this there if the value can only be one thing? Also the Vulkan specification is very explicit that you can only use vk*CreateInfo structs as parameters for their corresponding vkCreate* function. It seems a little redundant. I can see that if the driver was passing this struct straight to the GPU, you might need to have it (I did notice it is always the first member). But this seems like a really bad idea for the app to do it because if the driver did it, apps would be much less error prone, and prepending an int to a struct doesn't seems like an extremely computational inefficient operation. I just don't see why it exists.

TL; DR结果
    在 VK * CreateInfo 结构为什么有 .sType 成员

TL;DR
    Why do the vk*CreateInfo structs have the .sType member?

推荐答案

这样的API可以不破坏向后兼容性进行更改。

So that the API can be changed without breaking backwards compatibility.

如果福尔康的1.1版本要扩大对创建,例如,命令缓冲池,怎么会这样?那么,他们可以添加一个全新的入口点: vkCreateCommandPool2 。不过这个功能将有几乎相同的签名 vkCreateCommandPool ;唯一的区别是,他们采取不同的 pCreateInfo 结构。

If version 1.1 of Vulkan wants to expand on the creation of, for example, command buffer pools, how would it do that? Well, they could add a whole new entrypoint: vkCreateCommandPool2. But this function would have almost the exact same signature as vkCreateCommandPool; the only difference is that they take different pCreateInfo structures.

因此​​,不是,你所要做的就是声明 VkCommandPoolCreateInfo2 结构。然后声明 vkCreateCommandPool 可以把任何一个。如何将对执行告诉你通过哪一个?

So instead, all you have to do is declare a VkCommandPoolCreateInfo2 structure. And then declare that vkCreateCommandPool can take either one. How would the implementation tell which one you passed in?

由于第4个字节的任何这种结构的是 STYPE 。他们可以测试该值。如果该值为 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO ,那么它的旧体制。如果是 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO_2 ,那么它是新的。

Because the first 4 bytes of any such structure is sType. They can test that value. If the value is VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, then it's the old structure. If it's VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO_2, then it's the new one.

这也使得它更容易扩展,完全重写 CreateInfo 结构。在 pNext 字段是与其他参数充实的API。随着 STYPE ,分机可以更改现有的参数。

This also makes it easier for extensions to fully override a CreateInfo structure. The pNext field is for augmenting an API with additional parameters. With sType, an extension can change existing parameters.

这篇关于福尔康:什么是S型的VK * CreateInfo结构的地步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆