Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use rustfmt for formatting after edits
  • Loading branch information
porky11 committed Jan 12, 2019
1 parent 6675a4d commit a5a5b88
Show file tree
Hide file tree
Showing 17 changed files with 466 additions and 447 deletions.
37 changes: 15 additions & 22 deletions examples/hello_triangle_rust/main.rs
Expand Up @@ -28,15 +28,15 @@ fn main() {
let fs_bytes = include_bytes!("./../data/hello_triangle.frag.spv");
let fs_module = device.create_shader_module(fs_bytes);

let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
bindings: &[],
});
let bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { bindings: &[] });
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&bind_group_layout],
});

let blend_state0 = device.create_blend_state(&wgpu::BlendStateDescriptor::REPLACE);
let depth_stencil_state = device.create_depth_stencil_state(&wgpu::DepthStencilStateDescriptor::IGNORE);
let depth_stencil_state =
device.create_depth_stencil_state(&wgpu::DepthStencilStateDescriptor::IGNORE);

let _render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
layout: &pipeline_layout,
Expand All @@ -54,38 +54,31 @@ fn main() {
],
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
attachments_state: wgpu::AttachmentsState {
color_attachments: &[
wgpu::Attachment {
format: wgpu::TextureFormat::R8g8b8a8Unorm,
samples: 1,
},
],
color_attachments: &[wgpu::Attachment {
format: wgpu::TextureFormat::R8g8b8a8Unorm,
samples: 1,
}],
depth_stencil_attachment: None,
},
blend_states: &[
&blend_state0,
],
blend_states: &[&blend_state0],
depth_stencil_state: &depth_stencil_state,
});

let mut cmd_buf = device.create_command_buffer(&wgpu::CommandBufferDescriptor {});

{
let rpass = cmd_buf.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor {
attachment: &color_view,
load_op: wgpu::LoadOp::Clear,
store_op: wgpu::StoreOp::Store,
clear_color: wgpu::Color::GREEN,
},
],
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &color_view,
load_op: wgpu::LoadOp::Clear,
store_op: wgpu::StoreOp::Store,
clear_color: wgpu::Color::GREEN,
}],
depth_stencil_attachment: None,
});
rpass.end_pass();
}


let queue = device.get_queue();
queue.submit(&[cmd_buf]);
}
1 change: 0 additions & 1 deletion wgpu-native/src/binding_model.rs
Expand Up @@ -2,7 +2,6 @@ use hal;

use {BindGroupLayoutId, BufferId, SamplerId, TextureViewId};


bitflags! {
#[repr(transparent)]
pub struct ShaderStageFlags: u32 {
Expand Down
25 changes: 15 additions & 10 deletions wgpu-native/src/command/allocator.rs
@@ -1,6 +1,6 @@
use super::CommandBuffer;
use track::Tracker;
use {DeviceId, LifeGuard, Stored};
use track::{Tracker};

use hal::command::RawCommandBuffer;
use hal::pool::RawCommandPool;
Expand Down Expand Up @@ -37,7 +37,9 @@ impl<B: hal::Backend> Inner<B> {
fn recycle(&mut self, cmd_buf: CommandBuffer<B>) {
let pool = self.pools.get_mut(&cmd_buf.recorded_thread_id).unwrap();
for mut raw in cmd_buf.raw {
unsafe { raw.reset(false); }
unsafe {
raw.reset(false);
}
pool.available.push(raw);
}
self.fences.push(cmd_buf.fence);
Expand All @@ -62,7 +64,9 @@ impl<B: hal::Backend> CommandAllocator<B> {
}

pub(crate) fn allocate(
&self, device_id: Stored<DeviceId>, device: &B::Device
&self,
device_id: Stored<DeviceId>,
device: &B::Device,
) -> CommandBuffer<B> {
let thread_id = thread::current().id();
let mut inner = self.inner.lock().unwrap();
Expand All @@ -72,16 +76,17 @@ impl<B: hal::Backend> CommandAllocator<B> {
unsafe { device.reset_fence(&fence).unwrap() };
fence
}
None => {
device.create_fence(false).unwrap()
}
None => device.create_fence(false).unwrap(),
};

let pool = inner.pools.entry(thread_id).or_insert_with(|| CommandPool {
raw: unsafe { device.create_command_pool(
self.queue_family,
hal::pool::CommandPoolCreateFlags::RESET_INDIVIDUAL,
)}.unwrap(),
raw: unsafe {
device.create_command_pool(
self.queue_family,
hal::pool::CommandPoolCreateFlags::RESET_INDIVIDUAL,
)
}
.unwrap(),
available: Vec::new(),
});
let init = pool.allocate();
Expand Down
34 changes: 12 additions & 22 deletions wgpu-native/src/command/compute.rs
@@ -1,36 +1,25 @@
use registry::{HUB, Items};
use {
Stored,
BindGroupId, CommandBufferId, ComputePassId, ComputePipelineId,
};
use registry::{Items, HUB};
use {BindGroupId, CommandBufferId, ComputePassId, ComputePipelineId, Stored};

use hal;
use hal::command::RawCommandBuffer;

use std::iter;


pub struct ComputePass<B: hal::Backend> {
raw: B::CommandBuffer,
cmb_id: Stored<CommandBufferId>,
}

impl<B: hal::Backend> ComputePass<B> {
pub(crate) fn new(raw: B::CommandBuffer, cmb_id: Stored<CommandBufferId>) -> Self {
ComputePass {
raw,
cmb_id,
}
ComputePass { raw, cmb_id }
}
}

#[no_mangle]
pub extern "C" fn wgpu_compute_pass_end_pass(
pass_id: ComputePassId,
) -> CommandBufferId {
let pass = HUB.compute_passes
.write()
.take(pass_id);
pub extern "C" fn wgpu_compute_pass_end_pass(pass_id: ComputePassId) -> CommandBufferId {
let pass = HUB.compute_passes.write().take(pass_id);

HUB.command_buffers
.write()
Expand All @@ -42,7 +31,9 @@ pub extern "C" fn wgpu_compute_pass_end_pass(

#[no_mangle]
pub extern "C" fn wgpu_compute_pass_set_bind_group(
pass_id: ComputePassId, index: u32, bind_group_id: BindGroupId,
pass_id: ComputePassId,
index: u32,
bind_group_id: BindGroupId,
) {
let bind_group_guard = HUB.bind_groups.read();
let set = &bind_group_guard.get(bind_group_id).raw;
Expand All @@ -60,11 +51,12 @@ pub extern "C" fn wgpu_compute_pass_set_bind_group(

#[no_mangle]
pub extern "C" fn wgpu_compute_pass_set_pipeline(
pass_id: ComputePassId, pipeline_id: ComputePipelineId,
pass_id: ComputePassId,
pipeline_id: ComputePipelineId,
) {
let pipeline_guard = HUB.compute_pipelines.read();
let pipeline = &pipeline_guard.get(pipeline_id).raw;

unsafe {
HUB.compute_passes
.write()
Expand All @@ -75,9 +67,7 @@ pub extern "C" fn wgpu_compute_pass_set_pipeline(
}

#[no_mangle]
pub extern "C" fn wgpu_compute_pass_dispatch(
pass_id: ComputePassId, x: u32, y: u32, z: u32,
) {
pub extern "C" fn wgpu_compute_pass_dispatch(pass_id: ComputePassId, x: u32, y: u32, z: u32) {
unsafe {
HUB.compute_passes
.write()
Expand Down

0 comments on commit a5a5b88

Please sign in to comment.