Skip to content

Commit

Permalink
chore(core): Cleanup round of util and API surface reduction (#2008)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Mar 6, 2024
1 parent b2caf5c commit c948447
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import type {CompilerMessage} from './compiler-message';
import type {CompilerMessage} from '../adapter/types/compiler-message';

/** @returns annotated errors or warnings */
export function formatCompilerLog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Copyright (c) vis.gl contributors

import type {Log} from '@probe.gl/log';
import type {DeviceProps} from '../adapter/device';
import {Device} from '../adapter/device';
import type {DeviceProps} from './device';
import {Device} from './device';
import {StatsManager} from '../utils/stats-manager';
import {lumaStats} from '../utils/stats-manager';
import {log} from '../utils/log';
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/adapter/resources/shader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type {Device} from '../device';
import {Resource, ResourceProps} from './resource';
// import { log } from '../../utils/log';
import {uid} from '../../utils/uid';
import {CompilerMessage} from '../../portable/compiler-log/compiler-message';
import {formatCompilerLog} from '../../portable/compiler-log/format-compiler-log';
import {CompilerMessage} from '../types/compiler-message';
import {formatCompilerLog} from '../../adapter-utils/format-compiler-log';

/**
* Properties for a Shader
Expand Down
15 changes: 7 additions & 8 deletions modules/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export {VERSION} from './init';

// MAIN API ACCESS POINT
export {luma} from './portable/luma';
export {luma} from './adapter/luma';

// ADAPTER (DEVICE AND GPU RESOURCE INTERFACES)
export type {DeviceProps, DeviceInfo, DeviceFeature} from './adapter/device';
Expand Down Expand Up @@ -66,14 +66,13 @@ export {TransformFeedback} from './adapter/resources/transform-feedback';
export type {QuerySetProps} from './adapter/resources/query-set';
export {QuerySet} from './adapter/resources/query-set';

// PORTABLE API - UNIFORM BUFFERS
export {UniformBufferLayout} from './portable/uniform-buffers/uniform-buffer-layout';
export {UniformBlock} from './portable/uniform-buffers/uniform-block';
export {UniformStore} from './portable/uniform-buffers/uniform-store';

// PORTABLE API - COMPILER LOG
export type {CompilerMessage} from './portable/compiler-log/compiler-message';
export {formatCompilerLog} from './portable/compiler-log/format-compiler-log';
export type {CompilerMessage} from './adapter/types/compiler-message';

// PORTABLE API - UNIFORM BUFFERS
export {UniformBufferLayout} from './portable/uniform-buffer-layout';
export {UniformBlock} from './portable/uniform-block';
export {UniformStore} from './portable/uniform-store';

// API TYPES
// export type {AccessorObject} from './adapter/types/accessor';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import type {ShaderUniformType} from '../../gpu-type-utils/shader-types';
import type {UniformValue} from '../../adapter/types/types';
import type {ShaderUniformType} from '../gpu-type-utils/shader-types';
import type {UniformValue} from '../adapter/types/types';
import {
ShaderLayout,
UniformInfo,
UniformBufferBindingLayout
} from '../../adapter/types/shader-layout';
import {arrayEqual, arrayCopy} from '../../utils/array-equal';
} from '../adapter/types/shader-layout';
import {arrayEqual, arrayCopy} from '../utils/array-equal';

/**
* A uniform block holds values of the of uniform values for one uniform block / buffer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import type {ShaderUniformType, ShaderDataType} from '../../gpu-type-utils/shader-types';
import {decodeShaderUniformType, alignTo} from '../../gpu-type-utils/decode-shader-types';
import type {ShaderUniformType, ShaderDataType} from '../gpu-type-utils/shader-types';
import {decodeShaderUniformType, alignTo} from '../gpu-type-utils/decode-shader-types';

import type {UniformValue} from '../../adapter/types/types';
import {getScratchArrayBuffer} from '../../utils/array-utils-flat';
import {isNumberArray} from '../../utils/is-array';
import {log} from '../../utils/log';
import type {UniformValue} from '../adapter/types/types';
import {getScratchArrayBuffer} from '../utils/array-utils-flat';
import {isNumberArray} from '../utils/is-array';
import {log} from '../utils/log';

/**
* Smallest buffer size that can be used for uniform buffers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import type {ShaderUniformType} from '../../gpu-type-utils/shader-types';
import type {UniformValue} from '../../adapter/types/types';
import type {Device} from '../../adapter/device';
import {Buffer} from '../../adapter/resources/buffer';
import type {ShaderUniformType} from '../gpu-type-utils/shader-types';
import type {UniformValue} from '../adapter/types/types';
import type {Device} from '../adapter/device';
import {Buffer} from '../adapter/resources/buffer';
import {log} from '../utils/log';
import {UniformBlock} from './uniform-block';
import {UniformBufferLayout} from './uniform-buffer-layout';
import {log} from '../../utils/log';

export type ShaderModuleInputs = {
uniformTypes?: Record<string, ShaderUniformType>;
Expand Down
32 changes: 1 addition & 31 deletions modules/core/src/utils/array-utils-flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import type {TypedArray, NumberArray} from '../types';
import type {TypedArray} from '../types';

let arrayBuffer: ArrayBuffer;

Expand All @@ -17,33 +17,3 @@ export function getScratchArray(Type: any, length: number): TypedArray {
const scratchArrayBuffer = getScratchArrayBuffer(Type.BYTES_PER_ELEMENT * length);
return new Type(scratchArrayBuffer, 0, length); // arrayBuffer, byteOffset, length (in elements)
}

// Uses copyWithin to significantly speed up typed array value filling
export function fillArray(options: {
target: NumberArray;
source: NumberArray;
start?: number;
count?: number;
}): NumberArray {
const {target, source, start = 0, count = 1} = options;
const length = source.length;
const total = count * length;
let copied = 0;
for (let i = start; copied < length; copied++) {
target[i++] = source[copied];
}

while (copied < total) {
// If we have copied less than half, copy everything we got
// else copy remaining in one operation
if (copied < total - copied) {
target.copyWithin(start + copied, start, start + copied);
copied *= 2;
} else {
target.copyWithin(start + copied, start, start + total - copied);
copied = total;
}
}

return options.target;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Copyright (c) vis.gl contributors

import test, {Test} from 'tape-promise/tape';
import {formatCompilerLog, CompilerMessage} from '@luma.gl/core';
import {CompilerMessage} from '@luma.gl/core';
import {formatCompilerLog} from '@luma.gl/core/adapter-utils/format-compiler-log';

const ERROR_LOG: CompilerMessage[] = [
{
Expand Down
6 changes: 2 additions & 4 deletions modules/core/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import './gpu-type-utils/vertex-format-from-attribute.spec';
// adapter utils
import './adapter-utils/get-attribute-from-layout.spec';
import './adapter-utils/is-uniform-value.spec';
import './adapter-utils/format-compiler-log.spec';

// adapter
import './adapter/canvas-context.spec';

// portable - uniform buffers
import './portable/uniform-buffers/uniform-buffer-layout.spec';

// portable - compiler logs
import './portable/compiler-log/format-compiler-log.spec';
import './portable/uniform-buffer-layout.spec';

0 comments on commit c948447

Please sign in to comment.