Skip to content

Commit 5ae0623

Browse files
committed
Switch the compute example to use the raw pass
1 parent 0db2719 commit 5ae0623

6 files changed

Lines changed: 117 additions & 186 deletions

File tree

examples/compute/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ int main(
127127
.todo = 0
128128
});
129129

130-
WGPUComputePassId command_pass =
130+
WGPURawComputePassId command_pass = //temp name
131131
wgpu_command_encoder_begin_compute_pass(encoder, NULL);
132132
wgpu_compute_pass_set_pipeline(command_pass, compute_pipeline);
133133

ffi/wgpu.h

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -284,20 +284,12 @@ typedef uint64_t WGPUId_CommandBuffer_Dummy;
284284

285285
typedef WGPUId_CommandBuffer_Dummy WGPUCommandBufferId;
286286

287-
typedef uint64_t WGPUId_ComputePass_Dummy;
288-
289-
typedef WGPUId_ComputePass_Dummy WGPUComputePassId;
290-
291-
typedef WGPUCommandBufferId WGPUCommandEncoderId;
292-
293-
typedef struct {
294-
uint32_t todo;
295-
} WGPUComputePassDescriptor;
296-
297287
typedef uint64_t WGPUId_RenderPass_Dummy;
298288

299289
typedef WGPUId_RenderPass_Dummy WGPURenderPassId;
300290

291+
typedef WGPUCommandBufferId WGPUCommandEncoderId;
292+
301293
typedef uint64_t WGPUId_TextureView_Dummy;
302294

303295
typedef WGPUId_TextureView_Dummy WGPUTextureViewId;
@@ -378,11 +370,7 @@ typedef struct {
378370
uint32_t todo;
379371
} WGPUCommandBufferDescriptor;
380372

381-
typedef const char *WGPURawString;
382-
383-
typedef uint64_t WGPUId_ComputePipeline_Dummy;
384-
385-
typedef WGPUId_ComputePipeline_Dummy WGPUComputePipelineId;
373+
typedef WGPURawPass *WGPURawComputePassId;
386374

387375
typedef uint64_t WGPUId_Surface;
388376

@@ -482,6 +470,10 @@ typedef struct {
482470
uint32_t todo;
483471
} WGPUCommandEncoderDescriptor;
484472

473+
typedef uint64_t WGPUId_ComputePipeline_Dummy;
474+
475+
typedef WGPUId_ComputePipeline_Dummy WGPUComputePipelineId;
476+
485477
typedef uint64_t WGPUId_PipelineLayout_Dummy;
486478

487479
typedef WGPUId_PipelineLayout_Dummy WGPUPipelineLayoutId;
@@ -490,6 +482,8 @@ typedef uint64_t WGPUId_ShaderModule_Dummy;
490482

491483
typedef WGPUId_ShaderModule_Dummy WGPUShaderModuleId;
492484

485+
typedef const char *WGPURawString;
486+
493487
typedef struct {
494488
WGPUShaderModuleId module;
495489
WGPURawString entry_point;
@@ -694,14 +688,9 @@ void wgpu_buffer_unmap(WGPUBufferId buffer_id);
694688

695689
void wgpu_command_buffer_destroy(WGPUCommandBufferId command_buffer_id);
696690

697-
WGPUComputePassId wgpu_command_encoder_begin_compute_pass(WGPUCommandEncoderId encoder_id,
698-
const WGPUComputePassDescriptor *desc);
699-
700691
WGPURenderPassId wgpu_command_encoder_begin_render_pass(WGPUCommandEncoderId encoder_id,
701692
const WGPURenderPassDescriptor *desc);
702693

703-
void wgpu_command_encoder_compute_pass(WGPUCommandEncoderId self_id, const WGPURawPass *pass);
704-
705694
void wgpu_command_encoder_copy_buffer_to_buffer(WGPUCommandEncoderId command_encoder_id,
706695
WGPUBufferId source,
707696
WGPUBufferAddress source_offset,
@@ -729,33 +718,7 @@ void wgpu_command_encoder_destroy(WGPUCommandEncoderId command_encoder_id);
729718
WGPUCommandBufferId wgpu_command_encoder_finish(WGPUCommandEncoderId encoder_id,
730719
const WGPUCommandBufferDescriptor *desc);
731720

732-
void wgpu_command_encoder_render_pass(WGPUCommandEncoderId self_id,
733-
const WGPURenderPassColorAttachmentDescriptor *color_attachments,
734-
uintptr_t color_attachment_length,
735-
const WGPURenderPassDepthStencilAttachmentDescriptor *depth_stencil_attachment,
736-
const WGPURawPass *pass);
737-
738-
void wgpu_compute_pass_dispatch(WGPUComputePassId pass_id, uint32_t x, uint32_t y, uint32_t z);
739-
740-
void wgpu_compute_pass_dispatch_indirect(WGPUComputePassId pass_id,
741-
WGPUBufferId indirect_buffer_id,
742-
WGPUBufferAddress indirect_offset);
743-
744-
void wgpu_compute_pass_end_pass(WGPUComputePassId pass_id);
745-
746-
void wgpu_compute_pass_insert_debug_marker(WGPUComputePassId _pass_id, WGPURawString _label);
747-
748-
void wgpu_compute_pass_pop_debug_group(WGPUComputePassId _pass_id);
749-
750-
void wgpu_compute_pass_push_debug_group(WGPUComputePassId _pass_id, WGPURawString _label);
751-
752-
void wgpu_compute_pass_set_bind_group(WGPUComputePassId pass_id,
753-
uint32_t index,
754-
WGPUBindGroupId bind_group_id,
755-
const WGPUBufferAddress *offsets,
756-
uintptr_t offsets_length);
757-
758-
void wgpu_compute_pass_set_pipeline(WGPUComputePassId pass_id, WGPUComputePipelineId pipeline_id);
721+
void wgpu_compute_pass_end_pass(WGPURawComputePassId pass_id);
759722

760723
WGPUSurfaceId wgpu_create_surface_from_metal_layer(void *layer);
761724

wgpu-core/src/command/compute.rs

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::{
77
bind::{Binder, LayoutChange},
88
CommandBuffer,
99
PhantomSlice,
10-
RawPass,
1110
},
1211
device::{all_buffer_stages, BIND_BUFFER_ALIGNMENT},
1312
hub::{GfxBackend, Global, IdentityFilter, Token},
@@ -21,7 +20,7 @@ use crate::{
2120
use hal::command::CommandBuffer as _;
2221
use peek_poke::{Peek, PeekCopy, Poke};
2322

24-
use std::{convert::TryInto, iter, mem, slice};
23+
use std::{iter, mem};
2524

2625

2726
#[derive(Clone, Copy, Debug, PeekCopy, Poke)]
@@ -422,16 +421,27 @@ impl<F> Global<F> {
422421
}
423422
}
424423

425-
impl RawPass {
424+
pub mod compute_ffi {
425+
use super::{
426+
ComputeCommand,
427+
super::{PhantomSlice, RawPass},
428+
};
429+
use crate::{
430+
id,
431+
BufferAddress,
432+
RawString,
433+
};
434+
use std::{convert::TryInto, slice};
435+
426436
#[no_mangle]
427-
pub unsafe extern "C" fn wgpu_raw_compute_pass_set_bind_group(
428-
&mut self,
437+
pub unsafe extern "C" fn wgpu_compute_pass_set_bind_group(
438+
pass: &mut RawPass,
429439
index: u32,
430440
bind_group_id: id::BindGroupId,
431441
offsets: *const BufferAddress,
432442
offset_length: usize,
433443
) {
434-
self.encode_with1(
444+
pass.encode_with1(
435445
&ComputeCommand::SetBindGroup {
436446
index,
437447
num_dynamic_offsets: offset_length.try_into().unwrap(),
@@ -443,32 +453,55 @@ impl RawPass {
443453
}
444454

445455
#[no_mangle]
446-
pub unsafe extern "C" fn wgpu_raw_compute_pass_set_pipeline(
447-
&mut self,
456+
pub unsafe extern "C" fn wgpu_compute_pass_set_pipeline(
457+
pass: &mut RawPass,
448458
pipeline_id: id::ComputePipelineId,
449459
) {
450-
self.encode(&ComputeCommand::SetPipeline(pipeline_id));
460+
pass.encode(&ComputeCommand::SetPipeline(pipeline_id));
451461
}
452462

453463
#[no_mangle]
454-
pub unsafe extern "C" fn wgpu_raw_compute_pass_dispatch(
455-
&mut self,
464+
pub unsafe extern "C" fn wgpu_compute_pass_dispatch(
465+
pass: &mut RawPass,
456466
groups_x: u32,
457467
groups_y: u32,
458468
groups_z: u32,
459469
) {
460-
self.encode(&ComputeCommand::Dispatch([groups_x, groups_y, groups_z]));
470+
pass.encode(&ComputeCommand::Dispatch([groups_x, groups_y, groups_z]));
461471
}
462472

463473
#[no_mangle]
464-
pub unsafe extern "C" fn wgpu_raw_compute_pass_dispatch_indirect(
465-
&mut self,
474+
pub unsafe extern "C" fn wgpu_compute_pass_dispatch_indirect(
475+
pass: &mut RawPass,
466476
buffer_id: id::BufferId,
467477
offset: BufferAddress,
468478
) {
469-
self.encode(&ComputeCommand::DispatchIndirect {
479+
pass.encode(&ComputeCommand::DispatchIndirect {
470480
buffer_id,
471481
offset,
472482
});
473483
}
484+
485+
#[no_mangle]
486+
pub extern "C" fn wgpu_compute_pass_push_debug_group(
487+
_pass: &mut RawPass,
488+
_label: RawString,
489+
) {
490+
//TODO
491+
}
492+
493+
#[no_mangle]
494+
pub extern "C" fn wgpu_compute_pass_pop_debug_group(
495+
_pass: &mut RawPass,
496+
) {
497+
//TODO
498+
}
499+
500+
#[no_mangle]
501+
pub extern "C" fn wgpu_compute_pass_insert_debug_marker(
502+
_pass: &mut RawPass,
503+
_label: RawString,
504+
) {
505+
//TODO
506+
}
474507
}

0 commit comments

Comments
 (0)