rhodonite
    Preparing search index...

    Class WebGpuResourceRepository

    WebGPU Resource Repository that manages WebGPU resources and provides rendering functionality. This class serves as a central hub for creating, managing, and utilizing WebGPU resources such as textures, buffers, pipelines, and render passes.

    ICGAPIResourceRepository

    Hierarchy (View Summary)

    Implements

    Index
    _getGpuTimer _getVertexBufferRange addWebGpuDeviceWrapper allocateTexture attachColorBufferCubeToFrameBufferObject attachColorBufferLayerToFrameBufferObject attachColorBufferToFrameBufferObject attachDepthBufferToFrameBufferObject attachDepthStencilBufferToFrameBufferObject attachStencilBufferToFrameBufferObject clearCache clearFrameBuffer copyTextureData createBindGroupLayoutForDrawParameters createCompressedTexture createCompressedTextureFromBasis createCubeTexture createCubeTextureFromFiles createCubeTextureViewAsRenderTarget createFrameBufferObject createIndexBuffer createRenderBuffer createRenderBundleEncoder createRenderTargetTexture createRenderTargetTextureArray createRenderTargetTextureCube createShaderProgram createStorageBlendShapeBuffer createStorageBuffer createTextureArray createTextureFromDataUri createTextureFromHTMLImageElement createTextureFromImageBitmapData createTextureSampler createTextureView2d createTextureView2dArray createTextureView2dArrayAsRenderTarget createTextureViewAsRenderTarget createTextureViewCube createUniformMorphOffsetsBuffer createUniformMorphWeightsBuffer createVertexBuffer createVertexBufferAndIndexBuffer createVertexBufferFromTypedArray deleteFrameBufferObject deleteRenderBuffer deleteStorageBlendShapeBuffer deleteTexture deleteUniformBuffer deleteVertexBuffer deleteVertexDataResources destroyStorageBuffer draw duplicateTextureAsMipmapped endRenderPassEncoderForExternalRendering finishRenderBundleEncoder finishRenderBundleEncoderAndKeepRenderPass flush generateMipmaps generateMipmaps2d generateMipmapsCube getCanvasSize getCubeTexturePixelData getEffekseerRenderPassOptions getOrCreateRenderPassEncoderForEffekseerExternalRendering getOrCreateRenderPassEncoderForExternalRendering getOrCreateRenderPipeline getPixelDataFromTexture getPixelDataFromTextureAsync getTexturePixelData getWebGpuDeviceWrapper isMippmappedTexture isSupportMultiViewVRRendering loadImageToMipLevelOfTexture2D recreateSystemDepthTexture renderWithRenderBundle renderWithRenderBundleAndKeepRenderPass resizeCanvas setColorWriteMask setDrawParameters setVertexDataToPipeline setViewport updateIndexBuffer updateStorageBlendShapeBuffer updateStorageBuffer updateStorageBufferPartially updateUniformMorphOffsetsBuffer updateUniformMorphWeightsBuffer updateVertexBuffer updateVertexBufferAndIndexBuffer getCgApiResourceRepository getWebGLResourceRepository getWebGpuResourceRepository init
    InvalidCGAPIResourceUid: -1

    Invalid resource handle constant used to indicate failed resource creation or invalid resources

    • Internal

      Returns the GPU timer, creating it on first use. Use Engine.gpuTimerEnabled and Engine.gpuTimeMilliseconds instead.

      Returns WebGpuGpuTimer

    • Internal

      Returns the buffer range of a vertex or index buffer handle.

      Parameters

      • resourceHandle: number

      Returns WebGpuBufferRange | undefined

    • Adds a WebGPU device wrapper to the repository and initializes the command encoder. This must be called before using any WebGPU functionality.

      Parameters

      • webGpuDeviceWrapper: WebGpuDeviceWrapper

        The WebGPU device wrapper containing the device and context

      Returns void

    • allocate a Texture

      Parameters

      • format: {
            format: TextureFormatEnum;
            height: number;
            mipLevelCount: number;
            width: number;
        }

        the format of the texture

      Returns number

      the handle of the texture

    • Clears all cached resources including render pipelines, bind groups, and render bundles. This method should be called when resources need to be recreated or when the rendering context changes.

      Returns void

    • Clears the framebuffer with the specified clear values. This method is executed when the render pass has no entities to render, but still needs to perform clear operations.

      Parameters

      • engine: Engine
      • renderPass: RenderPass

        The render pass containing clear settings and target framebuffer

      • displayIdx: number

      Returns void

    • copy Texture Data

      Parameters

      • fromTexture: number
      • toTexture: number

      Returns void

    • Returns void

    • Create Cube Texture from image files.

      Parameters

      • engine: Engine
      • baseUri: string

        the base uri to load images;

      • mipLevelCount: number

        the number of mip levels (include root level). if no mipmap, the value should be 1;

      • isNamePosNeg: boolean
      • hdriFormat: EnumIO

      Returns Promise<[number, Sampler, number, number]>

      the WebGLResourceHandle for the generated Cube Texture

    • Parameters

      • textureHandle: number
      • faceIdx: number
      • mipLevel: number

      Returns number

    • Creates a WebGPU index buffer from an accessor containing index data. Automatically converts UnsignedByte indices to UnsignedShort since WebGPU doesn't support 8-bit index buffers.

      Parameters

      • accessor: Accessor

        Accessor containing the index data to upload

      Returns number

      Handle to the created index buffer resource

    • Creates a render buffer for multisampling (MSAA) or as a render attachment. Render buffers are textures that are only used for rendering and cannot be sampled in shaders.

      Parameters

      • width: number

        Width of the render buffer in pixels

      • height: number

        Height of the render buffer in pixels

      • internalFormat: TextureParameterEnum

        Internal format of the render buffer

      • isMSAA: boolean

        Whether to enable multisampling

      • sampleCountMSAA: number

        Number of samples for MSAA (ignored if isMSAA is false)

      Returns number

      Handle to the created render buffer resource

    • Parameters

      Returns void

    • Creates a render target texture that can be used as a color attachment in framebuffers. This texture can be rendered to and also used as a texture input in shaders.

      Parameters

      • params: {
            format: TextureParameterEnum;
            height: number;
            mipLevelCount: number;
            width: number;
        }

        Configuration for the render target texture

        • format: TextureParameterEnum

          Texture format for the render target

        • height: number

          Height of the texture in pixels

        • mipLevelCount: number

          Number of mipmap levels to create

        • width: number

          Width of the texture in pixels

      Returns number

      Handle to the created render target texture resource

    • Creates a render target texture array that can hold multiple 2D textures. Useful for techniques like shadow mapping with multiple lights or layered rendering.

      Parameters

      • params: {
            arrayLength: number;
            height: number;
            internalFormat: TextureParameterEnum;
            width: number;
        }

        Configuration for the render target texture array

        • arrayLength: number

          Number of texture layers in the array

        • height: number

          Height of each texture layer in pixels

        • internalFormat: TextureParameterEnum

          Internal format of the texture

        • width: number

          Width of each texture layer in pixels

      Returns number

      Handle to the created render target texture array resource

    • Creates a render target cube texture for environment mapping or omnidirectional shadow mapping. This creates a cube texture with 6 faces that can be rendered to.

      Parameters

      • params: {
            format: TextureParameterEnum;
            height: number;
            mipLevelCount: number;
            width: number;
        }

        Configuration for the render target cube texture

        • format: TextureParameterEnum

          Texture format for the render target

        • height: number

          Height of each cube face in pixels

        • mipLevelCount: number

          Number of mipmap levels to create

        • width: number

          Width of each cube face in pixels

      Returns number

      Handle to the created render target cube texture resource

    • Creates shader modules (vertex and fragment) from shader source code. This method compiles both vertex and fragment shaders and returns their handles.

      Parameters

      • params: {
            config: Config;
            engine: Engine;
            fragmentShaderStr: string;
            material: Material;
            vertexShaderStr: string;
        }

        Configuration object for shader creation

        • config: Config
        • engine: Engine

          The engine instance for logging

        • fragmentShaderStr: string

          WGSL fragment shader source code

        • material: Material

          The material that will use these shaders

        • vertexShaderStr: string

          WGSL vertex shader source code

      Returns number

      Handle to the shader program containing both modules

    • Parameters

      • inputArray: Float32Array

      Returns number

    • Creates a storage buffer from a Float32Array and registers it as a WebGPU resource. Storage buffers are used for storing large amounts of data accessible from shaders.

      Parameters

      • gpuInstanceDataBuffers: Buffer[]

        The buffers containing the data to store

      Returns number

      Handle to the created storage buffer resource

    • Creates a WebGPU texture from a data URI string. This method loads the image from the data URI and creates a texture from it.

      Parameters

      • dataUri: string

        The data URI string containing the image data

      • params: { generateMipmap: boolean; internalFormat: TextureParameterEnum }

        Configuration object containing texture parameters

        • generateMipmap: boolean

          Whether to generate mipmaps automatically

        • internalFormat: TextureParameterEnum

          Internal format of the texture

      Returns Promise<number>

      Promise that resolves to the texture resource handle

    • create a Texture

      Parameters

      • imageData: HTMLImageElement
      • param1: {
            generateMipmap: boolean;
            height: number;
            internalFormat: TextureParameterEnum;
            width: number;
        }

      Returns Promise<number>

    • Creates a WebGPU texture from ImageBitmap data with specified parameters. This method handles texture creation, data upload, and optional mipmap generation.

      Parameters

      • imageData: ImageBitmapData

        The ImageBitmap data to create the texture from

      • params: {
            generateMipmap: boolean;
            height: number;
            internalFormat: TextureParameterEnum;
            width: number;
        }

        Configuration object containing texture parameters

        • generateMipmap: boolean

          Whether to generate mipmaps automatically

        • height: number

          Height of the texture in pixels

        • internalFormat: TextureParameterEnum

          Internal format of the texture

        • width: number

          Width of the texture in pixels

      Returns Promise<number>

      Promise that resolves to the texture resource handle

    • Creates a 2D texture view from a texture resource. This view can be used for sampling the texture in shaders.

      Parameters

      • textureHandle: number

        Handle to the source texture

      Returns number

      Handle to the created texture view

    • Parameters

      • textureHandle: number
      • arrayLayerCount: number

      Returns number

    • Parameters

      • textureHandle: number
      • arrayIdx: number
      • mipLevel: number

      Returns number

    • Creates a texture view suitable for use as a render target. This view targets only the base mip level and first array layer.

      Parameters

      • textureHandle: number

        Handle to the source texture

      Returns number

      Handle to the created render target texture view

    • Creates a cube texture view from a cube texture resource. This view exposes all 6 faces of the cube texture for sampling.

      Parameters

      • textureHandle: number

        Handle to the source cube texture

      Returns number

      Handle to the created cube texture view

    • Parameters

      • sizeInByte: number

      Returns number

    • Parameters

      • sizeInByte: number

      Returns number

    • Creates a WebGPU vertex buffer from an accessor containing vertex data. The buffer is created with the appropriate size and the data is uploaded immediately.

      Parameters

      • accessor: Accessor

        Accessor containing the vertex data to upload

      Returns number

      Handle to the created vertex buffer

    • Creates vertex and index buffers for a primitive and returns their handles. This method processes all vertex attributes and creates appropriate buffers while tracking which attributes are present.

      Parameters

      • primitive: Primitive

        The primitive containing vertex and index data

      Returns VertexHandles

      Object containing buffer handles and attribute flags

    • Creates a WebGPU vertex buffer from a typed array. This is a more direct method when you have raw typed array data.

      Parameters

      • typedArray: TypedArray

        The typed array containing vertex data

      Returns number

      Handle to the created vertex buffer resource

    • delete a FrameBufferObject

      Parameters

      • _frameBufferObjectHandle: number

      Returns void

    • delete a RenderBuffer

      Parameters

      • renderBufferUid: number

      Returns void

    • Parameters

      • storageBufferHandle: number

      Returns void

    • Deletes a texture resource and frees associated GPU memory.

      Parameters

      • textureHandle: number

        Handle to the texture to delete

      Returns void

    • Parameters

      • uniformBufferHandle: number

      Returns void

    • Deletes a vertex buffer and releases its range of the vertex buffer arena.

      Parameters

      • resourceHandle: number

        Handle to the vertex buffer to delete

      Returns void

      Error if the vertex buffer is not found

    • Deletes all vertex data resources (vertex and index buffers) associated with vertex handles. This method destroys both vertex buffers and index buffers to free GPU memory.

      Parameters

      • vertexHandles: VertexHandles

        Object containing handles to the vertex data resources to delete

      Returns void

    • Parameters

      • storageBufferHandle: number

      Returns void

    • Executes a draw call for rendering a primitive with the specified material and render pass. This is the core rendering method that sets up the render pipeline, bind groups, and executes the actual GPU draw commands.

      Parameters

      • engine: Engine
      • primitive: Primitive

        The geometric primitive to render (vertices, indices, attributes)

      • material: Material

        The material containing shaders and rendering properties

      • renderPass: RenderPass

        The render pass defining render targets and clear operations

      • cameraId: number

        Identifier for the camera used for rendering

      • zWrite: boolean

        Whether to enable depth writing during rendering

      • _displayIdx: number

      Returns void

    • Parameters

      • fromTexture: number

      Returns [number, number]

    • Returns void

    • Parameters

      Returns void

    • Parameters

      Returns GPURenderPassEncoder | undefined

    • Submits all recorded commands to the GPU queue and resets the command encoder. This method must be called to execute any recorded rendering commands.

      Returns void

    • Generates mipmaps for a texture using render passes (including CubeMap support). This is an optimized method adapted from WebGPU best practices that uses a custom shader to generate each mipmap level from the previous one.

      Parameters

      • texture: GPUTexture

        The GPU texture to generate mipmaps for

      • textureDescriptor: GPUTextureDescriptor

        Descriptor containing texture format and dimensions

      Returns void

    • Generates mipmaps for a 2D texture using the specified dimensions. This method creates all mipmap levels from the base texture.

      Parameters

      • textureHandle: number

        Handle to the texture resource

      • width: number

        Width of the base texture level

      • height: number

        Height of the base texture level

      Returns void

    • Generates mipmaps for a cube texture using the specified dimensions. This method creates all mipmap levels for all 6 faces of the cube texture.

      Parameters

      • textureHandle: number

        Handle to the cube texture resource

      • width: number

        Width of the base texture level

      • height: number

        Height of the base texture level

      Returns void

    • Gets the current canvas size as a tuple of width and height.

      Returns [number, number]

      A tuple containing [width, height] of the canvas

    • Reads pixel data from a specific face of a cube texture. Uses a shader-based approach to sample the cubemap and render to a 2D texture, then copies the result to a buffer for CPU access.

      Parameters

      • textureHandle: number

        Handle to the cube texture

      • width: number

        Width of the face texture

      • height: number

        Height of the face texture

      • faceIndex: number

        Index of the cube face (0=+X, 1=-X, 2=+Y, 3=-Y, 4=+Z, 5=-Z)

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Promise resolving to the pixel data as a Uint8Array (RGBA format)

    • Parameters

      Returns { colorFormat?: GPUTextureFormat; depthFormat?: GPUTextureFormat }

    • Parameters

      Returns GPURenderPassEncoder | undefined

    • Parameters

      Returns GPURenderPassEncoder | undefined

    • Parameters

      • renderPipelineId: string
      • pipelineLayoutKey: string
      • pipelineLayout: GPUPipelineLayout
      • primitive: Primitive
      • material: Material
      • renderPass: RenderPass
      • zWrite: boolean

      Returns [GPURenderPipeline, boolean]

    • Reads pixel data directly from a 2D texture (synchronous version). Note: WebGPU does not support synchronous texture readback. This method throws an error - use getPixelDataFromTextureAsync instead.

      Parameters

      • _textureHandle: number
      • _x: number
      • _y: number
      • _width: number
      • _height: number

      Returns Uint8Array

    • Reads pixel data directly from a 2D texture asynchronously. This method uses a render-based approach to avoid requiring COPY_SRC usage on the source texture. It renders the texture to a temporary render target with COPY_SRC, then reads from that.

      Parameters

      • textureHandle: number

        Handle to the texture to read from

      • _x: number
      • _y: number
      • width: number

        Width of the region to read

      • height: number

        Height of the region to read

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Promise resolving to the pixel data as a Uint8Array in RGBA format

    • Reads pixel data from a texture and returns it as a Uint8Array. This method is useful for debugging or post-processing texture data.

      Parameters

      • textureHandle: number

        Handle to the texture resource

      • width: number

        Width of the texture region to read

      • height: number

        Height of the texture region to read

      • _frameBufferUid: number
      • _colorAttachmentIndex: number

      Returns Promise<Uint8Array<ArrayBufferLike>>

      Promise that resolves to the pixel data as Uint8Array

    • Returns the WebGPU device wrapper instance.

      Returns WebGpuDeviceWrapper

      The WebGPU device wrapper

      Error if the device wrapper has not been initialized

    • Parameters

      • textureHandle: number

      Returns boolean

    • Checks if the implementation supports multi-view VR rendering.

      Returns boolean

      Always false for WebGPU implementation (not yet supported)

    • Load an image to a specific mip level of a texture

      Parameters

      • mipLevel: {
            data: TypedArray;
            format: TextureFormatEnum;
            height: number;
            mipLevel: number;
            rowSizeByPixel: number;
            textureUid: number;
            type: ComponentTypeEnum;
            width: number;
            xOffset: number;
            yOffset: number;
        }

        the mip level to load the image to

      Returns Promise<void>

    • Recreates the system depth texture with the current canvas dimensions. This is called when the canvas is resized or initialized.

      Returns void

    • Parameters

      Returns boolean

    • Parameters

      Returns GPURenderPassEncoder | undefined

    • Resizes the canvas and recreates the system depth texture. This method should be called when the window or viewport size changes.

      Parameters

      • width: number

        New canvas width in pixels

      • height: number

        New canvas height in pixels

      Returns void

    • Parameters

      Returns number

    • Selects the draw parameters (group 3) for the next draw().

      The parameters are stored in an immutable uniform buffer shared by every draw with the same values, so consecutive draws of the same material and camera keep the same bind group.

      Parameters

      • materialSid: number

        The material SID

      • cameraSID: number

        The camera component SID

      • currentPrimitiveIdx: number

        The index of the primitive among the primitives with morph targets

      • morphTargetNumber: number

        The number of morph targets of the primitive

      Returns void

    • Configures vertex data layout for the rendering pipeline. This method sets up vertex buffer layouts including both per-vertex and per-instance data.

      Parameters

      • bufferHandles: { vboHandles: number[] }

        Object containing vertex array object, index buffer, and vertex buffer handles

        • vboHandles: number[]

          Array of vertex buffer handles

      • primitive: Primitive

        The primitive containing vertex attribute information

      Returns void

    • Sets the viewport for rendering (currently not implemented in WebGPU version).

      Parameters

      Returns void

    • Updates the data in an existing index buffer with new data from an accessor. Automatically handles conversion of UnsignedByte indices to UnsignedShort if needed.

      Parameters

      • accessor: Accessor

        Accessor containing the new index data

      • resourceHandle: number

        Handle to the existing index buffer to update

      Returns void

      Error if the index buffer is not found

    • Parameters

      • storageBufferHandle: number
      • inputArray: Float32Array
      • updateComponentSize: number

      Returns void

    • Updates an existing storage buffer with new data. Only updates the specified number of components to optimize data transfer.

      Parameters

      • storageBufferHandle: number

        Handle to the storage buffer to update

      • gpuInstanceDataBuffers: Buffer[]

        New data to write to the buffer

      Returns void

    • Updates a portion of a storage buffer with new data at a specific offset. This allows for efficient partial updates of large storage buffers.

      Parameters

      • storageBufferHandle: number

        Handle to the storage buffer to update

      • inputArray: Float32Array

        New data to write to the buffer

      • offsetOfStorageBufferInByte: number

        Byte offset in the storage buffer where to start writing

      • offsetOfInputArrayInElement: number

        Element offset in the input array where to start reading

      • updateComponentSize: number

        Number of components to update

      Returns void

    • Parameters

      • inputArray: Uint32Array
      • elementNum: number

      Returns void

    • Parameters

      • inputArray: Float32Array
      • elementNum: number

      Returns void

    • Updates the data in an existing vertex buffer with new data from an accessor. The data must not be larger than the data the buffer was created with.

      Parameters

      • accessor: Accessor

        Accessor containing the new vertex data

      • resourceHandle: number

        Handle to the existing vertex buffer to update

      Returns void

      Error if the vertex buffer is not found

    • Updates the vertex and index buffers for a primitive with new data. This method updates all existing buffers with fresh data from the primitive.

      Parameters

      • primitive: Primitive

        The primitive containing the updated vertex and index data

      • vertexHandles: VertexHandles

        Object containing the handles to the buffers to update

      Returns void

    • Returns the singleton instance of WebGpuResourceRepository. Creates a new instance if one doesn't exist.

      Returns WebGpuResourceRepository

      The singleton instance