Skip to content

Conversation

39ali
Copy link
Contributor

@39ali 39ali commented Jul 30, 2023

Checklist

  • Run cargo clippy.
  • Run cargo clippy --target wasm32-unknown-unknown if applicable.
  • Add change to CHANGELOG.md. See simple instructions inside file.

Connections
fixes #3072

Description
Fixes Queue::write_texture failing on the DX12 backend and added a new test to test writing/copying from different mipmap levels .
Testing
Run tests for write_texture.rs

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Great stuff, one minor nit

cwfitzgerald
cwfitzgerald previously approved these changes Aug 1, 2023
Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Nice!

@cwfitzgerald
Copy link
Member

Seems to not pass tests

@teoxoy
Copy link
Member

teoxoy commented Aug 2, 2023

I haven't looked at the details but we are now ignoring

self.buffer_layout.rows_per_image
self.buffer_layout.bytes_per_row
self.texture_base.aspect

@39ali
Copy link
Contributor Author

39ali commented Aug 2, 2023

@teoxoy self.texture_base.aspect is now being used , correct me if I'm wrong but I believe rows_per_image and bytes_per_row are redundant since they're being calculated by GetCopyableFootprints.

@teoxoy
Copy link
Member

teoxoy commented Aug 2, 2023

rows_per_image and bytes_per_row are passed by the user and they can be higher than the minimum required to perform the copy, so we can't assume they will be the minimum.

Related: https://gpuweb.github.io/gpuweb/#abstract-opdef-validating-linear-texture-data

@teoxoy
Copy link
Member

teoxoy commented Aug 2, 2023

I doubt we can use GetCopyableFootprints as it seems to calculate the minimums.

But maybe we can use it to figure out why our calculations were wrong previously by comparing their outputs.

@39ali
Copy link
Contributor Author

39ali commented Aug 2, 2023

@teoxoy looks like it, I'll look into it.

@39ali 39ali force-pushed the write_texture_subset_dx12 branch from 9eb78c7 to d655986 Compare August 4, 2023 23:21
@39ali 39ali force-pushed the write_texture_subset_dx12 branch from 5096e23 to 013f712 Compare August 26, 2023 16:04
@39ali 39ali force-pushed the write_texture_subset_dx12 branch from 013f712 to 995aaf7 Compare August 26, 2023 16:18
@39ali
Copy link
Contributor Author

39ali commented Aug 26, 2023

ran all tests and it's working as expected


let total_bytes_in_copy = total_bytes_in_copy(format, bytes_per_row, rows_per_image, copy_size);

test(
Copy link
Member

Choose a reason for hiding this comment

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

The dimension is hardcoded to be wgpu::TextureDimension::D2 but should be 3d for this test.

mips_count,
tex_size,
copy_size,
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.

Suggested change
copy_size,
tex_size,

We should copy back the whole texture.


let val = (mip_level + 1) as u8;
let data = vec![val; total_size_in_bytes as usize];

// Write the first two rows
Copy link
Member

Choose a reason for hiding this comment

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

Comment is outdated.

);

ctx.queue.submit(None);

let read_buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: (size * size) as u64,
size: (total_size_in_bytes) as u64,
Copy link
Member

Choose a reason for hiding this comment

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

Should be large enough to copy back the whole texture.

Comment on lines +159 to +161
tex_size,
tex_size,
tex_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 test seems to now copy the whole texture instead of a subset (prev. height: 2).

Height: self
.buffer_layout
.rows_per_image
.map_or(self.size.height, |count| count * block_height),
Height: self.size.height,
Copy link
Member

Choose a reason for hiding this comment

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

This looks correct but I'm not sure what happens if you copy a 3D texture with a non-default rows_per_image.
We have RowPitch but no ColPitch.
Vulkan has bufferImageHeight and Metal has sourceBytesPerImage.

@cwfitzgerald any ideas?

Copy link
Member

Choose a reason for hiding this comment

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

Dawn appears to issue one copy per layer, though I'm not 100% sure on this, as dawn has a lot of layers to their d3d12 copy code.

It seems like we should issue one copy if it's dense, otherwise one copy per subresource if it's not

Copy link
Member

Choose a reason for hiding this comment

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

That's my conclusion as well, Vulkan and Metal support specifying rows_per_image for 3D textures but D3D12 doesn't.
So, for a non-default rows_per_image we should set depth: 1 and issue multiple copies by advancing D3D12_PLACED_SUBRESOURCE_FOOTPRINT.Offset by rows_per_image * depth_index.

This is a pre-existing issue, will open an issue to track it.

Copy link
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

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

Marking as "Request changes"

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] Get test write_texture_subset to pass with dx12
3 participants