Skip to content

Commit

Permalink
added code to get to OutOfDeviceMemory error
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewl-thirdwayv committed May 22, 2017
1 parent 0dddd6f commit 40e0b24
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vulkano-win/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ categories = ["rendering::graphics-api"]
[dependencies]
vulkano = { version = "0.3.0", path = "../vulkano" }
winit = "0.6.4"
metal-rs = "0.3"
cocoa = "0.8.1"
objc = ""
28 changes: 28 additions & 0 deletions vulkano-win/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
extern crate vulkano;
extern crate winit;

extern crate objc;
extern crate cocoa;
extern crate metal_rs as metal;

use std::error;
use std::fmt;
use std::ptr;
Expand All @@ -13,6 +17,15 @@ use vulkano::swapchain::SurfaceCreationError;
use winit::{EventsLoop, WindowBuilder};
use winit::CreationError as WindowCreationError;

use objc::runtime::{YES};

use cocoa::base::id as cocoa_id;
use cocoa::appkit::{NSWindow, NSView};

use metal::*;

use std::mem;

pub fn required_extensions() -> InstanceExtensions {
let ideal = InstanceExtensions {
khr_surface: true,
Expand Down Expand Up @@ -160,5 +173,20 @@ unsafe fn winit_to_surface(instance: &Arc<Instance>, win: &winit::Window)
-> Result<Arc<Surface>, SurfaceCreationError>
{
use winit::os::macos::WindowExt;

unsafe {
let wnd: cocoa_id = mem::transmute(win.get_nswindow());

let layer = CAMetalLayer::new();

layer.set_edge_antialiasing_mask(0);
layer.set_presents_with_transaction(false);
layer.remove_all_animations();

let view = wnd.contentView();
view.setWantsLayer(YES);
view.setLayer(mem::transmute(layer.0)); // Bombs here with out of memory
}

Surface::from_macos_moltenvk(instance, win.get_nsview() as *const ())
}
1 change: 1 addition & 0 deletions vulkano/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ fn main() {
println!("cargo:rustc-link-lib=framework=MoltenVK");
println!("cargo:rustc-link-lib=framework=QuartzCore");
println!("cargo:rustc-link-lib=framework=Metal");
println!("cargo:rustc-link-lib=framework=Foundation");
}
}

0 comments on commit 40e0b24

Please sign in to comment.