mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-28 00:59:12 +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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user