Commit-Queue | +1 |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
LGTM
kUsage, kUsage, image, image_info,
Why isn't this one None for now as well?
// Add on any internal-usage flags that aren't already present in `usage`.
internal_usage_flags = static_cast<WGPUTextureUsage>(
static_cast<int>(internal_usage_flags) & ~static_cast<int>(usage));
WGPUDawnTextureInternalUsageDescriptor internal_usage_desc = {};
IMHO it's not really necessary to actually remove the extra usages that are already specified.
internal_usage_desc.internalUsage = internal_usage_flags,
I think we need to set the sType here otherwise Dawn won't know what the structure is. (in the C++ binding this is done for you, but we are still in the process of making Blink use them)
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Why isn't this one None for now as well?
Done.
(Both have the same effect, and it will change in the next CL anyway)
// Add on any internal-usage flags that aren't already present in `usage`.
internal_usage_flags = static_cast<WGPUTextureUsage>(
static_cast<int>(internal_usage_flags) & ~static_cast<int>(usage));
WGPUDawnTextureInternalUsageDescriptor internal_usage_desc = {};
IMHO it's not really necessary to actually remove the extra usages that are already specified.
Done.
Masking-off step removed
internal_usage_desc.internalUsage = internal_usage_flags,
I think we need to set the sType here otherwise Dawn won't know what the structure is. (in the C++ binding this is done for you, but we are still in the process of making Blink use them)
Thanks, good catch :) Done.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
Looks good, about from a nit and a few questions.
WGPUTextureUsage internal_usage_flags,
Just wondering: why is this API using the C version of the enum instead of the C++ version? The C++ version is vastly more popular, with [2746](https://source.chromium.org/search?q=%5CbTextureUsage::%5Cw%2B%5Cb&sq=&ss=chromium) Code Search results vs. [121](https://source.chromium.org/search?q=%5CbWGPUTextureUsage_%5Cw%2B%5Cb&ss=chromium).
WGPUTextureDescriptor tex_desc = {};
tex_desc.usage = usage;
tex_desc.dimension = WGPUTextureDimension_2D;
tex_desc.size.width = size.width();
tex_desc.size.height = size.height();
tex_desc.format = VizToWGPUFormat(canvas_resource->GetSharedImageFormat());
Drive-by and unrelated to this CL: couldn't this be initialized with designated initializers, instead of default-initializing and then assigning?
https://abseil.io/tips/172
internal_usage_desc.chain.sType = WGPUSType_DawnTextureInternalUsageDescriptor;
Nit: keep within 80 characters to prevent wrapping?
tex_desc.nextInChain = &internal_usage_desc.chain;
I was worried about this pointer being used after the function terminates, but looking in Code Search, it looks like it's not used at all. Is this coming in a future change? Or am I missing something?
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
tex_desc.nextInChain = &internal_usage_desc.chain;
I was worried about this pointer being used after the function terminates, but looking in Code Search, it looks like it's not used at all. Is this coming in a future change? Or am I missing something?
Which pointer are you saying isn't used exactly? I'm not sure what you mean.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
WGPUTextureUsage internal_usage_flags,
Just wondering: why is this API using the C version of the enum instead of the C++ version? The C++ version is vastly more popular, with [2746](https://source.chromium.org/search?q=%5CbTextureUsage::%5Cw%2B%5Cb&sq=&ss=chromium) Code Search results vs. [121](https://source.chromium.org/search?q=%5CbWGPUTextureUsage_%5Cw%2B%5Cb&ss=chromium).
`WGPU` is part of Blink, `wgpu::` is part of Dawn. Blink wraps Dawn in a large set of parallel classes/types/etc.
Code-Review | +0 |
WGPUTextureUsage internal_usage_flags,
Just wondering: why is this API using the C version of the enum instead of the C++ version? The C++ version is vastly more popular, with [2746](https://source.chromium.org/search?q=%5CbTextureUsage::%5Cw%2B%5Cb&sq=&ss=chromium) Code Search results vs. [121](https://source.chromium.org/search?q=%5CbWGPUTextureUsage_%5Cw%2B%5Cb&ss=chromium).
Somewhat historical reasons, it will be fixed very soon as https://chromium-review.googlesource.com/c/chromium/src/+/5460722 lands
tex_desc.nextInChain = &internal_usage_desc.chain;
I was worried about this pointer being used after the function terminates, but looking in Code Search, it looks like it's not used at all. Is this coming in a future change? Or am I missing something?
Uh right, I was surprised that the sType missing didn't cause crashes. John do you have tests that unsupported usages are actually not supported but CopySrc is?
It seems like we might need to add an internalUsage argument to AssociateMailbox and handle it in webgpu_decoder_impl.cc and all the SI stuff. +CC Austin, any concern with adding this?
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
WGPUTextureUsage internal_usage_flags,
Corentin WallezJust wondering: why is this API using the C version of the enum instead of the C++ version? The C++ version is vastly more popular, with [2746](https://source.chromium.org/search?q=%5CbTextureUsage::%5Cw%2B%5Cb&sq=&ss=chromium) Code Search results vs. [121](https://source.chromium.org/search?q=%5CbWGPUTextureUsage_%5Cw%2B%5Cb&ss=chromium).
Somewhat historical reasons, it will be fixed very soon as https://chromium-review.googlesource.com/c/chromium/src/+/5460722 lands
Oh, that's exciting! I didn't realize we were going to migrate all these. That is a solid improvement.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
tex_desc.nextInChain = &internal_usage_desc.chain;
Corentin WallezI was worried about this pointer being used after the function terminates, but looking in Code Search, it looks like it's not used at all. Is this coming in a future change? Or am I missing something?
Uh right, I was surprised that the sType missing didn't cause crashes. John do you have tests that unsupported usages are actually not supported but CopySrc is?
It seems like we might need to add an internalUsage argument to AssociateMailbox and handle it in webgpu_decoder_impl.cc and all the SI stuff. +CC Austin, any concern with adding this?
You're right, at one point I had thought that `desc` was passed in and the `nextInChain` would automatically kick in, but I see now that `AssociateMailbox` takes `desc.usage` directly and not the entire `desc`, so it isn't going to see the rest of the chain.
WGPUTextureUsage internal_usage_flags,
Corentin WallezJust wondering: why is this API using the C version of the enum instead of the C++ version? The C++ version is vastly more popular, with [2746](https://source.chromium.org/search?q=%5CbTextureUsage::%5Cw%2B%5Cb&sq=&ss=chromium) Code Search results vs. [121](https://source.chromium.org/search?q=%5CbWGPUTextureUsage_%5Cw%2B%5Cb&ss=chromium).
John StilesSomewhat historical reasons, it will be fixed very soon as https://chromium-review.googlesource.com/c/chromium/src/+/5460722 lands
Oh, that's exciting! I didn't realize we were going to migrate all these. That is a solid improvement.
Acknowledged
WGPUTextureDescriptor tex_desc = {};
tex_desc.usage = usage;
tex_desc.dimension = WGPUTextureDimension_2D;
tex_desc.size.width = size.width();
tex_desc.size.height = size.height();
tex_desc.format = VizToWGPUFormat(canvas_resource->GetSharedImageFormat());
Drive-by and unrelated to this CL: couldn't this be initialized with designated initializers, instead of default-initializing and then assigning?
https://abseil.io/tips/172
So, this actually has nested structures and type narrowing, so it's not quite a 1:1 replacement. It ends up looking like this:
```
WGPUTextureDescriptor tex_desc = {
.usage = usage,
.dimension = WGPUTextureDimension_2D,
.size = {.width = static_cast<uint32_t>(size.width()),
.height = static_cast<uint32_t>(size.height())},
.format = VizToWGPUFormat(canvas_resource->GetSharedImageFormat()),
};
```
WDYT, is this an improvement? To my eyes it's less readable overall (the casts add more noise/clutter than the removal of `tex_desc.` saves IMO) but I am not particular and will defer to your opinion.
+jpgravel@ for OWNERS in canvas2D
Acknowledged
WGPUTextureDescriptor tex_desc = {};
tex_desc.usage = usage;
tex_desc.dimension = WGPUTextureDimension_2D;
tex_desc.size.width = size.width();
tex_desc.size.height = size.height();
tex_desc.format = VizToWGPUFormat(canvas_resource->GetSharedImageFormat());
John StilesDrive-by and unrelated to this CL: couldn't this be initialized with designated initializers, instead of default-initializing and then assigning?
https://abseil.io/tips/172
So, this actually has nested structures and type narrowing, so it's not quite a 1:1 replacement. It ends up looking like this:
```
WGPUTextureDescriptor tex_desc = {
.usage = usage,
.dimension = WGPUTextureDimension_2D,
.size = {.width = static_cast<uint32_t>(size.width()),
.height = static_cast<uint32_t>(size.height())},
.format = VizToWGPUFormat(canvas_resource->GetSharedImageFormat()),
};
```WDYT, is this an improvement? To my eyes it's less readable overall (the casts add more noise/clutter than the removal of `tex_desc.` saves IMO) but I am not particular and will defer to your opinion.
PTAL
internal_usage_desc.chain.sType = WGPUSType_DawnTextureInternalUsageDescriptor;
Nit: keep within 80 characters to prevent wrapping?
Done
tex_desc.nextInChain = &internal_usage_desc.chain;
Corentin WallezI was worried about this pointer being used after the function terminates, but looking in Code Search, it looks like it's not used at all. Is this coming in a future change? Or am I missing something?
John StilesUh right, I was surprised that the sType missing didn't cause crashes. John do you have tests that unsupported usages are actually not supported but CopySrc is?
It seems like we might need to add an internalUsage argument to AssociateMailbox and handle it in webgpu_decoder_impl.cc and all the SI stuff. +CC Austin, any concern with adding this?
You're right, at one point I had thought that `desc` was passed in and the `nextInChain` would automatically kick in, but I see now that `AssociateMailbox` takes `desc.usage` directly and not the entire `desc`, so it isn't going to see the rest of the chain.
Looking at it, the rabbit hole for `AssociateMailbox` goes very deep. I'd like enga@'s input before making any changes to it.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
tex_desc.nextInChain = &internal_usage_desc.chain;
Corentin WallezI was worried about this pointer being used after the function terminates, but looking in Code Search, it looks like it's not used at all. Is this coming in a future change? Or am I missing something?
John StilesUh right, I was surprised that the sType missing didn't cause crashes. John do you have tests that unsupported usages are actually not supported but CopySrc is?
It seems like we might need to add an internalUsage argument to AssociateMailbox and handle it in webgpu_decoder_impl.cc and all the SI stuff. +CC Austin, any concern with adding this?
John StilesYou're right, at one point I had thought that `desc` was passed in and the `nextInChain` would automatically kick in, but I see now that `AssociateMailbox` takes `desc.usage` directly and not the entire `desc`, so it isn't going to see the rest of the chain.
Looking at it, the rabbit hole for `AssociateMailbox` goes very deep. I'd like enga@'s input before making any changes to it.
a lot of the shared image backings already add the internal usage of CopySrc
https://source.chromium.org/search?q=internalUsage%20%22CopySrc%22%20-f:third_party%2Fdawn&sq=&ss=chromium%2Fchromium%2Fsrc
were you seeing it was not added for some reason?
(that said, that automatic internal usages may cause us problems in the future since some of them automatically add RenderAttachment - it messes up concurrent read/write determination. And so we indeed may end up needing to add internal usage to AssociateMailbox)
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
tex_desc.nextInChain = &internal_usage_desc.chain;
Corentin WallezI was worried about this pointer being used after the function terminates, but looking in Code Search, it looks like it's not used at all. Is this coming in a future change? Or am I missing something?
John StilesUh right, I was surprised that the sType missing didn't cause crashes. John do you have tests that unsupported usages are actually not supported but CopySrc is?
It seems like we might need to add an internalUsage argument to AssociateMailbox and handle it in webgpu_decoder_impl.cc and all the SI stuff. +CC Austin, any concern with adding this?
John StilesYou're right, at one point I had thought that `desc` was passed in and the `nextInChain` would automatically kick in, but I see now that `AssociateMailbox` takes `desc.usage` directly and not the entire `desc`, so it isn't going to see the rest of the chain.
Austin EngLooking at it, the rabbit hole for `AssociateMailbox` goes very deep. I'd like enga@'s input before making any changes to it.
a lot of the shared image backings already add the internal usage of CopySrc
https://source.chromium.org/search?q=internalUsage%20%22CopySrc%22%20-f:third_party%2Fdawn&sq=&ss=chromium%2Fchromium%2Fsrcwere you seeing it was not added for some reason?
(that said, that automatic internal usages may cause us problems in the future since some of them automatically add RenderAttachment - it messes up concurrent read/write determination. And so we indeed may end up needing to add internal usage to AssociateMailbox)
In practice things do seem to be working, so it's possible we are also hitting a path where CopySrc is being tacked on for us and that is the explanation for it. But this sounds more like "we are getting away with something" instead of a robust solution to me? I need to _make sure_ that CopySrc is possible when `endWebGPUAccess` does its copyback, so what's the right way of doing that?
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Chatted with enga@ a bit. We have a hypothesis that we don't actually need internal flags here, because our copying to/from IOSurfaces happens via RasterInterface and not via WebGPU, and it should always just work. I'm going to check this theory.
Code-Review | +0 |
WGPUTextureDescriptor tex_desc = {};
tex_desc.usage = usage;
tex_desc.dimension = WGPUTextureDimension_2D;
tex_desc.size.width = size.width();
tex_desc.size.height = size.height();
tex_desc.format = VizToWGPUFormat(canvas_resource->GetSharedImageFormat());
John StilesDrive-by and unrelated to this CL: couldn't this be initialized with designated initializers, instead of default-initializing and then assigning?
https://abseil.io/tips/172
John StilesSo, this actually has nested structures and type narrowing, so it's not quite a 1:1 replacement. It ends up looking like this:
```
WGPUTextureDescriptor tex_desc = {
.usage = usage,
.dimension = WGPUTextureDimension_2D,
.size = {.width = static_cast<uint32_t>(size.width()),
.height = static_cast<uint32_t>(size.height())},
.format = VizToWGPUFormat(canvas_resource->GetSharedImageFormat()),
};
```WDYT, is this an improvement? To my eyes it's less readable overall (the casts add more noise/clutter than the removal of `tex_desc.` saves IMO) but I am not particular and will defer to your opinion.
PTAL
I think this is better for a couple of reasons, though you should probably use a safer type conversion than `static_cast` (see last point about that).
- [The style guide recommends initializing data on declaration, instead of declaring and initializing later.](https://google.github.io/styleguide/cppguide.html#Local_Variables) This is more efficient and can help avoid bugs from uninitialized data (e.g. if someone adds or moves code in there).
- The indentation makes it very clear that this whole code block is about initializing the struct. For readers, it becomes trivial to just skip over if not deemed interesting.
- Designated initializers are in general safer because any unspecified POD fields will be initialized to zero. In the original code, if you had forgotten the easily omittable `= {}`, you'd get undefined behavior. Adopting the habit of using designated initializers makes this error less likely.
- I think that the cast here is a feature, not a bug. It brings a real pitfall to the attention of the reader, one that I hadn't noticed before: this statement can overflow. Since the size here is ultimately user-control, you have to handle this edge case. As such, you should use a cast from [base/numerics](https://chromium.googlesource.com/chromium/src/+/main/base/numerics/README.md) instead of a `static_cast`.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |