@luma.gl/webgpu
Advanced tools
Comparing version 9.0.0-alpha.54 to 9.0.0-beta.1
@@ -46,3 +46,5 @@ import { Buffer, Sampler, Texture, log, cast } from '@luma.gl/core'; | ||
binding: index, | ||
resource: cast(binding).handle.createView() | ||
resource: cast(binding).handle.createView({ | ||
label: 'bind-group-auto-created' | ||
}) | ||
}; | ||
@@ -49,0 +51,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { decodeVertexFormat } from '@luma.gl/core'; | ||
import { log, decodeVertexFormat } from '@luma.gl/core'; | ||
function getWebGPUVertexFormat(format) { | ||
@@ -29,2 +29,5 @@ if (format.endsWith('-webgl')) { | ||
const attributeLayout = findAttributeLayout(shaderLayout, mapping.name, usedAttributes); | ||
if (!attributeLayout) { | ||
continue; | ||
} | ||
byteStride = decodeVertexFormat(mapping.format).byteLength; | ||
@@ -83,3 +86,4 @@ stepMode = attributeLayout.stepMode || 'vertex'; | ||
if (!attribute) { | ||
throw new Error(`Unknown attribute ${name}`); | ||
log.warn(`Unknown attribute ${name}`)(); | ||
return null; | ||
} | ||
@@ -86,0 +90,0 @@ if (attributeNames.has(name)) { |
@@ -12,5 +12,5 @@ import { RenderPass, cast, log } from '@luma.gl/core'; | ||
const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer); | ||
log.groupCollapsed(1, `new WebGPURenderPass(${this.id})`)(); | ||
log.probe(1, JSON.stringify(renderPassDescriptor, null, 2))(); | ||
log.groupEnd(1)(); | ||
log.groupCollapsed(3, `new WebGPURenderPass(${this.id})`)(); | ||
log.probe(3, JSON.stringify(renderPassDescriptor, null, 2))(); | ||
log.groupEnd(3)(); | ||
this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor); | ||
@@ -89,7 +89,7 @@ this.handle.label = this.props.id; | ||
storeOp: this.props.discard ? 'discard' : 'store', | ||
view: colorAttachment.handle.createView() | ||
view: colorAttachment.createView() | ||
})); | ||
if (framebuffer.depthStencilAttachment) { | ||
renderPassDescriptor.depthStencilAttachment = { | ||
view: framebuffer.depthStencilAttachment.handle.createView() | ||
view: framebuffer.depthStencilAttachment.createView() | ||
}; | ||
@@ -96,0 +96,0 @@ const { |
/// <reference types="dist" /> | ||
import type { TypedArray, Binding, UniformValue, RenderPass } from '@luma.gl/core'; | ||
import { Buffer, RenderPipeline, RenderPipelineProps } from '@luma.gl/core'; | ||
import type { Binding, UniformValue, RenderPass, VertexArray } from '@luma.gl/core'; | ||
import { RenderPipeline, RenderPipelineProps } from '@luma.gl/core'; | ||
import type { WebGPUDevice } from '../webgpu-device'; | ||
import type { WebGPUShader } from './webgpu-shader'; | ||
import type { WebGPURenderPass } from './webgpu-render-pass'; | ||
/** Creates a new render pipeline when parameters change */ | ||
@@ -13,5 +12,2 @@ export declare class WebGPURenderPipeline extends RenderPipeline { | ||
fs: WebGPUShader | null; | ||
private _bufferSlots; | ||
private _buffers; | ||
private _indexBuffer; | ||
/** For internal use to create BindGroups */ | ||
@@ -22,16 +18,7 @@ private _bindGroupLayout; | ||
destroy(): void; | ||
setIndexBuffer(indexBuffer: Buffer): void; | ||
setAttributes(attributes: Record<string, Buffer>): void; | ||
setConstantAttributes(attributes: Record<string, TypedArray>): void; | ||
setBindings(bindings: Record<string, Binding>): void; | ||
setUniforms(uniforms: Record<string, UniformValue>): void; | ||
_getBuffers(): Buffer[]; | ||
/** Return a bind group created by setBindings */ | ||
_getBindGroup(): GPUBindGroup; | ||
/** | ||
* Populate the complex WebGPU GPURenderPipelineDescriptor | ||
*/ | ||
protected _getRenderPipelineDescriptor(): GPURenderPipelineDescriptor; | ||
draw(options: { | ||
renderPass?: RenderPass; | ||
renderPass: RenderPass; | ||
vertexArray: VertexArray; | ||
vertexCount?: number; | ||
@@ -45,4 +32,9 @@ indexCount?: number; | ||
}): void; | ||
_setAttributeBuffers(webgpuRenderPass: WebGPURenderPass): void; | ||
/** Return a bind group created by setBindings */ | ||
_getBindGroup(): GPUBindGroup; | ||
/** | ||
* Populate the complex WebGPU GPURenderPipelineDescriptor | ||
*/ | ||
protected _getRenderPipelineDescriptor(): GPURenderPipelineDescriptor; | ||
} | ||
//# sourceMappingURL=webgpu-render-pipeline.d.ts.map |
@@ -5,3 +5,3 @@ import { RenderPipeline, cast, log, isObjectEmpty } from '@luma.gl/core'; | ||
import { getBindGroup } from "../helpers/get-bind-group.js"; | ||
import { getVertexBufferLayout, getBufferSlots } from "../helpers/get-vertex-buffer-layout.js"; | ||
import { getVertexBufferLayout } from "../helpers/get-vertex-buffer-layout.js"; | ||
export class WebGPURenderPipeline extends RenderPipeline { | ||
@@ -14,5 +14,2 @@ constructor(device, props) { | ||
this.fs = null; | ||
this._bufferSlots = void 0; | ||
this._buffers = void 0; | ||
this._indexBuffer = null; | ||
this._bindGroupLayout = null; | ||
@@ -32,22 +29,4 @@ this._bindGroup = null; | ||
this.fs = cast(props.fs); | ||
this._bufferSlots = getBufferSlots(this.props.shaderLayout, this.props.bufferLayout); | ||
this._buffers = new Array(Object.keys(this._bufferSlots).length).fill(null); | ||
} | ||
destroy() {} | ||
setIndexBuffer(indexBuffer) { | ||
this._indexBuffer = cast(indexBuffer); | ||
} | ||
setAttributes(attributes) { | ||
for (const [name, buffer] of Object.entries(attributes)) { | ||
const bufferIndex = this._bufferSlots[name]; | ||
if (bufferIndex >= 0) { | ||
this._buffers[bufferIndex] = buffer; | ||
} else { | ||
throw new Error(`Setting attribute '${name}' not listed in shader layout for program ${this.id}`); | ||
} | ||
} | ||
} | ||
setConstantAttributes(attributes) { | ||
throw new Error('not implemented'); | ||
} | ||
setBindings(bindings) { | ||
@@ -65,4 +44,16 @@ if (!isObjectEmpty(this.props.bindings)) { | ||
} | ||
_getBuffers() { | ||
return this._buffers; | ||
draw(options) { | ||
const webgpuRenderPass = cast(options.renderPass) || this.device.getDefaultRenderPass(); | ||
webgpuRenderPass.handle.setPipeline(this.handle); | ||
const bindGroup = this._getBindGroup(); | ||
if (bindGroup) { | ||
webgpuRenderPass.handle.setBindGroup(0, bindGroup); | ||
} | ||
options.vertexArray.bindBeforeRender(options.renderPass); | ||
if (options.indexCount) { | ||
webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance); | ||
} else { | ||
webgpuRenderPass.handle.draw(options.vertexCount || 0, options.instanceCount || 1, options.firstInstance); | ||
} | ||
options.vertexArray.unbindAfterRender(options.renderPass); | ||
} | ||
@@ -106,31 +97,3 @@ _getBindGroup() { | ||
} | ||
draw(options) { | ||
const webgpuRenderPass = cast(options.renderPass) || this.device.getDefaultRenderPass(); | ||
webgpuRenderPass.handle.setPipeline(this.handle); | ||
const bindGroup = this._getBindGroup(); | ||
if (bindGroup) { | ||
webgpuRenderPass.handle.setBindGroup(0, bindGroup); | ||
} | ||
this._setAttributeBuffers(webgpuRenderPass); | ||
if (options.indexCount) { | ||
webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance); | ||
} else { | ||
webgpuRenderPass.handle.draw(options.vertexCount || 0, options.instanceCount || 1, options.firstInstance); | ||
} | ||
} | ||
_setAttributeBuffers(webgpuRenderPass) { | ||
if (this._indexBuffer) { | ||
webgpuRenderPass.handle.setIndexBuffer(this._indexBuffer.handle, this._indexBuffer.props.indexType); | ||
} | ||
const buffers = this._getBuffers(); | ||
for (let i = 0; i < buffers.length; ++i) { | ||
const buffer = cast(buffers[i]); | ||
if (!buffer) { | ||
const attribute = this.props.shaderLayout.attributes.find(attribute => attribute.location === i); | ||
throw new Error(`No buffer provided for attribute '${(attribute === null || attribute === void 0 ? void 0 : attribute.name) || ''}' in Model '${this.props.id}'`); | ||
} | ||
webgpuRenderPass.handle.setVertexBuffer(i, buffer.handle); | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=webgpu-render-pipeline.js.map |
@@ -13,2 +13,3 @@ /// <reference types="dist" /> | ||
constructor(device: WebGPUDevice, props: TextureProps); | ||
protected initialize(props: TextureProps): void; | ||
protected createHandle(): GPUTexture; | ||
@@ -46,3 +47,5 @@ destroy(): void; | ||
}; | ||
/** TODO - intention is to expose TextureViews in the public API */ | ||
createView(): GPUTextureView; | ||
} | ||
//# sourceMappingURL=webgpu-texture.d.ts.map |
@@ -21,7 +21,19 @@ import { Texture } from '@luma.gl/core'; | ||
this.width = 1; | ||
if (typeof this.props.format === 'number') { | ||
throw new Error('number format'); | ||
this.device = device; | ||
if (props.data instanceof Promise) { | ||
props.data.then(resolvedImageData => { | ||
this.props = { | ||
...props, | ||
data: resolvedImageData | ||
}; | ||
this.initialize(this.props); | ||
}); | ||
return; | ||
} | ||
this.device = device; | ||
this.initialize(props); | ||
} | ||
initialize(props) { | ||
var _this$handle; | ||
this.handle = this.props.handle || this.createHandle(); | ||
(_this$handle = this.handle).label || (_this$handle.label = this.id); | ||
if (this.props.data) { | ||
@@ -35,12 +47,10 @@ this.setData({ | ||
this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler); | ||
this.view = this.handle.createView({}); | ||
this.view = this.createView(); | ||
} | ||
createHandle() { | ||
var _this$props$data, _this$props$data2; | ||
if (typeof this.props.format === 'number') { | ||
throw new Error('number format'); | ||
} | ||
const width = this.props.width || ((_this$props$data = this.props.data) === null || _this$props$data === void 0 ? void 0 : _this$props$data.width) || 1; | ||
const height = this.props.height || ((_this$props$data2 = this.props.data) === null || _this$props$data2 === void 0 ? void 0 : _this$props$data2.height) || 1; | ||
return this.device.handle.createTexture({ | ||
label: this.id, | ||
size: { | ||
@@ -102,3 +112,8 @@ width, | ||
} | ||
createView() { | ||
return this.handle.createView({ | ||
label: this.id | ||
}); | ||
} | ||
} | ||
//# sourceMappingURL=webgpu-texture.js.map |
@@ -31,6 +31,12 @@ let _Symbol$toStringTag; | ||
const webgpuIndexBuffer = this.indexBuffer; | ||
webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer === null || webgpuIndexBuffer === void 0 ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer === null || webgpuIndexBuffer === void 0 ? void 0 : webgpuIndexBuffer.indexType); | ||
if (webgpuIndexBuffer !== null && webgpuIndexBuffer !== void 0 && webgpuIndexBuffer.handle) { | ||
log.warn('setting index buffer', webgpuIndexBuffer === null || webgpuIndexBuffer === void 0 ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer === null || webgpuIndexBuffer === void 0 ? void 0 : webgpuIndexBuffer.indexType)(); | ||
webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer === null || webgpuIndexBuffer === void 0 ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer === null || webgpuIndexBuffer === void 0 ? void 0 : webgpuIndexBuffer.indexType); | ||
} | ||
for (let location = 0; location < this.maxVertexAttributes; location++) { | ||
const webgpuBuffer = this.attributes[location]; | ||
webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer.handle); | ||
if (webgpuBuffer !== null && webgpuBuffer !== void 0 && webgpuBuffer.handle) { | ||
log.warn('setting vertex buffer', location, webgpuBuffer === null || webgpuBuffer === void 0 ? void 0 : webgpuBuffer.handle)(); | ||
webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer === null || webgpuBuffer === void 0 ? void 0 : webgpuBuffer.handle); | ||
} | ||
} | ||
@@ -37,0 +43,0 @@ } |
@@ -23,3 +23,2 @@ /// <reference types="dist" /> | ||
destroy(): void; | ||
getCurrentTexture(): WebGPUTexture; | ||
/** Update framebuffer with properly resized "swap chain" texture views */ | ||
@@ -34,2 +33,4 @@ getCurrentFramebuffer(): WebGPUFramebuffer; | ||
}): void; | ||
/** Wrap the current canvas context texture in a luma.gl texture */ | ||
getCurrentTexture(): WebGPUTexture; | ||
/** We build render targets on demand (i.e. not when size changes but when about to render) */ | ||
@@ -36,0 +37,0 @@ _createDepthStencilAttachment(): Texture<import("@luma.gl/core").TextureProps>; |
@@ -22,8 +22,2 @@ import { CanvasContext, log } from '@luma.gl/core'; | ||
} | ||
getCurrentTexture() { | ||
return this.device._createTexture({ | ||
id: 'default-render-target', | ||
handle: this.gpuCanvasContext.getCurrentTexture() | ||
}); | ||
} | ||
getCurrentFramebuffer() { | ||
@@ -62,6 +56,12 @@ this.update(); | ||
} | ||
getCurrentTexture() { | ||
return this.device._createTexture({ | ||
id: `${this.id}#color-texture`, | ||
handle: this.gpuCanvasContext.getCurrentTexture() | ||
}); | ||
} | ||
_createDepthStencilAttachment() { | ||
if (!this.depthStencilAttachment) { | ||
this.depthStencilAttachment = this.device.createTexture({ | ||
id: 'depth-stencil-target', | ||
id: `${this.id}#depth-stencil-texture`, | ||
format: this.depthStencilFormat, | ||
@@ -68,0 +68,0 @@ width: this.width, |
{ | ||
"name": "@luma.gl/webgpu", | ||
"version": "9.0.0-alpha.54", | ||
"version": "9.0.0-beta.1", | ||
"description": "WebGPU adapter for the luma.gl API", | ||
@@ -22,5 +22,5 @@ "type": "module", | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs", | ||
"types": "./dist/index.d.ts" | ||
"require": "./dist/index.cjs" | ||
} | ||
@@ -41,7 +41,7 @@ }, | ||
"@babel/runtime": "^7.0.0", | ||
"@luma.gl/core": "9.0.0-alpha.54", | ||
"@luma.gl/core": "9.0.0-beta.1", | ||
"@probe.gl/env": "^4.0.2", | ||
"@webgpu/types": "^0.1.34" | ||
}, | ||
"gitHead": "6028eb651303eadbc8f25e86d135d28f118fa3cf" | ||
"gitHead": "5fb42f651e80825336a372ca5a66de7d55611ddf" | ||
} |
@@ -88,3 +88,3 @@ // luma.gl, MIT license | ||
binding: index, | ||
resource: cast<WebGPUTexture>(binding).handle.createView() | ||
resource: cast<WebGPUTexture>(binding).handle.createView({label: 'bind-group-auto-created'}) | ||
}; | ||
@@ -91,0 +91,0 @@ } |
// luma.gl, MIT license | ||
import type {ShaderLayout, BufferLayout, AttributeDeclaration, VertexFormat} from '@luma.gl/core'; | ||
import {decodeVertexFormat} from '@luma.gl/core'; | ||
import {log, decodeVertexFormat} from '@luma.gl/core'; | ||
// import {getAttributeInfosFromLayouts} from '@luma.gl/core'; | ||
@@ -54,2 +55,5 @@ /** Throw error on any WebGL-only vertex formats */ | ||
const attributeLayout = findAttributeLayout(shaderLayout, mapping.name, usedAttributes); | ||
if (!attributeLayout) { | ||
continue; // eslint-disable-line no-continue | ||
} | ||
byteStride = decodeVertexFormat(mapping.format).byteLength; | ||
@@ -138,3 +142,4 @@ | ||
if (!attribute) { | ||
throw new Error(`Unknown attribute ${name}`); | ||
log.warn(`Unknown attribute ${name}`)(); | ||
return null; | ||
} | ||
@@ -141,0 +146,0 @@ if (attributeNames.has(name)) { |
@@ -21,5 +21,5 @@ import type {RenderPassProps, RenderPassParameters, Binding, Framebuffer} from '@luma.gl/core'; | ||
const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer); | ||
log.groupCollapsed(1, `new WebGPURenderPass(${this.id})`)(); | ||
log.probe(1, JSON.stringify(renderPassDescriptor, null, 2))(); | ||
log.groupEnd(1)(); | ||
log.groupCollapsed(3, `new WebGPURenderPass(${this.id})`)(); | ||
log.probe(3, JSON.stringify(renderPassDescriptor, null, 2))(); | ||
log.groupEnd(3)(); | ||
this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor); | ||
@@ -153,3 +153,3 @@ this.handle.label = this.props.id; | ||
// ...colorAttachment, | ||
view: (colorAttachment as WebGPUTexture).handle.createView() | ||
view: (colorAttachment as WebGPUTexture).createView() | ||
})); | ||
@@ -159,3 +159,3 @@ | ||
renderPassDescriptor.depthStencilAttachment = { | ||
view: (framebuffer.depthStencilAttachment as WebGPUTexture).handle.createView() | ||
view: (framebuffer.depthStencilAttachment as WebGPUTexture).createView() | ||
}; | ||
@@ -162,0 +162,0 @@ const {depthStencilAttachment} = renderPassDescriptor; |
// luma.gl MIT license | ||
import type {TypedArray, Binding, UniformValue, RenderPass} from '@luma.gl/core'; | ||
import {Buffer, RenderPipeline, RenderPipelineProps, cast, log, isObjectEmpty} from '@luma.gl/core'; | ||
import type {Binding, UniformValue, RenderPass, VertexArray} from '@luma.gl/core'; | ||
import {RenderPipeline, RenderPipelineProps, cast, log, isObjectEmpty} from '@luma.gl/core'; | ||
import {applyParametersToRenderPipelineDescriptor} from '../helpers/webgpu-parameters'; | ||
import {getWebGPUTextureFormat} from '../helpers/convert-texture-format'; | ||
import {getBindGroup} from '../helpers/get-bind-group'; | ||
import {getVertexBufferLayout, getBufferSlots} from '../helpers/get-vertex-buffer-layout'; | ||
import {getVertexBufferLayout} from '../helpers/get-vertex-buffer-layout'; | ||
// import {convertAttributesVertexBufferToLayout} from '../helpers/get-vertex-buffer-layout'; | ||
@@ -14,3 +14,3 @@ // import {mapAccessorToWebGPUFormat} from './helpers/accessor-to-format'; | ||
import type {WebGPUDevice} from '../webgpu-device'; | ||
import type {WebGPUBuffer} from './webgpu-buffer'; | ||
// import type {WebGPUBuffer} from './webgpu-buffer'; | ||
import type {WebGPUShader} from './webgpu-shader'; | ||
@@ -29,5 +29,4 @@ import type {WebGPURenderPass} from './webgpu-render-pass'; | ||
private _bufferSlots: Record<string, number>; | ||
private _buffers: Buffer[]; | ||
private _indexBuffer: WebGPUBuffer | null = null; | ||
// private _bufferSlots: Record<string, number>; | ||
// private _buffers: Buffer[]; | ||
// private _firstIndex: number; | ||
@@ -56,4 +55,4 @@ // private _lastIndex: number; | ||
this._bufferSlots = getBufferSlots(this.props.shaderLayout, this.props.bufferLayout); | ||
this._buffers = new Array<Buffer>(Object.keys(this._bufferSlots).length).fill(null); | ||
// this._bufferSlots = getBufferSlots(this.props.shaderLayout, this.props.bufferLayout); | ||
// this._buffers = new Array<Buffer>(Object.keys(this._bufferSlots).length).fill(null); | ||
} | ||
@@ -65,6 +64,7 @@ | ||
setIndexBuffer(indexBuffer: Buffer): void { | ||
this._indexBuffer = cast<WebGPUBuffer>(indexBuffer); | ||
} | ||
// setIndexBuffer(indexBuffer: Buffer): void { | ||
// this._indexBuffer = cast<WebGPUBuffer>(indexBuffer); | ||
// } | ||
/* | ||
setAttributes(attributes: Record<string, Buffer>): void { | ||
@@ -88,6 +88,7 @@ for (const [name, buffer] of Object.entries(attributes)) { | ||
} | ||
*/ | ||
setConstantAttributes(attributes: Record<string, TypedArray>): void { | ||
throw new Error('not implemented'); | ||
} | ||
// setConstantAttributes(attributes: Record<string, TypedArray>): void { | ||
// throw new Error('not implemented'); | ||
// } | ||
@@ -118,6 +119,55 @@ setBindings(bindings: Record<string, Binding>): void { | ||
_getBuffers() { | ||
return this._buffers; | ||
draw(options: { | ||
renderPass: RenderPass; | ||
vertexArray: VertexArray; | ||
vertexCount?: number; | ||
indexCount?: number; | ||
instanceCount?: number; | ||
firstVertex?: number; | ||
firstIndex?: number; | ||
firstInstance?: number; | ||
baseVertex?: number; | ||
}): void { | ||
const webgpuRenderPass: WebGPURenderPass = | ||
cast<WebGPURenderPass>(options.renderPass) || this.device.getDefaultRenderPass(); | ||
// Set pipeline | ||
webgpuRenderPass.handle.setPipeline(this.handle); | ||
// Set bindings (uniform buffers, textures etc) | ||
const bindGroup = this._getBindGroup(); | ||
if (bindGroup) { | ||
webgpuRenderPass.handle.setBindGroup(0, bindGroup); | ||
} | ||
// Set attributes | ||
// Note: Rebinds constant attributes before each draw call | ||
options.vertexArray.bindBeforeRender(options.renderPass); | ||
// Draw | ||
if (options.indexCount) { | ||
webgpuRenderPass.handle.drawIndexed( | ||
options.indexCount, | ||
options.instanceCount, | ||
options.firstIndex, | ||
options.baseVertex, | ||
options.firstInstance | ||
); | ||
} else { | ||
webgpuRenderPass.handle.draw( | ||
options.vertexCount || 0, | ||
options.instanceCount || 1, // If 0, nothing will be drawn | ||
options.firstInstance | ||
); | ||
} | ||
// Note: Rebinds constant attributes before each draw call | ||
options.vertexArray.unbindAfterRender(options.renderPass); | ||
} | ||
// _getBuffers() { | ||
// return this._buffers; | ||
// } | ||
/** Return a bind group created by setBindings */ | ||
@@ -179,45 +229,3 @@ _getBindGroup() { | ||
draw(options: { | ||
renderPass?: RenderPass; | ||
vertexCount?: number; | ||
indexCount?: number; | ||
instanceCount?: number; | ||
firstVertex?: number; | ||
firstIndex?: number; | ||
firstInstance?: number; | ||
baseVertex?: number; | ||
}): void { | ||
const webgpuRenderPass: WebGPURenderPass = | ||
cast<WebGPURenderPass>(options.renderPass) || this.device.getDefaultRenderPass(); | ||
// Set pipeline | ||
webgpuRenderPass.handle.setPipeline(this.handle); | ||
// Set bindings (uniform buffers, textures etc) | ||
const bindGroup = this._getBindGroup(); | ||
if (bindGroup) { | ||
webgpuRenderPass.handle.setBindGroup(0, bindGroup); | ||
} | ||
// Set attributes | ||
this._setAttributeBuffers(webgpuRenderPass); | ||
// Draw | ||
if (options.indexCount) { | ||
webgpuRenderPass.handle.drawIndexed( | ||
options.indexCount, | ||
options.instanceCount, | ||
options.firstIndex, | ||
options.baseVertex, | ||
options.firstInstance | ||
); | ||
} else { | ||
webgpuRenderPass.handle.draw( | ||
options.vertexCount || 0, | ||
options.instanceCount || 1, // If 0, nothing will be drawn | ||
options.firstInstance | ||
); | ||
} | ||
} | ||
/** | ||
_setAttributeBuffers(webgpuRenderPass: WebGPURenderPass) { | ||
@@ -261,4 +269,5 @@ if (this._indexBuffer) { | ||
} | ||
*/ | ||
* | ||
} | ||
*/ | ||
} |
@@ -35,11 +35,23 @@ // luma.gl, MIT license | ||
if (typeof this.props.format === 'number') { | ||
throw new Error('number format'); | ||
this.device = device; | ||
if (props.data instanceof Promise) { | ||
props.data.then(resolvedImageData => { | ||
// @ts-expect-error | ||
this.props = {...props, data: resolvedImageData}; | ||
this.initialize(this.props); | ||
}); | ||
return; | ||
} | ||
this.device = device; | ||
this.initialize(props); | ||
} | ||
protected initialize(props: TextureProps): void { | ||
// @ts-expect-error | ||
this.handle = this.props.handle || this.createHandle(); | ||
this.handle.label ||= this.id; | ||
if (this.props.data) { | ||
this.setData({data: this.props.data} ); | ||
this.setData({data: this.props.data}); | ||
} | ||
@@ -63,18 +75,14 @@ | ||
// But we are not ready to expose TextureViews to the public API. | ||
this.view = this.handle.createView({ | ||
// format: this.props.format, | ||
// dimension: this.props.dimension, | ||
// aspect = "all"; | ||
// baseMipLevel: 0; | ||
// mipLevelCount; | ||
// baseArrayLayer = 0; | ||
// arrayLayerCount; | ||
}); | ||
// @ts-expect-error | ||
this.view = this.createView(); | ||
// format: this.props.format, | ||
// dimension: this.props.dimension, | ||
// aspect = "all"; | ||
// baseMipLevel: 0; | ||
// mipLevelCount; | ||
// baseArrayLayer = 0; | ||
// arrayLayerCount; | ||
} | ||
protected createHandle(): GPUTexture { | ||
if (typeof this.props.format === 'number') { | ||
throw new Error('number format'); | ||
} | ||
// Deduce size from data - TODO this is a hack | ||
@@ -87,2 +95,3 @@ // @ts-expect-error | ||
return this.device.handle.createTexture({ | ||
label: this.id, | ||
size: { | ||
@@ -179,2 +188,9 @@ width, | ||
// WebGPU specific | ||
/** TODO - intention is to expose TextureViews in the public API */ | ||
createView(): GPUTextureView { | ||
return this.handle.createView({label: this.id}); | ||
} | ||
/* | ||
@@ -181,0 +197,0 @@ async readPixels() { |
@@ -63,6 +63,13 @@ // luma.gl, MIT license | ||
const webgpuIndexBuffer = this.indexBuffer as WebGPUBuffer; | ||
webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType); | ||
if (webgpuIndexBuffer?.handle) { | ||
// Note we can't unset an index buffer | ||
log.warn('setting index buffer', webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType)(); | ||
webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType); | ||
} | ||
for (let location = 0; location < this.maxVertexAttributes; location++) { | ||
const webgpuBuffer = this.attributes[location] as WebGPUBuffer; | ||
webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer.handle); | ||
if (webgpuBuffer?.handle) { | ||
log.warn('setting vertex buffer', location, webgpuBuffer?.handle)(); | ||
webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer?.handle); | ||
} | ||
} | ||
@@ -73,4 +80,6 @@ // TODO - emit warnings/errors/throw if constants have been set on this vertex array | ||
override unbindAfterRender(renderPass: RenderPass): void { | ||
// On WebGPU we don't unbind | ||
// On WebGPU we don't need to unbind. | ||
// In fact we can't easily do it. setIndexBuffer/setVertexBuffer don't accept null. | ||
// Unbinding presumably happens automatically when the render pass is ended. | ||
} | ||
} |
@@ -44,10 +44,2 @@ // / <reference types="@webgpu/types" /> | ||
getCurrentTexture(): WebGPUTexture { | ||
// Wrap the current canvas context texture in a luma.gl texture | ||
return this.device._createTexture({ | ||
id: 'default-render-target', | ||
handle: this.gpuCanvasContext.getCurrentTexture() | ||
}); | ||
} | ||
/** Update framebuffer with properly resized "swap chain" texture views */ | ||
@@ -115,2 +107,10 @@ getCurrentFramebuffer(): WebGPUFramebuffer { | ||
/** Wrap the current canvas context texture in a luma.gl texture */ | ||
getCurrentTexture(): WebGPUTexture { | ||
return this.device._createTexture({ | ||
id: `${this.id}#color-texture`, | ||
handle: this.gpuCanvasContext.getCurrentTexture() | ||
}); | ||
} | ||
/** We build render targets on demand (i.e. not when size changes but when about to render) */ | ||
@@ -120,3 +120,3 @@ _createDepthStencilAttachment() { | ||
this.depthStencilAttachment = this.device.createTexture({ | ||
id: 'depth-stencil-target', | ||
id: `${this.id}#depth-stencil-texture`, | ||
format: this.depthStencilFormat, | ||
@@ -123,0 +123,0 @@ width: this.width, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9363
648787
+ Added@luma.gl/core@9.0.0-beta.1(transitive)
- Removed@luma.gl/core@9.0.0-alpha.54(transitive)
Updated@luma.gl/core@9.0.0-beta.1