mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-16 17:02:32 +00:00
Merge #21
21: Use pointers for descriptors r=kvark a=grovesNL (Mostly) fixes #20 I didn't try to handle the remote case yet, but it will need serialization as we mentioned. Co-authored-by: Joshua Groves <josh@joshgroves.com>
This commit is contained in:
commit
bcf51a60c6
@ -27,30 +27,30 @@ int main()
|
||||
WGPUAdapterDescriptor adapter_desc = {
|
||||
.power_preference = WGPUPowerPreference_LowPower,
|
||||
};
|
||||
WGPUAdapterId adapter = wgpu_instance_get_adapter(instance, adapter_desc);
|
||||
WGPUAdapterId adapter = wgpu_instance_get_adapter(instance, &adapter_desc);
|
||||
WGPUDeviceDescriptor device_desc = {
|
||||
.extensions = {
|
||||
.anisotropic_filtering = false,
|
||||
},
|
||||
};
|
||||
WGPUDeviceId device = wgpu_adapter_create_device(adapter, device_desc);
|
||||
WGPUDeviceId device = wgpu_adapter_create_device(adapter, &device_desc);
|
||||
|
||||
WGPUBindGroupLayoutDescriptor bind_group_layout_desc = {
|
||||
.bindings = NULL,
|
||||
.bindings_length = 0,
|
||||
};
|
||||
WGPUBindGroupLayoutId _bind_group_layout = wgpu_device_create_bind_group_layout(device, bind_group_layout_desc);
|
||||
WGPUBindGroupLayoutId _bind_group_layout = wgpu_device_create_bind_group_layout(device, &bind_group_layout_desc);
|
||||
|
||||
WGPUPipelineLayoutDescriptor pipeline_layout_desc = {
|
||||
.bind_group_layouts = NULL,
|
||||
.bind_group_layouts_length = 0,
|
||||
};
|
||||
WGPUPipelineLayoutId layout = wgpu_device_create_pipeline_layout(device, pipeline_layout_desc);
|
||||
WGPUPipelineLayoutId layout = wgpu_device_create_pipeline_layout(device, &pipeline_layout_desc);
|
||||
|
||||
WGPUShaderModuleDescriptor vertex_shader_desc = {
|
||||
.code = read_file("./../data/hello_triangle.vert.spv"),
|
||||
};
|
||||
WGPUShaderModuleId vertex_shader = wgpu_device_create_shader_module(device, vertex_shader_desc);
|
||||
WGPUShaderModuleId vertex_shader = wgpu_device_create_shader_module(device, &vertex_shader_desc);
|
||||
WGPUPipelineStageDescriptor vertex_stage = {
|
||||
.module = vertex_shader,
|
||||
.stage = WGPUShaderStage_Vertex,
|
||||
@ -60,7 +60,7 @@ int main()
|
||||
WGPUShaderModuleDescriptor fragment_shader_desc = {
|
||||
.code = read_file("./../data/hello_triangle.frag.spv"),
|
||||
};
|
||||
WGPUShaderModuleId fragment_shader = wgpu_device_create_shader_module(device, fragment_shader_desc);
|
||||
WGPUShaderModuleId fragment_shader = wgpu_device_create_shader_module(device, &fragment_shader_desc);
|
||||
WGPUPipelineStageDescriptor fragment_stage = {
|
||||
.module = fragment_shader,
|
||||
.stage = WGPUShaderStage_Fragment,
|
||||
@ -85,7 +85,7 @@ int main()
|
||||
.color = blend_color,
|
||||
.write_mask = 0,
|
||||
};
|
||||
WGPUBlendStateId blend_state_0 = wgpu_device_create_blend_state(device, blend_state_0_desc);
|
||||
WGPUBlendStateId blend_state_0 = wgpu_device_create_blend_state(device, &blend_state_0_desc);
|
||||
WGPUBlendStateId blend_state[BLEND_STATE_LENGTH] = { blend_state_0 };
|
||||
|
||||
WGPUStencilStateFaceDescriptor stencil_state_front = {
|
||||
@ -108,14 +108,14 @@ int main()
|
||||
.stencil_read_mask = 0,
|
||||
.stencil_write_mask = 0,
|
||||
};
|
||||
WGPUDepthStencilStateId depth_stencil_state = wgpu_device_create_depth_stencil_state(device, depth_stencil_state_desc);
|
||||
WGPUDepthStencilStateId depth_stencil_state = wgpu_device_create_depth_stencil_state(device, &depth_stencil_state_desc);
|
||||
|
||||
WGPUTextureFormat formats[FORMATS_LENGTH] = { WGPUTextureFormat_R8g8b8a8Unorm };
|
||||
WGPUAttachmentStateDescriptor attachment_state_desc = {
|
||||
.formats = formats,
|
||||
.formats_length = FORMATS_LENGTH,
|
||||
};
|
||||
WGPUAttachmentStateId attachment_state = wgpu_device_create_attachment_state(device, attachment_state_desc);
|
||||
WGPUAttachmentStateId attachment_state = wgpu_device_create_attachment_state(device, &attachment_state_desc);
|
||||
|
||||
WGPURenderPipelineDescriptor render_pipeline_desc = {
|
||||
.layout = layout,
|
||||
@ -128,10 +128,10 @@ int main()
|
||||
.attachment_state = attachment_state,
|
||||
};
|
||||
|
||||
WGPURenderPipelineId render_pipeline = wgpu_device_create_render_pipeline(device, render_pipeline_desc);
|
||||
WGPURenderPipelineId render_pipeline = wgpu_device_create_render_pipeline(device, &render_pipeline_desc);
|
||||
|
||||
WGPUCommandBufferDescriptor cmd_buf_desc = { };
|
||||
WGPUCommandBufferId cmd_buf = wgpu_device_create_command_buffer(device, cmd_buf_desc);
|
||||
WGPUCommandBufferId cmd_buf = wgpu_device_create_command_buffer(device, &cmd_buf_desc);
|
||||
WGPUQueueId queue = wgpu_device_get_queue(device);
|
||||
wgpu_queue_submit(queue, &cmd_buf, 1);
|
||||
|
||||
@ -155,7 +155,7 @@ int main()
|
||||
.usage = texture_usage,
|
||||
};
|
||||
|
||||
WGPUTextureId texture = wgpu_device_create_texture(device, texture_desc);
|
||||
WGPUTextureId texture = wgpu_device_create_texture(device, &texture_desc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
extern crate wgpu;
|
||||
fn main() {
|
||||
let instance = wgpu::Instance::new();
|
||||
let adapter = instance.get_adapter(wgpu::AdapterDescriptor {
|
||||
let adapter = instance.get_adapter(&wgpu::AdapterDescriptor {
|
||||
power_preference: wgpu::PowerPreference::LowPower,
|
||||
});
|
||||
let device = adapter.create_device(wgpu::DeviceDescriptor {
|
||||
let device = adapter.create_device(&wgpu::DeviceDescriptor {
|
||||
extensions: wgpu::Extensions {
|
||||
anisotropic_filtering: false,
|
||||
},
|
||||
@ -15,20 +15,20 @@ fn main() {
|
||||
let fs_bytes = include_bytes!("./../data/hello_triangle.frag.spv");
|
||||
let fs_module = device.create_shader_module(fs_bytes);
|
||||
|
||||
let bind_group_layout = device.create_bind_group_layout(wgpu::BindGroupLayoutDescriptor {
|
||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
bindings: &[],
|
||||
});
|
||||
let pipeline_layout = device.create_pipeline_layout(wgpu::PipelineLayoutDescriptor {
|
||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: &[&bind_group_layout],
|
||||
});
|
||||
|
||||
let blend_state0 = device.create_blend_state(wgpu::BlendStateDescriptor::REPLACE);
|
||||
let depth_stencil_state = device.create_depth_stencil_state(wgpu::DepthStencilStateDescriptor::IGNORE);
|
||||
let attachment_state = device.create_attachment_state(wgpu::AttachmentStateDescriptor {
|
||||
let blend_state0 = device.create_blend_state(&wgpu::BlendStateDescriptor::REPLACE);
|
||||
let depth_stencil_state = device.create_depth_stencil_state(&wgpu::DepthStencilStateDescriptor::IGNORE);
|
||||
let attachment_state = device.create_attachment_state(&wgpu::AttachmentStateDescriptor {
|
||||
formats: &[wgpu::TextureFormat::R8g8b8a8Unorm],
|
||||
});
|
||||
|
||||
let _render_pipeline = device.create_render_pipeline(wgpu::RenderPipelineDescriptor {
|
||||
let _render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
layout: &pipeline_layout,
|
||||
stages: &[
|
||||
wgpu::PipelineStageDescriptor {
|
||||
@ -50,11 +50,11 @@ fn main() {
|
||||
attachment_state: &attachment_state,
|
||||
});
|
||||
|
||||
let mut cmd_buf = device.create_command_buffer(wgpu::CommandBufferDescriptor {});
|
||||
let mut cmd_buf = device.create_command_buffer(&wgpu::CommandBufferDescriptor {});
|
||||
|
||||
{
|
||||
let color_view = unimplemented!(); //TODO!
|
||||
let rpass = cmd_buf.begin_render_pass(wgpu::RenderPassDescriptor {
|
||||
let rpass = cmd_buf.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: &[
|
||||
wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &color_view,
|
||||
|
@ -284,7 +284,8 @@ typedef struct {
|
||||
|
||||
#define WGPUWHITE (Color){ .r = 1, .g = 1, .b = 1, .a = 1 }
|
||||
|
||||
WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id, WGPUDeviceDescriptor _desc);
|
||||
WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id,
|
||||
const WGPUDeviceDescriptor *_desc);
|
||||
|
||||
WGPUComputePassId wgpu_command_buffer_begin_compute_pass(WGPUCommandBufferId command_buffer_id);
|
||||
|
||||
@ -296,34 +297,35 @@ WGPUCommandBufferId wgpu_compute_pass_end_pass(WGPUComputePassId pass_id);
|
||||
WGPUInstanceId wgpu_create_instance(void);
|
||||
|
||||
WGPUAttachmentStateId wgpu_device_create_attachment_state(WGPUDeviceId device_id,
|
||||
WGPUAttachmentStateDescriptor desc);
|
||||
const WGPUAttachmentStateDescriptor *desc);
|
||||
|
||||
WGPUBindGroupLayoutId wgpu_device_create_bind_group_layout(WGPUDeviceId device_id,
|
||||
WGPUBindGroupLayoutDescriptor desc);
|
||||
const WGPUBindGroupLayoutDescriptor *desc);
|
||||
|
||||
WGPUBlendStateId wgpu_device_create_blend_state(WGPUDeviceId _device_id,
|
||||
WGPUBlendStateDescriptor desc);
|
||||
const WGPUBlendStateDescriptor *desc);
|
||||
|
||||
WGPUCommandBufferId wgpu_device_create_command_buffer(WGPUDeviceId device_id,
|
||||
WGPUCommandBufferDescriptor _desc);
|
||||
const WGPUCommandBufferDescriptor *_desc);
|
||||
|
||||
WGPUDepthStencilStateId wgpu_device_create_depth_stencil_state(WGPUDeviceId _device_id,
|
||||
WGPUDepthStencilStateDescriptor desc);
|
||||
const WGPUDepthStencilStateDescriptor *desc);
|
||||
|
||||
WGPUPipelineLayoutId wgpu_device_create_pipeline_layout(WGPUDeviceId device_id,
|
||||
WGPUPipelineLayoutDescriptor desc);
|
||||
const WGPUPipelineLayoutDescriptor *desc);
|
||||
|
||||
WGPURenderPipelineId wgpu_device_create_render_pipeline(WGPUDeviceId device_id,
|
||||
WGPURenderPipelineDescriptor desc);
|
||||
const WGPURenderPipelineDescriptor *desc);
|
||||
|
||||
WGPUShaderModuleId wgpu_device_create_shader_module(WGPUDeviceId device_id,
|
||||
WGPUShaderModuleDescriptor desc);
|
||||
const WGPUShaderModuleDescriptor *desc);
|
||||
|
||||
WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, WGPUTextureDescriptor desc);
|
||||
WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, const WGPUTextureDescriptor *desc);
|
||||
|
||||
WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id);
|
||||
|
||||
WGPUAdapterId wgpu_instance_get_adapter(WGPUInstanceId instance_id, WGPUAdapterDescriptor desc);
|
||||
WGPUAdapterId wgpu_instance_get_adapter(WGPUInstanceId instance_id,
|
||||
const WGPUAdapterDescriptor *desc);
|
||||
|
||||
void wgpu_queue_submit(WGPUQueueId queue_id,
|
||||
const WGPUCommandBufferId *command_buffer_ptr,
|
||||
|
@ -41,7 +41,7 @@ pub(crate) fn map_buffer_usage(
|
||||
}
|
||||
|
||||
pub(crate) fn map_binding_type(
|
||||
binding_ty: &binding_model::BindingType,
|
||||
binding_ty: binding_model::BindingType,
|
||||
) -> hal::pso::DescriptorType {
|
||||
use binding_model::BindingType::*;
|
||||
use hal::pso::DescriptorType as H;
|
||||
@ -88,15 +88,16 @@ pub(crate) fn map_primitive_topology(
|
||||
}
|
||||
|
||||
pub(crate) fn map_blend_state_descriptor(
|
||||
desc: pipeline::BlendStateDescriptor,
|
||||
desc: &pipeline::BlendStateDescriptor,
|
||||
) -> hal::pso::ColorBlendDesc {
|
||||
let color_mask = desc.write_mask;
|
||||
let blend_state = match desc.blend_enabled {
|
||||
true => hal::pso::BlendState::On {
|
||||
color: map_blend_descriptor(desc.color),
|
||||
alpha: map_blend_descriptor(desc.alpha),
|
||||
},
|
||||
false => hal::pso::BlendState::Off,
|
||||
let blend_state = if desc.blend_enabled {
|
||||
hal::pso::BlendState::On {
|
||||
color: map_blend_descriptor(&desc.color),
|
||||
alpha: map_blend_descriptor(&desc.alpha),
|
||||
}
|
||||
} else {
|
||||
hal::pso::BlendState::Off
|
||||
};
|
||||
hal::pso::ColorBlendDesc(map_color_write_flags(color_mask), blend_state)
|
||||
}
|
||||
@ -122,7 +123,7 @@ fn map_color_write_flags(flags: u32) -> hal::pso::ColorMask {
|
||||
value
|
||||
}
|
||||
|
||||
fn map_blend_descriptor(blend_desc: pipeline::BlendDescriptor) -> hal::pso::BlendOp {
|
||||
fn map_blend_descriptor(blend_desc: &pipeline::BlendDescriptor) -> hal::pso::BlendOp {
|
||||
use hal::pso::BlendOp as H;
|
||||
use pipeline::BlendOperation::*;
|
||||
match blend_desc.operation {
|
||||
@ -164,7 +165,7 @@ fn map_blend_factor(blend_factor: pipeline::BlendFactor) -> hal::pso::Factor {
|
||||
}
|
||||
|
||||
pub(crate) fn map_depth_stencil_state(
|
||||
desc: pipeline::DepthStencilStateDescriptor,
|
||||
desc: &pipeline::DepthStencilStateDescriptor,
|
||||
) -> hal::pso::DepthStencilDesc {
|
||||
hal::pso::DepthStencilDesc {
|
||||
// TODO DepthTest::Off?
|
||||
@ -175,14 +176,14 @@ pub(crate) fn map_depth_stencil_state(
|
||||
depth_bounds: false, // TODO
|
||||
// TODO StencilTest::Off?
|
||||
stencil: hal::pso::StencilTest::On {
|
||||
front: map_stencil_face(desc.front, desc.stencil_read_mask, desc.stencil_write_mask),
|
||||
back: map_stencil_face(desc.back, desc.stencil_read_mask, desc.stencil_write_mask),
|
||||
front: map_stencil_face(&desc.front, desc.stencil_read_mask, desc.stencil_write_mask),
|
||||
back: map_stencil_face(&desc.back, desc.stencil_read_mask, desc.stencil_write_mask),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn map_stencil_face(
|
||||
stencil_state_face_desc: pipeline::StencilStateFaceDescriptor,
|
||||
stencil_state_face_desc: &pipeline::StencilStateFaceDescriptor,
|
||||
stencil_read_mask: u32,
|
||||
stencil_write_mask: u32,
|
||||
) -> hal::pso::StencilFace {
|
||||
|
@ -65,7 +65,7 @@ pub(crate) struct ShaderModule<B: hal::Backend> {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_create_texture(
|
||||
device_id: DeviceId,
|
||||
desc: resource::TextureDescriptor,
|
||||
desc: &resource::TextureDescriptor,
|
||||
) -> TextureId {
|
||||
let kind = conv::map_texture_dimension_size(desc.dimension, desc.size);
|
||||
let format = conv::map_texture_format(desc.format);
|
||||
@ -111,7 +111,7 @@ pub extern "C" fn wgpu_device_create_texture(
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_create_bind_group_layout(
|
||||
device_id: DeviceId,
|
||||
desc: binding_model::BindGroupLayoutDescriptor,
|
||||
desc: &binding_model::BindGroupLayoutDescriptor,
|
||||
) -> BindGroupLayoutId {
|
||||
let bindings = unsafe { slice::from_raw_parts(desc.bindings, desc.bindings_length) };
|
||||
|
||||
@ -123,7 +123,7 @@ pub extern "C" fn wgpu_device_create_bind_group_layout(
|
||||
bindings.iter().map(|binding| {
|
||||
hal::pso::DescriptorSetLayoutBinding {
|
||||
binding: binding.binding,
|
||||
ty: conv::map_binding_type(&binding.ty),
|
||||
ty: conv::map_binding_type(binding.ty),
|
||||
count: bindings.len(),
|
||||
stage_flags: conv::map_shader_stage_flags(binding.visibility),
|
||||
immutable_samplers: false, // TODO
|
||||
@ -142,7 +142,7 @@ pub extern "C" fn wgpu_device_create_bind_group_layout(
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_create_pipeline_layout(
|
||||
device_id: DeviceId,
|
||||
desc: binding_model::PipelineLayoutDescriptor,
|
||||
desc: &binding_model::PipelineLayoutDescriptor,
|
||||
) -> PipelineLayoutId {
|
||||
let bind_group_layouts = unsafe {
|
||||
slice::from_raw_parts(desc.bind_group_layouts, desc.bind_group_layouts_length)
|
||||
@ -169,7 +169,7 @@ pub extern "C" fn wgpu_device_create_pipeline_layout(
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_create_blend_state(
|
||||
_device_id: DeviceId,
|
||||
desc: pipeline::BlendStateDescriptor,
|
||||
desc: &pipeline::BlendStateDescriptor,
|
||||
) -> BlendStateId {
|
||||
HUB.blend_states
|
||||
.lock()
|
||||
@ -181,7 +181,7 @@ pub extern "C" fn wgpu_device_create_blend_state(
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_create_depth_stencil_state(
|
||||
_device_id: DeviceId,
|
||||
desc: pipeline::DepthStencilStateDescriptor,
|
||||
desc: &pipeline::DepthStencilStateDescriptor,
|
||||
) -> DepthStencilStateId {
|
||||
HUB.depth_stencil_states
|
||||
.lock()
|
||||
@ -193,7 +193,7 @@ pub extern "C" fn wgpu_device_create_depth_stencil_state(
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_create_shader_module(
|
||||
device_id: DeviceId,
|
||||
desc: pipeline::ShaderModuleDescriptor,
|
||||
desc: &pipeline::ShaderModuleDescriptor,
|
||||
) -> ShaderModuleId {
|
||||
let spv = unsafe {
|
||||
slice::from_raw_parts(desc.code.bytes, desc.code.length)
|
||||
@ -213,7 +213,7 @@ pub extern "C" fn wgpu_device_create_shader_module(
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_create_command_buffer(
|
||||
device_id: DeviceId,
|
||||
_desc: command::CommandBufferDescriptor,
|
||||
_desc: &command::CommandBufferDescriptor,
|
||||
) -> CommandBufferId {
|
||||
let mut device_guard = HUB.devices.lock();
|
||||
let device = device_guard.get_mut(device_id);
|
||||
@ -286,7 +286,7 @@ pub extern "C" fn wgpu_queue_submit(
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_create_attachment_state(
|
||||
device_id: DeviceId,
|
||||
desc: pipeline::AttachmentStateDescriptor,
|
||||
desc: &pipeline::AttachmentStateDescriptor,
|
||||
) -> AttachmentStateId {
|
||||
let device_guard = HUB.devices.lock();
|
||||
let device = &device_guard.get(device_id).raw;
|
||||
@ -339,7 +339,7 @@ pub extern "C" fn wgpu_device_create_attachment_state(
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_create_render_pipeline(
|
||||
device_id: DeviceId,
|
||||
desc: pipeline::RenderPipelineDescriptor,
|
||||
desc: &pipeline::RenderPipelineDescriptor,
|
||||
) -> RenderPipelineId {
|
||||
// TODO
|
||||
let extent = hal::window::Extent2D {
|
||||
|
@ -50,7 +50,7 @@ pub extern "C" fn wgpu_create_instance() -> InstanceId {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_instance_get_adapter(
|
||||
instance_id: InstanceId,
|
||||
desc: AdapterDescriptor,
|
||||
desc: &AdapterDescriptor,
|
||||
) -> AdapterId {
|
||||
let instance_guard = HUB.instances.lock();
|
||||
let instance = instance_guard.get(instance_id);
|
||||
@ -75,7 +75,7 @@ pub extern "C" fn wgpu_instance_get_adapter(
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_adapter_create_device(
|
||||
adapter_id: AdapterId,
|
||||
_desc: DeviceDescriptor,
|
||||
_desc: &DeviceDescriptor,
|
||||
) -> DeviceId {
|
||||
let mut adapter_guard = HUB.adapters.lock();
|
||||
let adapter = adapter_guard.get_mut(adapter_id);
|
||||
|
@ -120,7 +120,7 @@ impl Instance {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_adapter(&self, desc: AdapterDescriptor) -> Adapter {
|
||||
pub fn get_adapter(&self, desc: &AdapterDescriptor) -> Adapter {
|
||||
Adapter {
|
||||
id: wgn::wgpu_instance_get_adapter(self.id, desc),
|
||||
}
|
||||
@ -128,7 +128,7 @@ impl Instance {
|
||||
}
|
||||
|
||||
impl Adapter {
|
||||
pub fn create_device(&self, desc: DeviceDescriptor) -> Device {
|
||||
pub fn create_device(&self, desc: &DeviceDescriptor) -> Device {
|
||||
Device {
|
||||
id: wgn::wgpu_adapter_create_device(self.id, desc),
|
||||
}
|
||||
@ -144,7 +144,7 @@ impl Device {
|
||||
},
|
||||
};
|
||||
ShaderModule {
|
||||
id: wgn::wgpu_device_create_shader_module(self.id, desc),
|
||||
id: wgn::wgpu_device_create_shader_module(self.id, &desc),
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,52 +154,52 @@ impl Device {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_command_buffer(&self, desc: CommandBufferDescriptor) -> CommandBuffer {
|
||||
pub fn create_command_buffer(&self, desc: &CommandBufferDescriptor) -> CommandBuffer {
|
||||
CommandBuffer {
|
||||
id: wgn::wgpu_device_create_command_buffer(self.id, desc),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_bind_group_layout(&self, desc: BindGroupLayoutDescriptor) -> BindGroupLayout {
|
||||
pub fn create_bind_group_layout(&self, desc: &BindGroupLayoutDescriptor) -> BindGroupLayout {
|
||||
BindGroupLayout {
|
||||
id: wgn::wgpu_device_create_bind_group_layout(self.id, wgn::BindGroupLayoutDescriptor {
|
||||
id: wgn::wgpu_device_create_bind_group_layout(self.id, &wgn::BindGroupLayoutDescriptor {
|
||||
bindings: desc.bindings.as_ptr(),
|
||||
bindings_length: desc.bindings.len(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_pipeline_layout(&self, desc: PipelineLayoutDescriptor) -> PipelineLayout {
|
||||
pub fn create_pipeline_layout(&self, desc: &PipelineLayoutDescriptor) -> PipelineLayout {
|
||||
PipelineLayout {
|
||||
id: wgn::wgpu_device_create_pipeline_layout(self.id, wgn::PipelineLayoutDescriptor {
|
||||
id: wgn::wgpu_device_create_pipeline_layout(self.id, &wgn::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: desc.bind_group_layouts.as_ptr() as *const _,
|
||||
bind_group_layouts_length: desc.bind_group_layouts.len(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_blend_state(&self, desc: BlendStateDescriptor) -> BlendState {
|
||||
pub fn create_blend_state(&self, desc: &BlendStateDescriptor) -> BlendState {
|
||||
BlendState {
|
||||
id: wgn::wgpu_device_create_blend_state(self.id, desc),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_depth_stencil_state(&self, desc: DepthStencilStateDescriptor) -> DepthStencilState {
|
||||
pub fn create_depth_stencil_state(&self, desc: &DepthStencilStateDescriptor) -> DepthStencilState {
|
||||
DepthStencilState {
|
||||
id: wgn::wgpu_device_create_depth_stencil_state(self.id, desc),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_attachment_state(&self, desc: AttachmentStateDescriptor) -> AttachmentState {
|
||||
pub fn create_attachment_state(&self, desc: &AttachmentStateDescriptor) -> AttachmentState {
|
||||
AttachmentState {
|
||||
id: wgn::wgpu_device_create_attachment_state(self.id, wgn::AttachmentStateDescriptor {
|
||||
id: wgn::wgpu_device_create_attachment_state(self.id, &wgn::AttachmentStateDescriptor {
|
||||
formats: desc.formats.as_ptr(),
|
||||
formats_length: desc.formats.len(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_render_pipeline(&self, desc: RenderPipelineDescriptor) -> RenderPipeline {
|
||||
pub fn create_render_pipeline(&self, desc: &RenderPipelineDescriptor) -> RenderPipeline {
|
||||
let entry_points = desc.stages
|
||||
.iter()
|
||||
.map(|ps| CString::new(ps.entry_point).unwrap())
|
||||
@ -215,7 +215,7 @@ impl Device {
|
||||
.collect::<ArrayVec<[_; 2]>>();
|
||||
|
||||
RenderPipeline {
|
||||
id: wgn::wgpu_device_create_render_pipeline(self.id, wgn::RenderPipelineDescriptor {
|
||||
id: wgn::wgpu_device_create_render_pipeline(self.id, &wgn::RenderPipelineDescriptor {
|
||||
layout: desc.layout.id,
|
||||
stages: stages.as_ptr(),
|
||||
stages_length: stages.len(),
|
||||
@ -230,7 +230,7 @@ impl Device {
|
||||
}
|
||||
|
||||
impl CommandBuffer {
|
||||
pub fn begin_render_pass(&mut self, desc: RenderPassDescriptor<&TextureView>) -> RenderPass {
|
||||
pub fn begin_render_pass(&mut self, desc: &RenderPassDescriptor<&TextureView>) -> RenderPass {
|
||||
let colors = desc.color_attachments
|
||||
.iter()
|
||||
.map(|ca| RenderPassColorAttachmentDescriptor {
|
||||
@ -242,6 +242,7 @@ impl CommandBuffer {
|
||||
.collect::<ArrayVec<[_; 4]>>();
|
||||
|
||||
let depth_stencil = desc.depth_stencil_attachment
|
||||
.as_ref()
|
||||
.map(|dsa| RenderPassDepthStencilAttachmentDescriptor {
|
||||
attachment: dsa.attachment.id,
|
||||
depth_load_op: dsa.depth_load_op,
|
||||
|
Loading…
Reference in New Issue
Block a user