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
 

Vídeos

Abrir menu Fechar menu
  • Coleções
  • Todos os vídeos
  • Sobre

Mais vídeos

  • Sobre
  • Código
  • Maximize your Metal ray tracing performance

    Learn how to simplify your ray tracing code and increase performance with the power of Metal 3. We'll explore the GPU debugging and profiling tools that can help you tune your ray tracing applications. We'll also show you how you can speed up intersection tests and reduce shader code memory accesses and indirections with per-primitive data in an acceleration structure. And we'll help you implement faster acceleration structure builds and refits to reduce load times and per-frame overhead.

    Recursos

    • Accelerating ray tracing using Metal
    • Metal
      • Vídeo HD
      • Vídeo SD

    Vídeos relacionados

    Tech Talks

    • Discover new Metal profiling tools for M3 and A17 Pro
    • Explore GPU advancements in M3 and A17 Pro

    WWDC23

    • Your guide to Metal ray tracing

    WWDC22

    • Discover Metal 3
    • Go bindless with Metal 3

    WWDC21

    • Discover Metal debugging, profiling, and asset creation tools

    WWDC20

    • Debug GPU-side errors in Metal
  • Buscar neste vídeo...
    • 4:04 - Alpha testing with intersection functions

      float alpha = texture.sample(sampler, UV).w;
      return alpha >= 0.5f;
    • 5:46 - Alpha testing intersection function

      [[intersection(triangle, raytracing::triangle_data, raytracing::instancing)]]
      bool alphaTestIntersection(float2               coordinates    [[barycentric_coord]],
                                 unsigned int         primitiveIndex [[primitive_id]],
                                 unsigned int         instanceIndex  [[instance_id]],
                                 device GlobalData   *globalData     [[buffer(1)]],
                                 device InstanceData *instanceData   [[buffer(0)]])
      {
          device Material *materials = globalData->materials;
          InstanceData instance = instanceData[instanceIndex];
          float2 UV = calculateSamplingCoords(coordinates,
                                              instance.uvs[primitiveIndex * 3 + 0],
                                              instance.uvs[primitiveIndex * 3 + 1],
                                              instance.uvs[primitiveIndex * 3 + 2]);
          int materialIndex = instance.materialIndices[primitiveIndex];
          float alpha = materials[materialIndex].texture.sample(sam, UV).w;
          return alpha >= 0.5f;
      }
    • 6:48 - Primitive Data

      struct PrimitiveData
      {
          texture2d<float> texture;
          float2 uvs[3];
      };
    • 7:08 - Alpha testing intersection function using per-primitive data

      // Alpha testing intersection function
      [[intersection(triangle, raytracing::triangle_data, raytracing::instancing)]]
      bool alphaTestIntersection(float2               coordinates    [[barycentric_coord]],
                           const device PrimitiveData *primitiveData [[primitive_data]])
      {
          PrimitiveData ppd = *primitiveData;
          float2 UV = calculateSamplingCoords(coordinates,
                                              ppd.uvs[0],
                                              ppd.uvs[1],
                                              ppd.uvs[2]);
          float alpha = ppd.texture.sample(sam, UV).w;
          return alpha >= 0.5f;
      }
    • 8:54 - Setting up per-primitive data

      geometryDescriptor.primitiveDataBuffer = primitiveDataBuffer
      geometryDescriptor.primitiveDataElementSize = MemoryLayout<PrimitiveData>.size
      geometryDescriptor.primitiveDataStride = MemoryLayout<PrimitiveData>.stride
      geometryDescriptor.primitiveDataBufferOffset = primitiveDataOffset
    • 9:18 - Using per-primitive data

      // Intersection function argument:
      const device void *primitiveData [[primitive_data]]
      
      // Intersection result:
      primitiveData = intersection.primitive_data;
      
      // Intersection query:
      primitiveData = query.get_candidate_primitive_data();
      primitiveData = query.get_committed_primitive_data();
    • 11:08 - Buffers from intersection function tables

      device int *buffer = intersectionFunctionTable.get_buffer<device int *>(index);
      
      visible_function_table<uint(uint)> table =
          intersectionFunctionTable.get_visible_function_table<uint(uint)>(index);
      
      uint result = table[0](parameter);
    • 11:36 - Ray tracing from indirect command buffers

      let icbDescriptor = MTLIndirectCommandBufferDescriptor()
      
      icbDescriptor.supportRayTracing = true
    • 15:43 - Parallel acceleration structure builds

      for (index, accelerationStructure) in accelerationStructures.enumerated() {
          encoder.build(accelerationStructure: accelerationStructure,
                        descriptor: descriptors[index],
                        scratchBuffer: scratchBuffers[index % numScratchBuffers],
                        scratchBufferOffset: 0)
      }
    • 17:28 - Setting vertex formats

      let geometryDescriptor = MTLAccelerationStructureTriangleGeometryDescriptor()
      
      geometryDescriptor.vertexFormat = .uint1010102Normalized
    • 18:29 - Creating transformation matrix buffer

      var scaleTransform =
          MTLPackedFloat4x3(columns: (
              MTLPackedFloat3Make( scale.x,      0.0,      0.0),
              MTLPackedFloat3Make(     0.0,  scale.y,      0.0),
              MTLPackedFloat3Make(     0.0,      0.0,  scale.z),
              MTLPackedFloat3Make(offset.x, offset.y, offset.z))
      
      let transformBuffer = device.makeBuffer(length: MemoryLayout<MTLPackedFloat4x3>.size,
                                              options: .storageModeShared)!
      
      transformBuffer.contents().copyMemory(from: &scaleTransform,
                                            byteCount: MemoryLayout<MTLPackedFloat4x3>.size)
    • 18:51 - Setting transformation matrix buffer on geometry descriptor

      let geometryDescriptor = MTLAccelerationStructureTriangleGeometryDescriptor()
      
      geometryDescriptor.transformationMatrixBuffer = transformBuffer
      geometryDescriptor.transformationMatrixBufferOffset = 0
    • 20:12 - Merging instances using transformation matrices

      let sphereGeometryDescriptor = MTLAccelerationStructureTriangleGeometryDescriptor()
      sphereGeometryDescriptor.vertexBuffer = sphereVertexBuffer
      sphereGeometryDescriptor.indexBuffer = sphereIndexBuffer
      sphereGeometryDescriptor.transformationMatrixBuffer = sphereTransformBuffer
      
      let redBoxGeometryDescriptor = MTLAccelerationStructureTriangleGeometryDescriptor()
      redBoxGeometryDescriptor.vertexBuffer = boxVertexBuffer
      redBoxGeometryDescriptor.indexBuffer = boxIndexBuffer
      redBoxGeometryDescriptor.transformationMatrixBuffer = redBoxTransformBuffer
      
      let blueBoxGeometryDescriptor = MTLAccelerationStructureTriangleGeometryDescriptor()
      blueBoxGeometryDescriptor.vertexBuffer = boxVertexBuffer
      blueBoxGeometryDescriptor.indexBuffer = boxIndexBuffer blueBoxGeometryDescriptor.transformationMatrixBuffer = blueBoxTransformBuffer
      
      let primitiveASDescriptor = MTLPrimitiveAccelerationStructureDescriptor()
      
      primitiveASDescriptor.geometryDescriptors =
          [sphereGeometryDescriptor, redBoxGeometryDescriptor, blueBoxGeometryDescriptor]
    • 22:33 - Heap acceleration structure allocation

      let heap = device.makeHeap(descriptor: heapDescriptor)!
      
      let accelerationStructure = heap.makeAccelerationStructure(descriptor: descriptor)
      
      let sizeAndAlign = device.heapAccelerationStructureSizeAndAlign(descriptor: descriptor)
      
      let accelerationStructure = heap.makeAccelerationStructure(size: sizeAndAlign.size)

Developer Footer

  • Vídeos
  • WWDC22
  • Maximize your Metal ray tracing performance
  • 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