Skip to content

Commit 40e0b24

Browse files
added code to get to OutOfDeviceMemory error
1 parent 0dddd6f commit 40e0b24

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

vulkano-win/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ categories = ["rendering::graphics-api"]
1010
[dependencies]
1111
vulkano = { version = "0.3.0", path = "../vulkano" }
1212
winit = "0.6.4"
13+
metal-rs = "0.3"
14+
cocoa = "0.8.1"
15+
objc = ""

vulkano-win/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
extern crate vulkano;
22
extern crate winit;
33

4+
extern crate objc;
5+
extern crate cocoa;
6+
extern crate metal_rs as metal;
7+
48
use std::error;
59
use std::fmt;
610
use std::ptr;
@@ -13,6 +17,15 @@ use vulkano::swapchain::SurfaceCreationError;
1317
use winit::{EventsLoop, WindowBuilder};
1418
use winit::CreationError as WindowCreationError;
1519

20+
use objc::runtime::{YES};
21+
22+
use cocoa::base::id as cocoa_id;
23+
use cocoa::appkit::{NSWindow, NSView};
24+
25+
use metal::*;
26+
27+
use std::mem;
28+
1629
pub fn required_extensions() -> InstanceExtensions {
1730
let ideal = InstanceExtensions {
1831
khr_surface: true,
@@ -160,5 +173,20 @@ unsafe fn winit_to_surface(instance: &Arc<Instance>, win: &winit::Window)
160173
-> Result<Arc<Surface>, SurfaceCreationError>
161174
{
162175
use winit::os::macos::WindowExt;
176+
177+
unsafe {
178+
let wnd: cocoa_id = mem::transmute(win.get_nswindow());
179+
180+
let layer = CAMetalLayer::new();
181+
182+
layer.set_edge_antialiasing_mask(0);
183+
layer.set_presents_with_transaction(false);
184+
layer.remove_all_animations();
185+
186+
let view = wnd.contentView();
187+
view.setWantsLayer(YES);
188+
view.setLayer(mem::transmute(layer.0)); // Bombs here with out of memory
189+
}
190+
163191
Surface::from_macos_moltenvk(instance, win.get_nsview() as *const ())
164192
}

vulkano/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ fn main() {
1717
println!("cargo:rustc-link-lib=framework=MoltenVK");
1818
println!("cargo:rustc-link-lib=framework=QuartzCore");
1919
println!("cargo:rustc-link-lib=framework=Metal");
20+
println!("cargo:rustc-link-lib=framework=Foundation");
2021
}
2122
}

0 commit comments

Comments
 (0)