Note | While the optional attribute can be used for scalar types such as integers, it does not affect the output generators included with the Vulkan API Specification. In this case, the attribute serves only as an indicator to human readers of the XML. Explicitly specifying optional="false" is not supported, but optional="false,true" is supported for a pointer type.
-- | --
KhronosGroup / KhronosGroup/Vulkan-Docs
xml scheme: Clarification for array pointer optionality (inheritance)
- Dominant language
- JavaScript
- Stars
- 3.3k
- Forks
- 549
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 2
Description
From https://registry.khronos.org/vulkan/specs/latest/registry.html#_attributes_of_member_tags
optional - optional.
Must be "true" or "false".
The default value if unspecified is "false".
"true" specifies that this member can contain a sentinel value
indicating that no corresponding object or explicit value is referred
to: NULL for pointers, VK_NULL_HANDLE for handles, or 0 for other
scalar types.
"false" specifies that the member must contain a value object
reference or explicit value.
If the member is a pointer, multiple values may be provided, separated
by commas - one for each pointer indirection.
Structure members with name pNext must always be specified with
optional="true", since there is no requirement that any member of a
pNext chain have a following member in the chain.
Note
While the optional attribute can be used for scalar types such as integers, it does not affect the output generators included with the [Vulkan API Specification](https://registry.khronos.org/vulkan/specs/latest/registry.html#vulkan-spec). In this case, the attribute serves only as an indicator to human readers of the XML.
Explicitly specifying optional="false" is not supported, but optional="false,true" is supported for a pointer type.
Btw I see the mention of `..it does not affect the output generators included with the Vulkan API Specification. In this case, the attribute serves only as an indicator to human readers of the XML...` part. But it could actually provide some benefits for language bindings (and yeah I also know that lang bindings is very unprioritized but still)
---
The `vk.xml` extensively uses links between the array pointer member and int member storing its size.
Simplest example is `VkDeviceCreateInfo` and extension enabling:
```xml
...
uint32_t enabledExtensionCount
const char* const* ppEnabledExtensionNames
...
```
We have `enabledExtensionCount` which is optional and we have `ppEnabledExtensionNames` which is not optional but links to the `enabledExtensionCount` (which is again optional). But it is common knowledge you can pass null to `ppEnabledExtensionNames`. Well seems like `ppEnabledExtensionNames` is actually "implicitly" `optional=true,false` but the [spec](https://registry.khronos.org/vulkan/specs/latest/registry.html#_attributes_of_member_tags) mentions that if `optional` is omitted it is value is by default `false`. The `vulkan_object.py` tells me that `ppEnabledExtensionNames` is `optional=false` but it is clear (maybe I am wrong) that it actually should be `optional=true,false`. It all seems like a general rule but I don't know maybe there are exceptions.
But if this is really a general rule I think that either:
1. Spec description and `vulkan_object.py` should reflect this **OR**
2. `vk.xml` be explicit and say if it is optional for each array linking to it is length ... (And yeah again I already know that lang binds are not in priority so 1 option seems better)
P.S: and one more thing. Counter example where `pGeometries` is explicitly set to `optional`:
```xml
...
uint32_t geometryCount
const VkAccelerationStructureGeometryKHR* pGeometries
const VkAccelerationStructureGeometryKHR* const* ppGeometries
...
```
Contributor guide
Assessment
This issue has not been assessed yet.