mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-16 17:02:32 +00:00
Framebuffer creation and actual begin_render_pass
This commit is contained in:
parent
08a1bd4bc7
commit
de4f2b70eb
@ -122,8 +122,8 @@ int main()
|
||||
.stages = stages,
|
||||
.stages_length = STAGES_LENGTH,
|
||||
.primitive_topology = WGPUPrimitiveTopology_TriangleList,
|
||||
.blend_state = blend_state,
|
||||
.blend_state_length = BLEND_STATE_LENGTH,
|
||||
.blend_states = blend_state,
|
||||
.blend_states_length = BLEND_STATE_LENGTH,
|
||||
.depth_stencil_state = depth_stencil_state,
|
||||
.attachment_state = attachment_state,
|
||||
};
|
||||
|
@ -43,7 +43,7 @@ fn main() {
|
||||
},
|
||||
],
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
blend_state: &[
|
||||
blend_states: &[
|
||||
&blend_state0,
|
||||
],
|
||||
depth_stencil_state: &depth_stencil_state,
|
||||
|
@ -219,8 +219,8 @@ typedef struct {
|
||||
const WGPUPipelineStageDescriptor *stages;
|
||||
uintptr_t stages_length;
|
||||
WGPUPrimitiveTopology primitive_topology;
|
||||
const WGPUBlendStateId *blend_state;
|
||||
uintptr_t blend_state_length;
|
||||
const WGPUBlendStateId *blend_states;
|
||||
uintptr_t blend_states_length;
|
||||
WGPUDepthStencilStateId depth_stencil_state;
|
||||
WGPUAttachmentStateId attachment_state;
|
||||
} WGPURenderPipelineDescriptor;
|
||||
@ -304,7 +304,7 @@ WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id,
|
||||
WGPUComputePassId wgpu_command_buffer_begin_compute_pass(WGPUCommandBufferId command_buffer_id);
|
||||
|
||||
WGPURenderPassId wgpu_command_buffer_begin_render_pass(WGPUCommandBufferId command_buffer_id,
|
||||
WGPURenderPassDescriptor_WGPUTextureViewId _descriptor);
|
||||
WGPURenderPassDescriptor_WGPUTextureViewId desc);
|
||||
|
||||
WGPUCommandBufferId wgpu_compute_pass_end_pass(WGPUComputePassId pass_id);
|
||||
|
||||
|
@ -7,6 +7,7 @@ pub use self::compute::*;
|
||||
pub use self::render::*;
|
||||
|
||||
use hal::{self, Device};
|
||||
use hal::command::RawCommandBuffer;
|
||||
|
||||
use {
|
||||
Color, Origin3d, Stored,
|
||||
@ -96,16 +97,22 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
||||
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 view_guard = HUB.texture_views.lock();
|
||||
|
||||
let current_comb = device.com_allocator.extend(cmb);
|
||||
let mut current_comb = device.com_allocator.extend(cmb);
|
||||
let mut extent = None;
|
||||
|
||||
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);
|
||||
if let Some(ex) = extent {
|
||||
assert_eq!(ex, view.extent);
|
||||
} else {
|
||||
extent = Some(view.extent);
|
||||
}
|
||||
let query = tracker.query(view.source_id.0);
|
||||
let (_, layout) = conv::map_texture_state(
|
||||
query.usage,
|
||||
@ -125,6 +132,11 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
||||
.iter()
|
||||
.map(|at| {
|
||||
let view = view_guard.get(at.attachment);
|
||||
if let Some(ex) = extent {
|
||||
assert_eq!(ex, view.extent);
|
||||
} else {
|
||||
extent = Some(view.extent);
|
||||
}
|
||||
let query = tracker.query(view.source_id.0);
|
||||
let (_, layout) = conv::map_texture_state(query.usage, hal::format::Aspects::COLOR);
|
||||
hal::pass::Attachment {
|
||||
@ -156,16 +168,45 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
||||
|
||||
device.raw.create_render_pass(attachments, iter::once(subpass), &[])
|
||||
};
|
||||
//let framebuffer = device.create_framebuffer();
|
||||
|
||||
/*TODO:
|
||||
raw.begin_render_pass(
|
||||
render_pass: &B::RenderPass,
|
||||
framebuffer: &B::Framebuffer,
|
||||
render_area: pso::Rect,
|
||||
clear_values: T,
|
||||
hal::SubpassContents::Inline,
|
||||
);*/
|
||||
let framebuffer = {
|
||||
let attachments = desc.color_attachments
|
||||
.iter()
|
||||
.map(|at| at.attachment)
|
||||
.chain(desc.depth_stencil_attachment.as_ref().map(|at| at.attachment))
|
||||
.map(|id| &view_guard.get(id).raw);
|
||||
device.raw
|
||||
.create_framebuffer(&render_pass, attachments, extent.unwrap())
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let rect = {
|
||||
let ex = extent.unwrap();
|
||||
hal::pso::Rect {
|
||||
x: 0,
|
||||
y: 0,
|
||||
w: ex.width as _,
|
||||
h: ex.height as _,
|
||||
}
|
||||
};
|
||||
let clear_values = desc.color_attachments
|
||||
.iter()
|
||||
.map(|at| {
|
||||
//TODO: integer types?
|
||||
let value = hal::command::ClearColor::Float(conv::map_color(at.clear_color));
|
||||
hal::command::ClearValueRaw::from(hal::command::ClearValue::Color(value))
|
||||
})
|
||||
.chain(desc.depth_stencil_attachment.map(|at| {
|
||||
let value = hal::command::ClearDepthStencil(at.clear_depth, at.clear_stencil);
|
||||
hal::command::ClearValueRaw::from(hal::command::ClearValue::DepthStencil(value))
|
||||
}));
|
||||
current_comb.begin_render_pass(
|
||||
&render_pass,
|
||||
&framebuffer,
|
||||
rect,
|
||||
clear_values,
|
||||
hal::command::SubpassContents::Inline,
|
||||
);
|
||||
|
||||
HUB.render_passes
|
||||
.lock()
|
||||
|
@ -1,6 +1,6 @@
|
||||
use hal;
|
||||
|
||||
use {Extent3d, binding_model, command, pipeline, resource};
|
||||
use {Color, Extent3d, binding_model, command, pipeline, resource};
|
||||
|
||||
|
||||
pub fn map_buffer_usage(
|
||||
@ -370,3 +370,7 @@ pub fn map_load_store_ops(load: command::LoadOp, store: command::StoreOp) -> hal
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_color(color: Color) -> hal::pso::ColorValue {
|
||||
[color.r, color.g, color.b, color.a]
|
||||
}
|
||||
|
@ -423,14 +423,14 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
|
||||
};
|
||||
|
||||
let blend_state_guard = HUB.blend_states.lock();
|
||||
let blend_state = unsafe { slice::from_raw_parts(desc.blend_state, desc.blend_state_length) }
|
||||
let blend_states = unsafe { slice::from_raw_parts(desc.blend_states, desc.blend_states_length) }
|
||||
.iter()
|
||||
.map(|id| blend_state_guard.get(id.clone()).raw)
|
||||
.collect();
|
||||
|
||||
let blender = hal::pso::BlendDesc {
|
||||
logic_op: None, // TODO
|
||||
targets: blend_state,
|
||||
targets: blend_states,
|
||||
};
|
||||
|
||||
let depth_stencil_state_guard = HUB.depth_stencil_states.lock();
|
||||
|
@ -247,8 +247,8 @@ pub struct RenderPipelineDescriptor {
|
||||
pub stages: *const PipelineStageDescriptor,
|
||||
pub stages_length: usize,
|
||||
pub primitive_topology: PrimitiveTopology,
|
||||
pub blend_state: *const BlendStateId,
|
||||
pub blend_state_length: usize,
|
||||
pub blend_states: *const BlendStateId,
|
||||
pub blend_states_length: usize,
|
||||
pub depth_stencil_state: DepthStencilStateId,
|
||||
pub attachment_state: AttachmentStateId,
|
||||
}
|
||||
|
@ -82,6 +82,7 @@ pub(crate) struct TextureView<B: hal::Backend> {
|
||||
pub raw: B::ImageView,
|
||||
pub source_id: Stored<TextureId>,
|
||||
pub format: TextureFormat,
|
||||
pub extent: hal::image::Extent,
|
||||
pub samples: hal::image::NumSamples,
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,11 @@ use std::ffi::CString;
|
||||
pub use wgn::{
|
||||
AdapterDescriptor, Color, CommandBufferDescriptor, DeviceDescriptor, Extensions, Extent3d,
|
||||
Origin3d, PowerPreference, ShaderModuleDescriptor, ShaderStage,
|
||||
BindGroupLayoutBinding, TextureFormat,
|
||||
BindGroupLayoutBinding, BindingType, TextureFormat,
|
||||
PrimitiveTopology, BlendStateDescriptor, ColorWriteFlags, DepthStencilStateDescriptor,
|
||||
RenderPassDescriptor, RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
|
||||
LoadOp, StoreOp,
|
||||
ShaderStageFlags_NONE, ShaderStageFlags_VERTEX, ShaderStageFlags_FRAGMENT, ShaderStageFlags_COMPUTE
|
||||
};
|
||||
|
||||
|
||||
@ -107,7 +108,7 @@ pub struct RenderPipelineDescriptor<'a> {
|
||||
pub layout: &'a PipelineLayout,
|
||||
pub stages: &'a [PipelineStageDescriptor<'a>],
|
||||
pub primitive_topology: PrimitiveTopology,
|
||||
pub blend_state: &'a [&'a BlendState],
|
||||
pub blend_states: &'a [&'a BlendState],
|
||||
pub depth_stencil_state: &'a DepthStencilState,
|
||||
pub attachment_state: &'a AttachmentState,
|
||||
}
|
||||
@ -170,10 +171,15 @@ impl Device {
|
||||
}
|
||||
|
||||
pub fn create_pipeline_layout(&self, desc: &PipelineLayoutDescriptor) -> PipelineLayout {
|
||||
//TODO: avoid allocation here
|
||||
let temp_layouts = desc.bind_group_layouts
|
||||
.iter()
|
||||
.map(|bgl| bgl.id)
|
||||
.collect::<Vec<_>>();
|
||||
PipelineLayout {
|
||||
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(),
|
||||
bind_group_layouts: temp_layouts.as_ptr(),
|
||||
bind_group_layouts_length: temp_layouts.len(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -214,14 +220,19 @@ impl Device {
|
||||
})
|
||||
.collect::<ArrayVec<[_; 2]>>();
|
||||
|
||||
let temp_blend_states = desc.blend_states
|
||||
.iter()
|
||||
.map(|bs| bs.id)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
RenderPipeline {
|
||||
id: wgn::wgpu_device_create_render_pipeline(self.id, &wgn::RenderPipelineDescriptor {
|
||||
layout: desc.layout.id,
|
||||
stages: stages.as_ptr(),
|
||||
stages_length: stages.len(),
|
||||
primitive_topology: desc.primitive_topology,
|
||||
blend_state: desc.blend_state.as_ptr() as *const _,
|
||||
blend_state_length: desc.blend_state.len(),
|
||||
blend_states: temp_blend_states.as_ptr(),
|
||||
blend_states_length: temp_blend_states.len(),
|
||||
depth_stencil_state: desc.depth_stencil_state.id,
|
||||
attachment_state: desc.attachment_state.id,
|
||||
}),
|
||||
|
Loading…
Reference in New Issue
Block a user