Skip to content

Additional validation of texture copies #7935

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

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

andyleiserson
Copy link
Contributor

@andyleiserson andyleiserson commented Jul 12, 2025

In studying whether #2951 is still an issue, I identified some other texture validation that is missing. This adds it, and also fixes the issue where we skip parameter validation for zero-size copies. I suspect that this may fix #7844 by rejecting an illegal operation before dx12 panics. I've also included a fix for #7844 that splits depth+stencil copies into two operations, although I'm not sure if this is the right fix -- it appears that metal does support a combined copy in copyTextureToTexture (but not in copyBufferToTexture), so maybe this should be pushed to the backends.

Testing
Enables all the copyTextureToTexture CTS tests. However, the CTS isn't complete coverage of the validation logic I added. In particular, it doesn't cover the logic that allows copies among different aspects of the same texture. I'm not sure if that even makes sense (copying between depth and stencil?), or if it's just the spec being thorough, but I would welcome a suggestion of an interesting test to add here.

Squash or Rebase? Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry. Maybe it's worth one overall changelog entry mentioning this, the vertex/index buffer offset change, and any other added validation that gets added.

 * Copies must not overlap.
 * Copies of multisampled or depth/stencil formats must span
   the entire texture.
 * Move no-op for zero-size copies after parameter validation.

Closes gfx-rs#2951
Fixes gfx-rs#7844
@andyleiserson andyleiserson requested review from crowlKats and a team as code owners July 12, 2025 00:31
@andyleiserson andyleiserson force-pushed the texture-copy-validation branch from 0b8f788 to fa7961b Compare July 12, 2025 01:35
@sagudev
Copy link
Collaborator

sagudev commented Jul 12, 2025

However, the CTS isn't complete coverage of the validation logic I added

Sounds like we need to add more CTS tests.

Comment on lines 1215 to 1217
src_texture.desc.format,
destination,
dst_texture.desc.format,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The format of the textures is the same since src = dst.

/// `validate_texture_copy_range`.
///
/// [srtc]: https://gpuweb.github.io/gpuweb/#abstract-opdef-set-of-subresources-for-texture-copy
pub(crate) fn validate_copy_within_same_texture<T>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fn is not allowing disjoint mip levels but should, per spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed. I'll also open a PR to add this to the CTS (it was noted as a TODO, but not implemented).

buffer_layout: source.layout,
size: hal_copy_size,
},
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case shouldn't be allowed by validation (same for copyTextureToBuffer and writeTexture).

If texture.format is a depth-or-stencil format format:
texelCopyTextureInfo.aspect must refer to a single aspect of texture.format.

from "validating texture buffer copy"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, we only need this case for copyTextureToTexture.

@andyleiserson andyleiserson force-pushed the texture-copy-validation branch from fa7961b to 04cd49f Compare July 22, 2025 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[dx12] Panic in calc_subresource_for_copy on texture aspect copy
3 participants