Merge pull request #3 from grovesNL/fix-build

Fix build, general queue group, shaders
This commit is contained in:
Dzmitry Malyshau 2018-09-16 14:08:34 -04:00 committed by GitHub
commit affe65d2cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 72 additions and 17 deletions

6
Cargo.lock generated
View File

@ -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)" = "<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?rev=a435a05)" = "<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?rev=483d64d)" = "<none>"
"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"

View File

@ -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" }

View File

@ -0,0 +1,7 @@
#version 450
layout(location = 0) out vec4 outColor;
void main() {
outColor = vec4(1.0, 0.0, 0.0, 1.0);
}

Binary file not shown.

View File

@ -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);
}

Binary file not shown.

View File

@ -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"),
});
}

View File

@ -1,7 +1,7 @@
use hal::{self, Device as _Device};
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,38 +12,63 @@ pub struct BufferDescriptor {
pub usage: BufferUsage,
}
#[repr(C)]
pub struct ShaderModuleDescriptor<'a> {
pub code: &'a [u8],
}
#[repr(C)]
pub struct CommandBufferDescriptor {
}
pub struct Device<B: hal::Backend> {
gpu: hal::Gpu<B>,
device: B::Device,
queue_group: QueueGroup<B, hal::General>,
allocator: memory::SmartAllocator<B>,
}
impl<B: hal::Backend> Device<B> {
pub(crate) fn new(gpu: hal::Gpu<B>, mem_props: hal::MemoryProperties) -> Self {
pub(crate) fn new(
device: B::Device,
queue_group: QueueGroup<B, hal::General>,
mem_props: hal::MemoryProperties,
) -> Self {
Device {
gpu,
device,
queue_group,
allocator: memory::SmartAllocator::new(mem_props, 1, 1, 1, 1),
}
}
}
pub struct Buffer<B: hal::Backend> {
pub raw: B::Buffer,
pub raw: B::UnboundBuffer,
}
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,
})
}
pub struct ShaderModule<B: hal::Backend> {
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

View File

@ -32,8 +32,11 @@ fn create_instance() -> InstanceHandle {
let inst = ::back::Instance::create("wgpu", 1);
InstanceHandle::new(inst)
}
#[cfg(not(any(feature = "gfx-backend-vulkan", feature = "gfx-backend-dx12", feature = "gfx-backend-metal")))]
{
unimplemented!()
}
}
pub extern "C"
fn instance_get_adapter(
@ -58,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))
}

View File

@ -26,6 +26,7 @@ pub type InstanceHandle = Handle<back::Instance>;
pub type AdapterHandle = Handle<hal::Adapter<B>>;
pub type DeviceHandle = Handle<Device<B>>;
pub type BufferHandle = Handle<Buffer<B>>;
pub type ShaderModuleHandle = Handle<ShaderModule<B>>;
pub type CommandBufferHandle = Handle<CommandBuffer<B>>;
pub type RenderPassHandle = Handle<RenderPass<B>>;
pub type ComputePassHandle = Handle<ComputePass<B>>;