Refactor after rebase

This commit is contained in:
Joshua Groves 2018-09-28 00:31:09 -06:00
parent e3d7fda9c7
commit c8a60c780c
3 changed files with 31 additions and 24 deletions

View File

@ -128,9 +128,6 @@ typedef WGPUId WGPUCommandBufferId;
typedef WGPUId WGPUInstanceId;
typedef struct {
} WGPUCommandBufferDescriptor;
typedef WGPUId WGPUAttachmentStateId;
typedef struct {
@ -170,6 +167,10 @@ typedef struct {
WGPUColorWriteFlags write_mask;
} WGPUBlendStateDescriptor;
typedef struct {
} WGPUCommandBufferDescriptor;
typedef WGPUId WGPUDepthStencilStateId;
typedef struct {
@ -239,8 +240,6 @@ WGPURenderPassId wgpu_command_buffer_begin_render_pass(WGPUCommandBufferId _comm
WGPUInstanceId wgpu_create_instance(void);
WGPUCommandBufferId wgpu_device_create_command_buffer(WGPUDeviceId device_id,
WGPUCommandBufferDescriptor desc);
WGPUAttachmentStateId wgpu_device_create_attachment_state(WGPUDeviceId device_id,
WGPUAttachmentStateDescriptor desc);
@ -250,6 +249,9 @@ WGPUBindGroupLayoutId wgpu_device_create_bind_group_layout(WGPUDeviceId device_i
WGPUBlendStateId wgpu_device_create_blend_state(WGPUDeviceId _device_id,
WGPUBlendStateDescriptor desc);
WGPUCommandBufferId wgpu_device_create_command_buffer(WGPUDeviceId device_id,
WGPUCommandBufferDescriptor _desc);
WGPUDepthStencilStateId wgpu_device_create_depth_stencil_state(WGPUDeviceId device_id,
WGPUDepthStencilStateDescriptor desc);

View File

@ -1,11 +1,11 @@
use hal::{self, Device as _Device};
use hal::queue::RawCommandQueue;
use {binding_model, command, conv, memory, pipeline, resource};
use {back, binding_model, command, conv, memory, pipeline};
use std::{iter, slice};
use std::{ffi, iter, slice};
use registry::{self, Items, Registry};
use {
AttachmentStateId, BindGroupLayoutId, BlendStateId, BufferId, CommandBufferId, DepthStencilStateId, DeviceId,
AttachmentStateId, BindGroupLayoutId, BlendStateId, CommandBufferId, DepthStencilStateId, DeviceId,
PipelineLayoutId, QueueId, RenderPipelineId, ShaderModuleId,
};
@ -119,7 +119,8 @@ pub extern "C" fn wgpu_device_create_command_buffer(
device_id: DeviceId,
_desc: command::CommandBufferDescriptor,
) -> CommandBufferId {
let device = registry::DEVICE_REGISTRY.get_mut(device_id);
let mut device_guard = registry::DEVICE_REGISTRY.lock();
let device = device_guard.get_mut(device_id);
let cmd_buf = device.com_allocator.allocate(&device.device);
registry::COMMAND_BUFFER_REGISTRY.register(cmd_buf)
}
@ -137,13 +138,15 @@ pub extern "C" fn wgpu_queue_submit(
command_buffer_ptr: *const CommandBufferId,
command_buffer_count: usize,
) {
let mut device = registry::DEVICE_REGISTRY.get_mut(queue_id);
let mut device_guard = registry::DEVICE_REGISTRY.lock();
let device = device_guard.get_mut(queue_id);
let command_buffer_ids = unsafe {
slice::from_raw_parts(command_buffer_ptr, command_buffer_count)
};
//TODO: submit at once, requires `get_all()`
let mut command_buffer_guard = registry::COMMAND_BUFFER_REGISTRY.lock();
for &cmb_id in command_buffer_ids {
let cmd_buf = registry::COMMAND_BUFFER_REGISTRY.take(cmb_id);
let cmd_buf = command_buffer_guard.take(cmb_id);
{
let submission = hal::queue::RawSubmission {
cmd_buffers: iter::once(&cmd_buf.raw),
@ -158,6 +161,9 @@ pub extern "C" fn wgpu_queue_submit(
}
device.com_allocator.submit(cmd_buf);
}
}
#[no_mangle]
pub extern "C" fn wgpu_device_create_attachment_state(
device_id: DeviceId,
desc: pipeline::AttachmentStateDescriptor,

View File

@ -37,7 +37,7 @@ pub(crate) trait Registry<T> {
pub(crate) trait Items<T> {
fn get(&self, id: Id) -> Item<T>;
fn get_mut(&mut self, id: Id) -> ItemMut<T>;
fn take(&self, id: Id) -> T;
fn take(&mut self, id: Id) -> T;
}
#[cfg(not(feature = "remote"))]
@ -54,6 +54,12 @@ impl<T> Items<T> for LocalItems<T> {
fn get_mut(&mut self, id: Id) -> ItemMut<T> {
unsafe { (id as *mut T).as_mut() }.unwrap()
}
fn take(&mut self, id: Id) -> T {
unsafe {
*Box::from_raw(id as *mut T)
}
}
}
#[cfg(not(feature = "remote"))]
@ -78,12 +84,6 @@ impl<T> Registry<T> for LocalRegistry<T> {
marker: PhantomData,
}
}
fn take(&self, id: Id) -> T {
unsafe {
*Box::from_raw(id as *mut T)
}
}
}
#[cfg(feature = "remote")]
@ -113,6 +113,11 @@ impl<T> Items<T> for RemoteItems<T> {
fn get_mut(&mut self, id: Id) -> ItemMut<T> {
self.tracked.get_mut(&id).unwrap()
}
fn take(&mut self, id: Id) -> T {
self.free.push(id);
self.tracked.remove(&id).unwrap()
}
}
#[cfg(feature = "remote")]
@ -144,12 +149,6 @@ impl<T> Registry<T> for RemoteRegistry<T> {
fn lock(&self) -> ItemsGuard<T> {
self.items.lock()
}
fn take(&self, id: Id) -> T {
let mut registrations = self.registrations.lock();
registrations.free.push(id);
registrations.tracked.remove(&id).unwrap()
}
}
#[cfg(not(feature = "remote"))]