mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Keep a reference to DeviceID in the command buffer
This commit is contained in:
parent
da95fe6b1e
commit
e4341603d7
@ -1,4 +1,5 @@
|
||||
use super::CommandBuffer;
|
||||
use {DeviceId, Stored};
|
||||
|
||||
use hal::command::RawCommandBuffer;
|
||||
use hal::pool::RawCommandPool;
|
||||
@ -14,7 +15,7 @@ struct CommandPool<B: hal::Backend> {
|
||||
available: Vec<CommandBuffer<B>>,
|
||||
}
|
||||
|
||||
pub struct Inner<B: hal::Backend> {
|
||||
struct Inner<B: hal::Backend> {
|
||||
pools: HashMap<thread::ThreadId, CommandPool<B>>,
|
||||
pending: Vec<CommandBuffer<B>>,
|
||||
}
|
||||
@ -35,7 +36,9 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn allocate(&self, device: &B::Device) -> CommandBuffer<B> {
|
||||
pub fn allocate(
|
||||
&self, device_id: DeviceId, device: &B::Device
|
||||
) -> CommandBuffer<B> {
|
||||
let thread_id = thread::current().id();
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
let pool = inner.pools.entry(thread_id).or_insert_with(|| CommandPool {
|
||||
@ -47,6 +50,7 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
||||
});
|
||||
|
||||
if let Some(cmd_buf) = pool.available.pop() {
|
||||
assert_eq!(device_id, cmd_buf.device_id.0);
|
||||
device.reset_fence(&cmd_buf.fence);
|
||||
return cmd_buf;
|
||||
}
|
||||
@ -56,6 +60,7 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
||||
raw: Some(cmbuf),
|
||||
fence: device.create_fence(false),
|
||||
recorded_thread_id: thread_id,
|
||||
device_id: Stored(device_id),
|
||||
});
|
||||
}
|
||||
pool.available.pop().unwrap()
|
||||
|
@ -2,15 +2,15 @@ mod allocator;
|
||||
mod compute;
|
||||
mod render;
|
||||
|
||||
pub use self::allocator::*;
|
||||
pub use self::allocator::CommandAllocator;
|
||||
pub use self::compute::*;
|
||||
pub use self::render::*;
|
||||
|
||||
use hal;
|
||||
|
||||
use {
|
||||
BufferId, Color, CommandBufferId, ComputePassId, Origin3d, RenderPassId, TextureId,
|
||||
TextureViewId,
|
||||
Color, Origin3d, Stored,
|
||||
BufferId, CommandBufferId, ComputePassId, DeviceId, RenderPassId, TextureId, TextureViewId,
|
||||
};
|
||||
use registry::{self, Items, Registry};
|
||||
|
||||
@ -75,6 +75,7 @@ pub struct CommandBuffer<B: hal::Backend> {
|
||||
pub(crate) raw: Option<B::CommandBuffer>,
|
||||
fence: B::Fence,
|
||||
recorded_thread_id: ThreadId,
|
||||
device_id: Stored<DeviceId>,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -85,12 +86,16 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
||||
command_buffer_id: CommandBufferId,
|
||||
_descriptor: RenderPassDescriptor<TextureViewId>,
|
||||
) -> RenderPassId {
|
||||
let raw = registry::COMMAND_BUFFER_REGISTRY
|
||||
.lock()
|
||||
.get_mut(command_buffer_id)
|
||||
.raw
|
||||
.take()
|
||||
.unwrap();
|
||||
let mut cmb_guard = registry::COMMAND_BUFFER_REGISTRY.lock();
|
||||
let mut cmb = cmb_guard.get_mut(command_buffer_id);
|
||||
|
||||
let raw = cmb.raw.take().unwrap();
|
||||
|
||||
let mut device_guard = registry::DEVICE_REGISTRY.lock();
|
||||
let device = &device_guard.get(cmb.device_id.0).raw;
|
||||
|
||||
//let render_pass = device.create_render_pass();
|
||||
//let framebuffer = device.create_framebuffer();
|
||||
|
||||
/*TODO:
|
||||
raw.begin_render_pass(
|
||||
|
@ -2,11 +2,14 @@ use hal;
|
||||
use hal::command::RawCommandBuffer;
|
||||
|
||||
use registry::{self, Items, Registry};
|
||||
use {CommandBufferId, RenderPassId};
|
||||
use {
|
||||
Stored,
|
||||
CommandBufferId, RenderPassId,
|
||||
};
|
||||
|
||||
pub struct RenderPass<B: hal::Backend> {
|
||||
raw: B::CommandBuffer,
|
||||
cmb_id: CommandBufferId,
|
||||
cmb_id: Stored<CommandBufferId>,
|
||||
}
|
||||
|
||||
// This is needed for `cmb_id` - would be great to remove.
|
||||
@ -17,7 +20,7 @@ impl<B: hal::Backend> RenderPass<B> {
|
||||
pub fn new(raw: B::CommandBuffer, cmb_id: CommandBufferId) -> Self {
|
||||
RenderPass {
|
||||
raw,
|
||||
cmb_id,
|
||||
cmb_id: Stored(cmb_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -33,7 +36,7 @@ pub extern "C" fn wgpu_render_pass_end_pass(
|
||||
|
||||
registry::COMMAND_BUFFER_REGISTRY
|
||||
.lock()
|
||||
.get_mut(rp.cmb_id)
|
||||
.get_mut(rp.cmb_id.0)
|
||||
.raw = Some(rp.raw);
|
||||
rp.cmb_id
|
||||
rp.cmb_id.0
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use {
|
||||
};
|
||||
|
||||
pub struct Device<B: hal::Backend> {
|
||||
raw: B::Device,
|
||||
pub(crate) raw: B::Device,
|
||||
queue_group: hal::QueueGroup<B, hal::General>,
|
||||
mem_allocator: memory::SmartAllocator<B>,
|
||||
com_allocator: command::CommandAllocator<B>,
|
||||
@ -131,7 +131,7 @@ pub extern "C" fn wgpu_device_create_command_buffer(
|
||||
) -> CommandBufferId {
|
||||
let mut device_guard = registry::DEVICE_REGISTRY.lock();
|
||||
let device = device_guard.get_mut(device_id);
|
||||
let mut cmd_buf = device.com_allocator.allocate(&device.raw);
|
||||
let mut cmd_buf = device.com_allocator.allocate(device_id, &device.raw);
|
||||
cmd_buf.raw.as_mut().unwrap().begin(
|
||||
hal::command::CommandBufferFlags::ONE_TIME_SUBMIT,
|
||||
hal::command::CommandBufferInheritanceInfo::default(),
|
||||
|
@ -40,6 +40,13 @@ pub use self::resource::*;
|
||||
use back::Backend as B;
|
||||
use registry::Id;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
struct Stored<T>(T);
|
||||
#[cfg(not(feature = "remote"))]
|
||||
unsafe impl<T> Sync for Stored<T> {}
|
||||
#[cfg(not(feature = "remote"))]
|
||||
unsafe impl<T> Send for Stored<T> {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Color {
|
||||
|
Loading…
Reference in New Issue
Block a user