Skip to content
Merged
Show file tree
Hide file tree
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
30 changes: 21 additions & 9 deletions src/graphics/metal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,11 @@ impl RenderingBackend for MetalContext {
msg_send_![descriptor, setVertexFunction:shader_internal.vertex_function];
msg_send_![descriptor, setFragmentFunction:shader_internal.fragment_function];
msg_send_![descriptor, setVertexDescriptor: vertex_descriptor];
// Only attachment 0 — the backend has no MRT path and
// setting attachment 1 to a non-Invalid pixelFormat
// fails Metal validation when no texture is bound.
let color_attachments = msg_send_![descriptor, colorAttachments];
for i in 0..2 {
for i in 0..1usize {
let color_attachment = msg_send_![color_attachments, objectAtIndexedSubscript: i];
let view_pixel_format: MTLPixelFormat = msg_send![self.view, colorPixelFormat];
msg_send_![color_attachment, setPixelFormat: view_pixel_format];
Expand Down Expand Up @@ -977,14 +980,23 @@ impl RenderingBackend for MetalContext {
];
}
}
msg_send_![
descriptor,
setDepthAttachmentPixelFormat: MTLPixelFormat::Depth32Float_Stencil8
];
msg_send_![
descriptor,
setStencilAttachmentPixelFormat: MTLPixelFormat::Depth32Float_Stencil8
];
// Pipeline depth/stencil formats must match whatever
// render pass uses this pipeline. MTKView reports
// `Invalid` when no depth/stencil is configured —
// leave the descriptor's defaults (also `Invalid`)
// alone in that case; otherwise mirror the view.
let view_depth_stencil_format: MTLPixelFormat =
msg_send![self.view, depthStencilPixelFormat];
if view_depth_stencil_format != MTLPixelFormat::Invalid {
msg_send_![
descriptor,
setDepthAttachmentPixelFormat: view_depth_stencil_format
];
msg_send_![
descriptor,
setStencilAttachmentPixelFormat: view_depth_stencil_format
];
}

let mut error: ObjcId = nil;
let pipeline_state: ObjcId = msg_send![
Expand Down
1 change: 1 addition & 0 deletions src/native/apple/frameworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ impl MTLClearColor {
#[allow(non_camel_case_types)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum MTLPixelFormat {
Invalid = 0,
BGRA8Unorm = 80,
Depth32Float = 252,
Stencil8 = 253,
Expand Down
Loading