调用 vkEnumerateDeviceExtensionProperties “两次"- 需要吗? [英] Calling vkEnumerateDeviceExtensionProperties "twice" - is it required?

查看:35
本文介绍了调用 vkEnumerateDeviceExtensionProperties “两次"- 需要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 vkEnumerateDeviceExtensionProperties 的手册页

vkEnumerateDeviceExtensionProperties 检索属性物理设备上的扩展,其句柄在物理设备.确定一个层集实现的扩展pLayerName 指向图层的名称和任何返回的扩展名由该层实现.将 pLayerName 设置为 NULL 将返回可用的非层扩展.pPropertyCount 必须设置为pProperties 指向的 VkExtensionProperties 数组的大小.这pProperties 应该指向一个 VkExtensionProperties 数组已填写或为空.如果为 null,vkEnumerateDeviceExtensionProperties 将使用找到的扩展数量更新 pPropertyCount.VkExtensionProperties 的定义如下:

vkEnumerateDeviceExtensionProperties retrieves properties for extensions on a physical device whose handle is given in physicalDevice. To determine the extensions implemented by a layer set pLayerName to point to the layer’s name and any returned extensions are implemented by that layer. Setting pLayerName to NULL will return the available non-layer extensions. pPropertyCount must be set to the size of the VkExtensionProperties array pointed to by pProperties. The pProperties should point to an array of VkExtensionProperties to be filled out or null. If null, vkEnumerateDeviceExtensionProperties will update pPropertyCount with the number of extensions found. The definition of VkExtensionProperties is as follows:

(强调我的).看来在目前的实现中(Window SDK v1.0.13),pPropertyCount 更新了扩展的数量,不管pProperties是否为空或不.但是,文档似乎没有明确说明在这种情况下会发生什么.

(emphasis mine). It seems in the current implementation (Window SDK v1.0.13), pPropertyCount is updated with the number of extensions, regardless of whether pProperties is null or not. However, the documentation doesn't appear to be explicit on what happens in this situation.

这里有一个例子,说明为什么拥有这样的功能更好":

Here's an example, of why having such a feature is 'nicer':

const uint32_t MaxCount = 1024; // More than you'll ever need
uint32_t ActualCount = MaxCount;
VkLayerProperties layers[MaxCount];
VkResult result = vkEnumerateDeviceLayerProperties(physicalDevice, &ActualCount, layers);
//...

对比

uint32_t ActualCount = 0;
VkLayerProperties* layers;
VkResult result = vkEnumerateDeviceLayerProperties(physicalDevice, &ActualCount, nullptr);
if (ActualCount > 0) 
{
    extensions = alloca(ActualCount * sizeof(VkLayerProperties));
    result = vkEnumerateDeviceLayerProperties(physicalDevice, &ActualCount, layers);
    //...
}

我的问题是:我这样做是依赖于不受支持的功能,还是以某种方式在文档的其他地方做广告?

My question is: am I depending on unsupported functionality by doing this, or is this somehow advertised somewhere else in the documentation?

推荐答案

来自 最新规范:

对于 vkEnumerateInstanceExtensionProperties 和 vkEnumerateDeviceExtensionProperties,如果 pProperties 为 NULL,则可用扩展属性的数量在 pPropertyCount 中返回.否则,pPropertyCount 必须指向用户设置的变量,以表示 pProperties 数组中的元素数量,返回时,该变量将被实际写入 pProperties 的结构数量覆盖.如果 pPropertyCount 小于可用扩展属性的数量,则最多将写入 pPropertyCount 结构.如果 pPropertyCount 小于可用扩展的数量,则将返回 VK_INCOMPLETE 而不是 VK_SUCCESS,以表明并非所有可用的属性都已返回.

For both vkEnumerateInstanceExtensionProperties and vkEnumerateDeviceExtensionProperties, if pProperties is NULL, then the number of extensions properties available is returned in pPropertyCount. Otherwise, pPropertyCount must point to a variable set by the user to the number of elements in the pProperties array, and on return the variable is overwritten with the number of structures actually written to pProperties. If pPropertyCount is less than the number of extension properties available, at most pPropertyCount structures will be written. If pPropertyCount is smaller than the number of extensions available, VK_INCOMPLETE will be returned instead of VK_SUCCESS, to indicate that not all the available properties were returned.

所以你的方法是正确的,即使它有点浪费内存.类似的返回数组的函数也有类似的行为.

So your approach is correct, even though it's a bit wasteful on memory. Similar functions returning arrays also behave like this.

另请注意,自 1.0.13 起,不推荐使用设备层.所有实例层都能够拦截对实例和从实例创建的设备的命令.

Also note that since 1.0.13, device layers are deprecated. All instance layers are able to intercept commands to both the instance and the devices created from it.

这篇关于调用 vkEnumerateDeviceExtensionProperties “两次"- 需要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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