Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 1 | // Copyright 2018 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef VK_CONFIG_HPP_ |
| 16 | #define VK_CONFIG_HPP_ |
| 17 | |
Antonio Maiorano | 42fd159 | 2020-04-27 11:30:40 -0400 | [diff] [blame] | 18 | #include "Version.hpp" |
Nicolas Capens | b7b7cb7 | 2021-09-29 14:02:53 -0400 | [diff] [blame] | 19 | #include "Device/Config.hpp" |
Antonio Maiorano | 42fd159 | 2020-04-27 11:30:40 -0400 | [diff] [blame] | 20 | #include "Vulkan/VulkanPlatform.hpp" |
Sean Risser | 019feda | 2020-11-09 14:19:27 -0500 | [diff] [blame] | 21 | #include "spirv-tools/libspirv.h" |
Nicolas Capens | ee841c5 | 2018-11-13 14:18:26 -0500 | [diff] [blame] | 22 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 23 | namespace vk { |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 24 | |
| 25 | // Note: Constant array initialization requires a string literal. |
| 26 | // constexpr char* or char[] does not work for that purpose. |
Antonio Maiorano | 71c49f8 | 2020-04-27 11:33:30 -0400 | [diff] [blame] | 27 | #define SWIFTSHADER_DEVICE_NAME "SwiftShader Device" // Max length: VK_MAX_PHYSICAL_DEVICE_NAME_SIZE |
| 28 | #define SWIFTSHADER_UUID "SwiftShaderUUID" // Max length: VK_UUID_SIZE (16) |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 29 | |
sugoi1 | ff53562 | 2022-01-27 16:49:13 -0500 | [diff] [blame] | 30 | constexpr spv_target_env SPIRV_VERSION = SPV_ENV_VULKAN_1_3; |
Sean Risser | 019feda | 2020-11-09 14:19:27 -0500 | [diff] [blame] | 31 | |
sugoi1 | ff53562 | 2022-01-27 16:49:13 -0500 | [diff] [blame] | 32 | constexpr uint32_t API_VERSION = VK_API_VERSION_1_3; |
Nicolas Capens | b7b7cb7 | 2021-09-29 14:02:53 -0400 | [diff] [blame] | 33 | constexpr uint32_t DRIVER_VERSION = VK_MAKE_VERSION(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION); |
| 34 | constexpr uint32_t VENDOR_ID = 0x1AE0; // Google, Inc.: https://pcisig.com/google-inc-1 |
| 35 | constexpr uint32_t DEVICE_ID = 0xC0DE; // SwiftShader (placeholder) |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 36 | |
Nicolas Capens | 0134dd8 | 2022-07-27 16:12:46 -0400 | [diff] [blame] | 37 | // "Allocations returned by vkAllocateMemory are guaranteed to meet any alignment requirement of the implementation." |
| 38 | constexpr VkDeviceSize DEVICE_MEMORY_ALLOCATION_ALIGNMENT = 256; |
Nicolas Capens | 52b5aae | 2019-05-24 16:27:55 -0400 | [diff] [blame] | 39 | |
Nicolas Capens | 80aaa8a | 2022-07-27 14:43:42 -0400 | [diff] [blame] | 40 | constexpr VkDeviceSize MIN_MEMORY_MAP_ALIGNMENT = 64; |
| 41 | static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_MEMORY_MAP_ALIGNMENT); |
| 42 | |
Nicolas Capens | 39787ac | 2022-07-27 12:29:52 -0400 | [diff] [blame] | 43 | constexpr VkDeviceSize MIN_IMPORTED_HOST_POINTER_ALIGNMENT = 4096; |
Nicolas Capens | 0134dd8 | 2022-07-27 16:12:46 -0400 | [diff] [blame] | 44 | static_assert(MIN_IMPORTED_HOST_POINTER_ALIGNMENT >= DEVICE_MEMORY_ALLOCATION_ALIGNMENT); |
Nicolas Capens | 39787ac | 2022-07-27 12:29:52 -0400 | [diff] [blame] | 45 | |
Nicolas Capens | b7b7cb7 | 2021-09-29 14:02:53 -0400 | [diff] [blame] | 46 | // Vulkan 1.2 requires buffer offset alignment to be at most 256. |
| 47 | constexpr VkDeviceSize MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT = 256; |
| 48 | constexpr VkDeviceSize MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT = 256; |
| 49 | constexpr VkDeviceSize MIN_STORAGE_BUFFER_OFFSET_ALIGNMENT = 256; |
Nicolas Capens | 0134dd8 | 2022-07-27 16:12:46 -0400 | [diff] [blame] | 50 | static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT); |
| 51 | static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT); |
| 52 | static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_STORAGE_BUFFER_OFFSET_ALIGNMENT); |
| 53 | |
| 54 | // Alignment of all other Vulkan resources. |
| 55 | constexpr VkDeviceSize MEMORY_REQUIREMENTS_OFFSET_ALIGNMENT = 16; // 16 bytes for 128-bit vector types. |
| 56 | static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MEMORY_REQUIREMENTS_OFFSET_ALIGNMENT); |
| 57 | |
| 58 | constexpr VkDeviceSize HOST_MEMORY_ALLOCATION_ALIGNMENT = 16; // 16 bytes for 128-bit vector types. |
Nicolas Capens | bd54e07 | 2019-04-25 23:28:28 -0400 | [diff] [blame] | 59 | |
Nicolas Capens | b7b7cb7 | 2021-09-29 14:02:53 -0400 | [diff] [blame] | 60 | constexpr uint32_t MEMORY_TYPE_GENERIC_BIT = 0x1; // Generic system memory. |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 61 | |
Nicolas Capens | 0625115 | 2021-09-29 17:37:58 -0400 | [diff] [blame] | 62 | constexpr uint32_t MAX_IMAGE_LEVELS_1D = 15; |
| 63 | constexpr uint32_t MAX_IMAGE_LEVELS_2D = 15; |
Nicolas Capens | b7b7cb7 | 2021-09-29 14:02:53 -0400 | [diff] [blame] | 64 | constexpr uint32_t MAX_IMAGE_LEVELS_3D = 12; |
Nicolas Capens | 0625115 | 2021-09-29 17:37:58 -0400 | [diff] [blame] | 65 | constexpr uint32_t MAX_IMAGE_LEVELS_CUBE = 15; |
Nicolas Capens | b7b7cb7 | 2021-09-29 14:02:53 -0400 | [diff] [blame] | 66 | constexpr uint32_t MAX_IMAGE_ARRAY_LAYERS = 2048; |
| 67 | constexpr float MAX_SAMPLER_LOD_BIAS = 15.0; |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 68 | |
Nicolas Capens | b7b7cb7 | 2021-09-29 14:02:53 -0400 | [diff] [blame] | 69 | static_assert(MAX_IMAGE_LEVELS_1D <= sw::MIPMAP_LEVELS); |
| 70 | static_assert(MAX_IMAGE_LEVELS_2D <= sw::MIPMAP_LEVELS); |
| 71 | static_assert(MAX_IMAGE_LEVELS_3D <= sw::MIPMAP_LEVELS); |
| 72 | static_assert(MAX_IMAGE_LEVELS_CUBE <= sw::MIPMAP_LEVELS); |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 73 | |
Nicolas Capens | b7b7cb7 | 2021-09-29 14:02:53 -0400 | [diff] [blame] | 74 | constexpr uint32_t MAX_BOUND_DESCRIPTOR_SETS = 4; |
| 75 | constexpr uint32_t MAX_VERTEX_INPUT_BINDINGS = 16; |
| 76 | constexpr uint32_t MAX_PUSH_CONSTANT_SIZE = 128; |
Alexis Hetu | 2ede378 | 2022-08-30 12:01:15 -0400 | [diff] [blame] | 77 | constexpr uint32_t MAX_UPDATE_AFTER_BIND_DESCRIPTORS = 500000; |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 78 | |
Nicolas Capens | b7b7cb7 | 2021-09-29 14:02:53 -0400 | [diff] [blame] | 79 | constexpr uint32_t MAX_DESCRIPTOR_SET_UNIFORM_BUFFERS_DYNAMIC = 8; |
| 80 | constexpr uint32_t MAX_DESCRIPTOR_SET_STORAGE_BUFFERS_DYNAMIC = 4; |
| 81 | constexpr uint32_t MAX_DESCRIPTOR_SET_COMBINED_BUFFERS_DYNAMIC = |
| 82 | MAX_DESCRIPTOR_SET_UNIFORM_BUFFERS_DYNAMIC + |
| 83 | MAX_DESCRIPTOR_SET_STORAGE_BUFFERS_DYNAMIC; |
| 84 | |
Alexis Hetu | 9f14d0b | 2021-10-29 11:09:23 -0400 | [diff] [blame] | 85 | constexpr uint32_t MAX_COMPUTE_WORKGROUP_INVOCATIONS = 256; |
| 86 | |
Alexis Hetu | 8941bde | 2021-11-17 17:45:40 -0500 | [diff] [blame] | 87 | constexpr size_t MAX_INLINE_UNIFORM_BLOCK_SIZE = 256; |
| 88 | |
Nicolas Capens | b7b7cb7 | 2021-09-29 14:02:53 -0400 | [diff] [blame] | 89 | constexpr float MAX_POINT_SIZE = 1023.0; |
Chris Forbes | 54c4772 | 2019-02-25 13:35:59 -0800 | [diff] [blame] | 90 | |
Nicolas Capens | 8532b0f | 2021-05-20 02:52:30 -0400 | [diff] [blame] | 91 | constexpr int MAX_SAMPLER_ALLOCATION_COUNT = 4000; |
| 92 | |
Antonio Maiorano | ae022fa | 2019-10-07 12:57:19 -0400 | [diff] [blame] | 93 | constexpr int SUBPIXEL_PRECISION_BITS = 4; |
| 94 | constexpr float SUBPIXEL_PRECISION_FACTOR = static_cast<float>(1 << SUBPIXEL_PRECISION_BITS); |
| 95 | constexpr int SUBPIXEL_PRECISION_MASK = 0xFFFFFFFF >> (32 - SUBPIXEL_PRECISION_BITS); |
| 96 | |
Alexis Hetu | 2aa8753 | 2021-11-18 16:22:17 -0500 | [diff] [blame] | 97 | constexpr int MAX_VIEWPORTS = 16; |
| 98 | |
Nicolas Capens | f1aca93 | 2021-09-27 10:30:18 -0400 | [diff] [blame] | 99 | // TODO: The heap size should be configured based on available RAM. |
Nicolas Capens | 08cb69c | 2022-01-14 10:34:51 -0500 | [diff] [blame] | 100 | constexpr VkDeviceSize PHYSICAL_DEVICE_HEAP_SIZE = 0x80000000ull; // 0x80000000 = 2 GiB |
| 101 | constexpr VkDeviceSize MAX_MEMORY_ALLOCATION_SIZE = 0x40000000ull; // 0x40000000 = 1 GiB |
Nicolas Capens | c79a36e | 2021-09-24 20:33:27 +0000 | [diff] [blame] | 102 | |
| 103 | // Memory offset calculations in 32-bit SIMD elements limit us to addressing at most 4 GiB. |
| 104 | // Signed arithmetic further restricts it to 2 GiB. |
| 105 | static_assert(MAX_MEMORY_ALLOCATION_SIZE <= 0x80000000ull, "maxMemoryAllocationSize must not exceed 2 GiB"); |
| 106 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 107 | } // namespace vk |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 108 | |
Yiwei Zhang | e6dc3d3 | 2020-11-11 19:25:19 +0000 | [diff] [blame] | 109 | #if defined(__linux__) && !defined(__ANDROID__) |
Antonio Maiorano | 71c49f8 | 2020-04-27 11:33:30 -0400 | [diff] [blame] | 110 | # define SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD 1 |
| 111 | # define SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD 1 |
Yiwei Zhang | e6dc3d3 | 2020-11-11 19:25:19 +0000 | [diff] [blame] | 112 | #elif defined(__ANDROID__) |
| 113 | # define SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD 1 |
David 'Digit' Turner | fda994c | 2019-09-04 16:36:36 +0200 | [diff] [blame] | 114 | #endif |
David 'Digit' Turner | 89fd148 | 2020-02-20 13:12:08 +0100 | [diff] [blame] | 115 | #if defined(__APPLE__) |
| 116 | # define SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD 1 |
| 117 | #endif |
David 'Digit' Turner | fda994c | 2019-09-04 16:36:36 +0200 | [diff] [blame] | 118 | |
Antonio Maiorano | 71c49f8 | 2020-04-27 11:33:30 -0400 | [diff] [blame] | 119 | #endif // VK_CONFIG_HPP_ |