metal_device_properties.h 8.1 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. #pragma once
  31. /**************************************************************************/
  32. /* */
  33. /* Portions of this code were derived from MoltenVK. */
  34. /* */
  35. /* Copyright (c) 2015-2023 The Brenwill Workshop Ltd. */
  36. /* (http://www.brenwill.com) */
  37. /* */
  38. /* Licensed under the Apache License, Version 2.0 (the "License"); */
  39. /* you may not use this file except in compliance with the License. */
  40. /* You may obtain a copy of the License at */
  41. /* */
  42. /* http://www.apache.org/licenses/LICENSE-2.0 */
  43. /* */
  44. /* Unless required by applicable law or agreed to in writing, software */
  45. /* distributed under the License is distributed on an "AS IS" BASIS, */
  46. /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
  47. /* implied. See the License for the specific language governing */
  48. /* permissions and limitations under the License. */
  49. /**************************************************************************/
  50. #import "servers/rendering/rendering_device.h"
  51. #import <Foundation/Foundation.h>
  52. #import <Metal/Metal.h>
  53. /** The buffer index to use for vertex content. */
  54. const static uint32_t VERT_CONTENT_BUFFER_INDEX = 0;
  55. const static uint32_t MAX_COLOR_ATTACHMENT_COUNT = 8;
  56. typedef NS_OPTIONS(NSUInteger, SampleCount) {
  57. SampleCount1 = (1UL << 0),
  58. SampleCount2 = (1UL << 1),
  59. SampleCount4 = (1UL << 2),
  60. SampleCount8 = (1UL << 3),
  61. SampleCount16 = (1UL << 4),
  62. SampleCount32 = (1UL << 5),
  63. SampleCount64 = (1UL << 6),
  64. };
  65. struct API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) MetalFeatures {
  66. uint32_t mslVersionMajor = 0;
  67. uint32_t mslVersionMinor = 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. bool supports_image_atomic_32_bit = false; /**< If true, 32-bit atomic operations on images are supported. */
  91. bool supports_image_atomic_64_bit = false; /**< If true, 64-bit atomic operations on images are supported. */
  92. };
  93. struct MetalLimits {
  94. uint64_t maxImageArrayLayers;
  95. uint64_t maxFramebufferHeight;
  96. uint64_t maxFramebufferWidth;
  97. uint64_t maxImageDimension1D;
  98. uint64_t maxImageDimension2D;
  99. uint64_t maxImageDimension3D;
  100. uint64_t maxImageDimensionCube;
  101. uint64_t maxViewportDimensionX;
  102. uint64_t maxViewportDimensionY;
  103. MTLSize maxThreadsPerThreadGroup;
  104. MTLSize maxComputeWorkGroupCount;
  105. uint64_t maxBoundDescriptorSets;
  106. uint64_t maxColorAttachments;
  107. uint64_t maxTexturesPerArgumentBuffer;
  108. uint64_t maxSamplersPerArgumentBuffer;
  109. uint64_t maxBuffersPerArgumentBuffer;
  110. uint64_t maxBufferLength;
  111. uint64_t minUniformBufferOffsetAlignment;
  112. uint64_t maxVertexDescriptorLayoutStride;
  113. uint16_t maxViewports;
  114. uint32_t maxPerStageBufferCount; /**< The total number of per-stage Metal buffers available for shader uniform content and attributes. */
  115. uint32_t maxPerStageTextureCount; /**< The total number of per-stage Metal textures available for shader uniform content. */
  116. uint32_t maxPerStageSamplerCount; /**< The total number of per-stage Metal samplers available for shader uniform content. */
  117. uint32_t maxVertexInputAttributes;
  118. uint32_t maxVertexInputBindings;
  119. uint32_t maxVertexInputBindingStride;
  120. uint32_t maxDrawIndexedIndexValue;
  121. uint32_t maxShaderVaryings;
  122. uint32_t maxThreadGroupMemoryAllocation;
  123. double temporalScalerInputContentMinScale;
  124. double temporalScalerInputContentMaxScale;
  125. uint32_t minSubgroupSize; /**< The minimum number of threads in a SIMD-group. */
  126. uint32_t maxSubgroupSize; /**< The maximum number of threads in a SIMD-group. */
  127. BitField<RDD::ShaderStage> subgroupSupportedShaderStages;
  128. BitField<RD::SubgroupOperations> subgroupSupportedOperations; /**< The subgroup operations supported by the device. */
  129. };
  130. class API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) MetalDeviceProperties {
  131. private:
  132. void init_features(id<MTLDevice> p_device);
  133. void init_limits(id<MTLDevice> p_device);
  134. public:
  135. MetalFeatures features;
  136. MetalLimits limits;
  137. SampleCount find_nearest_supported_sample_count(RenderingDevice::TextureSamples p_samples) const;
  138. MetalDeviceProperties(id<MTLDevice> p_device);
  139. ~MetalDeviceProperties();
  140. private:
  141. static const SampleCount sample_count[RenderingDevice::TextureSamples::TEXTURE_SAMPLES_MAX];
  142. };