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

Method releaseTexture

tfjs-backend-webgl/src/texture_manager.ts:89–130  ·  view source on GitHub ↗
(
      texture: Texture, shape: [number, number], logicalTexType: TextureUsage,
      isPacked: boolean)

Source from the content-addressed store, hash-verified

87 }
88
89 releaseTexture(
90 texture: Texture, shape: [number, number], logicalTexType: TextureUsage,
91 isPacked: boolean): void {
92 if (this.freeTextures == null) {
93 // Already disposed.
94 return;
95 }
96 const physicalTexType =
97 getPhysicalFromLogicalTextureType(logicalTexType, isPacked);
98 const shapeKey = getKeyFromTextureShape(shape, physicalTexType, isPacked);
99 if (!(shapeKey in this.freeTextures)) {
100 this.freeTextures[shapeKey] = [];
101 }
102
103 const texBytes = computeBytes(
104 shape, physicalTexType, this.gpgpu.gl, this.gpgpu.textureConfig,
105 isPacked);
106 const deleteTexThreshold = env()
107 .getNumber('WEBGL_DELETE_TEXTURE_THRESHOLD');
108 if (deleteTexThreshold !== -1 &&
109 this._numBytesAllocated > deleteTexThreshold) {
110 this.gpgpu.deleteMatrixTexture(texture.texture);
111 this._numBytesAllocated -= texBytes;
112 } else {
113 this.freeTextures[shapeKey].push(texture);
114 this.numFreeTextures++;
115 this._numBytesFree += texBytes;
116 }
117
118 this.numUsedTextures--;
119
120 const texList = this.usedTextures[shapeKey];
121 const texIndex = texList && texList.indexOf(texture);
122 if (texIndex == null || texIndex < 0) {
123 throw new Error(
124 'Cannot release a texture that was never provided by this ' +
125 'texture manager');
126 }
127 texList[texIndex] = texList[texList.length - 1];
128 texList.pop();
129 this.log();
130 }
131
132 private log() {
133 if (!this.logEnabled) {

Callers 1

releaseGPUDataMethod · 0.45

Calls 9

logMethod · 0.95
envFunction · 0.90
getKeyFromTextureShapeFunction · 0.85
computeBytesFunction · 0.85
getNumberMethod · 0.80
deleteMatrixTextureMethod · 0.80
pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected