Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Jiawei-Shao
Copy link
Contributor

@Jiawei-Shao Jiawei-Shao commented Mar 26, 2020

@Kangz
Copy link
Contributor

Kangz commented Mar 26, 2020

Thanks, it looks very good overall, I just wish the usage rules where grouped semantically, as right now it's difficult to make sure everything is handled. Maybe it could be:

the following validation rules apply.

For {{encoder}}:

 - encoder must be a valid GPUCommandEncoder.
 - ...

For source.buffer:

For source.texture:

For the copy being in-bounds:

For the texel block alignment:

For other source members:

For other destination members:

Copy link
Contributor

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Looks great! Just have a few notes

spec/index.bs Outdated
- If |source|.{{GPUBufferCopyView/bytesPerRow}} is 0, the number of |bytes in a complete row| must be a multiple of 256.
- |destination|.{{GPUTextureCopyView/mipLevel}} must be less than the {{GPUTexture/[[mipLevelCount]]}} of |destination|.{{GPUTextureCopyView/texture}}.
- |destination|.{{GPUTextureCopyView/arrayLayer}} must be less than the {{GPUTexture/[[textureSize]]}}.{{GPUExtent3DDict/depth}} of |destination|.{{GPUTextureCopyView/texture}}.
- {{GPUExtent3DDict/depth}} must be 1 when the {{GPUTexture/[[dimension]]}} of {{GPUTextureCopyView/texture}} is {{GPUTextureDimension/2d}}.
Copy link
Contributor

Choose a reason for hiding this comment

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

also, for GPUTextureDimension/1d

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually not true for 2d textures, because all 2d textures are semantically 2d texture arrays. Instead, this should just say the depth must be <= the texture's depth.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Metal only supports copying into one layer of a 2d texture:
https://developer.apple.com/documentation/metal/mtlblitcommandencoder/1400752-copyfrombuffer?language=objc
"when you copy to a 2D texture, depth must be 1."

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want to expose multi-layer copies, we can implement them as multiple copies when necessary

Copy link
Contributor

Choose a reason for hiding this comment

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

"when you copy to a 2D texture, depth must be 1."

I'm pretty sure this is talking about 2D non-array textures specifically.

That documentation is kind of confusing though. On sourceBytesPerImage it says:

For 3D textures and 2D array textures, the stride in bytes between 2D images of the source buffer memory. The value must be a multiple of the destination texture's pixel size, in bytes.

which strongly implies that copies into multiple layers of a 2D array texture is allowed. But destinationSlice doesn't say anything about it. I think destinationSlice is actually destinationFirstSlice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @JusSn @litherum, what do you think?

I also notice that in MoltenVK the multi-layer copy is implemented by an iteration over every layers in a for-loop.

spec/index.bs Outdated
- If |source|.{{GPUBufferCopyView/bytesPerRow}} is 0, the number of |bytes in a complete row| must be a multiple of 256.
- |destination|.{{GPUTextureCopyView/mipLevel}} must be less than the {{GPUTexture/[[mipLevelCount]]}} of |destination|.{{GPUTextureCopyView/texture}}.
- |destination|.{{GPUTextureCopyView/arrayLayer}} must be less than the {{GPUTexture/[[textureSize]]}}.{{GPUExtent3DDict/depth}} of |destination|.{{GPUTextureCopyView/texture}}.
- {{GPUExtent3DDict/depth}} must be 1 when the {{GPUTexture/[[dimension]]}} of {{GPUTextureCopyView/texture}} is {{GPUTextureDimension/2d}}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually not true for 2d textures, because all 2d textures are semantically 2d texture arrays. Instead, this should just say the depth must be <= the texture's depth.

spec/index.bs Outdated
Comment on lines 2624 to 2626
- |copySize|.[=Extent3D/width=] cannot be 0.
- |copySize|.[=Extent3D/height=] cannot be 0.
- |copySize|.[=Extent3D/depth=] cannot be 0.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found on D3D12 it is not allowed to specify copySize.width, copySize.height or copySize.depth to 0 when I was writing SPEC for copy commands, so here I suggest we not allow copySize.width, copySize.height or copySize.depth be 0.

Here are the error message reported from D3D12 validation layer:

D3D12 ERROR: ID3D12CommandList::CopyTextureRegion: D3D12_SUBRESOURCE_FOOTPRINT::Width, D3D12_SUBRESOURCE_FOOTPRINT::Height, and D3D12_SUBRESOURCE_FOOTPRINT::Depth cannot be 0. The minimum value is 1. Width = 64, Height = 0, and Depth = 1. [ RESOURCE_MANIPULATION ERROR #854: COPYTEXTUREREGION_INVALIDDSTDIMENSIONS]

Copy link
Contributor

Choose a reason for hiding this comment

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

Imho empty copies should be allowed, because making them noops is as much work as validating them out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you are suggesting that "it is no-op if any of the copySize.width, copySize.height or copySize.depth is 0"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but that can be non-normative ("Note: ...") because when we actually define the copies they'll probably be done as for-loops which describe that behavior.

Comment on lines 2495 to 2505
The following validation rules apply:
- |textureCopyView|.{{GPUTextureCopyView/texture}} must be a [=valid=] {{GPUTexture}}.
- The {{GPUTexture/[[sampleCount]]}} of |textureCopyView|.{{GPUTextureCopyView/texture}} must be 1.
- |textureCopyView|.{{GPUTextureCopyView/mipLevel}} must be less than the {{GPUTexture/[[mipLevelCount]]}} of
|textureCopyView|.{{GPUTextureCopyView/texture}}.
- If the |textureCopyView|.{{GPUTextureCopyView/texture}} is {{GPUTextureDimension/1d}} or {{GPUTextureDimension/3d}}:
- |textureCopyView|.{{GPUTextureCopyView/arrayLayer}} must be zero.
- If the {{GPUTexture/[[dimension]]}} of |textureCopyView|.{{GPUTextureCopyView/texture}} is {{GPUTextureDimension/2d}}:
- |textureCopyView|.{{GPUTextureCopyView/arrayLayer}} must be less than the {{GPUTexture/[[textureSize]]}}.[=Extent3D/depth=] of |textureCopyView|.{{GPUTextureCopyView/texture}}.
- |textureCopyView|.{{GPUTextureCopyView/origin}}.{{GPUOrigin3DDict/x}} must be a multiple of |blockWidth|.
- |textureCopyView|.{{GPUTextureCopyView/origin}}.{{GPUOrigin3DDict/y}} must be a multiple of |blockHeight|.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These rules are the same for both buffer-to-texture and texture-to-buffer copies so I decide to put it here.

@kainino0x
Copy link
Contributor

nit: Please mark comment threads as "resolved" when you resolve them so they get minimized; you can do that instead of commenting "Done". :)

Copy link
Contributor

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

Sorry for another huge review!! This is looking really good overall!

@Jiawei-Shao
Copy link
Contributor Author

OK. There are totally 5 TODOs:

  1. Always allow bytesPerRow == 0?
  2. Allow CopySize == 0? (D3D12 doesn't allow this)
  3. Allow copying multiple 2D array layers in one copy command? (Metal doesn't support this)
  4. Copy with 1D and 3D textures (need more investigation)
  5. Copy with depth stencil textures (Copying of depth24plus formats #652)

@kainino0x
Copy link
Contributor

There was agreement in the F2F here (based on my recollection - the minutes don't seem to capture it) that rowsPerImage=0 would only be allowed for 2d copies (there's no "tightly packed" mode for it). I thought we also agreed there would be no "tightly packed" mode for bytesPerRow but maybe @kvark @JusSn could give explicit approval on that (and the other issues).

Note that it would be a nonbreaking change to allow "0 = tightly packed" later on if we really find it's useful.

@kainino0x
Copy link
Contributor

kainino0x commented Apr 6, 2020

Resolutions from the meeting:

There are totally 5 TODOs:

  1. Always allow bytesPerRow == 0?

bytesPerRow = 0 has no special meaning. Have a rule saying two rows of the copy may not overlap, making 0 invalid if height>1.

rowsPerImage = 0 has no special meaning. Have a rule saying two images of the copy may not overlap, making 0 invalid if depth > 1.

  1. Allow CopySize == 0? (D3D12 doesn't allow this)

Yes, but don't explicitly call it out (except maybe in non-normative text). Just don't disallow CopySize=0.

  1. Allow copying multiple 2D array layers in one copy command? (Metal doesn't support this)

Yes.

  1. Copy with 1D and 3D textures (need more investigation)
  2. Copy with depth stencil textures (Copying of depth24plus formats #652)

Leave TODOs in the spec for now.

@Jiawei-Shao
Copy link
Contributor Author

Hi @kainino0x, I have updated all these changes in the latest commit. PTAL, thanks!

Copy link
Contributor

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

latest commit lgtm with nits, but I still have a bunch of open comments that I'd like to get resolved at some point.

I think we should merge this without those. I think I'll go ahead and take care of some syntax stuff right now.

@kainino0x
Copy link
Contributor

@kvark @JusSn would one of you like to do a quick review before we merge this and handle the remaining comments in followup?

@Jiawei-Shao
Copy link
Contributor Author

Hi @kainino0x, I have updated this PR. PTAL, thanks!

@kvark kvark self-requested a review April 8, 2020 19:02
texels, used when copying data from or to a {{GPUTexture}}.

- For {{GPUTextureDimension/2d}} textures, data is copied from or to one [=mipmap level=] and one [=array layer=] of the [=texture=].
A {{GPUTextureCopyView}} is a view of a sub-region of one or multiple contiguous [=texture=] [=subresources=] with the initial
Copy link
Contributor

Choose a reason for hiding this comment

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

we may need to put an Issue here to clarify what "contiguous" means.
I.e. if I select mipmaps 1-2 and array layers 1-2, is that sub-region contiguous?

@kvark kvark merged commit 03da857 into gpuweb:master Apr 8, 2020
@kainino0x
Copy link
Contributor

Last commit LGTM.

Jiawei, will you be able to take a followup to address the rest of the unresolved comments on this PR?

@Jiawei-Shao
Copy link
Contributor Author

@kainino0x @kvark @Kangz thanks for all your suggestions!

Jiawei, will you be able to take a followup to address the rest of the unresolved comments on this PR?

Yes I will. I plan to do further investigations after finishing another two PRs about the copy commmands (texture-to-buffer and texture-to-texture).

JusSn pushed a commit to JusSn/gpuweb that referenced this pull request Jun 8, 2020
* Add validation rules for copyBufferToTexture

* Small fix

* Address more reviewer's suggestions

* Address more comments from the reviewers

* Fix several typos
JusSn pushed a commit to JusSn/gpuweb that referenced this pull request Jun 8, 2020
* Add validation rules for copyBufferToTexture

* Small fix

* Address more reviewer's suggestions

* Address more comments from the reviewers

* Fix several typos
@kainino0x
Copy link
Contributor

@Jiawei-Shao I think the open issues on this PR are still open. Will you be able to take them?

Also, I just noticed that the rendered indentation for "For other members in layout:" in the spec right now is broken.

@Jiawei-Shao
Copy link
Contributor Author

@kainino0x Yes I will.

Here are the remaining two opens:

Also now we don't allow bytesPerRow==0 when height > 1, this rule should also be implemented in Dawn.

@kainino0x
Copy link
Contributor

I'm mainly talking about the copyediting issues outstanding above: indentation, naming, incorrect usage of [=valid=], redundant rules

ben-clayton pushed a commit to ben-clayton/gpuweb that referenced this pull request Sep 6, 2022
* Depth/stencil formats should be invalid for 3D textures

* Address feedback from Kai: need to revise test name or description

* Address feedback from Kai
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.

4 participants