Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scripts/update_benchmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const outputFile = async (name: string, content: any) => {
.map((benchmark) => {
benchmark.gpu = benchmark.gpu
.toLowerCase()
.replace(/\s*\([^\)]+(\))/g, '')
.replace(/([0-9]+)\/[^ ]+/, '$1')
.replace(/\s*\([^)]+(\))/g, '')
.replace(/(\d+)\/[^ ]+/, '$1')
.replace(
/x\.org |inc\. |open source technology center |imagination technologies |™ |nvidia corporation |apple inc\. |advanced micro devices, inc\. | series$| edition$| graphics$/g,
''
Expand Down Expand Up @@ -99,7 +99,7 @@ const outputFile = async (name: string, content: any) => {
fps:
fpses[index] === ''
? undefined
: Math.round(Number(fpses[index].replace(/[^0-9.]+/g, ''))),
: Math.round(Number(fpses[index].replace(/[^\d.]+/g, ''))),
gpu: gpuNameLookup[gpuIndex],
mobile: formFactorLookup[formFactor[index]].includes('mobile'),
resolution: screenSizeLookup[screenSizes[index]],
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const getGPUTier = async ({
? (['adreno', 'apple', 'mali-t', 'mali', 'nvidia', 'powervr'] as const)
: (['intel', 'amd', 'radeon', 'nvidia', 'geforce'] as const);
for (const type of types) {
if (renderer.indexOf(type) > -1) {
if (renderer.includes(type)) {
return type;
}
}
Expand Down Expand Up @@ -168,7 +168,7 @@ export const getGPUTier = async ({

// If nothing matched, try comparing model names:
if (!matched.length) {
matched = benchmarks.filter(([model]) => model.indexOf(renderer) > -1);
matched = benchmarks.filter(([model]) => model.includes(renderer));

debug?.(
`found ${matched.length} matching entries comparing model names`,
Expand Down Expand Up @@ -229,7 +229,7 @@ export const getGPUTier = async ({
}

if (!closest) {
return undefined;
return;
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down Expand Up @@ -287,10 +287,10 @@ export const getGPUTier = async ({
);

if (!results.length) {
const blocklistedModel: string | undefined = BLOCKLISTED_GPUS.filter(
const blocklistedModel: string | undefined = BLOCKLISTED_GPUS.find(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(blocklistedModel) => renderer!.indexOf(blocklistedModel) > -1
)[0];
(blocklistedModel) => renderer!.includes(blocklistedModel)
);
return blocklistedModel
? toResult(0, 'BLOCKLISTED', blocklistedModel)
: toResult(1, 'FALLBACK', `${renderer} (${rawRenderer})`);
Expand Down
4 changes: 2 additions & 2 deletions src/internal/cleanRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export const cleanRenderer = (renderer: string) => {
.toLowerCase()
// Strip off ANGLE() - for example:
// 'ANGLE (NVIDIA TITAN Xp)' becomes 'NVIDIA TITAN Xp'':
.replace(/angle \((.+)\)*$/, '$1')
.replace(/^angle ?\((.+)\)*$/, '$1')
// Strip off [number]gb & strip off direct3d and after - for example:
// 'Radeon (TM) RX 470 Series Direct3D11 vs_5_0 ps_5_0' becomes
// 'Radeon (TM) RX 470 Series'
.replace(/\s+([0-9]+gb|direct3d.+$)|\(r\)| \([^)]+\)$/g, '');
.replace(/\s(\d{1,2}gb|direct3d.+$)|\(r\)| \([^)]+\)$/g, '');

debug?.('cleanRenderer - renderer cleaned to', { renderer });

Expand Down
2 changes: 1 addition & 1 deletion src/internal/deobfuscateAppleGPU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const deobfuscateAppleGPU = (
gl.vertexAttribPointer(aPosition, 3, GL_FLOAT, false, 0, 0);
gl.enableVertexAttribArray(aPosition);

gl.clearColor(1.0, 1.0, 1.0, 1.0);
gl.clearColor(1, 1, 1, 1);
gl.clear(GL_COLOR_BUFFER_BIT);
gl.viewport(0, 0, 1, 1);
gl.drawArrays(GL_TRIANGLES, 0, 3);
Expand Down
6 changes: 1 addition & 5 deletions src/internal/deobfuscateRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@ export const deobfuscateRenderer = (
renderer: string,
isMobileTier: boolean
) => {
if (renderer === 'apple gpu') {
return deobfuscateAppleGPU(gl, renderer, isMobileTier);
} else {
return [renderer];
}
return renderer === 'apple gpu' ? deobfuscateAppleGPU(gl, renderer, isMobileTier) : [renderer];
};
4 changes: 2 additions & 2 deletions src/internal/getGPUVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ export const getGPUVersion = (model: string) => {

const matches =
// First set of digits
model.match(/[\d]+/) ||
model.match(/\d+/) ||
// If the renderer did not contain any numbers, match letters
model.match(/(\W|^)([a-zA-Z]{1,3})(\W|$)/g);
model.match(/(\W|^)([A-Za-z]{1,3})(\W|$)/g);

// Remove any non-word characters and also remove 'amd' which could be matched
// in the clause above
Expand Down
6 changes: 3 additions & 3 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async () => {
});

// expect BENCHMARK results:
[
for (const { input, expected } of [
{
expected: {
gpu: 'intel uhd graphics 620',
Expand Down Expand Up @@ -233,7 +233,7 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async () => {
renderer: 'Mali-G51',
},
},
].forEach(({ input, expected }) => {
]) {
test(`${input.renderer} should find ${expected.gpu}`, async () => {
expectGPUResults(
{
Expand All @@ -243,7 +243,7 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async () => {
await getTier(input)
);
});
});
}

// expect FALLBACK results:
[
Expand Down