MCPcopy Create free account
hub / github.com/gpujs/gpu.js / testImmutableKernelMappedTexturesDoesNotLeak

Function testImmutableKernelMappedTexturesDoesNotLeak

test/internal/recycling.js:301–351  ·  view source on GitHub ↗
(precision, done, mode)

Source from the content-addressed store, hash-verified

299});
300
301function testImmutableKernelMappedTexturesDoesNotLeak(precision, done, mode) {
302 const gpu = new GPU({ mode });
303 function saveValue(value) {
304 return value;
305 }
306 const toTextures = gpu.createKernelMap([saveValue],function(value1, value2) {
307 saveValue(value1[this.thread.x]);
308 return value2[this.thread.x];
309 }, {
310 output: [1],
311 pipeline: true,
312 immutable: true,
313 precision,
314 });
315 const { result: one, 0: two } = toTextures([1], [2]);
316 assert.equal(one.texture._refs, 2); // one's texture will be used in two places at first, in one and toTexture.texture
317 assert.equal(two.texture._refs, 2); // one's texture will be used in two places at first, in one and toTexture.mappedTextures[0]
318 assert.equal(toTextures.texture.texture, one.texture); // very important, a clone was mode, but not a deep clone
319 assert.equal(toTextures.mappedTextures[0].texture, two.texture); // very important, a clone was mode, but not a deep clone
320 assert.notEqual(one, toTextures.texture);
321 assert.notEqual(one, toTextures.mappedTextures[0]);
322 const { result: three, 0: four } = toTextures([3], [4]);
323 assert.equal(one.texture._refs, 1); // was tracked on toTexture.texture, and deleted
324 assert.equal(two.texture._refs, 1); // was tracked on toTexture.mappedTextures[0], and deleted
325 assert.equal(toTextures.texture.texture, three.texture);
326 assert.equal(toTextures.mappedTextures[0].texture, four.texture);
327 assert.notEqual(toTextures.texture.texture, one.texture);
328 assert.notEqual(toTextures.mappedTextures[0].texture, two.texture);
329 assert.equal(three.texture._refs, 2);
330 assert.equal(four.texture._refs, 2);
331 one.delete();
332 two.delete();
333 three.delete();
334 four.delete();
335 assert.equal(one.texture._refs, 0);
336 assert.equal(two.texture._refs, 0);
337 assert.equal(three.texture._refs, 1); // still used by toTexture.texture
338 assert.equal(four.texture._refs, 1); // still used by toTexture.mappedTextures[0]
339 three.delete(); // already deleted
340 four.delete(); // already deleted
341 assert.equal(three.texture._refs, 1); // still used by toTexture
342 assert.equal(four.texture._refs, 1); // still used by toTexture
343 gpu.destroy()
344 .then(() => {
345 assert.equal(one.texture._refs, 0);
346 assert.equal(two.texture._refs, 0);
347 assert.equal(three.texture._refs, 0);
348 assert.equal(four.texture._refs, 0);
349 done();
350 });
351}
352
353test('immutable unsigned precision kernel.mappedTextures does not leak auto', t => {
354 testImmutableKernelMappedTexturesDoesNotLeak('unsigned', t.async());

Callers 1

recycling.jsFile · 0.85

Calls 4

createKernelMapMethod · 0.95
destroyMethod · 0.95
saveValueFunction · 0.85
deleteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…