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 18 #include "Version.hpp" 19 #include "Device/Config.hpp" 20 #include "Vulkan/VulkanPlatform.hpp" 21 #include "spirv-tools/libspirv.h" 22 23 #ifndef SWIFTSHADER_LEGACY_PRECISION 24 # define SWIFTSHADER_LEGACY_PRECISION false 25 #endif 26 27 namespace vk { 28 29 // Note: Constant array initialization requires a string literal. 30 // constexpr char* or char[] does not work for that purpose. 31 #define SWIFTSHADER_DEVICE_NAME "SwiftShader Device" // Max length: VK_MAX_PHYSICAL_DEVICE_NAME_SIZE 32 #define SWIFTSHADER_UUID "SwiftShaderUUID" // Max length: VK_UUID_SIZE (16) 33 34 constexpr spv_target_env SPIRV_VERSION = SPV_ENV_VULKAN_1_3; 35 36 constexpr uint32_t API_VERSION = VK_API_VERSION_1_3; 37 constexpr uint32_t DRIVER_VERSION = VK_MAKE_VERSION(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION); 38 constexpr uint32_t VENDOR_ID = 0x1AE0; // Google, Inc.: https://pcisig.com/google-inc-1 39 constexpr uint32_t DEVICE_ID = 0xC0DE; // SwiftShader (placeholder) 40 41 // "Allocations returned by vkAllocateMemory are guaranteed to meet any alignment requirement of the implementation." 42 constexpr VkDeviceSize DEVICE_MEMORY_ALLOCATION_ALIGNMENT = 256; 43 44 constexpr VkDeviceSize MIN_MEMORY_MAP_ALIGNMENT = 64; 45 static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_MEMORY_MAP_ALIGNMENT); 46 47 constexpr VkDeviceSize MIN_IMPORTED_HOST_POINTER_ALIGNMENT = 4096; 48 static_assert(MIN_IMPORTED_HOST_POINTER_ALIGNMENT >= DEVICE_MEMORY_ALLOCATION_ALIGNMENT); 49 50 // Vulkan 1.2 requires buffer offset alignment to be at most 256. 51 constexpr VkDeviceSize MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT = 256; 52 constexpr VkDeviceSize MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT = 256; 53 constexpr VkDeviceSize MIN_STORAGE_BUFFER_OFFSET_ALIGNMENT = 256; 54 static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT); 55 static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT); 56 static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_STORAGE_BUFFER_OFFSET_ALIGNMENT); 57 58 // Alignment of all other Vulkan resources. 59 constexpr VkDeviceSize MEMORY_REQUIREMENTS_OFFSET_ALIGNMENT = 16; // 16 bytes for 128-bit vector types. 60 static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MEMORY_REQUIREMENTS_OFFSET_ALIGNMENT); 61 62 constexpr VkDeviceSize HOST_MEMORY_ALLOCATION_ALIGNMENT = 16; // 16 bytes for 128-bit vector types. 63 64 constexpr uint32_t MEMORY_TYPE_GENERIC_BIT = 0x1; // Generic system memory. 65 66 constexpr uint32_t MAX_IMAGE_LEVELS_1D = 15; 67 constexpr uint32_t MAX_IMAGE_LEVELS_2D = 15; 68 constexpr uint32_t MAX_IMAGE_LEVELS_3D = 12; 69 constexpr uint32_t MAX_IMAGE_LEVELS_CUBE = 15; 70 constexpr uint32_t MAX_IMAGE_ARRAY_LAYERS = 2048; 71 constexpr float MAX_SAMPLER_LOD_BIAS = 15.0; 72 73 static_assert(MAX_IMAGE_LEVELS_1D <= sw::MIPMAP_LEVELS); 74 static_assert(MAX_IMAGE_LEVELS_2D <= sw::MIPMAP_LEVELS); 75 static_assert(MAX_IMAGE_LEVELS_3D <= sw::MIPMAP_LEVELS); 76 static_assert(MAX_IMAGE_LEVELS_CUBE <= sw::MIPMAP_LEVELS); 77 78 constexpr uint32_t MAX_BOUND_DESCRIPTOR_SETS = 4; 79 constexpr uint32_t MAX_VERTEX_INPUT_BINDINGS = 16; 80 constexpr uint32_t MAX_PUSH_CONSTANT_SIZE = 128; 81 constexpr uint32_t MAX_UPDATE_AFTER_BIND_DESCRIPTORS = 500000; 82 83 constexpr uint32_t MAX_DESCRIPTOR_SET_UNIFORM_BUFFERS_DYNAMIC = 8; 84 constexpr uint32_t MAX_DESCRIPTOR_SET_STORAGE_BUFFERS_DYNAMIC = 4; 85 constexpr uint32_t MAX_DESCRIPTOR_SET_COMBINED_BUFFERS_DYNAMIC = 86 MAX_DESCRIPTOR_SET_UNIFORM_BUFFERS_DYNAMIC + 87 MAX_DESCRIPTOR_SET_STORAGE_BUFFERS_DYNAMIC; 88 89 constexpr uint32_t MAX_COMPUTE_WORKGROUP_INVOCATIONS = 256; 90 91 constexpr size_t MAX_INLINE_UNIFORM_BLOCK_SIZE = 256; 92 93 constexpr float MAX_POINT_SIZE = 1023.0; 94 95 constexpr int MAX_SAMPLER_ALLOCATION_COUNT = 4000; 96 97 constexpr int SUBPIXEL_PRECISION_BITS = SWIFTSHADER_LEGACY_PRECISION ? 4 : 8; 98 constexpr float SUBPIXEL_PRECISION_FACTOR = static_cast<float>(1 << SUBPIXEL_PRECISION_BITS); 99 constexpr int SUBPIXEL_PRECISION_MASK = 0xFFFFFFFF >> (32 - SUBPIXEL_PRECISION_BITS); 100 101 constexpr int MAX_VIEWPORTS = 16; 102 103 // TODO: The heap size should be configured based on available RAM. 104 constexpr VkDeviceSize PHYSICAL_DEVICE_HEAP_SIZE = 0x80000000ull; // 0x80000000 = 2 GiB 105 constexpr VkDeviceSize MAX_MEMORY_ALLOCATION_SIZE = 0x40000000ull; // 0x40000000 = 1 GiB 106 107 // Memory offset calculations in 32-bit SIMD elements limit us to addressing at most 4 GiB. 108 // Signed arithmetic further restricts it to 2 GiB. 109 static_assert(MAX_MEMORY_ALLOCATION_SIZE <= 0x80000000ull, "maxMemoryAllocationSize must not exceed 2 GiB"); 110 111 } // namespace vk 112 113 #if defined(__linux__) && !defined(__ANDROID__) 114 # define SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD 1 115 # define SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD 1 116 #elif defined(__ANDROID__) 117 # define SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD 1 118 #endif 119 #if defined(__APPLE__) 120 # define SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD 1 121 #endif 122 123 #endif // VK_CONFIG_HPP_ 124