metal_device_properties.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**************************************************************************/
  2. /* metal_device_properties.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. /**************************************************************************/
  31. /* */
  32. /* Portions of this code were derived from MoltenVK. */
  33. /* */
  34. /* Copyright (c) 2015-2023 The Brenwill Workshop Ltd. */
  35. /* (http://www.brenwill.com) */
  36. /* */
  37. /* Licensed under the Apache License, Version 2.0 (the "License"); */
  38. /* you may not use this file except in compliance with the License. */
  39. /* You may obtain a copy of the License at */
  40. /* */
  41. /* http://www.apache.org/licenses/LICENSE-2.0 */
  42. /* */
  43. /* Unless required by applicable law or agreed to in writing, software */
  44. /* distributed under the License is distributed on an "AS IS" BASIS, */
  45. /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
  46. /* implied. See the License for the specific language governing */
  47. /* permissions and limitations under the License. */
  48. /**************************************************************************/
  49. #ifndef METAL_DEVICE_PROPERTIES_H
  50. #define METAL_DEVICE_PROPERTIES_H
  51. #import "servers/rendering/rendering_device.h"
  52. #import <Foundation/Foundation.h>
  53. #import <Metal/Metal.h>
  54. /** The buffer index to use for vertex content. */
  55. const static uint32_t VERT_CONTENT_BUFFER_INDEX = 0;
  56. const static uint32_t MAX_COLOR_ATTACHMENT_COUNT = 8;
  57. typedef NS_OPTIONS(NSUInteger, SampleCount) {
  58. SampleCount1 = (1UL << 0),
  59. SampleCount2 = (1UL << 1),
  60. SampleCount4 = (1UL << 2),
  61. SampleCount8 = (1UL << 3),
  62. SampleCount16 = (1UL << 4),
  63. SampleCount32 = (1UL << 5),
  64. SampleCount64 = (1UL << 6),
  65. };
  66. struct API_AVAILABLE(macos(11.0), ios(14.0)) MetalFeatures {
  67. uint32_t mslVersion;
  68. MTLGPUFamily highestFamily;
  69. MTLLanguageVersion mslVersionEnum;
  70. SampleCount supportedSampleCounts;
  71. long hostMemoryPageSize;
  72. bool layeredRendering;
  73. bool multisampleLayeredRendering;
  74. bool quadPermute; /**< If true, quadgroup permutation functions (vote, ballot, shuffle) are supported in shaders. */
  75. bool simdPermute; /**< If true, SIMD-group permutation functions (vote, ballot, shuffle) are supported in shaders. */
  76. bool simdReduction; /**< If true, SIMD-group reduction functions (arithmetic) are supported in shaders. */
  77. bool tessellationShader; /**< If true, tessellation shaders are supported. */
  78. bool imageCubeArray; /**< If true, image cube arrays are supported. */
  79. };
  80. struct MetalLimits {
  81. uint64_t maxImageArrayLayers;
  82. uint64_t maxFramebufferHeight;
  83. uint64_t maxFramebufferWidth;
  84. uint64_t maxImageDimension1D;
  85. uint64_t maxImageDimension2D;
  86. uint64_t maxImageDimension3D;
  87. uint64_t maxImageDimensionCube;
  88. uint64_t maxViewportDimensionX;
  89. uint64_t maxViewportDimensionY;
  90. MTLSize maxThreadsPerThreadGroup;
  91. MTLSize maxComputeWorkGroupCount;
  92. uint64_t maxBoundDescriptorSets;
  93. uint64_t maxColorAttachments;
  94. uint64_t maxTexturesPerArgumentBuffer;
  95. uint64_t maxSamplersPerArgumentBuffer;
  96. uint64_t maxBuffersPerArgumentBuffer;
  97. uint64_t maxBufferLength;
  98. uint64_t minUniformBufferOffsetAlignment;
  99. uint64_t maxVertexDescriptorLayoutStride;
  100. uint16_t maxViewports;
  101. uint32_t maxPerStageBufferCount; /**< The total number of per-stage Metal buffers available for shader uniform content and attributes. */
  102. uint32_t maxPerStageTextureCount; /**< The total number of per-stage Metal textures available for shader uniform content. */
  103. uint32_t maxPerStageSamplerCount; /**< The total number of per-stage Metal samplers available for shader uniform content. */
  104. uint32_t maxVertexInputAttributes;
  105. uint32_t maxVertexInputBindings;
  106. uint32_t maxVertexInputBindingStride;
  107. uint32_t maxDrawIndexedIndexValue;
  108. uint32_t minSubgroupSize; /**< The minimum number of threads in a SIMD-group. */
  109. uint32_t maxSubgroupSize; /**< The maximum number of threads in a SIMD-group. */
  110. BitField<RDD::ShaderStage> subgroupSupportedShaderStages;
  111. BitField<RD::SubgroupOperations> subgroupSupportedOperations; /**< The subgroup operations supported by the device. */
  112. };
  113. class API_AVAILABLE(macos(11.0), ios(14.0)) MetalDeviceProperties {
  114. private:
  115. void init_features(id<MTLDevice> p_device);
  116. void init_limits(id<MTLDevice> p_device);
  117. public:
  118. MetalFeatures features;
  119. MetalLimits limits;
  120. SampleCount find_nearest_supported_sample_count(RenderingDevice::TextureSamples p_samples) const;
  121. MetalDeviceProperties(id<MTLDevice> p_device);
  122. ~MetalDeviceProperties();
  123. private:
  124. static const SampleCount sample_count[RenderingDevice::TextureSamples::TEXTURE_SAMPLES_MAX];
  125. };
  126. #endif // METAL_DEVICE_PROPERTIES_H