mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 00:03:29 +00:00
native: compute pass boilerplate
This commit is contained in:
parent
69df9c4eae
commit
1fd05608fb
@ -1,7 +1,37 @@
|
||||
use hal;
|
||||
|
||||
//use {CommandBuffer, CommandBufferId, ComputePassId};
|
||||
use registry::{self, Items, Registry};
|
||||
use {
|
||||
Stored,
|
||||
CommandBufferId, ComputePassId
|
||||
};
|
||||
|
||||
|
||||
pub struct ComputePass<B: hal::Backend> {
|
||||
raw: B::CommandBuffer,
|
||||
cmb_id: Stored<CommandBufferId>,
|
||||
}
|
||||
|
||||
impl<B: hal::Backend> ComputePass<B> {
|
||||
pub fn new(raw: B::CommandBuffer, cmb_id: CommandBufferId) -> Self {
|
||||
ComputePass {
|
||||
raw,
|
||||
cmb_id: Stored(cmb_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_end_pass(
|
||||
pass_id: ComputePassId,
|
||||
) -> CommandBufferId {
|
||||
let pass = registry::COMPUTE_PASS_REGISTRY
|
||||
.lock()
|
||||
.take(pass_id);
|
||||
|
||||
registry::COMMAND_BUFFER_REGISTRY
|
||||
.lock()
|
||||
.get_mut(pass.cmb_id.0)
|
||||
.raw = Some(pass.raw);
|
||||
pass.cmb_id.0
|
||||
}
|
||||
|
@ -112,6 +112,15 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_command_buffer_begin_compute_pass() -> ComputePassId {
|
||||
unimplemented!()
|
||||
pub extern "C" fn wgpu_command_buffer_begin_compute_pass(
|
||||
command_buffer_id: CommandBufferId,
|
||||
) -> ComputePassId {
|
||||
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();
|
||||
|
||||
registry::COMPUTE_PASS_REGISTRY
|
||||
.lock()
|
||||
.register(ComputePass::new(raw, command_buffer_id))
|
||||
}
|
||||
|
@ -7,15 +7,12 @@ use {
|
||||
CommandBufferId, RenderPassId,
|
||||
};
|
||||
|
||||
|
||||
pub struct RenderPass<B: hal::Backend> {
|
||||
raw: B::CommandBuffer,
|
||||
cmb_id: Stored<CommandBufferId>,
|
||||
}
|
||||
|
||||
// This is needed for `cmb_id` - would be great to remove.
|
||||
#[cfg(not(feature = "remote"))]
|
||||
unsafe impl<B: hal::Backend> Sync for RenderPass<B> {}
|
||||
|
||||
impl<B: hal::Backend> RenderPass<B> {
|
||||
pub fn new(raw: B::CommandBuffer, cmb_id: CommandBufferId) -> Self {
|
||||
RenderPass {
|
||||
@ -27,16 +24,16 @@ impl<B: hal::Backend> RenderPass<B> {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_end_pass(
|
||||
render_pass_id: RenderPassId,
|
||||
pass_id: RenderPassId,
|
||||
) -> CommandBufferId {
|
||||
let mut rp = registry::RENDER_PASS_REGISTRY
|
||||
let mut pass = registry::RENDER_PASS_REGISTRY
|
||||
.lock()
|
||||
.take(render_pass_id);
|
||||
rp.raw.end_render_pass();
|
||||
.take(pass_id);
|
||||
pass.raw.end_render_pass();
|
||||
|
||||
registry::COMMAND_BUFFER_REGISTRY
|
||||
.lock()
|
||||
.get_mut(rp.cmb_id.0)
|
||||
.raw = Some(rp.raw);
|
||||
rp.cmb_id.0
|
||||
.get_mut(pass.cmb_id.0)
|
||||
.raw = Some(pass.raw);
|
||||
pass.cmb_id.0
|
||||
}
|
||||
|
@ -126,3 +126,4 @@ type CommandBufferHandle = CommandBuffer<B>;
|
||||
pub type RenderPassId = Id;
|
||||
type RenderPassHandle = RenderPass<B>;
|
||||
pub type ComputePassId = Id;
|
||||
type ComputePassHandle = ComputePass<B>;
|
||||
|
@ -12,7 +12,7 @@ use std::sync::Arc;
|
||||
use {
|
||||
AdapterHandle, AttachmentStateHandle, BindGroupLayoutHandle, BlendStateHandle,
|
||||
CommandBufferHandle, DepthStencilStateHandle, DeviceHandle, InstanceHandle,
|
||||
RenderPassHandle,
|
||||
RenderPassHandle, ComputePassHandle,
|
||||
PipelineLayoutHandle, RenderPipelineHandle, ShaderModuleHandle,
|
||||
};
|
||||
|
||||
@ -178,4 +178,6 @@ lazy_static! {
|
||||
ConcreteRegistry::new();
|
||||
pub(crate) static ref RENDER_PASS_REGISTRY: ConcreteRegistry<RenderPassHandle> =
|
||||
ConcreteRegistry::new();
|
||||
pub(crate) static ref COMPUTE_PASS_REGISTRY: ConcreteRegistry<ComputePassHandle> =
|
||||
ConcreteRegistry::new();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user