Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was investigating why this sample didn't work on compat mode in Chrome.
I found 1 issue in the code which is the shader that makes the probability map only worked if the source image is was a multiple of 64 pixels wide. This was because it was not conditionally skipping out of bounds pixels and so those pixels would end up overwriting other results.
This issue does not come up in the sample but if you change the image to some image that is not a multiple of 64 pixels across the issue comes up.
In debugging why GL was failing one my paths was to make a 16x16 pixel
F
using the canvas 2D api and passing that in so that I can print out all the data. With that I ran into this issue.So, I added the skipping. Thank's to Peter McNeeley for finding that issue.
While pursing the code I find somethings I thought maybe should be refactored?
Calculating the number of mip level was done in a loop.
Changed it to just math.
Moving some calculations to use properties on the texture.
I can revert these changes. They were useful when I switched the source image since then the code didn't depend on variables that were no longer available.
Getting rid of
struct Buffer
I can revert these changes. I get the impression that this was a limitation of an earlier version of WGSL. It seems more confusing to me personally have have a struct with a single array member in it than to just have the array.
Simpler math
I can revert this but, changed
sum = dot(vec4f(a, b, c, d), vec4f(1.0))
tosum = a + b + c + d
.Note that, even with the change for the first pass, the code only works for square power-of-2 images. Both the probability generation and the usage of that data require each mip level to be exactly 1/2 the size of the previous level so added some asserts.