View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vidéos

Ouvrir le menu Fermer le menu
  • Collections
  • Toutes les vidéos
  • À propos

Plus de vidéos

  • À propos
  • Code
  • Transform your geometry with Metal mesh shaders

    Meet Metal mesh shaders — a modern and flexible pipeline in Metal for GPU-driven geometry creation and processing. We'll explore how this API can improve and add flexibility to your render pipeline, and share some of the opportunities that GPU-driven work can create. Discover how you can create procedural geometry — like hair rendering — on the GPU using mesh shaders, and build single render passes without additional compute passes or intermediate buffers. We'll also show you how to improve scene processing and rendering through GPU-driven meshlet culling.

    Ressources

    • Adjusting the level of detail using Metal mesh shaders
    • Metal
      • Vidéo HD
      • Vidéo SD

    Vidéos connexes

    Tech Talks

    • Explore GPU advancements in M3 and A17 Pro

    WWDC22

    • Discover Metal 3
    • WWDC22 Day 3 recap
  • Rechercher dans cette vidéo…
    • 8:13 - Object shader (MSL)

      [[object]] 
      void objectShader(object_data CurvePayload *payloadOutput [[payload]],
                                   const device void *inputData [[buffer(0)]], 
                                   uint hairID [[thread_index_in_threadgroup]],
                                   uint triangleID [[threadgroup_position_in_grid]],
                                   mesh_grid_properties mgp)
      {
          if (hairID < kHairsPerBlock)
             payloadOutput[hairID] = generateCurveData(inputData, hairID, triangleID);
          if (hairID == 0)
             mgp.set_threadgroups_per_grid(uint3(kHairPerBlockX, kHairPerBlockY, 1));
      }
    • 8:35 - Initializing object stage

      let meshPipelineDescriptor = MTLMeshRenderPipelineDescriptor()
      meshPipelineDescriptor.objectFunction = objectFunction
      meshPipelineDescriptor.payloadMemoryLength = payloadLength
      meshPipelineDescriptor.maxTotalThreadsPerObjectThreadgroup = hairsPerBlock
    • 9:26 - Defining a Metal Mesh

      struct VertexData    { float4 position [[position]]; };
      struct PrimitiveData { float4 color; };
      
      using triangle_mesh_t = metal::mesh<
                                          VertexData,               // Vertex type
                                          PrimitiveData,            // Primitive type
                                          10,                       // Maximum vertices
                                          6,                        // Maximum primitives
                                          metal::topology::triangle // Topology
      >;
      
      [[mesh]] 
      void myMeshShader(triangle_mesh_t outputMesh, ...);
    • 11:16 - Mesh Shader (MSL)

      [[mesh]] void myMeshShader(triangle_mesh_t outputMesh,
                               uint tid [[thread_index_in_threadgroup]])
      {
      
          if (tid < kVertexCount) 
              outputMesh.set_vertex(tid, calculateVertex(tid));
      
          if (tid < kIndexCount) 
              outputMesh.set_index(tid, calculateIndex(tid));
      
          if (tid < kPrimitiveCount)
              outputMesh.set_primitive(tid, calculatePrimitive(tid));
      
      if (tid == 0)
          outputMesh.set_primitive_count(kPrimitiveCount);
      
      }
    • 11:35 - Initializing the mesh stage

      meshPipelineDescriptor.meshFunction = meshFunction
      meshPipelineDescriptor.maxTotalThreadsPerMeshThreadgroup = vertexCountPerHair
    • 12:08 - Initializing the fragment stage

      meshPipelineDescriptor.maxTotalThreadsPerMeshThreadgroup = vertexCountPerHair
    • 12:14 - Creating a mesh render pipeline

      /// A mesh pipeline state the device creates from a mesh render pipeline descriptor.
      let meshPipeline: MTLRenderPipelineState
      
      do {
          /// A tuple of the mesh pipeline and its reflection information, if applicable.
          let (pipeline, reflection) = try device.makeRenderPipelineState(descriptor: meshRenderPipelineDescriptor,
                                                                          options: [])
          meshPipeline = pipeline
      } catch {
          print("The device can't create a mesh pipeline state: \(error)")
          return
      }
    • 12:25 - Encoding a mesh pipeline

      // Create a encoder for a render pass from the command buffer.
      let encoder: MTLRenderCommandEncoder!
      encoder = commandBuffer.makeRenderCommandEncoder(descriptor: descriptor)
      
      // Apply the mesh pipeline to the render pass.
      encoder.setRenderPipelineState(meshPipeline)
      
      // Bind the resources for the render pass.
      encoder.setObjectBuffer(objectBuffer, offset: 0, index: 0)
      encoder.setMeshTexture(meshTexture, index: 2)
      encoder.setFragmentBuffer(fragmentBuffer, offset: 0, index: 0)
      
      // Create the size instances for the mesh threadgroups.
      let objectGridDimensions = MTLSize(width: trianglesPerModel, height: 1, depth: 1)
      let threadsPerObject = MTLSize(width: hairsPerBlock, height: 1, depth: 1)
      let threadsPerMesh = MTLSize(width: threadsPerHair, height: 1, depth: 1)
      
      // Encode the draw command for the render pass.
      encoder.drawMeshThreadgroups(objectGridDimensions,
                                   threadsPerObjectThreadgroup: threadsPerObject,
                                   threadsPerMeshThreadgroup: threadsPerMesh)
      
      // Finish encoding the render pass.
      encoder.endEncoding()

Developer Footer

  • Vidéos
  • WWDC22
  • Transform your geometry with Metal mesh shaders
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines