Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert tests to use UBOs #9195

Merged
merged 12 commits into from
Oct 2, 2024
Merged
2 changes: 1 addition & 1 deletion modules/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/shaderlib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
21 changes: 11 additions & 10 deletions test/modules/aggregation-layers/hexbin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand All @@ -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
Expand All @@ -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({
Expand All @@ -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);
Expand Down
65 changes: 33 additions & 32 deletions test/modules/core/shaderlib/project/project-32-64-glsl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
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} 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;

Expand Down Expand Up @@ -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,
Expand All @@ -58,59 +57,57 @@ 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: {
projectProps: {
viewport: TEST_VIEWPORT,
coordinateSystem: COORDINATE_SYSTEM.LNGLAT
},
tests: [
{
name: 'project_position_to_clipspace_world_position',
vs: TRANSFORM_VS.project_position_to_clipspace_world_position,
input: [-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: [-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: [-122.45, 37.78, 100],
testProps: {uPos: [-122.45, 37.78, 100]},
output: TEST_VIEWPORT.project([-122.45, 37.78, 100]),
precision: PIXEL_TOLERANCE
}
]
},
{
title: 'LNGLAT mode - high zoom',
params: {
projectProps: {
viewport: TEST_VIEWPORT_HIGH_ZOOM,
coordinateSystem: COORDINATE_SYSTEM.LNGLAT
},
tests: [
{
name: 'project_position_to_clipspace_world_position',
vs: TRANSFORM_VS.project_position_to_clipspace_world_position,
input: [-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]),
Expand All @@ -119,24 +116,24 @@ const TEST_CASES = [
{
name: 'project_position_to_clipspace',
vs: TRANSFORM_VS.project_position_to_clipspace,
input: [-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
}
]
},
{
title: 'LNGLAT_OFFSETS mode',
params: {
projectProps: {
viewport: TEST_VIEWPORT,
coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS,
coordinateOrigin: [-122.05, 37.92]
coordinateOrigin: [-122.05, 37.92, 0]
},
tests: [
{
name: 'project_position_to_clipspace_world_position',
vs: TRANSFORM_VS.project_position_to_clipspace_world_position,
input: [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])
Expand All @@ -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],
testProps: {uPos: [0.05, 0.08, 0]},
output: TEST_VIEWPORT.project([-122, 38, 0]),
precision: PIXEL_TOLERANCE
}
Expand All @@ -159,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;
}
Expand All @@ -169,22 +166,26 @@ test('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) {
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.projectProps,
project64: testCase.projectProps,
test: {
uPos: c.testProps.uPos!,
uPos64Low: c.testProps.uPos!.map(fp64LowPart) as NumberArray3
}
},
uniforms
});
config.EPSILON = c.precision ?? 1e-5;

Expand Down
Loading
Loading