From 691c790f7bfbfa2e7dde71117478997fcb5d113b Mon Sep 17 00:00:00 2001 From: Andy Nichols Date: Fri, 6 Aug 2021 16:56:56 +0200 Subject: [PATCH] Don't use unseeded random positions for benchmarks Previously there was a lot of variablity in performance between runs on certain hardware because models were spawned at random positions which were differn't between runs. This variablity is visible when hardware is bound by fragment operations. When this is the case the more space a model takes up on the screen as it rotates by the more fragments need to be rasterized by the GPU. If every run puts items in a differnt position, it can be hard to get stable peformance results between runs, and between differnt variations of the product. This changes the MeshSpawner to a method for generating random numbers that can be seeded to generate the same random numbers each run. Math.random can not be seeded as there is no API to do so. --- BenchmarkDemoQt6/BenchmarkUI/MeshSpawner.qml | 14 ++++++++------ BenchmarkDemoQt6/BenchmarkUI/notrandom.js | 12 ++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 BenchmarkDemoQt6/BenchmarkUI/notrandom.js diff --git a/BenchmarkDemoQt6/BenchmarkUI/MeshSpawner.qml b/BenchmarkDemoQt6/BenchmarkUI/MeshSpawner.qml index 919cc3d..7a7a6ca 100644 --- a/BenchmarkDemoQt6/BenchmarkUI/MeshSpawner.qml +++ b/BenchmarkDemoQt6/BenchmarkUI/MeshSpawner.qml @@ -2,6 +2,8 @@ import QtQuick import QtQuick3D import QtQuick3D.Helpers +import "notrandom.js" as Not + Node { id: shapeSpawner property bool demomode: false; @@ -42,13 +44,13 @@ Node { instances.push(instance); } else { var xPos = (instanceCount > 1 && randomize) - ? 2 * ((2 * Math.random() * range) - range) + ? 2 * ((2 * Not.random() * range) - range) : 0; var yPos = (instanceCount > 1 && randomize) - ? (2 * Math.random() * range) - range + ? (2 * Not.random() * range) - range : -150; var zPos = (instanceCount > 1 && randomize) - ? (2 * Math.random() * range) - range + ? (2 * Not.random() * range) - range : 0; if (Math.abs(xPos) < minRange) @@ -70,9 +72,9 @@ Node { shapeSpawner, { "x": xPos, "y": yPos, "z": zPos, "scale": Qt.vector3d(instanceScale, instanceScale, instanceScale), - "eulerRotation": Qt.vector3d(Math.random() * xPos / 20, - Math.random() * yPos / 20, - Math.random() * zPos / 20), + "eulerRotation": Qt.vector3d(Not.random() * xPos / 20, + Not.random() * yPos / 20, + Not.random() * zPos / 20), "materials": shapeSpawner.material, "useExternalMaterial": !shapeSpawner.useInternalMaterial, "textureSize": textureSize, diff --git a/BenchmarkDemoQt6/BenchmarkUI/notrandom.js b/BenchmarkDemoQt6/BenchmarkUI/notrandom.js new file mode 100644 index 0000000..47397d2 --- /dev/null +++ b/BenchmarkDemoQt6/BenchmarkUI/notrandom.js @@ -0,0 +1,12 @@ +var seed = 0x1337 + +function generateRandom(seedValue) { + return function() { + var t = seedValue += 0x6D2B79F5; + t = Math.imul(t ^ t >>> 15, t | 1); + t ^= t + Math.imul(t ^ t >>> 7, t | 61); + return ((t ^ t >>> 14) >>> 0) / 4294967296; + } +} + +var random = generateRandom(seed) -- 2.27.0.windows.1