Skip to content

Fix custom shaders not reading property tables with padded buffer views - #14006

Merged
mzschwartz5 merged 4 commits into
CesiumGS:mainfrom
mdastous-bentley:property-table-texture-rows
Dec 4, 2026
Merged

mzschwartz5 merged 4 commits into
CesiumGS:mainfrom
mdastous-bentley:property-table-texture-rows

Conversation

@mdastous-bentley

@mdastous-bentley mdastous-bentley commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

A CustomShader cannot read any property of an EXT_structural_metadata
property table if one of the table's values buffer views is longer than
count × elementSize bytes, for example because the exporter padded it to an
8-byte boundary.

collectGpuCompatiblePropertyInfo requires the view to be exactly
count × elementSize bytes and throws otherwise. The error is caught and
logged, 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 exactly count values from the
same 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 count elements when the view is
longer. A view that is too short still throws.

Example on current main, from a 3D Tiles 1.1 point cloud produced by Bentley
Reality Management:

Failed to create texture for property table "undefined": Property with
ID: "Intensity" has (22936), which does not match number of features in
the property table: (22934).

Intensity is UINT16: 22 934 × 2 = 45 868 bytes, padded to 45 872.

Notes for reviewers:

  • This PR originally also wrapped wide tables onto several texture rows.
    Add custom shader for Gaussian Splats #13418 has since done that, so that part is dropped.
  • It replaces the spec added in Add custom shader for Gaussian Splats #13418 that asserted over-long views produce
    no texture.
  • 3d-tiles-validator reports such views as METADATA_INVALID_LENGTH. The
    case for accepting them is consistency with the CPU reader, and that one
    padded property currently disables the whole table.

… 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.
@github-actions

Copy link
Copy Markdown
Contributor

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.

@mdastous-bentley

Copy link
Copy Markdown
Contributor Author

@mzschwartz5 Would you mind taking a look at this one too ?

@lilleyse

Copy link
Copy Markdown
Contributor

Motivation: 3D Tiles 1.1 point clouds produced by Bentley Reality Management store per-point Intensity, GPSTime and Classification in a property table with 20 000–25 000 points per tile and 8-byte-aligned buffer views. On stock CesiumJS none of it is readable from a shader on a 16 384-texel GPU.

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.

@mzschwartz5

Copy link
Copy Markdown
Contributor

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.

@mdastous-bentley
mdastous-bentley marked this pull request as draft November 11, 2026 13:17
@mdastous-bentley

Copy link
Copy Markdown
Contributor Author

Another drive by comment from me - it may be better to use Property Attributes here. That's the recommended approach for per-point properties.

I agree, a defect has already been filled for the tiles generator.

@mdastous-bentley mdastous-bentley changed the title Pack wide property tables onto several texture rows; accept padded buffer views Fix custom shaders not reading property tables with padded buffer views Nov 11, 2026
@mzschwartz5

Copy link
Copy Markdown
Contributor

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?

@javagl

javagl commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

3d-tiles-validator reports such views as METADATA_INVALID_LENGTH. The
case for accepting them is consistency with the CPU reader, and that one
padded property currently disables the whole table.

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 numPropertyTableRows * elementSize. Any padding that may be inserted refers to buffers. The buffer view does not need to be padded. It can have an arbitrary length, and this does not have to be divisible by anything.

(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

  • The valid data
  • The "meshFeatures_INVALID_BUFFER_VIEW_LENGTH.glb"
  • A sandcastle for loading that data (with batteries and custom shader and such...)

Cesium issue 14006.zip

To be clear:

  • The invalid file causes a validator error saying

    The 'values' buffer view of property 'example_UINT16_SCALAR' stores values with type SCALAR and component type UINT16. It is part of a property table with a 'count' of 3. So there are 3 * 1 = 3 values, and the buffer view should have a byteLength of 3 * 2 = 6. But the buffer view with index 5 has a byteLength of 8.

    (Yeah, the message is elaborate. That's what the validator is for. Nobody wants an error message that just says "Ooops, something wrong!!!111" 🤪 )

  • The invalid file cannot be used in the sandcastle, and CesiumJS says

    Failed to create texture for property table "Property Table": Property with ID: "example_UINT16_SCALAR" has (4), which does not match number of features in the property table: (3).

  • The file is invalid

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 console.warn or oneTimeWarning or so...

@mdastous-bentley

Copy link
Copy Markdown
Contributor Author

Thanks @mzschwartz5 and @javagl!

@javagl Agreed — per EXT_structural_metadata, padding belongs between views in the buffer rather than inside bufferView.byteLength, so 3d-tiles-validator flagging METADATA_INVALID_LENGTH is right (we've already filed a defect on the tile exporter). The goal here is purely loader resilience and matching MetadataTableProperty on the CPU so one padded view doesn't drop the whole table on the GPU.

I've updated the branch with:

  1. Merged latest main and resolved CHANGES.md.
  2. Added a oneTimeWarning (PropertyTableBufferViewHasExcessBytes) when trimming trailing bytes from an over-long property table bufferView, covered in parseStructuralMetadataSpec.
  3. Added an end-to-end WebGL2 rendering spec in ModelSpec ("renders custom shader reading a property table with a padded buffer view") that builds a synthetic glTF with an 8-byte-padded UINT16 property table view and renders it with a CustomShader reading fsInput.metadata.

@mzschwartz5 In addition to @javagl's Cesium issue 14006.zip Sandcastle and the new ModelSpec test (npx gulp test --includeName "renders custom shader reading a property table with a padded buffer view"), you can also paste the self-contained Sandcastle snippet below (no external files needed — fails shader compilation on main, renders 3 colored points on this branch).

pr14006_michel_sandcastleExample.js

@mdastous-bentley
mdastous-bentley marked this pull request as ready for review November 25, 2026 12:22

@mzschwartz5 mzschwartz5 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks for the contribution!

@mzschwartz5
mzschwartz5 added this pull request to the merge queue Dec 4, 2026
Merged via the queue into CesiumGS:main with commit 3a48f70 Dec 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants