Skip to content

Commit

Permalink
Metal: Support Apple4 GPUs (2017 era iOS devices)
Browse files Browse the repository at this point in the history
Closes #99682
  • Loading branch information
stuartcarnie committed Dec 17, 2024
1 parent 2b7ea62 commit aa2562e
Show file tree
Hide file tree
Showing 15 changed files with 1,353 additions and 232 deletions.
25 changes: 13 additions & 12 deletions drivers/metal/metal_device_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,19 @@ typedef NS_OPTIONS(NSUInteger, SampleCount) {
};

struct API_AVAILABLE(macos(11.0), ios(14.0)) MetalFeatures {
uint32_t mslVersion;
MTLGPUFamily highestFamily;
MTLLanguageVersion mslVersionEnum;
SampleCount supportedSampleCounts;
long hostMemoryPageSize;
bool layeredRendering;
bool multisampleLayeredRendering;
bool quadPermute; /**< If true, quadgroup permutation functions (vote, ballot, shuffle) are supported in shaders. */
bool simdPermute; /**< If true, SIMD-group permutation functions (vote, ballot, shuffle) are supported in shaders. */
bool simdReduction; /**< If true, SIMD-group reduction functions (arithmetic) are supported in shaders. */
bool tessellationShader; /**< If true, tessellation shaders are supported. */
bool imageCubeArray; /**< If true, image cube arrays are supported. */
uint32_t mslVersion = 0;
MTLGPUFamily highestFamily = MTLGPUFamilyApple4;
MTLLanguageVersion mslVersionEnum = MTLLanguageVersion1_2;
SampleCount supportedSampleCounts = SampleCount1;
long hostMemoryPageSize = 0;
bool layeredRendering = false;
bool multisampleLayeredRendering = false;
bool quadPermute = false; /**< If true, quadgroup permutation functions (vote, ballot, shuffle) are supported in shaders. */
bool simdPermute = false; /**< If true, SIMD-group permutation functions (vote, ballot, shuffle) are supported in shaders. */
bool simdReduction = false; /**< If true, SIMD-group reduction functions (arithmetic) are supported in shaders. */
bool tessellationShader = false; /**< If true, tessellation shaders are supported. */
bool imageCubeArray = false; /**< If true, image cube arrays are supported. */
MTLArgumentBuffersTier argument_buffers_tier = MTLArgumentBuffersTier1;
};

struct MetalLimits {
Expand Down
1 change: 1 addition & 0 deletions drivers/metal/metal_device_properties.mm
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
features.quadPermute = [p_device supportsFamily:MTLGPUFamilyApple4];
features.simdPermute = [p_device supportsFamily:MTLGPUFamilyApple6];
features.simdReduction = [p_device supportsFamily:MTLGPUFamilyApple7];
features.argument_buffers_tier = p_device.argumentBuffersSupport;

MTLCompileOptions *opts = [MTLCompileOptions new];
features.mslVersionEnum = opts.languageVersion; // By default, Metal uses the most recent language version.
Expand Down
21 changes: 16 additions & 5 deletions drivers/metal/metal_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,11 +696,12 @@ class API_AVAILABLE(macos(11.0), ios(14.0)) MDShader {
public:
CharString name;
Vector<UniformSet> sets;
bool uses_argument_buffers = true;

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

MDShader(CharString p_name, Vector<UniformSet> p_sets) :
name(p_name), sets(p_sets) {}
MDShader(CharString p_name, Vector<UniformSet> p_sets, bool p_uses_argument_buffers) :
name(p_name), sets(p_sets), uses_argument_buffers(p_uses_argument_buffers) {}
virtual ~MDShader() = default;
};

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

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

MDComputeShader(CharString p_name, Vector<UniformSet> p_sets, MDLibrary *p_kernel);
MDComputeShader(CharString p_name, Vector<UniformSet> p_sets, bool p_uses_argument_buffers, MDLibrary *p_kernel);
};

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

MDRenderShader(CharString p_name,
bool p_needs_view_mask_buffer,
Vector<UniformSet> p_sets,
bool p_needs_view_mask_buffer,
bool p_uses_argument_buffers,
MDLibrary *p_vert, MDLibrary *p_frag);
};

Expand Down Expand Up @@ -783,12 +785,21 @@ struct BoundUniformSet {
};

class API_AVAILABLE(macos(11.0), ios(14.0)) MDUniformSet {
private:
void bind_uniforms_argument_buffers(MDShader *p_shader, MDCommandBuffer::RenderState &p_state);
void bind_uniforms_direct(MDShader *p_shader, MDCommandBuffer::RenderState &p_state);
void bind_uniforms_argument_buffers(MDShader *p_shader, MDCommandBuffer::ComputeState &p_state);
void bind_uniforms_direct(MDShader *p_shader, MDCommandBuffer::ComputeState &p_state);

public:
uint32_t index;
LocalVector<RDD::BoundUniform> uniforms;
HashMap<MDShader *, BoundUniformSet> bound_uniforms;

BoundUniformSet &boundUniformSetForShader(MDShader *p_shader, id<MTLDevice> p_device);
void bind_uniforms(MDShader *p_shader, MDCommandBuffer::RenderState &p_state);
void bind_uniforms(MDShader *p_shader, MDCommandBuffer::ComputeState &p_state);

BoundUniformSet &bound_uniform_set(MDShader *p_shader, id<MTLDevice> p_device, ResourceUsageMap &p_resource_usage);
};

class API_AVAILABLE(macos(11.0), ios(14.0)) MDPipeline {
Expand Down
Loading

0 comments on commit aa2562e

Please sign in to comment.