From 40e0b24127b3d7874356f92fa39a28c857d2ef81 Mon Sep 17 00:00:00 2001 From: "Andrew P. Lentvorski" Date: Mon, 22 May 2017 09:52:36 -0700 Subject: [PATCH] added code to get to OutOfDeviceMemory error --- vulkano-win/Cargo.toml | 3 +++ vulkano-win/src/lib.rs | 28 ++++++++++++++++++++++++++++ vulkano/build.rs | 1 + 3 files changed, 32 insertions(+) diff --git a/vulkano-win/Cargo.toml b/vulkano-win/Cargo.toml index 4f5ab5a879..338dd5d75b 100644 --- a/vulkano-win/Cargo.toml +++ b/vulkano-win/Cargo.toml @@ -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 = "" \ No newline at end of file diff --git a/vulkano-win/src/lib.rs b/vulkano-win/src/lib.rs index 44806fb9c4..b97232ddc7 100644 --- a/vulkano-win/src/lib.rs +++ b/vulkano-win/src/lib.rs @@ -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; @@ -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, @@ -160,5 +173,20 @@ unsafe fn winit_to_surface(instance: &Arc, win: &winit::Window) -> Result, 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 ()) } diff --git a/vulkano/build.rs b/vulkano/build.rs index 0e7e64a3b0..dce0a24e3c 100644 --- a/vulkano/build.rs +++ b/vulkano/build.rs @@ -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"); } }