mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-26 00:33:51 +00:00
Add check for bound pipeline
fix #456 Validate that a pipeline is bound before issuing draw/dispatch call.
This commit is contained in:
parent
09beda1942
commit
aef0c7c2c4
@ -19,6 +19,11 @@ use peek_poke::{Peek, PeekCopy, Poke};
|
||||
|
||||
use std::iter;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum PipelineState {
|
||||
Required,
|
||||
Set,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PeekCopy, Poke)]
|
||||
enum ComputeCommand {
|
||||
@ -76,6 +81,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let (buffer_guard, mut token) = hub.buffers.read(&mut token);
|
||||
let (texture_guard, _) = hub.textures.read(&mut token);
|
||||
|
||||
let mut pipeline_state = PipelineState::Required;
|
||||
|
||||
let mut peeker = raw_data.as_ptr();
|
||||
let raw_data_end = unsafe {
|
||||
raw_data.as_ptr().add(raw_data.len())
|
||||
@ -142,6 +149,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
}
|
||||
ComputeCommand::SetPipeline(pipeline_id) => {
|
||||
pipeline_state = PipelineState::Set;
|
||||
let pipeline = cmb.trackers
|
||||
.compute_pipes
|
||||
.use_extend(&*pipeline_guard, pipeline_id, (), ())
|
||||
@ -186,11 +194,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
}
|
||||
ComputeCommand::Dispatch(groups) => {
|
||||
assert_eq!(pipeline_state, PipelineState::Set, "Dispatch error: Pipeline is missing");
|
||||
unsafe {
|
||||
raw.dispatch(groups);
|
||||
}
|
||||
}
|
||||
ComputeCommand::DispatchIndirect { buffer_id, offset } => {
|
||||
assert_eq!(pipeline_state, PipelineState::Set, "Dispatch error: Pipeline is missing");
|
||||
let (src_buffer, src_pending) = cmb.trackers.buffers.use_replace(
|
||||
&*buffer_guard,
|
||||
buffer_id,
|
||||
|
@ -182,6 +182,7 @@ impl OptionalState {
|
||||
enum DrawError {
|
||||
MissingBlendColor,
|
||||
MissingStencilReference,
|
||||
MissingPipeline,
|
||||
IncompatibleBindGroup {
|
||||
index: u32,
|
||||
//expected: BindGroupLayoutId,
|
||||
@ -255,6 +256,7 @@ struct State {
|
||||
binder: Binder,
|
||||
blend_color: OptionalState,
|
||||
stencil_reference: OptionalState,
|
||||
pipeline: OptionalState,
|
||||
index: IndexState,
|
||||
vertex: VertexState,
|
||||
}
|
||||
@ -269,6 +271,9 @@ impl State {
|
||||
index: bind_mask.trailing_zeros(),
|
||||
});
|
||||
}
|
||||
if self.pipeline == OptionalState::Required {
|
||||
return Err(DrawError::MissingPipeline);
|
||||
}
|
||||
if self.blend_color == OptionalState::Required {
|
||||
return Err(DrawError::MissingBlendColor);
|
||||
}
|
||||
@ -785,6 +790,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
binder: Binder::new(cmb.features.max_bind_groups),
|
||||
blend_color: OptionalState::Unused,
|
||||
stencil_reference: OptionalState::Unused,
|
||||
pipeline: OptionalState::Required,
|
||||
index: IndexState {
|
||||
bound_buffer_view: None,
|
||||
format: IndexFormat::Uint16,
|
||||
@ -852,6 +858,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
};
|
||||
}
|
||||
RenderCommand::SetPipeline(pipeline_id) => {
|
||||
state.pipeline = OptionalState::Set;
|
||||
let pipeline = trackers
|
||||
.render_pipes
|
||||
.use_extend(&*pipeline_guard, pipeline_id, (), ())
|
||||
|
Loading…
Reference in New Issue
Block a user