Skip to content

Commit b8154c5

Browse files
committed
[metal] Import prefixed metal items
A lot of Metal types are prefixed with MTL, which makes it quite clear where they're coming from. This means that we don't loose any clarity if we import them instead of having them prefixed with `metal::`. This will make it easier to migrate to `objc2-metal` since that crate is named differently from the `metal` crate.
1 parent 96c1fb1 commit b8154c5

File tree

6 files changed

+211
-213
lines changed

6 files changed

+211
-213
lines changed

wgpu-hal/src/metal/adapter.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use metal::{MTLFeatureSet, MTLGPUFamily, MTLLanguageVersion, MTLReadWriteTextureTier};
1+
use metal::{
2+
MTLArgumentBuffersTier, MTLCounterSamplingPoint, MTLFeatureSet, MTLGPUFamily,
3+
MTLLanguageVersion, MTLPixelFormat, MTLReadWriteTextureTier, NSInteger,
4+
};
25
use objc::{class, msg_send, sel, sel_impl};
36
use parking_lot::Mutex;
47
use wgt::{AstcBlock, AstcChannel};
@@ -575,19 +578,18 @@ impl super::PrivateCapabilities {
575578

576579
let mut timestamp_query_support = TimestampQuerySupport::empty();
577580
if version.at_least((11, 0), (14, 0), os_is_mac)
578-
&& device.supports_counter_sampling(metal::MTLCounterSamplingPoint::AtStageBoundary)
581+
&& device.supports_counter_sampling(MTLCounterSamplingPoint::AtStageBoundary)
579582
{
580583
// If we don't support at stage boundary, don't support anything else.
581584
timestamp_query_support.insert(TimestampQuerySupport::STAGE_BOUNDARIES);
582585

583-
if device.supports_counter_sampling(metal::MTLCounterSamplingPoint::AtDrawBoundary) {
586+
if device.supports_counter_sampling(MTLCounterSamplingPoint::AtDrawBoundary) {
584587
timestamp_query_support.insert(TimestampQuerySupport::ON_RENDER_ENCODER);
585588
}
586-
if device.supports_counter_sampling(metal::MTLCounterSamplingPoint::AtDispatchBoundary)
587-
{
589+
if device.supports_counter_sampling(MTLCounterSamplingPoint::AtDispatchBoundary) {
588590
timestamp_query_support.insert(TimestampQuerySupport::ON_COMPUTE_ENCODER);
589591
}
590-
if device.supports_counter_sampling(metal::MTLCounterSamplingPoint::AtBlitBoundary) {
592+
if device.supports_counter_sampling(MTLCounterSamplingPoint::AtBlitBoundary) {
591593
timestamp_query_support.insert(TimestampQuerySupport::ON_BLIT_ENCODER);
592594
}
593595
// `TimestampQuerySupport::INSIDE_WGPU_PASSES` emerges from the other flags.
@@ -728,8 +730,7 @@ impl super::PrivateCapabilities {
728730
31
729731
},
730732
max_samplers_per_stage: 16,
731-
max_binding_array_elements: if argument_buffers == metal::MTLArgumentBuffersTier::Tier2
732-
{
733+
max_binding_array_elements: if argument_buffers == MTLArgumentBuffersTier::Tier2 {
733734
1_000_000
734735
} else if family_check && device.supports_family(MTLGPUFamily::Apple4) {
735736
96
@@ -753,8 +754,7 @@ impl super::PrivateCapabilities {
753754
buffer_alignment: if os_is_mac || os_is_xr { 256 } else { 64 },
754755
max_buffer_size: if version.at_least((10, 14), (12, 0), os_is_mac) {
755756
// maxBufferLength available on macOS 10.14+ and iOS 12.0+
756-
let buffer_size: metal::NSInteger =
757-
unsafe { msg_send![device.as_ref(), maxBufferLength] };
757+
let buffer_size: NSInteger = unsafe { msg_send![device.as_ref(), maxBufferLength] };
758758
buffer_size as _
759759
} else if os_is_mac {
760760
1 << 30 // 1GB on macOS 10.11 and up
@@ -955,7 +955,7 @@ impl super::PrivateCapabilities {
955955
| F::PARTIALLY_BOUND_BINDING_ARRAY,
956956
self.msl_version >= MTLLanguageVersion::V3_0
957957
&& self.supports_arrays_of_textures
958-
&& self.argument_buffers as u64 >= metal::MTLArgumentBuffersTier::Tier2 as u64,
958+
&& self.argument_buffers as u64 >= MTLArgumentBuffersTier::Tier2 as u64,
959959
);
960960
features.set(
961961
F::SHADER_INT64,
@@ -1080,9 +1080,9 @@ impl super::PrivateCapabilities {
10801080
}
10811081
}
10821082

1083-
pub fn map_format(&self, format: wgt::TextureFormat) -> metal::MTLPixelFormat {
1084-
use metal::MTLPixelFormat::*;
1083+
pub fn map_format(&self, format: wgt::TextureFormat) -> MTLPixelFormat {
10851084
use wgt::TextureFormat as Tf;
1085+
use MTLPixelFormat::*;
10861086
match format {
10871087
Tf::R8Unorm => R8Unorm,
10881088
Tf::R8Snorm => R8Snorm,
@@ -1229,10 +1229,10 @@ impl super::PrivateCapabilities {
12291229
&self,
12301230
format: wgt::TextureFormat,
12311231
aspects: crate::FormatAspects,
1232-
) -> metal::MTLPixelFormat {
1232+
) -> MTLPixelFormat {
12331233
use crate::FormatAspects as Fa;
1234-
use metal::MTLPixelFormat::*;
12351234
use wgt::TextureFormat as Tf;
1235+
use MTLPixelFormat::*;
12361236
match (format, aspects) {
12371237
// map combined depth-stencil format to their stencil-only format
12381238
// see https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/WhatsNewiniOS10tvOS10andOSX1012/WhatsNewiniOS10tvOS10andOSX1012.html#//apple_ref/doc/uid/TP40014221-CH14-DontLinkElementID_77

wgpu-hal/src/metal/command.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ use alloc::{
55
vec::Vec,
66
};
77
use core::ops::Range;
8+
use metal::{
9+
MTLIndexType, MTLLoadAction, MTLPrimitiveType, MTLScissorRect, MTLSize, MTLStoreAction,
10+
MTLViewport, MTLVisibilityResultMode, NSRange,
11+
};
812

913
// has to match `Temp::binding_sizes`
1014
const WORD_SIZE: usize = 4;
@@ -15,9 +19,9 @@ impl Default for super::CommandState {
1519
blit: None,
1620
render: None,
1721
compute: None,
18-
raw_primitive_type: metal::MTLPrimitiveType::Point,
22+
raw_primitive_type: MTLPrimitiveType::Point,
1923
index: None,
20-
raw_wg_size: metal::MTLSize::new(0, 0, 0),
24+
raw_wg_size: MTLSize::new(0, 0, 0),
2125
stage_infos: Default::default(),
2226
storage_buffer_length_map: Default::default(),
2327
vertex_buffer_size_map: Default::default(),
@@ -81,7 +85,7 @@ impl super::CommandEncoder {
8185
// As explained above, we need to do some write:
8286
// Conveniently, we have a buffer with every query set, that we can use for this for a dummy write,
8387
// since we know that it is going to be overwritten again on timer resolve and HAL doesn't define its state before that.
84-
let raw_range = metal::NSRange {
88+
let raw_range = NSRange {
8589
location: last_query.as_ref().unwrap().1 as u64 * crate::QUERY_SIZE,
8690
length: 1,
8791
};
@@ -413,7 +417,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
413417
.as_ref()
414418
.unwrap()
415419
.set_visibility_result_mode(
416-
metal::MTLVisibilityResultMode::Boolean,
420+
MTLVisibilityResultMode::Boolean,
417421
index as u64 * crate::QUERY_SIZE,
418422
);
419423
}
@@ -427,7 +431,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
427431
.render
428432
.as_ref()
429433
.unwrap()
430-
.set_visibility_result_mode(metal::MTLVisibilityResultMode::Disabled, 0);
434+
.set_visibility_result_mode(MTLVisibilityResultMode::Disabled, 0);
431435
}
432436
_ => {}
433437
}
@@ -473,7 +477,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
473477

474478
unsafe fn reset_queries(&mut self, set: &super::QuerySet, range: Range<u32>) {
475479
let encoder = self.enter_blit();
476-
let raw_range = metal::NSRange {
480+
let raw_range = NSRange {
477481
location: range.start as u64 * crate::QUERY_SIZE,
478482
length: (range.end - range.start) as u64 * crate::QUERY_SIZE,
479483
};
@@ -503,7 +507,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
503507
wgt::QueryType::Timestamp => {
504508
encoder.resolve_counters(
505509
set.counter_sample_buffer.as_ref().unwrap(),
506-
metal::NSRange::new(range.start as u64, (range.end - range.start) as u64),
510+
NSRange::new(range.start as u64, (range.end - range.start) as u64),
507511
&buffer.raw,
508512
offset,
509513
);
@@ -537,10 +541,10 @@ impl crate::CommandEncoder for super::CommandEncoder {
537541
at_descriptor.set_resolve_texture(Some(&resolve.view.raw));
538542
}
539543
let load_action = if at.ops.contains(crate::AttachmentOps::LOAD) {
540-
metal::MTLLoadAction::Load
544+
MTLLoadAction::Load
541545
} else {
542546
at_descriptor.set_clear_color(conv::map_clear_color(&at.clear_value));
543-
metal::MTLLoadAction::Clear
547+
MTLLoadAction::Clear
544548
};
545549
let store_action = conv::map_store_action(
546550
at.ops.contains(crate::AttachmentOps::STORE),
@@ -557,15 +561,15 @@ impl crate::CommandEncoder for super::CommandEncoder {
557561
at_descriptor.set_texture(Some(&at.target.view.raw));
558562

559563
let load_action = if at.depth_ops.contains(crate::AttachmentOps::LOAD) {
560-
metal::MTLLoadAction::Load
564+
MTLLoadAction::Load
561565
} else {
562566
at_descriptor.set_clear_depth(at.clear_value.0 as f64);
563-
metal::MTLLoadAction::Clear
567+
MTLLoadAction::Clear
564568
};
565569
let store_action = if at.depth_ops.contains(crate::AttachmentOps::STORE) {
566-
metal::MTLStoreAction::Store
570+
MTLStoreAction::Store
567571
} else {
568-
metal::MTLStoreAction::DontCare
572+
MTLStoreAction::DontCare
569573
};
570574
at_descriptor.set_load_action(load_action);
571575
at_descriptor.set_store_action(store_action);
@@ -580,15 +584,15 @@ impl crate::CommandEncoder for super::CommandEncoder {
580584
at_descriptor.set_texture(Some(&at.target.view.raw));
581585

582586
let load_action = if at.stencil_ops.contains(crate::AttachmentOps::LOAD) {
583-
metal::MTLLoadAction::Load
587+
MTLLoadAction::Load
584588
} else {
585589
at_descriptor.set_clear_stencil(at.clear_value.1);
586-
metal::MTLLoadAction::Clear
590+
MTLLoadAction::Clear
587591
};
588592
let store_action = if at.stencil_ops.contains(crate::AttachmentOps::STORE) {
589-
metal::MTLStoreAction::Store
593+
MTLStoreAction::Store
590594
} else {
591-
metal::MTLStoreAction::DontCare
595+
MTLStoreAction::DontCare
592596
};
593597
at_descriptor.set_load_action(load_action);
594598
at_descriptor.set_store_action(store_action);
@@ -948,8 +952,8 @@ impl crate::CommandEncoder for super::CommandEncoder {
948952
format: wgt::IndexFormat,
949953
) {
950954
let (stride, raw_type) = match format {
951-
wgt::IndexFormat::Uint16 => (2, metal::MTLIndexType::UInt16),
952-
wgt::IndexFormat::Uint32 => (4, metal::MTLIndexType::UInt32),
955+
wgt::IndexFormat::Uint16 => (2, MTLIndexType::UInt16),
956+
wgt::IndexFormat::Uint32 => (4, MTLIndexType::UInt32),
953957
};
954958
self.state.index = Some(super::IndexState {
955959
buffer_ptr: AsNative::from(binding.buffer.raw.as_ref()),
@@ -997,7 +1001,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
9971001
depth_range.end
9981002
};
9991003
let encoder = self.state.render.as_ref().unwrap();
1000-
encoder.set_viewport(metal::MTLViewport {
1004+
encoder.set_viewport(MTLViewport {
10011005
originX: rect.x as _,
10021006
originY: rect.y as _,
10031007
width: rect.w as _,
@@ -1008,7 +1012,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
10081012
}
10091013
unsafe fn set_scissor_rect(&mut self, rect: &crate::Rect<u32>) {
10101014
//TODO: support empty scissors by modifying the viewport
1011-
let scissor = metal::MTLScissorRect {
1015+
let scissor = MTLScissorRect {
10121016
x: rect.x as _,
10131017
y: rect.y as _,
10141018
width: rect.w as _,
@@ -1296,7 +1300,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
12961300
unsafe fn dispatch(&mut self, count: [u32; 3]) {
12971301
if count[0] > 0 && count[1] > 0 && count[2] > 0 {
12981302
let encoder = self.state.compute.as_ref().unwrap();
1299-
let raw_count = metal::MTLSize {
1303+
let raw_count = MTLSize {
13001304
width: count[0] as u64,
13011305
height: count[1] as u64,
13021306
depth: count[2] as u64,

0 commit comments

Comments
 (0)