From 4f513a35291141345f741c26b435a8677771bdcf Mon Sep 17 00:00:00 2001 From: grovesNL Date: Sat, 15 Sep 2018 11:04:36 -0600 Subject: [PATCH 1/4] Update to latest gfx-memory --- Cargo.lock | 6 +++--- Cargo.toml | 3 +-- src/device.rs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 274c1554e..7d1b715a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -291,7 +291,7 @@ dependencies = [ [[package]] name = "gfx-memory" version = "0.1.0" -source = "git+https://github.com/kvark/gfx-mem?branch=update#a82aa4221250a493c2fe6fcc22a2b6876742cef2" +source = "git+https://github.com/gfx-rs/gfx-memory?rev=483d64d#483d64dba6d3e2acfcd8f77a2baade78f120d49f" dependencies = [ "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=a435a05)", @@ -307,7 +307,7 @@ dependencies = [ "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?rev=a435a05)", "gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)", - "gfx-memory 0.1.0 (git+https://github.com/kvark/gfx-mem?branch=update)", + "gfx-memory 0.1.0 (git+https://github.com/gfx-rs/gfx-memory?rev=483d64d)", ] [[package]] @@ -844,7 +844,7 @@ dependencies = [ "checksum gfx-backend-metal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)" = "" "checksum gfx-backend-vulkan 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)" = "" "checksum gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)" = "" -"checksum gfx-memory 0.1.0 (git+https://github.com/kvark/gfx-mem?branch=update)" = "" +"checksum gfx-memory 0.1.0 (git+https://github.com/gfx-rs/gfx-memory?rev=483d64d)" = "" "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 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" diff --git a/Cargo.toml b/Cargo.toml index 663ffd9a9..b3079b9c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,5 +12,4 @@ gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "a435a05" } gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "a435a05", 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", rev = "a435a05", optional = true } -#gfx-memory = { git = "https://github.com/gfx-rs/gfx-memory" } -gfx-memory = { git = "https://github.com/kvark/gfx-mem", branch = "update" } +gfx-memory = { git = "https://github.com/gfx-rs/gfx-memory", rev = "483d64d" } diff --git a/src/device.rs b/src/device.rs index 63763bcb2..5a6eb9878 100644 --- a/src/device.rs +++ b/src/device.rs @@ -31,7 +31,7 @@ impl Device { } pub struct Buffer { - pub raw: B::Buffer, + pub raw: B::UnboundBuffer, } pub extern "C" From ed01eb04ad75c61600aca4ef4a66d46fa16e25f8 Mon Sep 17 00:00:00 2001 From: grovesNL Date: Sat, 15 Sep 2018 11:07:19 -0600 Subject: [PATCH 2/4] Fix return value --- src/instance.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/instance.rs b/src/instance.rs index e1dfb0e91..316ee1e4f 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -32,7 +32,10 @@ fn create_instance() -> InstanceHandle { let inst = ::back::Instance::create("wgpu", 1); InstanceHandle::new(inst) } - unimplemented!() + #[cfg(not(any(feature = "gfx-backend-vulkan", feature = "gfx-backend-dx12", feature = "gfx-backend-metal")))] + { + unimplemented!() + } } pub extern "C" From 569c5fbeb747b49dc39135fb9f437d2149513d39 Mon Sep 17 00:00:00 2001 From: grovesNL Date: Sat, 15 Sep 2018 11:43:22 -0600 Subject: [PATCH 3/4] Create general queue group --- src/device.rs | 16 +++++++++++----- src/instance.rs | 7 +++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/device.rs b/src/device.rs index 5a6eb9878..36041ed6f 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1,4 +1,4 @@ -use hal::{self, Device as _Device}; +use hal::{self, Device as _Device, QueueGroup}; use memory; use {BufferHandle, CommandBufferHandle, DeviceHandle}; @@ -17,14 +17,20 @@ pub struct CommandBufferDescriptor { } pub struct Device { - gpu: hal::Gpu, + device: B::Device, + queue_group: QueueGroup, allocator: memory::SmartAllocator, } impl Device { - pub(crate) fn new(gpu: hal::Gpu, mem_props: hal::MemoryProperties) -> Self { + pub(crate) fn new( + device: B::Device, + queue_group: QueueGroup, + mem_props: hal::MemoryProperties, + ) -> Self { Device { - gpu, + device, + queue_group, allocator: memory::SmartAllocator::new(mem_props, 1, 1, 1, 1), } } @@ -38,7 +44,7 @@ pub extern "C" fn device_create_buffer( device: DeviceHandle, desc: BufferDescriptor ) -> BufferHandle { - let buffer = device.gpu.device.create_buffer(desc.size, desc.usage).unwrap(); + let buffer = device.device.create_buffer(desc.size, desc.usage).unwrap(); BufferHandle::new(Buffer { raw: buffer, }) diff --git a/src/instance.rs b/src/instance.rs index 316ee1e4f..de11a2bab 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -61,10 +61,9 @@ fn instance_get_adapter( pub extern "C" fn adapter_create_device( - adapter: AdapterHandle, desc: DeviceDescriptor + mut adapter: AdapterHandle, desc: DeviceDescriptor ) -> DeviceHandle { - let queue_family = &adapter.queue_families[0]; - let gpu = adapter.physical_device.open(&[(queue_family, &[1f32])]).unwrap(); + let (device, queue_group) = adapter.open_with::<_, hal::General>(1, |_qf| true).unwrap(); let mem_props = adapter.physical_device.memory_properties(); - DeviceHandle::new(Device::new(gpu, mem_props)) + DeviceHandle::new(Device::new(device, queue_group, mem_props)) } From 76af247a510edfbd1a452a1eec9f3b138195845b Mon Sep 17 00:00:00 2001 From: grovesNL Date: Sun, 16 Sep 2018 00:40:42 -0600 Subject: [PATCH 4/4] Create shader modules --- examples/data/hello_triangle.frag | 7 +++++++ examples/data/hello_triangle.frag.spv | Bin 0 -> 352 bytes examples/data/hello_triangle.vert | 15 +++++++++++++++ examples/data/hello_triangle.vert.spv | Bin 0 -> 904 bytes examples/{init.rs => hello_triangle.rs} | 6 ++++++ src/device.rs | 21 ++++++++++++++++++++- src/lib.rs | 1 + 7 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 examples/data/hello_triangle.frag create mode 100644 examples/data/hello_triangle.frag.spv create mode 100644 examples/data/hello_triangle.vert create mode 100644 examples/data/hello_triangle.vert.spv rename examples/{init.rs => hello_triangle.rs} (56%) diff --git a/examples/data/hello_triangle.frag b/examples/data/hello_triangle.frag new file mode 100644 index 000000000..74e14f410 --- /dev/null +++ b/examples/data/hello_triangle.frag @@ -0,0 +1,7 @@ +#version 450 + +layout(location = 0) out vec4 outColor; + +void main() { + outColor = vec4(1.0, 0.0, 0.0, 1.0); +} diff --git a/examples/data/hello_triangle.frag.spv b/examples/data/hello_triangle.frag.spv new file mode 100644 index 0000000000000000000000000000000000000000..59e491519bc95272ee281f0c70f2f758e7f55974 GIT binary patch literal 352 zcmYk2yJ`Yq6og0D^=?!I?PSGL5epLnf)*Awc6ow;ji4?hYwxr9R5pU&{3>{0_MDl2 z&V`Ng!;+L!No6(kh_>=5QccB>*PEZsrPesC^-YKl-R>WRNeXqBx`>v59)9mJ_w0mknd~dA z&!5~gt&QOJR)KV0zIZKgX-t><>cAfBhU+ix^)24x@VqNZOkTje!+kgY+&8!b;(Zb8 literal 0 HcmV?d00001 diff --git a/examples/data/hello_triangle.vert b/examples/data/hello_triangle.vert new file mode 100644 index 000000000..ac6dcc7c3 --- /dev/null +++ b/examples/data/hello_triangle.vert @@ -0,0 +1,15 @@ +#version 450 + +out gl_PerVertex { + vec4 gl_Position; +}; + +const vec2 positions[3] = vec2[3]( + vec2(0.0, -0.5), + vec2(0.5, 0.5), + vec2(-0.5, 0.5) +); + +void main() { + gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); +} diff --git a/examples/data/hello_triangle.vert.spv b/examples/data/hello_triangle.vert.spv new file mode 100644 index 0000000000000000000000000000000000000000..9a3f5994b71471f4f282bdb2299e70ce2ebd9d62 GIT binary patch literal 904 zcmYk4OD}^_5QdLdTa;4wyN_alhy@}M8mp365Q(i++DH@Hgf1-oGl^eiBk?@nMV#i% z%)Il?oH^4kpR1KZ7zm{>6t+Whsv!pxLOB#;+qk~F-hb=2_79H^R8&Gf7OEMi(lZEN znw_rx2v`7lemU$H!UBr_ngYFt$UQwj+_Ycs+pqohJ0Wbs>znJnb^4uNm->9%SKeCt zlTQk-x-F{<{FdQ6hRw(4HvT1?_jt;Q2@QJ5Ia`CN>}75TOu@>p$I~a8S^Oeg1m@8D zVq@R4n)Z^5V1}`7$Nr~j>^|gXh`lEQtR(EF@hHB>-eXvMJA?WPHUb{?#^b<#%fu5{ zYvjyZTLqpho=n2eJ$9jX3aF9KG}HK;dZw8nkP{gUl{9v?Y@P@|gpa!UO+4Rg%`tCqH}2je{|!^XdY8TZ2GpJrJHsOI z{&UpkocV$Z?_C9QYScT!8j!z5<386@4)e!tq?~WM;WqE90k!7bZv?!@`L}@If&aC0 L7_0wbD<|L=@_;WL literal 0 HcmV?d00001 diff --git a/examples/init.rs b/examples/hello_triangle.rs similarity index 56% rename from examples/init.rs rename to examples/hello_triangle.rs index 1e03e88ed..5b4450ae3 100644 --- a/examples/init.rs +++ b/examples/hello_triangle.rs @@ -10,4 +10,10 @@ fn main() { anisotropic_filtering: false, }, }); + let _vs = gn::device_create_shader_module(device, gn::ShaderModuleDescriptor { + code: include_bytes!("./data/hello_triangle.vert.spv"), + }); + let _fs = gn::device_create_shader_module(device, gn::ShaderModuleDescriptor { + code: include_bytes!("./data/hello_triangle.frag.spv"), + }); } diff --git a/src/device.rs b/src/device.rs index 36041ed6f..e9d200a37 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1,7 +1,7 @@ use hal::{self, Device as _Device, QueueGroup}; use memory; -use {BufferHandle, CommandBufferHandle, DeviceHandle}; +use {BufferHandle, CommandBufferHandle, DeviceHandle, ShaderModuleHandle}; pub type BufferUsage = hal::buffer::Usage; @@ -12,6 +12,11 @@ pub struct BufferDescriptor { pub usage: BufferUsage, } +#[repr(C)] +pub struct ShaderModuleDescriptor<'a> { + pub code: &'a [u8], +} + #[repr(C)] pub struct CommandBufferDescriptor { } @@ -50,6 +55,20 @@ fn device_create_buffer( }) } +pub struct ShaderModule { + pub raw: B::ShaderModule, +} + +pub extern "C" +fn device_create_shader_module( + device: DeviceHandle, desc: ShaderModuleDescriptor +) -> ShaderModuleHandle { + let shader = device.device.create_shader_module(desc.code).unwrap(); + ShaderModuleHandle::new(ShaderModule { + raw: shader, + }) +} + pub extern "C" fn device_create_command_buffer( device: DeviceHandle, desc: CommandBufferDescriptor diff --git a/src/lib.rs b/src/lib.rs index e55095cd6..961c649aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,7 @@ pub type InstanceHandle = Handle; pub type AdapterHandle = Handle>; pub type DeviceHandle = Handle>; pub type BufferHandle = Handle>; +pub type ShaderModuleHandle = Handle>; pub type CommandBufferHandle = Handle>; pub type RenderPassHandle = Handle>; pub type ComputePassHandle = Handle>;