问题描述
来自 vkEnumerateDeviceExtensionProperties 的手册页,
vkEnumerateDeviceExtensionProperties 检索属性物理设备上的扩展,其句柄在物理设备.确定一个层集实现的扩展pLayerName 指向图层的名称和任何返回的扩展名由该层实现.将 pLayerName 设置为 NULL 将返回可用的非层扩展.pPropertyCount 必须设置为pProperties 指向的 VkExtensionProperties 数组的大小.这pProperties 应该指向一个 VkExtensionProperties 数组已填写或为空.如果为 null,vkEnumerateDeviceExtensionProperties 将使用找到的扩展数量更新 pPropertyCount.VkExtensionProperties 的定义如下:
(强调我的).看来在目前的实现中(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,以表明并非所有可用的属性都已返回.
所以你的方法是正确的,即使它有点浪费内存.类似的返回数组的函数也有类似的行为.
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 “两次"- 需要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!