mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +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 = stages,
|
||||||
.stages_length = STAGES_LENGTH,
|
.stages_length = STAGES_LENGTH,
|
||||||
.primitive_topology = WGPUPrimitiveTopology_TriangleList,
|
.primitive_topology = WGPUPrimitiveTopology_TriangleList,
|
||||||
.blend_state = blend_state,
|
.blend_states = blend_state,
|
||||||
.blend_state_length = BLEND_STATE_LENGTH,
|
.blend_states_length = BLEND_STATE_LENGTH,
|
||||||
.depth_stencil_state = depth_stencil_state,
|
.depth_stencil_state = depth_stencil_state,
|
||||||
.attachment_state = attachment_state,
|
.attachment_state = attachment_state,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -43,7 +43,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||||
blend_state: &[
|
blend_states: &[
|
||||||
&blend_state0,
|
&blend_state0,
|
||||||
],
|
],
|
||||||
depth_stencil_state: &depth_stencil_state,
|
depth_stencil_state: &depth_stencil_state,
|
||||||
|
|||||||
@ -219,8 +219,8 @@ typedef struct {
|
|||||||
const WGPUPipelineStageDescriptor *stages;
|
const WGPUPipelineStageDescriptor *stages;
|
||||||
uintptr_t stages_length;
|
uintptr_t stages_length;
|
||||||
WGPUPrimitiveTopology primitive_topology;
|
WGPUPrimitiveTopology primitive_topology;
|
||||||
const WGPUBlendStateId *blend_state;
|
const WGPUBlendStateId *blend_states;
|
||||||
uintptr_t blend_state_length;
|
uintptr_t blend_states_length;
|
||||||
WGPUDepthStencilStateId depth_stencil_state;
|
WGPUDepthStencilStateId depth_stencil_state;
|
||||||
WGPUAttachmentStateId attachment_state;
|
WGPUAttachmentStateId attachment_state;
|
||||||
} WGPURenderPipelineDescriptor;
|
} WGPURenderPipelineDescriptor;
|
||||||
@ -304,7 +304,7 @@ WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id,
|
|||||||
WGPUComputePassId wgpu_command_buffer_begin_compute_pass(WGPUCommandBufferId command_buffer_id);
|
WGPUComputePassId wgpu_command_buffer_begin_compute_pass(WGPUCommandBufferId command_buffer_id);
|
||||||
|
|
||||||
WGPURenderPassId wgpu_command_buffer_begin_render_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);
|
WGPUCommandBufferId wgpu_compute_pass_end_pass(WGPUComputePassId pass_id);
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ pub use self::compute::*;
|
|||||||
pub use self::render::*;
|
pub use self::render::*;
|
||||||
|
|
||||||
use hal::{self, Device};
|
use hal::{self, Device};
|
||||||
|
use hal::command::RawCommandBuffer;
|
||||||
|
|
||||||
use {
|
use {
|
||||||
Color, Origin3d, Stored,
|
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 cmb = cmb_guard.get_mut(command_buffer_id);
|
||||||
let device_guard = HUB.devices.lock();
|
let device_guard = HUB.devices.lock();
|
||||||
let device = device_guard.get(cmb.device_id.0);
|
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 render_pass = {
|
||||||
let tracker = &mut cmb.texture_tracker;
|
let tracker = &mut cmb.texture_tracker;
|
||||||
let view_guard = HUB.texture_views.lock();
|
|
||||||
|
|
||||||
let depth_stencil_attachment = match desc.depth_stencil_attachment {
|
let depth_stencil_attachment = match desc.depth_stencil_attachment {
|
||||||
Some(ref at) => {
|
Some(ref at) => {
|
||||||
let view = view_guard.get(at.attachment);
|
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 query = tracker.query(view.source_id.0);
|
||||||
let (_, layout) = conv::map_texture_state(
|
let (_, layout) = conv::map_texture_state(
|
||||||
query.usage,
|
query.usage,
|
||||||
@ -125,6 +132,11 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|at| {
|
.map(|at| {
|
||||||
let view = view_guard.get(at.attachment);
|
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 query = tracker.query(view.source_id.0);
|
||||||
let (_, layout) = conv::map_texture_state(query.usage, hal::format::Aspects::COLOR);
|
let (_, layout) = conv::map_texture_state(query.usage, hal::format::Aspects::COLOR);
|
||||||
hal::pass::Attachment {
|
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), &[])
|
device.raw.create_render_pass(attachments, iter::once(subpass), &[])
|
||||||
};
|
};
|
||||||
//let framebuffer = device.create_framebuffer();
|
|
||||||
|
|
||||||
/*TODO:
|
let framebuffer = {
|
||||||
raw.begin_render_pass(
|
let attachments = desc.color_attachments
|
||||||
render_pass: &B::RenderPass,
|
.iter()
|
||||||
framebuffer: &B::Framebuffer,
|
.map(|at| at.attachment)
|
||||||
render_area: pso::Rect,
|
.chain(desc.depth_stencil_attachment.as_ref().map(|at| at.attachment))
|
||||||
clear_values: T,
|
.map(|id| &view_guard.get(id).raw);
|
||||||
hal::SubpassContents::Inline,
|
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
|
HUB.render_passes
|
||||||
.lock()
|
.lock()
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use hal;
|
use hal;
|
||||||
|
|
||||||
use {Extent3d, binding_model, command, pipeline, resource};
|
use {Color, Extent3d, binding_model, command, pipeline, resource};
|
||||||
|
|
||||||
|
|
||||||
pub fn map_buffer_usage(
|
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_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()
|
.iter()
|
||||||
.map(|id| blend_state_guard.get(id.clone()).raw)
|
.map(|id| blend_state_guard.get(id.clone()).raw)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let blender = hal::pso::BlendDesc {
|
let blender = hal::pso::BlendDesc {
|
||||||
logic_op: None, // TODO
|
logic_op: None, // TODO
|
||||||
targets: blend_state,
|
targets: blend_states,
|
||||||
};
|
};
|
||||||
|
|
||||||
let depth_stencil_state_guard = HUB.depth_stencil_states.lock();
|
let depth_stencil_state_guard = HUB.depth_stencil_states.lock();
|
||||||
|
|||||||
@ -247,8 +247,8 @@ pub struct RenderPipelineDescriptor {
|
|||||||
pub stages: *const PipelineStageDescriptor,
|
pub stages: *const PipelineStageDescriptor,
|
||||||
pub stages_length: usize,
|
pub stages_length: usize,
|
||||||
pub primitive_topology: PrimitiveTopology,
|
pub primitive_topology: PrimitiveTopology,
|
||||||
pub blend_state: *const BlendStateId,
|
pub blend_states: *const BlendStateId,
|
||||||
pub blend_state_length: usize,
|
pub blend_states_length: usize,
|
||||||
pub depth_stencil_state: DepthStencilStateId,
|
pub depth_stencil_state: DepthStencilStateId,
|
||||||
pub attachment_state: AttachmentStateId,
|
pub attachment_state: AttachmentStateId,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,6 +82,7 @@ pub(crate) struct TextureView<B: hal::Backend> {
|
|||||||
pub raw: B::ImageView,
|
pub raw: B::ImageView,
|
||||||
pub source_id: Stored<TextureId>,
|
pub source_id: Stored<TextureId>,
|
||||||
pub format: TextureFormat,
|
pub format: TextureFormat,
|
||||||
|
pub extent: hal::image::Extent,
|
||||||
pub samples: hal::image::NumSamples,
|
pub samples: hal::image::NumSamples,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,10 +8,11 @@ use std::ffi::CString;
|
|||||||
pub use wgn::{
|
pub use wgn::{
|
||||||
AdapterDescriptor, Color, CommandBufferDescriptor, DeviceDescriptor, Extensions, Extent3d,
|
AdapterDescriptor, Color, CommandBufferDescriptor, DeviceDescriptor, Extensions, Extent3d,
|
||||||
Origin3d, PowerPreference, ShaderModuleDescriptor, ShaderStage,
|
Origin3d, PowerPreference, ShaderModuleDescriptor, ShaderStage,
|
||||||
BindGroupLayoutBinding, TextureFormat,
|
BindGroupLayoutBinding, BindingType, TextureFormat,
|
||||||
PrimitiveTopology, BlendStateDescriptor, ColorWriteFlags, DepthStencilStateDescriptor,
|
PrimitiveTopology, BlendStateDescriptor, ColorWriteFlags, DepthStencilStateDescriptor,
|
||||||
RenderPassDescriptor, RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
|
RenderPassDescriptor, RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
|
||||||
LoadOp, StoreOp,
|
LoadOp, StoreOp,
|
||||||
|
ShaderStageFlags_NONE, ShaderStageFlags_VERTEX, ShaderStageFlags_FRAGMENT, ShaderStageFlags_COMPUTE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ pub struct RenderPipelineDescriptor<'a> {
|
|||||||
pub layout: &'a PipelineLayout,
|
pub layout: &'a PipelineLayout,
|
||||||
pub stages: &'a [PipelineStageDescriptor<'a>],
|
pub stages: &'a [PipelineStageDescriptor<'a>],
|
||||||
pub primitive_topology: PrimitiveTopology,
|
pub primitive_topology: PrimitiveTopology,
|
||||||
pub blend_state: &'a [&'a BlendState],
|
pub blend_states: &'a [&'a BlendState],
|
||||||
pub depth_stencil_state: &'a DepthStencilState,
|
pub depth_stencil_state: &'a DepthStencilState,
|
||||||
pub attachment_state: &'a AttachmentState,
|
pub attachment_state: &'a AttachmentState,
|
||||||
}
|
}
|
||||||
@ -170,10 +171,15 @@ impl Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_pipeline_layout(&self, desc: &PipelineLayoutDescriptor) -> PipelineLayout {
|
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 {
|
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: temp_layouts.as_ptr(),
|
||||||
bind_group_layouts_length: desc.bind_group_layouts.len(),
|
bind_group_layouts_length: temp_layouts.len(),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,14 +220,19 @@ impl Device {
|
|||||||
})
|
})
|
||||||
.collect::<ArrayVec<[_; 2]>>();
|
.collect::<ArrayVec<[_; 2]>>();
|
||||||
|
|
||||||
|
let temp_blend_states = desc.blend_states
|
||||||
|
.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(self.id, &wgn::RenderPipelineDescriptor {
|
||||||
layout: desc.layout.id,
|
layout: desc.layout.id,
|
||||||
stages: stages.as_ptr(),
|
stages: stages.as_ptr(),
|
||||||
stages_length: stages.len(),
|
stages_length: stages.len(),
|
||||||
primitive_topology: desc.primitive_topology,
|
primitive_topology: desc.primitive_topology,
|
||||||
blend_state: desc.blend_state.as_ptr() as *const _,
|
blend_states: temp_blend_states.as_ptr(),
|
||||||
blend_state_length: desc.blend_state.len(),
|
blend_states_length: temp_blend_states.len(),
|
||||||
depth_stencil_state: desc.depth_stencil_state.id,
|
depth_stencil_state: desc.depth_stencil_state.id,
|
||||||
attachment_state: desc.attachment_state.id,
|
attachment_state: desc.attachment_state.id,
|
||||||
}),
|
}),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user