Skip to content

Commit

Permalink
Update TextureView validation (#3410)
Browse files Browse the repository at this point in the history
* update TextureView validation

* add changelog entry

* remove call to clone

* dereference instead
  • Loading branch information
teoxoy authored Jan 24, 2023
1 parent 5a999e6 commit 964c94a
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 139 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ let texture = device.create_texture(&wgpu::TextureDescriptor {
- Add validation in accordance with WebGPU `GPUSamplerDescriptor` valid usage for `lodMinClamp` and `lodMaxClamp`. By @James2022-rgb in [#3353](https://github.com/gfx-rs/wgpu/pull/3353)
- Remove panics in `Deref` implementations for `QueueWriteBufferView` and `BufferViewMut`. Instead, warnings are logged, since reading from these types is not recommended. By @botahamec in [#3336]
- Implement `view_formats` in TextureDescriptor to match the WebGPU spec. By @jinleili in [#3237](https://github.com/gfx-rs/wgpu/pull/3237)
- Update `TextureView` validation according to the WebGPU spec. By @teoxoy in [#3410](https://github.com/gfx-rs/wgpu/pull/3410)

#### WebGPU

Expand Down
5 changes: 2 additions & 3 deletions wgpu-core/src/command/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
if let Some(ref mut list) = cmd_buf.commands {
list.push(TraceCommand::ClearTexture {
dst,
subresource_range: subresource_range.clone(),
subresource_range: *subresource_range,
});
}

Expand Down Expand Up @@ -408,9 +408,8 @@ fn clear_texture_via_render_passes<A: hal::Api>(
};

let sample_count = dst_texture.desc.sample_count;
let is_3d_texture = dst_texture.desc.dimension == wgt::TextureDimension::D3;
for mip_level in range.mip_range {
let extent = extent_base.mip_level_size(mip_level, is_3d_texture);
let extent = extent_base.mip_level_size(mip_level, dst_texture.desc.dimension);
let layer_or_depth_range = if dst_texture.desc.dimension == wgt::TextureDimension::D3 {
// TODO: We assume that we're allowed to do clear operations on
// volume texture slices, this is not properly specified.
Expand Down
21 changes: 15 additions & 6 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ pub enum RenderPassErrorInner {
UnsupportedResolveTargetFormat(wgt::TextureFormat),
#[error("missing color or depth_stencil attachments, at least one is required.")]
MissingAttachments,
#[error("attachment texture view is not renderable")]
TextureViewIsNotRenderable,
#[error("attachments have differing sizes: {previous:?} is followed by {mismatch:?}")]
AttachmentsDimensionMismatch {
previous: (&'static str, wgt::Extent3d),
Expand Down Expand Up @@ -714,15 +716,18 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
Ok(())
};
let mut add_view = |view: &TextureView<A>, type_name| {
let render_extent = view
.render_extent
.ok_or(RenderPassErrorInner::TextureViewIsNotRenderable)?;
if let Some(ex) = extent {
if ex != view.extent {
if ex != render_extent {
return Err(RenderPassErrorInner::AttachmentsDimensionMismatch {
previous: (attachment_type_name, ex),
mismatch: (type_name, view.extent),
mismatch: (type_name, render_extent),
});
}
} else {
extent = Some(view.extent);
extent = Some(render_extent);
}
if sample_count == 0 {
sample_count = view.samples;
Expand Down Expand Up @@ -910,10 +915,14 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
.ok_or(RenderPassErrorInner::InvalidAttachment(resolve_target))?;

check_multiview(resolve_view)?;
if color_view.extent != resolve_view.extent {

let render_extent = resolve_view
.render_extent
.ok_or(RenderPassErrorInner::TextureViewIsNotRenderable)?;
if color_view.render_extent.unwrap() != render_extent {
return Err(RenderPassErrorInner::AttachmentsDimensionMismatch {
previous: (attachment_type_name, extent.unwrap_or_default()),
mismatch: ("resolve", resolve_view.extent),
mismatch: ("resolve", render_extent),
});
}
if color_view.samples == 1 || resolve_view.samples != 1 {
Expand Down Expand Up @@ -1071,7 +1080,7 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
};
let desc = hal::RenderPassDescriptor {
label: Some("(wgpu internal) Zero init discarded depth/stencil aspect"),
extent: view.extent,
extent: view.render_extent.unwrap(),
sample_count: view.samples,
color_attachments: &[],
depth_stencil_attachment: Some(hal::DepthStencilAttachment {
Expand Down
Loading

0 comments on commit 964c94a

Please sign in to comment.