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