WebGPUTextures.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. import { GPUTextureFormat, GPUAddressMode, GPUFilterMode, GPUTextureDimension } from './constants.js';
  2. import { VideoTexture, CubeTexture, Texture, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, RepeatWrapping, MirroredRepeatWrapping,
  3. RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, sRGBEncoding
  4. } from 'three';
  5. import WebGPUTextureUtils from './WebGPUTextureUtils.js';
  6. class WebGPUTextures {
  7. constructor( device, properties, info ) {
  8. this.device = device;
  9. this.properties = properties;
  10. this.info = info;
  11. this.defaultTexture = null;
  12. this.defaultVideoTexture = null;
  13. this.defaultCubeTexture = null;
  14. this.defaultSampler = null;
  15. this.samplerCache = new Map();
  16. this.utils = null;
  17. }
  18. getDefaultSampler() {
  19. if ( this.defaultSampler === null ) {
  20. this.defaultSampler = this.device.createSampler( {} );
  21. }
  22. return this.defaultSampler;
  23. }
  24. getDefaultTexture() {
  25. if ( this.defaultTexture === null ) {
  26. const texture = new Texture();
  27. texture.minFilter = NearestFilter;
  28. texture.magFilter = NearestFilter;
  29. this._uploadTexture( texture );
  30. this.defaultTexture = this.getTextureGPU( texture );
  31. }
  32. return this.defaultTexture;
  33. }
  34. getVideoDefaultTexture() {
  35. if ( this.defaultVideoTexture === null ) {
  36. const video = document.getElementById( 'video' );
  37. const texture = new VideoTexture( video );
  38. texture.minFilter = NearestFilter;
  39. texture.magFilter = NearestFilter;
  40. this._uploadVideoTexture( texture );
  41. this.defaultVideoTexture = this.getTextureGPU( texture );
  42. }
  43. return this.defaultVideoTexture;
  44. }
  45. getDefaultCubeTexture() {
  46. if ( this.defaultCubeTexture === null ) {
  47. const texture = new CubeTexture();
  48. texture.minFilter = NearestFilter;
  49. texture.magFilter = NearestFilter;
  50. this._uploadTexture( texture );
  51. this.defaultCubeTexture = this.getTextureGPU( texture );
  52. }
  53. return this.defaultCubeTexture;
  54. }
  55. getTextureGPU( texture ) {
  56. const textureProperties = this.properties.get( texture );
  57. return textureProperties.textureGPU;
  58. }
  59. getSampler( texture ) {
  60. const textureProperties = this.properties.get( texture );
  61. return textureProperties.samplerGPU;
  62. }
  63. updateTexture( texture ) {
  64. let needsUpdate = false;
  65. const textureProperties = this.properties.get( texture );
  66. if ( texture.version > 0 && textureProperties.version !== texture.version ) {
  67. const image = texture.image;
  68. if ( image === undefined ) {
  69. console.warn( 'THREE.WebGPURenderer: Texture marked for update but image is undefined.' );
  70. } else if ( image.complete === false ) {
  71. console.warn( 'THREE.WebGPURenderer: Texture marked for update but image is incomplete.' );
  72. } else {
  73. // texture init
  74. if ( textureProperties.initialized === undefined ) {
  75. textureProperties.initialized = true;
  76. const disposeCallback = onTextureDispose.bind( this );
  77. textureProperties.disposeCallback = disposeCallback;
  78. texture.addEventListener( 'dispose', disposeCallback );
  79. this.info.memory.textures ++;
  80. }
  81. //
  82. if ( texture.isVideoTexture ) {
  83. needsUpdate = this._uploadVideoTexture( texture );
  84. } else {
  85. needsUpdate = this._uploadTexture( texture );
  86. }
  87. }
  88. }
  89. // if the texture is used for RTT, it's necessary to init it once so the binding
  90. // group's resource definition points to the respective GPUTexture
  91. if ( textureProperties.initializedRTT === false ) {
  92. textureProperties.initializedRTT = true;
  93. needsUpdate = true;
  94. }
  95. return needsUpdate;
  96. }
  97. updateSampler( texture ) {
  98. const array = [];
  99. array.push( texture.wrapS );
  100. array.push( texture.wrapT );
  101. array.push( texture.wrapR );
  102. array.push( texture.magFilter );
  103. array.push( texture.minFilter );
  104. array.push( texture.anisotropy );
  105. const key = array.join();
  106. let samplerGPU = this.samplerCache.get( key );
  107. if ( samplerGPU === undefined ) {
  108. samplerGPU = this.device.createSampler( {
  109. addressModeU: this._convertAddressMode( texture.wrapS ),
  110. addressModeV: this._convertAddressMode( texture.wrapT ),
  111. addressModeW: this._convertAddressMode( texture.wrapR ),
  112. magFilter: this._convertFilterMode( texture.magFilter ),
  113. minFilter: this._convertFilterMode( texture.minFilter ),
  114. mipmapFilter: this._convertFilterMode( texture.minFilter ),
  115. maxAnisotropy: texture.anisotropy
  116. } );
  117. this.samplerCache.set( key, samplerGPU );
  118. }
  119. const textureProperties = this.properties.get( texture );
  120. textureProperties.samplerGPU = samplerGPU;
  121. }
  122. initRenderTarget( renderTarget ) {
  123. const properties = this.properties;
  124. const renderTargetProperties = properties.get( renderTarget );
  125. if ( renderTargetProperties.initialized === undefined ) {
  126. const device = this.device;
  127. const width = renderTarget.width;
  128. const height = renderTarget.height;
  129. const colorTextureFormat = this._getFormat( renderTarget.texture );
  130. const colorTextureGPU = device.createTexture( {
  131. size: {
  132. width: width,
  133. height: height,
  134. depthOrArrayLayers: 1
  135. },
  136. format: colorTextureFormat,
  137. usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
  138. } );
  139. this.info.memory.textures ++;
  140. renderTargetProperties.colorTextureGPU = colorTextureGPU;
  141. renderTargetProperties.colorTextureFormat = colorTextureFormat;
  142. // When the ".texture" or ".depthTexture" property of a render target is used as a map,
  143. // the renderer has to find the respective GPUTexture objects to setup the bind groups.
  144. // Since it's not possible to see just from a texture object whether it belongs to a render
  145. // target or not, we need the initializedRTT flag.
  146. const textureProperties = properties.get( renderTarget.texture );
  147. textureProperties.textureGPU = colorTextureGPU;
  148. textureProperties.initializedRTT = false;
  149. if ( renderTarget.depthBuffer === true ) {
  150. const depthTextureFormat = GPUTextureFormat.Depth24PlusStencil8; // @TODO: Make configurable
  151. const depthTextureGPU = device.createTexture( {
  152. size: {
  153. width: width,
  154. height: height,
  155. depthOrArrayLayers: 1
  156. },
  157. format: depthTextureFormat,
  158. usage: GPUTextureUsage.RENDER_ATTACHMENT
  159. } );
  160. this.info.memory.textures ++;
  161. renderTargetProperties.depthTextureGPU = depthTextureGPU;
  162. renderTargetProperties.depthTextureFormat = depthTextureFormat;
  163. if ( renderTarget.depthTexture !== null ) {
  164. const depthTextureProperties = properties.get( renderTarget.depthTexture );
  165. depthTextureProperties.textureGPU = depthTextureGPU;
  166. depthTextureProperties.initializedRTT = false;
  167. }
  168. }
  169. //
  170. const disposeCallback = onRenderTargetDispose.bind( this );
  171. renderTargetProperties.disposeCallback = disposeCallback;
  172. renderTarget.addEventListener( 'dispose', disposeCallback );
  173. //
  174. renderTargetProperties.initialized = true;
  175. }
  176. }
  177. dispose() {
  178. this.samplerCache.clear();
  179. }
  180. _convertAddressMode( value ) {
  181. let addressMode = GPUAddressMode.ClampToEdge;
  182. if ( value === RepeatWrapping ) {
  183. addressMode = GPUAddressMode.Repeat;
  184. } else if ( value === MirroredRepeatWrapping ) {
  185. addressMode = GPUAddressMode.MirrorRepeat;
  186. }
  187. return addressMode;
  188. }
  189. _convertFilterMode( value ) {
  190. let filterMode = GPUFilterMode.Linear;
  191. if ( value === NearestFilter || value === NearestMipmapNearestFilter || value === NearestMipmapLinearFilter ) {
  192. filterMode = GPUFilterMode.Nearest;
  193. }
  194. return filterMode;
  195. }
  196. _uploadVideoTexture( texture ) {
  197. const device = this.device;
  198. const textureProperties = this.properties.get( texture );
  199. const textureGPU = device.importExternalTexture( {
  200. source: texture.source.data
  201. } );
  202. textureProperties.textureGPU = textureGPU;
  203. //textureProperties.version = texture.version; // @TODO: Force update for now, study a better solution soon using native VideoTexture.update() to fix warns
  204. return true;
  205. }
  206. _uploadTexture( texture ) {
  207. let needsUpdate = false;
  208. const device = this.device;
  209. const image = texture.image;
  210. const textureProperties = this.properties.get( texture );
  211. const { width, height, depth } = this._getSize( texture );
  212. const needsMipmaps = this._needsMipmaps( texture );
  213. const dimension = this._getDimension( texture );
  214. const mipLevelCount = this._getMipLevelCount( texture, width, height, needsMipmaps );
  215. const format = this._getFormat( texture );
  216. let usage = GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST;
  217. if ( needsMipmaps === true ) {
  218. // current mipmap generation requires RENDER_ATTACHMENT
  219. usage |= GPUTextureUsage.RENDER_ATTACHMENT;
  220. }
  221. const textureGPUDescriptor = {
  222. size: {
  223. width: width,
  224. height: height,
  225. depthOrArrayLayers: depth,
  226. },
  227. mipLevelCount: mipLevelCount,
  228. sampleCount: 1,
  229. dimension: dimension,
  230. format: format,
  231. usage: usage
  232. };
  233. // texture creation
  234. let textureGPU = textureProperties.textureGPU;
  235. if ( textureGPU === undefined ) {
  236. textureGPU = device.createTexture( textureGPUDescriptor );
  237. needsUpdate = true;
  238. }
  239. // transfer texture data
  240. if ( texture.isDataTexture || texture.isDataArrayTexture || texture.isData3DTexture ) {
  241. this._copyBufferToTexture( image, format, textureGPU );
  242. if ( needsMipmaps === true ) this._generateMipmaps( textureGPU, textureGPUDescriptor );
  243. } else if ( texture.isCompressedTexture ) {
  244. this._copyCompressedBufferToTexture( texture.mipmaps, format, textureGPU );
  245. } else if ( texture.isCubeTexture ) {
  246. if ( image.length === 6 ) {
  247. this._copyCubeMapToTexture( image, format, texture, textureGPU, textureGPUDescriptor, needsMipmaps );
  248. }
  249. } else if ( image !== null ) {
  250. // assume HTMLImageElement, HTMLCanvasElement or ImageBitmap
  251. this._getImageBitmap( image, texture ).then( imageBitmap => {
  252. this._copyExternalImageToTexture( imageBitmap, textureGPU );
  253. if ( needsMipmaps === true ) this._generateMipmaps( textureGPU, textureGPUDescriptor );
  254. } );
  255. }
  256. //
  257. textureProperties.textureGPU = textureGPU;
  258. textureProperties.version = texture.version;
  259. return needsUpdate;
  260. }
  261. _copyBufferToTexture( image, format, textureGPU, origin = { x: 0, y: 0, z: 0 } ) {
  262. // @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture()
  263. // @TODO: Consider to support valid buffer layouts with other formats like RGB
  264. const data = image.data;
  265. const bytesPerTexel = this._getBytesPerTexel( format );
  266. const bytesPerRow = image.width * bytesPerTexel;
  267. this.device.queue.writeTexture(
  268. {
  269. texture: textureGPU,
  270. mipLevel: 0,
  271. origin
  272. },
  273. data,
  274. {
  275. offset: 0,
  276. bytesPerRow
  277. },
  278. {
  279. width: image.width,
  280. height: image.height,
  281. depthOrArrayLayers: ( image.depth !== undefined ) ? image.depth : 1
  282. } );
  283. }
  284. _copyCubeMapToTexture( images, format, texture, textureGPU, textureGPUDescriptor, needsMipmaps ) {
  285. for ( let i = 0; i < 6; i ++ ) {
  286. const image = images[ i ];
  287. if ( image.isDataTexture ) {
  288. this._copyBufferToTexture( image.image, format, textureGPU, { z: i } );
  289. if ( needsMipmaps === true ) this._generateMipmaps( textureGPU, textureGPUDescriptor, i );
  290. } else {
  291. this._getImageBitmap( image, texture ).then( imageBitmap => {
  292. this._copyExternalImageToTexture( imageBitmap, textureGPU, { z: i } );
  293. if ( needsMipmaps === true ) this._generateMipmaps( textureGPU, textureGPUDescriptor, i );
  294. } );
  295. }
  296. }
  297. }
  298. _copyExternalImageToTexture( image, textureGPU, origin = { x: 0, y: 0, z: 0 } ) {
  299. this.device.queue.copyExternalImageToTexture(
  300. {
  301. source: image
  302. }, {
  303. texture: textureGPU,
  304. mipLevel: 0,
  305. origin
  306. }, {
  307. width: image.width,
  308. height: image.height,
  309. depthOrArrayLayers: 1
  310. }
  311. );
  312. }
  313. _copyCompressedBufferToTexture( mipmaps, format, textureGPU ) {
  314. // @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture()
  315. const blockData = this._getBlockData( format );
  316. for ( let i = 0; i < mipmaps.length; i ++ ) {
  317. const mipmap = mipmaps[ i ];
  318. const width = mipmap.width;
  319. const height = mipmap.height;
  320. const bytesPerRow = Math.ceil( width / blockData.width ) * blockData.byteLength;
  321. this.device.queue.writeTexture(
  322. {
  323. texture: textureGPU,
  324. mipLevel: i
  325. },
  326. mipmap.data,
  327. {
  328. offset: 0,
  329. bytesPerRow
  330. },
  331. {
  332. width: Math.ceil( width / blockData.width ) * blockData.width,
  333. height: Math.ceil( height / blockData.width ) * blockData.width,
  334. depthOrArrayLayers: 1
  335. } );
  336. }
  337. }
  338. _generateMipmaps( textureGPU, textureGPUDescriptor, baseArrayLayer ) {
  339. if ( this.utils === null ) {
  340. this.utils = new WebGPUTextureUtils( this.device ); // only create this helper if necessary
  341. }
  342. this.utils.generateMipmaps( textureGPU, textureGPUDescriptor, baseArrayLayer );
  343. }
  344. _getBlockData( format ) {
  345. // this method is only relevant for compressed texture formats
  346. if ( format === GPUTextureFormat.BC1RGBAUnorm || format === GPUTextureFormat.BC1RGBAUnormSRGB ) return { byteLength: 8, width: 4, height: 4 }; // DXT1
  347. if ( format === GPUTextureFormat.BC2RGBAUnorm || format === GPUTextureFormat.BC2RGBAUnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; // DXT3
  348. if ( format === GPUTextureFormat.BC3RGBAUnorm || format === GPUTextureFormat.BC3RGBAUnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; // DXT5
  349. if ( format === GPUTextureFormat.BC4RUnorm || format === GPUTextureFormat.BC4RSNorm ) return { byteLength: 8, width: 4, height: 4 }; // RGTC1
  350. if ( format === GPUTextureFormat.BC5RGUnorm || format === GPUTextureFormat.BC5RGSnorm ) return { byteLength: 16, width: 4, height: 4 }; // RGTC2
  351. if ( format === GPUTextureFormat.BC6HRGBUFloat || format === GPUTextureFormat.BC6HRGBFloat ) return { byteLength: 16, width: 4, height: 4 }; // BPTC (float)
  352. if ( format === GPUTextureFormat.BC7RGBAUnorm || format === GPUTextureFormat.BC7RGBAUnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; // BPTC (unorm)
  353. }
  354. _getBytesPerTexel( format ) {
  355. if ( format === GPUTextureFormat.R8Unorm ) return 1;
  356. if ( format === GPUTextureFormat.R16Float ) return 2;
  357. if ( format === GPUTextureFormat.RG8Unorm ) return 2;
  358. if ( format === GPUTextureFormat.RG16Float ) return 4;
  359. if ( format === GPUTextureFormat.R32Float ) return 4;
  360. if ( format === GPUTextureFormat.RGBA8Unorm || format === GPUTextureFormat.RGBA8UnormSRGB ) return 4;
  361. if ( format === GPUTextureFormat.RG32Float ) return 8;
  362. if ( format === GPUTextureFormat.RGBA16Float ) return 8;
  363. if ( format === GPUTextureFormat.RGBA32Float ) return 16;
  364. }
  365. _getDimension( texture ) {
  366. let dimension;
  367. if ( texture.isData3DTexture ) {
  368. dimension = GPUTextureDimension.ThreeD;
  369. } else {
  370. dimension = GPUTextureDimension.TwoD;
  371. }
  372. return dimension;
  373. }
  374. _getFormat( texture ) {
  375. const format = texture.format;
  376. const type = texture.type;
  377. const encoding = texture.encoding;
  378. let formatGPU;
  379. switch ( format ) {
  380. case RGBA_S3TC_DXT1_Format:
  381. formatGPU = ( encoding === sRGBEncoding ) ? GPUTextureFormat.BC1RGBAUnormSRGB : GPUTextureFormat.BC1RGBAUnorm;
  382. break;
  383. case RGBA_S3TC_DXT3_Format:
  384. formatGPU = ( encoding === sRGBEncoding ) ? GPUTextureFormat.BC2RGBAUnormSRGB : GPUTextureFormat.BC2RGBAUnorm;
  385. break;
  386. case RGBA_S3TC_DXT5_Format:
  387. formatGPU = ( encoding === sRGBEncoding ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm;
  388. break;
  389. case RGBAFormat:
  390. switch ( type ) {
  391. case UnsignedByteType:
  392. formatGPU = ( encoding === sRGBEncoding ) ? GPUTextureFormat.RGBA8UnormSRGB : GPUTextureFormat.RGBA8Unorm;
  393. break;
  394. case HalfFloatType:
  395. formatGPU = GPUTextureFormat.RGBA16Float;
  396. break;
  397. case FloatType:
  398. formatGPU = GPUTextureFormat.RGBA32Float;
  399. break;
  400. default:
  401. console.error( 'WebGPURenderer: Unsupported texture type with RGBAFormat.', type );
  402. }
  403. break;
  404. case RedFormat:
  405. switch ( type ) {
  406. case UnsignedByteType:
  407. formatGPU = GPUTextureFormat.R8Unorm;
  408. break;
  409. case HalfFloatType:
  410. formatGPU = GPUTextureFormat.R16Float;
  411. break;
  412. case FloatType:
  413. formatGPU = GPUTextureFormat.R32Float;
  414. break;
  415. default:
  416. console.error( 'WebGPURenderer: Unsupported texture type with RedFormat.', type );
  417. }
  418. break;
  419. case RGFormat:
  420. switch ( type ) {
  421. case UnsignedByteType:
  422. formatGPU = GPUTextureFormat.RG8Unorm;
  423. break;
  424. case HalfFloatType:
  425. formatGPU = GPUTextureFormat.RG16Float;
  426. break;
  427. case FloatType:
  428. formatGPU = GPUTextureFormat.RG32Float;
  429. break;
  430. default:
  431. console.error( 'WebGPURenderer: Unsupported texture type with RGFormat.', type );
  432. }
  433. break;
  434. default:
  435. console.error( 'WebGPURenderer: Unsupported texture format.', format );
  436. }
  437. return formatGPU;
  438. }
  439. _getImageBitmap( image, texture ) {
  440. const width = image.width;
  441. const height = image.height;
  442. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  443. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ) {
  444. const options = {};
  445. options.imageOrientation = ( texture.flipY === true ) ? 'flipY' : 'none';
  446. options.premultiplyAlpha = ( texture.premultiplyAlpha === true ) ? 'premultiply' : 'default';
  447. return createImageBitmap( image, 0, 0, width, height, options );
  448. } else {
  449. // assume ImageBitmap
  450. return Promise.resolve( image );
  451. }
  452. }
  453. _getMipLevelCount( texture, width, height, needsMipmaps ) {
  454. let mipLevelCount;
  455. if ( texture.isCompressedTexture ) {
  456. mipLevelCount = texture.mipmaps.length;
  457. } else if ( needsMipmaps === true ) {
  458. mipLevelCount = Math.floor( Math.log2( Math.max( width, height ) ) ) + 1;
  459. } else {
  460. mipLevelCount = 1; // a texture without mipmaps has a base mip (mipLevel 0)
  461. }
  462. return mipLevelCount;
  463. }
  464. _getSize( texture ) {
  465. const image = texture.image;
  466. let width, height, depth;
  467. if ( texture.isCubeTexture ) {
  468. const faceImage = image.length > 0 ? image[ 0 ].image || image[ 0 ] : null;
  469. width = faceImage ? faceImage.width : 1;
  470. height = faceImage ? faceImage.height : 1;
  471. depth = 6; // one image for each side of the cube map
  472. } else if ( image !== null ) {
  473. width = image.width;
  474. height = image.height;
  475. depth = ( image.depth !== undefined ) ? image.depth : 1;
  476. } else {
  477. width = height = depth = 1;
  478. }
  479. return { width, height, depth };
  480. }
  481. _needsMipmaps( texture ) {
  482. return ( texture.isCompressedTexture !== true ) && ( texture.generateMipmaps === true ) && ( texture.minFilter !== NearestFilter ) && ( texture.minFilter !== LinearFilter );
  483. }
  484. }
  485. function onRenderTargetDispose( event ) {
  486. const renderTarget = event.target;
  487. const properties = this.properties;
  488. const renderTargetProperties = properties.get( renderTarget );
  489. renderTarget.removeEventListener( 'dispose', renderTargetProperties.disposeCallback );
  490. renderTargetProperties.colorTextureGPU.destroy();
  491. properties.remove( renderTarget.texture );
  492. this.info.memory.textures --;
  493. if ( renderTarget.depthBuffer === true ) {
  494. renderTargetProperties.depthTextureGPU.destroy();
  495. this.info.memory.textures --;
  496. if ( renderTarget.depthTexture !== null ) {
  497. properties.remove( renderTarget.depthTexture );
  498. }
  499. }
  500. properties.remove( renderTarget );
  501. }
  502. function onTextureDispose( event ) {
  503. const texture = event.target;
  504. const textureProperties = this.properties.get( texture );
  505. textureProperties.textureGPU.destroy();
  506. texture.removeEventListener( 'dispose', textureProperties.disposeCallback );
  507. this.properties.remove( texture );
  508. this.info.memory.textures --;
  509. }
  510. export default WebGPUTextures;