mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-27 16:49:39 +01:00
Render pass creation
This commit is contained in:
1 parent
32b92afa5c
commit
08a1bd4bc7
7 files changed
+123
-16
No files matched your search
@@ -6,15 +6,17 @@ pub use self::allocator::CommandAllocator;
|
||||
pub use self::compute::*;
|
||||
pub use self::render::*;
|
||||
|
||||
use hal;
|
||||
use hal::{self, Device};
|
||||
|
||||
use {
|
||||
Color, Origin3d, Stored,
|
||||
BufferId, CommandBufferId, ComputePassId, DeviceId, RenderPassId, TextureId, TextureViewId,
|
||||
};
|
||||
use conv;
|
||||
use registry::{HUB, Items, Registry};
|
||||
use track::{BufferTracker, TextureTracker};
|
||||
|
||||
use std::iter;
|
||||
use std::thread::ThreadId;
|
||||
|
||||
|
||||
@@ -88,17 +90,72 @@ pub struct CommandBufferDescriptor {}
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
||||
command_buffer_id: CommandBufferId,
|
||||
_descriptor: RenderPassDescriptor<TextureViewId>,
|
||||
desc: RenderPassDescriptor<TextureViewId>,
|
||||
) -> RenderPassId {
|
||||
let mut cmb_guard = HUB.command_buffers.lock();
|
||||
let cmb = cmb_guard.get_mut(command_buffer_id);
|
||||
|
||||
let device_guard = HUB.devices.lock();
|
||||
let device = device_guard.get(cmb.device_id.0);
|
||||
|
||||
let current_comb = device.com_allocator.extend(cmb);
|
||||
|
||||
//let render_pass = device.create_render_pass();
|
||||
let render_pass = {
|
||||
let tracker = &mut cmb.texture_tracker;
|
||||
let view_guard = HUB.texture_views.lock();
|
||||
|
||||
let depth_stencil_attachment = match desc.depth_stencil_attachment {
|
||||
Some(ref at) => {
|
||||
let view = view_guard.get(at.attachment);
|
||||
let query = tracker.query(view.source_id.0);
|
||||
let (_, layout) = conv::map_texture_state(
|
||||
query.usage,
|
||||
hal::format::Aspects::DEPTH | hal::format::Aspects::STENCIL,
|
||||
);
|
||||
Some(hal::pass::Attachment {
|
||||
format: Some(conv::map_texture_format(view.format)),
|
||||
samples: view.samples,
|
||||
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),
|
||||
layouts: layout .. layout,
|
||||
})
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let color_attachments = desc.color_attachments
|
||||
.iter()
|
||||
.map(|at| {
|
||||
let view = view_guard.get(at.attachment);
|
||||
let query = tracker.query(view.source_id.0);
|
||||
let (_, layout) = conv::map_texture_state(query.usage, hal::format::Aspects::COLOR);
|
||||
hal::pass::Attachment {
|
||||
format: Some(conv::map_texture_format(view.format)),
|
||||
samples: view.samples,
|
||||
ops: conv::map_load_store_ops(at.load_op, at.store_op),
|
||||
stencil_ops: hal::pass::AttachmentOps::DONT_CARE,
|
||||
layouts: layout .. layout,
|
||||
}
|
||||
});
|
||||
let attachments = color_attachments.chain(depth_stencil_attachment);
|
||||
|
||||
//TODO: retain the storage
|
||||
let color_refs = (0 .. desc.color_attachments.len())
|
||||
.map(|i| {
|
||||
(i, hal::image::Layout::ColorAttachmentOptimal)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let ds_ref = desc.depth_stencil_attachment.as_ref().map(|_| {
|
||||
(desc.color_attachments.len(), hal::image::Layout::DepthStencilAttachmentOptimal)
|
||||
});
|
||||
let subpass = hal::pass::SubpassDesc {
|
||||
colors: &color_refs,
|
||||
depth_stencil: ds_ref.as_ref(),
|
||||
inputs: &[],
|
||||
resolves: &[],
|
||||
preserves: &[],
|
||||
};
|
||||
|
||||
device.raw.create_render_pass(attachments, iter::once(subpass), &[])
|
||||
};
|
||||
//let framebuffer = device.create_framebuffer();
|
||||
|
||||
/*TODO:
|
||||
|
||||
Reference in new issue
Block a user