Skip to content

Commit f27764e

Browse files
committed
Metal: Add support for 2017 era iOS devices
This commit introduces support for checking the argument buffer tier, and falling back to disabling argument buffers when tier 1 is available. Closes godotengine#99682
1 parent 33e858c commit f27764e

15 files changed

+1351
-232
lines changed

drivers/metal/metal_device_properties.h

+13-12
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,19 @@ typedef NS_OPTIONS(NSUInteger, SampleCount) {
7171
};
7272

7373
struct API_AVAILABLE(macos(11.0), ios(14.0)) MetalFeatures {
74-
uint32_t mslVersion;
75-
MTLGPUFamily highestFamily;
76-
MTLLanguageVersion mslVersionEnum;
77-
SampleCount supportedSampleCounts;
78-
long hostMemoryPageSize;
79-
bool layeredRendering;
80-
bool multisampleLayeredRendering;
81-
bool quadPermute; /**< If true, quadgroup permutation functions (vote, ballot, shuffle) are supported in shaders. */
82-
bool simdPermute; /**< If true, SIMD-group permutation functions (vote, ballot, shuffle) are supported in shaders. */
83-
bool simdReduction; /**< If true, SIMD-group reduction functions (arithmetic) are supported in shaders. */
84-
bool tessellationShader; /**< If true, tessellation shaders are supported. */
85-
bool imageCubeArray; /**< If true, image cube arrays are supported. */
74+
uint32_t mslVersion = 0;
75+
MTLGPUFamily highestFamily = MTLGPUFamilyApple4;
76+
MTLLanguageVersion mslVersionEnum = MTLLanguageVersion1_2;
77+
SampleCount supportedSampleCounts = SampleCount1;
78+
long hostMemoryPageSize = 0;
79+
bool layeredRendering = false;
80+
bool multisampleLayeredRendering = false;
81+
bool quadPermute = false; /**< If true, quadgroup permutation functions (vote, ballot, shuffle) are supported in shaders. */
82+
bool simdPermute = false; /**< If true, SIMD-group permutation functions (vote, ballot, shuffle) are supported in shaders. */
83+
bool simdReduction = false; /**< If true, SIMD-group reduction functions (arithmetic) are supported in shaders. */
84+
bool tessellationShader = false; /**< If true, tessellation shaders are supported. */
85+
bool imageCubeArray = false; /**< If true, image cube arrays are supported. */
86+
MTLArgumentBuffersTier argument_buffers_tier = MTLArgumentBuffersTier1;
8687
};
8788

8889
struct MetalLimits {

drivers/metal/metal_device_properties.mm

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
features.quadPermute = [p_device supportsFamily:MTLGPUFamilyApple4];
9999
features.simdPermute = [p_device supportsFamily:MTLGPUFamilyApple6];
100100
features.simdReduction = [p_device supportsFamily:MTLGPUFamilyApple7];
101+
features.argument_buffers_tier = p_device.argumentBuffersSupport;
101102

102103
MTLCompileOptions *opts = [MTLCompileOptions new];
103104
features.mslVersionEnum = opts.languageVersion; // By default, Metal uses the most recent language version.

drivers/metal/metal_objects.h

+16-5
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,12 @@ class API_AVAILABLE(macos(11.0), ios(14.0)) MDShader {
696696
public:
697697
CharString name;
698698
Vector<UniformSet> sets;
699+
bool uses_argument_buffers = true;
699700

700701
virtual void encode_push_constant_data(VectorView<uint32_t> p_data, MDCommandBuffer *p_cb) = 0;
701702

702-
MDShader(CharString p_name, Vector<UniformSet> p_sets) :
703-
name(p_name), sets(p_sets) {}
703+
MDShader(CharString p_name, Vector<UniformSet> p_sets, bool p_uses_argument_buffers) :
704+
name(p_name), sets(p_sets), uses_argument_buffers(p_uses_argument_buffers) {}
704705
virtual ~MDShader() = default;
705706
};
706707

@@ -719,7 +720,7 @@ class API_AVAILABLE(macos(11.0), ios(14.0)) MDComputeShader final : public MDSha
719720

720721
void encode_push_constant_data(VectorView<uint32_t> p_data, MDCommandBuffer *p_cb) final;
721722

722-
MDComputeShader(CharString p_name, Vector<UniformSet> p_sets, MDLibrary *p_kernel);
723+
MDComputeShader(CharString p_name, Vector<UniformSet> p_sets, bool p_uses_argument_buffers, MDLibrary *p_kernel);
723724
};
724725

725726
class API_AVAILABLE(macos(11.0), ios(14.0)) MDRenderShader final : public MDShader {
@@ -746,8 +747,9 @@ class API_AVAILABLE(macos(11.0), ios(14.0)) MDRenderShader final : public MDShad
746747
void encode_push_constant_data(VectorView<uint32_t> p_data, MDCommandBuffer *p_cb) final;
747748

748749
MDRenderShader(CharString p_name,
749-
bool p_needs_view_mask_buffer,
750750
Vector<UniformSet> p_sets,
751+
bool p_needs_view_mask_buffer,
752+
bool p_uses_argument_buffers,
751753
MDLibrary *p_vert, MDLibrary *p_frag);
752754
};
753755

@@ -783,12 +785,21 @@ struct BoundUniformSet {
783785
};
784786

785787
class API_AVAILABLE(macos(11.0), ios(14.0)) MDUniformSet {
788+
private:
789+
void bind_uniforms_argument_buffers(MDShader *p_shader, MDCommandBuffer::RenderState &p_state);
790+
void bind_uniforms_direct(MDShader *p_shader, MDCommandBuffer::RenderState &p_state);
791+
void bind_uniforms_argument_buffers(MDShader *p_shader, MDCommandBuffer::ComputeState &p_state);
792+
void bind_uniforms_direct(MDShader *p_shader, MDCommandBuffer::ComputeState &p_state);
793+
786794
public:
787795
uint32_t index;
788796
LocalVector<RDD::BoundUniform> uniforms;
789797
HashMap<MDShader *, BoundUniformSet> bound_uniforms;
790798

791-
BoundUniformSet &boundUniformSetForShader(MDShader *p_shader, id<MTLDevice> p_device);
799+
void bind_uniforms(MDShader *p_shader, MDCommandBuffer::RenderState &p_state);
800+
void bind_uniforms(MDShader *p_shader, MDCommandBuffer::ComputeState &p_state);
801+
802+
BoundUniformSet &bound_uniform_set(MDShader *p_shader, id<MTLDevice> p_device, ResourceUsageMap &p_resource_usage);
792803
};
793804

794805
class API_AVAILABLE(macos(11.0), ios(14.0)) MDPipeline {

0 commit comments

Comments
 (0)