1/*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
4 *
5 * Copyright (c) 2022 Google, Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Fuchsia Platform definition.
22 *//*--------------------------------------------------------------------*/
23
24#include "tcuFunctionLibrary.hpp"
25#include "tcuPlatform.hpp"
26#include "vkPlatform.hpp"
27
28class FuchsiaVkLibrary : public vk::Library {
29public:
30    FuchsiaVkLibrary(const char* library_path)
31        : library_(library_path ? library_path : "libvulkan.so"), driver_(library_) {}
32
33    const vk::PlatformInterface& getPlatformInterface() const {
34        return driver_;
35    }
36    const tcu::FunctionLibrary&             getFunctionLibrary              (void) const
37    {
38            return library_;
39    }
40
41private:
42    const tcu::DynamicFunctionLibrary library_;
43    const vk::PlatformDriver driver_;
44};
45
46class FuchsiaVkPlatform : public vk::Platform {
47public:
48    vk::Library* createLibrary(const char* library_path) const {
49        return new FuchsiaVkLibrary(library_path);
50    }
51
52    void describePlatform (std::ostream& dst) const
53    {
54        dst << "OS: Fuchsia\n";
55        const char* cpu = "Unknown";
56#if defined(__x86_64__)
57        cpu = "x86_64";
58#elif defined(__aarch64__)
59        cpu = "aarch64";
60#endif
61        dst << "CPU: " << cpu << "\n";
62    }
63
64    void getMemoryLimits(tcu::PlatformMemoryLimits& limits) const {
65        // Copied from tcuX11VulkanPlatform.cpp
66        limits.totalSystemMemory = 256 * 1024 * 1024;
67        limits.totalDeviceLocalMemory = 0; // unified memory
68        limits.deviceMemoryAllocationGranularity = 64 * 1024;
69        limits.devicePageSize = 4096;
70        limits.devicePageTableEntrySize = 8;
71        limits.devicePageTableHierarchyLevels = 3;
72    }
73};
74
75class FuchsiaPlatform : public tcu::Platform {
76public:
77    ~FuchsiaPlatform() {}
78
79    const vk::Platform& getVulkanPlatform() const { return vk_platform_; }
80
81private:
82    FuchsiaVkPlatform vk_platform_;
83};
84
85tcu::Platform* createPlatform() {
86    return new FuchsiaPlatform();
87}
88