Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@luma.gl/webgpu

Package Overview
Dependencies
Maintainers
7
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@luma.gl/webgpu - npm Package Compare versions

Comparing version 9.0.0-alpha.30 to 9.0.0-alpha.31

6

dist/adapter/helpers/get-bind-group.d.ts
/// <reference types="dist" />
import type { ShaderLayout, BindingLayout, Binding } from '@luma.gl/core';
import type { ShaderLayout, BindingDeclaration, Binding } from '@luma.gl/core';
/**

@@ -11,4 +11,4 @@ * Create a WebGPU "bind group layout" from an array of luma.gl bindings

*/
export declare function getBindGroup(device: GPUDevice, bindGroupLayout: GPUBindGroupLayout, layout: ShaderLayout, bindings: Record<string, Binding>): GPUBindGroup;
export declare function getShaderLayoutBinding(layout: ShaderLayout, bindingName: string): BindingLayout;
export declare function getBindGroup(device: GPUDevice, bindGroupLayout: GPUBindGroupLayout, shaderLayout: ShaderLayout, bindings: Record<string, Binding>): GPUBindGroup;
export declare function getShaderLayoutBinding(shaderLayout: ShaderLayout, bindingName: string): BindingDeclaration;
//# sourceMappingURL=get-bind-group.d.ts.map

@@ -5,4 +5,4 @@ import { Buffer, Sampler, Texture, log, cast } from '@luma.gl/core';

}
export function getBindGroup(device, bindGroupLayout, layout, bindings) {
const entries = getBindGroupEntries(bindings, layout);
export function getBindGroup(device, bindGroupLayout, shaderLayout, bindings) {
const entries = getBindGroupEntries(bindings, shaderLayout);
return device.createBindGroup({

@@ -13,4 +13,4 @@ layout: bindGroupLayout,

}
export function getShaderLayoutBinding(layout, bindingName) {
const bindingLayout = layout.bindings.find(binding => binding.name === bindingName);
export function getShaderLayoutBinding(shaderLayout, bindingName) {
const bindingLayout = shaderLayout.bindings.find(binding => binding.name === bindingName);
if (!bindingLayout) {

@@ -21,6 +21,6 @@ log.warn("Binding ".concat(bindingName, " not set: Not found in shader layout."))();

}
function getBindGroupEntries(bindings, layout) {
function getBindGroupEntries(bindings, shaderLayout) {
const entries = [];
for (const [bindingName, value] of Object.entries(bindings)) {
const bindingLayout = getShaderLayoutBinding(layout, bindingName);
const bindingLayout = getShaderLayoutBinding(shaderLayout, bindingName);
if (bindingLayout) {

@@ -27,0 +27,0 @@ entries.push(getBindGroupEntry(value, bindingLayout.location));

/// <reference types="dist" />
import type { ShaderLayout, BufferMapping } from '@luma.gl/core';
import type { ShaderLayout, BufferLayout } from '@luma.gl/core';
/**

@@ -7,7 +7,7 @@ * Build a WebGPU vertex buffer layout intended for use in a GPURenderPassDescriptor.

* @param layout
* @param bufferMap The buffer map is optional
* @param bufferLayout The buffer map is optional
* @returns WebGPU layout intended for a GPURenderPassDescriptor.
*/
export declare function getVertexBufferLayout(layout: ShaderLayout, bufferMap: BufferMapping[]): GPUVertexBufferLayout[];
export declare function getBufferSlots(layout: ShaderLayout, bufferMap: BufferMapping[]): Record<string, number>;
export declare function getVertexBufferLayout(shaderLayout: ShaderLayout, bufferLayout: BufferLayout[]): GPUVertexBufferLayout[];
export declare function getBufferSlots(shaderLayout: ShaderLayout, bufferLayout: BufferLayout[]): Record<string, number>;
//# sourceMappingURL=get-vertex-buffer-layout.d.ts.map

@@ -8,6 +8,6 @@ import { decodeVertexFormat } from '@luma.gl/core';

}
export function getVertexBufferLayout(layout, bufferMap) {
export function getVertexBufferLayout(shaderLayout, bufferLayout) {
const vertexBufferLayouts = [];
const usedAttributes = new Set();
for (const mapping of bufferMap) {
for (const mapping of bufferLayout) {
const vertexAttributes = [];

@@ -17,19 +17,19 @@ let stepMode = 'vertex';

const byteOffset = mapping.byteOffset || 0;
if ('attributes' in mapping) {
if (mapping.attributes) {
for (const interleaved of mapping.attributes) {
const attributeLayout = findAttributeLayout(layout, interleaved.name, usedAttributes);
const attributeLayout = findAttributeLayout(shaderLayout, interleaved.name, usedAttributes);
stepMode = attributeLayout.stepMode || 'vertex';
vertexAttributes.push({
format: getWebGPUVertexFormat(attributeLayout.format),
format: getWebGPUVertexFormat(interleaved.format || mapping.format),
offset: byteOffset + byteStride,
shaderLocation: attributeLayout.location
});
byteStride += decodeVertexFormat(attributeLayout.format).byteLength;
byteStride += decodeVertexFormat(mapping.format).byteLength;
}
} else {
const attributeLayout = findAttributeLayout(layout, mapping.name, usedAttributes);
byteStride = decodeVertexFormat(attributeLayout.format).byteLength;
const attributeLayout = findAttributeLayout(shaderLayout, mapping.name, usedAttributes);
byteStride = decodeVertexFormat(mapping.format).byteLength;
stepMode = attributeLayout.stepMode || 'vertex';
vertexAttributes.push({
format: getWebGPUVertexFormat(attributeLayout.format),
format: getWebGPUVertexFormat(mapping.format),
offset: byteOffset,

@@ -45,9 +45,9 @@ shaderLocation: attributeLayout.location

}
for (const attribute of layout.attributes) {
for (const attribute of shaderLayout.attributes) {
if (!usedAttributes.has(attribute.name)) {
vertexBufferLayouts.push({
arrayStride: decodeVertexFormat(attribute.format).byteLength,
arrayStride: decodeVertexFormat('float32x3').byteLength,
stepMode: attribute.stepMode || 'vertex',
attributes: [{
format: getWebGPUVertexFormat(attribute.format),
format: getWebGPUVertexFormat('float32x3'),
offset: 0,

@@ -61,7 +61,7 @@ shaderLocation: attribute.location

}
export function getBufferSlots(layout, bufferMap) {
export function getBufferSlots(shaderLayout, bufferLayout) {
const usedAttributes = new Set();
let bufferSlot = 0;
const bufferSlots = {};
for (const mapping of bufferMap) {
for (const mapping of bufferLayout) {
if ('attributes' in mapping) {

@@ -76,3 +76,3 @@ for (const interleaved of mapping.attributes) {

}
for (const attribute of layout.attributes) {
for (const attribute of shaderLayout.attributes) {
if (!usedAttributes.has(attribute.name)) {

@@ -84,4 +84,4 @@ bufferSlots[attribute.name] = bufferSlot++;

}
function findAttributeLayout(layout, name, attributeNames) {
const attribute = layout.attributes.find(attribute => attribute.name === name);
function findAttributeLayout(shaderLayout, name, attributeNames) {
const attribute = shaderLayout.attributes.find(attribute => attribute.name === name);
if (!attribute) {

@@ -88,0 +88,0 @@ throw new Error("Unknown attribute ".concat(name));

@@ -5,3 +5,3 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

constructor(device, props) {
super(props);
super(device, props);
_defineProperty(this, "device", void 0);

@@ -8,0 +8,0 @@ _defineProperty(this, "handle", void 0);

@@ -24,3 +24,3 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

this.fs = cast(props.fs);
this._bufferSlots = getBufferSlots(this.props.layout, this.props.bufferMap);
this._bufferSlots = getBufferSlots(this.props.shaderLayout, this.props.bufferLayout);
this._buffers = new Array(Object.keys(this._bufferSlots).length).fill(null);

@@ -52,3 +52,3 @@ this._bindGroupLayout = this.handle.getBindGroupLayout(0);

setConstantAttributes(attributes) {
console.error('not implemented');
throw new Error('not implemented');
}

@@ -58,3 +58,3 @@ setBindings(bindings) {

Object.assign(this.props.bindings, bindings);
this._bindGroup = getBindGroup(this.device.handle, this._bindGroupLayout, this.props.layout, this.props.bindings);
this._bindGroup = getBindGroup(this.device.handle, this._bindGroupLayout, this.props.shaderLayout, this.props.bindings);
}

@@ -77,3 +77,3 @@ }

entryPoint: this.props.vsEntryPoint || 'main',
buffers: getVertexBufferLayout(this.props.layout, this.props.bufferMap)
buffers: getVertexBufferLayout(this.props.shaderLayout, this.props.bufferLayout)
};

@@ -130,3 +130,3 @@ let fragment;

if (!buffer) {
const attribute = this.props.layout.attributes.find(attribute => attribute.location === i);
const attribute = this.props.shaderLayout.attributes.find(attribute => attribute.location === i);
throw new Error("No buffer provided for attribute '".concat((attribute === null || attribute === void 0 ? void 0 : attribute.name) || '', "' in Model '").concat(this.props.id, "'"));

@@ -133,0 +133,0 @@ }

{
"name": "@luma.gl/webgpu",
"version": "9.0.0-alpha.30",
"version": "9.0.0-alpha.31",
"description": "WebGPU adapter for the luma.gl API",

@@ -40,7 +40,7 @@ "type": "module",

"@babel/runtime": "^7.0.0",
"@luma.gl/core": "9.0.0-alpha.30",
"@luma.gl/core": "9.0.0-alpha.31",
"@probe.gl/env": "^4.0.2",
"@webgpu/types": "^0.1.34"
},
"gitHead": "7fb163f20d3400d59b59a17d36b4f3c466c559ba"
"gitHead": "9f22c8a7f5a03abb1bea5530b77c083b8f553569"
}
// luma.gl, MIT license
import type {ShaderLayout, BindingLayout, Binding} from '@luma.gl/core';
import type {ShaderLayout, BindingDeclaration, Binding} from '@luma.gl/core';
import {Buffer, Sampler, Texture, log, cast} from '@luma.gl/core';

@@ -12,3 +12,7 @@ import type {WebGPUBuffer} from '../resources/webgpu-buffer';

*/
export function makeBindGroupLayout(device: GPUDevice, layout: GPUBindGroupLayout, bindings: Binding[]): GPUBindGroupLayout {
export function makeBindGroupLayout(
device: GPUDevice,
layout: GPUBindGroupLayout,
bindings: Binding[]
): GPUBindGroupLayout {
throw new Error('not implemented');

@@ -27,6 +31,6 @@ // return device.createBindGroupLayout({

bindGroupLayout: GPUBindGroupLayout,
layout: ShaderLayout,
shaderLayout: ShaderLayout,
bindings: Record<string, Binding>
): GPUBindGroup {
const entries = getBindGroupEntries(bindings, layout);
const entries = getBindGroupEntries(bindings, shaderLayout);
return device.createBindGroup({

@@ -38,4 +42,7 @@ layout: bindGroupLayout,

export function getShaderLayoutBinding(layout: ShaderLayout, bindingName: string): BindingLayout {
const bindingLayout = layout.bindings.find(binding => binding.name === bindingName);
export function getShaderLayoutBinding(
shaderLayout: ShaderLayout,
bindingName: string
): BindingDeclaration {
const bindingLayout = shaderLayout.bindings.find(binding => binding.name === bindingName);
if (!bindingLayout) {

@@ -51,7 +58,10 @@ log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();

*/
function getBindGroupEntries(bindings: Record<string, Binding>, layout: ShaderLayout): GPUBindGroupEntry[] {
function getBindGroupEntries(
bindings: Record<string, Binding>,
shaderLayout: ShaderLayout
): GPUBindGroupEntry[] {
const entries: GPUBindGroupEntry[] = [];
for (const [bindingName, value] of Object.entries(bindings)) {
const bindingLayout = getShaderLayoutBinding(layout, bindingName);
const bindingLayout = getShaderLayoutBinding(shaderLayout, bindingName);
if (bindingLayout) {

@@ -58,0 +68,0 @@ entries.push(getBindGroupEntry(value, bindingLayout.location));

@@ -1,2 +0,2 @@

import type {ShaderLayout, BufferMapping, AttributeLayout, VertexFormat} from '@luma.gl/core';
import type {ShaderLayout, BufferLayout, AttributeDeclaration, VertexFormat} from '@luma.gl/core';
import {decodeVertexFormat} from '@luma.gl/core';

@@ -16,11 +16,14 @@

* @param layout
* @param bufferMap The buffer map is optional
* @param bufferLayout The buffer map is optional
* @returns WebGPU layout intended for a GPURenderPassDescriptor.
*/
export function getVertexBufferLayout(layout: ShaderLayout, bufferMap: BufferMapping[]): GPUVertexBufferLayout[] {
export function getVertexBufferLayout(
shaderLayout: ShaderLayout,
bufferLayout: BufferLayout[]
): GPUVertexBufferLayout[] {
const vertexBufferLayouts: GPUVertexBufferLayout[] = [];
const usedAttributes = new Set<string>();
// First handle any buffers mentioned in `bufferMapping`
for (const mapping of bufferMap) {
// First handle any buffers mentioned in `bufferLayout`
for (const mapping of bufferLayout) {
// Build vertex attributes for one buffer

@@ -35,10 +38,10 @@ const vertexAttributes: GPUVertexAttribute[] = [];

// interleaved mapping {..., attributes: [{...}, ...]}
if ('attributes' in mapping) {
// const arrayStride = mapping.byteStride; TODO
if (mapping.attributes) {
// const arrayStride = mapping.byteStride; TODO
for (const interleaved of mapping.attributes) {
const attributeLayout = findAttributeLayout(layout, interleaved.name, usedAttributes);
const attributeLayout = findAttributeLayout(shaderLayout, interleaved.name, usedAttributes);
stepMode = attributeLayout.stepMode || 'vertex';
vertexAttributes.push({
format: getWebGPUVertexFormat(attributeLayout.format),
format: getWebGPUVertexFormat(interleaved.format || mapping.format),
offset: byteOffset + byteStride,

@@ -48,12 +51,12 @@ shaderLocation: attributeLayout.location

byteStride += decodeVertexFormat(attributeLayout.format).byteLength;
byteStride += decodeVertexFormat(mapping.format).byteLength;
}
// non-interleaved mapping (just set offset and stride)
} else {
const attributeLayout = findAttributeLayout(layout, mapping.name, usedAttributes);
byteStride = decodeVertexFormat(attributeLayout.format).byteLength;
const attributeLayout = findAttributeLayout(shaderLayout, mapping.name, usedAttributes);
byteStride = decodeVertexFormat(mapping.format).byteLength;
stepMode = attributeLayout.stepMode || 'vertex';
vertexAttributes.push({
format: getWebGPUVertexFormat(attributeLayout.format),
format: getWebGPUVertexFormat(mapping.format),
offset: byteOffset,

@@ -72,13 +75,15 @@ shaderLocation: attributeLayout.location

// Add any non-mapped attributes
for (const attribute of layout.attributes) {
// Add any non-mapped attributes - TODO - avoid hardcoded types
for (const attribute of shaderLayout.attributes) {
if (!usedAttributes.has(attribute.name)) {
vertexBufferLayouts.push({
arrayStride: decodeVertexFormat(attribute.format).byteLength,
arrayStride: decodeVertexFormat('float32x3').byteLength,
stepMode: attribute.stepMode || 'vertex',
attributes: [{
format: getWebGPUVertexFormat(attribute.format),
offset: 0,
shaderLocation: attribute.location
}]
attributes: [
{
format: getWebGPUVertexFormat('float32x3'),
offset: 0,
shaderLocation: attribute.location
}
]
});

@@ -91,3 +96,6 @@ }

export function getBufferSlots(layout: ShaderLayout, bufferMap: BufferMapping[]): Record<string, number> {
export function getBufferSlots(
shaderLayout: ShaderLayout,
bufferLayout: BufferLayout[]
): Record<string, number> {
const usedAttributes = new Set<string>();

@@ -97,4 +105,4 @@ let bufferSlot = 0;

// First handle any buffers mentioned in `bufferMapping`
for (const mapping of bufferMap) {
// First handle any buffers mentioned in `bufferLayout`
for (const mapping of bufferLayout) {
// interleaved mapping {..., attributes: [{...}, ...]}

@@ -113,3 +121,3 @@ if ('attributes' in mapping) {

// Add any non-mapped attributes
for (const attribute of layout.attributes) {
for (const attribute of shaderLayout.attributes) {
if (!usedAttributes.has(attribute.name)) {

@@ -128,4 +136,8 @@ bufferSlots[attribute.name] = bufferSlot++;

*/
function findAttributeLayout(layout: ShaderLayout, name: string, attributeNames: Set<string>): AttributeLayout {
const attribute = layout.attributes.find(attribute => attribute.name === name);
function findAttributeLayout(
shaderLayout: ShaderLayout,
name: string,
attributeNames: Set<string>
): AttributeDeclaration {
const attribute = shaderLayout.attributes.find(attribute => attribute.name === name);
if (!attribute) {

@@ -132,0 +144,0 @@ throw new Error(`Unknown attribute ${name}`);

@@ -16,3 +16,3 @@ import {CommandEncoder, CommandEncoderProps, Buffer, Texture, cast,

constructor(device: WebGPUDevice, props: CommandEncoderProps) {
super(props);
super(device, props);
this.device = device;

@@ -19,0 +19,0 @@ this.handle = props.handle || this.device.handle.createCommandEncoder({

@@ -47,3 +47,3 @@ // luma.gl MIT license

this._bufferSlots = getBufferSlots(this.props.layout, this.props.bufferMap);
this._bufferSlots = getBufferSlots(this.props.shaderLayout, this.props.bufferLayout);
this._buffers = new Array<Buffer>(Object.keys(this._bufferSlots).length).fill(null);

@@ -91,3 +91,3 @@ this._bindGroupLayout = this.handle.getBindGroupLayout(0);

setConstantAttributes(attributes: Record<string, TypedArray>): void {
console.error('not implemented');
throw new Error('not implemented');
}

@@ -103,3 +103,3 @@

this._bindGroupLayout,
this.props.layout,
this.props.shaderLayout,
this.props.bindings

@@ -132,3 +132,3 @@ );

entryPoint: this.props.vsEntryPoint || 'main',
buffers: getVertexBufferLayout(this.props.layout, this.props.bufferMap)
buffers: getVertexBufferLayout(this.props.shaderLayout, this.props.bufferLayout)
};

@@ -228,3 +228,3 @@

if (!buffer) {
const attribute = this.props.layout.attributes.find(
const attribute = this.props.shaderLayout.attributes.find(
(attribute) => attribute.location === i

@@ -241,3 +241,3 @@ );

/*
for (const [bufferName, attributeMapping] of Object.entries(this.props.bufferMap)) {
for (const [bufferName, attributeMapping] of Object.entries(this.props.bufferLayout)) {
const buffer = cast<WebGPUBuffer>(this.props.attributes[bufferName]);

@@ -244,0 +244,0 @@ if (!buffer) {

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 too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc