Repository navigation
Fix custom shaders not reading property tables with padded buffer views - #14006
Conversation
… buffer views EXT_structural_metadata property tables were skipped for the GPU when the feature count exceeded ContextLimits.maximumTextureSize, or when a property's buffer view was longer than count * elementSize. In both cases the property never reached the shader and a custom shader referencing it failed to compile. - createTextureForPropertyTable packs ceil(count / maximumTextureSize) rows per property; MetadataPipelineStage indexes (fid % width, p * rows + fid / width) when rows > 1 and keeps the one-row lookup otherwise. - collectGpuCompatiblePropertyInfo reads exactly count elements from a longer buffer view, as MetadataTableProperty does on the CPU; shorter still throws.
|
Thank you for the pull request, @mdastous-bentley! Welcome to the Cesium community! In order for us to review your PR, please complete the following steps:
Review Pull Request Guidelines to make sure your PR gets accepted quickly. |
|
@mzschwartz5 Would you mind taking a look at this one too ? |
Another drive by comment from me - it may be better to use Property Attributes here. That's the recommended approach for per-point properties. This may still be a good fix, I just wanted to point out an alternative that doesn't run into this limitation. |
|
I'll try to give this a review tomorrow. I have context here, so it shouldn't take me too long to grok it all and give feedback. |
I agree, a defect has already been filled for the tiles generator. |
|
Hey @mdastous-bentley -- the code looks fine to me, but could you provide a way to test the PR? Also, can you move the PR to ready if it's appropriate to do so now? |
If you think that this data should be valid (and the validator message is wrong), then I'd like to better understand why. The specification is not pointing out the length of the buffer view as explicitly as it could (and maybe should). But it says that the elements are tightly packed. And given the tight packing, the length of a buffer view should be (A form of "padding" is only mentioned for the case of boolean values, given that they ave stored as a bitstream, and thus, necessarily aligned to 8 (bits per byte)). That said: I just spent a bit more time than I'd like to admit with creating some test data. That's difficult. The metadata implementation in the 3D Tiles Tools is simply not capable of writing out data that is invalid in this form. So I had to convert the GLB to glTF, manually tweak some values, and convert it back to GLB. Here is an archive that contains
To be clear:
We can always argue about how "reslilient" a loader should be against invalid data. One can make a strong case to "load as much as possible, and not crash". That's fine. But we can (or should) not argue about the fact that the writer should not generate invalid data! Bottom line: When running CesiumJS from the branch of this PR, it can load the data. Maybe it could/should point out that the data is invalid, with some |
|
Thanks @mzschwartz5 and @javagl! @javagl Agreed — per I've updated the branch with:
@mzschwartz5 In addition to @javagl's |
mzschwartz5
left a comment
There was a problem hiding this comment.
LGTM, thanks for the contribution!
A
CustomShadercannot read any property of anEXT_structural_metadataproperty table if one of the table's
valuesbuffer views is longer thancount × elementSizebytes, for example because the exporter padded it to an8-byte boundary.
collectGpuCompatiblePropertyInforequires the view to be exactlycount × elementSizebytes and throws otherwise. The error is caught andlogged, and no texture is created for the whole table, so every property in
it is lost to the shader, not only the padded one.
MetadataTableProperty, the CPU reader, reads exactlycountvalues from thesame view and ignores trailing bytes. The same table therefore works on the
CPU but not on the GPU.
This PR makes the GPU path read exactly
countelements when the view islonger. A view that is too short still throws.
Example on current
main, from a 3D Tiles 1.1 point cloud produced by BentleyReality Management:
Intensityis UINT16: 22 934 × 2 = 45 868 bytes, padded to 45 872.Notes for reviewers:
Add custom shader for Gaussian Splats #13418 has since done that, so that part is dropped.
no texture.
3d-tiles-validatorreports such views asMETADATA_INVALID_LENGTH. Thecase for accepting them is consistency with the CPU reader, and that one
padded property currently disables the whole table.