@zephyr3d/device 0.2.7 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Nullable, Immutable, TypedArray, IDisposable, CubeFace, VectorBase, MaybeArray, IEventTarget, Vector4, Observable } from '@zephyr3d/base';
1
+ import { Nullable, Immutable, TypedArray, IDisposable, CubeFace, VectorBase, MaybeArray, IEventTarget, Vector3, Vector4, Rect, Observable } from '@zephyr3d/base';
2
2
 
3
3
  /**
4
4
  * Struct layout types
@@ -3122,6 +3122,8 @@ interface FrameInfo {
3122
3122
  * @public
3123
3123
  */
3124
3124
  interface GPUObjectList {
3125
+ /** Creation stack */
3126
+ stacks: Map<GPUObject, string>;
3125
3127
  /** list of textures */
3126
3128
  textures: BaseTexture[];
3127
3129
  /** list of samplers */
@@ -3357,6 +3359,28 @@ type DeviceViewport = {
3357
3359
  */
3358
3360
  default: boolean;
3359
3361
  };
3362
+ /**
3363
+ * Horizontal alignment for text layout
3364
+ * @public
3365
+ */
3366
+ type TextHorizontalAlignment = 'left' | 'center' | 'right';
3367
+ /**
3368
+ * Vertical alignment for text layout
3369
+ * @public
3370
+ */
3371
+ type TextVerticalAlignment = 'top' | 'center' | 'bottom';
3372
+ /**
3373
+ * Layout options for drawing text inside a rectangle
3374
+ * @public
3375
+ */
3376
+ interface DrawTextLayoutOptions {
3377
+ /** Horizontal alignment of each line */
3378
+ halign?: TextHorizontalAlignment;
3379
+ /** Vertical alignment of the text block */
3380
+ valign?: TextVerticalAlignment;
3381
+ /** Whether to wrap text automatically to fit the rectangle width */
3382
+ wordWrap?: boolean;
3383
+ }
3360
3384
  /**
3361
3385
  * Abstract interface for the rendering device.
3362
3386
  * @public
@@ -3395,7 +3419,9 @@ interface AbstractDevice extends IEventTarget<DeviceEventMap> {
3395
3419
  /** Cancel schedule next frame */
3396
3420
  cancelNextFrame(handle: number): void;
3397
3421
  /** Set font for drawText function */
3398
- setFont(fontName: string): void;
3422
+ setFont(fontName: Nullable<string>): void;
3423
+ /** Set render states to be used when drawing text. If not set, default states will be used. */
3424
+ setTextRenderStates(states: Nullable<RenderStateSet>): void;
3399
3425
  /**
3400
3426
  * Draw a string
3401
3427
  * @param text - The string that will be drawn
@@ -3403,7 +3429,15 @@ interface AbstractDevice extends IEventTarget<DeviceEventMap> {
3403
3429
  * @param y - y coordinate in pixels related to the viewport origin
3404
3430
  * @param color - A CSS color value
3405
3431
  */
3406
- drawText(text: string, x: number, y: number, color: string, viewport?: Immutable<number[]>): void;
3432
+ drawText(text: string, x: number, y: number, color: string | Vector3 | Vector4): void;
3433
+ /**
3434
+ * Draw a string inside a rectangle with layout and clipping
3435
+ * @param text - The string that will be drawn
3436
+ * @param rect - Layout rectangle in pixels related to the viewport origin
3437
+ * @param color - A CSS color value
3438
+ * @param options - Text layout options
3439
+ */
3440
+ drawText(text: string, rect: Immutable<Rect>, color: string | Vector3 | Vector4, options?: DrawTextLayoutOptions): void;
3407
3441
  /**
3408
3442
  * Clears the current frame buffer
3409
3443
  * @param clearColor - If not null, the color buffer will be cleared to this value.
@@ -3984,8 +4018,10 @@ declare abstract class BaseDevice extends Observable<DeviceEventMap> {
3984
4018
  get programBuilder(): ProgramBuilder;
3985
4019
  poolExists(key: string | symbol): boolean;
3986
4020
  getPool(key: string | symbol): Pool;
3987
- setFont(fontName: string): void;
3988
- drawText(text: string, x: number, y: number, color: string, viewport?: Immutable<number[]>): void;
4021
+ setFont(fontName: Nullable<string>): void;
4022
+ setTextRenderStates(renderStates: Nullable<RenderStateSet>): void;
4023
+ drawText(text: string, x: number, y: number, color: string | Vector3 | Vector4): void;
4024
+ drawText(text: string, rect: Immutable<Rect>, color: string | Vector3 | Vector4, options?: DrawTextLayoutOptions): void;
3989
4025
  setFramebuffer(rt: Nullable<FrameBuffer>): void;
3990
4026
  setFramebuffer(color: BaseTexture[], depth?: BaseTexture, sampleCount?: number): void;
3991
4027
  disposeObject(obj: GPUObject, remove?: boolean): void;
@@ -4014,6 +4050,7 @@ declare abstract class BaseDevice extends Observable<DeviceEventMap> {
4014
4050
  deviceYToScreen(val: number): number;
4015
4051
  buildRenderProgram(options: PBRenderOptions): Nullable<GPUProgram<unknown>>;
4016
4052
  buildComputeProgram(options: PBComputeOptions): Nullable<GPUProgram<unknown>>;
4053
+ getGPUObjectStack(obj: GPUObject): string;
4017
4054
  addGPUObject(obj: GPUObject): void;
4018
4055
  removeGPUObject(obj: GPUObject): void;
4019
4056
  updateVideoMemoryCost(delta: number): void;
@@ -4075,6 +4112,18 @@ declare class TextureAtlasManager {
4075
4112
  * @returns Atlas texture for given index
4076
4113
  */
4077
4114
  getAtlasTexture(index: number): Texture2D<unknown> | undefined;
4115
+ /**
4116
+ * Width of each atlas bin in texels.
4117
+ */
4118
+ get binWidth(): number;
4119
+ /**
4120
+ * Height of each atlas bin in texels.
4121
+ */
4122
+ get binHeight(): number;
4123
+ /**
4124
+ * Border reserved around each packed rectangle in texels.
4125
+ */
4126
+ get rectBorderWidth(): number;
4078
4127
  /**
4079
4128
  * Gets the information about specified atlas
4080
4129
  * @param key - Key of the atlas
@@ -4211,7 +4260,12 @@ declare class DrawText {
4211
4260
  * @param device - The render device
4212
4261
  * @param name - The font name
4213
4262
  */
4214
- static setFont(device: AbstractDevice, name: string): void;
4263
+ static setFont(device: AbstractDevice, name: Nullable<string>): void;
4264
+ /**
4265
+ * Set render states to be used when drawing text. If not set, default states will be used.
4266
+ * @param renderStates - The render states to use when drawing text. If null, default states will be used.
4267
+ */
4268
+ static setRenderStates(renderStates: Nullable<RenderStateSet>): void;
4215
4269
  /**
4216
4270
  * Draw text onto the screen
4217
4271
  * @param device - The render device
@@ -4220,7 +4274,16 @@ declare class DrawText {
4220
4274
  * @param x - X coordinate of the text
4221
4275
  * @param y - Y coordinate of the text
4222
4276
  */
4223
- static drawText(device: AbstractDevice, text: string, color: string, x: number, y: number, viewport?: Immutable<number[]>): void;
4277
+ static drawText(device: AbstractDevice, text: string, color: string | Vector3 | Vector4, x: number, y: number): void;
4278
+ /**
4279
+ * Draw text inside a rectangle with layout and clipping
4280
+ * @param device - The render device
4281
+ * @param text - The text to be drawn
4282
+ * @param color - The text color
4283
+ * @param rect - The layout rectangle
4284
+ * @param options - Layout options
4285
+ */
4286
+ static drawText(device: AbstractDevice, text: string, color: string | Vector3 | Vector4, rect: Immutable<Rect>, options?: DrawTextLayoutOptions): void;
4224
4287
  }
4225
4288
 
4226
4289
  /**
@@ -4248,4 +4311,4 @@ declare class StructuredBufferData {
4248
4311
  set(name: string, value: StructuredValue): void;
4249
4312
  }
4250
4313
 
4251
- export { type AbstractDevice, type ArrayTypeDetail, type AtlasInfo, type AtomicTypeInfoDetail, type BaseCreationOptions, BaseDevice, type BaseTexture, type BindGroup, type BindGroupLayout, type BindGroupLayoutEntry, type BindPointInfo, type BlendEquation, type BlendFunc, type BlendingState, type BufferBindingLayout, type BufferCreationOptions, type BufferUsage, CPUTimer, type ColorState, type CompareFunc, type ComputeProgramConstructParams, type DataType, type DepthState, type DeviceBackend, type DeviceCaps, type DeviceEventMap, type DeviceOptions, type DeviceViewport, DrawText, type ExpValueNonArrayType, type ExpValueType, type ExternalTextureBindingLayout, type FaceMode, type FaceWinding, Font, type FrameBuffer, type FrameBufferOptions, type FrameBufferTextureAttachment, type FrameInfo, type FramebufferCaps, type FunctionTypeDetail, type GPUDataBuffer, type GPUObject, type GPUObjectList, type GPUProgram, type GPUProgramConstructParams, GPUResourceUsageFlags, GlyphManager, type ITimer, type IndexBuffer, MAX_BINDING_GROUPS, MAX_TEXCOORD_INDEX_COUNT, MAX_VERTEX_ATTRIBUTES, type MiscCaps, PBAddressSpace, PBAnyTypeInfo, PBArrayTypeInfo, PBAtomicI32TypeInfo, PBAtomicU32TypeInfo, PBBuiltinScope, type PBComputeOptions, PBDoWhileScope, PBForScope, PBFunctionScope, PBFunctionTypeInfo, PBGlobalScope, PBIfScope, PBInputScope, PBInsideFunctionScope, PBLocalScope, PBNakedScope, PBOutputScope, PBPointerTypeInfo, PBPrimitiveType, PBPrimitiveTypeInfo, PBReflection, type PBReflectionTagGetter, type PBRenderOptions, PBSamplerAccessMode, PBSamplerTypeInfo, PBScope, PBShaderExp, type PBStructLayout, PBStructTypeInfo, PBTextureType, PBTextureTypeInfo, PBTypeInfo, PBVoidTypeInfo, PBWhileScope, type PointerTypeDetail, Pool, type PrimitiveType, type PrimitiveTypeDetail, ProgramBuilder, Proxiable, type RasterizerState, type RenderBundle, type RenderProgramConstructParams, type RenderStateSet, type SamplerBindingLayout, type SamplerOptions, type SamplerTypeDetail, type ShaderCaps, type ShaderExpTagRecord, type ShaderExpTagValue, type ShaderKind, ShaderType, type ShaderTypeFunc, type StencilOp, type StencilState, type StorageTextureBindingLayout, type StructTypeDetail, type StructuredBuffer, StructuredBufferData, type StructuredValue, type Texture2D, type Texture2DArray, type Texture3D, type TextureAddressMode, TextureAtlasManager, type TextureBindingLayout, type TextureCaps, type TextureColorSpace, type TextureCreationOptions, type TextureCube, type TextureFilterMode, type TextureFormat, type TextureFormatInfo, type TextureImageElement, type TextureMipmapData, type TextureMipmapLevelData, type TextureSampler, type TextureType, type TextureTypeDetail, type TextureVideo, type TypeDetailInfo, type UniformBufferLayout, type UniformLayout, VERTEX_ATTRIB_BLEND_INDICES, VERTEX_ATTRIB_BLEND_WEIGHT, VERTEX_ATTRIB_DIFFUSE, VERTEX_ATTRIB_NORMAL, VERTEX_ATTRIB_POSITION, VERTEX_ATTRIB_TANGENT, VERTEX_ATTRIB_TEXCOORD0, VERTEX_ATTRIB_TEXCOORD1, VERTEX_ATTRIB_TEXCOORD2, VERTEX_ATTRIB_TEXCOORD3, VERTEX_ATTRIB_TEXCOORD4, VERTEX_ATTRIB_TEXCOORD5, VERTEX_ATTRIB_TEXCOORD6, VERTEX_ATTRIB_TEXCOORD7, type VertexAttribFormat, type VertexBufferInfo, VertexData, type VertexLayout, type VertexLayoutOptions, type VertexSemantic, type VertexStepMode, type WebGLContext, genDefaultName, getTextureFormatBlockHeight, getTextureFormatBlockSize, getTextureFormatBlockWidth, getVertexAttribByName, getVertexAttribFormat, getVertexAttribName, getVertexAttributeFormat, getVertexAttributeIndex, getVertexBufferAttribType, getVertexBufferAttribTypeBySemantic, getVertexBufferLength, getVertexBufferStride, getVertexFormatComponentCount, getVertexFormatSize, hasAlphaChannel, hasBlueChannel, hasDepthChannel, hasGreenChannel, hasRedChannel, hasStencilChannel, isCompressedTextureFormat, isFloatTextureFormat, isIntegerTextureFormat, isSRGBTextureFormat, isSignedTextureFormat, linearTextureFormatToSRGB, makeVertexBufferType, matchVertexBuffer, semanticList };
4314
+ export { type AbstractDevice, type ArrayTypeDetail, type AtlasInfo, type AtomicTypeInfoDetail, type BaseCreationOptions, BaseDevice, type BaseTexture, type BindGroup, type BindGroupLayout, type BindGroupLayoutEntry, type BindPointInfo, type BlendEquation, type BlendFunc, type BlendingState, type BufferBindingLayout, type BufferCreationOptions, type BufferUsage, CPUTimer, type ColorState, type CompareFunc, type ComputeProgramConstructParams, type DataType, type DepthState, type DeviceBackend, type DeviceCaps, type DeviceEventMap, type DeviceOptions, type DeviceViewport, DrawText, type DrawTextLayoutOptions, type ExpValueNonArrayType, type ExpValueType, type ExternalTextureBindingLayout, type FaceMode, type FaceWinding, Font, type FrameBuffer, type FrameBufferOptions, type FrameBufferTextureAttachment, type FrameInfo, type FramebufferCaps, type FunctionTypeDetail, type GPUDataBuffer, type GPUObject, type GPUObjectList, type GPUProgram, type GPUProgramConstructParams, GPUResourceUsageFlags, GlyphManager, type ITimer, type IndexBuffer, MAX_BINDING_GROUPS, MAX_TEXCOORD_INDEX_COUNT, MAX_VERTEX_ATTRIBUTES, type MiscCaps, PBAddressSpace, PBAnyTypeInfo, PBArrayTypeInfo, PBAtomicI32TypeInfo, PBAtomicU32TypeInfo, PBBuiltinScope, type PBComputeOptions, PBDoWhileScope, PBForScope, PBFunctionScope, PBFunctionTypeInfo, PBGlobalScope, PBIfScope, PBInputScope, PBInsideFunctionScope, PBLocalScope, PBNakedScope, PBOutputScope, PBPointerTypeInfo, PBPrimitiveType, PBPrimitiveTypeInfo, PBReflection, type PBReflectionTagGetter, type PBRenderOptions, PBSamplerAccessMode, PBSamplerTypeInfo, PBScope, PBShaderExp, type PBStructLayout, PBStructTypeInfo, PBTextureType, PBTextureTypeInfo, PBTypeInfo, PBVoidTypeInfo, PBWhileScope, type PointerTypeDetail, Pool, type PrimitiveType, type PrimitiveTypeDetail, ProgramBuilder, Proxiable, type RasterizerState, type RenderBundle, type RenderProgramConstructParams, type RenderStateSet, type SamplerBindingLayout, type SamplerOptions, type SamplerTypeDetail, type ShaderCaps, type ShaderExpTagRecord, type ShaderExpTagValue, type ShaderKind, ShaderType, type ShaderTypeFunc, type StencilOp, type StencilState, type StorageTextureBindingLayout, type StructTypeDetail, type StructuredBuffer, StructuredBufferData, type StructuredValue, type TextHorizontalAlignment, type TextVerticalAlignment, type Texture2D, type Texture2DArray, type Texture3D, type TextureAddressMode, TextureAtlasManager, type TextureBindingLayout, type TextureCaps, type TextureColorSpace, type TextureCreationOptions, type TextureCube, type TextureFilterMode, type TextureFormat, type TextureFormatInfo, type TextureImageElement, type TextureMipmapData, type TextureMipmapLevelData, type TextureSampler, type TextureType, type TextureTypeDetail, type TextureVideo, type TypeDetailInfo, type UniformBufferLayout, type UniformLayout, VERTEX_ATTRIB_BLEND_INDICES, VERTEX_ATTRIB_BLEND_WEIGHT, VERTEX_ATTRIB_DIFFUSE, VERTEX_ATTRIB_NORMAL, VERTEX_ATTRIB_POSITION, VERTEX_ATTRIB_TANGENT, VERTEX_ATTRIB_TEXCOORD0, VERTEX_ATTRIB_TEXCOORD1, VERTEX_ATTRIB_TEXCOORD2, VERTEX_ATTRIB_TEXCOORD3, VERTEX_ATTRIB_TEXCOORD4, VERTEX_ATTRIB_TEXCOORD5, VERTEX_ATTRIB_TEXCOORD6, VERTEX_ATTRIB_TEXCOORD7, type VertexAttribFormat, type VertexBufferInfo, VertexData, type VertexLayout, type VertexLayoutOptions, type VertexSemantic, type VertexStepMode, type WebGLContext, genDefaultName, getTextureFormatBlockHeight, getTextureFormatBlockSize, getTextureFormatBlockWidth, getVertexAttribByName, getVertexAttribFormat, getVertexAttribName, getVertexAttributeFormat, getVertexAttributeIndex, getVertexBufferAttribType, getVertexBufferAttribTypeBySemantic, getVertexBufferLength, getVertexBufferStride, getVertexFormatComponentCount, getVertexFormatSize, hasAlphaChannel, hasBlueChannel, hasDepthChannel, hasGreenChannel, hasRedChannel, hasStencilChannel, isCompressedTextureFormat, isFloatTextureFormat, isIntegerTextureFormat, isSRGBTextureFormat, isSignedTextureFormat, linearTextureFormatToSRGB, makeVertexBufferType, matchVertexBuffer, semanticList };
package/dist/pool.js CHANGED
@@ -259,7 +259,7 @@
259
259
  */ releaseTexture(texture) {
260
260
  const info = this._allocatedTextures.get(texture);
261
261
  if (!info) {
262
- console.error(`ObjectPool.releaseTexture(): texture is not allocated from pool`);
262
+ console.error(`ObjectPool.releaseTexture(): texture is not allocated from pool: ${this._device.getGPUObjects().stacks.get(texture) ?? '<No stack>'}`);
263
263
  } else {
264
264
  this.safeReleaseTexture(texture);
265
265
  }
@@ -270,7 +270,7 @@
270
270
  */ retainTexture(texture) {
271
271
  const info = this._allocatedTextures.get(texture);
272
272
  if (!info) {
273
- console.error(`ObjectPool.retainTexture(): texture is not allocated from pool`);
273
+ console.error(`ObjectPool.retainTexture(): texture is not allocated from pool: ${this._device.getGPUObjects().stacks.get(texture) ?? '<No stack>'}`);
274
274
  } else {
275
275
  info.refcount++;
276
276
  }
package/dist/pool.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pool.js","sources":["../src/pool.ts"],"sourcesContent":["import type { Nullable, MaybeArray } from '@zephyr3d/base';\r\nimport type { AbstractDevice, TextureFormat } from './base_types';\r\nimport type { BaseTexture, FrameBuffer, Texture2D, Texture2DArray, TextureCube } from './gpuobject';\r\n\r\n/**\r\n * ObjectPool class is responsible for managing and reusing textures and framebuffers.\r\n * @public\r\n */\r\nexport class Pool {\r\n /** @internal */\r\n private _memCost: number;\r\n /** @internal */\r\n private readonly _memCostThreshold: number;\r\n /** @internal */\r\n private readonly _device: AbstractDevice;\r\n /** @internal */\r\n private readonly _id: string | symbol;\r\n /** @internal */\r\n private _freeTextures: Record<string, BaseTexture[]> = {};\r\n /** @internal */\r\n private readonly _allocatedTextures: WeakMap<\r\n BaseTexture,\r\n { hash: string; refcount: number; dispose: boolean }\r\n > = new WeakMap();\r\n /** @internal */\r\n private readonly _autoReleaseTextures: Set<BaseTexture> = new Set();\r\n /** @internal */\r\n private _freeFramebuffers: Record<string, FrameBuffer[]> = {};\r\n /** @internal */\r\n private readonly _allocatedFramebuffers: WeakMap<FrameBuffer, { hash: string; refcount: number }> =\r\n new WeakMap();\r\n /** @internal */\r\n private readonly _autoReleaseFramebuffers: Set<FrameBuffer> = new Set();\r\n /**\r\n * Creates an instance of Pool class\r\n * @param device - Rendering device\r\n */\r\n constructor(device: AbstractDevice, id: string | symbol, memCostThreshold = 1024 * 1024 * 1024) {\r\n this._device = device;\r\n this._id = id;\r\n this._memCost = 0;\r\n this._memCostThreshold = memCostThreshold;\r\n this._freeTextures = {};\r\n this._allocatedTextures = new WeakMap();\r\n this._autoReleaseTextures = new Set();\r\n this._freeFramebuffers = {};\r\n this._allocatedFramebuffers = new WeakMap();\r\n this._autoReleaseFramebuffers = new Set();\r\n this._memCost = 0;\r\n }\r\n /**\r\n * Id for this pool\r\n */\r\n get id() {\r\n return this._id;\r\n }\r\n autoRelease() {\r\n // auto release objects\r\n for (const tex of this._autoReleaseTextures) {\r\n this.releaseTexture(tex);\r\n }\r\n this._autoReleaseTextures.clear();\r\n for (const fb of this._autoReleaseFramebuffers) {\r\n this.releaseFrameBuffer(fb);\r\n }\r\n this._autoReleaseFramebuffers.clear();\r\n // Free up video memory if memory usage is greater than specific value\r\n if (this._memCost >= this._memCostThreshold) {\r\n this.purge();\r\n }\r\n }\r\n /**\r\n * Fetch a temporal 2D texture from the object pool.\r\n * @param autoRelease - Whether the texture should be automatically released at the next frame.\r\n * @param format - The format of the texture.\r\n * @param width - The width of the texture.\r\n * @param height - The height of the texture.\r\n * @param mipmapping - Whether this texture support mipmapping\r\n * @returns The fetched Texture2D object.\r\n */\r\n fetchTemporalTexture2D(\r\n autoRelease: boolean,\r\n format: TextureFormat,\r\n width: number,\r\n height: number,\r\n mipmapping = false\r\n ) {\r\n const hash = `2d:${format}:${width}:${height}:${mipmapping ? 1 : 0}`;\r\n let texture: Nullable<BaseTexture> = null;\r\n const list = this._freeTextures[hash];\r\n if (!list) {\r\n texture = this._device.createTexture2D(format, width, height, { mipmapping });\r\n if (!texture) {\r\n throw new Error(`Create 2D texture failed: ${format}-${width}x${height}`);\r\n }\r\n this._memCost += texture.memCost;\r\n } else {\r\n texture = list.pop()!;\r\n if (list.length === 0) {\r\n delete this._freeTextures[hash];\r\n }\r\n }\r\n this._allocatedTextures.set(texture, { hash, refcount: 1, dispose: false });\r\n if (autoRelease) {\r\n this._autoReleaseTextures.add(texture);\r\n }\r\n return texture as Texture2D;\r\n }\r\n /**\r\n * Fetch a temporal 2D array texture from the object pool.\r\n * @param autoRelease - Whether the texture should be automatically released at the next frame.\r\n * @param format - Format of the texture.\r\n * @param width - Width of the texture.\r\n * @param height - Height of the texture.\r\n * @param numLayers - Layer count of the texture\r\n * @param mipmapping - Whether this texture support mipmapping\r\n * @returns The fetched Texture2DArray object.\r\n */\r\n fetchTemporalTexture2DArray(\r\n autoRelease: boolean,\r\n format: TextureFormat,\r\n width: number,\r\n height: number,\r\n numLayers: number,\r\n mipmapping = false\r\n ) {\r\n const hash = `2darray:${format}:${width}:${height}:${numLayers}:${mipmapping ? 1 : 0}`;\r\n let texture: Nullable<BaseTexture> = null;\r\n const list = this._freeTextures[hash];\r\n if (!list) {\r\n texture = this._device.createTexture2DArray(format, width, height, numLayers, { mipmapping });\r\n if (!texture) {\r\n throw new Error(`Create 2DArray texture failed: ${format}-${width}x${height}x${numLayers}`);\r\n }\r\n this._memCost += texture.memCost;\r\n } else {\r\n texture = list.pop()!;\r\n if (list.length === 0) {\r\n delete this._freeTextures[hash];\r\n }\r\n }\r\n this._allocatedTextures.set(texture, { hash, refcount: 1, dispose: false });\r\n if (autoRelease) {\r\n this._autoReleaseTextures.add(texture);\r\n }\r\n return texture as Texture2DArray;\r\n }\r\n /**\r\n * Fetch a temporal Cube texture from the object pool.\r\n * @param autoRelease - Whether the texture should be automatically released at the next frame.\r\n * @param format - Format of the texture.\r\n * @param size - size of the texture.\r\n * @param mipmapping - Whether this texture support mipmapping\r\n * @returns The fetched TextureCube object.\r\n */\r\n fetchTemporalTextureCube(autoRelease: boolean, format: TextureFormat, size: number, mipmapping = false) {\r\n const hash = `cube:${format}:${size}:${mipmapping ? 1 : 0}`;\r\n let texture: Nullable<BaseTexture> = null;\r\n const list = this._freeTextures[hash];\r\n if (!list) {\r\n texture = this._device.createCubeTexture(format, size, { mipmapping });\r\n if (!texture) {\r\n throw new Error(`Create Cube texture failed: ${format}-${size}`);\r\n }\r\n this._memCost += texture.memCost;\r\n } else {\r\n texture = list.pop()!;\r\n if (list.length === 0) {\r\n delete this._freeTextures[hash];\r\n }\r\n }\r\n this._allocatedTextures.set(texture, { hash, refcount: 1, dispose: false });\r\n if (autoRelease) {\r\n this._autoReleaseTextures.add(texture);\r\n }\r\n return texture as TextureCube;\r\n }\r\n /**\r\n * Creates a temporal framebuffer from the object pool.\r\n * @param autoRelease - Whether the framebuffer should be automatically released at the next frame.\r\n * @param width - Width of the framebuffer\r\n * @param height - Height of the framebuffer\r\n * @param colorAttachments - Array of color attachments or texture format of the framebuffer.\r\n * @param depthAttachment - Depth attachment or texture format of the framebuffer.\r\n * @param mipmapping - Whether mipmapping should be enabled when creating color attachment textures, default is false.\r\n * @param sampleCount - The sample count for the framebuffer, default is 1.\r\n * @param ignoreDepthStencil - Whether to ignore depth stencil when resolving msaa framebuffer, default is true.\r\n * @param attachmentMipLevel - The mipmap level to which the color attachment will render, default is 0\r\n * @param attachmentCubeface - The cubemap face to which the color attachment will render, default is 0\r\n * @param attachmentLayer - The texture layer to which the color attachment will render, default is 0\r\n * @returns The fetched FrameBuffer object.\r\n */\r\n fetchTemporalFramebuffer<T extends BaseTexture<unknown>>(\r\n autoRelease: boolean,\r\n width: number,\r\n height: number,\r\n colorTexOrFormat: MaybeArray<TextureFormat | T>,\r\n depthTexOrFormat: Nullable<TextureFormat | T> = null,\r\n mipmapping = false,\r\n sampleCount = 1,\r\n ignoreDepthStencil = true,\r\n attachmentMipLevel = 0,\r\n attachmentCubeface = 0,\r\n attachmentLayer = 0\r\n ) {\r\n const colors = Array.isArray(colorTexOrFormat)\r\n ? colorTexOrFormat\r\n : colorTexOrFormat\r\n ? [colorTexOrFormat]\r\n : [];\r\n const colorAttachments = colors.map((val) => {\r\n return typeof val === 'string'\r\n ? this.fetchTemporalTexture2D(false, val, width, height, mipmapping)\r\n : val;\r\n });\r\n const depthAttachment =\r\n typeof depthTexOrFormat === 'string'\r\n ? this.fetchTemporalTexture2D(false, depthTexOrFormat, width, height, false)\r\n : depthTexOrFormat;\r\n const fb = this.createTemporalFramebuffer(\r\n autoRelease,\r\n colorAttachments,\r\n depthAttachment,\r\n sampleCount,\r\n ignoreDepthStencil,\r\n attachmentMipLevel,\r\n attachmentCubeface,\r\n attachmentLayer\r\n );\r\n for (let i = 0; i < colors.length; i++) {\r\n if (typeof colors[i] === 'string') {\r\n this.releaseTexture(colorAttachments[i]);\r\n }\r\n }\r\n if (!!depthAttachment && typeof depthTexOrFormat === 'string') {\r\n this.releaseTexture(depthAttachment);\r\n }\r\n return fb;\r\n }\r\n /**\r\n * Creates a temporal framebuffer from the object pool.\r\n * @param autoRelease - Whether the framebuffer should be automatically released at the next frame.\r\n * @param colorAttachments - Array of color attachments for the framebuffer.\r\n * @param depthAttachment - Depth attachment for the framebuffer.\r\n * @param sampleCount - The sample count for the framebuffer, default is 1.\r\n * @param ignoreDepthStencil - Whether to ignore depth stencil when resolving msaa framebuffer, default is true.\r\n * @param attachmentMipLevel - The mipmap level to which the color attachment will render, default is 0.\r\n * @param attachmentCubeface - The cubemap face to which the color attachment will render, default is 0.\r\n * @param attachmentLayer - The texture layer to which the color attachment will render, default is 0.\r\n * @returns The fetched FrameBuffer object.\r\n */\r\n createTemporalFramebuffer(\r\n autoRelease: boolean,\r\n colorAttachments: BaseTexture[],\r\n depthAttachment: Nullable<BaseTexture> = null,\r\n sampleCount = 1,\r\n ignoreDepthStencil = true,\r\n attachmentMipLevel = 0,\r\n attachmentCubeface = 0,\r\n attachmentLayer = 0\r\n ) {\r\n colorAttachments = colorAttachments ?? [];\r\n let hash = `${depthAttachment?.uid ?? 0}:${sampleCount ?? 1}:${ignoreDepthStencil ? 1 : 0}`;\r\n if (colorAttachments.length > 0) {\r\n hash += `:${attachmentMipLevel}:${attachmentCubeface}:${attachmentLayer}`;\r\n for (const tex of colorAttachments) {\r\n hash += `:${tex.uid}`;\r\n }\r\n }\r\n let fb: Nullable<FrameBuffer> = null;\r\n const list = this._freeFramebuffers[hash];\r\n if (!list) {\r\n fb = this._device.createFrameBuffer(colorAttachments, depthAttachment, {\r\n ignoreDepthStencil,\r\n sampleCount\r\n });\r\n for (let i = 0; i < fb.getColorAttachments().length; i++) {\r\n fb.setColorAttachmentMipLevel(i, attachmentMipLevel);\r\n fb.setColorAttachmentCubeFace(i, attachmentCubeface);\r\n fb.setColorAttachmentLayer(i, attachmentLayer);\r\n }\r\n } else {\r\n fb = list.pop()!;\r\n if (list.length === 0) {\r\n delete this._freeFramebuffers[hash];\r\n }\r\n }\r\n // Mark referenced textures\r\n const info = depthAttachment ? this._allocatedTextures.get(depthAttachment) : null;\r\n if (info) {\r\n info.refcount++;\r\n }\r\n for (const tex of colorAttachments) {\r\n const info = this._allocatedTextures.get(tex);\r\n if (info) {\r\n info.refcount++;\r\n }\r\n }\r\n this._allocatedFramebuffers.set(fb, { hash, refcount: 1 });\r\n if (autoRelease) {\r\n this._autoReleaseFramebuffers.add(fb);\r\n }\r\n return fb;\r\n }\r\n /**\r\n * Dispose a texture that is allocated from the object pool.\r\n * @param texture - The texture to dispose.\r\n */\r\n disposeTexture(texture: BaseTexture) {\r\n this.safeReleaseTexture(texture, true);\r\n }\r\n /**\r\n * Release a texture back to the object pool.\r\n * @param texture - The texture to release.\r\n */\r\n releaseTexture(texture: BaseTexture) {\r\n const info = this._allocatedTextures.get(texture);\r\n if (!info) {\r\n console.error(`ObjectPool.releaseTexture(): texture is not allocated from pool`);\r\n } else {\r\n this.safeReleaseTexture(texture);\r\n }\r\n }\r\n /**\r\n * Increment reference counter for given texture\r\n * @param texture - The texture to retain\r\n */\r\n retainTexture(texture: BaseTexture) {\r\n const info = this._allocatedTextures.get(texture);\r\n if (!info) {\r\n console.error(`ObjectPool.retainTexture(): texture is not allocated from pool`);\r\n } else {\r\n info.refcount++;\r\n }\r\n }\r\n /**\r\n * Dispose a framebuffer that is allocated from the object pool.\r\n * @param fb - The framebuffer to dispose.\r\n */\r\n disposeFrameBuffer(fb: FrameBuffer) {\r\n const hash = this._allocatedFramebuffers.get(fb);\r\n if (!hash) {\r\n console.error(`ObjectPool.disposeFrameBuffer(): framebuffer is not allocated from pool`);\r\n } else {\r\n this.internalDisposeFrameBuffer(fb);\r\n fb.dispose();\r\n }\r\n }\r\n /**\r\n * Release a framebuffer back to the object pool.\r\n * @param fb - The framebuffer to release.\r\n */\r\n releaseFrameBuffer(fb: FrameBuffer) {\r\n const info = this._allocatedFramebuffers.get(fb);\r\n if (!info) {\r\n console.error(`ObjectPool.releaseFrameBuffer(): framebuffer is not allocated from pool`);\r\n } else {\r\n info.refcount--;\r\n if (info.refcount <= 0) {\r\n this.internalDisposeFrameBuffer(fb);\r\n const list = this._freeFramebuffers[info.hash];\r\n if (list) {\r\n list.push(fb);\r\n } else {\r\n this._freeFramebuffers[info.hash] = [fb];\r\n }\r\n }\r\n }\r\n }\r\n /**\r\n * Increment reference counter for given framebuffer\r\n * @param fb - The framebuffer to retain\r\n */\r\n retainFrameBuffer(fb: FrameBuffer) {\r\n const info = this._allocatedFramebuffers.get(fb);\r\n if (!info) {\r\n console.error(`ObjectPool.retainFrameBuffer(): framebuffer is not allocated from pool`);\r\n } else {\r\n info.refcount++;\r\n }\r\n }\r\n /**\r\n * Purge the object pool by disposing all free framebuffers and textures.\r\n */\r\n purge() {\r\n for (const k in this._freeFramebuffers) {\r\n const list = this._freeFramebuffers[k];\r\n if (list) {\r\n for (const fb of this._freeFramebuffers[k]) {\r\n this.internalDisposeFrameBuffer(fb);\r\n fb.dispose();\r\n }\r\n }\r\n }\r\n this._freeFramebuffers = {};\r\n for (const k in this._freeTextures) {\r\n const list = this._freeTextures[k];\r\n for (const tex of list) {\r\n this._memCost -= tex.memCost;\r\n tex.dispose();\r\n }\r\n }\r\n this._freeTextures = {};\r\n }\r\n /** @internal */\r\n private internalDisposeFrameBuffer(fb: FrameBuffer) {\r\n if (fb) {\r\n // Release attachment textures\r\n const colorAttachments = fb.getColorAttachments();\r\n if (colorAttachments) {\r\n for (const tex of colorAttachments) {\r\n this.safeReleaseTexture(tex);\r\n }\r\n }\r\n const depthAttachment = fb.getDepthAttachment();\r\n if (depthAttachment) {\r\n this.safeReleaseTexture(depthAttachment);\r\n }\r\n this._allocatedFramebuffers.delete(fb);\r\n this._autoReleaseFramebuffers.delete(fb);\r\n }\r\n }\r\n /** @internal */\r\n private safeReleaseTexture(texture: BaseTexture, purge = false) {\r\n const info = this._allocatedTextures.get(texture);\r\n if (info) {\r\n info.refcount--;\r\n if (info.refcount <= 0) {\r\n this._allocatedTextures.delete(texture);\r\n this._autoReleaseTextures.delete(texture);\r\n if (purge || info.dispose) {\r\n this._memCost -= texture.memCost;\r\n texture.dispose();\r\n } else {\r\n const list = this._freeTextures[info.hash];\r\n if (list) {\r\n list.push(texture);\r\n } else {\r\n this._freeTextures[info.hash] = [texture];\r\n }\r\n }\r\n } else if (purge) {\r\n info.dispose = true;\r\n }\r\n }\r\n }\r\n}\r\n"],"names":["Pool","_freeTextures","_allocatedTextures","WeakMap","_autoReleaseTextures","Set","_freeFramebuffers","_allocatedFramebuffers","_autoReleaseFramebuffers","device","id","memCostThreshold","_device","_id","_memCost","_memCostThreshold","autoRelease","tex","releaseTexture","clear","fb","releaseFrameBuffer","purge","fetchTemporalTexture2D","format","width","height","mipmapping","hash","texture","list","createTexture2D","Error","memCost","pop","length","set","refcount","dispose","add","fetchTemporalTexture2DArray","numLayers","createTexture2DArray","fetchTemporalTextureCube","size","createCubeTexture","fetchTemporalFramebuffer","colorTexOrFormat","depthTexOrFormat","sampleCount","ignoreDepthStencil","attachmentMipLevel","attachmentCubeface","attachmentLayer","colors","Array","isArray","colorAttachments","map","val","depthAttachment","createTemporalFramebuffer","i","uid","createFrameBuffer","getColorAttachments","setColorAttachmentMipLevel","setColorAttachmentCubeFace","setColorAttachmentLayer","info","get","disposeTexture","safeReleaseTexture","console","error","retainTexture","disposeFrameBuffer","internalDisposeFrameBuffer","push","retainFrameBuffer","k","getDepthAttachment","delete"],"mappings":"AAIA;;;AAGC,IACM,MAAMA,IAAAA,CAAAA;qBAEX,QAAyB;qBAEzB,iBAA2C;qBAE3C,OAAyC;qBAEzC,GAAsC;AACtC,qBACQC,aAA+C,GAAA,EAAG;AAC1D,qBACiBC,kBAGb,GAAA,IAAIC,OAAU,EAAA;AAClB,qBACiBC,oBAAyC,GAAA,IAAIC,GAAM,EAAA;AACpE,qBACQC,iBAAmD,GAAA,EAAG;AAC9D,qBACiBC,sBACf,GAAA,IAAIJ,OAAU,EAAA;AAChB,qBACiBK,wBAA6C,GAAA,IAAIH,GAAM,EAAA;AACxE;;;MAIA,WAAA,CAAYI,MAAsB,EAAEC,EAAmB,EAAEC,gBAAmB,GAAA,IAAA,GAAO,IAAO,GAAA,IAAI,CAAE;QAC9F,IAAI,CAACC,OAAO,GAAGH,MAAAA;QACf,IAAI,CAACI,GAAG,GAAGH,EAAAA;QACX,IAAI,CAACI,QAAQ,GAAG,CAAA;Q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AAAA,CAAQS,OAAO,EAAA;iBACV,MAAA;AACL,oBAAA,MAAMR,OAAO,IAAI,CAAC7B,aAAa,CAACoE,IAAAA,CAAKzC,IAAI,CAAC;AAC1C,oBAAA,IAAIE,IAAM,EAAA;AACRA,wBAAAA,IAAAA,CAAKgD,IAAI,CAACjD,OAAAA,CAAAA;qBACL,MAAA;AACL,wBAAA,IAAI,CAAC5B,aAAa,CAACoE,IAAKzC,CAAAA,IAAI,CAAC,GAAG;AAACC,4BAAAA;AAAQ,yBAAA;AAC3C;AACF;AACF,aAAA,MAAO,IAAIP,KAAO,EAAA;AAChB+C,gBAAAA,IAAAA,CAAK/B,OAAO,GAAG,IAAA;AACjB;AACF;AACF;AACF;;;;"}
1
+ {"version":3,"file":"pool.js","sources":["../src/pool.ts"],"sourcesContent":["import type { Nullable, MaybeArray } from '@zephyr3d/base';\r\nimport type { AbstractDevice, TextureFormat } from './base_types';\r\nimport type { BaseTexture, FrameBuffer, Texture2D, Texture2DArray, TextureCube } from './gpuobject';\r\n\r\n/**\r\n * ObjectPool class is responsible for managing and reusing textures and framebuffers.\r\n * @public\r\n */\r\nexport class Pool {\r\n /** @internal */\r\n private _memCost: number;\r\n /** @internal */\r\n private readonly _memCostThreshold: number;\r\n /** @internal */\r\n private readonly _device: AbstractDevice;\r\n /** @internal */\r\n private readonly _id: string | symbol;\r\n /** @internal */\r\n private _freeTextures: Record<string, BaseTexture[]> = {};\r\n /** @internal */\r\n private readonly _allocatedTextures: WeakMap<\r\n BaseTexture,\r\n { hash: string; refcount: number; dispose: boolean }\r\n > = new WeakMap();\r\n /** @internal */\r\n private readonly _autoReleaseTextures: Set<BaseTexture> = new Set();\r\n /** @internal */\r\n private _freeFramebuffers: Record<string, FrameBuffer[]> = {};\r\n /** @internal */\r\n private readonly _allocatedFramebuffers: WeakMap<FrameBuffer, { hash: string; refcount: number }> =\r\n new WeakMap();\r\n /** @internal */\r\n private readonly _autoReleaseFramebuffers: Set<FrameBuffer> = new Set();\r\n /**\r\n * Creates an instance of Pool class\r\n * @param device - Rendering device\r\n */\r\n constructor(device: AbstractDevice, id: string | symbol, memCostThreshold = 1024 * 1024 * 1024) {\r\n this._device = device;\r\n this._id = id;\r\n this._memCost = 0;\r\n this._memCostThreshold = memCostThreshold;\r\n this._freeTextures = {};\r\n this._allocatedTextures = new WeakMap();\r\n this._autoReleaseTextures = new Set();\r\n this._freeFramebuffers = {};\r\n this._allocatedFramebuffers = new WeakMap();\r\n this._autoReleaseFramebuffers = new Set();\r\n this._memCost = 0;\r\n }\r\n /**\r\n * Id for this pool\r\n */\r\n get id() {\r\n return this._id;\r\n }\r\n autoRelease() {\r\n // auto release objects\r\n for (const tex of this._autoReleaseTextures) {\r\n this.releaseTexture(tex);\r\n }\r\n this._autoReleaseTextures.clear();\r\n for (const fb of this._autoReleaseFramebuffers) {\r\n this.releaseFrameBuffer(fb);\r\n }\r\n this._autoReleaseFramebuffers.clear();\r\n // Free up video memory if memory usage is greater than specific value\r\n if (this._memCost >= this._memCostThreshold) {\r\n this.purge();\r\n }\r\n }\r\n /**\r\n * Fetch a temporal 2D texture from the object pool.\r\n * @param autoRelease - Whether the texture should be automatically released at the next frame.\r\n * @param format - The format of the texture.\r\n * @param width - The width of the texture.\r\n * @param height - The height of the texture.\r\n * @param mipmapping - Whether this texture support mipmapping\r\n * @returns The fetched Texture2D object.\r\n */\r\n fetchTemporalTexture2D(\r\n autoRelease: boolean,\r\n format: TextureFormat,\r\n width: number,\r\n height: number,\r\n mipmapping = false\r\n ) {\r\n const hash = `2d:${format}:${width}:${height}:${mipmapping ? 1 : 0}`;\r\n let texture: Nullable<BaseTexture> = null;\r\n const list = this._freeTextures[hash];\r\n if (!list) {\r\n texture = this._device.createTexture2D(format, width, height, { mipmapping });\r\n if (!texture) {\r\n throw new Error(`Create 2D texture failed: ${format}-${width}x${height}`);\r\n }\r\n this._memCost += texture.memCost;\r\n } else {\r\n texture = list.pop()!;\r\n if (list.length === 0) {\r\n delete this._freeTextures[hash];\r\n }\r\n }\r\n this._allocatedTextures.set(texture, { hash, refcount: 1, dispose: false });\r\n if (autoRelease) {\r\n this._autoReleaseTextures.add(texture);\r\n }\r\n return texture as Texture2D;\r\n }\r\n /**\r\n * Fetch a temporal 2D array texture from the object pool.\r\n * @param autoRelease - Whether the texture should be automatically released at the next frame.\r\n * @param format - Format of the texture.\r\n * @param width - Width of the texture.\r\n * @param height - Height of the texture.\r\n * @param numLayers - Layer count of the texture\r\n * @param mipmapping - Whether this texture support mipmapping\r\n * @returns The fetched Texture2DArray object.\r\n */\r\n fetchTemporalTexture2DArray(\r\n autoRelease: boolean,\r\n format: TextureFormat,\r\n width: number,\r\n height: number,\r\n numLayers: number,\r\n mipmapping = false\r\n ) {\r\n const hash = `2darray:${format}:${width}:${height}:${numLayers}:${mipmapping ? 1 : 0}`;\r\n let texture: Nullable<BaseTexture> = null;\r\n const list = this._freeTextures[hash];\r\n if (!list) {\r\n texture = this._device.createTexture2DArray(format, width, height, numLayers, { mipmapping });\r\n if (!texture) {\r\n throw new Error(`Create 2DArray texture failed: ${format}-${width}x${height}x${numLayers}`);\r\n }\r\n this._memCost += texture.memCost;\r\n } else {\r\n texture = list.pop()!;\r\n if (list.length === 0) {\r\n delete this._freeTextures[hash];\r\n }\r\n }\r\n this._allocatedTextures.set(texture, { hash, refcount: 1, dispose: false });\r\n if (autoRelease) {\r\n this._autoReleaseTextures.add(texture);\r\n }\r\n return texture as Texture2DArray;\r\n }\r\n /**\r\n * Fetch a temporal Cube texture from the object pool.\r\n * @param autoRelease - Whether the texture should be automatically released at the next frame.\r\n * @param format - Format of the texture.\r\n * @param size - size of the texture.\r\n * @param mipmapping - Whether this texture support mipmapping\r\n * @returns The fetched TextureCube object.\r\n */\r\n fetchTemporalTextureCube(autoRelease: boolean, format: TextureFormat, size: number, mipmapping = false) {\r\n const hash = `cube:${format}:${size}:${mipmapping ? 1 : 0}`;\r\n let texture: Nullable<BaseTexture> = null;\r\n const list = this._freeTextures[hash];\r\n if (!list) {\r\n texture = this._device.createCubeTexture(format, size, { mipmapping });\r\n if (!texture) {\r\n throw new Error(`Create Cube texture failed: ${format}-${size}`);\r\n }\r\n this._memCost += texture.memCost;\r\n } else {\r\n texture = list.pop()!;\r\n if (list.length === 0) {\r\n delete this._freeTextures[hash];\r\n }\r\n }\r\n this._allocatedTextures.set(texture, { hash, refcount: 1, dispose: false });\r\n if (autoRelease) {\r\n this._autoReleaseTextures.add(texture);\r\n }\r\n return texture as TextureCube;\r\n }\r\n /**\r\n * Creates a temporal framebuffer from the object pool.\r\n * @param autoRelease - Whether the framebuffer should be automatically released at the next frame.\r\n * @param width - Width of the framebuffer\r\n * @param height - Height of the framebuffer\r\n * @param colorAttachments - Array of color attachments or texture format of the framebuffer.\r\n * @param depthAttachment - Depth attachment or texture format of the framebuffer.\r\n * @param mipmapping - Whether mipmapping should be enabled when creating color attachment textures, default is false.\r\n * @param sampleCount - The sample count for the framebuffer, default is 1.\r\n * @param ignoreDepthStencil - Whether to ignore depth stencil when resolving msaa framebuffer, default is true.\r\n * @param attachmentMipLevel - The mipmap level to which the color attachment will render, default is 0\r\n * @param attachmentCubeface - The cubemap face to which the color attachment will render, default is 0\r\n * @param attachmentLayer - The texture layer to which the color attachment will render, default is 0\r\n * @returns The fetched FrameBuffer object.\r\n */\r\n fetchTemporalFramebuffer<T extends BaseTexture<unknown>>(\r\n autoRelease: boolean,\r\n width: number,\r\n height: number,\r\n colorTexOrFormat: MaybeArray<TextureFormat | T>,\r\n depthTexOrFormat: Nullable<TextureFormat | T> = null,\r\n mipmapping = false,\r\n sampleCount = 1,\r\n ignoreDepthStencil = true,\r\n attachmentMipLevel = 0,\r\n attachmentCubeface = 0,\r\n attachmentLayer = 0\r\n ) {\r\n const colors = Array.isArray(colorTexOrFormat)\r\n ? colorTexOrFormat\r\n : colorTexOrFormat\r\n ? [colorTexOrFormat]\r\n : [];\r\n const colorAttachments = colors.map((val) => {\r\n return typeof val === 'string'\r\n ? this.fetchTemporalTexture2D(false, val, width, height, mipmapping)\r\n : val;\r\n });\r\n const depthAttachment =\r\n typeof depthTexOrFormat === 'string'\r\n ? this.fetchTemporalTexture2D(false, depthTexOrFormat, width, height, false)\r\n : depthTexOrFormat;\r\n const fb = this.createTemporalFramebuffer(\r\n autoRelease,\r\n colorAttachments,\r\n depthAttachment,\r\n sampleCount,\r\n ignoreDepthStencil,\r\n attachmentMipLevel,\r\n attachmentCubeface,\r\n attachmentLayer\r\n );\r\n for (let i = 0; i < colors.length; i++) {\r\n if (typeof colors[i] === 'string') {\r\n this.releaseTexture(colorAttachments[i]);\r\n }\r\n }\r\n if (!!depthAttachment && typeof depthTexOrFormat === 'string') {\r\n this.releaseTexture(depthAttachment);\r\n }\r\n return fb;\r\n }\r\n /**\r\n * Creates a temporal framebuffer from the object pool.\r\n * @param autoRelease - Whether the framebuffer should be automatically released at the next frame.\r\n * @param colorAttachments - Array of color attachments for the framebuffer.\r\n * @param depthAttachment - Depth attachment for the framebuffer.\r\n * @param sampleCount - The sample count for the framebuffer, default is 1.\r\n * @param ignoreDepthStencil - Whether to ignore depth stencil when resolving msaa framebuffer, default is true.\r\n * @param attachmentMipLevel - The mipmap level to which the color attachment will render, default is 0.\r\n * @param attachmentCubeface - The cubemap face to which the color attachment will render, default is 0.\r\n * @param attachmentLayer - The texture layer to which the color attachment will render, default is 0.\r\n * @returns The fetched FrameBuffer object.\r\n */\r\n createTemporalFramebuffer(\r\n autoRelease: boolean,\r\n colorAttachments: BaseTexture[],\r\n depthAttachment: Nullable<BaseTexture> = null,\r\n sampleCount = 1,\r\n ignoreDepthStencil = true,\r\n attachmentMipLevel = 0,\r\n attachmentCubeface = 0,\r\n attachmentLayer = 0\r\n ) {\r\n colorAttachments = colorAttachments ?? [];\r\n let hash = `${depthAttachment?.uid ?? 0}:${sampleCount ?? 1}:${ignoreDepthStencil ? 1 : 0}`;\r\n if (colorAttachments.length > 0) {\r\n hash += `:${attachmentMipLevel}:${attachmentCubeface}:${attachmentLayer}`;\r\n for (const tex of colorAttachments) {\r\n hash += `:${tex.uid}`;\r\n }\r\n }\r\n let fb: Nullable<FrameBuffer> = null;\r\n const list = this._freeFramebuffers[hash];\r\n if (!list) {\r\n fb = this._device.createFrameBuffer(colorAttachments, depthAttachment, {\r\n ignoreDepthStencil,\r\n sampleCount\r\n });\r\n for (let i = 0; i < fb.getColorAttachments().length; i++) {\r\n fb.setColorAttachmentMipLevel(i, attachmentMipLevel);\r\n fb.setColorAttachmentCubeFace(i, attachmentCubeface);\r\n fb.setColorAttachmentLayer(i, attachmentLayer);\r\n }\r\n } else {\r\n fb = list.pop()!;\r\n if (list.length === 0) {\r\n delete this._freeFramebuffers[hash];\r\n }\r\n }\r\n // Mark referenced textures\r\n const info = depthAttachment ? this._allocatedTextures.get(depthAttachment) : null;\r\n if (info) {\r\n info.refcount++;\r\n }\r\n for (const tex of colorAttachments) {\r\n const info = this._allocatedTextures.get(tex);\r\n if (info) {\r\n info.refcount++;\r\n }\r\n }\r\n this._allocatedFramebuffers.set(fb, { hash, refcount: 1 });\r\n if (autoRelease) {\r\n this._autoReleaseFramebuffers.add(fb);\r\n }\r\n return fb;\r\n }\r\n /**\r\n * Dispose a texture that is allocated from the object pool.\r\n * @param texture - The texture to dispose.\r\n */\r\n disposeTexture(texture: BaseTexture) {\r\n this.safeReleaseTexture(texture, true);\r\n }\r\n /**\r\n * Release a texture back to the object pool.\r\n * @param texture - The texture to release.\r\n */\r\n releaseTexture(texture: BaseTexture) {\r\n const info = this._allocatedTextures.get(texture);\r\n if (!info) {\r\n console.error(\r\n `ObjectPool.releaseTexture(): texture is not allocated from pool: ${this._device.getGPUObjects().stacks.get(texture) ?? '<No stack>'}`\r\n );\r\n } else {\r\n this.safeReleaseTexture(texture);\r\n }\r\n }\r\n /**\r\n * Increment reference counter for given texture\r\n * @param texture - The texture to retain\r\n */\r\n retainTexture(texture: BaseTexture) {\r\n const info = this._allocatedTextures.get(texture);\r\n if (!info) {\r\n console.error(\r\n `ObjectPool.retainTexture(): texture is not allocated from pool: ${this._device.getGPUObjects().stacks.get(texture) ?? '<No stack>'}`\r\n );\r\n } else {\r\n info.refcount++;\r\n }\r\n }\r\n /**\r\n * Dispose a framebuffer that is allocated from the object pool.\r\n * @param fb - The framebuffer to dispose.\r\n */\r\n disposeFrameBuffer(fb: FrameBuffer) {\r\n const hash = this._allocatedFramebuffers.get(fb);\r\n if (!hash) {\r\n console.error(`ObjectPool.disposeFrameBuffer(): framebuffer is not allocated from pool`);\r\n } else {\r\n this.internalDisposeFrameBuffer(fb);\r\n fb.dispose();\r\n }\r\n }\r\n /**\r\n * Release a framebuffer back to the object pool.\r\n * @param fb - The framebuffer to release.\r\n */\r\n releaseFrameBuffer(fb: FrameBuffer) {\r\n const info = this._allocatedFramebuffers.get(fb);\r\n if (!info) {\r\n console.error(`ObjectPool.releaseFrameBuffer(): framebuffer is not allocated from pool`);\r\n } else {\r\n info.refcount--;\r\n if (info.refcount <= 0) {\r\n this.internalDisposeFrameBuffer(fb);\r\n const list = this._freeFramebuffers[info.hash];\r\n if (list) {\r\n list.push(fb);\r\n } else {\r\n this._freeFramebuffers[info.hash] = [fb];\r\n }\r\n }\r\n }\r\n }\r\n /**\r\n * Increment reference counter for given framebuffer\r\n * @param fb - The framebuffer to retain\r\n */\r\n retainFrameBuffer(fb: FrameBuffer) {\r\n const info = this._allocatedFramebuffers.get(fb);\r\n if (!info) {\r\n console.error(`ObjectPool.retainFrameBuffer(): framebuffer is not allocated from pool`);\r\n } else {\r\n info.refcount++;\r\n }\r\n }\r\n /**\r\n * Purge the object pool by disposing all free framebuffers and textures.\r\n */\r\n purge() {\r\n for (const k in this._freeFramebuffers) {\r\n const list = this._freeFramebuffers[k];\r\n if (list) {\r\n for (const fb of this._freeFramebuffers[k]) {\r\n this.internalDisposeFrameBuffer(fb);\r\n fb.dispose();\r\n }\r\n }\r\n }\r\n this._freeFramebuffers = {};\r\n for (const k in this._freeTextures) {\r\n const list = this._freeTextures[k];\r\n for (const tex of list) {\r\n this._memCost -= tex.memCost;\r\n tex.dispose();\r\n }\r\n }\r\n this._freeTextures = {};\r\n }\r\n /** @internal */\r\n private internalDisposeFrameBuffer(fb: FrameBuffer) {\r\n if (fb) {\r\n // Release attachment textures\r\n const colorAttachments = fb.getColorAttachments();\r\n if (colorAttachments) {\r\n for (const tex of colorAttachments) {\r\n this.safeReleaseTexture(tex);\r\n }\r\n }\r\n const depthAttachment = fb.getDepthAttachment();\r\n if (depthAttachment) {\r\n this.safeReleaseTexture(depthAttachment);\r\n }\r\n this._allocatedFramebuffers.delete(fb);\r\n this._autoReleaseFramebuffers.delete(fb);\r\n }\r\n }\r\n /** @internal */\r\n private safeReleaseTexture(texture: BaseTexture, purge = false) {\r\n const info = this._allocatedTextures.get(texture);\r\n if (info) {\r\n info.refcount--;\r\n if (info.refcount <= 0) {\r\n this._allocatedTextures.delete(texture);\r\n this._autoReleaseTextures.delete(texture);\r\n if (purge || info.dispose) {\r\n this._memCost -= texture.memCost;\r\n texture.dispose();\r\n } else {\r\n const list = this._freeTextures[info.hash];\r\n if (list) {\r\n list.push(texture);\r\n } else {\r\n this._freeTextures[info.hash] = [texture];\r\n }\r\n }\r\n } else if (purge) {\r\n info.dispose = true;\r\n }\r\n }\r\n }\r\n}\r\n"],"names":["Pool","_freeTextures","_allocatedTextures","WeakMap","_autoReleaseTextures","Set","_freeFramebuffers","_allocatedFramebuffers","_autoReleaseFramebuffers","device","id","memCostThreshold","_device","_id","_memCost","_memCostThreshold","autoRelease","tex","releaseTexture","clear","fb","releaseFrameBuffer","purge","fetchTemporalTexture2D","format","width","height","mipmapping","hash","texture","list","createTexture2D","Error","memCost","pop","length","set","refcount","dispose","add","fetchTemporalTexture2DArray","numLayers","createTexture2DArray","fetchTemporalTextureCube","size","createCubeTexture","fetchTemporalFramebuffer","colorTexOrFormat","depthTexOrFormat","sampleCount","ignoreDepthStencil","attachmentMipLevel","attachmentCubeface","attachmentLayer","colors","Array","isArray","colorAttachments","map","val","depthAttachment","createTemporalFramebuffer","i","uid","createFrameBuffer","getColorAttachments","setColorAttachmentMipLevel","setColorAttachmentCubeFace","setColorAttachmentLayer","info","get","disposeTexture","safeReleaseTexture","console","error","getGPUObjects","stacks","retainTexture","disposeFrameBuffer","internalDisposeFrameBuffer","push","retainFrameBuffer","k","getDepthAttachment","delete"],"mappings":"AAIA;;;AAGC,IACM,MAAMA,IAAAA,CAAAA;qBAEX,QAAyB;qBAEzB,iBAA2C;qBAE3C,OAAyC;qBAEzC,GAAsC;AACtC,qBACQC,aAA+C,GAAA,EAAG;AAC1D,qBACiBC,kBAGb,GAAA,IAAIC,OAAU,EAAA;AAClB,qBACiBC,oBAAyC,GAAA,IAAIC,GAAM,EAAA;AACpE,qBACQC,iBAAmD,GAAA,EAAG;AAC9D,qBACiBC,sBACf,GAAA,IAAIJ,OAAU,EAAA;AAChB,qBACiBK,wBAA6C,GAAA,IAAIH,GAAM,EAAA;AACxE;;;MAIA,WAAA,CAAYI,MAAsB,EAAEC,EAAmB,EAAEC,gBAAmB,GAAA,IAAA,GAAO,IAAO,GAAA,IAAI,CAAE;QAC9F,IAAI,CAACC,OAAO,GAAGH,MAAAA;QACf,IAAI,CAACI,GAAG,GAAGH,EAAAA;QACX,IAAI,CAACI,QAAQ,GAAG,CAAA;QAChB,IAAI,CAACC,iBAAiB,GAAGJ,gBAAAA;QACzB,IAAI,CAACV,aAAa,GAAG,EAAC;QACtB,IAAI,CAACC,kBAAkB,GAAG,IAAIC,OAAAA,EAAAA;QAC9B,IAAI,CAACC,oBAAoB,GAAG,IAAIC,GAAAA,EAAAA;QAChC,IAAI,CAACC,iBAAiB,GAAG,EAAC;QAC1B,IAAI,CAACC,sBAAsB,GAAG,IAAIJ,OAAAA,EAAAA;QAClC,IAAI,CAACK,wBAAwB,GAAG,IAAIH,GAAAA,EAAAA;QACpC,IAAI,CAACS,QAAQ,GAAG,CAAA;AAClB;AACA;;AAEC,MACD,IAAIJ,EAAK,GAAA;QACP,OAAO,IAAI,CAACG,GAAG;A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zC,CAAAA,IAAI,CAAC,GAAG;AAACC,4BAAAA;AAAQ,yBAAA;AAC3C;AACF;AACF,aAAA,MAAO,IAAIP,KAAO,EAAA;AAChB+C,gBAAAA,IAAAA,CAAK/B,OAAO,GAAG,IAAA;AACjB;AACF;AACF;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zephyr3d/device",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "Device API for zephyr3d",
5
5
  "homepage": "https://github.com/gavinyork/zephyr3d#readme",
6
6
  "type": "module",
@@ -68,7 +68,7 @@
68
68
  "@rollup/plugin-commonjs": "~28.0.2",
69
69
  "@types/node": "^22.12.0",
70
70
  "@webgpu/types": "^0.1.65",
71
- "@zephyr3d/base": "^0.2.1",
71
+ "@zephyr3d/base": "^0.2.5",
72
72
  "rollup-plugin-import-css": "~3.5.8"
73
73
  },
74
74
  "scripts": {