diff --git a/src/texture-utils.ts b/src/texture-utils.ts index b0aa3cd..b4aac13 100644 --- a/src/texture-utils.ts +++ b/src/texture-utils.ts @@ -177,7 +177,7 @@ export function copySourcesToTexture( if (texture.dimension === '3d') { tempTexture = tempTexture ?? device.createTexture({ format: texture.format, - usage: texture.usage, + usage: texture.usage | GPUTextureUsage.COPY_SRC, size: [texture.width, texture.height, 1], }); dstTexture = tempTexture; diff --git a/test/tests/texture-utils-test.js b/test/tests/texture-utils-test.js index e76bb35..f30a2b4 100644 --- a/test/tests/texture-utils-test.js +++ b/test/tests/texture-utils-test.js @@ -5,7 +5,7 @@ import { createTextureFromSources, createTextureFromImage, } from '../../dist/1.x/webgpu-utils.module.js'; -import { assertArrayEqual, assertArrayEqualApproximately, assertEqual } from '../assert.js'; +import { assertArrayEqual, assertArrayEqualApproximately, assertEqual, assertFalsy } from '../assert.js'; import { readTextureUnpadded, testWithDevice, testWithDeviceAndDocument } from '../webgpu.js'; // prevent global document @@ -142,6 +142,33 @@ describe('texture-utils tests', () => { assertArrayEqualApproximately(result, [255, 0, 0, 255, 0, 0, 255, 255], 0); })); + it('canc create 3D texture from canvases without COPY_SRC', testWithDeviceAndDocument(async (device, document) => { + const createCanvas = color => { + const canvas = document.createElement('canvas'); + canvas.width = 1; + canvas.height = 1; + const ctx = canvas.getContext('2d'); + ctx.fillStyle = color; + ctx.fillRect(0, 0, 1, 1); + return canvas; + }; + const canvases = [ + createCanvas('#f00'), + createCanvas('#00f'), + ]; + + createTextureFromSources( + device, + canvases, + { + usage: GPUTextureUsage.TEXTURE_BINDING | + GPUTextureUsage.RENDER_ATTACHMENT | + GPUTextureUsage.COPY_DST, + dimension: '3d', + } + ); + })); + it('creates texture from image url with mips', testWithDevice(async device => { const dataUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAAAXNSR0IArs4c6QAAACJJREFUGFddibENAAAMgvD/o2l07AIJBBRAUpUv2LkzkR8OvcEL/bJgfmEAAAAASUVORK5CYII='; const texture = await createTextureFromImage(