mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 22:11:01 +01:00
Basic render pipeline compatibility check
This commit is contained in:
1 parent
152fad43c3
commit
650bbaeb42
4 files changed
+77
-43
No files matched your search
@@ -10,7 +10,7 @@ pub use self::render::*;
|
||||
pub use self::transfer::*;
|
||||
|
||||
use crate::device::{
|
||||
FramebufferKey, RenderPassKey,
|
||||
FramebufferKey, RenderPassKey, RenderPassContext,
|
||||
all_buffer_stages, all_image_stages,
|
||||
};
|
||||
use crate::hub::{HUB, Storage};
|
||||
@@ -190,7 +190,7 @@ pub fn command_encoder_begin_render_pass(
|
||||
let trackers = &mut cmb.trackers;
|
||||
let swap_chain_links = &mut cmb.swap_chain_links;
|
||||
|
||||
let depth_stencil_key = depth_stencil_attachment.map(|at| {
|
||||
let depth_stencil = depth_stencil_attachment.map(|at| {
|
||||
let view = &view_guard[at.attachment];
|
||||
if let Some(ex) = extent {
|
||||
assert_eq!(ex, view.extent);
|
||||
@@ -257,7 +257,8 @@ pub fn command_encoder_begin_render_pass(
|
||||
});
|
||||
|
||||
RenderPassKey {
|
||||
attachments: color_keys.chain(depth_stencil_key).collect(),
|
||||
colors: color_keys.collect(),
|
||||
depth_stencil,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -287,7 +288,7 @@ pub fn command_encoder_begin_render_pass(
|
||||
let pass = unsafe {
|
||||
device
|
||||
.raw
|
||||
.create_render_pass(&e.key().attachments, &[subpass], &[])
|
||||
.create_render_pass(e.key().all(), &[subpass], &[])
|
||||
}
|
||||
.unwrap();
|
||||
e.insert(pass)
|
||||
@@ -296,13 +297,12 @@ pub fn command_encoder_begin_render_pass(
|
||||
|
||||
let mut framebuffer_cache = device.framebuffers.lock();
|
||||
let fb_key = FramebufferKey {
|
||||
attachments: color_attachments
|
||||
colors: color_attachments
|
||||
.iter()
|
||||
.map(|at| at.attachment)
|
||||
.chain(
|
||||
depth_stencil_attachment.map(|at| at.attachment),
|
||||
)
|
||||
.collect(),
|
||||
depth_stencil: depth_stencil_attachment
|
||||
.map(|at| at.attachment),
|
||||
};
|
||||
let framebuffer = match framebuffer_cache.entry(fb_key) {
|
||||
Entry::Occupied(e) => e.into_mut(),
|
||||
@@ -310,8 +310,7 @@ pub fn command_encoder_begin_render_pass(
|
||||
let fb = {
|
||||
let attachments = e
|
||||
.key()
|
||||
.attachments
|
||||
.iter()
|
||||
.all()
|
||||
.map(|&id| &view_guard[id].raw);
|
||||
|
||||
unsafe {
|
||||
@@ -362,12 +361,22 @@ pub fn command_encoder_begin_render_pass(
|
||||
}));
|
||||
}
|
||||
|
||||
let context = RenderPassContext {
|
||||
colors: color_attachments
|
||||
.iter()
|
||||
.map(|at| view_guard[at.attachment].format)
|
||||
.collect(),
|
||||
depth_stencil: depth_stencil_attachment
|
||||
.map(|at| view_guard[at.attachment].format),
|
||||
};
|
||||
|
||||
RenderPass::new(
|
||||
current_comb,
|
||||
Stored {
|
||||
value: command_encoder_id,
|
||||
ref_count: cmb.life_guard.ref_count.clone(),
|
||||
},
|
||||
context,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::command::bind::Binder;
|
||||
use crate::device::RenderPassContext;
|
||||
use crate::hub::HUB;
|
||||
use crate::resource::BufferUsageFlags;
|
||||
use crate::resource::{BufferUsageFlags};
|
||||
use crate::track::{Stitch, TrackerSet};
|
||||
use crate::{
|
||||
CommandBuffer, Stored,
|
||||
@@ -15,15 +16,21 @@ use std::{iter, slice};
|
||||
pub struct RenderPass<B: hal::Backend> {
|
||||
raw: B::CommandBuffer,
|
||||
cmb_id: Stored<CommandBufferId>,
|
||||
context: RenderPassContext,
|
||||
binder: Binder,
|
||||
trackers: TrackerSet,
|
||||
}
|
||||
|
||||
impl<B: hal::Backend> RenderPass<B> {
|
||||
pub(crate) fn new(raw: B::CommandBuffer, cmb_id: Stored<CommandBufferId>) -> Self {
|
||||
pub(crate) fn new(
|
||||
raw: B::CommandBuffer,
|
||||
cmb_id: Stored<CommandBufferId>,
|
||||
context: RenderPassContext,
|
||||
) -> Self {
|
||||
RenderPass {
|
||||
raw,
|
||||
cmb_id,
|
||||
context,
|
||||
binder: Binder::default(),
|
||||
trackers: TrackerSet::new(),
|
||||
}
|
||||
@@ -202,6 +209,9 @@ pub extern "C" fn wgpu_render_pass_set_pipeline(
|
||||
let pipeline_guard = HUB.render_pipelines.read();
|
||||
let pipeline = &pipeline_guard[pipeline_id];
|
||||
|
||||
assert_eq!(pass.context, pipeline.pass_context,
|
||||
"The render pipeline is not compatible with the pass!");
|
||||
|
||||
unsafe {
|
||||
pass.raw.bind_graphics_pipeline(&pipeline.raw);
|
||||
}
|
||||
|
||||
+44
-31
@@ -35,8 +35,6 @@ use std::collections::hash_map::Entry;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
|
||||
type AttachmentVec<T> = ArrayVec<[T; 5]>;
|
||||
|
||||
pub fn all_buffer_stages() -> hal::pso::PipelineStage {
|
||||
use hal::pso::PipelineStage as Ps;
|
||||
Ps::DRAW_INDIRECT |
|
||||
@@ -58,17 +56,21 @@ pub fn all_image_stages() -> hal::pso::PipelineStage {
|
||||
Ps::TRANSFER
|
||||
}
|
||||
|
||||
#[derive(Hash, PartialEq)]
|
||||
pub(crate) struct RenderPassKey {
|
||||
pub attachments: AttachmentVec<hal::pass::Attachment>,
|
||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
||||
pub(crate) struct AttachmentData<T> {
|
||||
pub colors: ArrayVec<[T; 4]>,
|
||||
pub depth_stencil: Option<T>,
|
||||
}
|
||||
impl<T: PartialEq> Eq for AttachmentData<T> {}
|
||||
impl<T> AttachmentData<T> {
|
||||
pub(crate) fn all(&self) -> impl Iterator<Item = &T> {
|
||||
self.colors.iter().chain(&self.depth_stencil)
|
||||
}
|
||||
}
|
||||
impl Eq for RenderPassKey {}
|
||||
|
||||
#[derive(Clone, Hash, PartialEq)]
|
||||
pub(crate) struct FramebufferKey {
|
||||
pub attachments: AttachmentVec<TextureViewId>,
|
||||
}
|
||||
impl Eq for FramebufferKey {}
|
||||
pub(crate) type RenderPassKey = AttachmentData<hal::pass::Attachment>;
|
||||
pub(crate) type FramebufferKey = AttachmentData<TextureViewId>;
|
||||
pub(crate) type RenderPassContext = AttachmentData<resource::TextureFormat>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum ResourceId {
|
||||
@@ -241,7 +243,7 @@ impl DestroyedResources<back::Backend> {
|
||||
.keys()
|
||||
.filter_map(|key| {
|
||||
let mut last_submit: SubmissionIndex = 0;
|
||||
for &at in &key.attachments {
|
||||
for &at in key.all() {
|
||||
if texture_view_guard.contains(at) {
|
||||
return None
|
||||
}
|
||||
@@ -1216,24 +1218,25 @@ pub fn device_create_render_pipeline(
|
||||
desc.depth_stencil_state.as_ref()
|
||||
};
|
||||
|
||||
let rp_key = {
|
||||
let color_keys = color_states.iter().map(|at| hal::pass::Attachment {
|
||||
format: Some(conv::map_texture_format(at.format)),
|
||||
samples: desc.sample_count as u8,
|
||||
ops: hal::pass::AttachmentOps::PRESERVE,
|
||||
stencil_ops: hal::pass::AttachmentOps::DONT_CARE,
|
||||
layouts: hal::image::Layout::General..hal::image::Layout::General,
|
||||
});
|
||||
let depth_stencil_key = depth_stencil_state.map(|at| hal::pass::Attachment {
|
||||
format: Some(conv::map_texture_format(at.format)),
|
||||
samples: desc.sample_count as u8,
|
||||
ops: hal::pass::AttachmentOps::PRESERVE,
|
||||
stencil_ops: hal::pass::AttachmentOps::PRESERVE,
|
||||
layouts: hal::image::Layout::General..hal::image::Layout::General,
|
||||
});
|
||||
RenderPassKey {
|
||||
attachments: color_keys.chain(depth_stencil_key).collect(),
|
||||
}
|
||||
let rp_key = RenderPassKey {
|
||||
colors: color_states
|
||||
.iter()
|
||||
.map(|at| hal::pass::Attachment {
|
||||
format: Some(conv::map_texture_format(at.format)),
|
||||
samples: desc.sample_count as u8,
|
||||
ops: hal::pass::AttachmentOps::PRESERVE,
|
||||
stencil_ops: hal::pass::AttachmentOps::DONT_CARE,
|
||||
layouts: hal::image::Layout::General..hal::image::Layout::General,
|
||||
})
|
||||
.collect(),
|
||||
depth_stencil: depth_stencil_state
|
||||
.map(|at| hal::pass::Attachment {
|
||||
format: Some(conv::map_texture_format(at.format)),
|
||||
samples: desc.sample_count as u8,
|
||||
ops: hal::pass::AttachmentOps::PRESERVE,
|
||||
stencil_ops: hal::pass::AttachmentOps::PRESERVE,
|
||||
layouts: hal::image::Layout::General..hal::image::Layout::General,
|
||||
}),
|
||||
};
|
||||
|
||||
let mut render_pass_cache = device.render_passes.lock();
|
||||
@@ -1262,7 +1265,7 @@ pub fn device_create_render_pipeline(
|
||||
let pass = unsafe {
|
||||
device
|
||||
.raw
|
||||
.create_render_pass(&e.key().attachments, &[subpass], &[])
|
||||
.create_render_pass(e.key().all(), &[subpass], &[])
|
||||
}
|
||||
.unwrap();
|
||||
e.insert(pass)
|
||||
@@ -1395,9 +1398,19 @@ pub fn device_create_render_pipeline(
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let pass_context = RenderPassContext {
|
||||
colors: color_states
|
||||
.iter()
|
||||
.map(|state| state.format)
|
||||
.collect(),
|
||||
depth_stencil: depth_stencil_state
|
||||
.map(|state| state.format),
|
||||
};
|
||||
|
||||
pipeline::RenderPipeline {
|
||||
raw: pipeline,
|
||||
layout_id: desc.layout,
|
||||
pass_context,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::device::RenderPassContext;
|
||||
use crate::resource;
|
||||
use crate::{
|
||||
ByteArray, PipelineLayoutId, ShaderModuleId,
|
||||
@@ -280,4 +281,5 @@ pub struct RenderPipelineDescriptor {
|
||||
pub struct RenderPipeline<B: hal::Backend> {
|
||||
pub(crate) raw: B::GraphicsPipeline,
|
||||
pub(crate) layout_id: PipelineLayoutId,
|
||||
pub(crate) pass_context: RenderPassContext,
|
||||
}
|
||||
Reference in new issue
Block a user