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
 

Videos

Abrir menú Cerrar menú
  • Colecciones
  • Todos los videos
  • Información

Más videos

  • Información
  • Código
  • Get to know Metal function pointers

    Metal is a low-level, low-overhead hardware-accelerated graphics framework and shader application programming interface for producing stunning visual effects in applications. Discover how to make your shaders written in Metal Shading Language more programmable and extensible by using function pointers. Learn how to take advantage of this new feature for dynamic flow control in Metal shaders. Discover how to use function pointers to specify custom intersection functions in your ray tracing application. We'll explain how function pointers allow several compilations models so you can balance GPU pipeline size against runtime performance.

    Recursos

    • Modern rendering with Metal
    • Accelerating ray tracing and motion blur using Metal
    • Metal for Accelerating Ray Tracing
    • Debugging the shaders within a draw command or compute dispatch
    • Metal Feature Set Tables
    • Metal Performance Shaders
    • Metal
    • Metal Shading Language Specification
      • Video HD
      • Video SD

    Videos relacionados

    WWDC21

    • Discover compilation workflows in Metal
    • Discover Metal debugging, profiling, and asset creation tools
  • Buscar este video…
    • 3:09 - Our simple Path Tracer in Metal Shading Language:

      float3 shade(...);
      
      [[kernel]] void rtKernel(...
                               device Material *materials,
                               constant Light &light)
      {
          // ...
      
          device Material &material = materials[intersection.geometry_id];
          float3 result = shade(ray, triangleIntersectionData, material, light);
      
          // ...
      }
    • 3:30 - Our shading function

      float3 shade(...)
      {
          Lighting lighting = LightingFromLight(light, triangleIntersectionData);
      
          return CalculateLightingForMaterial(material, lighting, triangleIntersectionData);
      }
    • 4:59 - Declare a function as visible

      [[visible]]
      Lighting Area(Light light, TriangleIntersectionData triangleIntersectionData)
      {
          Lighting result;
          
          // Clever math code ...
          
          return result;
      }
    • 5:30 - Single compilation pipeline on CPU

      // Single compilation configuration
      let linkedFunctions = MTLLinkedFunctions()
      linkedFunctions.functions = [area, spot, sphere, hair, glass, skin]
      computeDescriptor.linkedFunctions = linkedFunctions
      
      // Pipeline creation
      let pipeline = try device.makeComputePipelineState(descriptor: computeDescriptor,
                                                         options: [],
                                                         reflection: nil)
    • 7:43 - Introducing MTLFunctionDescriptor

      // Create by function descriptor:
      let functionDescriptor = MTLFunctionDescriptor()
      functionDescriptor.name = "Area"
      // More configuration goes here
      let areaBinaryFunction = try library.makeFunction(descriptor: functionDescriptor)
    • 8:08 - Binary pre–compilation

      // Create and compile by function descriptor:
      let functionDescriptor = MTLFunctionDescriptor()
      functionDescriptor.name = "Area"
      functionDescriptor.options = MTLFunctionOptions.compileToBinary
      let areaBinaryFunction = try library.makeFunction(descriptor: functionDescriptor)
    • 8:20 - Binary functions

      // Specify binary functions on compute pipeline descriptor
      let linkedFunctions = MTLLinkedFunctions()
      linkedFunctions.functions = [spot, sphere, hair, glass, skin]
      linkedFunctions.binaryFunctions = [areaBinaryFunction]
      computeDescriptor.linkedFunctions = linkedFunctions
      
      // Pipeline creation
      let pipeline = try device.makeComputePipelineState(descriptor: computeDescriptor,
                                                         options: [],
                                                         reflection: nil)
    • 11:04 - Incremental compilation pipeline

      // Create initial pipeline with option
      computeDescriptor.supportAddingBinaryFunctions = true
      
      // Create and compile by function descriptor
      let functionDescriptor = MTLFunctionDescriptor()
      functionDescriptor.name = "Wood"
      functionDescriptor.options = MTLFunctionOptions.compileToBinary
      let wood = try library.makeFunction(descriptor: functionDescriptor)
      
      // Create new pipeline from existing pipeline
      let newPipeline =
         try pipeline.makeComputePipelineStateWithAdditionalBinaryFunctions(functions: [wood])
    • 12:22 - Visible function tables on the GPU

      // Helper using declaration in Metal
      using LightingFunction = Lighting(Light, TriangleIntersectionData);
      using MaterialFunction = float3(Material, Lighting, TriangleIntersectionData);
      
      // Specify tables as kernel parameters
      visible_function_table<LightingFunction> lightingFunctions [[buffer(1)]],
      visible_function_table<MaterialFunction> materialFunctions [[buffer(2)]],
      
      // Access via index
      LightingFunction *lightingFunction = lightingFunctions[light.index];
      Lighting lighting = lightingFunction(light, triangleIntersection);
      return materialFunctions[material.index](material, lighting, triangleIntersection);
    • 12:49 - Visible function tables on the CPU

      // Initialize descriptor
      let vftDescriptor = MTLVisibleFunctionTableDescriptor()
      vftDescriptor.functionCount = 3
      let lightingFunctionTable = pipeline.makeVisibleFunctionTable(descriptor: vftDescriptor)!
      
      // Find and set functions by handle
      let functionHandle = pipeline.functionHandle(function: spot)!
      lightingFunctionTable.setFunction(functionHandle, index:0)
      
      // Find and set functions by handle
      computeCommandEncoder.setVisibleFunctionTable(lightingFunctionTable, bufferIndex:1)
      argumentEncoder.setVisibleFunctionTable(lightingFunctionTable, index:1)
    • 14:23 - Function groups on GPU

      // Add function groups to our shading function
      float3 shade(...)
      {
          LightingFunction *lightingFunction = lightingFunctions[light.index];
          [[function_groups("lighting")]] Lighting lighting = lightingFunction(light,
      triangleIntersection);
          
          MaterialFunction *materialFunction = materialFunctions[material.index];
          [[function_groups("material")]] float3 result = materialFunction(material, lighting, triangleIntersection);
          return result;
      }
    • 14:49 - Function groups on CPU

      // Function Group configuration
      let linkedFunctions = MTLLinkedFunctions()
      linkedFunctions.functions = [area, spot, sphere, hair, glass, skin]
      linkedFunctions.groups = ["lighting" : [area, spot, sphere ],
                                "material" : [hair, glass, skin ] ]
      computeDescriptor.linkedFunctions = linkedFunctions

Developer Footer

  • Videos
  • WWDC20
  • Get to know Metal function pointers
  • 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