blob: 488498689dc3bf05840e90cfad04f0328742e45c [file] [log] [blame]
Alexis Hetu767b41b2018-09-26 11:25:46 -04001// 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 Maiorano42fd1592020-04-27 11:30:40 -040018#include "Version.hpp"
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040019#include "Device/Config.hpp"
Antonio Maiorano42fd1592020-04-27 11:30:40 -040020#include "Vulkan/VulkanPlatform.hpp"
Sean Risser019feda2020-11-09 14:19:27 -050021#include "spirv-tools/libspirv.h"
Nicolas Capensee841c52018-11-13 14:18:26 -050022
Nicolas Capens157ba262019-12-10 17:49:14 -050023namespace vk {
Alexis Hetu767b41b2018-09-26 11:25:46 -040024
25// Note: Constant array initialization requires a string literal.
26// constexpr char* or char[] does not work for that purpose.
Antonio Maiorano71c49f82020-04-27 11:33:30 -040027#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 Hetu767b41b2018-09-26 11:25:46 -040029
sugoi1ff535622022-01-27 16:49:13 -050030constexpr spv_target_env SPIRV_VERSION = SPV_ENV_VULKAN_1_3;
Sean Risser019feda2020-11-09 14:19:27 -050031
sugoi1ff535622022-01-27 16:49:13 -050032constexpr uint32_t API_VERSION = VK_API_VERSION_1_3;
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040033constexpr uint32_t DRIVER_VERSION = VK_MAKE_VERSION(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION);
34constexpr uint32_t VENDOR_ID = 0x1AE0; // Google, Inc.: https://pcisig.com/google-inc-1
35constexpr uint32_t DEVICE_ID = 0xC0DE; // SwiftShader (placeholder)
Alexis Hetu767b41b2018-09-26 11:25:46 -040036
Nicolas Capens0134dd82022-07-27 16:12:46 -040037// "Allocations returned by vkAllocateMemory are guaranteed to meet any alignment requirement of the implementation."
38constexpr VkDeviceSize DEVICE_MEMORY_ALLOCATION_ALIGNMENT = 256;
Nicolas Capens52b5aae2019-05-24 16:27:55 -040039
Nicolas Capens80aaa8a2022-07-27 14:43:42 -040040constexpr VkDeviceSize MIN_MEMORY_MAP_ALIGNMENT = 64;
41static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_MEMORY_MAP_ALIGNMENT);
42
Nicolas Capens39787ac2022-07-27 12:29:52 -040043constexpr VkDeviceSize MIN_IMPORTED_HOST_POINTER_ALIGNMENT = 4096;
Nicolas Capens0134dd82022-07-27 16:12:46 -040044static_assert(MIN_IMPORTED_HOST_POINTER_ALIGNMENT >= DEVICE_MEMORY_ALLOCATION_ALIGNMENT);
Nicolas Capens39787ac2022-07-27 12:29:52 -040045
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040046// Vulkan 1.2 requires buffer offset alignment to be at most 256.
47constexpr VkDeviceSize MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT = 256;
48constexpr VkDeviceSize MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT = 256;
49constexpr VkDeviceSize MIN_STORAGE_BUFFER_OFFSET_ALIGNMENT = 256;
Nicolas Capens0134dd82022-07-27 16:12:46 -040050static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT);
51static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT);
52static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MIN_STORAGE_BUFFER_OFFSET_ALIGNMENT);
53
54// Alignment of all other Vulkan resources.
55constexpr VkDeviceSize MEMORY_REQUIREMENTS_OFFSET_ALIGNMENT = 16; // 16 bytes for 128-bit vector types.
56static_assert(DEVICE_MEMORY_ALLOCATION_ALIGNMENT >= MEMORY_REQUIREMENTS_OFFSET_ALIGNMENT);
57
58constexpr VkDeviceSize HOST_MEMORY_ALLOCATION_ALIGNMENT = 16; // 16 bytes for 128-bit vector types.
Nicolas Capensbd54e072019-04-25 23:28:28 -040059
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040060constexpr uint32_t MEMORY_TYPE_GENERIC_BIT = 0x1; // Generic system memory.
Alexis Hetu767b41b2018-09-26 11:25:46 -040061
Nicolas Capens06251152021-09-29 17:37:58 -040062constexpr uint32_t MAX_IMAGE_LEVELS_1D = 15;
63constexpr uint32_t MAX_IMAGE_LEVELS_2D = 15;
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040064constexpr uint32_t MAX_IMAGE_LEVELS_3D = 12;
Nicolas Capens06251152021-09-29 17:37:58 -040065constexpr uint32_t MAX_IMAGE_LEVELS_CUBE = 15;
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040066constexpr uint32_t MAX_IMAGE_ARRAY_LAYERS = 2048;
67constexpr float MAX_SAMPLER_LOD_BIAS = 15.0;
Alexis Hetu767b41b2018-09-26 11:25:46 -040068
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040069static_assert(MAX_IMAGE_LEVELS_1D <= sw::MIPMAP_LEVELS);
70static_assert(MAX_IMAGE_LEVELS_2D <= sw::MIPMAP_LEVELS);
71static_assert(MAX_IMAGE_LEVELS_3D <= sw::MIPMAP_LEVELS);
72static_assert(MAX_IMAGE_LEVELS_CUBE <= sw::MIPMAP_LEVELS);
Alexis Hetu767b41b2018-09-26 11:25:46 -040073
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040074constexpr uint32_t MAX_BOUND_DESCRIPTOR_SETS = 4;
75constexpr uint32_t MAX_VERTEX_INPUT_BINDINGS = 16;
76constexpr uint32_t MAX_PUSH_CONSTANT_SIZE = 128;
Alexis Hetu2ede3782022-08-30 12:01:15 -040077constexpr uint32_t MAX_UPDATE_AFTER_BIND_DESCRIPTORS = 500000;
Ben Clayton225a1302019-04-02 12:28:22 +010078
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040079constexpr uint32_t MAX_DESCRIPTOR_SET_UNIFORM_BUFFERS_DYNAMIC = 8;
80constexpr uint32_t MAX_DESCRIPTOR_SET_STORAGE_BUFFERS_DYNAMIC = 4;
81constexpr uint32_t MAX_DESCRIPTOR_SET_COMBINED_BUFFERS_DYNAMIC =
82 MAX_DESCRIPTOR_SET_UNIFORM_BUFFERS_DYNAMIC +
83 MAX_DESCRIPTOR_SET_STORAGE_BUFFERS_DYNAMIC;
84
Alexis Hetu9f14d0b2021-10-29 11:09:23 -040085constexpr uint32_t MAX_COMPUTE_WORKGROUP_INVOCATIONS = 256;
86
Alexis Hetu8941bde2021-11-17 17:45:40 -050087constexpr size_t MAX_INLINE_UNIFORM_BLOCK_SIZE = 256;
88
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040089constexpr float MAX_POINT_SIZE = 1023.0;
Chris Forbes54c47722019-02-25 13:35:59 -080090
Nicolas Capens8532b0f2021-05-20 02:52:30 -040091constexpr int MAX_SAMPLER_ALLOCATION_COUNT = 4000;
92
Antonio Maioranoae022fa2019-10-07 12:57:19 -040093constexpr int SUBPIXEL_PRECISION_BITS = 4;
94constexpr float SUBPIXEL_PRECISION_FACTOR = static_cast<float>(1 << SUBPIXEL_PRECISION_BITS);
95constexpr int SUBPIXEL_PRECISION_MASK = 0xFFFFFFFF >> (32 - SUBPIXEL_PRECISION_BITS);
96
Alexis Hetu2aa87532021-11-18 16:22:17 -050097constexpr int MAX_VIEWPORTS = 16;
98
Nicolas Capensf1aca932021-09-27 10:30:18 -040099// TODO: The heap size should be configured based on available RAM.
Nicolas Capens08cb69c2022-01-14 10:34:51 -0500100constexpr VkDeviceSize PHYSICAL_DEVICE_HEAP_SIZE = 0x80000000ull; // 0x80000000 = 2 GiB
101constexpr VkDeviceSize MAX_MEMORY_ALLOCATION_SIZE = 0x40000000ull; // 0x40000000 = 1 GiB
Nicolas Capensc79a36e2021-09-24 20:33:27 +0000102
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.
105static_assert(MAX_MEMORY_ALLOCATION_SIZE <= 0x80000000ull, "maxMemoryAllocationSize must not exceed 2 GiB");
106
Nicolas Capens157ba262019-12-10 17:49:14 -0500107} // namespace vk
Alexis Hetu767b41b2018-09-26 11:25:46 -0400108
Yiwei Zhange6dc3d32020-11-11 19:25:19 +0000109#if defined(__linux__) && !defined(__ANDROID__)
Antonio Maiorano71c49f82020-04-27 11:33:30 -0400110# define SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD 1
111# define SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD 1
Yiwei Zhange6dc3d32020-11-11 19:25:19 +0000112#elif defined(__ANDROID__)
113# define SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD 1
David 'Digit' Turnerfda994c2019-09-04 16:36:36 +0200114#endif
David 'Digit' Turner89fd1482020-02-20 13:12:08 +0100115#if defined(__APPLE__)
116# define SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD 1
117#endif
David 'Digit' Turnerfda994c2019-09-04 16:36:36 +0200118
Antonio Maiorano71c49f82020-04-27 11:33:30 -0400119#endif // VK_CONFIG_HPP_