mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Switch the examples to use the new raw passes
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -673,6 +673,7 @@ dependencies = [
|
||||
name = "wgpu-native"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
||||
@@ -127,7 +127,7 @@ int main(
|
||||
.todo = 0
|
||||
});
|
||||
|
||||
WGPUComputePassId command_pass =
|
||||
WGPURawComputePassId command_pass = //temp name
|
||||
wgpu_command_encoder_begin_compute_pass(encoder, NULL);
|
||||
wgpu_compute_pass_set_pipeline(command_pass, compute_pipeline);
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ int main() {
|
||||
},
|
||||
};
|
||||
|
||||
WGPURenderPassId rpass =
|
||||
WGPURawRenderPassId rpass =
|
||||
wgpu_command_encoder_begin_render_pass(cmd_encoder,
|
||||
&(WGPURenderPassDescriptor){
|
||||
.color_attachments = color_attachments,
|
||||
|
||||
207
ffi/wgpu.h
207
ffi/wgpu.h
@@ -19,6 +19,18 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define WGPUDEFAULT_BIND_GROUPS 4
|
||||
|
||||
#define WGPUDESIRED_NUM_FRAMES 3
|
||||
|
||||
#define WGPUMAX_BIND_GROUPS 4
|
||||
|
||||
#define WGPUMAX_COLOR_TARGETS 4
|
||||
|
||||
#define WGPUMAX_MIP_LEVELS 16
|
||||
|
||||
#define WGPUMAX_VERTEX_BUFFERS 8
|
||||
|
||||
typedef enum {
|
||||
WGPUAddressMode_ClampToEdge = 0,
|
||||
WGPUAddressMode_Repeat = 1,
|
||||
@@ -243,8 +255,6 @@ typedef enum {
|
||||
WGPUVertexFormat_Int4 = 48,
|
||||
} WGPUVertexFormat;
|
||||
|
||||
typedef struct WGPURawPass WGPURawPass;
|
||||
|
||||
typedef uint64_t WGPUId_Device_Dummy;
|
||||
|
||||
typedef WGPUId_Device_Dummy WGPUDeviceId;
|
||||
@@ -284,20 +294,21 @@ typedef uint64_t WGPUId_CommandBuffer_Dummy;
|
||||
|
||||
typedef WGPUId_CommandBuffer_Dummy WGPUCommandBufferId;
|
||||
|
||||
typedef uint64_t WGPUId_ComputePass_Dummy;
|
||||
|
||||
typedef WGPUId_ComputePass_Dummy WGPUComputePassId;
|
||||
|
||||
typedef WGPUCommandBufferId WGPUCommandEncoderId;
|
||||
|
||||
typedef struct {
|
||||
uint8_t *data;
|
||||
uint8_t *base;
|
||||
uintptr_t capacity;
|
||||
WGPUCommandEncoderId parent;
|
||||
} WGPURawPass;
|
||||
|
||||
typedef WGPURawPass *WGPURawComputePassId;
|
||||
|
||||
typedef struct {
|
||||
uint32_t todo;
|
||||
} WGPUComputePassDescriptor;
|
||||
|
||||
typedef uint64_t WGPUId_RenderPass_Dummy;
|
||||
|
||||
typedef WGPUId_RenderPass_Dummy WGPURenderPassId;
|
||||
|
||||
typedef uint64_t WGPUId_TextureView_Dummy;
|
||||
|
||||
typedef WGPUId_TextureView_Dummy WGPUTextureViewId;
|
||||
@@ -317,13 +328,13 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
WGPUTextureViewId attachment;
|
||||
const WGPUTextureViewId *resolve_target;
|
||||
WGPUTextureViewId resolve_target;
|
||||
WGPULoadOp load_op;
|
||||
WGPUStoreOp store_op;
|
||||
WGPUColor clear_color;
|
||||
} WGPURenderPassColorAttachmentDescriptorBase_TextureViewId;
|
||||
} WGPURenderPassColorAttachmentDescriptorBase_TextureViewId__TextureViewId;
|
||||
|
||||
typedef WGPURenderPassColorAttachmentDescriptorBase_TextureViewId WGPURenderPassColorAttachmentDescriptor;
|
||||
typedef WGPURenderPassColorAttachmentDescriptorBase_TextureViewId__TextureViewId WGPURawRenderPassColorAttachmentDescriptor;
|
||||
|
||||
typedef struct {
|
||||
WGPUTextureViewId attachment;
|
||||
@@ -337,6 +348,30 @@ typedef struct {
|
||||
|
||||
typedef WGPURenderPassDepthStencilAttachmentDescriptorBase_TextureViewId WGPURenderPassDepthStencilAttachmentDescriptor;
|
||||
|
||||
typedef struct {
|
||||
WGPURawRenderPassColorAttachmentDescriptor colors[WGPUMAX_COLOR_TARGETS];
|
||||
WGPURenderPassDepthStencilAttachmentDescriptor depth_stencil;
|
||||
} WGPURawRenderTargets;
|
||||
|
||||
typedef struct {
|
||||
WGPURawPass raw;
|
||||
WGPURawRenderTargets targets;
|
||||
} WGPURawRenderPass;
|
||||
|
||||
typedef WGPURawRenderPass *WGPURawRenderPassId;
|
||||
|
||||
typedef const WGPUTextureViewId *WGPUOptionRef_TextureViewId;
|
||||
|
||||
typedef struct {
|
||||
WGPUTextureViewId attachment;
|
||||
WGPUOptionRef_TextureViewId resolve_target;
|
||||
WGPULoadOp load_op;
|
||||
WGPUStoreOp store_op;
|
||||
WGPUColor clear_color;
|
||||
} WGPURenderPassColorAttachmentDescriptorBase_TextureViewId__OptionRef_TextureViewId;
|
||||
|
||||
typedef WGPURenderPassColorAttachmentDescriptorBase_TextureViewId__OptionRef_TextureViewId WGPURenderPassColorAttachmentDescriptor;
|
||||
|
||||
typedef struct {
|
||||
const WGPURenderPassColorAttachmentDescriptor *color_attachments;
|
||||
uintptr_t color_attachments_length;
|
||||
@@ -694,13 +729,11 @@ void wgpu_buffer_unmap(WGPUBufferId buffer_id);
|
||||
|
||||
void wgpu_command_buffer_destroy(WGPUCommandBufferId command_buffer_id);
|
||||
|
||||
WGPUComputePassId wgpu_command_encoder_begin_compute_pass(WGPUCommandEncoderId encoder_id,
|
||||
const WGPUComputePassDescriptor *desc);
|
||||
WGPURawComputePassId wgpu_command_encoder_begin_compute_pass(WGPUCommandEncoderId encoder_id,
|
||||
const WGPUComputePassDescriptor *_desc);
|
||||
|
||||
WGPURenderPassId wgpu_command_encoder_begin_render_pass(WGPUCommandEncoderId encoder_id,
|
||||
const WGPURenderPassDescriptor *desc);
|
||||
|
||||
void wgpu_command_encoder_compute_pass(WGPUCommandEncoderId self_id, const WGPURawPass *pass);
|
||||
WGPURawRenderPassId wgpu_command_encoder_begin_render_pass(WGPUCommandEncoderId encoder_id,
|
||||
const WGPURenderPassDescriptor *desc);
|
||||
|
||||
void wgpu_command_encoder_copy_buffer_to_buffer(WGPUCommandEncoderId command_encoder_id,
|
||||
WGPUBufferId source,
|
||||
@@ -729,33 +762,30 @@ void wgpu_command_encoder_destroy(WGPUCommandEncoderId command_encoder_id);
|
||||
WGPUCommandBufferId wgpu_command_encoder_finish(WGPUCommandEncoderId encoder_id,
|
||||
const WGPUCommandBufferDescriptor *desc);
|
||||
|
||||
void wgpu_command_encoder_render_pass(WGPUCommandEncoderId self_id,
|
||||
const WGPURenderPassColorAttachmentDescriptor *color_attachments,
|
||||
uintptr_t color_attachment_length,
|
||||
const WGPURenderPassDepthStencilAttachmentDescriptor *depth_stencil_attachment,
|
||||
const WGPURawPass *pass);
|
||||
void wgpu_compute_pass_dispatch(WGPURawPass *pass,
|
||||
uint32_t groups_x,
|
||||
uint32_t groups_y,
|
||||
uint32_t groups_z);
|
||||
|
||||
void wgpu_compute_pass_dispatch(WGPUComputePassId pass_id, uint32_t x, uint32_t y, uint32_t z);
|
||||
void wgpu_compute_pass_dispatch_indirect(WGPURawPass *pass,
|
||||
WGPUBufferId buffer_id,
|
||||
WGPUBufferAddress offset);
|
||||
|
||||
void wgpu_compute_pass_dispatch_indirect(WGPUComputePassId pass_id,
|
||||
WGPUBufferId indirect_buffer_id,
|
||||
WGPUBufferAddress indirect_offset);
|
||||
void wgpu_compute_pass_end_pass(WGPURawComputePassId pass_id);
|
||||
|
||||
void wgpu_compute_pass_end_pass(WGPUComputePassId pass_id);
|
||||
void wgpu_compute_pass_insert_debug_marker(WGPURawPass *_pass, WGPURawString _label);
|
||||
|
||||
void wgpu_compute_pass_insert_debug_marker(WGPUComputePassId _pass_id, WGPURawString _label);
|
||||
void wgpu_compute_pass_pop_debug_group(WGPURawPass *_pass);
|
||||
|
||||
void wgpu_compute_pass_pop_debug_group(WGPUComputePassId _pass_id);
|
||||
void wgpu_compute_pass_push_debug_group(WGPURawPass *_pass, WGPURawString _label);
|
||||
|
||||
void wgpu_compute_pass_push_debug_group(WGPUComputePassId _pass_id, WGPURawString _label);
|
||||
|
||||
void wgpu_compute_pass_set_bind_group(WGPUComputePassId pass_id,
|
||||
void wgpu_compute_pass_set_bind_group(WGPURawPass *pass,
|
||||
uint32_t index,
|
||||
WGPUBindGroupId bind_group_id,
|
||||
const WGPUBufferAddress *offsets,
|
||||
uintptr_t offsets_length);
|
||||
uintptr_t offset_length);
|
||||
|
||||
void wgpu_compute_pass_set_pipeline(WGPUComputePassId pass_id, WGPUComputePipelineId pipeline_id);
|
||||
void wgpu_compute_pass_set_pipeline(WGPURawPass *pass, WGPUComputePipelineId pipeline_id);
|
||||
|
||||
WGPUSurfaceId wgpu_create_surface_from_metal_layer(void *layer);
|
||||
|
||||
@@ -812,74 +842,63 @@ void wgpu_queue_submit(WGPUQueueId queue_id,
|
||||
const WGPUCommandBufferId *command_buffers,
|
||||
uintptr_t command_buffers_length);
|
||||
|
||||
void wgpu_render_pass_draw(WGPURenderPassId pass_id,
|
||||
uint32_t vertex_count,
|
||||
uint32_t instance_count,
|
||||
uint32_t first_vertex,
|
||||
uint32_t first_instance);
|
||||
void wgpu_raw_render_pass_draw(WGPURawRenderPass *pass,
|
||||
uint32_t vertex_count,
|
||||
uint32_t instance_count,
|
||||
uint32_t first_vertex,
|
||||
uint32_t first_instance);
|
||||
|
||||
void wgpu_render_pass_draw_indexed(WGPURenderPassId pass_id,
|
||||
uint32_t index_count,
|
||||
uint32_t instance_count,
|
||||
uint32_t first_index,
|
||||
int32_t base_vertex,
|
||||
uint32_t first_instance);
|
||||
void wgpu_raw_render_pass_draw_indirect(WGPURawRenderPass *pass,
|
||||
WGPUBufferId buffer_id,
|
||||
WGPUBufferAddress offset);
|
||||
|
||||
void wgpu_render_pass_draw_indexed_indirect(WGPURenderPassId pass_id,
|
||||
WGPUBufferId indirect_buffer_id,
|
||||
WGPUBufferAddress indirect_offset);
|
||||
void wgpu_raw_render_pass_set_bind_group(WGPURawRenderPass *pass,
|
||||
uint32_t index,
|
||||
WGPUBindGroupId bind_group_id,
|
||||
const WGPUBufferAddress *offsets,
|
||||
uintptr_t offset_length);
|
||||
|
||||
void wgpu_render_pass_draw_indirect(WGPURenderPassId pass_id,
|
||||
WGPUBufferId indirect_buffer_id,
|
||||
WGPUBufferAddress indirect_offset);
|
||||
void wgpu_raw_render_pass_set_blend_color(WGPURawRenderPass *pass, const WGPUColor *color);
|
||||
|
||||
void wgpu_render_pass_end_pass(WGPURenderPassId pass_id);
|
||||
void wgpu_raw_render_pass_set_index_buffer(WGPURawRenderPass *pass,
|
||||
WGPUBufferId buffer_id,
|
||||
WGPUBufferAddress offset);
|
||||
|
||||
void wgpu_render_pass_execute_bundles(WGPURenderPassId _pass_id,
|
||||
void wgpu_raw_render_pass_set_pipeline(WGPURawRenderPass *pass, WGPURenderPipelineId pipeline_id);
|
||||
|
||||
void wgpu_raw_render_pass_set_scissor(WGPURawRenderPass *pass,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
uint32_t w,
|
||||
uint32_t h);
|
||||
|
||||
void wgpu_raw_render_pass_set_stencil_reference(WGPURawRenderPass *pass, uint32_t value);
|
||||
|
||||
void wgpu_raw_render_pass_set_vertex_buffers(WGPURawRenderPass *pass,
|
||||
uint32_t start_slot,
|
||||
const WGPUBufferId *buffer_ids,
|
||||
const WGPUBufferAddress *offsets,
|
||||
uintptr_t length);
|
||||
|
||||
void wgpu_raw_render_pass_set_viewport(WGPURawRenderPass *pass,
|
||||
float x,
|
||||
float y,
|
||||
float w,
|
||||
float h,
|
||||
float depth_min,
|
||||
float depth_max);
|
||||
|
||||
void wgpu_render_pass_end_pass(WGPURawRenderPassId pass_id);
|
||||
|
||||
void wgpu_render_pass_execute_bundles(WGPURawRenderPass *_pass,
|
||||
const WGPURenderBundleId *_bundles,
|
||||
uintptr_t _bundles_length);
|
||||
|
||||
void wgpu_render_pass_insert_debug_marker(WGPURenderPassId _pass_id, WGPURawString _label);
|
||||
void wgpu_render_pass_insert_debug_marker(WGPURawRenderPass *_pass, WGPURawString _label);
|
||||
|
||||
void wgpu_render_pass_pop_debug_group(WGPURenderPassId _pass_id);
|
||||
void wgpu_render_pass_pop_debug_group(WGPURawRenderPass *_pass);
|
||||
|
||||
void wgpu_render_pass_push_debug_group(WGPURenderPassId _pass_id, WGPURawString _label);
|
||||
|
||||
void wgpu_render_pass_set_bind_group(WGPURenderPassId pass_id,
|
||||
uint32_t index,
|
||||
WGPUBindGroupId bind_group_id,
|
||||
const WGPUBufferAddress *offsets,
|
||||
uintptr_t offsets_length);
|
||||
|
||||
void wgpu_render_pass_set_blend_color(WGPURenderPassId pass_id, const WGPUColor *color);
|
||||
|
||||
void wgpu_render_pass_set_index_buffer(WGPURenderPassId pass_id,
|
||||
WGPUBufferId buffer_id,
|
||||
WGPUBufferAddress offset);
|
||||
|
||||
void wgpu_render_pass_set_pipeline(WGPURenderPassId pass_id, WGPURenderPipelineId pipeline_id);
|
||||
|
||||
void wgpu_render_pass_set_scissor_rect(WGPURenderPassId pass_id,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
uint32_t w,
|
||||
uint32_t h);
|
||||
|
||||
void wgpu_render_pass_set_stencil_reference(WGPURenderPassId pass_id, uint32_t value);
|
||||
|
||||
void wgpu_render_pass_set_vertex_buffers(WGPURenderPassId pass_id,
|
||||
uint32_t start_slot,
|
||||
const WGPUBufferId *buffers,
|
||||
const WGPUBufferAddress *offsets,
|
||||
uintptr_t length);
|
||||
|
||||
void wgpu_render_pass_set_viewport(WGPURenderPassId pass_id,
|
||||
float x,
|
||||
float y,
|
||||
float w,
|
||||
float h,
|
||||
float min_depth,
|
||||
float max_depth);
|
||||
void wgpu_render_pass_push_debug_group(WGPURawRenderPass *_pass, WGPURawString _label);
|
||||
|
||||
void wgpu_request_adapter_async(const WGPURequestAdapterOptions *desc,
|
||||
WGPUBackendBit mask,
|
||||
|
||||
@@ -7,7 +7,6 @@ use crate::{
|
||||
bind::{Binder, LayoutChange},
|
||||
CommandBuffer,
|
||||
PhantomSlice,
|
||||
RawPass,
|
||||
},
|
||||
device::{all_buffer_stages, BIND_BUFFER_ALIGNMENT},
|
||||
hub::{GfxBackend, Global, IdentityFilter, Token},
|
||||
@@ -21,13 +20,13 @@ use crate::{
|
||||
use hal::command::CommandBuffer as _;
|
||||
use peek_poke::{Peek, PeekCopy, Poke};
|
||||
|
||||
use std::{convert::TryInto, iter, mem, slice};
|
||||
use std::iter;
|
||||
|
||||
|
||||
#[derive(Clone, Copy, Debug, PeekCopy, Poke)]
|
||||
enum ComputeCommand {
|
||||
SetBindGroup {
|
||||
index: u32,
|
||||
index: u8,
|
||||
num_dynamic_offsets: u8,
|
||||
bind_group_id: id::BindGroupId,
|
||||
phantom_offsets: PhantomSlice<BufferAddress>,
|
||||
@@ -38,6 +37,17 @@ enum ComputeCommand {
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
},
|
||||
End,
|
||||
}
|
||||
|
||||
impl super::RawPass {
|
||||
pub fn new_compute(parent: id::CommandEncoderId) -> Self {
|
||||
Self::from_vec(Vec::<ComputeCommand>::with_capacity(1), parent)
|
||||
}
|
||||
|
||||
pub unsafe fn finish_compute(self) -> (Vec<u8>, id::CommandEncoderId) {
|
||||
self.finish_with(ComputeCommand::End)
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -113,7 +123,8 @@ impl<F> Global<F> {
|
||||
raw_data.as_ptr().add(raw_data.len())
|
||||
};
|
||||
let mut command = ComputeCommand::Dispatch([0; 3]); // dummy
|
||||
while unsafe { peeker.add(mem::size_of::<ComputeCommand>()) } <= raw_data_end {
|
||||
loop {
|
||||
assert!(unsafe { peeker.add(ComputeCommand::max_size()) } <= raw_data_end);
|
||||
peeker = unsafe { command.peek_from(peeker) };
|
||||
match command {
|
||||
ComputeCommand::SetBindGroup { index, num_dynamic_offsets, bind_group_id, phantom_offsets } => {
|
||||
@@ -238,10 +249,9 @@ impl<F> Global<F> {
|
||||
raw.dispatch_indirect(&src_buffer.raw, offset);
|
||||
}
|
||||
}
|
||||
ComputeCommand::End => break,
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(peeker, raw_data_end);
|
||||
}
|
||||
|
||||
pub fn compute_pass_set_bind_group<B: GfxBackend>(
|
||||
@@ -422,53 +432,87 @@ impl<F> Global<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl RawPass {
|
||||
mod ffi {
|
||||
use super::{
|
||||
ComputeCommand,
|
||||
super::{PhantomSlice, RawPass},
|
||||
};
|
||||
use crate::{
|
||||
id,
|
||||
BufferAddress,
|
||||
RawString,
|
||||
};
|
||||
use std::{convert::TryInto, slice};
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_compute_pass_set_bind_group(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_compute_pass_set_bind_group(
|
||||
pass: &mut RawPass,
|
||||
index: u32,
|
||||
bind_group_id: id::BindGroupId,
|
||||
offsets: *const BufferAddress,
|
||||
offset_length: usize,
|
||||
) {
|
||||
self.encode_with1(
|
||||
&ComputeCommand::SetBindGroup {
|
||||
index,
|
||||
num_dynamic_offsets: offset_length.try_into().unwrap(),
|
||||
bind_group_id,
|
||||
phantom_offsets: PhantomSlice::new(),
|
||||
},
|
||||
pass.encode(&ComputeCommand::SetBindGroup {
|
||||
index: index.try_into().unwrap(),
|
||||
num_dynamic_offsets: offset_length.try_into().unwrap(),
|
||||
bind_group_id,
|
||||
phantom_offsets: PhantomSlice::new(),
|
||||
});
|
||||
pass.encode_slice(
|
||||
slice::from_raw_parts(offsets, offset_length),
|
||||
);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_compute_pass_set_pipeline(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_compute_pass_set_pipeline(
|
||||
pass: &mut RawPass,
|
||||
pipeline_id: id::ComputePipelineId,
|
||||
) {
|
||||
self.encode(&ComputeCommand::SetPipeline(pipeline_id));
|
||||
pass.encode(&ComputeCommand::SetPipeline(pipeline_id));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_compute_pass_dispatch(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_compute_pass_dispatch(
|
||||
pass: &mut RawPass,
|
||||
groups_x: u32,
|
||||
groups_y: u32,
|
||||
groups_z: u32,
|
||||
) {
|
||||
self.encode(&ComputeCommand::Dispatch([groups_x, groups_y, groups_z]));
|
||||
pass.encode(&ComputeCommand::Dispatch([groups_x, groups_y, groups_z]));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_compute_pass_dispatch_indirect(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_compute_pass_dispatch_indirect(
|
||||
pass: &mut RawPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) {
|
||||
self.encode(&ComputeCommand::DispatchIndirect {
|
||||
pass.encode(&ComputeCommand::DispatchIndirect {
|
||||
buffer_id,
|
||||
offset,
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_push_debug_group(
|
||||
_pass: &mut RawPass,
|
||||
_label: RawString,
|
||||
) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_pop_debug_group(
|
||||
_pass: &mut RawPass,
|
||||
) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_insert_debug_marker(
|
||||
_pass: &mut RawPass,
|
||||
_label: RawString,
|
||||
) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ pub use self::transfer::*;
|
||||
use crate::{
|
||||
conv,
|
||||
device::{
|
||||
MAX_COLOR_TARGETS,
|
||||
all_buffer_stages,
|
||||
all_image_stages,
|
||||
FramebufferKey,
|
||||
@@ -23,16 +24,7 @@ use crate::{
|
||||
RenderPassKey,
|
||||
},
|
||||
hub::{GfxBackend, Global, IdentityFilter, Storage, Token},
|
||||
id::{
|
||||
BufferId,
|
||||
CommandBufferId,
|
||||
CommandEncoderId,
|
||||
ComputePassId,
|
||||
DeviceId,
|
||||
RenderPassId,
|
||||
TextureId,
|
||||
TextureViewId,
|
||||
},
|
||||
id,
|
||||
resource::{Buffer, Texture, TextureUsage, TextureViewInner},
|
||||
track::TrackerSet,
|
||||
Features,
|
||||
@@ -41,7 +33,11 @@ use crate::{
|
||||
};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use hal::{adapter::PhysicalDevice as _, command::CommandBuffer as _, device::Device as _};
|
||||
use hal::{
|
||||
adapter::PhysicalDevice as _,
|
||||
command::CommandBuffer as _,
|
||||
device::Device as _,
|
||||
};
|
||||
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
@@ -49,12 +45,14 @@ use std::{
|
||||
iter,
|
||||
marker::PhantomData,
|
||||
mem,
|
||||
ptr,
|
||||
slice,
|
||||
thread::ThreadId,
|
||||
};
|
||||
|
||||
|
||||
pub type RawRenderPassId = *mut RawRenderPass;
|
||||
pub type RawComputePassId = *mut RawPass;
|
||||
|
||||
#[derive(Clone, Copy, Debug, peek_poke::PeekCopy, peek_poke::Poke)]
|
||||
struct PhantomSlice<T>(PhantomData<T>);
|
||||
|
||||
@@ -66,88 +64,80 @@ impl<T> PhantomSlice<T> {
|
||||
unsafe fn decode<'a>(
|
||||
self, pointer: *const u8, count: usize, bound: *const u8
|
||||
) -> (*const u8, &'a [T]) {
|
||||
debug_assert_eq!(pointer.align_offset(mem::align_of::<T>()), 0);
|
||||
let extra_size = count * mem::size_of::<T>();
|
||||
let end = pointer.add(extra_size);
|
||||
let align_offset = pointer.align_offset(mem::align_of::<T>());
|
||||
let aligned = pointer.add(align_offset);
|
||||
let size = count * mem::size_of::<T>();
|
||||
let end = aligned.add(size);
|
||||
assert!(end <= bound);
|
||||
(end, slice::from_raw_parts(pointer as *const T, count))
|
||||
(end, slice::from_raw_parts(aligned as *const T, count))
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct RawPass {
|
||||
data: *mut u8,
|
||||
base: *mut u8,
|
||||
capacity: usize,
|
||||
parent: id::CommandEncoderId,
|
||||
}
|
||||
|
||||
impl RawPass {
|
||||
pub fn new() -> Self {
|
||||
let mut vec = Vec::with_capacity(16);
|
||||
fn from_vec<T>(
|
||||
mut vec: Vec<T>,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
) -> Self {
|
||||
let ptr = vec.as_mut_ptr() as *mut u8;
|
||||
let capacity = vec.capacity() * mem::size_of::<T>();
|
||||
mem::forget(vec);
|
||||
RawPass {
|
||||
data: vec.as_mut_ptr(),
|
||||
base: vec.as_mut_ptr(),
|
||||
capacity: vec.capacity(),
|
||||
data: ptr,
|
||||
base: ptr,
|
||||
capacity,
|
||||
parent: encoder_id,
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn delete(self) {
|
||||
let size = self.data as usize - self.base as usize;
|
||||
let _ = Vec::from_raw_parts(self.base, size, self.capacity);
|
||||
}
|
||||
|
||||
pub unsafe fn to_slice(&self) -> &[u8] {
|
||||
let size = self.data as usize - self.base as usize;
|
||||
/// Finish encoding a raw pass.
|
||||
///
|
||||
/// The last command is provided, yet the encoder
|
||||
/// is guaranteed to have exactly `C::max_size()` space for it.
|
||||
unsafe fn finish_with<C: peek_poke::Poke>(
|
||||
mut self, command: C
|
||||
) -> (Vec<u8>, id::CommandEncoderId) {
|
||||
self.ensure_extra_size(C::max_size());
|
||||
command.poke_into(self.data);
|
||||
let size = self.data as usize + C::max_size() - self.base as usize;
|
||||
assert!(size <= self.capacity);
|
||||
slice::from_raw_parts(self.base, size)
|
||||
(Vec::from_raw_parts(self.base, size, self.capacity), self.parent)
|
||||
}
|
||||
|
||||
unsafe fn ensure_extra_size(&mut self, extra_size: usize) {
|
||||
let size = self.data as usize - self.base as usize;
|
||||
if let Some(extra_capacity) = (size + extra_size).checked_sub(self.capacity) {
|
||||
if size + extra_size > self.capacity {
|
||||
let mut vec = Vec::from_raw_parts(self.base, size, self.capacity);
|
||||
vec.reserve(extra_capacity);
|
||||
vec.reserve(extra_size);
|
||||
//let (data, size, capacity) = vec.into_raw_parts(); //TODO: when stable
|
||||
self.data = vec.as_mut_ptr().add(vec.len());
|
||||
self.base = vec.as_mut_ptr();
|
||||
self.capacity = vec.capacity();
|
||||
mem::forget(vec);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn encode<C: peek_poke::Poke>(&mut self, command: &C) {
|
||||
self.ensure_extra_size(mem::size_of::<C>());
|
||||
self.ensure_extra_size(C::max_size());
|
||||
self.data = command.poke_into(self.data);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn encode_with1<C: peek_poke::Poke, T>(
|
||||
&mut self, command: &C, extra: &[T]
|
||||
) {
|
||||
let extra_size = extra.len() * mem::size_of::<T>();
|
||||
self.ensure_extra_size(mem::size_of::<C>() + extra_size);
|
||||
self.data = command.poke_into(self.data);
|
||||
|
||||
debug_assert_eq!(self.data.align_offset(mem::align_of::<T>()), 0);
|
||||
ptr::copy_nonoverlapping(extra.as_ptr(), self.data as *mut T, extra.len());
|
||||
self.data = self.data.add(extra_size);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn encode_with2<C: peek_poke::Poke, T, V>(
|
||||
&mut self, command: &C, extra1: &[T], extra2: &[V]
|
||||
) {
|
||||
let extra1_size = extra1.len() * mem::size_of::<T>();
|
||||
let extra2_size = extra2.len() * mem::size_of::<V>();
|
||||
self.ensure_extra_size(mem::size_of::<C>() + extra1_size + extra2_size);
|
||||
self.data = command.poke_into(self.data);
|
||||
|
||||
debug_assert_eq!(self.data.align_offset(mem::align_of::<T>()), 0);
|
||||
ptr::copy_nonoverlapping(extra1.as_ptr(), self.data as *mut T, extra1.len());
|
||||
self.data = self.data.add(extra1_size);
|
||||
|
||||
debug_assert_eq!(self.data.align_offset(mem::align_of::<V>()), 0);
|
||||
ptr::copy_nonoverlapping(extra2.as_ptr(), self.data as *mut V, extra2.len());
|
||||
self.data = self.data.add(extra2_size);
|
||||
unsafe fn encode_slice<T: Copy>(&mut self, data: &[T]) {
|
||||
let align_offset = self.data.align_offset(mem::align_of::<T>());
|
||||
let extra = align_offset + mem::size_of::<T>() * data.len();
|
||||
self.ensure_extra_size(extra);
|
||||
slice::from_raw_parts_mut(self.data.add(align_offset) as *mut T, data.len())
|
||||
.copy_from_slice(data);
|
||||
self.data = self.data.add(extra);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,10 +150,10 @@ pub struct CommandBuffer<B: hal::Backend> {
|
||||
pub(crate) raw: Vec<B::CommandBuffer>,
|
||||
is_recording: bool,
|
||||
recorded_thread_id: ThreadId,
|
||||
pub(crate) device_id: Stored<DeviceId>,
|
||||
pub(crate) device_id: Stored<id::DeviceId>,
|
||||
pub(crate) life_guard: LifeGuard,
|
||||
pub(crate) trackers: TrackerSet,
|
||||
pub(crate) used_swap_chain: Option<(Stored<TextureViewId>, B::Framebuffer)>,
|
||||
pub(crate) used_swap_chain: Option<(Stored<id::TextureViewId>, B::Framebuffer)>,
|
||||
pub(crate) features: Features,
|
||||
}
|
||||
|
||||
@@ -172,8 +162,8 @@ impl<B: GfxBackend> CommandBuffer<B> {
|
||||
raw: &mut B::CommandBuffer,
|
||||
base: &mut TrackerSet,
|
||||
head: &TrackerSet,
|
||||
buffer_guard: &Storage<Buffer<B>, BufferId>,
|
||||
texture_guard: &Storage<Texture<B>, TextureId>,
|
||||
buffer_guard: &Storage<Buffer<B>, id::BufferId>,
|
||||
texture_guard: &Storage<Texture<B>, id::TextureId>,
|
||||
) {
|
||||
debug_assert_eq!(B::VARIANT, base.backend());
|
||||
debug_assert_eq!(B::VARIANT, head.backend());
|
||||
@@ -221,12 +211,66 @@ pub struct CommandBufferDescriptor {
|
||||
pub todo: u32,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_command_encoder_begin_compute_pass(
|
||||
encoder_id: id::CommandEncoderId,
|
||||
_desc: Option<&ComputePassDescriptor>,
|
||||
) -> RawComputePassId {
|
||||
let pass = RawPass::new_compute(encoder_id);
|
||||
Box::into_raw(Box::new(pass))
|
||||
}
|
||||
|
||||
type RawRenderPassColorAttachmentDescriptor =
|
||||
RenderPassColorAttachmentDescriptorBase<id::TextureViewId, id::TextureViewId>;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct RawRenderTargets {
|
||||
pub colors: [RawRenderPassColorAttachmentDescriptor; MAX_COLOR_TARGETS],
|
||||
pub depth_stencil: RenderPassDepthStencilAttachmentDescriptor,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct RawRenderPass {
|
||||
raw: RawPass,
|
||||
targets: RawRenderTargets,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_command_encoder_begin_render_pass(
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &RenderPassDescriptor,
|
||||
) -> RawRenderPassId {
|
||||
let mut colors: [RawRenderPassColorAttachmentDescriptor; MAX_COLOR_TARGETS] = mem::zeroed();
|
||||
for (color, at) in colors
|
||||
.iter_mut()
|
||||
.zip(slice::from_raw_parts(desc.color_attachments, desc.color_attachments_length))
|
||||
{
|
||||
*color = RawRenderPassColorAttachmentDescriptor {
|
||||
attachment: at.attachment,
|
||||
resolve_target: at.resolve_target.map_or(id::TextureViewId::ERROR, |rt| *rt),
|
||||
load_op: at.load_op,
|
||||
store_op: at.store_op,
|
||||
clear_color: at.clear_color,
|
||||
};
|
||||
}
|
||||
let pass = RawRenderPass {
|
||||
raw: RawPass::new_render(encoder_id),
|
||||
targets: RawRenderTargets {
|
||||
colors,
|
||||
depth_stencil: desc.depth_stencil_attachment
|
||||
.cloned()
|
||||
.unwrap_or_else(|| mem::zeroed()),
|
||||
},
|
||||
};
|
||||
Box::into_raw(Box::new(pass))
|
||||
}
|
||||
|
||||
impl<F> Global<F> {
|
||||
pub fn command_encoder_finish<B: GfxBackend>(
|
||||
&self,
|
||||
encoder_id: CommandEncoderId,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
_desc: &CommandBufferDescriptor,
|
||||
) -> CommandBufferId {
|
||||
) -> id::CommandBufferId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
//TODO: actually close the last recorded command buffer
|
||||
@@ -243,13 +287,13 @@ impl<F> Global<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
impl<F: IdentityFilter<id::RenderPassId>> Global<F> {
|
||||
pub fn command_encoder_begin_render_pass<B: GfxBackend>(
|
||||
&self,
|
||||
encoder_id: CommandEncoderId,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &RenderPassDescriptor,
|
||||
id_in: F::Input,
|
||||
) -> RenderPassId {
|
||||
) -> id::RenderPassId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
|
||||
@@ -279,12 +323,12 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
let (view_guard, _) = hub.texture_views.read(&mut token);
|
||||
|
||||
let mut extent = None;
|
||||
let mut used_swap_chain_image = None::<Stored<TextureViewId>>;
|
||||
let mut used_swap_chain_image = None::<Stored<id::TextureViewId>>;
|
||||
|
||||
let color_attachments = unsafe {
|
||||
slice::from_raw_parts(desc.color_attachments, desc.color_attachments_length)
|
||||
};
|
||||
let depth_stencil_attachment = unsafe { desc.depth_stencil_attachment.as_ref() };
|
||||
let depth_stencil_attachment = desc.depth_stencil_attachment;
|
||||
|
||||
let sample_count = color_attachments
|
||||
.get(0)
|
||||
@@ -297,7 +341,7 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
|
||||
const MAX_TOTAL_ATTACHMENTS: usize = 10;
|
||||
type OutputAttachment<'a> = (
|
||||
&'a Stored<TextureId>,
|
||||
&'a Stored<id::TextureId>,
|
||||
&'a hal::image::SubresourceRange,
|
||||
Option<TextureUsage>,
|
||||
);
|
||||
@@ -525,7 +569,7 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
(3, hal::image::Layout::ColorAttachmentOptimal),
|
||||
];
|
||||
|
||||
let mut resolve_ids = ArrayVec::<[_; crate::device::MAX_COLOR_TARGETS]>::new();
|
||||
let mut resolve_ids = ArrayVec::<[_; MAX_COLOR_TARGETS]>::new();
|
||||
let mut attachment_index = color_attachments.len();
|
||||
if color_attachments
|
||||
.iter()
|
||||
@@ -732,13 +776,13 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<ComputePassId>> Global<F> {
|
||||
impl<F: IdentityFilter<id::ComputePassId>> Global<F> {
|
||||
pub fn command_encoder_begin_compute_pass<B: GfxBackend>(
|
||||
&self,
|
||||
encoder_id: CommandEncoderId,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
_desc: &ComputePassDescriptor,
|
||||
id_in: F::Input,
|
||||
) -> ComputePassId {
|
||||
) -> id::ComputePassId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
bind::{Binder, LayoutChange},
|
||||
CommandBuffer,
|
||||
PhantomSlice,
|
||||
RawPass,
|
||||
RawRenderTargets,
|
||||
},
|
||||
conv,
|
||||
device::{
|
||||
@@ -16,6 +16,7 @@ use crate::{
|
||||
RenderPassKey,
|
||||
BIND_BUFFER_ALIGNMENT,
|
||||
MAX_VERTEX_BUFFERS,
|
||||
MAX_COLOR_TARGETS,
|
||||
},
|
||||
hub::{GfxBackend, Global, IdentityFilter, Token},
|
||||
id,
|
||||
@@ -34,12 +35,9 @@ use peek_poke::{Peek, PeekCopy, Poke};
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
collections::hash_map::Entry,
|
||||
convert::TryInto,
|
||||
iter,
|
||||
marker::PhantomData,
|
||||
mem,
|
||||
ops::Range,
|
||||
slice,
|
||||
};
|
||||
|
||||
|
||||
@@ -59,16 +57,16 @@ pub enum StoreOp {
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct RenderPassColorAttachmentDescriptorBase<'a, T> {
|
||||
pub attachment: id::TextureViewId,
|
||||
pub resolve_target: Option<&'a T>,
|
||||
pub struct RenderPassColorAttachmentDescriptorBase<T, R> {
|
||||
pub attachment: T,
|
||||
pub resolve_target: R,
|
||||
pub load_op: LoadOp,
|
||||
pub store_op: StoreOp,
|
||||
pub clear_color: Color,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RenderPassDepthStencilAttachmentDescriptorBase<T> {
|
||||
pub attachment: T,
|
||||
pub depth_load_op: LoadOp,
|
||||
@@ -79,15 +77,20 @@ pub struct RenderPassDepthStencilAttachmentDescriptorBase<T> {
|
||||
pub clear_stencil: u32,
|
||||
}
|
||||
|
||||
pub type RenderPassDepthStencilAttachmentDescriptor = RenderPassDepthStencilAttachmentDescriptorBase<id::TextureViewId>;
|
||||
pub type RenderPassColorAttachmentDescriptor<'a> = RenderPassColorAttachmentDescriptorBase<'a, id::TextureViewId>;
|
||||
//Note: this could look better if `cbindgen` wasn't confused by &T used in place of
|
||||
// a generic paramter, it's not able to mange
|
||||
pub type OptionRef<'a, T> = Option<&'a T>;
|
||||
pub type RenderPassColorAttachmentDescriptor<'a> =
|
||||
RenderPassColorAttachmentDescriptorBase<id::TextureViewId, OptionRef<'a, id::TextureViewId>>;
|
||||
pub type RenderPassDepthStencilAttachmentDescriptor =
|
||||
RenderPassDepthStencilAttachmentDescriptorBase<id::TextureViewId>;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct RenderPassDescriptor<'a> {
|
||||
pub color_attachments: *const RenderPassColorAttachmentDescriptor<'a>,
|
||||
pub color_attachments_length: usize,
|
||||
pub depth_stencil_attachment: *const RenderPassDepthStencilAttachmentDescriptor,
|
||||
pub depth_stencil_attachment: Option<&'a RenderPassDepthStencilAttachmentDescriptor>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PeekCopy, Poke)]
|
||||
@@ -101,7 +104,7 @@ pub struct Rect<T> {
|
||||
#[derive(Clone, Copy, Debug, PeekCopy, Poke)]
|
||||
enum RenderCommand {
|
||||
SetBindGroup {
|
||||
index: u32,
|
||||
index: u8,
|
||||
num_dynamic_offsets: u8,
|
||||
bind_group_id: id::BindGroupId,
|
||||
phantom_offsets: PhantomSlice<BufferAddress>,
|
||||
@@ -147,6 +150,20 @@ enum RenderCommand {
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
},
|
||||
End,
|
||||
}
|
||||
|
||||
impl super::RawPass {
|
||||
pub fn new_render(parent_id: id::CommandEncoderId) -> Self {
|
||||
Self::from_vec(Vec::<RenderCommand>::with_capacity(1), parent_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl super::RawRenderPass {
|
||||
pub unsafe fn finish_render(self) -> (Vec<u8>, id::CommandEncoderId, RawRenderTargets) {
|
||||
let (vec, parent_id) = self.raw.finish_with(RenderCommand::End);
|
||||
(vec, parent_id, self.targets)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -650,7 +667,7 @@ impl<F> Global<F> {
|
||||
(3, hal::image::Layout::ColorAttachmentOptimal),
|
||||
];
|
||||
|
||||
let mut resolve_ids = ArrayVec::<[_; crate::device::MAX_COLOR_TARGETS]>::new();
|
||||
let mut resolve_ids = ArrayVec::<[_; MAX_COLOR_TARGETS]>::new();
|
||||
let mut attachment_index = color_attachments.len();
|
||||
if color_attachments
|
||||
.iter()
|
||||
@@ -869,7 +886,8 @@ impl<F> Global<F> {
|
||||
first_vertex: 0,
|
||||
first_instance: 0,
|
||||
};
|
||||
while unsafe { peeker.add(mem::size_of::<RenderCommand>()) } <= raw_data_end {
|
||||
loop {
|
||||
assert!(unsafe { peeker.add(RenderCommand::max_size()) } <= raw_data_end);
|
||||
peeker = unsafe { command.peek_from(peeker) };
|
||||
match command {
|
||||
RenderCommand::SetBindGroup { index, num_dynamic_offsets, bind_group_id, phantom_offsets } => {
|
||||
@@ -1179,10 +1197,9 @@ impl<F> Global<F> {
|
||||
raw.draw_indexed_indirect(&buffer.raw, offset, 1, 0);
|
||||
}
|
||||
}
|
||||
RenderCommand::End => break,
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(peeker, raw_data_end);
|
||||
}
|
||||
|
||||
pub fn render_pass_set_bind_group<B: GfxBackend>(
|
||||
@@ -1651,85 +1668,99 @@ impl<F> Global<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl RawPass {
|
||||
mod ffi {
|
||||
use super::{
|
||||
RenderCommand,
|
||||
super::{PhantomSlice, RawRenderPass, Rect},
|
||||
};
|
||||
use crate::{
|
||||
id,
|
||||
BufferAddress,
|
||||
Color,
|
||||
RawString,
|
||||
};
|
||||
use std::{convert::TryInto, slice};
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_render_pass_set_bind_group(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_render_pass_set_bind_group(
|
||||
pass: &mut RawRenderPass,
|
||||
index: u32,
|
||||
bind_group_id: id::BindGroupId,
|
||||
offsets: *const BufferAddress,
|
||||
offset_length: usize,
|
||||
) {
|
||||
self.encode_with1(
|
||||
&RenderCommand::SetBindGroup {
|
||||
index,
|
||||
num_dynamic_offsets: offset_length.try_into().unwrap(),
|
||||
bind_group_id,
|
||||
phantom_offsets: PhantomSlice::new(),
|
||||
},
|
||||
pass.raw.encode(&RenderCommand::SetBindGroup {
|
||||
index: index.try_into().unwrap(),
|
||||
num_dynamic_offsets: offset_length.try_into().unwrap(),
|
||||
bind_group_id,
|
||||
phantom_offsets: PhantomSlice::new(),
|
||||
});
|
||||
pass.raw.encode_slice(
|
||||
slice::from_raw_parts(offsets, offset_length),
|
||||
);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_render_pass_set_pipeline(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_render_pass_set_pipeline(
|
||||
pass: &mut RawRenderPass,
|
||||
pipeline_id: id::RenderPipelineId,
|
||||
) {
|
||||
self.encode(&RenderCommand::SetPipeline(pipeline_id));
|
||||
pass.raw.encode(&RenderCommand::SetPipeline(pipeline_id));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_render_pass_set_index_buffer(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_render_pass_set_index_buffer(
|
||||
pass: &mut RawRenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) {
|
||||
self.encode(&RenderCommand::SetIndexBuffer {
|
||||
pass.raw.encode(&RenderCommand::SetIndexBuffer {
|
||||
buffer_id,
|
||||
offset,
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_render_pass_set_vertex_buffers(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_render_pass_set_vertex_buffers(
|
||||
pass: &mut RawRenderPass,
|
||||
start_slot: u32,
|
||||
buffer_ids: *const id::BufferId,
|
||||
offsets: *const BufferAddress,
|
||||
length: usize,
|
||||
) {
|
||||
self.encode_with2(
|
||||
&RenderCommand::SetVertexBuffers {
|
||||
start_index: start_slot.try_into().unwrap(),
|
||||
count: length.try_into().unwrap(),
|
||||
phantom_buffer_ids: PhantomSlice::new(),
|
||||
phantom_offsets: PhantomSlice::new(),
|
||||
},
|
||||
pass.raw.encode(&RenderCommand::SetVertexBuffers {
|
||||
start_index: start_slot.try_into().unwrap(),
|
||||
count: length.try_into().unwrap(),
|
||||
phantom_buffer_ids: PhantomSlice::new(),
|
||||
phantom_offsets: PhantomSlice::new(),
|
||||
});
|
||||
pass.raw.encode_slice(
|
||||
slice::from_raw_parts(buffer_ids, length),
|
||||
);
|
||||
pass.raw.encode_slice(
|
||||
slice::from_raw_parts(offsets, length),
|
||||
);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_render_pass_set_blend_color(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_render_pass_set_blend_color(
|
||||
pass: &mut RawRenderPass,
|
||||
color: &Color,
|
||||
) {
|
||||
self.encode(&RenderCommand::SetBlendColor(*color));
|
||||
pass.raw.encode(&RenderCommand::SetBlendColor(*color));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_render_pass_set_stencil_reference(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_render_pass_set_stencil_reference(
|
||||
pass: &mut RawRenderPass,
|
||||
value: u32,
|
||||
) {
|
||||
self.encode(&RenderCommand::SetStencilReference(value));
|
||||
pass.raw.encode(&RenderCommand::SetStencilReference(value));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_render_pass_set_viewport(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_render_pass_set_viewport(
|
||||
pass: &mut RawRenderPass,
|
||||
x: f32,
|
||||
y: f32,
|
||||
w: f32,
|
||||
@@ -1737,7 +1768,7 @@ impl RawPass {
|
||||
depth_min: f32,
|
||||
depth_max: f32,
|
||||
) {
|
||||
self.encode(&RenderCommand::SetViewport {
|
||||
pass.raw.encode(&RenderCommand::SetViewport {
|
||||
rect: Rect { x, y, w, h },
|
||||
depth_min,
|
||||
depth_max,
|
||||
@@ -1745,25 +1776,25 @@ impl RawPass {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_render_pass_set_scissor(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_render_pass_set_scissor(
|
||||
pass: &mut RawRenderPass,
|
||||
x: u32,
|
||||
y: u32,
|
||||
w: u32,
|
||||
h: u32,
|
||||
) {
|
||||
self.encode(&RenderCommand::SetScissor(Rect { x, y, w, h }));
|
||||
pass.raw.encode(&RenderCommand::SetScissor(Rect { x, y, w, h }));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_render_pass_draw(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_render_pass_draw(
|
||||
pass: &mut RawRenderPass,
|
||||
vertex_count: u32,
|
||||
instance_count: u32,
|
||||
first_vertex: u32,
|
||||
first_instance: u32,
|
||||
) {
|
||||
self.encode(&RenderCommand::Draw {
|
||||
pass.raw.encode(&RenderCommand::Draw {
|
||||
vertex_count,
|
||||
instance_count,
|
||||
first_vertex,
|
||||
@@ -1772,14 +1803,46 @@ impl RawPass {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_raw_render_pass_draw_indirect(
|
||||
&mut self,
|
||||
pub unsafe extern "C" fn wgpu_render_pass_draw_indirect(
|
||||
pass: &mut RawRenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) {
|
||||
self.encode(&RenderCommand::DrawIndirect {
|
||||
pass.raw.encode(&RenderCommand::DrawIndirect {
|
||||
buffer_id,
|
||||
offset,
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_execute_bundles(
|
||||
_pass: &mut RawRenderPass,
|
||||
_bundles: *const id::RenderBundleId,
|
||||
_bundles_length: usize,
|
||||
) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_push_debug_group(
|
||||
_pass: &mut RawRenderPass,
|
||||
_label: RawString,
|
||||
) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_pop_debug_group(
|
||||
_pass: &mut RawRenderPass,
|
||||
) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_insert_debug_marker(
|
||||
_pass: &mut RawRenderPass,
|
||||
_label: RawString,
|
||||
) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ package = "wgpu-core"
|
||||
version = "0.1"
|
||||
|
||||
[dependencies]
|
||||
arrayvec = "0.5"
|
||||
lazy_static = "1.1"
|
||||
parking_lot = "0.9"
|
||||
raw-window-handle = "0.3"
|
||||
|
||||
@@ -25,6 +25,8 @@ exclude = ["BufferMapResult"]
|
||||
parse_deps = true
|
||||
include = ["wgpu-core"]
|
||||
|
||||
extra_bindings = ["wgpu-core"]
|
||||
|
||||
[fn]
|
||||
|
||||
[struct]
|
||||
@@ -38,3 +40,7 @@ derive_helper_methods = true
|
||||
bitflags = true
|
||||
|
||||
[defines]
|
||||
#"target_os = ios" = "WGPU_TARGET_IOS"
|
||||
#"target_os = macos" = "WGPU_TARGET_MACOS"
|
||||
#"unix" = "WGPU_TARGET_FAMILY_UNIX"
|
||||
#"windows" = "WGPU_TARGET_WINDOWS"
|
||||
|
||||
@@ -6,8 +6,6 @@ use crate::GLOBAL;
|
||||
|
||||
use core::{gfx_select, id};
|
||||
|
||||
use std::{marker::PhantomData, slice};
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_command_encoder_finish(
|
||||
@@ -79,261 +77,38 @@ pub extern "C" fn wgpu_command_encoder_copy_texture_to_texture(
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_command_encoder_begin_render_pass(
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &core::command::RenderPassDescriptor,
|
||||
) -> id::RenderPassId {
|
||||
gfx_select!(encoder_id => GLOBAL.command_encoder_begin_render_pass(encoder_id, desc, PhantomData))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_end_pass(pass_id: id::RenderPassId) {
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_end_pass(pass_id))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_render_pass_set_bind_group(
|
||||
pass_id: id::RenderPassId,
|
||||
index: u32,
|
||||
bind_group_id: id::BindGroupId,
|
||||
offsets: *const core::BufferAddress,
|
||||
offsets_length: usize,
|
||||
) {
|
||||
let offsets = if offsets_length != 0 {
|
||||
slice::from_raw_parts(offsets, offsets_length)
|
||||
pub unsafe extern "C" fn wgpu_render_pass_end_pass(pass_id: core::command::RawRenderPassId) {
|
||||
let (pass_data, encoder_id, targets) = Box::from_raw(pass_id).finish_render();
|
||||
let color_attachments: arrayvec::ArrayVec<[_; core::device::MAX_COLOR_TARGETS]> = targets.colors
|
||||
.iter()
|
||||
.flat_map(|at| {
|
||||
if at.attachment == core::id::TextureViewId::ERROR {
|
||||
None
|
||||
} else {
|
||||
Some(core::command::RenderPassColorAttachmentDescriptor {
|
||||
attachment: at.attachment,
|
||||
resolve_target: if at.resolve_target == core::id::TextureViewId::ERROR {
|
||||
None
|
||||
} else {
|
||||
Some(&at.resolve_target)
|
||||
},
|
||||
load_op: at.load_op,
|
||||
store_op: at.store_op,
|
||||
clear_color: at.clear_color,
|
||||
})
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let depth_stencil_attachment = if targets.depth_stencil.attachment == core::id::TextureViewId::ERROR {
|
||||
None
|
||||
} else {
|
||||
&[]
|
||||
Some(&targets.depth_stencil)
|
||||
};
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_set_bind_group(pass_id, index, bind_group_id, offsets))
|
||||
gfx_select!(encoder_id => GLOBAL.command_encoder_run_render_pass(encoder_id, &color_attachments, depth_stencil_attachment, &pass_data))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_push_debug_group(
|
||||
_pass_id: id::RenderPassId,
|
||||
_label: core::RawString,
|
||||
) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_pop_debug_group(_pass_id: id::RenderPassId) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_insert_debug_marker(
|
||||
_pass_id: id::RenderPassId,
|
||||
_label: core::RawString,
|
||||
) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_set_index_buffer(
|
||||
pass_id: id::RenderPassId,
|
||||
buffer_id: id::BufferId,
|
||||
offset: core::BufferAddress,
|
||||
) {
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_set_index_buffer(pass_id, buffer_id, offset))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_render_pass_set_vertex_buffers(
|
||||
pass_id: id::RenderPassId,
|
||||
start_slot: u32,
|
||||
buffers: *const id::BufferId,
|
||||
offsets: *const core::BufferAddress,
|
||||
length: usize,
|
||||
) {
|
||||
let buffers = slice::from_raw_parts(buffers, length);
|
||||
let offsets = slice::from_raw_parts(offsets, length);
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_set_vertex_buffers(pass_id, start_slot, buffers, offsets))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_draw(
|
||||
pass_id: id::RenderPassId,
|
||||
vertex_count: u32,
|
||||
instance_count: u32,
|
||||
first_vertex: u32,
|
||||
first_instance: u32,
|
||||
) {
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_draw(pass_id, vertex_count, instance_count, first_vertex, first_instance))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_draw_indirect(
|
||||
pass_id: id::RenderPassId,
|
||||
indirect_buffer_id: id::BufferId,
|
||||
indirect_offset: core::BufferAddress,
|
||||
) {
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_draw_indirect(pass_id, indirect_buffer_id, indirect_offset))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_draw_indexed(
|
||||
pass_id: id::RenderPassId,
|
||||
index_count: u32,
|
||||
instance_count: u32,
|
||||
first_index: u32,
|
||||
base_vertex: i32,
|
||||
first_instance: u32,
|
||||
) {
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_draw_indexed(pass_id, index_count, instance_count, first_index, base_vertex, first_instance))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_draw_indexed_indirect(
|
||||
pass_id: id::RenderPassId,
|
||||
indirect_buffer_id: id::BufferId,
|
||||
indirect_offset: core::BufferAddress,
|
||||
) {
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_draw_indexed_indirect(pass_id, indirect_buffer_id, indirect_offset))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_set_pipeline(
|
||||
pass_id: id::RenderPassId,
|
||||
pipeline_id: id::RenderPipelineId,
|
||||
) {
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_set_pipeline(pass_id, pipeline_id))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_set_blend_color(pass_id: id::RenderPassId, color: &core::Color) {
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_set_blend_color(pass_id, color))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_set_stencil_reference(pass_id: id::RenderPassId, value: u32) {
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_set_stencil_reference(pass_id, value))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_set_viewport(
|
||||
pass_id: id::RenderPassId,
|
||||
x: f32,
|
||||
y: f32,
|
||||
w: f32,
|
||||
h: f32,
|
||||
min_depth: f32,
|
||||
max_depth: f32,
|
||||
) {
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_set_viewport(pass_id, x, y, w, h, min_depth, max_depth))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_set_scissor_rect(
|
||||
pass_id: id::RenderPassId,
|
||||
x: u32,
|
||||
y: u32,
|
||||
w: u32,
|
||||
h: u32,
|
||||
) {
|
||||
gfx_select!(pass_id => GLOBAL.render_pass_set_scissor_rect(pass_id, x, y, w, h))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_execute_bundles(
|
||||
_pass_id: id::RenderPassId,
|
||||
_bundles: *const id::RenderBundleId,
|
||||
_bundles_length: usize,
|
||||
) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_command_encoder_begin_compute_pass(
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: Option<&core::command::ComputePassDescriptor>,
|
||||
) -> id::ComputePassId {
|
||||
let desc = &desc.cloned().unwrap_or_default();
|
||||
gfx_select!(encoder_id => GLOBAL.command_encoder_begin_compute_pass(encoder_id, desc, PhantomData))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_end_pass(pass_id: id::ComputePassId) {
|
||||
gfx_select!(pass_id => GLOBAL.compute_pass_end_pass(pass_id))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_compute_pass_set_bind_group(
|
||||
pass_id: id::ComputePassId,
|
||||
index: u32,
|
||||
bind_group_id: id::BindGroupId,
|
||||
offsets: *const core::BufferAddress,
|
||||
offsets_length: usize,
|
||||
) {
|
||||
let offsets = if offsets_length != 0 {
|
||||
slice::from_raw_parts(offsets, offsets_length)
|
||||
} else {
|
||||
&[]
|
||||
};
|
||||
gfx_select!(pass_id => GLOBAL.compute_pass_set_bind_group(pass_id, index, bind_group_id, offsets))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_push_debug_group(
|
||||
_pass_id: id::ComputePassId,
|
||||
_label: core::RawString,
|
||||
) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_pop_debug_group(_pass_id: id::ComputePassId) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_insert_debug_marker(
|
||||
_pass_id: id::ComputePassId,
|
||||
_label: core::RawString,
|
||||
) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_dispatch(pass_id: id::ComputePassId, x: u32, y: u32, z: u32) {
|
||||
gfx_select!(pass_id => GLOBAL.compute_pass_dispatch(pass_id, x, y, z))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_dispatch_indirect(
|
||||
pass_id: id::ComputePassId,
|
||||
indirect_buffer_id: id::BufferId,
|
||||
indirect_offset: core::BufferAddress,
|
||||
) {
|
||||
gfx_select!(pass_id => GLOBAL.compute_pass_dispatch_indirect(pass_id, indirect_buffer_id, indirect_offset))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_set_pipeline(
|
||||
pass_id: id::ComputePassId,
|
||||
pipeline_id: id::ComputePipelineId,
|
||||
) {
|
||||
gfx_select!(pass_id => GLOBAL.compute_pass_set_pipeline(pass_id, pipeline_id))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_command_encoder_compute_pass(
|
||||
self_id: id::CommandEncoderId,
|
||||
pass: &core::command::RawPass,
|
||||
) {
|
||||
let raw_data = pass.to_slice();
|
||||
gfx_select!(self_id => GLOBAL.command_encoder_run_compute_pass(self_id, raw_data));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_command_encoder_render_pass(
|
||||
self_id: id::CommandEncoderId,
|
||||
color_attachments: *const core::command::RenderPassColorAttachmentDescriptor,
|
||||
color_attachment_length: usize,
|
||||
depth_stencil_attachment: Option<&core::command::RenderPassDepthStencilAttachmentDescriptor>,
|
||||
pass: &core::command::RawPass,
|
||||
) {
|
||||
let color_attachments = slice::from_raw_parts(color_attachments, color_attachment_length);
|
||||
let raw_data = pass.to_slice();
|
||||
gfx_select!(self_id => GLOBAL.command_encoder_run_render_pass(self_id, color_attachments, depth_stencil_attachment, raw_data));
|
||||
pub unsafe extern "C" fn wgpu_compute_pass_end_pass(pass_id: core::command::RawComputePassId) {
|
||||
let (pass_data, encoder_id) = Box::from_raw(pass_id).finish_compute();
|
||||
gfx_select!(encoder_id => GLOBAL.command_encoder_run_compute_pass(encoder_id, &pass_data))
|
||||
}
|
||||
|
||||
@@ -116,11 +116,10 @@ pub extern "C" fn wgpu_server_device_create_encoder(
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_server_encoder_destroy(
|
||||
_global: &Global,
|
||||
_self_id: id::CommandEncoderId,
|
||||
global: &Global,
|
||||
self_id: id::CommandEncoderId,
|
||||
) {
|
||||
//TODO
|
||||
//gfx_select!(self_id => global.command_encoder_destroy(self_id));
|
||||
gfx_select!(self_id => global.command_encoder_destroy(self_id));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
Reference in New Issue
Block a user