Skip to content

Commit b6b4b1f

Browse files
John BaumanCommit Bot
authored andcommitted
[graphics] Fix loader API flag checking
The loaders were incorrectly checking IcdFlags, so the Vulkan loader was attempting to load OpenCL ICDs and the OpenCL loader was attempting to load Vulkan ICDs. Change-Id: Id925e309bc1f43e788825e464b917886b0a7d479 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/638634 Fuchsia-Auto-Submit: John Bauman <[email protected]> Reviewed-by: Jamie Howarth <[email protected]> Commit-Queue: Auto-Submit <[email protected]>
1 parent e6e4bce commit b6b4b1f

File tree

8 files changed

+20
-2
lines changed

8 files changed

+20
-2
lines changed

src/graphics/bin/opencl_loader/app.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class LoaderApp {
8181
std::optional<zx::vmo> GetMatchingIcd(const std::string& system_lib_name);
8282

8383
size_t device_count() const { return devices_.size(); }
84+
const std::vector<std::unique_ptr<GpuDevice>>& devices() const { return devices_; }
8485

8586
async_dispatcher_t* fdio_loop_dispatcher() { return fdio_loop_.dispatcher(); }
8687

src/graphics/bin/opencl_loader/icd_list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class IcdList {
2626
// Finds an ICD in the list with a `library_path` matching this string.
2727
std::optional<zx::vmo> GetVmoMatchingSystemLib(const std::string& library_path) const;
2828

29+
size_t ComponentCount() const { return components_.size(); }
30+
2931
private:
3032
inspect::StringProperty active_icd_;
3133
std::vector<std::shared_ptr<IcdComponent>> components_;

src/graphics/bin/opencl_loader/magma_device.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bool MagmaDevice::Initialize(int dir_fd, const std::string& name, inspect::Node*
6868
data.node = node().CreateChild(std::to_string(i++));
6969
data.node.CreateString("component_url", icd.component_url(), &data.values);
7070
data.node.CreateUint("flags", static_cast<uint32_t>(icd.flags()), &data.values);
71-
if (icd.flags().SUPPORTS_OPENCL) {
71+
if (icd.flags() & fuchsia::gpu::magma::IcdFlags::SUPPORTS_OPENCL) {
7272
icd_list_.Add(app()->CreateIcdComponent(icd.component_url()));
7373
}
7474

src/graphics/bin/opencl_loader/test/unittest.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class FakeMagmaDevice : public fuchsia::gpu::magma::testing::Device_TestBase {
4242
info.set_flags(fuchsia::gpu::magma::IcdFlags::SUPPORTS_OPENCL);
4343
std::vector<fuchsia::gpu::magma::IcdInfo> vec;
4444
vec.push_back(std::move(info));
45+
info.set_component_url("b");
46+
info.set_flags(fuchsia::gpu::magma::IcdFlags::SUPPORTS_VULKAN);
47+
vec.push_back(std::move(info));
4548
callback(std::move(vec));
4649
}
4750
fidl::InterfaceRequestHandler<fuchsia::gpu::magma::Device> GetHandler() {
@@ -80,6 +83,9 @@ TEST_F(LoaderUnittest, MagmaDevice) {
8083
RunLoopUntil([&device_ptr]() { return device_ptr->icd_count() > 0; });
8184
EXPECT_EQ(1u, app.device_count());
8285

86+
// Only 1 ICD listed supports OpenCL.
87+
EXPECT_EQ(1u, static_cast<MagmaDevice*>(app.devices()[0].get())->icd_list().ComponentCount());
88+
8389
async::PostTask(vfs_loop.dispatcher(), [&magma_device]() { magma_device.CloseAll(); });
8490
RunLoopUntil([&app]() { return app.device_count() == 0; });
8591
EXPECT_EQ(0u, app.device_count());

src/graphics/bin/vulkan_loader/app.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class LoaderApp {
8181
std::optional<zx::vmo> GetMatchingIcd(const std::string& system_lib_name);
8282

8383
size_t device_count() const { return devices_.size(); }
84+
const std::vector<std::unique_ptr<GpuDevice>>& devices() const { return devices_; }
8485

8586
async_dispatcher_t* fdio_loop_dispatcher() { return fdio_loop_.dispatcher(); }
8687

src/graphics/bin/vulkan_loader/icd_list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class IcdList {
2626
// Finds an ICD in the list with a `library_path` matching this string.
2727
std::optional<zx::vmo> GetVmoMatchingSystemLib(const std::string& library_path) const;
2828

29+
size_t ComponentCount() const { return components_.size(); }
30+
2931
private:
3032
inspect::StringProperty active_icd_;
3133
std::vector<std::shared_ptr<IcdComponent>> components_;

src/graphics/bin/vulkan_loader/magma_device.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bool MagmaDevice::Initialize(int dir_fd, std::string name, inspect::Node* parent
6868
data.node = node().CreateChild(std::to_string(i++));
6969
data.node.CreateString("component_url", icd.component_url(), &data.values);
7070
data.node.CreateUint("flags", static_cast<uint32_t>(icd.flags()), &data.values);
71-
if (icd.flags().SUPPORTS_VULKAN) {
71+
if (icd.flags() & fuchsia::gpu::magma::IcdFlags::SUPPORTS_VULKAN) {
7272
icd_list_.Add(app()->CreateIcdComponent(icd.component_url()));
7373
}
7474

src/graphics/bin/vulkan_loader/test/unittest.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class FakeMagmaDevice : public fuchsia::gpu::magma::testing::Device_TestBase {
4444
info.set_flags(fuchsia::gpu::magma::IcdFlags::SUPPORTS_VULKAN);
4545
std::vector<fuchsia::gpu::magma::IcdInfo> vec;
4646
vec.push_back(std::move(info));
47+
info.set_component_url("b");
48+
info.set_flags(fuchsia::gpu::magma::IcdFlags::SUPPORTS_OPENCL);
49+
vec.push_back(std::move(info));
4750
callback(std::move(vec));
4851
}
4952
fidl::InterfaceRequestHandler<fuchsia::gpu::magma::Device> GetHandler() {
@@ -82,6 +85,9 @@ TEST_F(LoaderUnittest, MagmaDevice) {
8285
RunLoopUntil([&device_ptr]() { return device_ptr->icd_count() > 0; });
8386
EXPECT_EQ(1u, app.device_count());
8487

88+
// Only 1 ICD listed supports Vulkan.
89+
EXPECT_EQ(1u, static_cast<MagmaDevice*>(app.devices()[0].get())->icd_list().ComponentCount());
90+
8591
async::PostTask(vfs_loop.dispatcher(), [&magma_device]() { magma_device.CloseAll(); });
8692
RunLoopUntil([&app]() { return app.device_count() == 0; });
8793
EXPECT_EQ(0u, app.device_count());

0 commit comments

Comments
 (0)