Skip to content

Commit 78a5b22

Browse files
madsmtmcwfitzgerald
authored andcommitted
[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 38b6663 commit 78a5b22

File tree

6 files changed

+211
-213
lines changed

6 files changed

+211
-213
lines changed

wgpu-hal/src/metal/adapter.rs

+15-15
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

+26-22
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
);
@@ -540,10 +544,10 @@ impl crate::CommandEncoder for super::CommandEncoder {
540544
at_descriptor.set_resolve_texture(Some(&resolve.view.raw));
541545
}
542546
let load_action = if at.ops.contains(crate::AttachmentOps::LOAD) {
543-
metal::MTLLoadAction::Load
547+
MTLLoadAction::Load
544548
} else {
545549
at_descriptor.set_clear_color(conv::map_clear_color(&at.clear_value));
546-
metal::MTLLoadAction::Clear
550+
MTLLoadAction::Clear
547551
};
548552
let store_action = conv::map_store_action(
549553
at.ops.contains(crate::AttachmentOps::STORE),
@@ -560,15 +564,15 @@ impl crate::CommandEncoder for super::CommandEncoder {
560564
at_descriptor.set_texture(Some(&at.target.view.raw));
561565

562566
let load_action = if at.depth_ops.contains(crate::AttachmentOps::LOAD) {
563-
metal::MTLLoadAction::Load
567+
MTLLoadAction::Load
564568
} else {
565569
at_descriptor.set_clear_depth(at.clear_value.0 as f64);
566-
metal::MTLLoadAction::Clear
570+
MTLLoadAction::Clear
567571
};
568572
let store_action = if at.depth_ops.contains(crate::AttachmentOps::STORE) {
569-
metal::MTLStoreAction::Store
573+
MTLStoreAction::Store
570574
} else {
571-
metal::MTLStoreAction::DontCare
575+
MTLStoreAction::DontCare
572576
};
573577
at_descriptor.set_load_action(load_action);
574578
at_descriptor.set_store_action(store_action);
@@ -583,15 +587,15 @@ impl crate::CommandEncoder for super::CommandEncoder {
583587
at_descriptor.set_texture(Some(&at.target.view.raw));
584588

585589
let load_action = if at.stencil_ops.contains(crate::AttachmentOps::LOAD) {
586-
metal::MTLLoadAction::Load
590+
MTLLoadAction::Load
587591
} else {
588592
at_descriptor.set_clear_stencil(at.clear_value.1);
589-
metal::MTLLoadAction::Clear
593+
MTLLoadAction::Clear
590594
};
591595
let store_action = if at.stencil_ops.contains(crate::AttachmentOps::STORE) {
592-
metal::MTLStoreAction::Store
596+
MTLStoreAction::Store
593597
} else {
594-
metal::MTLStoreAction::DontCare
598+
MTLStoreAction::DontCare
595599
};
596600
at_descriptor.set_load_action(load_action);
597601
at_descriptor.set_store_action(store_action);
@@ -953,8 +957,8 @@ impl crate::CommandEncoder for super::CommandEncoder {
953957
format: wgt::IndexFormat,
954958
) {
955959
let (stride, raw_type) = match format {
956-
wgt::IndexFormat::Uint16 => (2, metal::MTLIndexType::UInt16),
957-
wgt::IndexFormat::Uint32 => (4, metal::MTLIndexType::UInt32),
960+
wgt::IndexFormat::Uint16 => (2, MTLIndexType::UInt16),
961+
wgt::IndexFormat::Uint32 => (4, MTLIndexType::UInt32),
958962
};
959963
self.state.index = Some(super::IndexState {
960964
buffer_ptr: AsNative::from(binding.buffer.raw.as_ref()),
@@ -1002,7 +1006,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
10021006
depth_range.end
10031007
};
10041008
let encoder = self.state.render.as_ref().unwrap();
1005-
encoder.set_viewport(metal::MTLViewport {
1009+
encoder.set_viewport(MTLViewport {
10061010
originX: rect.x as _,
10071011
originY: rect.y as _,
10081012
width: rect.w as _,
@@ -1013,7 +1017,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
10131017
}
10141018
unsafe fn set_scissor_rect(&mut self, rect: &crate::Rect<u32>) {
10151019
//TODO: support empty scissors by modifying the viewport
1016-
let scissor = metal::MTLScissorRect {
1020+
let scissor = MTLScissorRect {
10171021
x: rect.x as _,
10181022
y: rect.y as _,
10191023
width: rect.w as _,
@@ -1301,7 +1305,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
13011305
unsafe fn dispatch(&mut self, count: [u32; 3]) {
13021306
if count[0] > 0 && count[1] > 0 && count[2] > 0 {
13031307
let encoder = self.state.compute.as_ref().unwrap();
1304-
let raw_count = metal::MTLSize {
1308+
let raw_count = MTLSize {
13051309
width: count[0] as u64,
13061310
height: count[1] as u64,
13071311
depth: count[2] as u64,

0 commit comments

Comments
 (0)