Add check for bound pipeline

fix #456
Validate that a pipeline is bound before issuing
draw/dispatch call.
This commit is contained in:
Kunal Mohan 2020-04-05 11:16:50 +05:30
parent 09beda1942
commit aef0c7c2c4
No known key found for this signature in database
GPG Key ID: 2B475A4524237BAC
2 changed files with 17 additions and 0 deletions

View File

@ -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,

View File

@ -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, (), ())