blob: a6145bd73e744f51843a479df75cc3272570b56f [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
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040030constexpr spv_target_env SPIRV_VERSION = SPV_ENV_VULKAN_1_2;
Sean Risser019feda2020-11-09 14:19:27 -050031
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040032constexpr uint32_t API_VERSION = VK_API_VERSION_1_2;
33constexpr 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 Capensb7b7cb72021-09-29 14:02:53 -040037// Alignment of all Vulkan objects, pools, device memory, images, buffers, descriptors.
38constexpr VkDeviceSize REQUIRED_MEMORY_ALIGNMENT = 16; // 16 bytes for 128-bit vector types.
Nicolas Capens52b5aae2019-05-24 16:27:55 -040039
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040040// Vulkan 1.2 requires buffer offset alignment to be at most 256.
41constexpr VkDeviceSize MIN_TEXEL_BUFFER_OFFSET_ALIGNMENT = 256;
42constexpr VkDeviceSize MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT = 256;
43constexpr VkDeviceSize MIN_STORAGE_BUFFER_OFFSET_ALIGNMENT = 256;
Nicolas Capensbd54e072019-04-25 23:28:28 -040044
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040045constexpr uint32_t MEMORY_TYPE_GENERIC_BIT = 0x1; // Generic system memory.
Alexis Hetu767b41b2018-09-26 11:25:46 -040046
Nicolas Capens06251152021-09-29 17:37:58 -040047constexpr uint32_t MAX_IMAGE_LEVELS_1D = 15;
48constexpr uint32_t MAX_IMAGE_LEVELS_2D = 15;
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040049constexpr uint32_t MAX_IMAGE_LEVELS_3D = 12;
Nicolas Capens06251152021-09-29 17:37:58 -040050constexpr uint32_t MAX_IMAGE_LEVELS_CUBE = 15;
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040051constexpr uint32_t MAX_IMAGE_ARRAY_LAYERS = 2048;
52constexpr float MAX_SAMPLER_LOD_BIAS = 15.0;
Alexis Hetu767b41b2018-09-26 11:25:46 -040053
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040054static_assert(MAX_IMAGE_LEVELS_1D <= sw::MIPMAP_LEVELS);
55static_assert(MAX_IMAGE_LEVELS_2D <= sw::MIPMAP_LEVELS);
56static_assert(MAX_IMAGE_LEVELS_3D <= sw::MIPMAP_LEVELS);
57static_assert(MAX_IMAGE_LEVELS_CUBE <= sw::MIPMAP_LEVELS);
Alexis Hetu767b41b2018-09-26 11:25:46 -040058
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040059constexpr uint32_t MAX_BOUND_DESCRIPTOR_SETS = 4;
60constexpr uint32_t MAX_VERTEX_INPUT_BINDINGS = 16;
61constexpr uint32_t MAX_PUSH_CONSTANT_SIZE = 128;
Ben Clayton225a1302019-04-02 12:28:22 +010062
Nicolas Capensb7b7cb72021-09-29 14:02:53 -040063constexpr uint32_t MAX_DESCRIPTOR_SET_UNIFORM_BUFFERS_DYNAMIC = 8;
64constexpr uint32_t MAX_DESCRIPTOR_SET_STORAGE_BUFFERS_DYNAMIC = 4;
65constexpr uint32_t MAX_DESCRIPTOR_SET_COMBINED_BUFFERS_DYNAMIC =
66 MAX_DESCRIPTOR_SET_UNIFORM_BUFFERS_DYNAMIC +
67 MAX_DESCRIPTOR_SET_STORAGE_BUFFERS_DYNAMIC;
68
69constexpr float MAX_POINT_SIZE = 1023.0;
Chris Forbes54c47722019-02-25 13:35:59 -080070
Nicolas Capens8532b0f2021-05-20 02:52:30 -040071constexpr int MAX_SAMPLER_ALLOCATION_COUNT = 4000;
72
Antonio Maioranoae022fa2019-10-07 12:57:19 -040073constexpr int SUBPIXEL_PRECISION_BITS = 4;
74constexpr float SUBPIXEL_PRECISION_FACTOR = static_cast<float>(1 << SUBPIXEL_PRECISION_BITS);
75constexpr int SUBPIXEL_PRECISION_MASK = 0xFFFFFFFF >> (32 - SUBPIXEL_PRECISION_BITS);
76
Nicolas Capensf1aca932021-09-27 10:30:18 -040077// TODO: The heap size should be configured based on available RAM.
Nicolas Capens08cb69c2022-01-14 10:34:51 -050078constexpr VkDeviceSize PHYSICAL_DEVICE_HEAP_SIZE = 0x80000000ull; // 0x80000000 = 2 GiB
79constexpr VkDeviceSize MAX_MEMORY_ALLOCATION_SIZE = 0x40000000ull; // 0x40000000 = 1 GiB
Nicolas Capensc79a36e2021-09-24 20:33:27 +000080
81// Memory offset calculations in 32-bit SIMD elements limit us to addressing at most 4 GiB.
82// Signed arithmetic further restricts it to 2 GiB.
83static_assert(MAX_MEMORY_ALLOCATION_SIZE <= 0x80000000ull, "maxMemoryAllocationSize must not exceed 2 GiB");
84
Nicolas Capens157ba262019-12-10 17:49:14 -050085} // namespace vk
Alexis Hetu767b41b2018-09-26 11:25:46 -040086
Yiwei Zhange6dc3d32020-11-11 19:25:19 +000087#if defined(__linux__) && !defined(__ANDROID__)
Antonio Maiorano71c49f82020-04-27 11:33:30 -040088# define SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD 1
89# define SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD 1
Yiwei Zhange6dc3d32020-11-11 19:25:19 +000090#elif defined(__ANDROID__)
91# define SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD 1
David 'Digit' Turnerfda994c2019-09-04 16:36:36 +020092#endif
David 'Digit' Turner89fd1482020-02-20 13:12:08 +010093#if defined(__APPLE__)
94# define SWIFTSHADER_EXTERNAL_MEMORY_OPAQUE_FD 1
95#endif
David 'Digit' Turnerfda994c2019-09-04 16:36:36 +020096
Antonio Maiorano71c49f82020-04-27 11:33:30 -040097#endif // VK_CONFIG_HPP_