|
1538 | 1538 | <span id="1538">1538</span>
|
1539 | 1539 | <span id="1539">1539</span>
|
1540 | 1540 | <span id="1540">1540</span>
|
| 1541 | +<span id="1541">1541</span> |
| 1542 | +<span id="1542">1542</span> |
| 1543 | +<span id="1543">1543</span> |
| 1544 | +<span id="1544">1544</span> |
| 1545 | +<span id="1545">1545</span> |
| 1546 | +<span id="1546">1546</span> |
| 1547 | +<span id="1547">1547</span> |
| 1548 | +<span id="1548">1548</span> |
| 1549 | +<span id="1549">1549</span> |
| 1550 | +<span id="1550">1550</span> |
| 1551 | +<span id="1551">1551</span> |
| 1552 | +<span id="1552">1552</span> |
| 1553 | +<span id="1553">1553</span> |
| 1554 | +<span id="1554">1554</span> |
| 1555 | +<span id="1555">1555</span> |
| 1556 | +<span id="1556">1556</span> |
| 1557 | +<span id="1557">1557</span> |
| 1558 | +<span id="1558">1558</span> |
1541 | 1559 | </pre><pre class="rust"><code><span class="kw">use </span><span class="kw">super</span>::conv;
|
1542 | 1560 |
|
1543 | 1561 | <span class="kw">use </span>ash::{extensions::khr, vk};
|
|
1612 | 1630 | ///
|
1613 | 1631 | /// `requested_features` should be the same as what was used to generate `enabled_extensions`.
|
1614 | 1632 | </span><span class="kw">fn </span>from_extensions_and_requested_features(
|
1615 |
| - api_version: u32, |
| 1633 | + effective_api_version: u32, |
1616 | 1634 | enabled_extensions: <span class="kw-2">&</span>[<span class="kw-2">&</span><span class="lifetime">'static </span>CStr],
|
1617 | 1635 | requested_features: wgt::Features,
|
1618 | 1636 | downlevel_flags: wgt::DownlevelFlags,
|
|
1747 | 1765 | } <span class="kw">else </span>{
|
1748 | 1766 | <span class="prelude-val">None
|
1749 | 1767 | </span>},
|
1750 |
| - imageless_framebuffer: <span class="kw">if </span>api_version >= vk::API_VERSION_1_2 |
| 1768 | + imageless_framebuffer: <span class="kw">if </span>effective_api_version >= vk::API_VERSION_1_2 |
1751 | 1769 | || enabled_extensions.contains(<span class="kw-2">&</span>vk::KhrImagelessFramebufferFn::name())
|
1752 | 1770 | {
|
1753 | 1771 | <span class="prelude-val">Some</span>(
|
|
1758 | 1776 | } <span class="kw">else </span>{
|
1759 | 1777 | <span class="prelude-val">None
|
1760 | 1778 | </span>},
|
1761 |
| - timeline_semaphore: <span class="kw">if </span>api_version >= vk::API_VERSION_1_2 |
| 1779 | + timeline_semaphore: <span class="kw">if </span>effective_api_version >= vk::API_VERSION_1_2 |
1762 | 1780 | || enabled_extensions.contains(<span class="kw-2">&</span>vk::KhrTimelineSemaphoreFn::name())
|
1763 | 1781 | {
|
1764 | 1782 | <span class="prelude-val">Some</span>(
|
|
1802 | 1820 | } <span class="kw">else </span>{
|
1803 | 1821 | <span class="prelude-val">None
|
1804 | 1822 | </span>},
|
1805 |
| - multiview: <span class="kw">if </span>api_version >= vk::API_VERSION_1_1 |
| 1823 | + multiview: <span class="kw">if </span>effective_api_version >= vk::API_VERSION_1_1 |
1806 | 1824 | || enabled_extensions.contains(<span class="kw-2">&</span>vk::KhrMultiviewFn::name())
|
1807 | 1825 | {
|
1808 | 1826 | <span class="prelude-val">Some</span>(
|
|
2051 | 2069 | supported_extensions: Vec<vk::ExtensionProperties>,
|
2052 | 2070 | properties: vk::PhysicalDeviceProperties,
|
2053 | 2071 | descriptor_indexing: <span class="prelude-ty">Option</span><vk::PhysicalDeviceDescriptorIndexingPropertiesEXT>,
|
| 2072 | + <span class="doccomment">/// The effective driver api version supported by the physical device. |
| 2073 | + /// |
| 2074 | + /// The Vulkan specification states the following in the documentation for VkPhysicalDeviceProperties: |
| 2075 | + /// > The value of apiVersion may be different than the version returned by vkEnumerateInstanceVersion; |
| 2076 | + /// > either higher or lower. In such cases, the application must not use functionality that exceeds |
| 2077 | + /// > the version of Vulkan associated with a given object. |
| 2078 | + /// |
| 2079 | + /// For example, a Vulkan 1.1 instance cannot use functionality added in Vulkan 1.2 even if the physical |
| 2080 | + /// device supports Vulkan 1.2. |
| 2081 | + /// |
| 2082 | + /// This means that assuming that the apiVersion provided by VkPhysicalDeviceProperties is the actual |
| 2083 | + /// version we can use is incorrect. Instead the effective version is the lower of the instance version |
| 2084 | + /// and physical device version. |
| 2085 | + </span>effective_api_version: u32, |
2054 | 2086 | }
|
2055 | 2087 |
|
2056 | 2088 | <span class="comment">// This is safe because the structs have `p_next: *mut c_void`, which we null out/never read.
|
|
2074 | 2106 |
|
2075 | 2107 | extensions.push(khr::Swapchain::name());
|
2076 | 2108 |
|
2077 |
| - <span class="kw">if </span><span class="self">self</span>.properties.api_version < vk::API_VERSION_1_1 { |
| 2109 | + <span class="kw">if </span><span class="self">self</span>.effective_api_version < vk::API_VERSION_1_1 { |
2078 | 2110 | extensions.push(vk::KhrMaintenance1Fn::name());
|
2079 | 2111 | extensions.push(vk::KhrMaintenance2Fn::name());
|
2080 | 2112 |
|
|
2092 | 2124 | }
|
2093 | 2125 | }
|
2094 | 2126 |
|
2095 |
| - <span class="kw">if </span><span class="self">self</span>.properties.api_version < vk::API_VERSION_1_2 { |
| 2127 | + <span class="kw">if </span><span class="self">self</span>.effective_api_version < vk::API_VERSION_1_2 { |
2096 | 2128 | <span class="kw">if </span><span class="self">self</span>.supports_extension(vk::KhrImagelessFramebufferFn::name()) {
|
2097 | 2129 | extensions.push(vk::KhrImagelessFramebufferFn::name());
|
2098 | 2130 | extensions.push(vk::KhrImageFormatListFn::name()); <span class="comment">// Required for `KhrImagelessFramebufferFn`
|
|
2104 | 2136 | <span class="kw">if </span>requested_features.intersects(indexing_features()) {
|
2105 | 2137 | extensions.push(vk::ExtDescriptorIndexingFn::name());
|
2106 | 2138 |
|
2107 |
| - <span class="kw">if </span><span class="self">self</span>.properties.api_version < vk::API_VERSION_1_1 { |
| 2139 | + <span class="kw">if </span><span class="self">self</span>.effective_api_version < vk::API_VERSION_1_1 { |
2108 | 2140 | extensions.push(vk::KhrMaintenance3Fn::name());
|
2109 | 2141 | }
|
2110 | 2142 | }
|
|
2295 | 2327 | <span class="kw">unsafe </span>{ <span class="self">self</span>.raw.get_physical_device_properties(phd) }
|
2296 | 2328 | };
|
2297 | 2329 |
|
| 2330 | + <span class="comment">// Set the effective api version |
| 2331 | + </span>capabilities.effective_api_version = <span class="self">self |
| 2332 | + </span>.driver_api_version |
| 2333 | + .min(capabilities.properties.api_version); |
2298 | 2334 | capabilities
|
2299 | 2335 | };
|
2300 | 2336 |
|
|
2305 | 2341 | <span class="kw">let </span><span class="kw-2">mut </span>builder = vk::PhysicalDeviceFeatures2KHR::builder().features(core);
|
2306 | 2342 |
|
2307 | 2343 | <span class="comment">// `VK_KHR_multiview` is promoted to 1.1
|
2308 |
| - </span><span class="kw">if </span>capabilities.properties.api_version >= vk::API_VERSION_1_1 |
| 2344 | + </span><span class="kw">if </span>capabilities.effective_api_version >= vk::API_VERSION_1_1 |
2309 | 2345 | || capabilities.supports_extension(vk::KhrMultiviewFn::name())
|
2310 | 2346 | {
|
2311 | 2347 | <span class="kw">let </span>next = features
|
|
2433 | 2469 | );
|
2434 | 2470 | };
|
2435 | 2471 |
|
2436 |
| - <span class="kw">if </span>phd_capabilities.properties.api_version == vk::API_VERSION_1_0 |
| 2472 | + <span class="kw">if </span>phd_capabilities.effective_api_version == vk::API_VERSION_1_0 |
2437 | 2473 | && !phd_capabilities.supports_extension(vk::KhrStorageBufferStorageClassFn::name())
|
2438 | 2474 | {
|
2439 | 2475 | <span class="macro">log::warn!</span>(
|
|
2444 | 2480 | }
|
2445 | 2481 | <span class="kw">if </span>!phd_capabilities.supports_extension(vk::AmdNegativeViewportHeightFn::name())
|
2446 | 2482 | && !phd_capabilities.supports_extension(vk::KhrMaintenance1Fn::name())
|
2447 |
| - && phd_capabilities.properties.api_version < vk::API_VERSION_1_1 |
| 2483 | + && phd_capabilities.effective_api_version < vk::API_VERSION_1_1 |
2448 | 2484 | {
|
2449 | 2485 | <span class="macro">log::warn!</span>(
|
2450 | 2486 | <span class="string">"viewport Y-flip is not supported, hiding adapter: {}"</span>,
|
|
2465 | 2501 | }
|
2466 | 2502 |
|
2467 | 2503 | <span class="kw">let </span>private_caps = <span class="kw">super</span>::PrivateCapabilities {
|
2468 |
| - flip_y_requires_shift: phd_capabilities.properties.api_version >= vk::API_VERSION_1_1 |
| 2504 | + flip_y_requires_shift: phd_capabilities.effective_api_version >= vk::API_VERSION_1_1 |
2469 | 2505 | || phd_capabilities.supports_extension(vk::KhrMaintenance1Fn::name()),
|
2470 | 2506 | imageless_framebuffers: <span class="kw">match </span>phd_features.imageless_framebuffer {
|
2471 | 2507 | <span class="prelude-val">Some</span>(features) => features.imageless_framebuffer == vk::TRUE,
|
2472 | 2508 | <span class="prelude-val">None </span>=> phd_features
|
2473 | 2509 | .imageless_framebuffer
|
2474 | 2510 | .map_or(<span class="bool-val">false</span>, |ext| ext.imageless_framebuffer != <span class="number">0</span>),
|
2475 | 2511 | },
|
2476 |
| - image_view_usage: phd_capabilities.properties.api_version >= vk::API_VERSION_1_1 |
| 2512 | + image_view_usage: phd_capabilities.effective_api_version >= vk::API_VERSION_1_1 |
2477 | 2513 | || phd_capabilities.supports_extension(vk::KhrMaintenance2Fn::name()),
|
2478 | 2514 | timeline_semaphores: <span class="kw">match </span>phd_features.timeline_semaphore {
|
2479 | 2515 | <span class="prelude-val">Some</span>(features) => features.timeline_semaphore == vk::TRUE,
|
|
2579 | 2615 | uab_types: <span class="kw">super</span>::UpdateAfterBindTypes,
|
2580 | 2616 | ) -> PhysicalDeviceFeatures {
|
2581 | 2617 | PhysicalDeviceFeatures::from_extensions_and_requested_features(
|
2582 |
| - <span class="self">self</span>.phd_capabilities.properties.api_version, |
| 2618 | + <span class="self">self</span>.phd_capabilities.effective_api_version, |
2583 | 2619 | enabled_extensions,
|
2584 | 2620 | features,
|
2585 | 2621 | <span class="self">self</span>.downlevel_flags,
|
|
2633 | 2669 | <span class="kw-2">&</span><span class="self">self</span>.instance.raw,
|
2634 | 2670 | <span class="kw-2">&</span>raw_device,
|
2635 | 2671 | )))
|
2636 |
| - } <span class="kw">else if </span><span class="self">self</span>.phd_capabilities.properties.api_version >= vk::API_VERSION_1_2 { |
| 2672 | + } <span class="kw">else if </span><span class="self">self</span>.phd_capabilities.effective_api_version >= vk::API_VERSION_1_2 { |
2637 | 2673 | <span class="prelude-val">Some</span>(<span class="kw">super</span>::ExtensionFn::Promoted)
|
2638 | 2674 | } <span class="kw">else </span>{
|
2639 | 2675 | <span class="prelude-val">None
|
|
0 commit comments