Skip to content

KTX2Loader: Improve target format selection and examples#32966

Open
epreston wants to merge 6 commits intomrdoob:devfrom
epreston:update-ktx2loader-and-examples
Open

KTX2Loader: Improve target format selection and examples#32966
epreston wants to merge 6 commits intomrdoob:devfrom
epreston:update-ktx2loader-and-examples

Conversation

@epreston
Copy link
Contributor

@epreston epreston commented Feb 5, 2026

Related issue: errors when running examples and code

Description

update ktx2loader and examples for both webgl2 and webgpu

Changes include:

  • update ktx2loader
  • add missing texture from original source:
  • update webgl2 example.
  • update webgpu example.

Changes to ktx2loader : update the webgl2 and webgpu compressed texture support settings provided to web workers. Additional notes illustrate the usage of extensions and how they differ between backends.

Changes to the examples : use the worker settings in the examples to avoid errors and illustrate how extensions map to gpu compression formats.

Both Chrome and Safari (where possible) used for local testing completed on:

  • Win11 / Nvidia 4080
  • iPhone 13
  • M1 Macbook Pro
  • iPad mini A17

for webgl2, bc4 and bc5 are provided by "rgtc".  This is GL_COMPRESSED_RED_RGTC1 and GL_COMPRESSED_SIGNED_RG_RGTC2.

for webgpu, bc4 and bc5 and provided by "bptc".  This is
bc4-r-unorm and bc5-rg-unorm
add missing texture from original source:
https://github.com/donmccurdy/KTX2-Samples
update webgl2 example.

use the support matrix given to worker threads to populate the "supported" field already expected by the example code.

bc1 and bc3 are dxt on webgl, bptc on webgpu
bc4 and bc5 are rgtc on webgl, bptc on webgpu
clarify webgpu texture support matrix support
update webgpu example.

use the support matrix given to worker threads to populate the "supported" field already expected by the example code.

some rearrangement required to have an initialized renderer to populate the data fields.

ect1 and ect2 support are from the ect2 extension
bc1-bc7 are from bptc on webgpu
@epreston
Copy link
Contributor Author

epreston commented Feb 5, 2026

@donmccurdy you might be the best to eyeball this. I wrote my notes in each commit on formats from testing and reviewing ktx and basis repos.

@epreston
Copy link
Contributor Author

epreston commented Feb 5, 2026

looks like CI is hung on physics sim because its seeing more balls

@donmccurdy donmccurdy changed the title update ktx2loader and examples KTX2Loader: Improve target format selection and examples Feb 5, 2026
trigger CI on PR
Copy link
Collaborator

@donmccurdy donmccurdy left a comment

Choose a reason for hiding this comment

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

Thanks @epreston! I think this is a good change, just a couple comments/questions about how we approach it.

As FYI to other readers, this change allows the KTX2 loader examples to show a placeholder image for textures that the device doesn't support. For example if my GPU didn't support BC4-7, I'd see this:

Image

If we don't like "LOAD FAIL" as the text, I'm happy to regenerate the .ktx2 image... just note that it's a 40x40px image and a pixel-aligned monospace font, so we can only fit 5 characters per line. :)

etc2Supported: renderer.hasFeature( 'texture-compression-etc2' ),
dxtSupported: renderer.hasFeature( 'texture-compression-s3tc' ),
dxtSupported: false, // rgb565 smooth and hard alpha provided by bc (bptc)
rgtcSupported: false, // 1 and 2 channel textures provided by bc (bptc)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to check renderer.hasFeature( 'texture-compression-bc' ) here instead? It'd be ideal if the 'supported' lists for each sample texture could be the same in the WebGL and WebGPU examples.

In retrospect... I think I wish that workerConfig just listed all the THREE.FooFormat enum values that the device supports, without the intermediate representation of these rgtcSupported, bptcSupported, ... booleans, which don't really line up well with WebGPU extensions. But that's a bigger change, no pressure to do so in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would trust your judgement on this. Yes, compression-bc covers everything and might make selection simpler for webgpu. The "GL format constants"? are different for the types but they are equivalent. Only matters if it matters.

It was helpful to me to see identical support matrixes side by side, showing how they differ between the backends. (ec1 is rolled into ec2 on webgpu, webgl2 requires a mix of dxt and rgtc to get what webgpu gets by default with compression-bc).

I didnt want to disturb worker code and hoped to keep changes to minimum. It is helpful for me to have consistent keys for tests, further improvements could make things simpler.

Comment on lines +127 to +131
{ path: '2d_bc1.ktx2', supported: formats[ 'dxtSupported' ] || formats[ 'bptcSupported' ] },
{ path: '2d_bc3.ktx2', supported: formats[ 'dxtSupported' ] || formats[ 'bptcSupported' ] },
{ path: '2d_bc4.ktx2', supported: formats[ 'rgtcSupported' ] || formats[ 'bptcSupported' ] },
{ path: '2d_bc5.ktx2', supported: formats[ 'rgtcSupported' ] || formats[ 'bptcSupported' ] },
{ path: '2d_bc7.ktx2', supported: formats[ 'bptcSupported' ] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above -- would it be possible to have the WebGL and WebGPU renderers set the same workerConfig flags, so we don't have to use different ways of checking support for the same sample texture?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think we could.

I would need to look at it again to ensure we are not losing information that informs choices.

Copy link
Contributor Author

@epreston epreston left a comment

Choose a reason for hiding this comment

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

Anytime, happy to do what's needed to add some clarity.

etc2Supported: renderer.hasFeature( 'texture-compression-etc2' ),
dxtSupported: renderer.hasFeature( 'texture-compression-s3tc' ),
dxtSupported: false, // rgb565 smooth and hard alpha provided by bc (bptc)
rgtcSupported: false, // 1 and 2 channel textures provided by bc (bptc)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would trust your judgement on this. Yes, compression-bc covers everything and might make selection simpler for webgpu. The "GL format constants"? are different for the types but they are equivalent. Only matters if it matters.

It was helpful to me to see identical support matrixes side by side, showing how they differ between the backends. (ec1 is rolled into ec2 on webgpu, webgl2 requires a mix of dxt and rgtc to get what webgpu gets by default with compression-bc).

I didnt want to disturb worker code and hoped to keep changes to minimum. It is helpful for me to have consistent keys for tests, further improvements could make things simpler.

Comment on lines +127 to +131
{ path: '2d_bc1.ktx2', supported: formats[ 'dxtSupported' ] || formats[ 'bptcSupported' ] },
{ path: '2d_bc3.ktx2', supported: formats[ 'dxtSupported' ] || formats[ 'bptcSupported' ] },
{ path: '2d_bc4.ktx2', supported: formats[ 'rgtcSupported' ] || formats[ 'bptcSupported' ] },
{ path: '2d_bc5.ktx2', supported: formats[ 'rgtcSupported' ] || formats[ 'bptcSupported' ] },
{ path: '2d_bc7.ktx2', supported: formats[ 'bptcSupported' ] }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think we could.

I would need to look at it again to ensure we are not losing information that informs choices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants