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 namespace vk { 24 25 // Note: Constant array initialization requires a string literal. 26 // constexpr char* or char[] does not work for that purpose. 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) 29 30 constexpr spv_target_env SPIRV_VERSION = SPV_ENV_VULKAN_1_2; 31 32 constexpr uint32_t API_VERSION = VK_API_VERSION_1_2; 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) 36 37 // Alignment of all Vulkan objects, pools, device memory, images, buffers, descriptors. 38 constexpr VkDeviceSize REQUIRED_MEMORY_ALIGNMENT = 16; // 16 bytes for 128-bit vector types. 39 40 // Vulkan 1.2 requires buffer offset alignment to be at most 256. 41 constexpr VkDeviceSize MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT = 256; 42 constexpr VkDeviceSize MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT = 256; 43 constexpr VkDeviceSize MIN_STORAGE_BUFFER_OFFSET_ALIGNMENT = 256; 44 45 constexpr uint32_t MEMORY_TYPE_GENERIC_BIT = 0x1; // Generic system memory. 46 47 constexpr uint32_t MAX_IMAGE_LEVELS_1D = 15; 48 constexpr uint32_t MAX_IMAGE_LEVELS_2D = 15; 49 constexpr uint32_t MAX_IMAGE_LEVELS_3D = 12; 50 constexpr uint32_t MAX_IMAGE_LEVELS_CUBE = 15; 51 constexpr uint32_t MAX_IMAGE_ARRAY_LAYERS = 2048; 52 constexpr float MAX_SAMPLER_LOD_BIAS = 15.0; 53 54 static_assert(MAX_IMAGE_LEVELS_1D <= sw::MIPMAP_LEVELS); 55 static_assert(MAX_IMAGE_LEVELS_2D <= sw::MIPMAP_LEVELS); 56 static_assert(MAX_IMAGE_LEVELS_3D <= sw::MIPMAP_LEVELS); 57 static_assert(MAX_IMAGE_LEVELS_CUBE <= sw::MIPMAP_LEVELS); 58 59 constexpr uint32_t MAX_BOUND_DESCRIPTOR_SETS = 4; 60 constexpr uint32_t MAX_VERTEX_INPUT_BINDINGS = 16; 61 constexpr uint32_t MAX_PUSH_CONSTANT_SIZE = 128; 62 63 constexpr uint32_t MAX_DESCRIPTOR_SET_UNIFORM_BUFFERS_DYNAMIC = 8; 64 constexpr uint32_t MAX_DESCRIPTOR_SET_STORAGE_BUFFERS_DYNAMIC = 4; 65 constexpr uint32_t MAX_DESCRIPTOR_SET_COMBINED_BUFFERS_DYNAMIC = 66 MAX_DESCRIPTOR_SET_UNIFORM_BUFFERS_DYNAMIC + 67 MAX_DESCRIPTOR_SET_STORAGE_BUFFERS_DYNAMIC; 68 69 constexpr float MAX_POINT_SIZE = 1023.0; 70 71 constexpr int MAX_SAMPLER_ALLOCATION_COUNT = 4000; 72 73 constexpr int SUBPIXEL_PRECISION_BITS = 4; 74 constexpr float SUBPIXEL_PRECISION_FACTOR = static_cast<float>(1 << SUBPIXEL_PRECISION_BITS); 75 constexpr int SUBPIXEL_PRECISION_MASK = 0xFFFFFFFF >> (32 - SUBPIXEL_PRECISION_BITS); 76 77 // TODO: The heap size should be configured based on available RAM. 78 // FIXME(angleproject:6444): Remove the 15 bytes of padding. 79 constexpr VkDeviceSize PHYSICAL_DEVICE_HEAP_SIZE = 0x80000000ull + 15; // 0x80000000 = 2 GiB 80 constexpr VkDeviceSize MAX_MEMORY_ALLOCATION_SIZE = 0x40000000ull; // 0x40000000 = 1 GiB 81 82 // Memory offset calculations in 32-bit SIMD elements limit us to addressing at most 4 GiB. 83 // Signed arithmetic further restricts it to 2 GiB. 84 static_assert(MAX_MEMORY_ALLOCATION_SIZE <= 0x80000000ull, "maxMemoryAllocationSize must not exceed 2 GiB"); 85 86 } // namespace vk 87 88 #if defined(__linux__) && !defined(__ANDROID__) 89 # define SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD 1 90 # define SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD 1 91 #elif defined(__ANDROID__) 92 # define SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD 1 93 #endif 94 #if defined(__APPLE__) 95 # define SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD 1 96 #endif 97 98 #endif // VK_CONFIG_HPP_ 99