Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] More vertex buffer validation #6804

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2901,18 +2901,8 @@ impl Device {
let mut shader_expects_dual_source_blending = false;
let mut pipeline_expects_dual_source_blending = false;
for (i, vb_state) in desc.vertex.buffers.iter().enumerate() {
let mut last_stride = 0;
for attribute in vb_state.attributes.iter() {
last_stride = last_stride.max(attribute.offset + attribute.format.size());
}
vertex_steps.push(pipeline::VertexStep {
stride: vb_state.array_stride,
last_stride,
mode: vb_state.step_mode,
});
if vb_state.attributes.is_empty() {
continue;
}
// https://gpuweb.github.io/gpuweb/#abstract-opdef-validating-gpuvertexbufferlayout

if vb_state.array_stride > self.limits.max_vertex_buffer_array_stride as u64 {
return Err(pipeline::CreateRenderPipelineError::VertexStrideTooLarge {
index: i as u32,
Expand All @@ -2926,6 +2916,46 @@ impl Device {
stride: vb_state.array_stride,
});
}
let mut last_stride = 0;
for attribute in vb_state.attributes.iter() {
if attribute.offset % attribute.format.size().min(4) != 0 {
sagudev marked this conversation as resolved.
Show resolved Hide resolved
return Err(
pipeline::CreateRenderPipelineError::InvalidVertexAttributeOffset {
location: attribute.shader_location,
offset: attribute.offset,
},
);
}
if attribute.shader_location >= self.limits.max_vertex_attributes {
return Err(
pipeline::CreateRenderPipelineError::TooManyVertexAttributes {
given: total_attributes as u32,
limit: self.limits.max_vertex_attributes,
},
);
}
last_stride = last_stride.max(attribute.offset + attribute.format.size());
}
let max_stride = if vb_state.array_stride == 0 {
self.limits.max_vertex_buffer_array_stride as u64
} else {
vb_state.array_stride
};
if last_stride > max_stride {
return Err(pipeline::CreateRenderPipelineError::VertexStrideTooLarge {
index: i as u32,
given: last_stride as u32,
limit: max_stride as u32,
});
sagudev marked this conversation as resolved.
Show resolved Hide resolved
}
vertex_steps.push(pipeline::VertexStep {
stride: vb_state.array_stride,
last_stride,
mode: vb_state.step_mode,
});
if vb_state.attributes.is_empty() {
continue;
}
vertex_buffers.push(hal::VertexBufferLayout {
array_stride: vb_state.array_stride,
step_mode: vb_state.step_mode,
Expand Down
Loading