mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
use rustfmt for formatting after edits
This commit is contained in:
parent
6675a4d3e4
commit
a5a5b88014
@ -28,15 +28,15 @@ fn main() {
|
|||||||
let fs_bytes = include_bytes!("./../data/hello_triangle.frag.spv");
|
let fs_bytes = include_bytes!("./../data/hello_triangle.frag.spv");
|
||||||
let fs_module = device.create_shader_module(fs_bytes);
|
let fs_module = device.create_shader_module(fs_bytes);
|
||||||
|
|
||||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
let bind_group_layout =
|
||||||
bindings: &[],
|
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],
|
bind_group_layouts: &[&bind_group_layout],
|
||||||
});
|
});
|
||||||
|
|
||||||
let blend_state0 = device.create_blend_state(&wgpu::BlendStateDescriptor::REPLACE);
|
let blend_state0 = device.create_blend_state(&wgpu::BlendStateDescriptor::REPLACE);
|
||||||
let depth_stencil_state = device.create_depth_stencil_state(&wgpu::DepthStencilStateDescriptor::IGNORE);
|
let depth_stencil_state =
|
||||||
|
device.create_depth_stencil_state(&wgpu::DepthStencilStateDescriptor::IGNORE);
|
||||||
|
|
||||||
let _render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
let _render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
layout: &pipeline_layout,
|
layout: &pipeline_layout,
|
||||||
@ -54,17 +54,13 @@ fn main() {
|
|||||||
],
|
],
|
||||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||||
attachments_state: wgpu::AttachmentsState {
|
attachments_state: wgpu::AttachmentsState {
|
||||||
color_attachments: &[
|
color_attachments: &[wgpu::Attachment {
|
||||||
wgpu::Attachment {
|
format: wgpu::TextureFormat::R8g8b8a8Unorm,
|
||||||
format: wgpu::TextureFormat::R8g8b8a8Unorm,
|
samples: 1,
|
||||||
samples: 1,
|
}],
|
||||||
},
|
|
||||||
],
|
|
||||||
depth_stencil_attachment: None,
|
depth_stencil_attachment: None,
|
||||||
},
|
},
|
||||||
blend_states: &[
|
blend_states: &[&blend_state0],
|
||||||
&blend_state0,
|
|
||||||
],
|
|
||||||
depth_stencil_state: &depth_stencil_state,
|
depth_stencil_state: &depth_stencil_state,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -72,20 +68,17 @@ fn main() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
let rpass = cmd_buf.begin_render_pass(&wgpu::RenderPassDescriptor {
|
let rpass = cmd_buf.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
color_attachments: &[
|
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||||
wgpu::RenderPassColorAttachmentDescriptor {
|
attachment: &color_view,
|
||||||
attachment: &color_view,
|
load_op: wgpu::LoadOp::Clear,
|
||||||
load_op: wgpu::LoadOp::Clear,
|
store_op: wgpu::StoreOp::Store,
|
||||||
store_op: wgpu::StoreOp::Store,
|
clear_color: wgpu::Color::GREEN,
|
||||||
clear_color: wgpu::Color::GREEN,
|
}],
|
||||||
},
|
|
||||||
],
|
|
||||||
depth_stencil_attachment: None,
|
depth_stencil_attachment: None,
|
||||||
});
|
});
|
||||||
rpass.end_pass();
|
rpass.end_pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let queue = device.get_queue();
|
let queue = device.get_queue();
|
||||||
queue.submit(&[cmd_buf]);
|
queue.submit(&[cmd_buf]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ use hal;
|
|||||||
|
|
||||||
use {BindGroupLayoutId, BufferId, SamplerId, TextureViewId};
|
use {BindGroupLayoutId, BufferId, SamplerId, TextureViewId};
|
||||||
|
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct ShaderStageFlags: u32 {
|
pub struct ShaderStageFlags: u32 {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use super::CommandBuffer;
|
use super::CommandBuffer;
|
||||||
|
use track::Tracker;
|
||||||
use {DeviceId, LifeGuard, Stored};
|
use {DeviceId, LifeGuard, Stored};
|
||||||
use track::{Tracker};
|
|
||||||
|
|
||||||
use hal::command::RawCommandBuffer;
|
use hal::command::RawCommandBuffer;
|
||||||
use hal::pool::RawCommandPool;
|
use hal::pool::RawCommandPool;
|
||||||
@ -37,7 +37,9 @@ impl<B: hal::Backend> Inner<B> {
|
|||||||
fn recycle(&mut self, cmd_buf: CommandBuffer<B>) {
|
fn recycle(&mut self, cmd_buf: CommandBuffer<B>) {
|
||||||
let pool = self.pools.get_mut(&cmd_buf.recorded_thread_id).unwrap();
|
let pool = self.pools.get_mut(&cmd_buf.recorded_thread_id).unwrap();
|
||||||
for mut raw in cmd_buf.raw {
|
for mut raw in cmd_buf.raw {
|
||||||
unsafe { raw.reset(false); }
|
unsafe {
|
||||||
|
raw.reset(false);
|
||||||
|
}
|
||||||
pool.available.push(raw);
|
pool.available.push(raw);
|
||||||
}
|
}
|
||||||
self.fences.push(cmd_buf.fence);
|
self.fences.push(cmd_buf.fence);
|
||||||
@ -62,7 +64,9 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn allocate(
|
pub(crate) fn allocate(
|
||||||
&self, device_id: Stored<DeviceId>, device: &B::Device
|
&self,
|
||||||
|
device_id: Stored<DeviceId>,
|
||||||
|
device: &B::Device,
|
||||||
) -> CommandBuffer<B> {
|
) -> CommandBuffer<B> {
|
||||||
let thread_id = thread::current().id();
|
let thread_id = thread::current().id();
|
||||||
let mut inner = self.inner.lock().unwrap();
|
let mut inner = self.inner.lock().unwrap();
|
||||||
@ -72,16 +76,17 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
|||||||
unsafe { device.reset_fence(&fence).unwrap() };
|
unsafe { device.reset_fence(&fence).unwrap() };
|
||||||
fence
|
fence
|
||||||
}
|
}
|
||||||
None => {
|
None => device.create_fence(false).unwrap(),
|
||||||
device.create_fence(false).unwrap()
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let pool = inner.pools.entry(thread_id).or_insert_with(|| CommandPool {
|
let pool = inner.pools.entry(thread_id).or_insert_with(|| CommandPool {
|
||||||
raw: unsafe { device.create_command_pool(
|
raw: unsafe {
|
||||||
self.queue_family,
|
device.create_command_pool(
|
||||||
hal::pool::CommandPoolCreateFlags::RESET_INDIVIDUAL,
|
self.queue_family,
|
||||||
)}.unwrap(),
|
hal::pool::CommandPoolCreateFlags::RESET_INDIVIDUAL,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.unwrap(),
|
||||||
available: Vec::new(),
|
available: Vec::new(),
|
||||||
});
|
});
|
||||||
let init = pool.allocate();
|
let init = pool.allocate();
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
use registry::{HUB, Items};
|
use registry::{Items, HUB};
|
||||||
use {
|
use {BindGroupId, CommandBufferId, ComputePassId, ComputePipelineId, Stored};
|
||||||
Stored,
|
|
||||||
BindGroupId, CommandBufferId, ComputePassId, ComputePipelineId,
|
|
||||||
};
|
|
||||||
|
|
||||||
use hal;
|
use hal;
|
||||||
use hal::command::RawCommandBuffer;
|
use hal::command::RawCommandBuffer;
|
||||||
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
|
|
||||||
pub struct ComputePass<B: hal::Backend> {
|
pub struct ComputePass<B: hal::Backend> {
|
||||||
raw: B::CommandBuffer,
|
raw: B::CommandBuffer,
|
||||||
cmb_id: Stored<CommandBufferId>,
|
cmb_id: Stored<CommandBufferId>,
|
||||||
@ -17,20 +13,13 @@ pub struct ComputePass<B: hal::Backend> {
|
|||||||
|
|
||||||
impl<B: hal::Backend> ComputePass<B> {
|
impl<B: hal::Backend> ComputePass<B> {
|
||||||
pub(crate) fn new(raw: B::CommandBuffer, cmb_id: Stored<CommandBufferId>) -> Self {
|
pub(crate) fn new(raw: B::CommandBuffer, cmb_id: Stored<CommandBufferId>) -> Self {
|
||||||
ComputePass {
|
ComputePass { raw, cmb_id }
|
||||||
raw,
|
|
||||||
cmb_id,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_compute_pass_end_pass(
|
pub extern "C" fn wgpu_compute_pass_end_pass(pass_id: ComputePassId) -> CommandBufferId {
|
||||||
pass_id: ComputePassId,
|
let pass = HUB.compute_passes.write().take(pass_id);
|
||||||
) -> CommandBufferId {
|
|
||||||
let pass = HUB.compute_passes
|
|
||||||
.write()
|
|
||||||
.take(pass_id);
|
|
||||||
|
|
||||||
HUB.command_buffers
|
HUB.command_buffers
|
||||||
.write()
|
.write()
|
||||||
@ -42,7 +31,9 @@ pub extern "C" fn wgpu_compute_pass_end_pass(
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_compute_pass_set_bind_group(
|
pub extern "C" fn wgpu_compute_pass_set_bind_group(
|
||||||
pass_id: ComputePassId, index: u32, bind_group_id: BindGroupId,
|
pass_id: ComputePassId,
|
||||||
|
index: u32,
|
||||||
|
bind_group_id: BindGroupId,
|
||||||
) {
|
) {
|
||||||
let bind_group_guard = HUB.bind_groups.read();
|
let bind_group_guard = HUB.bind_groups.read();
|
||||||
let set = &bind_group_guard.get(bind_group_id).raw;
|
let set = &bind_group_guard.get(bind_group_id).raw;
|
||||||
@ -60,11 +51,12 @@ pub extern "C" fn wgpu_compute_pass_set_bind_group(
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_compute_pass_set_pipeline(
|
pub extern "C" fn wgpu_compute_pass_set_pipeline(
|
||||||
pass_id: ComputePassId, pipeline_id: ComputePipelineId,
|
pass_id: ComputePassId,
|
||||||
|
pipeline_id: ComputePipelineId,
|
||||||
) {
|
) {
|
||||||
let pipeline_guard = HUB.compute_pipelines.read();
|
let pipeline_guard = HUB.compute_pipelines.read();
|
||||||
let pipeline = &pipeline_guard.get(pipeline_id).raw;
|
let pipeline = &pipeline_guard.get(pipeline_id).raw;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
HUB.compute_passes
|
HUB.compute_passes
|
||||||
.write()
|
.write()
|
||||||
@ -75,9 +67,7 @@ pub extern "C" fn wgpu_compute_pass_set_pipeline(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_compute_pass_dispatch(
|
pub extern "C" fn wgpu_compute_pass_dispatch(pass_id: ComputePassId, x: u32, y: u32, z: u32) {
|
||||||
pass_id: ComputePassId, x: u32, y: u32, z: u32,
|
|
||||||
) {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
HUB.compute_passes
|
HUB.compute_passes
|
||||||
.write()
|
.write()
|
||||||
|
|||||||
@ -6,23 +6,22 @@ pub(crate) use self::allocator::CommandAllocator;
|
|||||||
pub use self::compute::*;
|
pub use self::compute::*;
|
||||||
pub use self::render::*;
|
pub use self::render::*;
|
||||||
|
|
||||||
use hal::{self, Device};
|
|
||||||
use hal::command::RawCommandBuffer;
|
use hal::command::RawCommandBuffer;
|
||||||
|
use hal::{self, Device};
|
||||||
|
|
||||||
use {
|
|
||||||
B, Color, LifeGuard, Origin3d, Stored, BufferUsageFlags, TextureUsageFlags, WeaklyStored,
|
|
||||||
BufferId, CommandBufferId, ComputePassId, DeviceId, RenderPassId, TextureId, TextureViewId,
|
|
||||||
};
|
|
||||||
use {conv, resource};
|
|
||||||
use device::{FramebufferKey, RenderPassKey};
|
use device::{FramebufferKey, RenderPassKey};
|
||||||
use registry::{HUB, Items};
|
use registry::{Items, HUB};
|
||||||
use track::{BufferTracker, TextureTracker};
|
use track::{BufferTracker, TextureTracker};
|
||||||
|
use {conv, resource};
|
||||||
|
use {
|
||||||
|
BufferId, BufferUsageFlags, Color, CommandBufferId, ComputePassId, DeviceId, LifeGuard,
|
||||||
|
Origin3d, RenderPassId, Stored, TextureId, TextureUsageFlags, TextureViewId, WeaklyStored, B,
|
||||||
|
};
|
||||||
|
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::thread::ThreadId;
|
use std::thread::ThreadId;
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
pub enum LoadOp {
|
pub enum LoadOp {
|
||||||
@ -105,10 +104,12 @@ impl CommandBuffer<B> {
|
|||||||
let b = buffer_guard.get(id);
|
let b = buffer_guard.get(id);
|
||||||
trace!("transit {:?} {:?}", id, transit);
|
trace!("transit {:?} {:?}", id, transit);
|
||||||
hal::memory::Barrier::Buffer {
|
hal::memory::Barrier::Buffer {
|
||||||
states: conv::map_buffer_state(transit.start) ..
|
states: conv::map_buffer_state(transit.start)..conv::map_buffer_state(transit.end),
|
||||||
conv::map_buffer_state(transit.end),
|
|
||||||
target: &b.raw,
|
target: &b.raw,
|
||||||
range: Range { start: None, end: None},
|
range: Range {
|
||||||
|
start: None,
|
||||||
|
end: None,
|
||||||
|
},
|
||||||
families: None,
|
families: None,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -117,8 +118,8 @@ impl CommandBuffer<B> {
|
|||||||
trace!("transit {:?} {:?}", id, transit);
|
trace!("transit {:?} {:?}", id, transit);
|
||||||
let aspects = t.full_range.aspects;
|
let aspects = t.full_range.aspects;
|
||||||
hal::memory::Barrier::Image {
|
hal::memory::Barrier::Image {
|
||||||
states: conv::map_texture_state(transit.start, aspects) ..
|
states: conv::map_texture_state(transit.start, aspects)
|
||||||
conv::map_texture_state(transit.end, aspects),
|
..conv::map_texture_state(transit.end, aspects),
|
||||||
target: &t.raw,
|
target: &t.raw,
|
||||||
range: t.full_range.clone(), //TODO?
|
range: t.full_range.clone(), //TODO?
|
||||||
families: None,
|
families: None,
|
||||||
@ -126,7 +127,7 @@ impl CommandBuffer<B> {
|
|||||||
});
|
});
|
||||||
unsafe {
|
unsafe {
|
||||||
raw.pipeline_barrier(
|
raw.pipeline_barrier(
|
||||||
hal::pso::PipelineStage::TOP_OF_PIPE .. hal::pso::PipelineStage::BOTTOM_OF_PIPE,
|
hal::pso::PipelineStage::TOP_OF_PIPE..hal::pso::PipelineStage::BOTTOM_OF_PIPE,
|
||||||
hal::memory::Dependencies::empty(),
|
hal::memory::Dependencies::empty(),
|
||||||
buffer_barriers.chain(texture_barriers),
|
buffer_barriers.chain(texture_barriers),
|
||||||
);
|
);
|
||||||
@ -178,31 +179,29 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
|||||||
samples: view.samples,
|
samples: view.samples,
|
||||||
ops: conv::map_load_store_ops(at.depth_load_op, at.depth_store_op),
|
ops: conv::map_load_store_ops(at.depth_load_op, at.depth_store_op),
|
||||||
stencil_ops: conv::map_load_store_ops(at.stencil_load_op, at.stencil_store_op),
|
stencil_ops: conv::map_load_store_ops(at.stencil_load_op, at.stencil_store_op),
|
||||||
layouts: layout .. layout,
|
layouts: layout..layout,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let color_keys = desc.color_attachments
|
let color_keys = desc.color_attachments.iter().map(|at| {
|
||||||
.iter()
|
let view = view_guard.get(at.attachment);
|
||||||
.map(|at| {
|
if let Some(ex) = extent {
|
||||||
let view = view_guard.get(at.attachment);
|
assert_eq!(ex, view.extent);
|
||||||
if let Some(ex) = extent {
|
} else {
|
||||||
assert_eq!(ex, view.extent);
|
extent = Some(view.extent);
|
||||||
} else {
|
}
|
||||||
extent = Some(view.extent);
|
let query = tracker.query(&view.texture_id, TextureUsageFlags::empty());
|
||||||
}
|
let (_, layout) = conv::map_texture_state(query.usage, hal::format::Aspects::COLOR);
|
||||||
let query = tracker.query(&view.texture_id, TextureUsageFlags::empty());
|
hal::pass::Attachment {
|
||||||
let (_, layout) = conv::map_texture_state(query.usage, hal::format::Aspects::COLOR);
|
format: Some(conv::map_texture_format(view.format)),
|
||||||
hal::pass::Attachment {
|
samples: view.samples,
|
||||||
format: Some(conv::map_texture_format(view.format)),
|
ops: conv::map_load_store_ops(at.load_op, at.store_op),
|
||||||
samples: view.samples,
|
stencil_ops: hal::pass::AttachmentOps::DONT_CARE,
|
||||||
ops: conv::map_load_store_ops(at.load_op, at.store_op),
|
layouts: layout..layout,
|
||||||
stencil_ops: hal::pass::AttachmentOps::DONT_CARE,
|
}
|
||||||
layouts: layout .. layout,
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
RenderPassKey {
|
RenderPassKey {
|
||||||
attachments: color_keys.chain(depth_stencil_key).collect(),
|
attachments: color_keys.chain(depth_stencil_key).collect(),
|
||||||
@ -219,31 +218,40 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
|||||||
(2, hal::image::Layout::ColorAttachmentOptimal),
|
(2, hal::image::Layout::ColorAttachmentOptimal),
|
||||||
(3, hal::image::Layout::ColorAttachmentOptimal),
|
(3, hal::image::Layout::ColorAttachmentOptimal),
|
||||||
];
|
];
|
||||||
let depth_id = (desc.color_attachments.len(), hal::image::Layout::DepthStencilAttachmentOptimal);
|
let depth_id = (
|
||||||
|
desc.color_attachments.len(),
|
||||||
|
hal::image::Layout::DepthStencilAttachmentOptimal,
|
||||||
|
);
|
||||||
|
|
||||||
let subpass = hal::pass::SubpassDesc {
|
let subpass = hal::pass::SubpassDesc {
|
||||||
colors: &color_ids[.. desc.color_attachments.len()],
|
colors: &color_ids[..desc.color_attachments.len()],
|
||||||
depth_stencil: desc.depth_stencil_attachment.as_ref().map(|_| &depth_id),
|
depth_stencil: desc.depth_stencil_attachment.as_ref().map(|_| &depth_id),
|
||||||
inputs: &[],
|
inputs: &[],
|
||||||
resolves: &[],
|
resolves: &[],
|
||||||
preserves: &[],
|
preserves: &[],
|
||||||
};
|
};
|
||||||
|
|
||||||
let pass = unsafe { device.raw.create_render_pass(
|
let pass = unsafe {
|
||||||
&e.key().attachments,
|
device
|
||||||
&[subpass],
|
.raw
|
||||||
&[],
|
.create_render_pass(&e.key().attachments, &[subpass], &[])
|
||||||
)}.unwrap();
|
}
|
||||||
|
.unwrap();
|
||||||
e.insert(pass)
|
e.insert(pass)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut framebuffer_cache = device.framebuffers.lock();
|
let mut framebuffer_cache = device.framebuffers.lock();
|
||||||
let fb_key = FramebufferKey {
|
let fb_key = FramebufferKey {
|
||||||
attachments: desc.color_attachments
|
attachments: desc
|
||||||
|
.color_attachments
|
||||||
.iter()
|
.iter()
|
||||||
.map(|at| WeaklyStored(at.attachment))
|
.map(|at| WeaklyStored(at.attachment))
|
||||||
.chain(desc.depth_stencil_attachment.as_ref().map(|at| WeaklyStored(at.attachment)))
|
.chain(
|
||||||
|
desc.depth_stencil_attachment
|
||||||
|
.as_ref()
|
||||||
|
.map(|at| WeaklyStored(at.attachment)),
|
||||||
|
)
|
||||||
.collect(),
|
.collect(),
|
||||||
};
|
};
|
||||||
let framebuffer = match framebuffer_cache.entry(fb_key) {
|
let framebuffer = match framebuffer_cache.entry(fb_key) {
|
||||||
@ -256,9 +264,12 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|&WeaklyStored(id)| &view_guard.get(id).raw);
|
.map(|&WeaklyStored(id)| &view_guard.get(id).raw);
|
||||||
|
|
||||||
unsafe { device.raw
|
unsafe {
|
||||||
.create_framebuffer(&render_pass, attachments, extent.unwrap())
|
device
|
||||||
}.unwrap()
|
.raw
|
||||||
|
.create_framebuffer(&render_pass, attachments, extent.unwrap())
|
||||||
|
}
|
||||||
|
.unwrap()
|
||||||
};
|
};
|
||||||
e.insert(fb)
|
e.insert(fb)
|
||||||
}
|
}
|
||||||
@ -273,7 +284,8 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
|||||||
h: ex.height as _,
|
h: ex.height as _,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let clear_values = desc.color_attachments
|
let clear_values = desc
|
||||||
|
.color_attachments
|
||||||
.iter()
|
.iter()
|
||||||
.map(|at| {
|
.map(|at| {
|
||||||
//TODO: integer types?
|
//TODO: integer types?
|
||||||
@ -284,7 +296,7 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
|||||||
let value = hal::command::ClearDepthStencil(at.clear_depth, at.clear_stencil);
|
let value = hal::command::ClearDepthStencil(at.clear_depth, at.clear_stencil);
|
||||||
hal::command::ClearValueRaw::from(hal::command::ClearValue::DepthStencil(value))
|
hal::command::ClearValueRaw::from(hal::command::ClearValue::DepthStencil(value))
|
||||||
}));
|
}));
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
current_comb.begin_render_pass(
|
current_comb.begin_render_pass(
|
||||||
render_pass,
|
render_pass,
|
||||||
@ -295,15 +307,13 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
HUB.render_passes
|
HUB.render_passes.write().register(RenderPass::new(
|
||||||
.write()
|
current_comb,
|
||||||
.register(RenderPass::new(
|
Stored {
|
||||||
current_comb,
|
value: command_buffer_id,
|
||||||
Stored {
|
ref_count: cmb.life_guard.ref_count.clone(),
|
||||||
value: command_buffer_id,
|
},
|
||||||
ref_count: cmb.life_guard.ref_count.clone(),
|
))
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|||||||
@ -1,14 +1,10 @@
|
|||||||
use registry::{HUB, Items};
|
use registry::{Items, HUB};
|
||||||
use track::{BufferTracker, TextureTracker};
|
use track::{BufferTracker, TextureTracker};
|
||||||
use {
|
use {CommandBuffer, CommandBufferId, RenderPassId, Stored};
|
||||||
CommandBuffer, Stored,
|
|
||||||
CommandBufferId, RenderPassId,
|
|
||||||
};
|
|
||||||
|
|
||||||
use hal;
|
use hal;
|
||||||
use hal::command::RawCommandBuffer;
|
use hal::command::RawCommandBuffer;
|
||||||
|
|
||||||
|
|
||||||
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>,
|
||||||
@ -17,10 +13,7 @@ pub struct RenderPass<B: hal::Backend> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<B: hal::Backend> RenderPass<B> {
|
impl<B: hal::Backend> RenderPass<B> {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(raw: B::CommandBuffer, cmb_id: Stored<CommandBufferId>) -> Self {
|
||||||
raw: B::CommandBuffer,
|
|
||||||
cmb_id: Stored<CommandBufferId>,
|
|
||||||
) -> Self {
|
|
||||||
RenderPass {
|
RenderPass {
|
||||||
raw,
|
raw,
|
||||||
cmb_id,
|
cmb_id,
|
||||||
@ -31,13 +24,11 @@ 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(pass_id: RenderPassId) -> CommandBufferId {
|
||||||
pass_id: RenderPassId,
|
let mut pass = HUB.render_passes.write().take(pass_id);
|
||||||
) -> CommandBufferId {
|
unsafe {
|
||||||
let mut pass = HUB.render_passes
|
pass.raw.end_render_pass();
|
||||||
.write()
|
}
|
||||||
.take(pass_id);
|
|
||||||
unsafe {pass.raw.end_render_pass(); }
|
|
||||||
|
|
||||||
let mut cmb_guard = HUB.command_buffers.write();
|
let mut cmb_guard = HUB.command_buffers.write();
|
||||||
let cmb = cmb_guard.get_mut(pass.cmb_id.value);
|
let cmb = cmb_guard.get_mut(pass.cmb_id.value);
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
use hal;
|
use hal;
|
||||||
|
|
||||||
use {Color, Extent3d, binding_model, command, pipeline, resource};
|
use {binding_model, command, pipeline, resource, Color, Extent3d};
|
||||||
|
|
||||||
|
|
||||||
pub fn map_buffer_usage(
|
pub fn map_buffer_usage(
|
||||||
usage: resource::BufferUsageFlags,
|
usage: resource::BufferUsageFlags,
|
||||||
@ -42,7 +41,8 @@ pub fn map_buffer_usage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_texture_usage(
|
pub fn map_texture_usage(
|
||||||
usage: resource::TextureUsageFlags, aspects: hal::format::Aspects
|
usage: resource::TextureUsageFlags,
|
||||||
|
aspects: hal::format::Aspects,
|
||||||
) -> hal::image::Usage {
|
) -> hal::image::Usage {
|
||||||
use hal::image::Usage as U;
|
use hal::image::Usage as U;
|
||||||
use resource::TextureUsageFlags as W;
|
use resource::TextureUsageFlags as W;
|
||||||
@ -72,9 +72,7 @@ pub fn map_texture_usage(
|
|||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_binding_type(
|
pub fn map_binding_type(binding_ty: binding_model::BindingType) -> hal::pso::DescriptorType {
|
||||||
binding_ty: binding_model::BindingType,
|
|
||||||
) -> hal::pso::DescriptorType {
|
|
||||||
use binding_model::BindingType::*;
|
use binding_model::BindingType::*;
|
||||||
use hal::pso::DescriptorType as H;
|
use hal::pso::DescriptorType as H;
|
||||||
match binding_ty {
|
match binding_ty {
|
||||||
@ -104,9 +102,7 @@ pub fn map_shader_stage_flags(
|
|||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_primitive_topology(
|
pub fn map_primitive_topology(primitive_topology: pipeline::PrimitiveTopology) -> hal::Primitive {
|
||||||
primitive_topology: pipeline::PrimitiveTopology,
|
|
||||||
) -> hal::Primitive {
|
|
||||||
use hal::Primitive as H;
|
use hal::Primitive as H;
|
||||||
use pipeline::PrimitiveTopology::*;
|
use pipeline::PrimitiveTopology::*;
|
||||||
match primitive_topology {
|
match primitive_topology {
|
||||||
@ -134,8 +130,8 @@ pub fn map_blend_state_descriptor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn map_color_write_flags(flags: pipeline::ColorWriteFlags) -> hal::pso::ColorMask {
|
fn map_color_write_flags(flags: pipeline::ColorWriteFlags) -> hal::pso::ColorMask {
|
||||||
use pipeline::ColorWriteFlags as F;
|
|
||||||
use hal::pso::ColorMask as H;
|
use hal::pso::ColorMask as H;
|
||||||
|
use pipeline::ColorWriteFlags as F;
|
||||||
|
|
||||||
let mut value = H::empty();
|
let mut value = H::empty();
|
||||||
if flags.contains(F::RED) {
|
if flags.contains(F::RED) {
|
||||||
@ -276,7 +272,11 @@ fn checked_u32_as_u16(value: u32) -> u16 {
|
|||||||
|
|
||||||
pub fn map_texture_dimension_size(
|
pub fn map_texture_dimension_size(
|
||||||
dimension: resource::TextureDimension,
|
dimension: resource::TextureDimension,
|
||||||
Extent3d { width, height, depth }: Extent3d,
|
Extent3d {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
depth,
|
||||||
|
}: Extent3d,
|
||||||
) -> hal::image::Kind {
|
) -> hal::image::Kind {
|
||||||
use hal::image::Kind as H;
|
use hal::image::Kind as H;
|
||||||
use resource::TextureDimension::*;
|
use resource::TextureDimension::*;
|
||||||
@ -305,11 +305,9 @@ pub fn map_texture_view_dimension(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_texture_aspect_flags(
|
pub fn map_texture_aspect_flags(aspect: resource::TextureAspectFlags) -> hal::format::Aspects {
|
||||||
aspect: resource::TextureAspectFlags
|
|
||||||
) -> hal::format::Aspects {
|
|
||||||
use resource::TextureAspectFlags as Taf;
|
|
||||||
use hal::format::Aspects;
|
use hal::format::Aspects;
|
||||||
|
use resource::TextureAspectFlags as Taf;
|
||||||
|
|
||||||
let mut flags = Aspects::empty();
|
let mut flags = Aspects::empty();
|
||||||
if aspect.contains(Taf::COLOR) {
|
if aspect.contains(Taf::COLOR) {
|
||||||
@ -324,9 +322,7 @@ pub fn map_texture_aspect_flags(
|
|||||||
flags
|
flags
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_buffer_state(
|
pub fn map_buffer_state(usage: resource::BufferUsageFlags) -> hal::buffer::State {
|
||||||
usage: resource::BufferUsageFlags,
|
|
||||||
) -> hal::buffer::State {
|
|
||||||
use hal::buffer::Access as A;
|
use hal::buffer::Access as A;
|
||||||
use resource::BufferUsageFlags as W;
|
use resource::BufferUsageFlags as W;
|
||||||
|
|
||||||
@ -386,13 +382,20 @@ pub fn map_texture_state(
|
|||||||
}
|
}
|
||||||
if usage.contains(W::OUTPUT_ATTACHMENT) {
|
if usage.contains(W::OUTPUT_ATTACHMENT) {
|
||||||
//TODO: read-only attachments
|
//TODO: read-only attachments
|
||||||
access |= if is_color { A::COLOR_ATTACHMENT_WRITE } else { A::DEPTH_STENCIL_ATTACHMENT_WRITE };
|
access |= if is_color {
|
||||||
|
A::COLOR_ATTACHMENT_WRITE
|
||||||
|
} else {
|
||||||
|
A::DEPTH_STENCIL_ATTACHMENT_WRITE
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
(access, layout)
|
(access, layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_load_store_ops(load: command::LoadOp, store: command::StoreOp) -> hal::pass::AttachmentOps {
|
pub fn map_load_store_ops(
|
||||||
|
load: command::LoadOp,
|
||||||
|
store: command::StoreOp,
|
||||||
|
) -> hal::pass::AttachmentOps {
|
||||||
hal::pass::AttachmentOps {
|
hal::pass::AttachmentOps {
|
||||||
load: match load {
|
load: match load {
|
||||||
command::LoadOp::Clear => hal::pass::AttachmentLoadOp::Clear,
|
command::LoadOp::Clear => hal::pass::AttachmentLoadOp::Clear,
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
use {back, binding_model, command, conv, pipeline, resource};
|
use registry::{Items, HUB};
|
||||||
use registry::{HUB, Items};
|
|
||||||
use track::{BufferTracker, TextureTracker};
|
use track::{BufferTracker, TextureTracker};
|
||||||
|
use {back, binding_model, command, conv, pipeline, resource};
|
||||||
use {
|
use {
|
||||||
CommandBuffer, LifeGuard, RefCount, Stored, SubmissionIndex, WeaklyStored,
|
BindGroupLayoutId, BlendStateId, BufferId, CommandBuffer, CommandBufferId, DepthStencilStateId,
|
||||||
TextureUsageFlags,
|
DeviceId, LifeGuard, PipelineLayoutId, QueueId, RefCount, RenderPipelineId, ShaderModuleId,
|
||||||
BindGroupLayoutId, BlendStateId, BufferId, CommandBufferId, DepthStencilStateId,
|
Stored, SubmissionIndex, TextureId, TextureUsageFlags, TextureViewId, WeaklyStored,
|
||||||
DeviceId, PipelineLayoutId, QueueId, RenderPipelineId, ShaderModuleId,
|
|
||||||
TextureId, TextureViewId,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use hal::command::RawCommandBuffer;
|
use hal::command::RawCommandBuffer;
|
||||||
@ -14,13 +12,12 @@ use hal::queue::RawCommandQueue;
|
|||||||
use hal::{self, Device as _Device};
|
use hal::{self, Device as _Device};
|
||||||
//use rendy_memory::{allocator, Config, Heaps};
|
//use rendy_memory::{allocator, Config, Heaps};
|
||||||
|
|
||||||
use std::{ffi, slice};
|
|
||||||
use std::collections::hash_map::{Entry, HashMap};
|
use std::collections::hash_map::{Entry, HashMap};
|
||||||
|
use std::{ffi, slice};
|
||||||
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Hash, PartialEq)]
|
#[derive(Hash, PartialEq)]
|
||||||
pub(crate) struct RenderPassKey {
|
pub(crate) struct RenderPassKey {
|
||||||
pub attachments: Vec<hal::pass::Attachment>,
|
pub attachments: Vec<hal::pass::Attachment>,
|
||||||
@ -66,16 +63,16 @@ unsafe impl<B: hal::Backend> Sync for DestroyedResources<B> {}
|
|||||||
|
|
||||||
impl<B: hal::Backend> DestroyedResources<B> {
|
impl<B: hal::Backend> DestroyedResources<B> {
|
||||||
fn add(&mut self, resource_id: ResourceId, life_guard: &LifeGuard) {
|
fn add(&mut self, resource_id: ResourceId, life_guard: &LifeGuard) {
|
||||||
self.referenced.push((resource_id, life_guard.ref_count.clone()));
|
self.referenced
|
||||||
|
.push((resource_id, life_guard.ref_count.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn triage_referenced<Gb, Gt>(
|
fn triage_referenced<Gb, Gt>(&mut self, buffer_guard: &mut Gb, texture_guard: &mut Gt)
|
||||||
&mut self, buffer_guard: &mut Gb, texture_guard: &mut Gt,
|
where
|
||||||
) where
|
|
||||||
Gb: Items<resource::Buffer<B>>,
|
Gb: Items<resource::Buffer<B>>,
|
||||||
Gt: Items<resource::Texture<B>>,
|
Gt: Items<resource::Texture<B>>,
|
||||||
{
|
{
|
||||||
for i in (0 .. self.referenced.len()).rev() {
|
for i in (0..self.referenced.len()).rev() {
|
||||||
// one in resource itself, and one here in this list
|
// one in resource itself, and one here in this list
|
||||||
let num_refs = self.referenced[i].1.load();
|
let num_refs = self.referenced[i].1.load();
|
||||||
if num_refs <= 2 {
|
if num_refs <= 2 {
|
||||||
@ -93,7 +90,8 @@ impl<B: hal::Backend> DestroyedResources<B> {
|
|||||||
(si, Resource::Texture(tex))
|
(si, Resource::Texture(tex))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match self.active
|
match self
|
||||||
|
.active
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.find(|af| af.submission_index == submit_index)
|
.find(|af| af.submission_index == submit_index)
|
||||||
{
|
{
|
||||||
@ -105,7 +103,7 @@ impl<B: hal::Backend> DestroyedResources<B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn cleanup(&mut self, raw: &B::Device) {
|
fn cleanup(&mut self, raw: &B::Device) {
|
||||||
for i in (0 .. self.active.len()).rev() {
|
for i in (0..self.active.len()).rev() {
|
||||||
if unsafe { raw.get_fence_status(&self.active[i].fence) }.unwrap() {
|
if unsafe { raw.get_fence_status(&self.active[i].fence) }.unwrap() {
|
||||||
let af = self.active.swap_remove(i);
|
let af = self.active.swap_remove(i);
|
||||||
self.free.extend(af.resources);
|
self.free.extend(af.resources);
|
||||||
@ -193,7 +191,6 @@ pub(crate) struct ShaderModule<B: hal::Backend> {
|
|||||||
pub raw: B::ShaderModule,
|
pub raw: B::ShaderModule,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_device_create_texture(
|
pub extern "C" fn wgpu_device_create_texture(
|
||||||
device_id: DeviceId,
|
device_id: DeviceId,
|
||||||
@ -205,9 +202,8 @@ pub extern "C" fn wgpu_device_create_texture(
|
|||||||
let usage = conv::map_texture_usage(desc.usage, aspects);
|
let usage = conv::map_texture_usage(desc.usage, aspects);
|
||||||
let device_guard = HUB.devices.read();
|
let device_guard = HUB.devices.read();
|
||||||
let device = &device_guard.get(device_id);
|
let device = &device_guard.get(device_id);
|
||||||
let mut image_unbound = unsafe { device
|
let mut image_unbound = unsafe {
|
||||||
.raw
|
device.raw.create_image(
|
||||||
.create_image(
|
|
||||||
kind,
|
kind,
|
||||||
1, // TODO: mips
|
1, // TODO: mips
|
||||||
format,
|
format,
|
||||||
@ -215,57 +211,59 @@ pub extern "C" fn wgpu_device_create_texture(
|
|||||||
usage,
|
usage,
|
||||||
hal::image::ViewCapabilities::empty(), // TODO: format, 2d array, cube
|
hal::image::ViewCapabilities::empty(), // TODO: format, 2d array, cube
|
||||||
)
|
)
|
||||||
}.unwrap();
|
}
|
||||||
|
.unwrap();
|
||||||
let image_req = unsafe { device.raw.get_image_requirements(&image_unbound) };
|
let image_req = unsafe { device.raw.get_image_requirements(&image_unbound) };
|
||||||
let device_type = device
|
let device_type = device
|
||||||
.mem_props
|
.mem_props
|
||||||
.memory_types
|
.memory_types
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.position(|(id, memory_type)| { // TODO
|
.position(|(id, memory_type)| {
|
||||||
|
// TODO
|
||||||
image_req.type_mask & (1 << id) != 0
|
image_req.type_mask & (1 << id) != 0
|
||||||
&& memory_type.properties.contains(hal::memory::Properties::DEVICE_LOCAL)
|
&& memory_type
|
||||||
|
.properties
|
||||||
|
.contains(hal::memory::Properties::DEVICE_LOCAL)
|
||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into();
|
.into();
|
||||||
// TODO: allocate with rendy
|
// TODO: allocate with rendy
|
||||||
let image_memory = unsafe{
|
let image_memory = unsafe { device.raw.allocate_memory(device_type, image_req.size) }.unwrap();
|
||||||
device.raw.allocate_memory(device_type, image_req.size)
|
|
||||||
}.unwrap();
|
|
||||||
unsafe {
|
unsafe {
|
||||||
device
|
device
|
||||||
.raw
|
.raw
|
||||||
.bind_image_memory(&image_memory, 0, &mut image_unbound)
|
.bind_image_memory(&image_memory, 0, &mut image_unbound)
|
||||||
}.unwrap();
|
}
|
||||||
|
.unwrap();
|
||||||
let bound_image = image_unbound; //TODO: Maybe call this image the same way in the first place
|
let bound_image = image_unbound; //TODO: Maybe call this image the same way in the first place
|
||||||
|
|
||||||
let full_range = hal::image::SubresourceRange {
|
let full_range = hal::image::SubresourceRange {
|
||||||
aspects,
|
aspects,
|
||||||
levels: 0 .. 1, //TODO: mips
|
levels: 0..1, //TODO: mips
|
||||||
layers: 0 .. 1, //TODO
|
layers: 0..1, //TODO
|
||||||
};
|
};
|
||||||
|
|
||||||
let life_guard = LifeGuard::new();
|
let life_guard = LifeGuard::new();
|
||||||
let ref_count = life_guard.ref_count.clone();
|
let ref_count = life_guard.ref_count.clone();
|
||||||
let id = HUB.textures
|
let id = HUB.textures.write().register(resource::Texture {
|
||||||
.write()
|
raw: bound_image,
|
||||||
.register(resource::Texture {
|
device_id: Stored {
|
||||||
raw: bound_image,
|
value: device_id,
|
||||||
device_id: Stored {
|
ref_count: device.life_guard.ref_count.clone(),
|
||||||
value: device_id,
|
},
|
||||||
ref_count: device.life_guard.ref_count.clone(),
|
kind,
|
||||||
},
|
format: desc.format,
|
||||||
kind,
|
full_range,
|
||||||
format: desc.format,
|
life_guard,
|
||||||
full_range,
|
});
|
||||||
life_guard,
|
let query = device.texture_tracker.lock().query(
|
||||||
});
|
&Stored {
|
||||||
let query = device.texture_tracker
|
value: id,
|
||||||
.lock()
|
ref_count,
|
||||||
.query(
|
},
|
||||||
&Stored { value: id, ref_count },
|
TextureUsageFlags::WRITE_ALL,
|
||||||
TextureUsageFlags::WRITE_ALL,
|
);
|
||||||
);
|
|
||||||
assert!(query.initialized);
|
assert!(query.initialized);
|
||||||
|
|
||||||
id
|
id
|
||||||
@ -279,42 +277,42 @@ pub extern "C" fn wgpu_texture_create_texture_view(
|
|||||||
let texture_guard = HUB.textures.read();
|
let texture_guard = HUB.textures.read();
|
||||||
let texture = texture_guard.get(texture_id);
|
let texture = texture_guard.get(texture_id);
|
||||||
|
|
||||||
let raw = unsafe { HUB.devices
|
let raw = unsafe {
|
||||||
.read()
|
HUB.devices
|
||||||
.get(texture.device_id.value)
|
.read()
|
||||||
.raw
|
.get(texture.device_id.value)
|
||||||
.create_image_view(
|
.raw
|
||||||
&texture.raw,
|
.create_image_view(
|
||||||
conv::map_texture_view_dimension(desc.dimension),
|
&texture.raw,
|
||||||
conv::map_texture_format(desc.format),
|
conv::map_texture_view_dimension(desc.dimension),
|
||||||
hal::format::Swizzle::NO,
|
conv::map_texture_format(desc.format),
|
||||||
hal::image::SubresourceRange {
|
hal::format::Swizzle::NO,
|
||||||
aspects: conv::map_texture_aspect_flags(desc.aspect),
|
hal::image::SubresourceRange {
|
||||||
levels: desc.base_mip_level as u8 .. (desc.base_mip_level + desc.level_count) as u8,
|
aspects: conv::map_texture_aspect_flags(desc.aspect),
|
||||||
layers: desc.base_array_layer as u16 .. (desc.base_array_layer + desc.array_count) as u16,
|
levels: desc.base_mip_level as u8
|
||||||
},
|
..(desc.base_mip_level + desc.level_count) as u8,
|
||||||
)
|
layers: desc.base_array_layer as u16
|
||||||
}.unwrap();
|
..(desc.base_array_layer + desc.array_count) as u16,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
HUB.texture_views
|
HUB.texture_views.write().register(resource::TextureView {
|
||||||
.write()
|
raw,
|
||||||
.register(resource::TextureView {
|
texture_id: Stored {
|
||||||
raw,
|
value: texture_id,
|
||||||
texture_id: Stored {
|
ref_count: texture.life_guard.ref_count.clone(),
|
||||||
value: texture_id,
|
},
|
||||||
ref_count: texture.life_guard.ref_count.clone(),
|
format: texture.format,
|
||||||
},
|
extent: texture.kind.extent(),
|
||||||
format: texture.format,
|
samples: texture.kind.num_samples(),
|
||||||
extent: texture.kind.extent(),
|
life_guard: LifeGuard::new(),
|
||||||
samples: texture.kind.num_samples(),
|
})
|
||||||
life_guard: LifeGuard::new(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_texture_create_default_texture_view(
|
pub extern "C" fn wgpu_texture_create_default_texture_view(texture_id: TextureId) -> TextureViewId {
|
||||||
texture_id: TextureId,
|
|
||||||
) -> TextureViewId {
|
|
||||||
let texture_guard = HUB.textures.read();
|
let texture_guard = HUB.textures.read();
|
||||||
let texture = texture_guard.get(texture_id);
|
let texture = texture_guard.get(texture_id);
|
||||||
|
|
||||||
@ -324,38 +322,36 @@ pub extern "C" fn wgpu_texture_create_default_texture_view(
|
|||||||
hal::image::Kind::D3(..) => hal::image::ViewKind::D3,
|
hal::image::Kind::D3(..) => hal::image::ViewKind::D3,
|
||||||
};
|
};
|
||||||
|
|
||||||
let raw = unsafe { HUB.devices
|
let raw = unsafe {
|
||||||
.read()
|
HUB.devices
|
||||||
.get(texture.device_id.value)
|
.read()
|
||||||
.raw
|
.get(texture.device_id.value)
|
||||||
.create_image_view(
|
.raw
|
||||||
&texture.raw,
|
.create_image_view(
|
||||||
view_kind,
|
&texture.raw,
|
||||||
conv::map_texture_format(texture.format),
|
view_kind,
|
||||||
hal::format::Swizzle::NO,
|
conv::map_texture_format(texture.format),
|
||||||
texture.full_range.clone(),
|
hal::format::Swizzle::NO,
|
||||||
)
|
texture.full_range.clone(),
|
||||||
}.unwrap();
|
)
|
||||||
|
}
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
HUB.texture_views
|
HUB.texture_views.write().register(resource::TextureView {
|
||||||
.write()
|
raw,
|
||||||
.register(resource::TextureView {
|
texture_id: Stored {
|
||||||
raw,
|
value: texture_id,
|
||||||
texture_id: Stored {
|
ref_count: texture.life_guard.ref_count.clone(),
|
||||||
value: texture_id,
|
},
|
||||||
ref_count: texture.life_guard.ref_count.clone(),
|
format: texture.format,
|
||||||
},
|
extent: texture.kind.extent(),
|
||||||
format: texture.format,
|
samples: texture.kind.num_samples(),
|
||||||
extent: texture.kind.extent(),
|
life_guard: LifeGuard::new(),
|
||||||
samples: texture.kind.num_samples(),
|
})
|
||||||
life_guard: LifeGuard::new(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_texture_destroy(
|
pub extern "C" fn wgpu_texture_destroy(texture_id: TextureId) {
|
||||||
texture_id: TextureId,
|
|
||||||
) {
|
|
||||||
let texture_guard = HUB.textures.read();
|
let texture_guard = HUB.textures.read();
|
||||||
let texture = texture_guard.get(texture_id);
|
let texture = texture_guard.get(texture_id);
|
||||||
let device_guard = HUB.devices.write();
|
let device_guard = HUB.devices.write();
|
||||||
@ -367,9 +363,7 @@ pub extern "C" fn wgpu_texture_destroy(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_texture_view_destroy(
|
pub extern "C" fn wgpu_texture_view_destroy(_texture_view_id: TextureViewId) {
|
||||||
_texture_view_id: TextureViewId,
|
|
||||||
) {
|
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,23 +374,25 @@ pub extern "C" fn wgpu_device_create_bind_group_layout(
|
|||||||
) -> BindGroupLayoutId {
|
) -> BindGroupLayoutId {
|
||||||
let bindings = unsafe { slice::from_raw_parts(desc.bindings, desc.bindings_length) };
|
let bindings = unsafe { slice::from_raw_parts(desc.bindings, desc.bindings_length) };
|
||||||
|
|
||||||
let descriptor_set_layout = unsafe { HUB.devices
|
let descriptor_set_layout = unsafe {
|
||||||
.read()
|
HUB.devices
|
||||||
.get(device_id)
|
.read()
|
||||||
.raw
|
.get(device_id)
|
||||||
.create_descriptor_set_layout(
|
.raw
|
||||||
bindings.iter().map(|binding| {
|
.create_descriptor_set_layout(
|
||||||
hal::pso::DescriptorSetLayoutBinding {
|
bindings.iter().map(|binding| {
|
||||||
binding: binding.binding,
|
hal::pso::DescriptorSetLayoutBinding {
|
||||||
ty: conv::map_binding_type(binding.ty),
|
binding: binding.binding,
|
||||||
count: bindings.len(),
|
ty: conv::map_binding_type(binding.ty),
|
||||||
stage_flags: conv::map_shader_stage_flags(binding.visibility),
|
count: bindings.len(),
|
||||||
immutable_samplers: false, // TODO
|
stage_flags: conv::map_shader_stage_flags(binding.visibility),
|
||||||
}
|
immutable_samplers: false, // TODO
|
||||||
}),
|
}
|
||||||
&[],
|
}),
|
||||||
)
|
&[],
|
||||||
}.unwrap();
|
)
|
||||||
|
}
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
HUB.bind_group_layouts
|
HUB.bind_group_layouts
|
||||||
.write()
|
.write()
|
||||||
@ -410,21 +406,22 @@ pub extern "C" fn wgpu_device_create_pipeline_layout(
|
|||||||
device_id: DeviceId,
|
device_id: DeviceId,
|
||||||
desc: &binding_model::PipelineLayoutDescriptor,
|
desc: &binding_model::PipelineLayoutDescriptor,
|
||||||
) -> PipelineLayoutId {
|
) -> PipelineLayoutId {
|
||||||
let bind_group_layouts = unsafe {
|
let bind_group_layouts =
|
||||||
slice::from_raw_parts(desc.bind_group_layouts, desc.bind_group_layouts_length)
|
unsafe { slice::from_raw_parts(desc.bind_group_layouts, desc.bind_group_layouts_length) };
|
||||||
};
|
|
||||||
let bind_group_layout_guard = HUB.bind_group_layouts.read();
|
let bind_group_layout_guard = HUB.bind_group_layouts.read();
|
||||||
let descriptor_set_layouts = bind_group_layouts
|
let descriptor_set_layouts = bind_group_layouts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&id| &bind_group_layout_guard.get(id).raw);
|
.map(|&id| &bind_group_layout_guard.get(id).raw);
|
||||||
|
|
||||||
// TODO: push constants
|
// TODO: push constants
|
||||||
let pipeline_layout = unsafe { HUB.devices
|
let pipeline_layout = unsafe {
|
||||||
.read()
|
HUB.devices
|
||||||
.get(device_id)
|
.read()
|
||||||
.raw
|
.get(device_id)
|
||||||
.create_pipeline_layout(descriptor_set_layouts, &[])
|
.raw
|
||||||
}.unwrap();
|
.create_pipeline_layout(descriptor_set_layouts, &[])
|
||||||
|
}
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
HUB.pipeline_layouts
|
HUB.pipeline_layouts
|
||||||
.write()
|
.write()
|
||||||
@ -438,11 +435,9 @@ pub extern "C" fn wgpu_device_create_blend_state(
|
|||||||
_device_id: DeviceId,
|
_device_id: DeviceId,
|
||||||
desc: &pipeline::BlendStateDescriptor,
|
desc: &pipeline::BlendStateDescriptor,
|
||||||
) -> BlendStateId {
|
) -> BlendStateId {
|
||||||
HUB.blend_states
|
HUB.blend_states.write().register(pipeline::BlendState {
|
||||||
.write()
|
raw: conv::map_blend_state_descriptor(desc),
|
||||||
.register(pipeline::BlendState {
|
})
|
||||||
raw: conv::map_blend_state_descriptor(desc),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@ -462,15 +457,15 @@ pub extern "C" fn wgpu_device_create_shader_module(
|
|||||||
device_id: DeviceId,
|
device_id: DeviceId,
|
||||||
desc: &pipeline::ShaderModuleDescriptor,
|
desc: &pipeline::ShaderModuleDescriptor,
|
||||||
) -> ShaderModuleId {
|
) -> ShaderModuleId {
|
||||||
let spv = unsafe {
|
let spv = unsafe { slice::from_raw_parts(desc.code.bytes, desc.code.length) };
|
||||||
slice::from_raw_parts(desc.code.bytes, desc.code.length)
|
let shader = unsafe {
|
||||||
};
|
HUB.devices
|
||||||
let shader = unsafe { HUB.devices
|
.read()
|
||||||
.read()
|
.get(device_id)
|
||||||
.get(device_id)
|
.raw
|
||||||
.raw
|
.create_shader_module(spv)
|
||||||
.create_shader_module(spv)
|
}
|
||||||
}.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
HUB.shader_modules
|
HUB.shader_modules
|
||||||
.write()
|
.write()
|
||||||
@ -516,13 +511,15 @@ pub extern "C" fn wgpu_queue_submit(
|
|||||||
let mut texture_tracker = device.texture_tracker.lock();
|
let mut texture_tracker = device.texture_tracker.lock();
|
||||||
|
|
||||||
let mut command_buffer_guard = HUB.command_buffers.write();
|
let mut command_buffer_guard = HUB.command_buffers.write();
|
||||||
let command_buffer_ids = unsafe {
|
let command_buffer_ids =
|
||||||
slice::from_raw_parts(command_buffer_ptr, command_buffer_count)
|
unsafe { slice::from_raw_parts(command_buffer_ptr, command_buffer_count) };
|
||||||
};
|
|
||||||
|
|
||||||
let mut buffer_guard = HUB.buffers.write();
|
let mut buffer_guard = HUB.buffers.write();
|
||||||
let mut texture_guard = HUB.textures.write();
|
let mut texture_guard = HUB.textures.write();
|
||||||
let old_submit_index = device.life_guard.submission_index.fetch_add(1, Ordering::Relaxed);
|
let old_submit_index = device
|
||||||
|
.life_guard
|
||||||
|
.submission_index
|
||||||
|
.fetch_add(1, Ordering::Relaxed);
|
||||||
|
|
||||||
//TODO: if multiple command buffers are submitted, we can re-use the last
|
//TODO: if multiple command buffers are submitted, we can re-use the last
|
||||||
// native command buffer of the previous chain instead of always creating
|
// native command buffer of the previous chain instead of always creating
|
||||||
@ -533,10 +530,18 @@ pub extern "C" fn wgpu_queue_submit(
|
|||||||
let comb = command_buffer_guard.get_mut(cmb_id);
|
let comb = command_buffer_guard.get_mut(cmb_id);
|
||||||
// update submission IDs
|
// update submission IDs
|
||||||
for id in comb.buffer_tracker.used() {
|
for id in comb.buffer_tracker.used() {
|
||||||
buffer_guard.get(id).life_guard.submission_index.store(old_submit_index, Ordering::Release);
|
buffer_guard
|
||||||
|
.get(id)
|
||||||
|
.life_guard
|
||||||
|
.submission_index
|
||||||
|
.store(old_submit_index, Ordering::Release);
|
||||||
}
|
}
|
||||||
for id in comb.texture_tracker.used() {
|
for id in comb.texture_tracker.used() {
|
||||||
texture_guard.get(id).life_guard.submission_index.store(old_submit_index, Ordering::Release);
|
texture_guard
|
||||||
|
.get(id)
|
||||||
|
.life_guard
|
||||||
|
.submission_index
|
||||||
|
.store(old_submit_index, Ordering::Release);
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute resource transitions
|
// execute resource transitions
|
||||||
@ -555,28 +560,27 @@ pub extern "C" fn wgpu_queue_submit(
|
|||||||
&*buffer_guard,
|
&*buffer_guard,
|
||||||
&*texture_guard,
|
&*texture_guard,
|
||||||
);
|
);
|
||||||
unsafe { transit.finish(); }
|
unsafe {
|
||||||
|
transit.finish();
|
||||||
|
}
|
||||||
comb.raw.insert(0, transit);
|
comb.raw.insert(0, transit);
|
||||||
unsafe {
|
unsafe {
|
||||||
comb.raw
|
comb.raw.last_mut().unwrap().finish();
|
||||||
.last_mut()
|
|
||||||
.unwrap()
|
|
||||||
.finish();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now prepare the GPU submission
|
// now prepare the GPU submission
|
||||||
let fence = device.raw.create_fence(false).unwrap();
|
let fence = device.raw.create_fence(false).unwrap();
|
||||||
{
|
{
|
||||||
let submission = hal::queue::Submission::<_, _, &[<back::Backend as hal::Backend>::Semaphore]> { //TODO: may `OneShot` be enough?
|
let submission =
|
||||||
command_buffers: command_buffer_ids
|
hal::queue::Submission::<_, _, &[<back::Backend as hal::Backend>::Semaphore]> {
|
||||||
.iter()
|
//TODO: may `OneShot` be enough?
|
||||||
.flat_map(|&cmb_id| {
|
command_buffers: command_buffer_ids
|
||||||
&command_buffer_guard.get(cmb_id).raw
|
.iter()
|
||||||
}),
|
.flat_map(|&cmb_id| &command_buffer_guard.get(cmb_id).raw),
|
||||||
wait_semaphores: Vec::new(),
|
wait_semaphores: Vec::new(),
|
||||||
signal_semaphores: &[],
|
signal_semaphores: &[],
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
device.queue_group.queues[0]
|
device.queue_group.queues[0]
|
||||||
.as_raw_mut()
|
.as_raw_mut()
|
||||||
@ -632,22 +636,21 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
|
|||||||
desc.attachments_state.color_attachments_length,
|
desc.attachments_state.color_attachments_length,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let depth_stencil_attachment = unsafe {
|
let depth_stencil_attachment =
|
||||||
desc.attachments_state.depth_stencil_attachment.as_ref()
|
unsafe { desc.attachments_state.depth_stencil_attachment.as_ref() };
|
||||||
};
|
|
||||||
let color_keys = color_attachments.iter().map(|at| hal::pass::Attachment {
|
let color_keys = color_attachments.iter().map(|at| hal::pass::Attachment {
|
||||||
format: Some(conv::map_texture_format(at.format)),
|
format: Some(conv::map_texture_format(at.format)),
|
||||||
samples: at.samples as u8,
|
samples: at.samples as u8,
|
||||||
ops: op_keep,
|
ops: op_keep,
|
||||||
stencil_ops: hal::pass::AttachmentOps::DONT_CARE,
|
stencil_ops: hal::pass::AttachmentOps::DONT_CARE,
|
||||||
layouts: hal::image::Layout::General .. hal::image::Layout::General,
|
layouts: hal::image::Layout::General..hal::image::Layout::General,
|
||||||
});
|
});
|
||||||
let depth_stencil_key = depth_stencil_attachment.map(|at| hal::pass::Attachment {
|
let depth_stencil_key = depth_stencil_attachment.map(|at| hal::pass::Attachment {
|
||||||
format: Some(conv::map_texture_format(at.format)),
|
format: Some(conv::map_texture_format(at.format)),
|
||||||
samples: at.samples as u8,
|
samples: at.samples as u8,
|
||||||
ops: op_keep,
|
ops: op_keep,
|
||||||
stencil_ops: op_keep,
|
stencil_ops: op_keep,
|
||||||
layouts: hal::image::Layout::General .. hal::image::Layout::General,
|
layouts: hal::image::Layout::General..hal::image::Layout::General,
|
||||||
});
|
});
|
||||||
RenderPassKey {
|
RenderPassKey {
|
||||||
attachments: color_keys.chain(depth_stencil_key).collect(),
|
attachments: color_keys.chain(depth_stencil_key).collect(),
|
||||||
@ -664,10 +667,13 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
|
|||||||
(2, hal::image::Layout::ColorAttachmentOptimal),
|
(2, hal::image::Layout::ColorAttachmentOptimal),
|
||||||
(3, hal::image::Layout::ColorAttachmentOptimal),
|
(3, hal::image::Layout::ColorAttachmentOptimal),
|
||||||
];
|
];
|
||||||
let depth_id = (desc.attachments_state.color_attachments_length, hal::image::Layout::DepthStencilAttachmentOptimal);
|
let depth_id = (
|
||||||
|
desc.attachments_state.color_attachments_length,
|
||||||
|
hal::image::Layout::DepthStencilAttachmentOptimal,
|
||||||
|
);
|
||||||
|
|
||||||
let subpass = hal::pass::SubpassDesc {
|
let subpass = hal::pass::SubpassDesc {
|
||||||
colors: &color_ids[.. desc.attachments_state.color_attachments_length],
|
colors: &color_ids[..desc.attachments_state.color_attachments_length],
|
||||||
depth_stencil: if desc.attachments_state.depth_stencil_attachment.is_null() {
|
depth_stencil: if desc.attachments_state.depth_stencil_attachment.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -678,11 +684,12 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
|
|||||||
preserves: &[],
|
preserves: &[],
|
||||||
};
|
};
|
||||||
|
|
||||||
let pass = unsafe { device.raw.create_render_pass(
|
let pass = unsafe {
|
||||||
&e.key().attachments,
|
device
|
||||||
&[subpass],
|
.raw
|
||||||
&[],
|
.create_render_pass(&e.key().attachments, &[subpass], &[])
|
||||||
)}.unwrap();
|
}
|
||||||
|
.unwrap();
|
||||||
e.insert(pass)
|
e.insert(pass)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -745,10 +752,11 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let blend_state_guard = HUB.blend_states.read();
|
let blend_state_guard = HUB.blend_states.read();
|
||||||
let blend_states = unsafe { slice::from_raw_parts(desc.blend_states, desc.blend_states_length) }
|
let blend_states =
|
||||||
.iter()
|
unsafe { slice::from_raw_parts(desc.blend_states, desc.blend_states_length) }
|
||||||
.map(|id| blend_state_guard.get(id.clone()).raw)
|
.iter()
|
||||||
.collect();
|
.map(|id| blend_state_guard.get(id.clone()).raw)
|
||||||
|
.collect();
|
||||||
|
|
||||||
let blender = hal::pso::BlendDesc {
|
let blender = hal::pso::BlendDesc {
|
||||||
logic_op: None, // TODO
|
logic_op: None, // TODO
|
||||||
@ -809,9 +817,7 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// TODO: cache
|
// TODO: cache
|
||||||
let pipeline = unsafe { device.raw
|
let pipeline = unsafe { device.raw.create_graphics_pipeline(&pipeline_desc, None) }.unwrap();
|
||||||
.create_graphics_pipeline(&pipeline_desc, None)
|
|
||||||
}.unwrap();
|
|
||||||
|
|
||||||
HUB.render_pipelines
|
HUB.render_pipelines
|
||||||
.write()
|
.write()
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice};
|
use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice};
|
||||||
|
|
||||||
use registry::{HUB, Items};
|
use registry::{Items, HUB};
|
||||||
use {AdapterId, Device, DeviceId, InstanceId};
|
use {AdapterId, Device, DeviceId, InstanceId};
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@ -67,9 +67,7 @@ pub extern "C" fn wgpu_instance_get_adapter(
|
|||||||
PowerPreference::LowPower => low.or(high),
|
PowerPreference::LowPower => low.or(high),
|
||||||
PowerPreference::HighPerformance | PowerPreference::Default => high.or(low),
|
PowerPreference::HighPerformance | PowerPreference::Default => high.or(low),
|
||||||
};
|
};
|
||||||
HUB.adapters
|
HUB.adapters.write().register(some.or(other).unwrap())
|
||||||
.write()
|
|
||||||
.register(some.or(other).unwrap())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|||||||
@ -45,7 +45,6 @@ pub use registry::Id;
|
|||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
||||||
|
|
||||||
type SubmissionIndex = usize;
|
type SubmissionIndex = usize;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -109,7 +108,6 @@ struct WeaklyStored<T>(T);
|
|||||||
unsafe impl<T> Send for WeaklyStored<T> {}
|
unsafe impl<T> Send for WeaklyStored<T> {}
|
||||||
unsafe impl<T> Sync for WeaklyStored<T> {}
|
unsafe impl<T> Sync for WeaklyStored<T> {}
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct Color {
|
pub struct Color {
|
||||||
@ -120,12 +118,42 @@ pub struct Color {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Color {
|
impl Color {
|
||||||
pub const TRANSPARENT : Self = Color { r: 0.0, g: 0.0, b: 0.0, a: 0.0 };
|
pub const TRANSPARENT: Self = Color {
|
||||||
pub const BLACK : Self = Color { r: 0.0, g: 0.0, b: 0.0, a: 1.0 };
|
r: 0.0,
|
||||||
pub const WHITE : Self = Color { r: 1.0, g: 1.0, b: 1.0, a: 1.0 };
|
g: 0.0,
|
||||||
pub const RED : Self = Color { r: 1.0, g: 0.0, b: 0.0, a: 1.0 };
|
b: 0.0,
|
||||||
pub const GREEN : Self = Color { r: 0.0, g: 1.0, b: 0.0, a: 1.0 };
|
a: 0.0,
|
||||||
pub const BLUE : Self = Color { r: 0.0, g: 0.0, b: 1.0, a: 1.0 };
|
};
|
||||||
|
pub const BLACK: Self = Color {
|
||||||
|
r: 0.0,
|
||||||
|
g: 0.0,
|
||||||
|
b: 0.0,
|
||||||
|
a: 1.0,
|
||||||
|
};
|
||||||
|
pub const WHITE: Self = Color {
|
||||||
|
r: 1.0,
|
||||||
|
g: 1.0,
|
||||||
|
b: 1.0,
|
||||||
|
a: 1.0,
|
||||||
|
};
|
||||||
|
pub const RED: Self = Color {
|
||||||
|
r: 1.0,
|
||||||
|
g: 0.0,
|
||||||
|
b: 0.0,
|
||||||
|
a: 1.0,
|
||||||
|
};
|
||||||
|
pub const GREEN: Self = Color {
|
||||||
|
r: 0.0,
|
||||||
|
g: 1.0,
|
||||||
|
b: 0.0,
|
||||||
|
a: 1.0,
|
||||||
|
};
|
||||||
|
pub const BLUE: Self = Color {
|
||||||
|
r: 0.0,
|
||||||
|
g: 0.0,
|
||||||
|
b: 1.0,
|
||||||
|
a: 1.0,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
use hal;
|
use hal;
|
||||||
use resource;
|
use resource;
|
||||||
|
|
||||||
use {
|
use {BlendStateId, ByteArray, DepthStencilStateId, PipelineLayoutId, ShaderModuleId};
|
||||||
BlendStateId, ByteArray, DepthStencilStateId, PipelineLayoutId,
|
|
||||||
ShaderModuleId,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::c_void;
|
||||||
|
|
||||||
|
|
||||||
pub type Id = *mut c_void;
|
pub type Id = *mut c_void;
|
||||||
|
|
||||||
pub struct Items<T> {
|
pub struct Items<T> {
|
||||||
|
|||||||
@ -3,14 +3,12 @@ use std::sync::Arc;
|
|||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
|
|
||||||
use {
|
use {
|
||||||
AdapterHandle, BindGroupLayoutHandle, BindGroupHandle,
|
AdapterHandle, BindGroupHandle, BindGroupLayoutHandle, BlendStateHandle, BufferHandle,
|
||||||
BlendStateHandle, CommandBufferHandle, DepthStencilStateHandle, DeviceHandle, InstanceHandle,
|
CommandBufferHandle, ComputePassHandle, ComputePipelineHandle, DepthStencilStateHandle,
|
||||||
RenderPassHandle, ComputePassHandle,
|
DeviceHandle, InstanceHandle, PipelineLayoutHandle, RenderPassHandle, RenderPipelineHandle,
|
||||||
PipelineLayoutHandle, RenderPipelineHandle, ComputePipelineHandle, ShaderModuleHandle,
|
ShaderModuleHandle, TextureHandle, TextureViewHandle,
|
||||||
BufferHandle, TextureHandle, TextureViewHandle,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#[cfg(not(feature = "remote"))]
|
#[cfg(not(feature = "remote"))]
|
||||||
mod local;
|
mod local;
|
||||||
#[cfg(feature = "remote")]
|
#[cfg(feature = "remote")]
|
||||||
@ -21,7 +19,6 @@ pub use self::local::{Id, Items as ConcreteItems};
|
|||||||
#[cfg(feature = "remote")]
|
#[cfg(feature = "remote")]
|
||||||
pub use self::remote::{Id, Items as ConcreteItems};
|
pub use self::remote::{Id, Items as ConcreteItems};
|
||||||
|
|
||||||
|
|
||||||
pub trait Items<T>: Default {
|
pub trait Items<T>: Default {
|
||||||
fn register(&mut self, handle: T) -> Id;
|
fn register(&mut self, handle: T) -> Id;
|
||||||
fn get(&self, id: Id) -> &T;
|
fn get(&self, id: Id) -> &T;
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
use hal::backend::FastHashMap;
|
use hal::backend::FastHashMap;
|
||||||
|
|
||||||
|
|
||||||
pub type Id = u32;
|
pub type Id = u32;
|
||||||
|
|
||||||
pub struct Items<T> {
|
pub struct Items<T> {
|
||||||
|
|||||||
@ -1,11 +1,7 @@
|
|||||||
use {
|
use {DeviceId, Extent3d, LifeGuard, Stored, TextureId};
|
||||||
Extent3d, LifeGuard, Stored,
|
|
||||||
DeviceId, TextureId,
|
|
||||||
};
|
|
||||||
|
|
||||||
use hal;
|
use hal;
|
||||||
|
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct BufferUsageFlags: u32 {
|
pub struct BufferUsageFlags: u32 {
|
||||||
@ -36,7 +32,6 @@ pub(crate) struct Buffer<B: hal::Backend> {
|
|||||||
// TODO: mapping, unmap()
|
// TODO: mapping, unmap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
pub enum TextureDimension {
|
pub enum TextureDimension {
|
||||||
@ -86,7 +81,6 @@ pub(crate) struct Texture<B: hal::Backend> {
|
|||||||
pub life_guard: LifeGuard,
|
pub life_guard: LifeGuard,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct TextureAspectFlags: u32 {
|
pub struct TextureAspectFlags: u32 {
|
||||||
@ -127,7 +121,6 @@ pub(crate) struct TextureView<B: hal::Backend> {
|
|||||||
pub life_guard: LifeGuard,
|
pub life_guard: LifeGuard,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
pub enum AddressMode {
|
pub enum AddressMode {
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
use {RefCount, Stored, WeaklyStored, BufferId, TextureId};
|
|
||||||
use resource::{BufferUsageFlags, TextureUsageFlags};
|
use resource::{BufferUsageFlags, TextureUsageFlags};
|
||||||
|
use {BufferId, RefCount, Stored, TextureId, WeaklyStored};
|
||||||
|
|
||||||
use std::collections::hash_map::{Entry, HashMap};
|
use std::collections::hash_map::{Entry, HashMap};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::{BitOr, Range};
|
use std::ops::{BitOr, Range};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub enum Tracktion<T> {
|
pub enum Tracktion<T> {
|
||||||
@ -29,7 +28,6 @@ bitflags! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub trait GenericUsage {
|
pub trait GenericUsage {
|
||||||
fn is_exclusive(&self) -> bool;
|
fn is_exclusive(&self) -> bool;
|
||||||
}
|
}
|
||||||
@ -61,10 +59,7 @@ pub struct Tracker<I, U> {
|
|||||||
pub type BufferTracker = Tracker<BufferId, BufferUsageFlags>;
|
pub type BufferTracker = Tracker<BufferId, BufferUsageFlags>;
|
||||||
pub type TextureTracker = Tracker<TextureId, TextureUsageFlags>;
|
pub type TextureTracker = Tracker<TextureId, TextureUsageFlags>;
|
||||||
|
|
||||||
impl<
|
impl<I: Clone + Hash + Eq, U: Copy + GenericUsage + BitOr<Output = U> + PartialEq> Tracker<I, U> {
|
||||||
I: Clone + Hash + Eq,
|
|
||||||
U: Copy + GenericUsage + BitOr<Output = U> + PartialEq,
|
|
||||||
> Tracker<I, U> {
|
|
||||||
pub(crate) fn new() -> Self {
|
pub(crate) fn new() -> Self {
|
||||||
Tracker {
|
Tracker {
|
||||||
map: HashMap::new(),
|
map: HashMap::new(),
|
||||||
@ -72,9 +67,7 @@ impl<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the last usage on a resource.
|
/// Get the last usage on a resource.
|
||||||
pub(crate) fn query(
|
pub(crate) fn query(&mut self, stored: &Stored<I>, default: U) -> Query<U> {
|
||||||
&mut self, stored: &Stored<I>, default: U
|
|
||||||
) -> Query<U> {
|
|
||||||
match self.map.entry(WeaklyStored(stored.value.clone())) {
|
match self.map.entry(WeaklyStored(stored.value.clone())) {
|
||||||
Entry::Vacant(e) => {
|
Entry::Vacant(e) => {
|
||||||
e.insert(Track {
|
e.insert(Track {
|
||||||
@ -87,18 +80,20 @@ impl<
|
|||||||
initialized: true,
|
initialized: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Entry::Occupied(e) => {
|
Entry::Occupied(e) => Query {
|
||||||
Query {
|
usage: e.get().last,
|
||||||
usage: e.get().last,
|
initialized: false,
|
||||||
initialized: false,
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transit a specified resource into a different usage.
|
/// Transit a specified resource into a different usage.
|
||||||
pub(crate) fn transit(
|
pub(crate) fn transit(
|
||||||
&mut self, id: I, ref_count: &RefCount, usage: U, permit: TrackPermit
|
&mut self,
|
||||||
|
id: I,
|
||||||
|
ref_count: &RefCount,
|
||||||
|
usage: U,
|
||||||
|
permit: TrackPermit,
|
||||||
) -> Result<Tracktion<U>, U> {
|
) -> Result<Tracktion<U>, U> {
|
||||||
match self.map.entry(WeaklyStored(id)) {
|
match self.map.entry(WeaklyStored(id)) {
|
||||||
Entry::Vacant(e) => {
|
Entry::Vacant(e) => {
|
||||||
@ -127,12 +122,9 @@ impl<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Consume another tacker, adding it's transitions to `self`.
|
/// Consume another tacker, adding it's transitions to `self`.
|
||||||
pub fn consume<'a>(
|
pub fn consume<'a>(&'a mut self, other: &'a Self) -> impl 'a + Iterator<Item = (I, Range<U>)> {
|
||||||
&'a mut self, other: &'a Self
|
other.map.iter().flat_map(move |(id, new)| {
|
||||||
) -> impl 'a + Iterator<Item = (I, Range<U>)> {
|
match self.map.entry(WeaklyStored(id.0.clone())) {
|
||||||
other.map
|
|
||||||
.iter()
|
|
||||||
.flat_map(move |(id, new)| match self.map.entry(WeaklyStored(id.0.clone())) {
|
|
||||||
Entry::Vacant(e) => {
|
Entry::Vacant(e) => {
|
||||||
e.insert(new.clone());
|
e.insert(new.clone());
|
||||||
None
|
None
|
||||||
@ -142,10 +134,11 @@ impl<
|
|||||||
if old == new.init {
|
if old == new.init {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some((id.0.clone(), old .. new.last))
|
Some((id.0.clone(), old..new.last))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return an iterator over used resources keys.
|
/// Return an iterator over used resources keys.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
extern crate wgpu_native as wgn;
|
|
||||||
extern crate arrayvec;
|
extern crate arrayvec;
|
||||||
|
extern crate wgpu_native as wgn;
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
|
|
||||||
@ -7,16 +7,14 @@ use std::ffi::CString;
|
|||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
pub use wgn::{
|
pub use wgn::{
|
||||||
AdapterDescriptor, Color, CommandBufferDescriptor, DeviceDescriptor, Extensions, Extent3d,
|
AdapterDescriptor, Attachment, BindGroupLayoutBinding, BindingType, BlendStateDescriptor,
|
||||||
Origin3d, PowerPreference, ShaderModuleDescriptor, ShaderStage, ShaderStageFlags,
|
Color, ColorWriteFlags, CommandBufferDescriptor, DepthStencilStateDescriptor, DeviceDescriptor,
|
||||||
BindGroupLayoutBinding, BindingType, TextureDimension, TextureDescriptor, TextureFormat,
|
Extensions, Extent3d, LoadOp, Origin3d, PowerPreference, PrimitiveTopology,
|
||||||
TextureUsageFlags, TextureViewDescriptor,
|
RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
|
||||||
PrimitiveTopology, BlendStateDescriptor, ColorWriteFlags, DepthStencilStateDescriptor,
|
RenderPassDescriptor, ShaderModuleDescriptor, ShaderStage, ShaderStageFlags, StoreOp,
|
||||||
RenderPassDescriptor, RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
|
TextureDescriptor, TextureDimension, TextureFormat, TextureUsageFlags, TextureViewDescriptor,
|
||||||
Attachment, LoadOp, StoreOp,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
id: wgn::InstanceId,
|
id: wgn::InstanceId,
|
||||||
}
|
}
|
||||||
@ -115,7 +113,6 @@ pub struct RenderPipelineDescriptor<'a> {
|
|||||||
pub depth_stencil_state: &'a DepthStencilState,
|
pub depth_stencil_state: &'a DepthStencilState,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Instance {
|
impl Instance {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Instance {
|
Instance {
|
||||||
@ -165,24 +162,31 @@ impl Device {
|
|||||||
|
|
||||||
pub fn create_bind_group_layout(&self, desc: &BindGroupLayoutDescriptor) -> BindGroupLayout {
|
pub fn create_bind_group_layout(&self, desc: &BindGroupLayoutDescriptor) -> BindGroupLayout {
|
||||||
BindGroupLayout {
|
BindGroupLayout {
|
||||||
id: wgn::wgpu_device_create_bind_group_layout(self.id, &wgn::BindGroupLayoutDescriptor {
|
id: wgn::wgpu_device_create_bind_group_layout(
|
||||||
bindings: desc.bindings.as_ptr(),
|
self.id,
|
||||||
bindings_length: desc.bindings.len(),
|
&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 {
|
||||||
//TODO: avoid allocation here
|
//TODO: avoid allocation here
|
||||||
let temp_layouts = desc.bind_group_layouts
|
let temp_layouts = desc
|
||||||
|
.bind_group_layouts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|bgl| bgl.id)
|
.map(|bgl| bgl.id)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
PipelineLayout {
|
PipelineLayout {
|
||||||
id: wgn::wgpu_device_create_pipeline_layout(self.id, &wgn::PipelineLayoutDescriptor {
|
id: wgn::wgpu_device_create_pipeline_layout(
|
||||||
bind_group_layouts: temp_layouts.as_ptr(),
|
self.id,
|
||||||
bind_group_layouts_length: temp_layouts.len(),
|
&wgn::PipelineLayoutDescriptor {
|
||||||
}),
|
bind_group_layouts: temp_layouts.as_ptr(),
|
||||||
|
bind_group_layouts_length: temp_layouts.len(),
|
||||||
|
},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,18 +196,23 @@ impl Device {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_depth_stencil_state(&self, desc: &DepthStencilStateDescriptor) -> DepthStencilState {
|
pub fn create_depth_stencil_state(
|
||||||
|
&self,
|
||||||
|
desc: &DepthStencilStateDescriptor,
|
||||||
|
) -> DepthStencilState {
|
||||||
DepthStencilState {
|
DepthStencilState {
|
||||||
id: wgn::wgpu_device_create_depth_stencil_state(self.id, desc),
|
id: wgn::wgpu_device_create_depth_stencil_state(self.id, desc),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_render_pipeline(&self, desc: &RenderPipelineDescriptor) -> RenderPipeline {
|
pub fn create_render_pipeline(&self, desc: &RenderPipelineDescriptor) -> RenderPipeline {
|
||||||
let entry_points = desc.stages
|
let entry_points = desc
|
||||||
|
.stages
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ps| CString::new(ps.entry_point).unwrap())
|
.map(|ps| CString::new(ps.entry_point).unwrap())
|
||||||
.collect::<ArrayVec<[_; 2]>>();
|
.collect::<ArrayVec<[_; 2]>>();
|
||||||
let stages = desc.stages
|
let stages = desc
|
||||||
|
.stages
|
||||||
.iter()
|
.iter()
|
||||||
.zip(&entry_points)
|
.zip(&entry_points)
|
||||||
.map(|(ps, ep_name)| wgn::PipelineStageDescriptor {
|
.map(|(ps, ep_name)| wgn::PipelineStageDescriptor {
|
||||||
@ -213,26 +222,31 @@ impl Device {
|
|||||||
})
|
})
|
||||||
.collect::<ArrayVec<[_; 2]>>();
|
.collect::<ArrayVec<[_; 2]>>();
|
||||||
|
|
||||||
let temp_blend_states = desc.blend_states
|
let temp_blend_states = desc.blend_states.iter().map(|bs| bs.id).collect::<Vec<_>>();
|
||||||
.iter()
|
|
||||||
.map(|bs| bs.id)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
RenderPipeline {
|
RenderPipeline {
|
||||||
id: wgn::wgpu_device_create_render_pipeline(self.id, &wgn::RenderPipelineDescriptor {
|
id: wgn::wgpu_device_create_render_pipeline(
|
||||||
layout: desc.layout.id,
|
self.id,
|
||||||
stages: stages.as_ptr(),
|
&wgn::RenderPipelineDescriptor {
|
||||||
stages_length: stages.len(),
|
layout: desc.layout.id,
|
||||||
primitive_topology: desc.primitive_topology,
|
stages: stages.as_ptr(),
|
||||||
attachments_state: wgn::AttachmentsState {
|
stages_length: stages.len(),
|
||||||
color_attachments: desc.attachments_state.color_attachments.as_ptr(),
|
primitive_topology: desc.primitive_topology,
|
||||||
color_attachments_length: desc.attachments_state.color_attachments.len(),
|
attachments_state: wgn::AttachmentsState {
|
||||||
depth_stencil_attachment: desc.attachments_state.depth_stencil_attachment.as_ref().map(|at| at as *const _).unwrap_or(ptr::null()),
|
color_attachments: desc.attachments_state.color_attachments.as_ptr(),
|
||||||
|
color_attachments_length: desc.attachments_state.color_attachments.len(),
|
||||||
|
depth_stencil_attachment: desc
|
||||||
|
.attachments_state
|
||||||
|
.depth_stencil_attachment
|
||||||
|
.as_ref()
|
||||||
|
.map(|at| at as *const _)
|
||||||
|
.unwrap_or(ptr::null()),
|
||||||
|
},
|
||||||
|
blend_states: temp_blend_states.as_ptr(),
|
||||||
|
blend_states_length: temp_blend_states.len(),
|
||||||
|
depth_stencil_state: desc.depth_stencil_state.id,
|
||||||
},
|
},
|
||||||
blend_states: temp_blend_states.as_ptr(),
|
),
|
||||||
blend_states_length: temp_blend_states.len(),
|
|
||||||
depth_stencil_state: desc.depth_stencil_state.id,
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +273,8 @@ impl Texture {
|
|||||||
|
|
||||||
impl CommandBuffer {
|
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
|
let colors = desc
|
||||||
|
.color_attachments
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ca| RenderPassColorAttachmentDescriptor {
|
.map(|ca| RenderPassColorAttachmentDescriptor {
|
||||||
attachment: ca.attachment.id,
|
attachment: ca.attachment.id,
|
||||||
@ -269,9 +284,8 @@ impl CommandBuffer {
|
|||||||
})
|
})
|
||||||
.collect::<ArrayVec<[_; 4]>>();
|
.collect::<ArrayVec<[_; 4]>>();
|
||||||
|
|
||||||
let depth_stencil = desc.depth_stencil_attachment
|
let depth_stencil = desc.depth_stencil_attachment.as_ref().map(|dsa| {
|
||||||
.as_ref()
|
RenderPassDepthStencilAttachmentDescriptor {
|
||||||
.map(|dsa| RenderPassDepthStencilAttachmentDescriptor {
|
|
||||||
attachment: dsa.attachment.id,
|
attachment: dsa.attachment.id,
|
||||||
depth_load_op: dsa.depth_load_op,
|
depth_load_op: dsa.depth_load_op,
|
||||||
depth_store_op: dsa.depth_store_op,
|
depth_store_op: dsa.depth_store_op,
|
||||||
@ -279,13 +293,17 @@ impl CommandBuffer {
|
|||||||
stencil_load_op: dsa.stencil_load_op,
|
stencil_load_op: dsa.stencil_load_op,
|
||||||
stencil_store_op: dsa.stencil_store_op,
|
stencil_store_op: dsa.stencil_store_op,
|
||||||
clear_stencil: dsa.clear_stencil,
|
clear_stencil: dsa.clear_stencil,
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
RenderPass {
|
RenderPass {
|
||||||
id: wgn::wgpu_command_buffer_begin_render_pass(self.id, RenderPassDescriptor {
|
id: wgn::wgpu_command_buffer_begin_render_pass(
|
||||||
color_attachments: &colors,
|
self.id,
|
||||||
depth_stencil_attachment: depth_stencil,
|
RenderPassDescriptor {
|
||||||
}),
|
color_attachments: &colors,
|
||||||
|
depth_stencil_attachment: depth_stencil,
|
||||||
|
},
|
||||||
|
),
|
||||||
parent: self,
|
parent: self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user