Skip to content

Commit

Permalink
Add COPY_SRC to temp texture since it's used as a COPY_SRC
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jun 7, 2024
1 parent 3d096d0 commit c0ee7b1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/texture-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 28 additions & 1 deletion test/tests/texture-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit c0ee7b1

Please sign in to comment.