metal_device_properties.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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), tvos(14.0)) MetalFeatures {
  67. uint32_t mslVersion = 0;
  68. MTLGPUFamily highestFamily = MTLGPUFamilyApple4;
  69. bool supportsBCTextureCompression = false;
  70. bool supportsDepth24Stencil8 = false;
  71. bool supports32BitFloatFiltering = false;
  72. bool supports32BitMSAA = false;
  73. bool supportsMac = TARGET_OS_OSX;
  74. MTLLanguageVersion mslVersionEnum = MTLLanguageVersion1_2;
  75. SampleCount supportedSampleCounts = SampleCount1;
  76. long hostMemoryPageSize = 0;
  77. bool layeredRendering = false;
  78. bool multisampleLayeredRendering = false;
  79. bool quadPermute = false; /**< If true, quadgroup permutation functions (vote, ballot, shuffle) are supported in shaders. */
  80. bool simdPermute = false; /**< If true, SIMD-group permutation functions (vote, ballot, shuffle) are supported in shaders. */
  81. bool simdReduction = false; /**< If true, SIMD-group reduction functions (arithmetic) are supported in shaders. */
  82. bool tessellationShader = false; /**< If true, tessellation shaders are supported. */
  83. bool imageCubeArray = false; /**< If true, image cube arrays are supported. */
  84. MTLArgumentBuffersTier argument_buffers_tier = MTLArgumentBuffersTier1;
  85. /// If true, argument encoders are required to encode arguments into an argument buffer.
  86. bool needs_arg_encoders = true;
  87. bool metal_fx_spatial = false; /**< If true, Metal FX spatial functions are supported. */
  88. bool metal_fx_temporal = false; /**< If true, Metal FX temporal functions are supported. */
  89. bool supports_gpu_address = false; /**< If true, referencing a GPU address in a shader is supported. */
  90. };
  91. struct MetalLimits {
  92. uint64_t maxImageArrayLayers;
  93. uint64_t maxFramebufferHeight;
  94. uint64_t maxFramebufferWidth;
  95. uint64_t maxImageDimension1D;
  96. uint64_t maxImageDimension2D;
  97. uint64_t maxImageDimension3D;
  98. uint64_t maxImageDimensionCube;
  99. uint64_t maxViewportDimensionX;
  100. uint64_t maxViewportDimensionY;
  101. MTLSize maxThreadsPerThreadGroup;
  102. MTLSize maxComputeWorkGroupCount;
  103. uint64_t maxBoundDescriptorSets;
  104. uint64_t maxColorAttachments;
  105. uint64_t maxTexturesPerArgumentBuffer;
  106. uint64_t maxSamplersPerArgumentBuffer;
  107. uint64_t maxBuffersPerArgumentBuffer;
  108. uint64_t maxBufferLength;
  109. uint64_t minUniformBufferOffsetAlignment;
  110. uint64_t maxVertexDescriptorLayoutStride;
  111. uint16_t maxViewports;
  112. uint32_t maxPerStageBufferCount; /**< The total number of per-stage Metal buffers available for shader uniform content and attributes. */
  113. uint32_t maxPerStageTextureCount; /**< The total number of per-stage Metal textures available for shader uniform content. */
  114. uint32_t maxPerStageSamplerCount; /**< The total number of per-stage Metal samplers available for shader uniform content. */
  115. uint32_t maxVertexInputAttributes;
  116. uint32_t maxVertexInputBindings;
  117. uint32_t maxVertexInputBindingStride;
  118. uint32_t maxDrawIndexedIndexValue;
  119. uint32_t maxShaderVaryings;
  120. double temporalScalerInputContentMinScale;
  121. double temporalScalerInputContentMaxScale;
  122. uint32_t minSubgroupSize; /**< The minimum number of threads in a SIMD-group. */
  123. uint32_t maxSubgroupSize; /**< The maximum number of threads in a SIMD-group. */
  124. BitField<RDD::ShaderStage> subgroupSupportedShaderStages;
  125. BitField<RD::SubgroupOperations> subgroupSupportedOperations; /**< The subgroup operations supported by the device. */
  126. };
  127. class API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) MetalDeviceProperties {
  128. private:
  129. void init_features(id<MTLDevice> p_device);
  130. void init_limits(id<MTLDevice> p_device);
  131. public:
  132. MetalFeatures features;
  133. MetalLimits limits;
  134. SampleCount find_nearest_supported_sample_count(RenderingDevice::TextureSamples p_samples) const;
  135. MetalDeviceProperties(id<MTLDevice> p_device);
  136. ~MetalDeviceProperties();
  137. private:
  138. static const SampleCount sample_count[RenderingDevice::TextureSamples::TEXTURE_SAMPLES_MAX];
  139. };
  140. #endif // METAL_DEVICE_PROPERTIES_H