MCPcopy Index your code
hub / github.com/tensorflow/tfjs / acquireTexture

Method acquireTexture

tfjs-backend-webgpu/src/texture_manager.ts:29–64  ·  view source on GitHub ↗
(
      width: number, height: number, format: GPUTextureFormat,
      usage: GPUTextureUsageFlags)

Source from the content-addressed store, hash-verified

27 constructor(private device: GPUDevice) {}
28
29 acquireTexture(
30 width: number, height: number, format: GPUTextureFormat,
31 usage: GPUTextureUsageFlags) {
32 const bytesPerElement = getBytesPerElement(format);
33 const byteSize = width * height * bytesPerElement;
34 const key = getTextureKey(width, height, format, usage);
35 if (!this.freeTextures.has(key)) {
36 this.freeTextures.set(key, []);
37 }
38
39 if (!this.usedTextures.has(key)) {
40 this.usedTextures.set(key, []);
41 }
42
43 this.numBytesUsed += byteSize;
44 this.numUsedTextures++;
45
46 if (this.freeTextures.get(key).length > 0) {
47 this.numFreeTextures--;
48
49 const newTexture = this.freeTextures.get(key).shift();
50 this.usedTextures.get(key).push(newTexture);
51 return newTexture;
52 }
53
54 this.numBytesAllocated += byteSize;
55
56 const newTexture = this.device.createTexture({
57 size: [width, height],
58 format,
59 usage,
60 });
61 this.usedTextures.get(key).push(newTexture);
62
63 return newTexture;
64 }
65
66 releaseTexture(texture: GPUTexture) {
67 if (this.freeTextures.size === 0) {

Callers 1

fromPixelsFunction · 0.45

Calls 7

getBytesPerElementFunction · 0.85
getTextureKeyFunction · 0.85
hasMethod · 0.80
shiftMethod · 0.80
setMethod · 0.45
getMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected