Create gfx-memory allocator

This commit is contained in:
Dzmitry Malyshau 2018-09-14 12:01:56 -04:00
parent 680918a11d
commit 7c23f7f0a2
4 changed files with 53 additions and 53 deletions

58
Cargo.lock generated
View File

@ -218,11 +218,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "gfx-backend-dx12" name = "gfx-backend-dx12"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#122da131665d8a757bdda7323442b9beb9ac2088" source = "git+https://github.com/gfx-rs/gfx?rev=a435a05#a435a052f604168154c645bb5033bb3f09d95e91"
dependencies = [ dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"derivative 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "derivative 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx)", "gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"spirv_cross 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "spirv_cross 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -234,22 +234,22 @@ dependencies = [
[[package]] [[package]]
name = "gfx-backend-empty" name = "gfx-backend-empty"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#122da131665d8a757bdda7323442b9beb9ac2088" source = "git+https://github.com/gfx-rs/gfx?rev=a435a05#a435a052f604168154c645bb5033bb3f09d95e91"
dependencies = [ dependencies = [
"gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx)", "gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)",
] ]
[[package]] [[package]]
name = "gfx-backend-metal" name = "gfx-backend-metal"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#122da131665d8a757bdda7323442b9beb9ac2088" source = "git+https://github.com/gfx-rs/gfx?rev=a435a05#a435a052f604168154c645bb5033bb3f09d95e91"
dependencies = [ dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"cocoa 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", "cocoa 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx)", "gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"metal 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "metal 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"objc 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "objc 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -263,11 +263,11 @@ dependencies = [
[[package]] [[package]]
name = "gfx-backend-vulkan" name = "gfx-backend-vulkan"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#122da131665d8a757bdda7323442b9beb9ac2088" source = "git+https://github.com/gfx-rs/gfx?rev=a435a05#a435a052f604168154c645bb5033bb3f09d95e91"
dependencies = [ dependencies = [
"ash 0.24.4 (registry+https://github.com/rust-lang/crates.io-index)", "ash 0.24.4 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx)", "gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)",
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -280,18 +280,7 @@ dependencies = [
[[package]] [[package]]
name = "gfx-hal" name = "gfx-hal"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx#122da131665d8a757bdda7323442b9beb9ac2088" source = "git+https://github.com/gfx-rs/gfx?rev=a435a05#a435a052f604168154c645bb5033bb3f09d95e91"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gfx-hal"
version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx?rev=6cb2a800b#6cb2a800b24affc34de1e6d0d93fd52a534e81a1"
dependencies = [ dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -302,10 +291,10 @@ dependencies = [
[[package]] [[package]]
name = "gfx-memory" name = "gfx-memory"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx-memory#4f6e4107806d19a54371325f3f5ae656300e3fea" source = "git+https://github.com/kvark/gfx-mem?branch=update#a82aa4221250a493c2fe6fcc22a2b6876742cef2"
dependencies = [ dependencies = [
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=6cb2a800b)", "gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)",
"relevant 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "relevant 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -313,12 +302,12 @@ dependencies = [
name = "gpu-native" name = "gpu-native"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"gfx-backend-dx12 0.1.0 (git+https://github.com/gfx-rs/gfx)", "gfx-backend-dx12 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)",
"gfx-backend-empty 0.1.0 (git+https://github.com/gfx-rs/gfx)", "gfx-backend-empty 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)",
"gfx-backend-metal 0.1.0 (git+https://github.com/gfx-rs/gfx)", "gfx-backend-metal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)",
"gfx-backend-vulkan 0.1.0 (git+https://github.com/gfx-rs/gfx)", "gfx-backend-vulkan 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)",
"gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx)", "gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)",
"gfx-memory 0.1.0 (git+https://github.com/gfx-rs/gfx-memory)", "gfx-memory 0.1.0 (git+https://github.com/kvark/gfx-mem?branch=update)",
] ]
[[package]] [[package]]
@ -850,13 +839,12 @@ dependencies = [
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" "checksum fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
"checksum gfx-backend-dx12 0.1.0 (git+https://github.com/gfx-rs/gfx)" = "<none>" "checksum gfx-backend-dx12 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)" = "<none>"
"checksum gfx-backend-empty 0.1.0 (git+https://github.com/gfx-rs/gfx)" = "<none>" "checksum gfx-backend-empty 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)" = "<none>"
"checksum gfx-backend-metal 0.1.0 (git+https://github.com/gfx-rs/gfx)" = "<none>" "checksum gfx-backend-metal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)" = "<none>"
"checksum gfx-backend-vulkan 0.1.0 (git+https://github.com/gfx-rs/gfx)" = "<none>" "checksum gfx-backend-vulkan 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)" = "<none>"
"checksum gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx)" = "<none>" "checksum gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)" = "<none>"
"checksum gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=6cb2a800b)" = "<none>" "checksum gfx-memory 0.1.0 (git+https://github.com/kvark/gfx-mem?branch=update)" = "<none>"
"checksum gfx-memory 0.1.0 (git+https://github.com/gfx-rs/gfx-memory)" = "<none>"
"checksum itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4833d6978da405305126af4ac88569b5d71ff758581ce5a987dbfa3755f694fc" "checksum itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4833d6978da405305126af4ac88569b5d71ff758581ce5a987dbfa3755f694fc"
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" "checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"

View File

@ -7,9 +7,10 @@ authors = ["Dzmitry Malyshau <kvark@mozilla.com>"]
default = [] default = []
[dependencies] [dependencies]
gfx-hal = { git = "https://github.com/gfx-rs/gfx" } gfx-hal = { git = "https://github.com/gfx-rs/gfx", rev = "a435a05" } # required by gfx-memory
gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx" } gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "a435a05" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", optional = true } gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "a435a05", optional = true }
gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", optional = true } gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "a435a05", optional = true }
gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", optional = true } gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "a435a05", optional = true }
gfx-memory = { git = "https://github.com/gfx-rs/gfx-memory" } #gfx-memory = { git = "https://github.com/gfx-rs/gfx-memory" }
gfx-memory = { git = "https://github.com/kvark/gfx-mem", branch = "update" }

View File

@ -17,8 +17,17 @@ pub struct CommandBufferDescriptor {
} }
pub struct Device<B: hal::Backend> { pub struct Device<B: hal::Backend> {
pub gpu: hal::Gpu<B>, gpu: hal::Gpu<B>,
pub memory_properties: hal::MemoryProperties, allocator: memory::SmartAllocator<B>,
}
impl<B: hal::Backend> Device<B> {
pub(crate) fn new(gpu: hal::Gpu<B>, mem_props: hal::MemoryProperties) -> Self {
Device {
gpu,
allocator: memory::SmartAllocator::new(mem_props, 1, 1, 1, 1),
}
}
} }
pub struct Buffer<B: hal::Backend> { pub struct Buffer<B: hal::Backend> {
@ -29,9 +38,10 @@ pub extern "C"
fn device_create_buffer( fn device_create_buffer(
device: DeviceHandle, desc: BufferDescriptor device: DeviceHandle, desc: BufferDescriptor
) -> BufferHandle { ) -> BufferHandle {
//let unbound = device.raw.create_buffer(desc.size, desc.usage).unwrap(); let buffer = device.gpu.device.create_buffer(desc.size, desc.usage).unwrap();
//let reqs = device.raw.get_buffer_requirements(&unbound); BufferHandle::new(Buffer {
unimplemented!() raw: buffer,
})
} }
pub extern "C" pub extern "C"

View File

@ -1,4 +1,3 @@
use back;
use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice}; use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice};
use {AdapterHandle, Device, DeviceHandle, InstanceHandle}; use {AdapterHandle, Device, DeviceHandle, InstanceHandle};
@ -28,8 +27,12 @@ pub struct DeviceDescriptor {
pub extern "C" pub extern "C"
fn create_instance() -> InstanceHandle { fn create_instance() -> InstanceHandle {
let inst = back::Instance::create("wgpu", 1); #[cfg(any(feature = "gfx-backend-vulkan", feature = "gfx-backend-dx12", feature = "gfx-backend-metal"))]
InstanceHandle::new(inst) {
let inst = ::back::Instance::create("wgpu", 1);
InstanceHandle::new(inst)
}
unimplemented!()
} }
pub extern "C" pub extern "C"
@ -59,8 +62,6 @@ fn adapter_create_device(
) -> DeviceHandle { ) -> DeviceHandle {
let queue_family = &adapter.queue_families[0]; let queue_family = &adapter.queue_families[0];
let gpu = adapter.physical_device.open(&[(queue_family, &[1f32])]).unwrap(); let gpu = adapter.physical_device.open(&[(queue_family, &[1f32])]).unwrap();
DeviceHandle::new(Device { let mem_props = adapter.physical_device.memory_properties();
gpu, DeviceHandle::new(Device::new(gpu, mem_props))
memory_properties: adapter.physical_device.memory_properties(),
})
} }