This commit is contained in:
Michael Zhang 2021-01-15 13:45:11 -06:00
parent da7b86ab31
commit b95e50c177
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
5 changed files with 285 additions and 5 deletions

204
Cargo.lock generated
View file

@ -129,6 +129,15 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e"
[[package]]
name = "ash"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c69a8137596e84c22d57f3da1b5de1d4230b1742a710091c85f4d7ce50f00f38"
dependencies = [
"libloading",
]
[[package]]
name = "atty"
version = "0.2.14"
@ -199,6 +208,21 @@ dependencies = [
"shlex",
]
[[package]]
name = "bit-set"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de"
dependencies = [
"bit-vec",
]
[[package]]
name = "bit-vec"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
[[package]]
name = "bitflags"
version = "1.2.1"
@ -300,6 +324,9 @@ name = "cc"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48"
dependencies = [
"jobserver",
]
[[package]]
name = "cesu8"
@ -503,6 +530,12 @@ dependencies = [
"url",
]
[[package]]
name = "copyless"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536"
[[package]]
name = "core-foundation"
version = "0.6.4"
@ -700,6 +733,17 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "d3d12"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a60cceb22c7c53035f8980524fdc7f17cf49681a3c154e6757d30afbec6ec4"
dependencies = [
"bitflags",
"libloading",
"winapi 0.3.9",
]
[[package]]
name = "darling"
version = "0.10.2"
@ -937,6 +981,9 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bass-sys",
"gfx-backend-dx12",
"gfx-backend-metal",
"gfx-backend-vulkan",
"gfx-hal",
"winit",
]
@ -966,6 +1013,15 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]]
name = "getrandom"
version = "0.1.16"
@ -999,6 +1055,83 @@ dependencies = [
"log",
]
[[package]]
name = "gfx-auxil"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07cd956b592970f08545b9325b87580eb95a51843b6f39da27b8667fec1a1216"
dependencies = [
"fxhash",
"gfx-hal",
"spirv_cross",
]
[[package]]
name = "gfx-backend-dx12"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "375014deed24d76b03604736dd899f0925158a1a96db90cbefb9cce070f71af7"
dependencies = [
"arrayvec",
"bit-set",
"bitflags",
"d3d12",
"gfx-auxil",
"gfx-hal",
"log",
"range-alloc",
"raw-window-handle",
"smallvec",
"spirv_cross",
"winapi 0.3.9",
]
[[package]]
name = "gfx-backend-metal"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "273d60d5207f96d99e0d11d0718995f67e56533a9df1444d83baf787f4c3cb32"
dependencies = [
"arrayvec",
"bitflags",
"block",
"cocoa-foundation",
"copyless",
"foreign-types",
"gfx-auxil",
"gfx-hal",
"lazy_static",
"log",
"metal",
"objc",
"parking_lot",
"range-alloc",
"raw-window-handle",
"smallvec",
"spirv_cross",
"storage-map",
]
[[package]]
name = "gfx-backend-vulkan"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a3a63cf61067a09b7d1ac480af3cb2ae0c5ede5bed294607bbd814cb1666c45"
dependencies = [
"arrayvec",
"ash",
"byteorder",
"core-graphics-types",
"gfx-hal",
"inplace_it",
"lazy_static",
"log",
"objc",
"raw-window-handle",
"smallvec",
"winapi 0.3.9",
]
[[package]]
name = "gfx-hal"
version = "0.6.0"
@ -1043,7 +1176,7 @@ dependencies = [
[[package]]
name = "ggez"
version = "0.6.0-rc0"
source = "git+https://github.com/ggez/ggez?branch=devel#0428e88b9f362118baf183a63d7a7b9e322fcf34"
source = "git+https://github.com/ggez/ggez?branch=devel#32b480356d04911234c8a70c79a72942e76830a8"
dependencies = [
"approx",
"bitflags",
@ -1347,6 +1480,12 @@ dependencies = [
"winit",
]
[[package]]
name = "inplace_it"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd01a2a73f2f399df96b22dc88ea687ef4d76226284e7531ae3c7ee1dc5cb534"
[[package]]
name = "instant"
version = "0.1.9"
@ -1418,6 +1557,15 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "jobserver"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2"
dependencies = [
"libc",
]
[[package]]
name = "jpeg-decoder"
version = "0.1.20"
@ -1680,6 +1828,20 @@ dependencies = [
"autocfg",
]
[[package]]
name = "metal"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c4e8a431536529327e28c9ba6992f2cb0c15d4222f0602a16e6d7695ff3bccf"
dependencies = [
"bitflags",
"block",
"cocoa-foundation",
"foreign-types",
"log",
"objc",
]
[[package]]
name = "minimp3"
version = "0.5.1"
@ -1999,6 +2161,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
dependencies = [
"malloc_buf",
"objc_exception",
]
[[package]]
name = "objc_exception"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4"
dependencies = [
"cc",
]
[[package]]
@ -2253,9 +2425,9 @@ dependencies = [
[[package]]
name = "quickcheck"
version = "1.0.2"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03e10546770d370e4eb8ac183a4bdbf9044059afdcbbba3c98627412f93461e3"
checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6"
dependencies = [
"env_logger",
"log",
@ -2363,6 +2535,12 @@ dependencies = [
"rand_core 0.6.1",
]
[[package]]
name = "range-alloc"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a871f1e45a3a3f0c73fb60343c811238bb5143a81642e27c2ac7aac27ff01a63"
[[package]]
name = "raw-window-handle"
version = "0.3.3"
@ -2746,6 +2924,17 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "spirv_cross"
version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ebd49af36be83ecd6290b57147e2a0e26145b832634b17146d934b197ca3713"
dependencies = [
"cc",
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "standback"
version = "0.2.14"
@ -2831,6 +3020,15 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
[[package]]
name = "storage-map"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418bb14643aa55a7841d5303f72cf512cfb323b8cc221d51580500a1ca75206c"
dependencies = [
"lock_api",
]
[[package]]
name = "strsim"
version = "0.8.0"

View file

@ -9,3 +9,10 @@ anyhow = "1.0.38"
gfx-hal = "0.6.0"
winit = { version = "0.24.0", features = ["web-sys"] }
bass-sys = { path = "../bass-sys" }
gfx-backend-vulkan = "0.6.5"
[target.'cfg(target_os = "macos")'.dependencies]
gfx-backend-metal = "0.6.5"
[target.'cfg(windows)'.dependencies]
gfx-backend-dx12 = "0.6.13"

76
framework/src/graphics.rs Normal file
View file

@ -0,0 +1,76 @@
#[cfg(windows)]
use gfx_backend_dx12 as back;
#[cfg(target_os = "macos")]
use gfx_backend_metal as back;
#[cfg(not(any(windows, target_os = "macos")))]
use gfx_backend_vulkan as back;
use std::mem::ManuallyDrop;
use std::ptr;
use anyhow::{anyhow, Result};
use gfx_hal::{
adapter::{Adapter, Gpu, PhysicalDevice},
device::Device,
pool::CommandPoolCreateFlags,
queue::{family::QueueFamily, QueueGroup, QueueType},
window::Surface,
Backend, Features, Instance,
};
use winit::window::Window;
pub struct Renderer<B: Backend> {
surface: ManuallyDrop<B::Surface>,
device: B::Device,
adapter: Adapter<B>,
queue_group: QueueGroup<B>,
instance: B::Instance,
}
impl<B: Backend> Renderer<B> {
pub fn new(
instance: B::Instance,
mut surface: B::Surface,
adapter: Adapter<B>,
) -> Result<Renderer<B>> {
let family = adapter
.queue_families
.iter()
.find(|family| {
surface.supports_queue_family(family) && family.queue_type().supports_graphics()
})
.unwrap();
let mut gpu = unsafe {
adapter
.physical_device
.open(&[(family, &[1.0])], Features::empty())
}?;
let mut queue_group = gpu.queue_groups.pop().unwrap();
let device = gpu.device;
let mut command_pool = unsafe {
device.create_command_pool(queue_group.family, CommandPoolCreateFlags::empty())
}?;
Ok(Renderer {
surface: ManuallyDrop::new(surface),
device,
adapter,
queue_group,
instance,
})
}
}
impl<B: Backend> Drop for Renderer<B> {
fn drop(&mut self) {
self.device.wait_idle().unwrap();
unsafe {
let surface = ManuallyDrop::into_inner(ptr::read(&self.surface));
self.instance.destroy_surface(surface);
}
}
}

View file

@ -1,4 +1,4 @@
mod game;
mod renderer;
mod graphics;
pub use crate::game::Game;

View file

@ -1 +0,0 @@