gputex 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -158,9 +158,9 @@ encoder.destroy()
158
158
  - `texture-compression-bc` (desktop) or `texture-compression-astc` (mobile) for compressed output
159
159
  - Falls back to uncompressed RGBA8 when neither is available
160
160
 
161
- ## Known issues
161
+ ## Device-specific workarounds
162
162
 
163
- - Black texture on Google Pixel 10
163
+ - Black texture on Google Pixel 10: `copyExternalImageToTexture` produces black textures on the Pixel 10's PowerVR DXT GPU (vendor `img-tec`, architecture `d-series`). Worked around by uploading via `writeTexture` with rasterised pixel data instead.
164
164
 
165
165
  ## Acknowledgements
166
166
 
package/dist/index.js CHANGED
@@ -50,6 +50,25 @@ import {
50
50
  SRGBColorSpace,
51
51
  RepeatWrapping
52
52
  } from "three";
53
+
54
+ // src/workarounds.ts
55
+ function needsWriteTextureWorkaround(adapter) {
56
+ const { vendor, architecture } = adapter.info ?? {};
57
+ return vendor === "img-tec" && architecture === "d-series";
58
+ }
59
+ function uploadSourceTexture(device, srcTex, source, width, height, flipY, useWriteTexture) {
60
+ if (useWriteTexture && source instanceof ImageData) {
61
+ device.queue.writeTexture({ texture: srcTex }, source.data, { bytesPerRow: width * 4 }, [width, height, 1]);
62
+ } else {
63
+ device.queue.copyExternalImageToTexture({ source, flipY }, { texture: srcTex }, [
64
+ width,
65
+ height,
66
+ 1
67
+ ]);
68
+ }
69
+ }
70
+
71
+ // src/Encoder.ts
53
72
  var Encoder = class {
54
73
  /**
55
74
  * Subclasses set this to the WebGPU feature string the output texture
@@ -184,9 +203,11 @@ var Encoder = class {
184
203
  label: `${this.label}-src`,
185
204
  size: [paddedWidth, paddedHeight, 1],
186
205
  format: "rgba8unorm",
206
+ // RENDER_ATTACHMENT is required by copyExternalImageToTexture
207
+ // (internally a blit) even though we never render into this texture.
187
208
  usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT
188
209
  });
189
- device.queue.copyExternalImageToTexture({ source, flipY }, { texture: srcTex }, [width, height, 1]);
210
+ uploadSourceTexture(device, srcTex, source, width, height, flipY, source instanceof ImageData);
190
211
  const dstBuffer = device.createBuffer({
191
212
  label: `${this.label}-dst`,
192
213
  size: outByteLen,
@@ -608,8 +629,16 @@ async function compressTexture(source, options = {}) {
608
629
  encoder = await selection.encoderClass.create();
609
630
  }
610
631
  try {
632
+ const needsWriteTexture = needsWriteTextureWorkaround(adapter);
611
633
  if (!mipmaps) {
612
- const bytes = await encoder.encodeToBytes(bitmap, { flipY });
634
+ let bytes;
635
+ if (needsWriteTexture) {
636
+ const level02 = bitmapToMipLevel(bitmap, flipY);
637
+ const imageData = mipLevelToImageData(level02);
638
+ bytes = await encoder.encodeToBytes(imageData);
639
+ } else {
640
+ bytes = await encoder.encodeToBytes(bitmap, { flipY });
641
+ }
613
642
  const tex2 = encoder.buildMippedTexture([bytes], { colorSpace });
614
643
  return {
615
644
  texture: tex2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gputex",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist"