Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  metal-buffer.rs

  Sprache: Rust
 

use std::sync::Arc;

use gpu_allocator::metal::{AllocationCreateDesc, Allocator, AllocatorCreateDesc};
use log::info;

fn main() {
    env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("trace")).init();

    let device = Arc::new(metal::Device::system_default().unwrap());

    // Setting up the allocator
    let mut allocator = Allocator::new(&AllocatorCreateDesc {
        device: device.clone(),
        debug_settings: Default::default(),
        allocation_sizes: Default::default(),
    })
    .unwrap();

    // Test allocating Gpu Only memory
    {
        let allocation_desc = AllocationCreateDesc::buffer(
            &device,
            "Test allocation (Gpu Only)",
            512,
            gpu_allocator::MemoryLocation::GpuOnly,
        );
        let allocation = allocator.allocate(&allocation_desc).unwrap();
        let _buffer = allocation.make_buffer().unwrap();
        allocator.free(&allocation).unwrap();
        info!("Allocation and deallocation of GpuOnly memory was successful.");
    }

    // Test allocating Cpu to Gpu memory
    {
        let allocation_desc = AllocationCreateDesc::buffer(
            &device,
            "Test allocation (Cpu to Gpu)",
            512,
            gpu_allocator::MemoryLocation::CpuToGpu,
        );
        let allocation = allocator.allocate(&allocation_desc).unwrap();
        let _buffer = allocation.make_buffer().unwrap();
        allocator.free(&allocation).unwrap();
        info!("Allocation and deallocation of CpuToGpu memory was successful.");
    }

    // Test allocating Gpu to Cpu memory
    {
        let allocation_desc = AllocationCreateDesc::buffer(
            &device,
            "Test allocation (Gpu to Cpu)",
            512,
            gpu_allocator::MemoryLocation::GpuToCpu,
        );
        let allocation = allocator.allocate(&allocation_desc).unwrap();
        let _buffer = allocation.make_buffer().unwrap();
        allocator.free(&allocation).unwrap();
        info!("Allocation and deallocation of GpuToCpu memory was successful.");
    }

    // Test allocating texture
    {
        let texture_desc = metal::TextureDescriptor::new();
        texture_desc.set_pixel_format(metal::MTLPixelFormat::RGBA8Unorm);
        texture_desc.set_width(64);
        texture_desc.set_height(64);
        texture_desc.set_storage_mode(metal::MTLStorageMode::Private);
        let allocation_desc =
            AllocationCreateDesc::texture(&device, "Test allocation (Texture)", &texture_desc);
        let allocation = allocator.allocate(&allocation_desc).unwrap();
        let _texture = allocation.make_texture(&texture_desc).unwrap();
        allocator.free(&allocation).unwrap();
        info!("Allocation and deallocation of Texture was successful.");
    }

    // Test allocating acceleration structure
    {
        let empty_array = metal::Array::from_slice(&[]);
        let acc_desc = metal::PrimitiveAccelerationStructureDescriptor::descriptor();
        acc_desc.set_geometry_descriptors(empty_array);
        let sizes = device.acceleration_structure_sizes_with_descriptor(&acc_desc);
        let allocation_desc = AllocationCreateDesc::acceleration_structure_with_size(
            &device,
            "Test allocation (Acceleration structure)",
            sizes.acceleration_structure_size,
            gpu_allocator::MemoryLocation::GpuOnly,
        );
        let allocation = allocator.allocate(&allocation_desc).unwrap();
        let _acc_structure = allocation.make_acceleration_structure();
        allocator.free(&allocation).unwrap();
        info!("Allocation and deallocation of Acceleration structure was successful.");
    }
}

Messung V0.5 in Prozent
C=96 H=94 G=94

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-06-23) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik