From ffd31bfd5ada827849682355adad109b7ea0fb8c Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 1 Oct 2024 11:34:46 +0200 Subject: [PATCH 01/11] Convert hexbin.spec to UBO --- .../modules/aggregation-layers/hexbin.spec.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/test/modules/aggregation-layers/hexbin.spec.ts b/test/modules/aggregation-layers/hexbin.spec.ts index 13aa33603e5..1c56870e00f 100644 --- a/test/modules/aggregation-layers/hexbin.spec.ts +++ b/test/modules/aggregation-layers/hexbin.spec.ts @@ -9,6 +9,7 @@ import { getHexbinCentroid, getHexbinCentroidGLSL } from '@deck.gl/aggregation-layers/hexagon-layer/hexbin'; +import {binOptionsUniforms} from '@deck.gl/aggregation-layers/hexagon-layer/bin-options-uniforms'; import {hexbin} from 'd3-hexbin'; import {device} from '@deck.gl/test-utils'; import {BufferTransform} from '@luma.gl/engine'; @@ -42,16 +43,15 @@ test('pointToHexbin vs d3-hexbin', t => { test('pointToHexbin CPU vs GPU', t => { const transform = new BufferTransform(device, { vs: `#version 300 es - uniform vec2 position; - uniform float radius; out vec2 binId; ${pointToHexbinGLSL} void main() { - binId = vec2(pointToHexbin(position, radius)); + binId = vec2(pointToHexbin(binOptions.hexOriginCommon, binOptions.radiusCommon)); } `, topology: 'point-list', - varyings: ['binId'] + varyings: ['binId'], + modules: [binOptionsUniforms] }); transform.model.setVertexCount(1); const outputBuffer = device.createBuffer({ @@ -61,7 +61,8 @@ test('pointToHexbin CPU vs GPU', t => { for (const d of TestData) { const expected = pointToHexbin(d.p, d.radius); - transform.model.setUniforms({position: d.p, radius: d.radius}); + const binOptions = {hexOriginCommon: d.p, radiusCommon: d.radius}; + transform.model.shaderInputs.setProps({binOptions}); transform.run({discard: true}); const result = new Float32Array(outputBuffer.readSyncWebGL().buffer); // tape does not consider -0 == 0 @@ -80,16 +81,15 @@ test('pointToHexbin CPU vs GPU', t => { test('getHexbinCentroid CPU vs GPU', t => { const transform = new BufferTransform(device, { vs: `#version 300 es - uniform vec2 binId; - uniform float radius; out vec2 position; ${getHexbinCentroidGLSL} void main() { - position = hexbinCentroid(binId, radius); + position = hexbinCentroid(binOptions.hexOriginCommon, binOptions.radiusCommon); } `, topology: 'point-list', - varyings: ['position'] + varyings: ['position'], + modules: [binOptionsUniforms] }); transform.model.setVertexCount(1); const outputBuffer = device.createBuffer({ @@ -99,7 +99,8 @@ test('getHexbinCentroid CPU vs GPU', t => { for (const d of TestData) { const bin = pointToHexbin(d.p, d.radius); - transform.model.setUniforms({binId: bin, radius: d.radius}); + const binOptions = {hexOriginCommon: bin, radiusCommon: d.radius}; + transform.model.shaderInputs.setProps({binOptions}); transform.run({discard: true}); const expected = getHexbinCentroid(bin, d.radius); const result = new Float32Array(outputBuffer.readSyncWebGL().buffer); From ba19a99d4bfb1ffa322ed21790a5d61b14445370 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 1 Oct 2024 11:52:48 +0200 Subject: [PATCH 02/11] Add testUniforms --- .../project/project-glsl-test-utils.ts | 43 +++++++++++++++++-- .../shaderlib/project/project-glsl.spec.ts | 26 ++++------- 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts index b3a6c3f4b97..682cc3454e3 100644 --- a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts +++ b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts @@ -2,8 +2,10 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import {equals, NumericArray} from '@math.gl/core'; +import {equals, NumericArray, NumberArray2, NumberArray3, NumberArray4} from '@math.gl/core'; import type {UniformValue} from '@luma.gl/core'; +import type {ShaderModule} from '@luma.gl/shadertools'; + import {BufferTransform, BufferTransformProps} from '@luma.gl/engine'; import {device} from '@deck.gl/test-utils'; @@ -13,6 +15,40 @@ export function getPixelOffset(p1, p2) { const OUT_BUFFER = device.createBuffer({byteLength: 4 * 16}); +// TODO move to separate file? +const uniformBlock = /* glsl */ `\ +uniform testUniforms { + vec4 uCommonPos; + vec3 uDirUp; + vec3 uInput; + vec3 uPos; + vec3 uPos64Low; + vec3 uWorldPos; +} test; +`; + +export type TestOptions = { + uCommonPos?: NumberArray4; + uDirUp?: NumberArray3; + uInput?: NumberArray3; + uPos?: NumberArray3; + uPos64Low?: NumberArray3; + uWorldPos?: NumberArray3; +}; + +export const testUniforms = { + name: 'test', + vs: uniformBlock, + uniformTypes: { + uCommonPos: 'vec4', + uDirUp: 'vec3', + uInput: 'vec3', + uPos: 'vec3', + uPos64Low: 'vec3', + uWorldPos: 'vec3' + } +} as const satisfies ShaderModule; + export async function runOnGPU({ shaderInputProps, uniforms, @@ -26,10 +62,11 @@ export async function runOnGPU({ const transform = new BufferTransform(device, { ...transformProps, feedbackBuffers: {[varying]: OUT_BUFFER}, - varyings: [varying] + varyings: [varying], + modules: [...transformProps.modules, testUniforms] }); transform.model.setUniforms(uniforms); - transform.model.shaderInputs.setProps(shaderInputProps); + transform.model.shaderInputs.setProps({...shaderInputProps, test: uniforms}); transform.run({ discard: true }); diff --git a/test/modules/core/shaderlib/project/project-glsl.spec.ts b/test/modules/core/shaderlib/project/project-glsl.spec.ts index 5c9b72bfa71..eb46709e54e 100644 --- a/test/modules/core/shaderlib/project/project-glsl.spec.ts +++ b/test/modules/core/shaderlib/project/project-glsl.spec.ts @@ -44,42 +44,36 @@ const TRANSFORM_VS = { project_size: (type: 'float' | 'vec2' | 'vec3') => `\ #version 300 es -uniform vec3 uWorldPos; -uniform vec4 uCommonPos; uniform ${type} uMeterSize; out ${type} outValue; void main() { - geometry.worldPosition = uWorldPos; - geometry.position = uCommonPos; + geometry.worldPosition = test.uWorldPos; + geometry.position = test.uCommonPos; outValue = project_size(uMeterSize); } `, project_position: `\ #version 300 es -uniform vec3 uPos; -uniform vec3 uPos64Low; - out vec4 outValue; void main() { - geometry.worldPosition = uPos; - outValue = project_position(vec4(uPos, 1.0), uPos64Low); + geometry.worldPosition = test.uPos; + outValue = project_position(vec4(test.uPos, 1.0), test.uPos64Low); } `, project_common_position_to_clipspace: `\ #version 300 es -uniform vec3 uPos; out vec3 outValue; void main() { - geometry.worldPosition = uPos; - vec4 pos = project_position(vec4(uPos, 1.0), vec3(0.)); + geometry.worldPosition = test.uPos; + vec4 pos = project_position(vec4(test.uPos, 1.0), vec3(0.)); vec4 glPos = project_common_position_to_clipspace(pos); outValue = glPos.xyz / glPos.w; outValue = vec3( @@ -319,7 +313,7 @@ const TEST_CASES: TestCase[] = [ } ]; -test('project#vs', async t => { +test.only('project#vs', async t => { const oldEpsilon = config.EPSILON; for (const testCase of TEST_CASES) { @@ -348,13 +342,11 @@ test('project#vs#project_get_orientation_matrix', async t => { const vs = `\ #version 300 es -uniform vec3 uDirUp; -uniform vec3 uInput; out vec3 outValue; void main() { - mat3 transform = project_get_orientation_matrix(uDirUp); - outValue = transform * uInput; + mat3 transform = project_get_orientation_matrix(test.uDirUp); + outValue = transform * test.uInput; } `; const shaderInputProps = { From 4573a22d3cbf8a1d95322da98ba3285638c76348 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 1 Oct 2024 12:02:03 +0200 Subject: [PATCH 03/11] Handled 1-3D meter sizes --- .../project/project-glsl-test-utils.ts | 9 +++++++ .../shaderlib/project/project-glsl.spec.ts | 24 +++++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts index 682cc3454e3..7d604f407c4 100644 --- a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts +++ b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts @@ -21,6 +21,9 @@ uniform testUniforms { vec4 uCommonPos; vec3 uDirUp; vec3 uInput; + float uMeterSize1; + vec2 uMeterSize2; + vec3 uMeterSize3; vec3 uPos; vec3 uPos64Low; vec3 uWorldPos; @@ -31,6 +34,9 @@ export type TestOptions = { uCommonPos?: NumberArray4; uDirUp?: NumberArray3; uInput?: NumberArray3; + uMeterSize1?: number; + uMeterSize2?: NumberArray2; + uMeterSize3?: NumberArray3; uPos?: NumberArray3; uPos64Low?: NumberArray3; uWorldPos?: NumberArray3; @@ -43,6 +49,9 @@ export const testUniforms = { uCommonPos: 'vec4', uDirUp: 'vec3', uInput: 'vec3', + uMeterSize1: 'f32', + uMeterSize2: 'vec2', + uMeterSize3: 'vec3', uPos: 'vec3', uPos64Low: 'vec3', uWorldPos: 'vec3' diff --git a/test/modules/core/shaderlib/project/project-glsl.spec.ts b/test/modules/core/shaderlib/project/project-glsl.spec.ts index eb46709e54e..c436c2a0690 100644 --- a/test/modules/core/shaderlib/project/project-glsl.spec.ts +++ b/test/modules/core/shaderlib/project/project-glsl.spec.ts @@ -9,8 +9,7 @@ import {Matrix4, Vector3, config, equals, NumericArray} from '@math.gl/core'; import {fp64} from '@luma.gl/shadertools'; const {fp64LowPart} = fp64; -import {getPixelOffset, runOnGPU, verifyGPUResult} from './project-glsl-test-utils'; -import {UniformValue} from '@luma.gl/shadertools/dist/lib/shader-module/shader-module'; +import {getPixelOffset, runOnGPU, TestOptions, verifyGPUResult} from './project-glsl-test-utils'; const PIXEL_TOLERANCE = 1e-4; const TEST_VIEWPORT = new WebMercatorViewport({ @@ -41,17 +40,16 @@ const TEST_VIEWPORT_ORTHO = new OrthographicViewport({ }); const TRANSFORM_VS = { - project_size: (type: 'float' | 'vec2' | 'vec3') => `\ + project_size: (dimension: 1 | 2 | 3) => `\ #version 300 es -uniform ${type} uMeterSize; -out ${type} outValue; +out ${dimension === 1 ? 'float' : `vec${dimension}`} outValue; void main() { geometry.worldPosition = test.uWorldPos; geometry.position = test.uCommonPos; - outValue = project_size(uMeterSize); + outValue = project_size(test.uMeterSize${dimension}); } `, project_position: `\ @@ -92,7 +90,7 @@ type TestCase = { name: string; vs: string; precision?: number; - input: Record; + input: TestOptions; output: any; }[]; }; @@ -106,31 +104,31 @@ const TEST_CASES: TestCase[] = [ tests: [ { name: 'project_size(float)', - vs: TRANSFORM_VS.project_size('float'), + vs: TRANSFORM_VS.project_size(1), input: { uWorldPos: [TEST_VIEWPORT.longitude, TEST_VIEWPORT.latitude, 0], uCommonPos: [0, 0, 0, 0], - uMeterSize: 1 + uMeterSize1: 1 }, output: TEST_VIEWPORT.getDistanceScales().unitsPerMeter[2] }, { name: 'project_size(vec2)', - vs: TRANSFORM_VS.project_size('vec2'), + vs: TRANSFORM_VS.project_size(2), input: { uWorldPos: [TEST_VIEWPORT.longitude, TEST_VIEWPORT.latitude, 0], uCommonPos: [0, 0, 0, 0], - uMeterSize: [1, 1] + uMeterSize2: [1, 1] }, output: TEST_VIEWPORT.getDistanceScales().unitsPerMeter.slice(0, 2) }, { name: 'project_size(vec3)', - vs: TRANSFORM_VS.project_size('vec3'), + vs: TRANSFORM_VS.project_size(3), input: { uWorldPos: [TEST_VIEWPORT.longitude, TEST_VIEWPORT.latitude, 0], uCommonPos: [0, 0, 0, 0], - uMeterSize: [1, 1, 1] + uMeterSize3: [1, 1, 1] }, output: TEST_VIEWPORT.getDistanceScales().unitsPerMeter }, From a4a957d8b67f3061cc6e1547ad757f20f5aad70c Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 1 Oct 2024 12:15:18 +0200 Subject: [PATCH 04/11] Types improve --- modules/core/src/index.ts | 2 +- modules/core/src/shaderlib/index.ts | 2 +- .../core/shaderlib/project/project-glsl-test-utils.ts | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/core/src/index.ts b/modules/core/src/index.ts index 72bdcb1a935..b76c565f2dd 100644 --- a/modules/core/src/index.ts +++ b/modules/core/src/index.ts @@ -125,7 +125,7 @@ export type {PickingInfo, GetPickingInfoParams} from './lib/picking/pick-info'; export type {ConstructorOf as _ConstructorOf} from './types/types'; export type {BinaryAttribute} from './lib/attribute/attribute'; export type {Effect, EffectContext, PreRenderOptions, PostRenderOptions} from './lib/effect'; -export type {PickingUniforms, ProjectUniforms} from './shaderlib/index'; +export type {PickingUniforms, ProjectProps, ProjectUniforms} from './shaderlib/index'; export type {DefaultProps} from './lifecycle/prop-types'; export type {LayersPassRenderOptions} from './passes/layers-pass'; export type {Widget, WidgetPlacement} from './lib/widget-manager'; diff --git a/modules/core/src/shaderlib/index.ts b/modules/core/src/shaderlib/index.ts index d1e3279cc80..85c7d67a2fc 100644 --- a/modules/core/src/shaderlib/index.ts +++ b/modules/core/src/shaderlib/index.ts @@ -37,7 +37,7 @@ export function getShaderAssembler() { export {layerUniforms, picking, project, project32, gouraudLighting, phongLighting, shadow}; // Useful for custom shader modules -export type {ProjectUniforms} from './project/viewport-uniforms'; +export type {ProjectProps, ProjectUniforms} from './project/viewport-uniforms'; // TODO - these should be imported from luma.gl /* eslint-disable camelcase */ diff --git a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts index 7d604f407c4..28929ba31f5 100644 --- a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts +++ b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts @@ -7,6 +7,7 @@ import type {UniformValue} from '@luma.gl/core'; import type {ShaderModule} from '@luma.gl/shadertools'; import {BufferTransform, BufferTransformProps} from '@luma.gl/engine'; +import {ProjectProps} from '@deck.gl/core'; import {device} from '@deck.gl/test-utils'; export function getPixelOffset(p1, p2) { @@ -30,7 +31,7 @@ uniform testUniforms { } test; `; -export type TestOptions = { +export type TestProps = { uCommonPos?: NumberArray4; uDirUp?: NumberArray3; uInput?: NumberArray3; @@ -56,7 +57,7 @@ export const testUniforms = { uPos64Low: 'vec3', uWorldPos: 'vec3' } -} as const satisfies ShaderModule; +} as const satisfies ShaderModule; export async function runOnGPU({ shaderInputProps, @@ -64,7 +65,9 @@ export async function runOnGPU({ varying, ...transformProps }: BufferTransformProps & { - shaderInputProps: Record>; + shaderInputProps: { + project: ProjectProps; + }; uniforms: Record; varying: string; }): Promise { @@ -74,7 +77,7 @@ export async function runOnGPU({ varyings: [varying], modules: [...transformProps.modules, testUniforms] }); - transform.model.setUniforms(uniforms); + transform.model.setUniforms(uniforms); // TODO delete transform.model.shaderInputs.setProps({...shaderInputProps, test: uniforms}); transform.run({ discard: true From 9f7837fa1fd532840f58d8e4b64cce8f899fbc9f Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 1 Oct 2024 12:19:15 +0200 Subject: [PATCH 05/11] Pass TestProps directly --- .../project/project-glsl-test-utils.ts | 3 +- .../shaderlib/project/project-glsl.spec.ts | 44 +++++++++++-------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts index 28929ba31f5..372b18b36e3 100644 --- a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts +++ b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts @@ -67,6 +67,7 @@ export async function runOnGPU({ }: BufferTransformProps & { shaderInputProps: { project: ProjectProps; + test: TestProps; }; uniforms: Record; varying: string; @@ -78,7 +79,7 @@ export async function runOnGPU({ modules: [...transformProps.modules, testUniforms] }); transform.model.setUniforms(uniforms); // TODO delete - transform.model.shaderInputs.setProps({...shaderInputProps, test: uniforms}); + transform.model.shaderInputs.setProps(shaderInputProps); transform.run({ discard: true }); diff --git a/test/modules/core/shaderlib/project/project-glsl.spec.ts b/test/modules/core/shaderlib/project/project-glsl.spec.ts index c436c2a0690..ad7c8d3639f 100644 --- a/test/modules/core/shaderlib/project/project-glsl.spec.ts +++ b/test/modules/core/shaderlib/project/project-glsl.spec.ts @@ -4,12 +4,18 @@ import test from 'tape-promise/tape'; -import {COORDINATE_SYSTEM, WebMercatorViewport, OrthographicViewport, project} from '@deck.gl/core'; -import {Matrix4, Vector3, config, equals, NumericArray} from '@math.gl/core'; +import { + COORDINATE_SYSTEM, + WebMercatorViewport, + OrthographicViewport, + project, + ProjectProps +} from '@deck.gl/core'; +import {Matrix4, Vector3, config, equals, NumericArray, NumberArray3} from '@math.gl/core'; import {fp64} from '@luma.gl/shadertools'; const {fp64LowPart} = fp64; -import {getPixelOffset, runOnGPU, TestOptions, verifyGPUResult} from './project-glsl-test-utils'; +import {getPixelOffset, runOnGPU, TestProps, verifyGPUResult} from './project-glsl-test-utils'; const PIXEL_TOLERANCE = 1e-4; const TEST_VIEWPORT = new WebMercatorViewport({ @@ -85,12 +91,12 @@ void main() type TestCase = { title: string; - params: Record; + params: ProjectProps; tests: { name: string; vs: string; precision?: number; - input: TestOptions; + input: TestProps; output: any; }[]; }; @@ -212,7 +218,7 @@ const TEST_CASES: TestCase[] = [ params: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS, - coordinateOrigin: [-122.05, 37.92], + coordinateOrigin: [-122.05, 37.92, 0], modelMatrix: new Matrix4().translate([0, 0, 100]) }, tests: [ @@ -248,7 +254,7 @@ const TEST_CASES: TestCase[] = [ params: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, - coordinateOrigin: [-122.05, 37.92] + coordinateOrigin: [-122.05, 37.92, 0] }, tests: [ { @@ -324,8 +330,11 @@ test.only('project#vs', async t => { varying: 'outValue', modules: [project], vertexCount: 1, - shaderInputProps: {project: testCase.params}, - uniforms: input + shaderInputProps: { + project: testCase.params, + test: input + }, + uniforms: {} }); t.is(verifyGPUResult(actual, output), true, name); @@ -347,21 +356,20 @@ void main() { outValue = transform * test.uInput; } `; - const shaderInputProps = { - project: { - viewport: TEST_VIEWPORT, - coordinateSystem: COORDINATE_SYSTEM.LNGLAT - } - }; - const runTransform = async (up: NumericArray, v: NumericArray): Promise => { const result = await runOnGPU({ vs, varying: 'outValue', modules: [project], vertexCount: 1, - shaderInputProps, - uniforms: {uDirUp: up, uInput: v} + shaderInputProps: { + project: { + viewport: TEST_VIEWPORT, + coordinateSystem: COORDINATE_SYSTEM.LNGLAT + }, + test: {uDirUp: up as NumberArray3, uInput: v as NumberArray3} + }, + uniforms: {} }); return new Vector3(result.slice(0, 3)); }; From 6995878b5df4ed72a4311f4ee4d655894a11864a Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 1 Oct 2024 12:22:10 +0200 Subject: [PATCH 06/11] Tidy --- .../shaderlib/project/project-glsl-test-utils.ts | 10 ++-------- .../core/shaderlib/project/project-glsl.spec.ts | 12 +++++++++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts index 372b18b36e3..97da612d85b 100644 --- a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts +++ b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts @@ -61,7 +61,6 @@ export const testUniforms = { export async function runOnGPU({ shaderInputProps, - uniforms, varying, ...transformProps }: BufferTransformProps & { @@ -69,20 +68,15 @@ export async function runOnGPU({ project: ProjectProps; test: TestProps; }; - uniforms: Record; varying: string; }): Promise { const transform = new BufferTransform(device, { ...transformProps, feedbackBuffers: {[varying]: OUT_BUFFER}, - varyings: [varying], - modules: [...transformProps.modules, testUniforms] + varyings: [varying] }); - transform.model.setUniforms(uniforms); // TODO delete transform.model.shaderInputs.setProps(shaderInputProps); - transform.run({ - discard: true - }); + transform.run({discard: true}); const result: Uint8Array = await OUT_BUFFER.readAsync(); return new Float32Array(result.buffer); diff --git a/test/modules/core/shaderlib/project/project-glsl.spec.ts b/test/modules/core/shaderlib/project/project-glsl.spec.ts index ad7c8d3639f..fc5e86ed4be 100644 --- a/test/modules/core/shaderlib/project/project-glsl.spec.ts +++ b/test/modules/core/shaderlib/project/project-glsl.spec.ts @@ -15,7 +15,13 @@ import {Matrix4, Vector3, config, equals, NumericArray, NumberArray3} from '@mat import {fp64} from '@luma.gl/shadertools'; const {fp64LowPart} = fp64; -import {getPixelOffset, runOnGPU, TestProps, verifyGPUResult} from './project-glsl-test-utils'; +import { + getPixelOffset, + runOnGPU, + TestProps, + testUniforms, + verifyGPUResult +} from './project-glsl-test-utils'; const PIXEL_TOLERANCE = 1e-4; const TEST_VIEWPORT = new WebMercatorViewport({ @@ -328,7 +334,7 @@ test.only('project#vs', async t => { let actual: NumericArray = await runOnGPU({ vs, varying: 'outValue', - modules: [project], + modules: [project, testUniforms], vertexCount: 1, shaderInputProps: { project: testCase.params, @@ -360,7 +366,7 @@ void main() { const result = await runOnGPU({ vs, varying: 'outValue', - modules: [project], + modules: [project, testUniforms], vertexCount: 1, shaderInputProps: { project: { From 06502e7680206fe8ce69e4832991e82c040ed364 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 1 Oct 2024 12:32:25 +0200 Subject: [PATCH 07/11] Start on 64 bit tests --- .../project/project-32-64-glsl.spec.ts | 52 +++++++++---------- .../shaderlib/project/project-glsl.spec.ts | 4 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts b/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts index ce07f222ade..33aa341f46f 100644 --- a/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts +++ b/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts @@ -8,10 +8,11 @@ import test from 'tape-promise/tape'; import {COORDINATE_SYSTEM, WebMercatorViewport, project, project32} from '@deck.gl/core'; import {project64} from '@deck.gl/extensions'; // import {Matrix4, config} from '@math.gl/core'; -import {config} from '@math.gl/core'; +import {config, NumberArray3} from '@math.gl/core'; import {fp64} from '@luma.gl/shadertools'; const {fp64LowPart} = fp64; -import {getPixelOffset, runOnGPU, verifyGPUResult} from './project-glsl-test-utils'; +import {getPixelOffset, runOnGPU, testUniforms, verifyGPUResult} from './project-glsl-test-utils'; +import {TestCase} from './project-glsl.spec'; const PIXEL_TOLERANCE = 0.001; @@ -39,14 +40,12 @@ const TRANSFORM_VS = { project_position_to_clipspace: `\ #version 300 es -uniform vec3 uPos; -uniform vec3 uPos64Low; out vec3 outValue; void main() { - geometry.worldPosition = uPos; - vec4 glPos = project_position_to_clipspace(uPos, uPos64Low, vec3(0, 0, 0)); + geometry.worldPosition = test.uPos; + vec4 glPos = project_position_to_clipspace(test.uPos, test.uPos64Low, vec3(0, 0, 0)); outValue = glPos.xyz / glPos.w; outValue = vec3( (1.0 + outValue.x) / 2.0 * project.viewportSize.x, @@ -58,19 +57,17 @@ void main() project_position_to_clipspace_world_position: `\ #version 300 es -uniform vec3 uPos; -uniform vec3 uPos64Low; out vec4 outValue; void main() { - geometry.worldPosition = uPos; - project_position_to_clipspace(uPos, uPos64Low, vec3(0, 0, 0), outValue); + geometry.worldPosition = test.uPos; + project_position_to_clipspace(test.uPos, test.uPos64Low, vec3(0, 0, 0), outValue); } ` }; -const TEST_CASES = [ +const TEST_CASES: TestCase[] = [ { title: 'LNGLAT mode', params: { @@ -81,20 +78,20 @@ const TEST_CASES = [ { name: 'project_position_to_clipspace_world_position', vs: TRANSFORM_VS.project_position_to_clipspace_world_position, - input: [-122.45, 37.78, 0], + input: {uPos: [-122.45, 37.78, 0]}, output: TEST_VIEWPORT.projectFlat([-122.45, 37.78]).concat([0, 1]) }, { name: 'project_position_to_clipspace', vs: TRANSFORM_VS.project_position_to_clipspace, - input: [-122.45, 37.78, 0], + input: {uPos: [-122.45, 37.78, 0]}, output: TEST_VIEWPORT.project([-122.45, 37.78, 0]), precision: PIXEL_TOLERANCE }, { name: 'project_position_to_clipspace (non-zero Z)', vs: TRANSFORM_VS.project_position_to_clipspace, - input: [-122.45, 37.78, 100], + input: {uPos: [-122.45, 37.78, 100]}, output: TEST_VIEWPORT.project([-122.45, 37.78, 100]), precision: PIXEL_TOLERANCE } @@ -110,7 +107,7 @@ const TEST_CASES = [ { name: 'project_position_to_clipspace_world_position', vs: TRANSFORM_VS.project_position_to_clipspace_world_position, - input: [-122.05, 37.92, 0], + input: {uPos: [-122.05, 37.92, 0]}, output: TEST_VIEWPORT_HIGH_ZOOM.projectFlat([-122.05, 37.92]) .map((x, i) => x - TEST_VIEWPORT_HIGH_ZOOM.center[i]) .concat([0, 1]), @@ -119,7 +116,7 @@ const TEST_CASES = [ { name: 'project_position_to_clipspace', vs: TRANSFORM_VS.project_position_to_clipspace, - input: [-122.05, 37.92, 0], + input: {uPos: [-122.05, 37.92, 0]}, output: TEST_VIEWPORT_HIGH_ZOOM.project([-122.05, 37.92, 0]), precision: PIXEL_TOLERANCE } @@ -136,7 +133,7 @@ const TEST_CASES = [ { name: 'project_position_to_clipspace_world_position', vs: TRANSFORM_VS.project_position_to_clipspace_world_position, - input: [0.05, 0.08, 0], + input: {uPos: [0.05, 0.08, 0]}, output: getPixelOffset( TEST_VIEWPORT.projectPosition([-122, 38, 0]), TEST_VIEWPORT.projectPosition([-122.05, 37.92, 0]) @@ -145,7 +142,7 @@ const TEST_CASES = [ { name: 'project_position_to_clipspace', vs: TRANSFORM_VS.project_position_to_clipspace, - input: [0.05, 0.08, 0], + input: {uPos: [0.05, 0.08, 0]}, output: TEST_VIEWPORT.project([-122, 38, 0]), precision: PIXEL_TOLERANCE } @@ -153,7 +150,7 @@ const TEST_CASES = [ } ]; -test('project32&64#vs', async t => { +test.only('project32&64#vs', async t => { const oldEpsilon = config.EPSILON; for (const usefp64 of [false, true]) { @@ -176,15 +173,18 @@ test('project32&64#vs', async t => { const expected = (usefp64 && c.output64) || c.output; const actual = await runOnGPU({ vs: c.vs, - modules: usefp64 ? [project64] : [project32], + modules: usefp64 ? [project64, testUniforms] : [project32, testUniforms], varying: 'outValue', vertexCount: 1, - shaderInputProps: {project: testCase.params, project64: testCase.params}, - uniforms: { - ...uniforms, - uPos: c.input, - uPos64Low: c.input.map(fp64LowPart) - } + shaderInputProps: { + project: testCase.params, + project64: testCase.params, + test: { + uPos: c.input.uPos!, + uPos64Low: c.input.uPos!.map(fp64LowPart) as NumberArray3 + } + }, + uniforms }); config.EPSILON = c.precision ?? 1e-5; diff --git a/test/modules/core/shaderlib/project/project-glsl.spec.ts b/test/modules/core/shaderlib/project/project-glsl.spec.ts index fc5e86ed4be..90ff3b78a61 100644 --- a/test/modules/core/shaderlib/project/project-glsl.spec.ts +++ b/test/modules/core/shaderlib/project/project-glsl.spec.ts @@ -95,7 +95,7 @@ void main() ` }; -type TestCase = { +export type TestCase = { title: string; params: ProjectProps; tests: { @@ -323,7 +323,7 @@ const TEST_CASES: TestCase[] = [ } ]; -test.only('project#vs', async t => { +test('project#vs', async t => { const oldEpsilon = config.EPSILON; for (const testCase of TEST_CASES) { From e29256cf2a544c47977b7218b70036929cf63aba Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 1 Oct 2024 12:39:42 +0200 Subject: [PATCH 08/11] Tidy --- .../core/shaderlib/project/project-32-64-glsl.spec.ts | 7 ++++--- .../core/shaderlib/project/project-glsl-test-utils.ts | 1 + test/modules/core/shaderlib/project/project-glsl.spec.ts | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts b/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts index 33aa341f46f..e8195cad91d 100644 --- a/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts +++ b/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts @@ -5,7 +5,7 @@ import test from 'tape-promise/tape'; // import {COORDINATE_SYSTEM, Viewport, WebMercatorViewport} from 'deck.gl'; -import {COORDINATE_SYSTEM, WebMercatorViewport, project, project32} from '@deck.gl/core'; +import {COORDINATE_SYSTEM, WebMercatorViewport, project32} from '@deck.gl/core'; import {project64} from '@deck.gl/extensions'; // import {Matrix4, config} from '@math.gl/core'; import {config, NumberArray3} from '@math.gl/core'; @@ -127,7 +127,7 @@ const TEST_CASES: TestCase[] = [ params: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, - coordinateOrigin: [-122.05, 37.92] + coordinateOrigin: [-122.05, 37.92, 0] }, tests: [ { @@ -166,7 +166,8 @@ test.only('project32&64#vs', async t => { let uniforms = {}; if (usefp64) { // fp64arithmetic uniform - uniforms = {...uniforms, ONE: 1.0}; + // TODO remove when https://github.com/visgl/luma.gl/pull/2262 landed + uniforms = {ONE: 1.0}; } for (const c of testCase.tests) { diff --git a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts index 97da612d85b..cd7965d9829 100644 --- a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts +++ b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts @@ -66,6 +66,7 @@ export async function runOnGPU({ }: BufferTransformProps & { shaderInputProps: { project: ProjectProps; + project64?: ProjectProps; test: TestProps; }; varying: string; diff --git a/test/modules/core/shaderlib/project/project-glsl.spec.ts b/test/modules/core/shaderlib/project/project-glsl.spec.ts index 90ff3b78a61..82964a0f84f 100644 --- a/test/modules/core/shaderlib/project/project-glsl.spec.ts +++ b/test/modules/core/shaderlib/project/project-glsl.spec.ts @@ -104,6 +104,7 @@ export type TestCase = { precision?: number; input: TestProps; output: any; + output64?: any; }[]; }; const TEST_CASES: TestCase[] = [ From b8342124b207488e7844a4fa43d51dbf69643491 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 1 Oct 2024 12:48:10 +0200 Subject: [PATCH 09/11] Functions --- .../project/project-32-64-glsl.spec.ts | 2 +- .../project/project-functions.spec.ts | 43 +++++++++++-------- .../shaderlib/project/project-glsl.spec.ts | 6 +-- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts b/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts index e8195cad91d..ceffc8084fd 100644 --- a/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts +++ b/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts @@ -150,7 +150,7 @@ const TEST_CASES: TestCase[] = [ } ]; -test.only('project32&64#vs', async t => { +test('project32&64#vs', async t => { const oldEpsilon = config.EPSILON; for (const usefp64 of [false, true]) { diff --git a/test/modules/core/shaderlib/project/project-functions.spec.ts b/test/modules/core/shaderlib/project/project-functions.spec.ts index 19a79fc9512..3c1dd033bcd 100644 --- a/test/modules/core/shaderlib/project/project-functions.spec.ts +++ b/test/modules/core/shaderlib/project/project-functions.spec.ts @@ -4,12 +4,18 @@ import test from 'tape-promise/tape'; -import {COORDINATE_SYSTEM, WebMercatorViewport, OrthographicViewport, project} from '@deck.gl/core'; +import { + COORDINATE_SYSTEM, + WebMercatorViewport, + OrthographicViewport, + project, + ProjectProps +} from '@deck.gl/core'; import {fp64} from '@luma.gl/shadertools'; const {fp64LowPart} = fp64; import {projectPosition} from '@deck.gl/core/shaderlib/project/project-functions'; -import {equals, config} from '@math.gl/core'; -import {runOnGPU, verifyGPUResult} from './project-glsl-test-utils'; +import {equals, config, NumberArray3} from '@math.gl/core'; +import {runOnGPU, TestProps, testUniforms, verifyGPUResult} from './project-glsl-test-utils'; const TEST_VIEWPORT = new WebMercatorViewport({ longitude: -122.45, @@ -21,9 +27,15 @@ const TEST_VIEWPORT_2 = new WebMercatorViewport({ latitude: 40.7, zoom: 8 }); -const TEST_COORDINATE_ORIGIN = [-122.45, 37.78, 0]; +const TEST_COORDINATE_ORIGIN: NumberArray3 = [-122.45, 37.78, 0]; -const TEST_CASES = [ +export type TestCase = { + title: string; + position: NumberArray3; + params: ProjectProps & {fromCoordinateSystem: number}; + result: NumberArray3; +}; +const TEST_CASES: TestCase[] = [ { title: 'LNGLAT:WEB_MERCATOR', position: [-70, 41, 1000], @@ -133,21 +145,18 @@ test('project#projectPosition', t => { t.end(); }); -test('project#projectPosition vs project_position', async t => { +test.only('project#projectPosition vs project_position', async t => { config.EPSILON = 1e-5; const vs = `\ #version 300 es -uniform vec3 uPos; -uniform vec3 uPos64Low; - out vec4 outValue; void main() { - geometry.worldPosition = uPos; - outValue = project_position(vec4(uPos, 1.0), uPos64Low); + geometry.worldPosition = test.uPos; + outValue = project_position(vec4(test.uPos, 1.0), test.uPos64Low); } `; @@ -155,16 +164,16 @@ void main() testCase => !testCase.params.fromCoordinateSystem )) { const cpuResult = projectPosition(position, params); + const testProps: TestProps = { + uPos: position, + uPos64Low: position.map(fp64LowPart) as NumberArray3 + }; const shaderResult = await runOnGPU({ vs, varying: 'outValue', - modules: [project], + modules: [project, testUniforms], vertexCount: 1, - shaderInputProps: {project: params}, - uniforms: { - uPos: position, - uPos64Low: position.map(fp64LowPart) - } + shaderInputProps: {project: params, test: testProps} }); t.is(verifyGPUResult(shaderResult, cpuResult), true, title); diff --git a/test/modules/core/shaderlib/project/project-glsl.spec.ts b/test/modules/core/shaderlib/project/project-glsl.spec.ts index 82964a0f84f..d6c6075795b 100644 --- a/test/modules/core/shaderlib/project/project-glsl.spec.ts +++ b/test/modules/core/shaderlib/project/project-glsl.spec.ts @@ -340,8 +340,7 @@ test('project#vs', async t => { shaderInputProps: { project: testCase.params, test: input - }, - uniforms: {} + } }); t.is(verifyGPUResult(actual, output), true, name); @@ -375,8 +374,7 @@ void main() { coordinateSystem: COORDINATE_SYSTEM.LNGLAT }, test: {uDirUp: up as NumberArray3, uInput: v as NumberArray3} - }, - uniforms: {} + } }); return new Vector3(result.slice(0, 3)); }; From 6b283e6c48b96b6522a6f1b7264879be9ea17ca4 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 1 Oct 2024 12:52:03 +0200 Subject: [PATCH 10/11] Rename --- .../project/project-32-64-glsl.spec.ts | 30 +++++------ .../project/project-functions.spec.ts | 32 ++++++------ .../shaderlib/project/project-glsl.spec.ts | 50 +++++++++---------- 3 files changed, 56 insertions(+), 56 deletions(-) diff --git a/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts b/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts index ceffc8084fd..5b4ad765cf5 100644 --- a/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts +++ b/test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts @@ -70,7 +70,7 @@ void main() const TEST_CASES: TestCase[] = [ { title: 'LNGLAT mode', - params: { + projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.LNGLAT }, @@ -78,20 +78,20 @@ const TEST_CASES: TestCase[] = [ { name: 'project_position_to_clipspace_world_position', vs: TRANSFORM_VS.project_position_to_clipspace_world_position, - input: {uPos: [-122.45, 37.78, 0]}, + testProps: {uPos: [-122.45, 37.78, 0]}, output: TEST_VIEWPORT.projectFlat([-122.45, 37.78]).concat([0, 1]) }, { name: 'project_position_to_clipspace', vs: TRANSFORM_VS.project_position_to_clipspace, - input: {uPos: [-122.45, 37.78, 0]}, + testProps: {uPos: [-122.45, 37.78, 0]}, output: TEST_VIEWPORT.project([-122.45, 37.78, 0]), precision: PIXEL_TOLERANCE }, { name: 'project_position_to_clipspace (non-zero Z)', vs: TRANSFORM_VS.project_position_to_clipspace, - input: {uPos: [-122.45, 37.78, 100]}, + testProps: {uPos: [-122.45, 37.78, 100]}, output: TEST_VIEWPORT.project([-122.45, 37.78, 100]), precision: PIXEL_TOLERANCE } @@ -99,7 +99,7 @@ const TEST_CASES: TestCase[] = [ }, { title: 'LNGLAT mode - high zoom', - params: { + projectProps: { viewport: TEST_VIEWPORT_HIGH_ZOOM, coordinateSystem: COORDINATE_SYSTEM.LNGLAT }, @@ -107,7 +107,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_position_to_clipspace_world_position', vs: TRANSFORM_VS.project_position_to_clipspace_world_position, - input: {uPos: [-122.05, 37.92, 0]}, + testProps: {uPos: [-122.05, 37.92, 0]}, output: TEST_VIEWPORT_HIGH_ZOOM.projectFlat([-122.05, 37.92]) .map((x, i) => x - TEST_VIEWPORT_HIGH_ZOOM.center[i]) .concat([0, 1]), @@ -116,7 +116,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_position_to_clipspace', vs: TRANSFORM_VS.project_position_to_clipspace, - input: {uPos: [-122.05, 37.92, 0]}, + testProps: {uPos: [-122.05, 37.92, 0]}, output: TEST_VIEWPORT_HIGH_ZOOM.project([-122.05, 37.92, 0]), precision: PIXEL_TOLERANCE } @@ -124,7 +124,7 @@ const TEST_CASES: TestCase[] = [ }, { title: 'LNGLAT_OFFSETS mode', - params: { + projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, coordinateOrigin: [-122.05, 37.92, 0] @@ -133,7 +133,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_position_to_clipspace_world_position', vs: TRANSFORM_VS.project_position_to_clipspace_world_position, - input: {uPos: [0.05, 0.08, 0]}, + testProps: {uPos: [0.05, 0.08, 0]}, output: getPixelOffset( TEST_VIEWPORT.projectPosition([-122, 38, 0]), TEST_VIEWPORT.projectPosition([-122.05, 37.92, 0]) @@ -142,7 +142,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_position_to_clipspace', vs: TRANSFORM_VS.project_position_to_clipspace, - input: {uPos: [0.05, 0.08, 0]}, + testProps: {uPos: [0.05, 0.08, 0]}, output: TEST_VIEWPORT.project([-122, 38, 0]), precision: PIXEL_TOLERANCE } @@ -156,7 +156,7 @@ test('project32&64#vs', async t => { for (const usefp64 of [false, true]) { /* eslint-disable max-nested-callbacks, complexity */ for (const testCase of TEST_CASES) { - if (usefp64 && testCase.params.coordinateSystem !== COORDINATE_SYSTEM.LNGLAT) { + if (usefp64 && testCase.projectProps.coordinateSystem !== COORDINATE_SYSTEM.LNGLAT) { // Apply 64 bit projection only for LNGLAT_DEPRECATED return; } @@ -178,11 +178,11 @@ test('project32&64#vs', async t => { varying: 'outValue', vertexCount: 1, shaderInputProps: { - project: testCase.params, - project64: testCase.params, + project: testCase.projectProps, + project64: testCase.projectProps, test: { - uPos: c.input.uPos!, - uPos64Low: c.input.uPos!.map(fp64LowPart) as NumberArray3 + uPos: c.testProps.uPos!, + uPos64Low: c.testProps.uPos!.map(fp64LowPart) as NumberArray3 } }, uniforms diff --git a/test/modules/core/shaderlib/project/project-functions.spec.ts b/test/modules/core/shaderlib/project/project-functions.spec.ts index 3c1dd033bcd..594ffaa5dc5 100644 --- a/test/modules/core/shaderlib/project/project-functions.spec.ts +++ b/test/modules/core/shaderlib/project/project-functions.spec.ts @@ -32,14 +32,14 @@ const TEST_COORDINATE_ORIGIN: NumberArray3 = [-122.45, 37.78, 0]; export type TestCase = { title: string; position: NumberArray3; - params: ProjectProps & {fromCoordinateSystem: number}; + projectProps: ProjectProps & {fromCoordinateSystem: number}; result: NumberArray3; }; const TEST_CASES: TestCase[] = [ { title: 'LNGLAT:WEB_MERCATOR', position: [-70, 41, 1000], - params: { + projectProps: { viewport: TEST_VIEWPORT_2, coordinateSystem: COORDINATE_SYSTEM.DEFAULT }, @@ -48,7 +48,7 @@ const TEST_CASES: TestCase[] = [ { title: 'LNGLAT:WEB_MERCATOR_AUTO_OFFSET', position: [-122.46, 37.8, 1000], - params: { + projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.DEFAULT }, @@ -57,7 +57,7 @@ const TEST_CASES: TestCase[] = [ { title: 'CARTESIAN:IDENTITY', position: [-10, 10, 10], - params: { + projectProps: { viewport: new OrthographicViewport({ width: 1, height: 1, @@ -71,7 +71,7 @@ const TEST_CASES: TestCase[] = [ { title: 'CARTESIAN:WEB_MERCATOR', position: [256, 256, 0], - params: { + projectProps: { viewport: TEST_VIEWPORT_2, coordinateSystem: COORDINATE_SYSTEM.CARTESIAN, coordinateOrigin: [0, 0, 0] @@ -81,7 +81,7 @@ const TEST_CASES: TestCase[] = [ { title: 'CARTESIAN:WEB_MERCATOR_AUTO_OFFSET', position: [0, 0, 0], - params: { + projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.CARTESIAN, coordinateOrigin: [256, 256, 0] @@ -91,7 +91,7 @@ const TEST_CASES: TestCase[] = [ { title: 'LNGLAT_OFFSETS', position: [-0.05, 0.06, 50], - params: { + projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, coordinateOrigin: [-122.5, 38.8] @@ -101,7 +101,7 @@ const TEST_CASES: TestCase[] = [ { title: 'METER_OFFSETS', position: [-100, 300, 50], - params: { + projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS, coordinateOrigin: [-122.5, 38.8] @@ -111,7 +111,7 @@ const TEST_CASES: TestCase[] = [ { title: 'LNGLAT to METER_OFFSETS', position: [-122.46, 37.8, 1000], - params: { + projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS, coordinateOrigin: TEST_COORDINATE_ORIGIN, @@ -122,7 +122,7 @@ const TEST_CASES: TestCase[] = [ { title: 'LNGLAT to LNGLAT_OFFSETS', position: [-122.46, 37.8, 1000], - params: { + projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, coordinateOrigin: TEST_COORDINATE_ORIGIN, @@ -136,7 +136,7 @@ test('project#projectPosition', t => { config.EPSILON = 1e-7; TEST_CASES.forEach(testCase => { - const result = projectPosition(testCase.position, testCase.params); + const result = projectPosition(testCase.position, testCase.projectProps); t.comment(result); t.comment(testCase.result); t.ok(equals(result, testCase.result), testCase.title); @@ -145,7 +145,7 @@ test('project#projectPosition', t => { t.end(); }); -test.only('project#projectPosition vs project_position', async t => { +test('project#projectPosition vs project_position', async t => { config.EPSILON = 1e-5; const vs = `\ @@ -160,10 +160,10 @@ void main() } `; - for (const {title, position, params} of TEST_CASES.filter( - testCase => !testCase.params.fromCoordinateSystem + for (const {title, position, projectProps} of TEST_CASES.filter( + testCase => !testCase.projectProps.fromCoordinateSystem )) { - const cpuResult = projectPosition(position, params); + const cpuResult = projectPosition(position, projectProps); const testProps: TestProps = { uPos: position, uPos64Low: position.map(fp64LowPart) as NumberArray3 @@ -173,7 +173,7 @@ void main() varying: 'outValue', modules: [project, testUniforms], vertexCount: 1, - shaderInputProps: {project: params, test: testProps} + shaderInputProps: {project: projectProps, test: testProps} }); t.is(verifyGPUResult(shaderResult, cpuResult), true, title); diff --git a/test/modules/core/shaderlib/project/project-glsl.spec.ts b/test/modules/core/shaderlib/project/project-glsl.spec.ts index d6c6075795b..936b22db12b 100644 --- a/test/modules/core/shaderlib/project/project-glsl.spec.ts +++ b/test/modules/core/shaderlib/project/project-glsl.spec.ts @@ -97,12 +97,12 @@ void main() export type TestCase = { title: string; - params: ProjectProps; + projectProps: ProjectProps; tests: { name: string; vs: string; precision?: number; - input: TestProps; + testProps: TestProps; output: any; output64?: any; }[]; @@ -110,7 +110,7 @@ export type TestCase = { const TEST_CASES: TestCase[] = [ { title: 'LNGLAT mode', - params: { + projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.LNGLAT }, @@ -118,7 +118,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_size(float)', vs: TRANSFORM_VS.project_size(1), - input: { + testProps: { uWorldPos: [TEST_VIEWPORT.longitude, TEST_VIEWPORT.latitude, 0], uCommonPos: [0, 0, 0, 0], uMeterSize1: 1 @@ -128,7 +128,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_size(vec2)', vs: TRANSFORM_VS.project_size(2), - input: { + testProps: { uWorldPos: [TEST_VIEWPORT.longitude, TEST_VIEWPORT.latitude, 0], uCommonPos: [0, 0, 0, 0], uMeterSize2: [1, 1] @@ -138,7 +138,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_size(vec3)', vs: TRANSFORM_VS.project_size(3), - input: { + testProps: { uWorldPos: [TEST_VIEWPORT.longitude, TEST_VIEWPORT.latitude, 0], uCommonPos: [0, 0, 0, 0], uMeterSize3: [1, 1, 1] @@ -148,7 +148,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_position', vs: TRANSFORM_VS.project_position, - input: { + testProps: { uPos: [-122.45, 37.78, 0], uPos64Low: [fp64LowPart(-122.45), fp64LowPart(37.78), 0] }, @@ -158,7 +158,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_common_position_to_clipspace(vec4)', vs: TRANSFORM_VS.project_common_position_to_clipspace, - input: { + testProps: { uPos: [-122.45, 37.78, 0] }, output: TEST_VIEWPORT.project([-122.45, 37.78, 0]), @@ -167,7 +167,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_common_position_to_clipspace (vec4, non-zero z)', vs: TRANSFORM_VS.project_common_position_to_clipspace, - input: { + testProps: { uPos: [-122.45, 37.78, 100] }, output: TEST_VIEWPORT.project([-122.45, 37.78, 100]), @@ -177,7 +177,7 @@ const TEST_CASES: TestCase[] = [ }, { title: 'LNGLAT mode - auto offset', - params: { + projectProps: { viewport: TEST_VIEWPORT_HIGH_ZOOM, coordinateSystem: COORDINATE_SYSTEM.LNGLAT }, @@ -185,7 +185,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_position', vs: TRANSFORM_VS.project_position, - input: { + testProps: { uPos: [-122.05, 37.92, 0], uPos64Low: [0, 0, 0] }, @@ -203,7 +203,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_common_position_to_clipspace(vec4)', vs: TRANSFORM_VS.project_common_position_to_clipspace, - input: { + testProps: { uPos: [-122.05, 37.92, 0] }, output: TEST_VIEWPORT_HIGH_ZOOM.project([-122.05, 37.92, 0]), @@ -212,7 +212,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_common_position_to_clipspace (vec4, non-zero z)', vs: TRANSFORM_VS.project_common_position_to_clipspace, - input: { + testProps: { uPos: [-122.05, 37.92, 100] }, output: TEST_VIEWPORT_HIGH_ZOOM.project([-122.05, 37.92, 100]), @@ -222,7 +222,7 @@ const TEST_CASES: TestCase[] = [ }, { title: 'METER_OFFSETS mode', - params: { + projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS, coordinateOrigin: [-122.05, 37.92, 0], @@ -232,7 +232,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_position', vs: TRANSFORM_VS.project_position, - input: { + testProps: { uPos: [1000, 1000, 0], uPos64Low: [0, 0, 0] }, @@ -248,7 +248,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_common_position_to_clipspace(vec4)', vs: TRANSFORM_VS.project_common_position_to_clipspace, - input: { + testProps: { uPos: [1000, 1000, 0] }, output: TEST_VIEWPORT.project([-122.0385984916185, 37.92899265369385, 100]), @@ -258,7 +258,7 @@ const TEST_CASES: TestCase[] = [ }, { title: 'LNGLAT_OFFSETS mode', - params: { + projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, coordinateOrigin: [-122.05, 37.92, 0] @@ -267,7 +267,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_position', vs: TRANSFORM_VS.project_position, - input: { + testProps: { uPos: [0.05, 0.08, 0], uPos64Low: [0, 0, 0] }, @@ -281,7 +281,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_common_position_to_clipspace(vec4)', vs: TRANSFORM_VS.project_common_position_to_clipspace, - input: { + testProps: { uPos: [0.05, 0.08, 0] }, output: TEST_VIEWPORT.project([-122, 38, 0]), @@ -291,7 +291,7 @@ const TEST_CASES: TestCase[] = [ }, { title: 'IDENTITY mode with modelMatrix', - params: { + projectProps: { viewport: TEST_VIEWPORT_ORTHO, coordinateSystem: COORDINATE_SYSTEM.CARTESIAN, modelMatrix: new Matrix4().rotateZ(Math.PI / 2).translate([0, 0, 10]) @@ -300,7 +300,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_position', vs: TRANSFORM_VS.project_position, - input: { + testProps: { uPos: [200, 200, 0], uPos64Low: [0, 0, 0] }, @@ -314,7 +314,7 @@ const TEST_CASES: TestCase[] = [ { name: 'project_common_position_to_clipspace(vec4)', vs: TRANSFORM_VS.project_common_position_to_clipspace, - input: { + testProps: { uPos: [200, 200, 0] }, output: TEST_VIEWPORT_ORTHO.project([-200, 200, 10]), @@ -330,7 +330,7 @@ test('project#vs', async t => { for (const testCase of TEST_CASES) { t.comment(testCase.title); - for (const {name, vs, input, output, precision = 1e-7} of testCase.tests) { + for (const {name, vs, testProps, output, precision = 1e-7} of testCase.tests) { config.EPSILON = precision; let actual: NumericArray = await runOnGPU({ vs, @@ -338,8 +338,8 @@ test('project#vs', async t => { modules: [project, testUniforms], vertexCount: 1, shaderInputProps: { - project: testCase.params, - test: input + project: testCase.projectProps, + test: testProps } }); From ac2330260449d924202c61e5cf61d6c6edaf6e88 Mon Sep 17 00:00:00 2001 From: Felix Palmer Date: Tue, 1 Oct 2024 12:53:36 +0200 Subject: [PATCH 11/11] Tidy --- .../core/shaderlib/project/project-functions.spec.ts | 6 +++--- .../core/shaderlib/project/project-glsl-test-utils.ts | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/test/modules/core/shaderlib/project/project-functions.spec.ts b/test/modules/core/shaderlib/project/project-functions.spec.ts index 594ffaa5dc5..ce8fc43536f 100644 --- a/test/modules/core/shaderlib/project/project-functions.spec.ts +++ b/test/modules/core/shaderlib/project/project-functions.spec.ts @@ -32,7 +32,7 @@ const TEST_COORDINATE_ORIGIN: NumberArray3 = [-122.45, 37.78, 0]; export type TestCase = { title: string; position: NumberArray3; - projectProps: ProjectProps & {fromCoordinateSystem: number}; + projectProps: ProjectProps & {fromCoordinateSystem?: number}; result: NumberArray3; }; const TEST_CASES: TestCase[] = [ @@ -94,7 +94,7 @@ const TEST_CASES: TestCase[] = [ projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, - coordinateOrigin: [-122.5, 38.8] + coordinateOrigin: [-122.5, 38.8, 0] }, result: [-0.07111111111110802, 0.10954078583623073, 0.0008212863345433337] }, @@ -104,7 +104,7 @@ const TEST_CASES: TestCase[] = [ projectProps: { viewport: TEST_VIEWPORT, coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS, - coordinateOrigin: [-122.5, 38.8] + coordinateOrigin: [-122.5, 38.8, 0] }, result: [-0.0016412509100689476, 0.00492356632304336, 0.0008206254565218747] }, diff --git a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts index cd7965d9829..28d574dd289 100644 --- a/test/modules/core/shaderlib/project/project-glsl-test-utils.ts +++ b/test/modules/core/shaderlib/project/project-glsl-test-utils.ts @@ -3,7 +3,6 @@ // Copyright (c) vis.gl contributors import {equals, NumericArray, NumberArray2, NumberArray3, NumberArray4} from '@math.gl/core'; -import type {UniformValue} from '@luma.gl/core'; import type {ShaderModule} from '@luma.gl/shadertools'; import {BufferTransform, BufferTransformProps} from '@luma.gl/engine'; @@ -16,7 +15,6 @@ export function getPixelOffset(p1, p2) { const OUT_BUFFER = device.createBuffer({byteLength: 4 * 16}); -// TODO move to separate file? const uniformBlock = /* glsl */ `\ uniform testUniforms { vec4 uCommonPos;