diff options
-rw-r--r-- | services/surfaceflinger/Layer.cpp | 4 | ||||
-rw-r--r-- | services/surfaceflinger/tests/Android.bp | 1 | ||||
-rw-r--r-- | services/surfaceflinger/tests/DetachChildren_test.cpp | 322 | ||||
-rw-r--r-- | services/surfaceflinger/tests/LayerUpdate_test.cpp | 203 | ||||
-rw-r--r-- | services/surfaceflinger/tests/fakehwc/FakeComposerUtils.cpp | 4 | ||||
-rw-r--r-- | vulkan/libvulkan/driver.cpp | 287 | ||||
-rw-r--r-- | vulkan/libvulkan/driver.h | 12 | ||||
-rw-r--r-- | vulkan/libvulkan/driver_gen.cpp | 141 | ||||
-rw-r--r-- | vulkan/libvulkan/driver_gen.h | 31 | ||||
-rw-r--r-- | vulkan/scripts/driver_generator.py | 111 | ||||
-rw-r--r-- | vulkan/scripts/generator_common.py | 17 | ||||
-rw-r--r-- | vulkan/vkjson/vkjson.h | 7 | ||||
-rw-r--r-- | vulkan/vkjson/vkjson_instance.cc | 441 |
13 files changed, 1081 insertions, 500 deletions
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index a34af1793f..2ed363aef5 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -1820,7 +1820,7 @@ bool Layer::reparent(const sp<IBinder>& newParentHandle) { onRemovedFromCurrentState(); } - if (callSetTransactionFlags || attachChildren()) { + if (attachChildren() || callSetTransactionFlags) { setTransactionFlags(eTransactionNeeded); } return true; @@ -1848,9 +1848,9 @@ bool Layer::attachChildren() { if (client != nullptr && parentClient != client) { if (child->mLayerDetached) { child->mLayerDetached = false; + child->attachChildren(); changed = true; } - changed |= child->attachChildren(); } } diff --git a/services/surfaceflinger/tests/Android.bp b/services/surfaceflinger/tests/Android.bp index fe2af80c98..c96dfc7935 100644 --- a/services/surfaceflinger/tests/Android.bp +++ b/services/surfaceflinger/tests/Android.bp @@ -21,6 +21,7 @@ cc_test { "CommonTypes_test.cpp", "Credentials_test.cpp", "DereferenceSurfaceControl_test.cpp", + "DetachChildren_test.cpp", "DisplayConfigs_test.cpp", "EffectLayer_test.cpp", "InvalidHandles_test.cpp", diff --git a/services/surfaceflinger/tests/DetachChildren_test.cpp b/services/surfaceflinger/tests/DetachChildren_test.cpp new file mode 100644 index 0000000000..b6c2fe2d55 --- /dev/null +++ b/services/surfaceflinger/tests/DetachChildren_test.cpp @@ -0,0 +1,322 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wconversion" + +#include "LayerTransactionTest.h" + +namespace android { + +class DetachChildren : public LayerTransactionTest { +protected: + virtual void SetUp() { + LayerTransactionTest::SetUp(); + + mMainSurface = createLayer(String8("Main Test Surface"), mMainSurfaceBounds.width(), + mMainSurfaceBounds.height(), 0, mBlackBgSurface.get()); + + ASSERT_TRUE(mMainSurface != nullptr); + ASSERT_TRUE(mMainSurface->isValid()); + + TransactionUtils::fillSurfaceRGBA8(mMainSurface, mMainSurfaceColor); + + asTransaction([&](Transaction& t) { + t.setLayer(mMainSurface, INT32_MAX - 1) + .setPosition(mMainSurface, mMainSurfaceBounds.left, mMainSurfaceBounds.top) + .show(mMainSurface); + }); + } + + virtual void TearDown() { + LayerTransactionTest::TearDown(); + mMainSurface = 0; + } + + sp<SurfaceControl> mMainSurface; + Color mMainSurfaceColor = {195, 63, 63, 255}; + Rect mMainSurfaceBounds = Rect(64, 64, 128, 128); + std::unique_ptr<ScreenCapture> mCapture; +}; + +TEST_F(DetachChildren, RelativesAreNotDetached) { + Color relativeColor = {10, 10, 10, 255}; + Rect relBounds = Rect(64, 64, 74, 74); + + sp<SurfaceControl> relative = + createLayer(String8("relativeTestSurface"), relBounds.width(), relBounds.height(), 0); + TransactionUtils::fillSurfaceRGBA8(relative, relativeColor); + + Transaction{} + .setRelativeLayer(relative, mMainSurface->getHandle(), 1) + .setPosition(relative, relBounds.left, relBounds.top) + .apply(); + + { + // The relative should be on top of the FG control. + mCapture = screenshot(); + mCapture->expectColor(relBounds, relativeColor); + } + Transaction{}.detachChildren(mMainSurface).apply(); + + { + // Nothing should change at this point. + mCapture = screenshot(); + mCapture->expectColor(relBounds, relativeColor); + } + + Transaction{}.hide(relative).apply(); + + { + // Ensure that the relative was actually hidden, rather than + // being left in the detached but visible state. + mCapture = screenshot(); + mCapture->expectColor(mMainSurfaceBounds, mMainSurfaceColor); + } +} + +TEST_F(DetachChildren, DetachChildrenSameClient) { + Color childColor = {200, 200, 200, 255}; + Rect childBounds = Rect(74, 74, 84, 84); + sp<SurfaceControl> child = createLayer(String8("Child surface"), childBounds.width(), + childBounds.height(), 0, mMainSurface.get()); + ASSERT_TRUE(child->isValid()); + + TransactionUtils::fillSurfaceRGBA8(child, childColor); + + asTransaction([&](Transaction& t) { + t.show(child); + t.setPosition(child, childBounds.left - mMainSurfaceBounds.left, + childBounds.top - mMainSurfaceBounds.top); + }); + + { + mCapture = screenshot(); + // Expect main color around the child surface + mCapture->expectBorder(childBounds, mMainSurfaceColor); + mCapture->expectColor(childBounds, childColor); + } + + asTransaction([&](Transaction& t) { t.detachChildren(mMainSurface); }); + + asTransaction([&](Transaction& t) { t.hide(child); }); + + // Since the child has the same client as the parent, it will not get + // detached and will be hidden. + { + mCapture = screenshot(); + mCapture->expectColor(mMainSurfaceBounds, mMainSurfaceColor); + } +} + +TEST_F(DetachChildren, DetachChildrenDifferentClient) { + Color childColor = {200, 200, 200, 255}; + Rect childBounds = Rect(74, 74, 84, 84); + + sp<SurfaceComposerClient> newComposerClient = new SurfaceComposerClient; + sp<SurfaceControl> childNewClient = + createSurface(newComposerClient, "New Child Test Surface", childBounds.width(), + childBounds.height(), PIXEL_FORMAT_RGBA_8888, 0, mMainSurface.get()); + ASSERT_TRUE(childNewClient->isValid()); + + TransactionUtils::fillSurfaceRGBA8(childNewClient, childColor); + + asTransaction([&](Transaction& t) { + t.show(childNewClient); + t.setPosition(childNewClient, childBounds.left - mMainSurfaceBounds.left, + childBounds.top - mMainSurfaceBounds.top); + }); + + { + mCapture = screenshot(); + // Expect main color around the child surface + mCapture->expectBorder(childBounds, mMainSurfaceColor); + mCapture->expectColor(childBounds, childColor); + } + + asTransaction([&](Transaction& t) { t.detachChildren(mMainSurface); }); + + asTransaction([&](Transaction& t) { t.hide(childNewClient); }); + + // Nothing should have changed. + { + mCapture = screenshot(); + mCapture->expectBorder(childBounds, mMainSurfaceColor); + mCapture->expectColor(childBounds, childColor); + } +} + +TEST_F(DetachChildren, DetachChildrenThenAttach) { + Color childColor = {200, 200, 200, 255}; + Rect childBounds = Rect(74, 74, 84, 84); + + sp<SurfaceComposerClient> newComposerClient = new SurfaceComposerClient; + sp<SurfaceControl> childNewClient = + createSurface(newComposerClient, "New Child Test Surface", childBounds.width(), + childBounds.height(), PIXEL_FORMAT_RGBA_8888, 0, mMainSurface.get()); + ASSERT_TRUE(childNewClient->isValid()); + + TransactionUtils::fillSurfaceRGBA8(childNewClient, childColor); + + Transaction() + .show(childNewClient) + .setPosition(childNewClient, childBounds.left - mMainSurfaceBounds.left, + childBounds.top - mMainSurfaceBounds.top) + .apply(); + + { + mCapture = screenshot(); + // Expect main color around the child surface + mCapture->expectBorder(childBounds, mMainSurfaceColor); + mCapture->expectColor(childBounds, childColor); + } + + Transaction().detachChildren(mMainSurface).apply(); + Transaction().hide(childNewClient).apply(); + + // Nothing should have changed. + { + mCapture = screenshot(); + mCapture->expectBorder(childBounds, mMainSurfaceColor); + mCapture->expectColor(childBounds, childColor); + } + + Color newParentColor = Color::RED; + Rect newParentBounds = Rect(20, 20, 52, 52); + sp<SurfaceControl> newParentSurface = + createLayer(String8("New Parent Surface"), newParentBounds.width(), + newParentBounds.height(), 0); + TransactionUtils::fillSurfaceRGBA8(newParentSurface, newParentColor); + Transaction() + .setLayer(newParentSurface, INT32_MAX - 1) + .show(newParentSurface) + .setPosition(newParentSurface, newParentBounds.left, newParentBounds.top) + .reparent(childNewClient, newParentSurface->getHandle()) + .apply(); + { + mCapture = screenshot(); + // Child is now hidden. + mCapture->expectColor(newParentBounds, newParentColor); + } +} + +TEST_F(DetachChildren, DetachChildrenWithDeferredTransaction) { + Color childColor = {200, 200, 200, 255}; + Rect childBounds = Rect(74, 74, 84, 84); + + sp<SurfaceComposerClient> newComposerClient = new SurfaceComposerClient; + sp<SurfaceControl> childNewClient = + createSurface(newComposerClient, "New Child Test Surface", childBounds.width(), + childBounds.height(), PIXEL_FORMAT_RGBA_8888, 0, mMainSurface.get()); + ASSERT_TRUE(childNewClient->isValid()); + + TransactionUtils::fillSurfaceRGBA8(childNewClient, childColor); + + Transaction() + .show(childNewClient) + .setPosition(childNewClient, childBounds.left - mMainSurfaceBounds.left, + childBounds.top - mMainSurfaceBounds.top) + .apply(); + + { + mCapture = screenshot(); + mCapture->expectBorder(childBounds, mMainSurfaceColor); + mCapture->expectColor(childBounds, childColor); + } + + Transaction() + .deferTransactionUntil_legacy(childNewClient, mMainSurface->getHandle(), + mMainSurface->getSurface()->getNextFrameNumber()) + .apply(); + Transaction().detachChildren(mMainSurface).apply(); + ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(mMainSurface, Color::RED, + mMainSurfaceBounds.width(), + mMainSurfaceBounds.height())); + + // BufferLayer can still dequeue buffers even though there's a detached layer with a + // deferred transaction. + { + SCOPED_TRACE("new buffer"); + mCapture = screenshot(); + mCapture->expectBorder(childBounds, Color::RED); + mCapture->expectColor(childBounds, childColor); + } +} + +TEST_F(DetachChildren, ReparentParentLayerOfDetachedChildren) { + Color childColor = {200, 200, 200, 255}; + Rect childBounds = Rect(74, 74, 94, 94); + Color grandchildColor = Color::RED; + Rect grandchildBounds = Rect(80, 80, 90, 90); + + sp<SurfaceComposerClient> newClient1 = new SurfaceComposerClient; + sp<SurfaceComposerClient> newClient2 = new SurfaceComposerClient; + + sp<SurfaceControl> childSurface = + createSurface(newClient1, "Child surface", childBounds.width(), childBounds.height(), + PIXEL_FORMAT_RGBA_8888, 0, mMainSurface.get()); + sp<SurfaceControl> grandchildSurface = + createSurface(newClient2, "Grandchild Surface", grandchildBounds.width(), + grandchildBounds.height(), PIXEL_FORMAT_RGBA_8888, 0, childSurface.get()); + + TransactionUtils::fillSurfaceRGBA8(childSurface, childColor); + TransactionUtils::fillSurfaceRGBA8(grandchildSurface, grandchildColor); + + Transaction() + .show(childSurface) + .show(grandchildSurface) + .setPosition(childSurface, childBounds.left - mMainSurfaceBounds.left, + childBounds.top - mMainSurfaceBounds.top) + .setPosition(grandchildSurface, grandchildBounds.left - childBounds.left, + grandchildBounds.top - childBounds.top) + .apply(); + + { + mCapture = screenshot(); + mCapture->expectBorder(childBounds, mMainSurfaceColor); + mCapture->expectBorder(grandchildBounds, childColor); + mCapture->expectColor(grandchildBounds, grandchildColor); + } + + Transaction().detachChildren(childSurface).apply(); + + // Remove main surface offscreen + Transaction().reparent(mMainSurface, nullptr).apply(); + { + mCapture = screenshot(); + mCapture->expectColor(mMainSurfaceBounds, Color::BLACK); + } + + Transaction().reparent(mMainSurface, mBlackBgSurface->getHandle()).apply(); + { + mCapture = screenshot(); + mCapture->expectBorder(childBounds, mMainSurfaceColor); + mCapture->expectBorder(grandchildBounds, childColor); + mCapture->expectColor(grandchildBounds, grandchildColor); + } + + Transaction().hide(grandchildSurface).apply(); + + // grandchild is still detached so it will not hide + { + mCapture = screenshot(); + mCapture->expectBorder(childBounds, mMainSurfaceColor); + mCapture->expectBorder(grandchildBounds, childColor); + mCapture->expectColor(grandchildBounds, grandchildColor); + } +} + +} // namespace android
\ No newline at end of file diff --git a/services/surfaceflinger/tests/LayerUpdate_test.cpp b/services/surfaceflinger/tests/LayerUpdate_test.cpp index cdd9d92063..84823f519f 100644 --- a/services/surfaceflinger/tests/LayerUpdate_test.cpp +++ b/services/surfaceflinger/tests/LayerUpdate_test.cpp @@ -103,41 +103,6 @@ protected: sp<SurfaceControl> mSyncSurfaceControl; }; -TEST_F(LayerUpdateTest, RelativesAreNotDetached) { - std::unique_ptr<ScreenCapture> sc; - - sp<SurfaceControl> relative = createLayer(String8("relativeTestSurface"), 10, 10, 0); - TransactionUtils::fillSurfaceRGBA8(relative, 10, 10, 10); - waitForPostedBuffers(); - - Transaction{} - .setRelativeLayer(relative, mFGSurfaceControl->getHandle(), 1) - .setPosition(relative, 64, 64) - .apply(); - - { - // The relative should be on top of the FG control. - ScreenCapture::captureScreen(&sc); - sc->checkPixel(64, 64, 10, 10, 10); - } - Transaction{}.detachChildren(mFGSurfaceControl).apply(); - - { - // Nothing should change at this point. - ScreenCapture::captureScreen(&sc); - sc->checkPixel(64, 64, 10, 10, 10); - } - - Transaction{}.hide(relative).apply(); - - { - // Ensure that the relative was actually hidden, rather than - // being left in the detached but visible state. - ScreenCapture::captureScreen(&sc); - sc->expectFGColor(64, 64); - } -} - class GeometryLatchingTest : public LayerUpdateTest { protected: void EXPECT_INITIAL_STATE(const char* trace) { @@ -588,174 +553,6 @@ TEST_F(ChildLayerTest, ChildrenRelativeZSurvivesParentDestruction) { } } -TEST_F(ChildLayerTest, DetachChildrenSameClient) { - asTransaction([&](Transaction& t) { - t.show(mChild); - t.setPosition(mChild, 10, 10); - t.setPosition(mFGSurfaceControl, 64, 64); - }); - - { - mCapture = screenshot(); - // Top left of foreground must now be visible - mCapture->expectFGColor(64, 64); - // But 10 pixels in we should see the child surface - mCapture->expectChildColor(74, 74); - // And 10 more pixels we should be back to the foreground surface - mCapture->expectFGColor(84, 84); - } - - asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); - - asTransaction([&](Transaction& t) { t.hide(mChild); }); - - // Since the child has the same client as the parent, it will not get - // detached and will be hidden. - { - mCapture = screenshot(); - mCapture->expectFGColor(64, 64); - mCapture->expectFGColor(74, 74); - mCapture->expectFGColor(84, 84); - } -} - -TEST_F(ChildLayerTest, DetachChildrenDifferentClient) { - sp<SurfaceComposerClient> mNewComposerClient = new SurfaceComposerClient; - sp<SurfaceControl> mChildNewClient = - createSurface(mNewComposerClient, "New Child Test Surface", 10, 10, - PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); - - ASSERT_TRUE(mChildNewClient->isValid()); - - TransactionUtils::fillSurfaceRGBA8(mChildNewClient, 200, 200, 200); - - asTransaction([&](Transaction& t) { - t.hide(mChild); - t.show(mChildNewClient); - t.setPosition(mChildNewClient, 10, 10); - t.setPosition(mFGSurfaceControl, 64, 64); - }); - - { - mCapture = screenshot(); - // Top left of foreground must now be visible - mCapture->expectFGColor(64, 64); - // But 10 pixels in we should see the child surface - mCapture->expectChildColor(74, 74); - // And 10 more pixels we should be back to the foreground surface - mCapture->expectFGColor(84, 84); - } - - asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); - - asTransaction([&](Transaction& t) { t.hide(mChildNewClient); }); - - // Nothing should have changed. - { - mCapture = screenshot(); - mCapture->expectFGColor(64, 64); - mCapture->expectChildColor(74, 74); - mCapture->expectFGColor(84, 84); - } -} - -TEST_F(ChildLayerTest, DetachChildrenThenAttach) { - sp<SurfaceComposerClient> newComposerClient = new SurfaceComposerClient; - sp<SurfaceControl> childNewClient = - newComposerClient->createSurface(String8("New Child Test Surface"), 10, 10, - PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); - - ASSERT_TRUE(childNewClient != nullptr); - ASSERT_TRUE(childNewClient->isValid()); - - TransactionUtils::fillSurfaceRGBA8(childNewClient, 200, 200, 200); - - Transaction() - .hide(mChild) - .show(childNewClient) - .setPosition(childNewClient, 10, 10) - .setPosition(mFGSurfaceControl, 64, 64) - .apply(); - - { - mCapture = screenshot(); - // Top left of foreground must now be visible - mCapture->expectFGColor(64, 64); - // But 10 pixels in we should see the child surface - mCapture->expectChildColor(74, 74); - // And 10 more pixels we should be back to the foreground surface - mCapture->expectFGColor(84, 84); - } - - Transaction().detachChildren(mFGSurfaceControl).apply(); - Transaction().hide(childNewClient).apply(); - - // Nothing should have changed. - { - mCapture = screenshot(); - mCapture->expectFGColor(64, 64); - mCapture->expectChildColor(74, 74); - mCapture->expectFGColor(84, 84); - } - - sp<SurfaceControl> newParentSurface = createLayer(String8("New Parent Surface"), 32, 32, 0); - fillLayerColor(ISurfaceComposerClient::eFXSurfaceBufferQueue, newParentSurface, Color::RED, 32, - 32); - Transaction() - .setLayer(newParentSurface, INT32_MAX - 1) - .show(newParentSurface) - .setPosition(newParentSurface, 20, 20) - .reparent(childNewClient, newParentSurface->getHandle()) - .apply(); - { - mCapture = screenshot(); - // Child is now hidden. - mCapture->expectColor(Rect(20, 20, 52, 52), Color::RED); - } -} -TEST_F(ChildLayerTest, DetachChildrenWithDeferredTransaction) { - sp<SurfaceComposerClient> newComposerClient = new SurfaceComposerClient; - sp<SurfaceControl> childNewClient = - newComposerClient->createSurface(String8("New Child Test Surface"), 10, 10, - PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); - - ASSERT_TRUE(childNewClient != nullptr); - ASSERT_TRUE(childNewClient->isValid()); - - TransactionUtils::fillSurfaceRGBA8(childNewClient, 200, 200, 200); - - Transaction() - .hide(mChild) - .show(childNewClient) - .setPosition(childNewClient, 10, 10) - .setPosition(mFGSurfaceControl, 64, 64) - .apply(); - - { - mCapture = screenshot(); - Rect rect = Rect(74, 74, 84, 84); - mCapture->expectBorder(rect, Color{195, 63, 63, 255}); - mCapture->expectColor(rect, Color{200, 200, 200, 255}); - } - - Transaction() - .deferTransactionUntil_legacy(childNewClient, mFGSurfaceControl->getHandle(), - mFGSurfaceControl->getSurface()->getNextFrameNumber()) - .apply(); - Transaction().detachChildren(mFGSurfaceControl).apply(); - ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(mFGSurfaceControl, Color::RED, 32, 32)); - - // BufferLayer can still dequeue buffers even though there's a detached layer with a - // deferred transaction. - { - SCOPED_TRACE("new buffer"); - mCapture = screenshot(); - Rect rect = Rect(74, 74, 84, 84); - mCapture->expectBorder(rect, Color::RED); - mCapture->expectColor(rect, Color{200, 200, 200, 255}); - } -} - TEST_F(ChildLayerTest, ChildrenInheritNonTransformScalingFromParent) { asTransaction([&](Transaction& t) { t.show(mChild); diff --git a/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.cpp b/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.cpp index 96a7541919..1cea25a80f 100644 --- a/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.cpp +++ b/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.cpp @@ -29,8 +29,8 @@ #include "SurfaceFlinger.h" // Get the name of the service... #include <binder/IServiceManager.h> - #include <cutils/properties.h> +#include <hidl/ServiceManagement.h> #include <iomanip> #include <thread> @@ -173,7 +173,7 @@ void FakeHwcEnvironment::SetUp() { property_set("debug.sf.hwc_service_name", "mock"); // This allows tests/SF to register/load a HIDL service not listed in manifest files. - setenv("TREBLE_TESTING_OVERRIDE", "true", true); + android::hardware::details::setTrebleTestingOverride(true); property_set("debug.sf.treble_testing_override", "true"); } diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 3e31a66d78..535e19063f 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -141,6 +141,7 @@ class CreateInfoWrapper { }; VkApplicationInfo application_info_; + uint32_t sanitized_api_version_; ExtensionFilter extension_filter_; @@ -329,6 +330,7 @@ CreateInfoWrapper::CreateInfoWrapper(const VkInstanceCreateInfo& create_info, loader_api_version_(VK_API_VERSION_1_1), physical_dev_(VK_NULL_HANDLE), instance_info_(create_info), + sanitized_api_version_(loader_api_version_), extension_filter_() {} CreateInfoWrapper::CreateInfoWrapper(VkPhysicalDevice physical_dev, @@ -385,10 +387,6 @@ VkResult CreateInfoWrapper::SanitizeApiVersion() { hal_extensions_.set(i); } - // If pApplicationInfo is NULL, apiVersion is assumed to be 1.0 - if (!instance_info_.pApplicationInfo) - return VK_SUCCESS; - uint32_t icd_api_version = VK_API_VERSION_1_0; PFN_vkEnumerateInstanceVersion pfn_enumerate_instance_version = reinterpret_cast<PFN_vkEnumerateInstanceVersion>( @@ -409,8 +407,13 @@ VkResult CreateInfoWrapper::SanitizeApiVersion() { return VK_SUCCESS; if (icd_api_version < loader_api_version_) { + sanitized_api_version_ = icd_api_version; + + if (!instance_info_.pApplicationInfo) + return VK_SUCCESS; + application_info_ = *instance_info_.pApplicationInfo; - application_info_.apiVersion = icd_api_version; + application_info_.apiVersion = sanitized_api_version_; instance_info_.pApplicationInfo = &application_info_; } } else { @@ -498,15 +501,33 @@ VkResult CreateInfoWrapper::SanitizeExtensions() { : dev_info_.ppEnabledExtensionNames; auto& ext_count = (is_instance_) ? instance_info_.enabledExtensionCount : dev_info_.enabledExtensionCount; - if (!ext_count) - return VK_SUCCESS; VkResult result = InitExtensionFilter(); if (result != VK_SUCCESS) return result; - for (uint32_t i = 0; i < ext_count; i++) - FilterExtension(ext_names[i]); + if (is_instance_ && sanitized_api_version_ < loader_api_version_) { + for (uint32_t i = 0; i < ext_count; i++) { + // Upon api downgrade, skip the promoted instance extensions in the + // first pass to avoid duplicate extensions. + const std::optional<uint32_t> version = + GetInstanceExtensionPromotedVersion(ext_names[i]); + if (version && *version > sanitized_api_version_ && + *version <= loader_api_version_) + continue; + + FilterExtension(ext_names[i]); + } + + // Enable the required extensions to support core functionalities. + const auto promoted_extensions = GetPromotedInstanceExtensions( + sanitized_api_version_, loader_api_version_); + for (const auto& promoted_extension : promoted_extensions) + FilterExtension(promoted_extension); + } else { + for (uint32_t i = 0; i < ext_count; i++) + FilterExtension(ext_names[i]); + } // Enable device extensions that contain physical-device commands, so that // vkGetInstanceProcAddr will return those physical-device commands. @@ -571,10 +592,20 @@ VkResult CreateInfoWrapper::InitExtensionFilter() { filter.ext_count = count; // allocate name array - uint32_t enabled_ext_count = (is_instance_) - ? instance_info_.enabledExtensionCount - : dev_info_.enabledExtensionCount; - count = std::min(filter.ext_count, enabled_ext_count); + if (is_instance_) { + uint32_t enabled_ext_count = instance_info_.enabledExtensionCount; + + // It requires enabling additional promoted extensions to downgrade api, + // so we reserve enough space here. + if (sanitized_api_version_ < loader_api_version_) { + enabled_ext_count += CountPromotedInstanceExtensions( + sanitized_api_version_, loader_api_version_); + } + + count = std::min(filter.ext_count, enabled_ext_count); + } else { + count = std::min(filter.ext_count, dev_info_.enabledExtensionCount); + } filter.names = reinterpret_cast<const char**>(allocator_.pfnAllocation( allocator_.pUserData, sizeof(const char*) * count, alignof(const char*), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND)); @@ -602,6 +633,10 @@ void CreateInfoWrapper::FilterExtension(const char* name) { hook_extensions_.set(ext_bit); break; case ProcHook::KHR_get_physical_device_properties2: + case ProcHook::KHR_device_group_creation: + case ProcHook::KHR_external_memory_capabilities: + case ProcHook::KHR_external_semaphore_capabilities: + case ProcHook::KHR_external_fence_capabilities: case ProcHook::EXTENSION_UNKNOWN: // Extensions we don't need to do anything about at this level break; @@ -658,6 +693,10 @@ void CreateInfoWrapper::FilterExtension(const char* name) { case ProcHook::KHR_android_surface: case ProcHook::KHR_get_physical_device_properties2: + case ProcHook::KHR_device_group_creation: + case ProcHook::KHR_external_memory_capabilities: + case ProcHook::KHR_external_semaphore_capabilities: + case ProcHook::KHR_external_fence_capabilities: case ProcHook::KHR_get_surface_capabilities2: case ProcHook::KHR_surface: case ProcHook::EXT_debug_report: @@ -937,13 +976,6 @@ VkResult EnumerateInstanceExtensionProperties( bool QueryPresentationProperties( VkPhysicalDevice physicalDevice, VkPhysicalDevicePresentationPropertiesANDROID *presentation_properties) { - const InstanceData& data = GetData(physicalDevice); - - // GPDP2 must be present and enabled on the instance. - if (!data.driver.GetPhysicalDeviceProperties2KHR && - !data.driver.GetPhysicalDeviceProperties2) - return false; - // Request the android-specific presentation properties via GPDP2 VkPhysicalDeviceProperties2KHR properties = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR, @@ -959,12 +991,7 @@ bool QueryPresentationProperties( presentation_properties->pNext = nullptr; presentation_properties->sharedImage = VK_FALSE; - if (data.driver.GetPhysicalDeviceProperties2KHR) { - data.driver.GetPhysicalDeviceProperties2KHR(physicalDevice, - &properties); - } else { - data.driver.GetPhysicalDeviceProperties2(physicalDevice, &properties); - } + GetPhysicalDeviceProperties2(physicalDevice, &properties); return true; } @@ -1235,7 +1262,8 @@ VkResult EnumeratePhysicalDeviceGroups( VkResult result = VK_SUCCESS; const auto& data = GetData(instance); - if (!data.driver.EnumeratePhysicalDeviceGroups) { + if (!data.driver.EnumeratePhysicalDeviceGroups && + !data.driver.EnumeratePhysicalDeviceGroupsKHR) { uint32_t device_count = 0; result = EnumeratePhysicalDevices(instance, &device_count, nullptr); if (result < 0) @@ -1267,9 +1295,15 @@ VkResult EnumeratePhysicalDeviceGroups( pPhysicalDeviceGroupProperties[i].subsetAllocation = 0; } } else { - result = data.driver.EnumeratePhysicalDeviceGroups( - instance, pPhysicalDeviceGroupCount, - pPhysicalDeviceGroupProperties); + if (data.driver.EnumeratePhysicalDeviceGroups) { + result = data.driver.EnumeratePhysicalDeviceGroups( + instance, pPhysicalDeviceGroupCount, + pPhysicalDeviceGroupProperties); + } else { + result = data.driver.EnumeratePhysicalDeviceGroupsKHR( + instance, pPhysicalDeviceGroupCount, + pPhysicalDeviceGroupProperties); + } if ((result == VK_SUCCESS || result == VK_INCOMPLETE) && *pPhysicalDeviceGroupCount && pPhysicalDeviceGroupProperties) { for (uint32_t i = 0; i < *pPhysicalDeviceGroupCount; i++) { @@ -1339,5 +1373,198 @@ VKAPI_ATTR VkResult QueueSubmit(VkQueue queue, return data.driver.QueueSubmit(queue, submitCount, pSubmits, fence); } +void GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, + VkPhysicalDeviceFeatures2* pFeatures) { + ATRACE_CALL(); + + const auto& driver = GetData(physicalDevice).driver; + + if (driver.GetPhysicalDeviceFeatures2) { + driver.GetPhysicalDeviceFeatures2(physicalDevice, pFeatures); + return; + } + + driver.GetPhysicalDeviceFeatures2KHR(physicalDevice, pFeatures); +} + +void GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, + VkPhysicalDeviceProperties2* pProperties) { + ATRACE_CALL(); + + const auto& driver = GetData(physicalDevice).driver; + + if (driver.GetPhysicalDeviceProperties2) { + driver.GetPhysicalDeviceProperties2(physicalDevice, pProperties); + return; + } + + driver.GetPhysicalDeviceProperties2KHR(physicalDevice, pProperties); +} + +void GetPhysicalDeviceFormatProperties2( + VkPhysicalDevice physicalDevice, + VkFormat format, + VkFormatProperties2* pFormatProperties) { + ATRACE_CALL(); + + const auto& driver = GetData(physicalDevice).driver; + + if (driver.GetPhysicalDeviceFormatProperties2) { + driver.GetPhysicalDeviceFormatProperties2(physicalDevice, format, + pFormatProperties); + return; + } + + driver.GetPhysicalDeviceFormatProperties2KHR(physicalDevice, format, + pFormatProperties); +} + +VkResult GetPhysicalDeviceImageFormatProperties2( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, + VkImageFormatProperties2* pImageFormatProperties) { + ATRACE_CALL(); + + const auto& driver = GetData(physicalDevice).driver; + + if (driver.GetPhysicalDeviceImageFormatProperties2) { + return driver.GetPhysicalDeviceImageFormatProperties2( + physicalDevice, pImageFormatInfo, pImageFormatProperties); + } + + return driver.GetPhysicalDeviceImageFormatProperties2KHR( + physicalDevice, pImageFormatInfo, pImageFormatProperties); +} + +void GetPhysicalDeviceQueueFamilyProperties2( + VkPhysicalDevice physicalDevice, + uint32_t* pQueueFamilyPropertyCount, + VkQueueFamilyProperties2* pQueueFamilyProperties) { + ATRACE_CALL(); + + const auto& driver = GetData(physicalDevice).driver; + + if (driver.GetPhysicalDeviceQueueFamilyProperties2) { + driver.GetPhysicalDeviceQueueFamilyProperties2( + physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties); + return; + } + + driver.GetPhysicalDeviceQueueFamilyProperties2KHR( + physicalDevice, pQueueFamilyPropertyCount, pQueueFamilyProperties); +} + +void GetPhysicalDeviceMemoryProperties2( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceMemoryProperties2* pMemoryProperties) { + ATRACE_CALL(); + + const auto& driver = GetData(physicalDevice).driver; + + if (driver.GetPhysicalDeviceMemoryProperties2) { + driver.GetPhysicalDeviceMemoryProperties2(physicalDevice, + pMemoryProperties); + return; + } + + driver.GetPhysicalDeviceMemoryProperties2KHR(physicalDevice, + pMemoryProperties); +} + +void GetPhysicalDeviceSparseImageFormatProperties2( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, + uint32_t* pPropertyCount, + VkSparseImageFormatProperties2* pProperties) { + ATRACE_CALL(); + + const auto& driver = GetData(physicalDevice).driver; + + if (driver.GetPhysicalDeviceSparseImageFormatProperties2) { + driver.GetPhysicalDeviceSparseImageFormatProperties2( + physicalDevice, pFormatInfo, pPropertyCount, pProperties); + return; + } + + driver.GetPhysicalDeviceSparseImageFormatProperties2KHR( + physicalDevice, pFormatInfo, pPropertyCount, pProperties); +} + +void GetPhysicalDeviceExternalBufferProperties( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, + VkExternalBufferProperties* pExternalBufferProperties) { + ATRACE_CALL(); + + const auto& driver = GetData(physicalDevice).driver; + + if (driver.GetPhysicalDeviceExternalBufferProperties) { + driver.GetPhysicalDeviceExternalBufferProperties( + physicalDevice, pExternalBufferInfo, pExternalBufferProperties); + return; + } + + if (driver.GetPhysicalDeviceExternalBufferPropertiesKHR) { + driver.GetPhysicalDeviceExternalBufferPropertiesKHR( + physicalDevice, pExternalBufferInfo, pExternalBufferProperties); + return; + } + + memset(&pExternalBufferProperties->externalMemoryProperties, 0, + sizeof(VkExternalMemoryProperties)); +} + +void GetPhysicalDeviceExternalSemaphoreProperties( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, + VkExternalSemaphoreProperties* pExternalSemaphoreProperties) { + ATRACE_CALL(); + + const auto& driver = GetData(physicalDevice).driver; + + if (driver.GetPhysicalDeviceExternalSemaphoreProperties) { + driver.GetPhysicalDeviceExternalSemaphoreProperties( + physicalDevice, pExternalSemaphoreInfo, + pExternalSemaphoreProperties); + return; + } + + if (driver.GetPhysicalDeviceExternalSemaphorePropertiesKHR) { + driver.GetPhysicalDeviceExternalSemaphorePropertiesKHR( + physicalDevice, pExternalSemaphoreInfo, + pExternalSemaphoreProperties); + return; + } + + pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0; + pExternalSemaphoreProperties->compatibleHandleTypes = 0; + pExternalSemaphoreProperties->externalSemaphoreFeatures = 0; +} + +void GetPhysicalDeviceExternalFenceProperties( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, + VkExternalFenceProperties* pExternalFenceProperties) { + ATRACE_CALL(); + + const auto& driver = GetData(physicalDevice).driver; + + if (driver.GetPhysicalDeviceExternalFenceProperties) { + driver.GetPhysicalDeviceExternalFenceProperties( + physicalDevice, pExternalFenceInfo, pExternalFenceProperties); + return; + } + + if (driver.GetPhysicalDeviceExternalFencePropertiesKHR) { + driver.GetPhysicalDeviceExternalFencePropertiesKHR( + physicalDevice, pExternalFenceInfo, pExternalFenceProperties); + return; + } + + pExternalFenceProperties->exportFromImportedHandleTypes = 0; + pExternalFenceProperties->compatibleHandleTypes = 0; + pExternalFenceProperties->externalFenceFeatures = 0; +} + } // namespace driver } // namespace vulkan diff --git a/vulkan/libvulkan/driver.h b/vulkan/libvulkan/driver.h index 23c717cf5d..e7b4bb25bf 100644 --- a/vulkan/libvulkan/driver.h +++ b/vulkan/libvulkan/driver.h @@ -126,6 +126,18 @@ VKAPI_ATTR void GetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint3 VKAPI_ATTR void GetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2* pQueueInfo, VkQueue* pQueue); VKAPI_ATTR VkResult AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers); VKAPI_ATTR VkResult QueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence); + +VKAPI_ATTR void GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures2* pFeatures); +VKAPI_ATTR void GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties2* pProperties); +VKAPI_ATTR void GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties2* pFormatProperties); +VKAPI_ATTR VkResult GetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, VkImageFormatProperties2* pImageFormatProperties); +VKAPI_ATTR void GetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties2* pQueueFamilyProperties); +VKAPI_ATTR void GetPhysicalDeviceMemoryProperties2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties2* pMemoryProperties); +VKAPI_ATTR void GetPhysicalDeviceSparseImageFormatProperties2(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, uint32_t* pPropertyCount, VkSparseImageFormatProperties2* pProperties); + +VKAPI_ATTR void GetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, VkExternalBufferProperties* pExternalBufferProperties); +VKAPI_ATTR void GetPhysicalDeviceExternalSemaphoreProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, VkExternalSemaphoreProperties* pExternalSemaphoreProperties); +VKAPI_ATTR void GetPhysicalDeviceExternalFenceProperties(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, VkExternalFenceProperties* pExternalFenceProperties); // clang-format on template <typename DispatchableType> diff --git a/vulkan/libvulkan/driver_gen.cpp b/vulkan/libvulkan/driver_gen.cpp index 52205e9e79..6549c370b4 100644 --- a/vulkan/libvulkan/driver_gen.cpp +++ b/vulkan/libvulkan/driver_gen.cpp @@ -363,6 +363,55 @@ const ProcHook g_proc_hooks[] = { reinterpret_cast<PFN_vkVoidFunction>(checkedGetPastPresentationTimingGOOGLE), }, { + "vkGetPhysicalDeviceExternalBufferProperties", + ProcHook::INSTANCE, + ProcHook::EXTENSION_CORE_1_1, + reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceExternalBufferProperties), + nullptr, + }, + { + "vkGetPhysicalDeviceExternalFenceProperties", + ProcHook::INSTANCE, + ProcHook::EXTENSION_CORE_1_1, + reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceExternalFenceProperties), + nullptr, + }, + { + "vkGetPhysicalDeviceExternalSemaphoreProperties", + ProcHook::INSTANCE, + ProcHook::EXTENSION_CORE_1_1, + reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceExternalSemaphoreProperties), + nullptr, + }, + { + "vkGetPhysicalDeviceFeatures2", + ProcHook::INSTANCE, + ProcHook::EXTENSION_CORE_1_1, + reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFeatures2), + nullptr, + }, + { + "vkGetPhysicalDeviceFormatProperties2", + ProcHook::INSTANCE, + ProcHook::EXTENSION_CORE_1_1, + reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFormatProperties2), + nullptr, + }, + { + "vkGetPhysicalDeviceImageFormatProperties2", + ProcHook::INSTANCE, + ProcHook::EXTENSION_CORE_1_1, + reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceImageFormatProperties2), + nullptr, + }, + { + "vkGetPhysicalDeviceMemoryProperties2", + ProcHook::INSTANCE, + ProcHook::EXTENSION_CORE_1_1, + reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceMemoryProperties2), + nullptr, + }, + { "vkGetPhysicalDevicePresentRectanglesKHR", ProcHook::INSTANCE, ProcHook::KHR_swapchain, @@ -370,6 +419,27 @@ const ProcHook g_proc_hooks[] = { nullptr, }, { + "vkGetPhysicalDeviceProperties2", + ProcHook::INSTANCE, + ProcHook::EXTENSION_CORE_1_1, + reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceProperties2), + nullptr, + }, + { + "vkGetPhysicalDeviceQueueFamilyProperties2", + ProcHook::INSTANCE, + ProcHook::EXTENSION_CORE_1_1, + reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceQueueFamilyProperties2), + nullptr, + }, + { + "vkGetPhysicalDeviceSparseImageFormatProperties2", + ProcHook::INSTANCE, + ProcHook::EXTENSION_CORE_1_1, + reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSparseImageFormatProperties2), + nullptr, + }, + { "vkGetPhysicalDeviceSurfaceCapabilities2KHR", ProcHook::INSTANCE, ProcHook::KHR_get_surface_capabilities2, @@ -505,6 +575,10 @@ ProcHook::Extension GetProcHookExtension(const char* name) { if (strcmp(name, "VK_ANDROID_external_memory_android_hardware_buffer") == 0) return ProcHook::ANDROID_external_memory_android_hardware_buffer; if (strcmp(name, "VK_KHR_bind_memory2") == 0) return ProcHook::KHR_bind_memory2; if (strcmp(name, "VK_KHR_get_physical_device_properties2") == 0) return ProcHook::KHR_get_physical_device_properties2; + if (strcmp(name, "VK_KHR_device_group_creation") == 0) return ProcHook::KHR_device_group_creation; + if (strcmp(name, "VK_KHR_external_memory_capabilities") == 0) return ProcHook::KHR_external_memory_capabilities; + if (strcmp(name, "VK_KHR_external_semaphore_capabilities") == 0) return ProcHook::KHR_external_semaphore_capabilities; + if (strcmp(name, "VK_KHR_external_fence_capabilities") == 0) return ProcHook::KHR_external_fence_capabilities; // clang-format on return ProcHook::EXTENSION_UNKNOWN; } @@ -543,9 +617,28 @@ bool InitDriverTable(VkInstance instance, INIT_PROC_EXT(EXT_debug_report, true, instance, CreateDebugReportCallbackEXT); INIT_PROC_EXT(EXT_debug_report, true, instance, DestroyDebugReportCallbackEXT); INIT_PROC_EXT(EXT_debug_report, true, instance, DebugReportMessageEXT); + INIT_PROC(false, instance, GetPhysicalDeviceFeatures2); + INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceFeatures2KHR); INIT_PROC(false, instance, GetPhysicalDeviceProperties2); INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceProperties2KHR); + INIT_PROC(false, instance, GetPhysicalDeviceFormatProperties2); + INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceFormatProperties2KHR); + INIT_PROC(false, instance, GetPhysicalDeviceImageFormatProperties2); + INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceImageFormatProperties2KHR); + INIT_PROC(false, instance, GetPhysicalDeviceQueueFamilyProperties2); + INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceQueueFamilyProperties2KHR); + INIT_PROC(false, instance, GetPhysicalDeviceMemoryProperties2); + INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceMemoryProperties2KHR); + INIT_PROC(false, instance, GetPhysicalDeviceSparseImageFormatProperties2); + INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceSparseImageFormatProperties2KHR); + INIT_PROC(false, instance, GetPhysicalDeviceExternalBufferProperties); + INIT_PROC_EXT(KHR_external_memory_capabilities, true, instance, GetPhysicalDeviceExternalBufferPropertiesKHR); + INIT_PROC(false, instance, GetPhysicalDeviceExternalSemaphoreProperties); + INIT_PROC_EXT(KHR_external_semaphore_capabilities, true, instance, GetPhysicalDeviceExternalSemaphorePropertiesKHR); + INIT_PROC(false, instance, GetPhysicalDeviceExternalFenceProperties); + INIT_PROC_EXT(KHR_external_fence_capabilities, true, instance, GetPhysicalDeviceExternalFencePropertiesKHR); INIT_PROC(false, instance, EnumeratePhysicalDeviceGroups); + INIT_PROC_EXT(KHR_device_group_creation, true, instance, EnumeratePhysicalDeviceGroupsKHR); // clang-format on return success; @@ -577,5 +670,53 @@ bool InitDriverTable(VkDevice dev, return success; } +const std::pair<const char*, uint32_t> g_promoted_instance_extensions[] = { + // clang-format off + std::make_pair("VK_KHR_device_group_creation", VK_API_VERSION_1_1), + std::make_pair("VK_KHR_external_fence_capabilities", VK_API_VERSION_1_1), + std::make_pair("VK_KHR_external_memory_capabilities", VK_API_VERSION_1_1), + std::make_pair("VK_KHR_external_semaphore_capabilities", VK_API_VERSION_1_1), + std::make_pair("VK_KHR_get_physical_device_properties2", VK_API_VERSION_1_1), + // clang-format on +}; + +std::optional<uint32_t> GetInstanceExtensionPromotedVersion(const char* name) { + auto begin = std::cbegin(g_promoted_instance_extensions); + auto end = std::cend(g_promoted_instance_extensions); + auto iter = + std::lower_bound(begin, end, name, + [](const std::pair<const char*, uint32_t>& e, + const char* n) { return strcmp(e.first, n) < 0; }); + return (iter < end && strcmp(iter->first, name) == 0) + ? std::optional<uint32_t>(iter->second) + : std::nullopt; +} + +uint32_t CountPromotedInstanceExtensions(uint32_t begin_version, + uint32_t end_version) { + auto begin = std::cbegin(g_promoted_instance_extensions); + auto end = std::cend(g_promoted_instance_extensions); + uint32_t count = 0; + + for (auto iter = begin; iter != end; iter++) + if (iter->second > begin_version && iter->second <= end_version) + count++; + + return count; +} + +std::vector<const char*> GetPromotedInstanceExtensions(uint32_t begin_version, + uint32_t end_version) { + auto begin = std::cbegin(g_promoted_instance_extensions); + auto end = std::cend(g_promoted_instance_extensions); + std::vector<const char*> extensions; + + for (auto iter = begin; iter != end; iter++) + if (iter->second > begin_version && iter->second <= end_version) + extensions.emplace_back(iter->first); + + return extensions; +} + } // namespace driver } // namespace vulkan diff --git a/vulkan/libvulkan/driver_gen.h b/vulkan/libvulkan/driver_gen.h index 43c4d1469e..1aba674c2c 100644 --- a/vulkan/libvulkan/driver_gen.h +++ b/vulkan/libvulkan/driver_gen.h @@ -23,6 +23,8 @@ #include <vulkan/vulkan.h> #include <bitset> +#include <optional> +#include <vector> namespace vulkan { namespace driver { @@ -48,6 +50,10 @@ struct ProcHook { ANDROID_external_memory_android_hardware_buffer, KHR_bind_memory2, KHR_get_physical_device_properties2, + KHR_device_group_creation, + KHR_external_memory_capabilities, + KHR_external_semaphore_capabilities, + KHR_external_fence_capabilities, EXTENSION_CORE_1_0, EXTENSION_CORE_1_1, @@ -74,9 +80,28 @@ struct InstanceDriverTable { PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT; PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT; PFN_vkDebugReportMessageEXT DebugReportMessageEXT; + PFN_vkGetPhysicalDeviceFeatures2 GetPhysicalDeviceFeatures2; + PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysicalDeviceFeatures2KHR; PFN_vkGetPhysicalDeviceProperties2 GetPhysicalDeviceProperties2; PFN_vkGetPhysicalDeviceProperties2KHR GetPhysicalDeviceProperties2KHR; + PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysicalDeviceFormatProperties2; + PFN_vkGetPhysicalDeviceFormatProperties2KHR GetPhysicalDeviceFormatProperties2KHR; + PFN_vkGetPhysicalDeviceImageFormatProperties2 GetPhysicalDeviceImageFormatProperties2; + PFN_vkGetPhysicalDeviceImageFormatProperties2KHR GetPhysicalDeviceImageFormatProperties2KHR; + PFN_vkGetPhysicalDeviceQueueFamilyProperties2 GetPhysicalDeviceQueueFamilyProperties2; + PFN_vkGetPhysicalDeviceQueueFamilyProperties2KHR GetPhysicalDeviceQueueFamilyProperties2KHR; + PFN_vkGetPhysicalDeviceMemoryProperties2 GetPhysicalDeviceMemoryProperties2; + PFN_vkGetPhysicalDeviceMemoryProperties2KHR GetPhysicalDeviceMemoryProperties2KHR; + PFN_vkGetPhysicalDeviceSparseImageFormatProperties2 GetPhysicalDeviceSparseImageFormatProperties2; + PFN_vkGetPhysicalDeviceSparseImageFormatProperties2KHR GetPhysicalDeviceSparseImageFormatProperties2KHR; + PFN_vkGetPhysicalDeviceExternalBufferProperties GetPhysicalDeviceExternalBufferProperties; + PFN_vkGetPhysicalDeviceExternalBufferPropertiesKHR GetPhysicalDeviceExternalBufferPropertiesKHR; + PFN_vkGetPhysicalDeviceExternalSemaphoreProperties GetPhysicalDeviceExternalSemaphoreProperties; + PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR GetPhysicalDeviceExternalSemaphorePropertiesKHR; + PFN_vkGetPhysicalDeviceExternalFenceProperties GetPhysicalDeviceExternalFenceProperties; + PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR GetPhysicalDeviceExternalFencePropertiesKHR; PFN_vkEnumeratePhysicalDeviceGroups EnumeratePhysicalDeviceGroups; + PFN_vkEnumeratePhysicalDeviceGroupsKHR EnumeratePhysicalDeviceGroupsKHR; // clang-format on }; @@ -109,6 +134,12 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc, const std::bitset<ProcHook::EXTENSION_COUNT>& extensions); +std::optional<uint32_t> GetInstanceExtensionPromotedVersion(const char* name); +uint32_t CountPromotedInstanceExtensions(uint32_t begin_version, + uint32_t end_version); +std::vector<const char*> GetPromotedInstanceExtensions(uint32_t begin_version, + uint32_t end_version); + } // namespace driver } // namespace vulkan diff --git a/vulkan/scripts/driver_generator.py b/vulkan/scripts/driver_generator.py index a64a7026db..566e063a57 100644 --- a/vulkan/scripts/driver_generator.py +++ b/vulkan/scripts/driver_generator.py @@ -40,6 +40,10 @@ _KNOWN_EXTENSIONS = _INTERCEPTED_EXTENSIONS + [ 'VK_ANDROID_external_memory_android_hardware_buffer', 'VK_KHR_bind_memory2', 'VK_KHR_get_physical_device_properties2', + 'VK_KHR_device_group_creation', + 'VK_KHR_external_memory_capabilities', + 'VK_KHR_external_semaphore_capabilities', + 'VK_KHR_external_fence_capabilities', ] # Functions needed at vulkan::driver level. @@ -71,12 +75,41 @@ _NEEDED_COMMANDS = [ 'vkDestroyImage', 'vkGetPhysicalDeviceProperties', - 'vkGetPhysicalDeviceProperties2', - 'vkGetPhysicalDeviceProperties2KHR', # VK_KHR_swapchain v69 requirement 'vkBindImageMemory2', 'vkBindImageMemory2KHR', + + # For promoted VK_KHR_device_group_creation + 'vkEnumeratePhysicalDeviceGroupsKHR', + + # For promoted VK_KHR_get_physical_device_properties2 + 'vkGetPhysicalDeviceFeatures2', + 'vkGetPhysicalDeviceFeatures2KHR', + 'vkGetPhysicalDeviceProperties2', + 'vkGetPhysicalDeviceProperties2KHR', + 'vkGetPhysicalDeviceFormatProperties2', + 'vkGetPhysicalDeviceFormatProperties2KHR', + 'vkGetPhysicalDeviceImageFormatProperties2', + 'vkGetPhysicalDeviceImageFormatProperties2KHR', + 'vkGetPhysicalDeviceQueueFamilyProperties2', + 'vkGetPhysicalDeviceQueueFamilyProperties2KHR', + 'vkGetPhysicalDeviceMemoryProperties2', + 'vkGetPhysicalDeviceMemoryProperties2KHR', + 'vkGetPhysicalDeviceSparseImageFormatProperties2', + 'vkGetPhysicalDeviceSparseImageFormatProperties2KHR', + + # For promoted VK_KHR_external_memory_capabilities + 'vkGetPhysicalDeviceExternalBufferProperties', + 'vkGetPhysicalDeviceExternalBufferPropertiesKHR', + + # For promoted VK_KHR_external_semaphore_capabilities + 'vkGetPhysicalDeviceExternalSemaphoreProperties', + 'vkGetPhysicalDeviceExternalSemaphorePropertiesKHR', + + # For promoted VK_KHR_external_fence_capabilities + 'vkGetPhysicalDeviceExternalFenceProperties', + 'vkGetPhysicalDeviceExternalFencePropertiesKHR', ] # Functions intercepted at vulkan::driver level. @@ -106,6 +139,24 @@ _INTERCEPTED_COMMANDS = [ # VK_KHR_swapchain v69 requirement 'vkBindImageMemory2', 'vkBindImageMemory2KHR', + + # For promoted VK_KHR_get_physical_device_properties2 + 'vkGetPhysicalDeviceFeatures2', + 'vkGetPhysicalDeviceProperties2', + 'vkGetPhysicalDeviceFormatProperties2', + 'vkGetPhysicalDeviceImageFormatProperties2', + 'vkGetPhysicalDeviceQueueFamilyProperties2', + 'vkGetPhysicalDeviceMemoryProperties2', + 'vkGetPhysicalDeviceSparseImageFormatProperties2', + + # For promoted VK_KHR_external_memory_capabilities + 'vkGetPhysicalDeviceExternalBufferProperties', + + # For promoted VK_KHR_external_semaphore_capabilities + 'vkGetPhysicalDeviceExternalSemaphoreProperties', + + # For promoted VK_KHR_external_fence_capabilities + 'vkGetPhysicalDeviceExternalFenceProperties', ] @@ -162,6 +213,8 @@ def gen_h(): #include <vulkan/vulkan.h> #include <bitset> +#include <optional> +#include <vector> namespace vulkan { namespace driver { @@ -229,6 +282,12 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc, const std::bitset<ProcHook::EXTENSION_COUNT>& extensions); +std::optional<uint32_t> GetInstanceExtensionPromotedVersion(const char* name); +uint32_t CountPromotedInstanceExtensions(uint32_t begin_version, + uint32_t end_version); +std::vector<const char*> GetPromotedInstanceExtensions(uint32_t begin_version, + uint32_t end_version); + } // namespace driver } // namespace vulkan @@ -539,6 +598,54 @@ bool InitDriverTable(VkDevice dev, return success; } +const std::pair<const char*, uint32_t> g_promoted_instance_extensions[] = { + // clang-format off\n""") + + for key, value in sorted(gencom.promoted_inst_ext_dict.items()): + f.write(gencom.indent(1) + 'std::make_pair("' + key + '", ' + value + '),\n') + + f.write("""\ + // clang-format on +}; + +std::optional<uint32_t> GetInstanceExtensionPromotedVersion(const char* name) { + auto begin = std::cbegin(g_promoted_instance_extensions); + auto end = std::cend(g_promoted_instance_extensions); + auto iter = + std::lower_bound(begin, end, name, + [](const std::pair<const char*, uint32_t>& e, + const char* n) { return strcmp(e.first, n) < 0; }); + return (iter < end && strcmp(iter->first, name) == 0) + ? std::optional<uint32_t>(iter->second) + : std::nullopt; +} + +uint32_t CountPromotedInstanceExtensions(uint32_t begin_version, + uint32_t end_version) { + auto begin = std::cbegin(g_promoted_instance_extensions); + auto end = std::cend(g_promoted_instance_extensions); + uint32_t count = 0; + + for (auto iter = begin; iter != end; iter++) + if (iter->second > begin_version && iter->second <= end_version) + count++; + + return count; +} + +std::vector<const char*> GetPromotedInstanceExtensions(uint32_t begin_version, + uint32_t end_version) { + auto begin = std::cbegin(g_promoted_instance_extensions); + auto end = std::cend(g_promoted_instance_extensions); + std::vector<const char*> extensions; + + for (auto iter = begin; iter != end; iter++) + if (iter->second > begin_version && iter->second <= end_version) + extensions.emplace_back(iter->first); + + return extensions; +} + } // namespace driver } // namespace vulkan\n""") diff --git a/vulkan/scripts/generator_common.py b/vulkan/scripts/generator_common.py index ef0719db64..ef021f2462 100644 --- a/vulkan/scripts/generator_common.py +++ b/vulkan/scripts/generator_common.py @@ -97,6 +97,9 @@ version_code_list = [] # Dict for mapping a function to the core Vulkan API version. version_dict = {} +# Dict for mapping a promoted instance extension to the core Vulkan API version. +promoted_inst_ext_dict = {} + def indent(num): """Returns the requested indents. @@ -183,6 +186,15 @@ def version_code(version): return version[11:] +def version_2_api_version(version): + """Returns the api version from a version string. + + Args: + version: Vulkan version string. + """ + return 'VK_API' + version[2:] + + def is_function_supported(cmd): """Returns true if a function is core or from a supportable extension. @@ -327,6 +339,7 @@ def parse_vulkan_registry(): return_type_dict version_code_list version_dict + promoted_inst_ext_dict """ registry = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', 'external', 'vulkan-headers', 'registry', 'vk.xml') @@ -379,6 +392,10 @@ def parse_vulkan_registry(): apiversion = '' if extension.tag == 'extension': extname = extension.get('name') + if (extension.get('type') == 'instance' and + extension.get('promotedto') is not None): + promoted_inst_ext_dict[extname] = \ + version_2_api_version(extension.get('promotedto')) for req in extension: if req.get('feature') is not None: apiversion = req.get('feature') diff --git a/vulkan/vkjson/vkjson.h b/vulkan/vkjson/vkjson.h index a283b83d7c..52e7bee288 100644 --- a/vulkan/vkjson/vkjson.h +++ b/vulkan/vkjson/vkjson.h @@ -158,10 +158,7 @@ bool VkJsonInstanceFromJson(const std::string& json, VkJsonInstance* instance, std::string* errors); -VkJsonDevice VkJsonGetDevice(VkInstance instance, - VkPhysicalDevice device, - uint32_t instanceExtensionCount, - const char* const* instanceExtensions); +VkJsonDevice VkJsonGetDevice(VkPhysicalDevice device); std::string VkJsonDeviceToJson(const VkJsonDevice& device); bool VkJsonDeviceFromJson(const std::string& json, VkJsonDevice* device, @@ -177,7 +174,7 @@ bool VkJsonImageFormatPropertiesFromJson(const std::string& json, typedef VkJsonDevice VkJsonAllProperties; inline VkJsonAllProperties VkJsonGetAllProperties( VkPhysicalDevice physicalDevice) { - return VkJsonGetDevice(VK_NULL_HANDLE, physicalDevice, 0, nullptr); + return VkJsonGetDevice(physicalDevice); } inline std::string VkJsonAllPropertiesToJson( const VkJsonAllProperties& properties) { diff --git a/vulkan/vkjson/vkjson_instance.cc b/vulkan/vkjson/vkjson_instance.cc index 84cfe5e00b..ace713b2a4 100644 --- a/vulkan/vkjson/vkjson_instance.cc +++ b/vulkan/vkjson/vkjson_instance.cc @@ -28,8 +28,6 @@ #include <utility> namespace { -const char* kSupportedInstanceExtensions[] = { - "VK_KHR_get_physical_device_properties2"}; bool EnumerateExtensions(const char* layer_name, std::vector<VkExtensionProperties>* extensions) { @@ -47,15 +45,6 @@ bool EnumerateExtensions(const char* layer_name, } bool HasExtension(const char* extension_name, - uint32_t count, - const char* const* extensions) { - return std::find_if(extensions, extensions + count, - [extension_name](const char* extension) { - return strcmp(extension, extension_name) == 0; - }) != extensions + count; -} - -bool HasExtension(const char* extension_name, const std::vector<VkExtensionProperties>& extensions) { return std::find_if(extensions.cbegin(), extensions.cend(), [extension_name](const VkExtensionProperties& extension) { @@ -65,27 +54,9 @@ bool HasExtension(const char* extension_name, } } // anonymous namespace -VkJsonDevice VkJsonGetDevice(VkInstance instance, - VkPhysicalDevice physical_device, - uint32_t instance_extension_count, - const char* const* instance_extensions) { +VkJsonDevice VkJsonGetDevice(VkPhysicalDevice physical_device) { VkJsonDevice device; - PFN_vkGetPhysicalDeviceProperties2KHR vkpGetPhysicalDeviceProperties2KHR = - nullptr; - PFN_vkGetPhysicalDeviceFeatures2KHR vkpGetPhysicalDeviceFeatures2KHR = - nullptr; - if (instance != VK_NULL_HANDLE && - HasExtension("VK_KHR_get_physical_device_properties2", - instance_extension_count, instance_extensions)) { - vkpGetPhysicalDeviceProperties2KHR = - reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2KHR>( - vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceProperties2KHR")); - vkpGetPhysicalDeviceFeatures2KHR = - reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures2KHR>( - vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceFeatures2KHR")); - } - uint32_t extension_count = 0; vkEnumerateDeviceExtensionProperties(physical_device, nullptr, &extension_count, nullptr); @@ -103,55 +74,48 @@ VkJsonDevice VkJsonGetDevice(VkInstance instance, device.layers.data()); } - if (HasExtension("VK_KHR_get_physical_device_properties2", - instance_extension_count, instance_extensions)) { - VkPhysicalDeviceProperties2KHR properties = { - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR, - nullptr, - {} // properties - }; - if (HasExtension("VK_KHR_driver_properties", device.extensions)) { - device.ext_driver_properties.reported = true; - device.ext_driver_properties.driver_properties_khr.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR; - device.ext_driver_properties.driver_properties_khr.pNext = - properties.pNext; - properties.pNext = - &device.ext_driver_properties.driver_properties_khr; - } - vkpGetPhysicalDeviceProperties2KHR(physical_device, &properties); - device.properties = properties.properties; + VkPhysicalDeviceProperties2 properties = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, + nullptr, + {}, + }; + if (HasExtension("VK_KHR_driver_properties", device.extensions)) { + device.ext_driver_properties.reported = true; + device.ext_driver_properties.driver_properties_khr.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR; + device.ext_driver_properties.driver_properties_khr.pNext = properties.pNext; + properties.pNext = &device.ext_driver_properties.driver_properties_khr; + } + vkGetPhysicalDeviceProperties2(physical_device, &properties); + device.properties = properties.properties; - VkPhysicalDeviceFeatures2KHR features = { - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR, - nullptr, - {} // features - }; - if (HasExtension("VK_KHR_variable_pointers", device.extensions)) { - device.ext_variable_pointer_features.reported = true; - device.ext_variable_pointer_features.variable_pointer_features_khr.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR; - device.ext_variable_pointer_features.variable_pointer_features_khr.pNext = - features.pNext; - features.pNext = - &device.ext_variable_pointer_features.variable_pointer_features_khr; - } - if (HasExtension("VK_KHR_shader_float16_int8", device.extensions)) { - device.ext_shader_float16_int8_features.reported = true; - device.ext_shader_float16_int8_features.shader_float16_int8_features_khr - .sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR; - device.ext_shader_float16_int8_features.shader_float16_int8_features_khr - .pNext = features.pNext; - features.pNext = &device.ext_shader_float16_int8_features - .shader_float16_int8_features_khr; - } - vkpGetPhysicalDeviceFeatures2KHR(physical_device, &features); - device.features = features.features; - } else { - vkGetPhysicalDeviceProperties(physical_device, &device.properties); - vkGetPhysicalDeviceFeatures(physical_device, &device.features); + VkPhysicalDeviceFeatures2 features = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, + nullptr, + {}, + }; + if (HasExtension("VK_KHR_variable_pointers", device.extensions)) { + device.ext_variable_pointer_features.reported = true; + device.ext_variable_pointer_features.variable_pointer_features_khr.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR; + device.ext_variable_pointer_features.variable_pointer_features_khr.pNext = + features.pNext; + features.pNext = + &device.ext_variable_pointer_features.variable_pointer_features_khr; + } + if (HasExtension("VK_KHR_shader_float16_int8", device.extensions)) { + device.ext_shader_float16_int8_features.reported = true; + device.ext_shader_float16_int8_features.shader_float16_int8_features_khr + .sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR; + device.ext_shader_float16_int8_features.shader_float16_int8_features_khr + .pNext = features.pNext; + features.pNext = &device.ext_shader_float16_int8_features + .shader_float16_int8_features_khr; } + vkGetPhysicalDeviceFeatures2(physical_device, &features); + device.features = features.features; + vkGetPhysicalDeviceMemoryProperties(physical_device, &device.memory); uint32_t queue_family_count = 0; @@ -189,135 +153,117 @@ VkJsonDevice VkJsonGetDevice(VkInstance instance, } } - PFN_vkGetPhysicalDeviceProperties2 vkpGetPhysicalDeviceProperties2 = - reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2>( - vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceProperties2")); - if (vkpGetPhysicalDeviceProperties2) { - VkPhysicalDeviceProperties2 properties2 = { - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, nullptr, {}}; - - device.subgroup_properties.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES; - device.subgroup_properties.pNext = properties2.pNext; - properties2.pNext = &device.subgroup_properties; - - device.point_clipping_properties.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES; - device.point_clipping_properties.pNext = properties2.pNext; - properties2.pNext = &device.point_clipping_properties; - - device.multiview_properties.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES; - device.multiview_properties.pNext = properties2.pNext; - properties2.pNext = &device.multiview_properties; - - device.id_properties.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES; - device.id_properties.pNext = properties2.pNext; - properties2.pNext = &device.id_properties; - - device.maintenance3_properties.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES; - device.maintenance3_properties.pNext = properties2.pNext; - properties2.pNext = &device.maintenance3_properties; - - (*vkpGetPhysicalDeviceProperties2)(physical_device, &properties2); - } + VkPhysicalDeviceProperties2 properties2 = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, + nullptr, + {}, + }; - PFN_vkGetPhysicalDeviceFeatures2 vkpGetPhysicalDeviceFeatures2 = - reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures2>( - vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceFeatures2")); - if (vkpGetPhysicalDeviceFeatures2) { - VkPhysicalDeviceFeatures2 features2 = { - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, nullptr, {}}; - - device.bit16_storage_features.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES; - device.bit16_storage_features.pNext = features2.pNext; - features2.pNext = &device.bit16_storage_features; - - device.multiview_features.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES; - device.multiview_features.pNext = features2.pNext; - features2.pNext = &device.multiview_features; - - device.variable_pointer_features.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES; - device.variable_pointer_features.pNext = features2.pNext; - features2.pNext = &device.variable_pointer_features; - - device.protected_memory_features.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES; - device.protected_memory_features.pNext = features2.pNext; - features2.pNext = &device.protected_memory_features; - - device.sampler_ycbcr_conversion_features.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES; - device.sampler_ycbcr_conversion_features.pNext = features2.pNext; - features2.pNext = &device.sampler_ycbcr_conversion_features; - - device.shader_draw_parameter_features.sType = - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES; - device.shader_draw_parameter_features.pNext = features2.pNext; - features2.pNext = &device.shader_draw_parameter_features; - - (*vkpGetPhysicalDeviceFeatures2)(physical_device, &features2); - } + device.subgroup_properties.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES; + device.subgroup_properties.pNext = properties2.pNext; + properties2.pNext = &device.subgroup_properties; + + device.point_clipping_properties.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES; + device.point_clipping_properties.pNext = properties2.pNext; + properties2.pNext = &device.point_clipping_properties; + + device.multiview_properties.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES; + device.multiview_properties.pNext = properties2.pNext; + properties2.pNext = &device.multiview_properties; + + device.id_properties.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES; + device.id_properties.pNext = properties2.pNext; + properties2.pNext = &device.id_properties; + + device.maintenance3_properties.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES; + device.maintenance3_properties.pNext = properties2.pNext; + properties2.pNext = &device.maintenance3_properties; + + vkGetPhysicalDeviceProperties2(physical_device, &properties2); + + VkPhysicalDeviceFeatures2 features2 = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, + nullptr, + {}, + }; - PFN_vkGetPhysicalDeviceExternalFenceProperties - vkpGetPhysicalDeviceExternalFenceProperties = - reinterpret_cast<PFN_vkGetPhysicalDeviceExternalFenceProperties>( - vkGetInstanceProcAddr( - instance, "vkGetPhysicalDeviceExternalFenceProperties")); - if (vkpGetPhysicalDeviceExternalFenceProperties) { - VkPhysicalDeviceExternalFenceInfo external_fence_info = { - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO, nullptr, - VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT}; - VkExternalFenceProperties external_fence_properties = {}; - - for (VkExternalFenceHandleTypeFlagBits handle_type = - VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT; - handle_type <= VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT; - handle_type = static_cast<VkExternalFenceHandleTypeFlagBits>( - handle_type << 1)) { - external_fence_info.handleType = handle_type; - (*vkpGetPhysicalDeviceExternalFenceProperties)( - physical_device, &external_fence_info, &external_fence_properties); - if (external_fence_properties.exportFromImportedHandleTypes || - external_fence_properties.compatibleHandleTypes || - external_fence_properties.externalFenceFeatures) { - device.external_fence_properties.insert( - std::make_pair(handle_type, external_fence_properties)); - } + device.bit16_storage_features.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES; + device.bit16_storage_features.pNext = features2.pNext; + features2.pNext = &device.bit16_storage_features; + + device.multiview_features.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES; + device.multiview_features.pNext = features2.pNext; + features2.pNext = &device.multiview_features; + + device.variable_pointer_features.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES; + device.variable_pointer_features.pNext = features2.pNext; + features2.pNext = &device.variable_pointer_features; + + device.protected_memory_features.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES; + device.protected_memory_features.pNext = features2.pNext; + features2.pNext = &device.protected_memory_features; + + device.sampler_ycbcr_conversion_features.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES; + device.sampler_ycbcr_conversion_features.pNext = features2.pNext; + features2.pNext = &device.sampler_ycbcr_conversion_features; + + device.shader_draw_parameter_features.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES; + device.shader_draw_parameter_features.pNext = features2.pNext; + features2.pNext = &device.shader_draw_parameter_features; + + vkGetPhysicalDeviceFeatures2(physical_device, &features2); + + VkPhysicalDeviceExternalFenceInfo external_fence_info = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO, nullptr, + VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT}; + VkExternalFenceProperties external_fence_properties = {}; + + for (VkExternalFenceHandleTypeFlagBits handle_type = + VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT; + handle_type <= VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT; + handle_type = + static_cast<VkExternalFenceHandleTypeFlagBits>(handle_type << 1)) { + external_fence_info.handleType = handle_type; + vkGetPhysicalDeviceExternalFenceProperties( + physical_device, &external_fence_info, &external_fence_properties); + if (external_fence_properties.exportFromImportedHandleTypes || + external_fence_properties.compatibleHandleTypes || + external_fence_properties.externalFenceFeatures) { + device.external_fence_properties.insert( + std::make_pair(handle_type, external_fence_properties)); } } - PFN_vkGetPhysicalDeviceExternalSemaphoreProperties - vkpGetPhysicalDeviceExternalSemaphoreProperties = reinterpret_cast< - PFN_vkGetPhysicalDeviceExternalSemaphoreProperties>( - vkGetInstanceProcAddr( - instance, "vkGetPhysicalDeviceExternalSemaphoreProperties")); - if (vkpGetPhysicalDeviceExternalSemaphoreProperties) { - VkPhysicalDeviceExternalSemaphoreInfo external_semaphore_info = { - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO, nullptr, - VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT}; - VkExternalSemaphoreProperties external_semaphore_properties = {}; - - for (VkExternalSemaphoreHandleTypeFlagBits handle_type = - VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT; - handle_type <= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; - handle_type = static_cast<VkExternalSemaphoreHandleTypeFlagBits>( - handle_type << 1)) { - external_semaphore_info.handleType = handle_type; - (*vkpGetPhysicalDeviceExternalSemaphoreProperties)( - physical_device, &external_semaphore_info, - &external_semaphore_properties); - if (external_semaphore_properties.exportFromImportedHandleTypes || - external_semaphore_properties.compatibleHandleTypes || - external_semaphore_properties.externalSemaphoreFeatures) { - device.external_semaphore_properties.insert( - std::make_pair(handle_type, external_semaphore_properties)); - } + VkPhysicalDeviceExternalSemaphoreInfo external_semaphore_info = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO, nullptr, + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT}; + VkExternalSemaphoreProperties external_semaphore_properties = {}; + + for (VkExternalSemaphoreHandleTypeFlagBits handle_type = + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT; + handle_type <= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; + handle_type = static_cast<VkExternalSemaphoreHandleTypeFlagBits>( + handle_type << 1)) { + external_semaphore_info.handleType = handle_type; + vkGetPhysicalDeviceExternalSemaphoreProperties( + physical_device, &external_semaphore_info, + &external_semaphore_properties); + if (external_semaphore_properties.exportFromImportedHandleTypes || + external_semaphore_properties.compatibleHandleTypes || + external_semaphore_properties.externalSemaphoreFeatures) { + device.external_semaphore_properties.insert( + std::make_pair(handle_type, external_semaphore_properties)); } } } @@ -351,19 +297,15 @@ VkJsonInstance VkJsonGetInstance() { if (!EnumerateExtensions(nullptr, &instance.extensions)) return VkJsonInstance(); - std::vector<const char*> instance_extensions; - for (const auto extension : kSupportedInstanceExtensions) { - if (HasExtension(extension, instance.extensions)) - instance_extensions.push_back(extension); - } - - const VkApplicationInfo app_info = {VK_STRUCTURE_TYPE_APPLICATION_INFO, - nullptr, - "vkjson_info", - 1, - "", - 0, - VK_API_VERSION_1_1}; + const VkApplicationInfo app_info = { + VK_STRUCTURE_TYPE_APPLICATION_INFO, + nullptr, + "vkjson_info", + 1, + "", + 0, + VK_API_VERSION_1_1, + }; VkInstanceCreateInfo instance_info = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, nullptr, @@ -371,8 +313,9 @@ VkJsonInstance VkJsonGetInstance() { &app_info, 0, nullptr, - static_cast<uint32_t>(instance_extensions.size()), - instance_extensions.data()}; + 0, + nullptr, + }; VkInstance vkinstance; result = vkCreateInstance(&instance_info, nullptr, &vkinstance); if (result != VK_SUCCESS) @@ -397,52 +340,38 @@ VkJsonInstance VkJsonGetInstance() { instance.devices.reserve(sz); for (uint32_t i = 0; i < sz; ++i) { device_map.insert(std::make_pair(devices[i], i)); - instance.devices.emplace_back(VkJsonGetDevice(vkinstance, devices[i], - instance_extensions.size(), - instance_extensions.data())); + instance.devices.emplace_back(VkJsonGetDevice(devices[i])); } - PFN_vkEnumerateInstanceVersion vkpEnumerateInstanceVersion = - reinterpret_cast<PFN_vkEnumerateInstanceVersion>( - vkGetInstanceProcAddr(nullptr, "vkEnumerateInstanceVersion")); - if (!vkpEnumerateInstanceVersion) { - instance.api_version = VK_API_VERSION_1_0; - } else { - result = (*vkpEnumerateInstanceVersion)(&instance.api_version); - if (result != VK_SUCCESS) { - vkDestroyInstance(vkinstance, nullptr); - return VkJsonInstance(); - } + result = vkEnumerateInstanceVersion(&instance.api_version); + if (result != VK_SUCCESS) { + vkDestroyInstance(vkinstance, nullptr); + return VkJsonInstance(); } - PFN_vkEnumeratePhysicalDeviceGroups vkpEnumeratePhysicalDeviceGroups = - reinterpret_cast<PFN_vkEnumeratePhysicalDeviceGroups>( - vkGetInstanceProcAddr(vkinstance, "vkEnumeratePhysicalDeviceGroups")); - if (vkpEnumeratePhysicalDeviceGroups) { - count = 0; - result = (*vkpEnumeratePhysicalDeviceGroups)(vkinstance, &count, nullptr); - if (result != VK_SUCCESS) { - vkDestroyInstance(vkinstance, nullptr); - return VkJsonInstance(); - } + count = 0; + result = vkEnumeratePhysicalDeviceGroups(vkinstance, &count, nullptr); + if (result != VK_SUCCESS) { + vkDestroyInstance(vkinstance, nullptr); + return VkJsonInstance(); + } - VkJsonDeviceGroup device_group; - std::vector<VkPhysicalDeviceGroupProperties> group_properties; - group_properties.resize(count); - result = (*vkpEnumeratePhysicalDeviceGroups)(vkinstance, &count, - group_properties.data()); - if (result != VK_SUCCESS) { - vkDestroyInstance(vkinstance, nullptr); - return VkJsonInstance(); - } - for (auto properties : group_properties) { - device_group.properties = properties; - for (uint32_t i = 0; i < properties.physicalDeviceCount; ++i) { - device_group.device_inds.push_back( - device_map[properties.physicalDevices[i]]); - } - instance.device_groups.push_back(device_group); + VkJsonDeviceGroup device_group; + std::vector<VkPhysicalDeviceGroupProperties> group_properties; + group_properties.resize(count); + result = vkEnumeratePhysicalDeviceGroups(vkinstance, &count, + group_properties.data()); + if (result != VK_SUCCESS) { + vkDestroyInstance(vkinstance, nullptr); + return VkJsonInstance(); + } + for (auto properties : group_properties) { + device_group.properties = properties; + for (uint32_t i = 0; i < properties.physicalDeviceCount; ++i) { + device_group.device_inds.push_back( + device_map[properties.physicalDevices[i]]); } + instance.device_groups.push_back(device_group); } vkDestroyInstance(vkinstance, nullptr); |