-
Notifications
You must be signed in to change notification settings - Fork 373
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
re_renderer: detect badly sized texture buffers before handing to wgpu #4005
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wgpu does no validation right away, but defer it to a background thread,
that's incorrect. There's nothing threaded about this, there's excessive validation pretty much immediately. It's just that we don't handle the wgpu error callback right now and even if we would it would be too late (especially particular on actual WebGPU where this may indeed be delayed).
Change lgtm but Texture2DBufferInfo
is kinda made for this size check.
I'm a bit surprised we're not adding any other validation much earlier in the pipeline as well, since clearly we got malformed data in. But the resulting error message looks good enough indeed, so this will do!
max_texture_dimension_2d, | ||
}); | ||
} | ||
|
||
if !format.is_compressed() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't we use our Texture2DBufferInfo
class here instead and check for its buffer_size_unpadded
field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? Because nothing in this function uses Texture2DBufferInfo
, so it didn't occur to me. Also it requires me to write more code and understand what buffer_size_unpadded
is in relation to the input data.
Counter-question: why use Texture2DBufferInfo
and buffer_size_unpadded
here? Would it make the code shorter? Or more correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it sure would make it more correct. As is the code will fail again in the future when somebody comes with a compressed format in which case we'll don't do any check at all then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because nothing in this function uses Texture2DBufferInfo, so it didn't occur to me.
it probably should though, the function predates this utility :)
As for understanding buffer_size_unpadded
: The code sadly already requires you to understand this since we deal with two different kind of widths in here, the padded and the unpadded one.
Looks like we offloaded that to wgpu by now here. The variable names are just reminiscent of when we didn't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean it's not a big issue at all, I approved the PR didn't I? 😄
also wondering if the viewer should try to truncate the image 🤔 |
What
wgpu does no validation right away, but defer it to a background thread, leading to lack of good error messages, and sometimes panics.
So we need to do the best we can up-front!
I tested this with:
Result:
Checklist