Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ impl super::CapabilitiesQuery {
.any(|x| raw.supportsFeatureSet(x))
}

fn is_capture_mtl_device(device: &ProtocolObject<dyn MTLDevice>) -> bool {
let obj: &AnyObject = device.as_ref();
obj.class().name().to_string_lossy() == "CaptureMTLDevice"
}

/// Query the capabilities of the device.
pub fn new(device: &ProtocolObject<dyn MTLDevice>) -> Self {
// There are four different OSes we can target: macOS, iOS, tvOS and
Expand Down Expand Up @@ -1164,10 +1169,15 @@ impl super::CapabilitiesQuery {
tvos = 18.0,
visionos = 2.0,
) {
device_class_responds_to(device, sel!(supportsRaytracing))
&& device.supportsRaytracing()
&& device_class_responds_to(device, sel!(supportsRaytracingFromRender))
&& device.supportsRaytracingFromRender()
// Special case for Xcode Capture, which misreports ray tracing support.
if Self::is_capture_mtl_device(device) {
metal4 || (family_check && device.supportsFamily(MTLGPUFamily::Apple6))
} else {
device_class_responds_to(device, sel!(supportsRaytracing))
&& device.supportsRaytracing()
&& device_class_responds_to(device, sel!(supportsRaytracingFromRender))
&& device.supportsRaytracingFromRender()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The device_class_responds_to stuff was added to avoid tripping objc2 debug assertions when running against the capture device. So that part can be removed if we're not going to use it with the capture device anyways. But I'm also not thrilled about having both device_class_responds_to and is_capture_mtl_device for the same purpose.

Since the Metal feature set tables say:

Some GPU devices in the Mac2 family support ray tracing in compute pipelines. You can check an individual GPU’s support for this feature by inspecting its MTLDevice.supportsRaytracing property at runtime.

... maybe the thing to do here is:

metal4
    || (family_check && device.supportsFamily(MTLGPUFamily::Apple6))
    || device_class_responds_to(device, sel!(supportsRaytracing))
                        && device.supportsRaytracing()
                        && device_class_responds_to(device, sel!(supportsRaytracingFromRender))
                        && device.supportsRaytracingFromRender()

There's also the issue of ray tracing compute vs. render pipelines which determines whether support starts in Metal3 or Metal4. Maybe somebody more familiar with the wgpu ray tracing feature can suggest how to handle that.

One other idea... we could do an is_capture_mtl_device check on adapter creation, and if so, print a warning that feature detection is degraded, referencing a wgpu issue that captures the known problems.

} else {
false
},
Expand Down