From 56642be88378bc479a3d2c8893d105998e36c76f Mon Sep 17 00:00:00 2001 From: Kelsey Gilbert Date: Fri, 5 Jan 2024 01:07:46 +0000 Subject: [PATCH] Bug 1826040 - Add ", or similar" to sanitized RENDERER strings. r=gfx-reviewers,lsalzman Differential Revision: https://phabricator.services.mozilla.com/D188046 --- dom/canvas/SanitizeRenderer.cpp | 72 ++++++++++++---------- dom/canvas/gtest/TestSanitizeRenderer.cpp | 52 ++++++++-------- .../webgl-mochitest/test_renderer_strings.html | 31 ++-------- 3 files changed, 69 insertions(+), 86 deletions(-) diff --git a/dom/canvas/SanitizeRenderer.cpp b/dom/canvas/SanitizeRenderer.cpp index 3e7a7cfce2a4..ef09f5ac81a4 100644 --- a/dom/canvas/SanitizeRenderer.cpp +++ b/dom/canvas/SanitizeRenderer.cpp @@ -275,44 +275,48 @@ static std::string ChooseDeviceReplacement(const std::string& str) { std::string SanitizeRenderer(const std::string& str) { std::smatch m; - // e.g. "ANGLE (AMD, AMD Radeon(TM) Graphics Direct3D11 vs_5_0 ps_5_0, - // D3D11-27.20.1020.2002)" - static const std::regex kReAngle( - "ANGLE [(]([^,]*), ([^,]*)( Direct3D[^,]*), .*[)]"); - if (std::regex_match(str, m, kReAngle)) { - const auto& vendor = m.str(1); - const auto& renderer = m.str(2); - const auto& d3d_suffix = m.str(3); - - const auto renderer2 = ChooseDeviceReplacement(renderer); - return std::string("ANGLE (") + vendor + ", " + renderer2 + d3d_suffix + - ")"; - } else if (Contains(str, "ANGLE")) { - gfxCriticalError() << "Failed to parse ANGLE renderer: " << str; - } + const auto replacementDevice = [&]() { + // e.g. "ANGLE (AMD, AMD Radeon(TM) Graphics Direct3D11 vs_5_0 ps_5_0, + // D3D11-27.20.1020.2002)" + static const std::regex kReAngle( + "ANGLE [(]([^,]*), ([^,]*)( Direct3D[^,]*), .*[)]"); + if (std::regex_match(str, m, kReAngle)) { + const auto& vendor = m.str(1); + const auto& renderer = m.str(2); + const auto& d3d_suffix = m.str(3); + + const auto renderer2 = ChooseDeviceReplacement(renderer); + return std::string("ANGLE (") + vendor + ", " + renderer2 + d3d_suffix + + ")"; + } else if (Contains(str, "ANGLE")) { + gfxCriticalError() << "Failed to parse ANGLE renderer: " << str; + } - static const std::regex kReOpenglEngine("(.*) OpenGL Engine"); - static const std::regex kRePcieSse2("(.*)(/PCIe?/SSE2)"); - static const std::regex kReStandard("(.*)( [(].*[)])"); - if (std::regex_match(str, m, kReOpenglEngine)) { - const auto& dev = m.str(1); - const auto dev2 = ChooseDeviceReplacement(dev); - return dev2; - } - if (std::regex_match(str, m, kRePcieSse2)) { - const auto& dev = m.str(1); - const auto dev2 = ChooseDeviceReplacement(dev); - return dev2 + m.str(2); - } - if (std::regex_match(str, m, kReStandard)) { - const auto& dev = m.str(1); + static const std::regex kReOpenglEngine("(.*) OpenGL Engine"); + static const std::regex kRePcieSse2("(.*)(/PCIe?/SSE2)"); + static const std::regex kReStandard("(.*)( [(].*[)])"); + if (std::regex_match(str, m, kReOpenglEngine)) { + const auto& dev = m.str(1); + const auto dev2 = ChooseDeviceReplacement(dev); + return dev2; + } + if (std::regex_match(str, m, kRePcieSse2)) { + const auto& dev = m.str(1); + const auto dev2 = ChooseDeviceReplacement(dev); + return dev2 + m.str(2); + } + if (std::regex_match(str, m, kReStandard)) { + const auto& dev = m.str(1); + const auto dev2 = ChooseDeviceReplacement(dev); + return dev2; + } + + const auto& dev = str; const auto dev2 = ChooseDeviceReplacement(dev); return dev2; - } + }(); - const auto& dev = str; - const auto dev2 = ChooseDeviceReplacement(dev); - return dev2; + return replacementDevice + ", or similar"; } }; // namespace webgl diff --git a/dom/canvas/gtest/TestSanitizeRenderer.cpp b/dom/canvas/gtest/TestSanitizeRenderer.cpp index 2aa5c7728988..9a6aba565f5b 100644 --- a/dom/canvas/gtest/TestSanitizeRenderer.cpp +++ b/dom/canvas/gtest/TestSanitizeRenderer.cpp @@ -13,7 +13,7 @@ TEST(SanitizeRenderer, TestLinuxRadeon) { const std::string renderer( "AMD Radeon RX 5700 (NAVI10, DRM 3.35.0, 5.4.0-65-generic, LLVM 11.0.0)"); - const std::string expectation("Radeon R9 200 Series"); + const std::string expectation("Radeon R9 200 Series, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -23,7 +23,7 @@ TEST(SanitizeRenderer, TestLinuxRadeonTM) const std::string renderer( "AMD Radeon (TM) RX 460 Graphics (POLARIS11, DRM 3.35.0, " "5.4.0-65-generic, LLVM 11.0.0)"); - const std::string expectation("Radeon R9 200 Series"); + const std::string expectation("Radeon R9 200 Series, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -32,7 +32,7 @@ TEST(SanitizeRenderer, TestLinuxRadeonWithoutGeneration) { const std::string renderer( "AMD Radeon RX 5700 (DRM 3.35.0, 5.4.0-65-generic, LLVM 11.0.0)"); - const std::string expectation("Radeon R9 200 Series"); + const std::string expectation("Radeon R9 200 Series, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -41,7 +41,7 @@ TEST(SanitizeRenderer, TestLinuxRenoir) { const std::string renderer( "AMD RENOIR (DRM 3.41.0, 5.13.4-1-default, LLVM 11.1.0)"); - const std::string expectation("Radeon R9 200 Series"); + const std::string expectation("Radeon R9 200 Series, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -49,7 +49,7 @@ TEST(SanitizeRenderer, TestLinuxRenoir) TEST(SanitizeRenderer, TestWindowsVega) { const std::string renderer("Radeon RX Vega"); - const std::string expectation("Radeon R9 200 Series"); + const std::string expectation("Radeon R9 200 Series, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -57,7 +57,7 @@ TEST(SanitizeRenderer, TestWindowsVega) TEST(SanitizeRenderer, TestMacAmd) { const std::string renderer("AMD Radeon Pro 5300M OpenGL Engine"); - const std::string expectation("Radeon R9 200 Series"); + const std::string expectation("Radeon R9 200 Series, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -66,7 +66,7 @@ TEST(SanitizeRenderer, TestLinuxAruba) { const std::string renderer( "AMD ARUBA (DRM 2.50.0 / 5.10.42-calculate, LLVM 12.0.1)"); - const std::string expectation("Radeon HD 5850"); + const std::string expectation("Radeon HD 5850, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -74,14 +74,14 @@ TEST(SanitizeRenderer, TestLinuxAruba) TEST(SanitizeRenderer, TestLinuxIntel620) { const std::string renderer("Mesa Intel(R) UHD Graphics 620 (KBL GT2)"); - const std::string expectation("Intel(R) HD Graphics 400"); + const std::string expectation("Intel(R) HD Graphics 400, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } TEST(SanitizeRenderer, TestLinuxIntel4000) { const std::string renderer("Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)"); - const std::string expectation("Intel(R) HD Graphics"); + const std::string expectation("Intel(R) HD Graphics, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -89,7 +89,7 @@ TEST(SanitizeRenderer, TestLinuxIntel4000) TEST(SanitizeRenderer, TestMacIntel) { const std::string renderer("Intel(R) HD Graphics 530"); - const std::string expectation("Intel(R) HD Graphics 400"); + const std::string expectation("Intel(R) HD Graphics 400, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -97,7 +97,7 @@ TEST(SanitizeRenderer, TestMacIntel) TEST(SanitizeRenderer, TestMacApple) { const std::string renderer("Apple M1"); - const std::string expectation("Apple M1"); + const std::string expectation("Apple M1, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -105,7 +105,7 @@ TEST(SanitizeRenderer, TestMacApple) TEST(SanitizeRenderer, TestPipe) { const std::string renderer("llvmpipe (LLVM 11.0.0, 128 bits)"); - const std::string expectation("llvmpipe"); + const std::string expectation("llvmpipe, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -118,7 +118,7 @@ TEST(SanitizeRenderer, TestAngleVega) "ANGLE (AMD, Radeon RX Vega Direct3D11 vs_5_0 ps_5_0, " "D3D11-27.20.22025.1006)"); const std::string expectation( - "ANGLE (AMD, Radeon R9 200 Series Direct3D11 vs_5_0 ps_5_0)"); + "ANGLE (AMD, Radeon R9 200 Series Direct3D11 vs_5_0 ps_5_0), or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -129,7 +129,7 @@ TEST(SanitizeRenderer, TestAngleRadeon) "ANGLE (AMD, AMD Radeon(TM) Graphics Direct3D11 vs_5_0 ps_5_0, " "D3D11-27.20.1020.2002)"); const std::string expectation( - "ANGLE (AMD, Radeon HD 3200 Graphics Direct3D11 vs_5_0 ps_5_0)"); + "ANGLE (AMD, Radeon HD 3200 Graphics Direct3D11 vs_5_0 ps_5_0), or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -140,7 +140,7 @@ TEST(SanitizeRenderer, TestAngleWarp) "ANGLE (Unknown, Microsoft Basic Render Driver Direct3D11 vs_5_0 ps_5_0, " "D3D11-10.0.22000.1)"); const std::string expectation = - "ANGLE (Unknown, Microsoft Basic Render Driver Direct3D11 vs_5_0 ps_5_0)"; + "ANGLE (Unknown, Microsoft Basic Render Driver Direct3D11 vs_5_0 ps_5_0), or similar"; const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -151,7 +151,7 @@ TEST(SanitizeRenderer, TestAngle3070) "ANGLE (NVIDIA, NVIDIA GeForce RTX 3070 Direct3D11 vs_5_0 ps_5_0, " "D3D11-10.0.22000.1)"); const std::string expectation( - "ANGLE (NVIDIA, NVIDIA GeForce GTX 980 Direct3D11 vs_5_0 ps_5_0)"); + "ANGLE (NVIDIA, NVIDIA GeForce GTX 980 Direct3D11 vs_5_0 ps_5_0), or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -159,7 +159,7 @@ TEST(SanitizeRenderer, TestAngle3070) TEST(SanitizeRenderer, TestWindows3070) { const std::string renderer("GeForce RTX 3070/PCIe/SSE2"); - const std::string expectation("GeForce GTX 980/PCIe/SSE2"); + const std::string expectation("GeForce GTX 980/PCIe/SSE2, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -170,7 +170,7 @@ TEST(SanitizeRenderer, TestAngleK600) "ANGLE (NVIDIA, NVIDIA Quadro K600 Direct3D11 vs_5_0 ps_5_0, somethig " "like D3D11-10.0.22000.1)"); const std::string expectation( - "ANGLE (NVIDIA, NVIDIA GeForce GTX 480 Direct3D11 vs_5_0 ps_5_0)"); + "ANGLE (NVIDIA, NVIDIA GeForce GTX 480 Direct3D11 vs_5_0 ps_5_0), or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -178,7 +178,7 @@ TEST(SanitizeRenderer, TestAngleK600) TEST(SanitizeRenderer, TestLinuxK600) { const std::string renderer("NVE7"); - const std::string expectation("GeForce GTX 480"); + const std::string expectation("GeForce GTX 480, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -186,7 +186,7 @@ TEST(SanitizeRenderer, TestLinuxK600) TEST(SanitizeRenderer, TestLinux980) { const std::string renderer("NV124"); - const std::string expectation("GeForce GTX 980"); + const std::string expectation("GeForce GTX 980, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -194,7 +194,7 @@ TEST(SanitizeRenderer, TestLinux980) TEST(SanitizeRenderer, TestAdreno512) { const std::string renderer("Adreno (TM) 512"); - const std::string expectation("Adreno (TM) 540"); + const std::string expectation("Adreno (TM) 540, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -207,7 +207,7 @@ TEST(SanitizeRenderer, TestAdreno512) TEST(SanitizeRenderer, TestCiAndroid) { const std::string renderer("Adreno (TM) 540"); - const std::string expectation("Adreno (TM) 540"); + const std::string expectation("Adreno (TM) 540, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -215,7 +215,7 @@ TEST(SanitizeRenderer, TestCiAndroid) TEST(SanitizeRenderer, TestCiLinux) { const std::string renderer("llvmpipe (LLVM 10.0.0, 256 bits)"); - const std::string expectation("llvmpipe"); + const std::string expectation("llvmpipe, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -223,7 +223,7 @@ TEST(SanitizeRenderer, TestCiLinux) TEST(SanitizeRenderer, TestCiMac) { const std::string renderer("Intel(R) UHD Graphics 630"); - const std::string expectation("Intel(R) HD Graphics 400"); + const std::string expectation("Intel(R) HD Graphics 400, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -231,7 +231,7 @@ TEST(SanitizeRenderer, TestCiMac) TEST(SanitizeRenderer, TestCiMac2) { const std::string renderer("Apple M1"); - const std::string expectation("Apple M1"); + const std::string expectation("Apple M1, or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } @@ -242,7 +242,7 @@ TEST(SanitizeRenderer, TestCiWindows) "ANGLE (NVIDIA, NVIDIA Tesla M60 Direct3D11 vs_5_0 ps_5_0, " "D3D11-23.21.13.9181)"); const std::string expectation( - "ANGLE (NVIDIA, NVIDIA GeForce 8800 GTX Direct3D11 vs_5_0 ps_5_0)"); + "ANGLE (NVIDIA, NVIDIA GeForce 8800 GTX Direct3D11 vs_5_0 ps_5_0), or similar"); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer); EXPECT_EQ(sanitized, expectation); } diff --git a/dom/canvas/test/webgl-mochitest/test_renderer_strings.html b/dom/canvas/test/webgl-mochitest/test_renderer_strings.html index cbf0aeac78d3..257a16d45e3d 100644 --- a/dom/canvas/test/webgl-mochitest/test_renderer_strings.html +++ b/dom/canvas/test/webgl-mochitest/test_renderer_strings.html @@ -23,7 +23,7 @@ function getStrings() { const RTX3070_R = 'ANGLE (NVIDIA, NVIDIA GeForce RTX 3070 Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5751)'; const RTX3070_V = 'Google Inc.'; -const RTX3070_R_SANITIZED = 'ANGLE (NVIDIA, NVIDIA GeForce GTX 980 Direct3D11 vs_5_0 ps_5_0)'; +const RTX3070_R_SANITIZED = 'ANGLE (NVIDIA, NVIDIA GeForce GTX 980 Direct3D11 vs_5_0 ps_5_0), or similar'; function expectJsonEqual(was, expected, when) { if (when) { @@ -59,7 +59,7 @@ async function testKnownCiStrings() { 'Intel(R) HD Graphics 400', // Mac 'Apple M1', // Mac 'ANGLE (NVIDIA, NVIDIA GeForce 8800 GTX Direct3D11 vs_5_0 ps_5_0)', // Windows - ], + ].map(x => x + ', or similar'), vendor: [ 'Mozilla', ], @@ -84,14 +84,14 @@ async function testKnownCiStrings() { const wasVal = was[k]; const knownList = KNOWN_ON_CI[k]; ok(knownList.includes(wasVal), - `[ignore if not on CI] getParameter(${k}) -> ${wasVal} must be in KNOWN_ON_CI`); + `[ignore if not on CI] getParameter(${k}) -> '${wasVal}' must be in KNOWN_ON_CI`); } await SpecialPowers.popPrefEnv(); } // - -async function testPrefBehavior() { +async function testPrefBehaviorForExampleRtx3070() { const canvas = document.createElement('canvas'); gl = canvas.getContext('webgl'); ext = null; @@ -107,27 +107,6 @@ async function testPrefBehavior() { // detailed driver version/date to its RENDERER strings, which // we want to prevent. - const KNOWN_CI_VENDORS = [ - 'Mozilla', - ]; - const KNOWN_CI_RENDERERS = [ - 'Adreno (TM) 540', // Android - 'Adreno (TM) 650', // Android - 'Intel(R) HD Graphics 400', // Mac - 'Apple M1', // Mac - 'llvmpipe', // Linux - 'ANGLE (NVIDIA, NVIDIA GeForce 8800 GTX Direct3D11 vs_5_0 ps_5_0)', // Windows - ]; - function assertKnownValid(key, knownList) { - const val = gl.getParameter(gl[key]); - ok(knownList.includes(val), - `[ignore if not on CI] getParameter(${key}) -> ${val} not known-valid!`); - } - assertKnownValid('VENDOR', KNOWN_CI_VENDORS); - assertKnownValid('RENDERER', KNOWN_CI_RENDERERS); - - // - - await SpecialPowers.pushPrefEnv({'set': [ ['webgl.override-unmasked-renderer', RTX3070_R], ['webgl.override-unmasked-vendor', RTX3070_V], @@ -237,7 +216,7 @@ async function testPrefBehavior() { SimpleTest.waitForExplicitFinish(); (async function() { await testKnownCiStrings(); - await testPrefBehavior(); + await testPrefBehaviorForExampleRtx3070(); ok(true, 'Test complete.'); SimpleTest.finish(); -- 2.11.4.GIT