Bug 1715690 - Generalize WebGL RENDERER into large buckets. r=lsalzman

+ Minor reduction in unused flexibility of limits.

Differential Revision: https://phabricator.services.mozilla.com/D117385
This commit is contained in:
Jeff Gilbert 2021-06-11 23:54:39 +00:00
Родитель 55dbc99e55
Коммит de085c82e3
9 изменённых файлов: 477 добавлений и 114 удалений

Просмотреть файл

@ -11,7 +11,6 @@
#include "HostWebGLContext.h" #include "HostWebGLContext.h"
#include "js/ScalarType.h" // js::Scalar::Type #include "js/ScalarType.h" // js::Scalar::Type
#include "mozilla/dom/Document.h" #include "mozilla/dom/Document.h"
#include "mozilla/dom/SanitizeRenderer.h"
#include "mozilla/dom/ToJSValue.h" #include "mozilla/dom/ToJSValue.h"
#include "mozilla/dom/WebGLContextEvent.h" #include "mozilla/dom/WebGLContextEvent.h"
#include "mozilla/dom/WorkerCommon.h" #include "mozilla/dom/WorkerCommon.h"
@ -37,6 +36,12 @@
namespace mozilla { namespace mozilla {
namespace webgl {
std::string SanitizeRenderer(const std::string&);
} // namespace webgl
// -
webgl::NotLostData::NotLostData(ClientWebGLContext& _context) webgl::NotLostData::NotLostData(ClientWebGLContext& _context)
: context(_context) {} : context(_context) {}
@ -1872,10 +1877,12 @@ void ClientWebGLContext::GetParameter(JSContext* cx, GLenum pname,
return; return;
// 2 ints // 2 ints
case LOCAL_GL_MAX_VIEWPORT_DIMS: case LOCAL_GL_MAX_VIEWPORT_DIMS: {
retval.set(CreateAs<dom::Int32Array, const int32_t*>( const auto dims =
cx, this, limits.maxViewportDims, rv)); std::array<uint32_t, 2>{limits.maxViewportDim, limits.maxViewportDim};
retval.set(CreateAs<dom::Int32Array, const int32_t*>(cx, this, dims, rv));
return; return;
}
// 4 ints // 4 ints
case LOCAL_GL_SCISSOR_BOX: case LOCAL_GL_SCISSOR_BOX:
@ -1962,7 +1969,8 @@ void ClientWebGLContext::GetParameter(JSContext* cx, GLenum pname,
return; return;
case LOCAL_GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: case LOCAL_GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
retval.set(JS::NumberValue(limits.maxTransformFeedbackSeparateAttribs)); retval.set(
JS::NumberValue(webgl::kMaxTransformFeedbackSeparateAttribs));
return; return;
case LOCAL_GL_MAX_UNIFORM_BUFFER_BINDINGS: case LOCAL_GL_MAX_UNIFORM_BUFFER_BINDINGS:
retval.set(JS::NumberValue(limits.maxUniformBufferBindings)); retval.set(JS::NumberValue(limits.maxUniformBufferBindings));
@ -2063,9 +2071,11 @@ void ClientWebGLContext::GetParameter(JSContext* cx, GLenum pname,
const auto maybe = GetString(driverEnum); const auto maybe = GetString(driverEnum);
if (maybe) { if (maybe) {
std::string renderer = *maybe; std::string str = *maybe;
mozilla::dom::SanitizeRenderer(renderer); if (driverEnum == LOCAL_GL_RENDERER) {
retval.set(StringValue(cx, renderer, rv)); str = webgl::SanitizeRenderer(str);
}
retval.set(StringValue(cx, str, rv));
} }
return; return;
} }
@ -2881,11 +2891,11 @@ Maybe<webgl::ErrorInfo> CheckBindBufferRange(
switch (target) { switch (target) {
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER: case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
if (index >= limits.maxTransformFeedbackSeparateAttribs) { if (index >= webgl::kMaxTransformFeedbackSeparateAttribs) {
const auto info = nsPrintfCString( const auto info = nsPrintfCString(
"`index` (%u) must be less than " "`index` (%u) must be less than "
"MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS (%u).", "MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS (%u).",
index, limits.maxTransformFeedbackSeparateAttribs); index, webgl::kMaxTransformFeedbackSeparateAttribs);
return fnSome(LOCAL_GL_INVALID_VALUE, info); return fnSome(LOCAL_GL_INVALID_VALUE, info);
} }
@ -6108,7 +6118,7 @@ WebGLShaderJS::WebGLShaderJS(const ClientWebGLContext& webgl, const GLenum type)
WebGLTransformFeedbackJS::WebGLTransformFeedbackJS( WebGLTransformFeedbackJS::WebGLTransformFeedbackJS(
const ClientWebGLContext& webgl) const ClientWebGLContext& webgl)
: webgl::ObjectJS(webgl), : webgl::ObjectJS(webgl),
mAttribBuffers(webgl.Limits().maxTransformFeedbackSeparateAttribs) {} mAttribBuffers(webgl::kMaxTransformFeedbackSeparateAttribs) {}
WebGLVertexArrayJS::WebGLVertexArrayJS(const ClientWebGLContext& webgl) WebGLVertexArrayJS::WebGLVertexArrayJS(const ClientWebGLContext& webgl)
: webgl::ObjectJS(webgl), mAttribBuffers(webgl.Limits().maxVertexAttribs) {} : webgl::ObjectJS(webgl), mAttribBuffers(webgl.Limits().maxVertexAttribs) {}

Просмотреть файл

@ -0,0 +1,298 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/gfx/Logging.h"
#include "mozilla/IntegerRange.h"
#include <regex>
#include <string>
namespace mozilla {
namespace webgl {
static bool Contains(const std::string& str, const std::string& part) {
return str.find(str) != size_t(-1);
}
/**
* Narrow renderer string space down to representative replacements.
* E.g. "GeForce RTX 3090" => "GeForce GTX 980"
*
* For example strings:
* https://hackmd.io/Ductv3pQTMej74gbveD4yw
*/
static std::string ChooseDeviceReplacement(const std::string& str) {
if (str.find("llvmpipe") == 0) return "llvmpipe";
if (str.find("Apple") == 0) return "Apple M1";
std::smatch m;
// -
if (Contains(str, "FirePro") || Contains(str, "Radeon")) {
static const std::string RADEON_HD_3000 = "Radeon HD 3200 Graphics";
static const std::string RADEON_HD_5850 = "Radeon HD 5850";
static const std::string RADEON_R9_290 = "Radeon R9 200 Series";
const auto RADEON_D3D_FL10_1 = RADEON_HD_3000;
const auto RADEON_GCN_GEN2 = RADEON_R9_290; // GCN Gen2
if (Contains(str, "Vega")) {
return RADEON_R9_290;
}
if (Contains(str, "VII")) {
return RADEON_R9_290;
}
if (Contains(str, "Fury")) {
return RADEON_R9_290;
}
static const std::regex kRadeon(
"Radeon.*?((R[579X]|HD) )?([0-9][0-9][0-9]+)");
if (std::regex_search(str, m, kRadeon)) {
const auto& rxOrHd = m.str(2);
const auto modelNum = stoul(m.str(3));
if (rxOrHd == "HD") {
if (modelNum >= 5000) {
return RADEON_HD_5850;
}
if (modelNum >= 3000) {
return RADEON_HD_3000; // FL10_1
}
// HD 2000 is FL10_0, but webgl2 needs 10_1, so claim "old".
return RADEON_D3D_FL10_1;
}
// R5/7/9/X
return RADEON_R9_290;
}
static const std::regex kFirePro("FirePro.*?([VDW])[0-9][0-9][0-9]+");
if (std::regex_search(str, m, kFirePro)) {
const auto& vdw = m.str(1);
if (vdw == "V") {
return RADEON_HD_3000; // FL10_1
}
return RADEON_R9_290;
}
return RADEON_D3D_FL10_1;
}
// -
static const std::string GEFORCE_8800 = "GeForce 8800 GTX";
static const std::string GEFORCE_480 = "GeForce GTX 480";
static const std::string GEFORCE_980 = "GeForce GTX 980";
if (Contains(str, "GeForce") || Contains(str, "Quadro")) {
static const std::regex kGeForce("GeForce.*?([0-9][0-9][0-9]+)");
if (std::regex_search(str, m, kGeForce)) {
const auto modelNum = stoul(m.str(1));
if (modelNum >= 8000) {
// Tesla+: D3D10.0, SM4.0
return GEFORCE_8800;
}
if (modelNum >= 900) {
// Maxwell Gen2+: D3D12 FL12_1
return GEFORCE_980;
}
if (modelNum >= 400) {
// Fermi+: D3D12 FL11_0
return GEFORCE_480;
}
// Tesla+: D3D10.0, SM4.0
return GEFORCE_8800;
}
static const std::regex kQuadro("Quadro.*?([KMPVT]?)[0-9][0-9][0-9]+");
if (std::regex_search(str, m, kQuadro)) {
if (Contains(str, "RTX")) return GEFORCE_980;
const auto archLetter = m.str(1);
if (archLetter.size()) {
switch (archLetter[0]) {
case 'M': // Maxwell
case 'P': // Pascal
case 'V': // Volta
case 'T': // Turing, mobile-only
return GEFORCE_980;
case 'K': // Kepler
default:
return GEFORCE_480;
}
}
return GEFORCE_8800; // Close enough.
}
}
/* Similarities for Titans:
* 780
* * GeForce GTX TITAN
* * -
* * Black
* * Z
* 980
* * GeForce GTX TITAN X
* 1080
* * Nvidia TITAN X
* * Nvidia TITAN Xp
* * Nvidia TITAN V
* 2080
* * Nvidia TITAN RTX
*/
static const std::regex kTitan("TITAN( [BZXVR])?");
if (std::regex_search(str, m, kTitan)) {
char letter = ' ';
const auto sub = m.str(1);
if (sub.length()) {
letter = sub[1];
}
switch (letter) {
case ' ':
case 'B':
case 'Z':
return GEFORCE_480;
default:
return GEFORCE_980;
}
}
static const std::regex kNouveau("NV(1?[0-9A-F][0-9A-F])");
if (std::regex_match(str, m, kNouveau)) {
const auto modelNum = stoul(m.str(1), nullptr, 16);
// https://nouveau.freedesktop.org/CodeNames.html#NV110
if (modelNum >= 0x120) return GEFORCE_980;
if (modelNum >= 0xC0) return GEFORCE_480;
return GEFORCE_8800;
}
// -
if (Contains(str, "Intel")) {
static const std::string HD_GRAPHICS = "Intel(R) HD Graphics";
static const std::string HD_GRAPHICS_400 = "Intel(R) HD Graphics 400";
static const std::string INTEL_945GM = "Intel 945GM";
static const std::regex kIntelHD("Intel.*Graphics( P?([0-9][0-9][0-9]+))?");
if (std::regex_search(str, m, kIntelHD)) {
if (!m.str(1).size()) {
return HD_GRAPHICS;
}
const auto modelNum = stoul(m.str(2));
if (modelNum >= 5000) {
return HD_GRAPHICS_400;
}
if (modelNum >= 1000) {
return HD_GRAPHICS;
}
return HD_GRAPHICS_400;
}
return INTEL_945GM;
}
// -
static const std::regex kAdreno("Adreno.*?([0-9][0-9][0-9]+)");
if (std::regex_search(str, m, kAdreno)) {
const auto modelNum = stoul(m.str(1));
if (modelNum >= 600) {
return "Adreno (TM) 650";
}
if (modelNum >= 500) {
return "Adreno (TM) 540";
}
if (modelNum >= 400) {
return "Adreno (TM) 430";
}
if (modelNum >= 300) {
return "Adreno (TM) 330";
}
return "Adreno (TM) 225";
}
static const std::regex kMali("Mali.*?([0-9][0-9]+)");
if (std::regex_search(str, m, kMali)) {
const auto modelNum = stoul(m.str(1));
if (modelNum >= 800) {
return "Mali-T880";
}
if (modelNum >= 700) {
return "Mali-T760";
}
if (modelNum >= 600) {
return "Mali-T628";
}
if (modelNum >= 400) {
return "Mali-400 MP";
}
return "Mali-G51";
}
if (Contains(str, "PowerVR")) {
if (Contains(str, "Rogue")) {
return "PowerVR Rogue G6200";
}
return "PowerVR SGX 540";
}
if (Contains(str, "Vivante")) return "Vivante GC1000";
if (Contains(str, "VideoCore")) return "VideoCore IV HW";
if (Contains(str, "Tegra")) return "NVIDIA Tegra";
// -
static const std::string D3D_WARP = "Microsoft Basic Render Driver";
if (Contains(str, D3D_WARP)) return str;
gfxCriticalNote << "Couldn't sanitize RENDERER device: " << str;
return "Generic Renderer";
}
// -
std::string SanitizeRenderer(const std::string& str) {
std::smatch m;
static const std::regex kReAngle("(.*ANGLE [(])(.*)( Direct3D.*)");
if (std::regex_match(str, m, kReAngle)) {
auto prefix = m.str(1);
auto dev = m.str(2);
// ANGLE seems to do this:
// "GeForce RTX 3070..." => ANGLE (NVIDIA GeForce RTX 3070..."
static const std::regex kStripAngleVendorPrefix("(NVIDIA) (.*)");
std::smatch m2;
if (std::regex_match(dev, m2, kStripAngleVendorPrefix)) {
prefix += m2.str(1) + " ";
dev = m2.str(2);
}
const auto dev2 = ChooseDeviceReplacement(dev);
return prefix + dev2 + m.str(3);
}
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;
}
}; // namespace webgl
}; // namespace mozilla

Просмотреть файл

@ -1,56 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_RendererSanitizer_h
#define mozilla_RendererSanitizer_h
#include <string>
namespace mozilla {
namespace dom {
inline static void SanitizeRenderer(std::string& aRenderer) {
// Remove DRM, kernel, and LLVM versions exposed by amdgpu.
// The string looks like this:
//
// AMD Radeon (TM) GPU model Graphics (GPUgeneration, DRM
// DRMversion, kernelversion, LLVM LLVMversion)
//
// e.g. AMD Radeon (TM) RX 460 Graphics (POLARIS11,
// DRM 3.35.0, 5.4.0-65-generic, LLVM 11.0.0)
//
// OR
//
// AMD Radeon GPU model (GPUgeneration, DRM DRMversion, kernelversion, LLVM
// LLVMversion)
//
// Just in case, let's handle the case without GPUgeneration, i.e.
//
// AMD Radeon GPU model (DRM DRMversion, kernelversion, LLVM LLVMversion)
//
// even though there's no existence proof of this variant.
if (aRenderer.empty()) {
return;
}
if (aRenderer.back() != ')') {
return;
}
auto pos = aRenderer.find(", DRM ");
if (pos != std::string::npos) {
aRenderer.resize(pos);
aRenderer.push_back(')');
return;
}
pos = aRenderer.find(" (DRM ");
if (pos != std::string::npos) {
aRenderer.resize(pos);
return;
}
}
}; // namespace dom
}; // namespace mozilla
#endif // mozilla_RendererSanitizer_h

Просмотреть файл

@ -1437,8 +1437,8 @@ void WebGLContext::Viewport(GLint x, GLint y, GLsizei width, GLsizei height) {
} }
const auto& limits = Limits(); const auto& limits = Limits();
width = std::min(width, static_cast<GLsizei>(limits.maxViewportDims[0])); width = std::min(width, static_cast<GLsizei>(limits.maxViewportDim));
height = std::min(height, static_cast<GLsizei>(limits.maxViewportDims[1])); height = std::min(height, static_cast<GLsizei>(limits.maxViewportDim));
gl->fViewport(x, y, width, height); gl->fViewport(x, y, width, height);

Просмотреть файл

@ -184,13 +184,15 @@ bool WebGLContext::ValidateAttribArraySetter(uint32_t setterElemSize,
static webgl::Limits MakeLimits(const WebGLContext& webgl) { static webgl::Limits MakeLimits(const WebGLContext& webgl) {
webgl::Limits limits; webgl::Limits limits;
gl::GLContext& gl = *webgl.GL();
// -
for (const auto i : IntegerRange(UnderlyingValue(WebGLExtensionID::Max))) { for (const auto i : IntegerRange(UnderlyingValue(WebGLExtensionID::Max))) {
const auto ext = WebGLExtensionID(i); const auto ext = WebGLExtensionID(i);
limits.supportedExtensions[ext] = webgl.IsExtensionSupported(ext); limits.supportedExtensions[ext] = webgl.IsExtensionSupported(ext);
} }
gl::GLContext& gl = *webgl.GL();
// - // -
// WebGL 1 // WebGL 1
@ -203,7 +205,10 @@ static webgl::Limits MakeLimits(const WebGLContext& webgl) {
gl.GetUIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &limits.maxTex2dSize); gl.GetUIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &limits.maxTex2dSize);
gl.GetUIntegerv(LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE, &limits.maxTexCubeSize); gl.GetUIntegerv(LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE, &limits.maxTexCubeSize);
gl.GetUIntegerv(LOCAL_GL_MAX_VERTEX_ATTRIBS, &limits.maxVertexAttribs); gl.GetUIntegerv(LOCAL_GL_MAX_VERTEX_ATTRIBS, &limits.maxVertexAttribs);
gl.GetUIntegerv(LOCAL_GL_MAX_VIEWPORT_DIMS, limits.maxViewportDims.data());
auto dims = std::array<uint32_t, 2>{};
gl.GetUIntegerv(LOCAL_GL_MAX_VIEWPORT_DIMS, dims.data());
limits.maxViewportDim = std::min(dims[0], dims[1]);
if (!gl.IsCoreProfile()) { if (!gl.IsCoreProfile()) {
gl.fGetFloatv(LOCAL_GL_ALIASED_LINE_WIDTH_RANGE, gl.fGetFloatv(LOCAL_GL_ALIASED_LINE_WIDTH_RANGE,
@ -221,8 +226,6 @@ static webgl::Limits MakeLimits(const WebGLContext& webgl) {
gl.GetUIntegerv(LOCAL_GL_MAX_ARRAY_TEXTURE_LAYERS, gl.GetUIntegerv(LOCAL_GL_MAX_ARRAY_TEXTURE_LAYERS,
&limits.maxTexArrayLayers); &limits.maxTexArrayLayers);
gl.GetUIntegerv(LOCAL_GL_MAX_3D_TEXTURE_SIZE, &limits.maxTex3dSize); gl.GetUIntegerv(LOCAL_GL_MAX_3D_TEXTURE_SIZE, &limits.maxTex3dSize);
gl.GetUIntegerv(LOCAL_GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
&limits.maxTransformFeedbackSeparateAttribs);
gl.GetUIntegerv(LOCAL_GL_MAX_UNIFORM_BUFFER_BINDINGS, gl.GetUIntegerv(LOCAL_GL_MAX_UNIFORM_BUFFER_BINDINGS,
&limits.maxUniformBufferBindings); &limits.maxUniformBufferBindings);
gl.GetUIntegerv(LOCAL_GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, gl.GetUIntegerv(LOCAL_GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT,
@ -492,8 +495,7 @@ bool WebGLContext::InitAndValidateGL(FailureReason* const out_failReason) {
RestrictCap(&limits.lineWidthRange[1], kCommonAliasedLineWidthRangeMax); RestrictCap(&limits.lineWidthRange[1], kCommonAliasedLineWidthRangeMax);
ok &= ok &=
RestrictCap(&limits.pointSizeRange[1], kCommonAliasedPointSizeRangeMax); RestrictCap(&limits.pointSizeRange[1], kCommonAliasedPointSizeRangeMax);
ok &= RestrictCap(&limits.maxViewportDims[0], kCommonMaxViewportDims); ok &= RestrictCap(&limits.maxViewportDim, kCommonMaxViewportDims);
ok &= RestrictCap(&limits.maxViewportDims[1], kCommonMaxViewportDims);
if (!ok) { if (!ok) {
GenerateWarning( GenerateWarning(

Просмотреть файл

@ -17,7 +17,7 @@ namespace mozilla {
WebGLTransformFeedback::WebGLTransformFeedback(WebGLContext* webgl, GLuint tf) WebGLTransformFeedback::WebGLTransformFeedback(WebGLContext* webgl, GLuint tf)
: WebGLContextBoundObject(webgl), : WebGLContextBoundObject(webgl),
mGLName(tf), mGLName(tf),
mIndexedBindings(webgl->Limits().maxTransformFeedbackSeparateAttribs), mIndexedBindings(webgl::kMaxTransformFeedbackSeparateAttribs),
mIsPaused(false), mIsPaused(false),
mIsActive(false) {} mIsActive(false) {}

Просмотреть файл

@ -601,6 +601,8 @@ struct InitContextDesc final {
uint32_t principalKey = 0; uint32_t principalKey = 0;
}; };
constexpr uint32_t kMaxTransformFeedbackSeparateAttribs = 4;
struct Limits final { struct Limits final {
ExtensionBits supportedExtensions; ExtensionBits supportedExtensions;
@ -609,14 +611,13 @@ struct Limits final {
uint32_t maxTex2dSize = 0; uint32_t maxTex2dSize = 0;
uint32_t maxTexCubeSize = 0; uint32_t maxTexCubeSize = 0;
uint32_t maxVertexAttribs = 0; uint32_t maxVertexAttribs = 0;
std::array<uint32_t, 2> maxViewportDims = {}; uint32_t maxViewportDim = 0;
std::array<float, 2> pointSizeRange = {{1, 1}}; std::array<float, 2> pointSizeRange = {{1, 1}};
std::array<float, 2> lineWidthRange = {{1, 1}}; std::array<float, 2> lineWidthRange = {{1, 1}};
// WebGL 2 // WebGL 2
uint32_t maxTexArrayLayers = 0; uint32_t maxTexArrayLayers = 0;
uint32_t maxTex3dSize = 0; uint32_t maxTex3dSize = 0;
uint32_t maxTransformFeedbackSeparateAttribs = 0;
uint32_t maxUniformBufferBindings = 0; uint32_t maxUniformBufferBindings = 0;
uint32_t uniformBufferOffsetAlignment = 0; uint32_t uniformBufferOffsetAlignment = 0;

Просмотреть файл

@ -4,56 +4,164 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */ * You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "mozilla/dom/SanitizeRenderer.h"
TEST(SanitizeRenderer, TestRadeonTM) namespace mozilla {
namespace webgl {
std::string SanitizeRenderer(const std::string&);
} // namespace webgl
} // namespace mozilla
TEST(SanitizeRenderer, TestLinuxRadeon)
{ {
std::string renderer( 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 auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(sanitized, expectation);
}
TEST(SanitizeRenderer, TestLinuxRadeonTM)
{
const std::string renderer(
"AMD Radeon (TM) RX 460 Graphics (POLARIS11, DRM 3.35.0, " "AMD Radeon (TM) RX 460 Graphics (POLARIS11, DRM 3.35.0, "
"5.4.0-65-generic, LLVM 11.0.0)"); "5.4.0-65-generic, LLVM 11.0.0)");
std::string expectation("AMD Radeon (TM) RX 460 Graphics (POLARIS11)"); const std::string expectation("Radeon R9 200 Series");
mozilla::dom::SanitizeRenderer(renderer); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(renderer, expectation); EXPECT_EQ(sanitized, expectation);
} }
TEST(SanitizeRenderer, TestRadeon) TEST(SanitizeRenderer, TestLinuxRadeonWithoutGeneration)
{ {
std::string renderer( const std::string renderer(
"AMD Radeon RX 5700 (NAVI10, DRM 3.35.0, 5.4.0-65-generic, LLVM 11.0.0)");
std::string expectation("AMD Radeon RX 5700 (NAVI10)");
mozilla::dom::SanitizeRenderer(renderer);
EXPECT_EQ(renderer, expectation);
}
TEST(SanitizeRenderer, TestRadeonWithoutGeneration)
{
std::string renderer(
"AMD Radeon RX 5700 (DRM 3.35.0, 5.4.0-65-generic, LLVM 11.0.0)"); "AMD Radeon RX 5700 (DRM 3.35.0, 5.4.0-65-generic, LLVM 11.0.0)");
std::string expectation("AMD Radeon RX 5700"); const std::string expectation("Radeon R9 200 Series");
mozilla::dom::SanitizeRenderer(renderer); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(renderer, expectation); EXPECT_EQ(sanitized, expectation);
} }
TEST(SanitizeRenderer, TestVega) TEST(SanitizeRenderer, TestWindowsVega)
{ {
std::string renderer("Radeon RX Vega"); const std::string renderer("Radeon RX Vega");
std::string expectation("Radeon RX Vega"); const std::string expectation("Radeon R9 200 Series");
mozilla::dom::SanitizeRenderer(renderer); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(renderer, expectation); EXPECT_EQ(sanitized, expectation);
} }
TEST(SanitizeRenderer, TestIntel) TEST(SanitizeRenderer, TestMacAmd)
{ {
std::string renderer("Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)"); const std::string renderer("AMD Radeon Pro 5300M OpenGL Engine");
std::string expectation("Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)"); const std::string expectation("Radeon R9 200 Series");
mozilla::dom::SanitizeRenderer(renderer); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(renderer, expectation); EXPECT_EQ(sanitized, expectation);
}
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 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 auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(sanitized, expectation);
}
TEST(SanitizeRenderer, TestMacIntel)
{
const std::string renderer("Intel(R) HD Graphics 530");
const std::string expectation("Intel(R) HD Graphics 400");
const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(sanitized, expectation);
}
TEST(SanitizeRenderer, TestMacApple)
{
const std::string renderer("Apple M1");
const std::string expectation("Apple M1");
const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(sanitized, expectation);
} }
TEST(SanitizeRenderer, TestPipe) TEST(SanitizeRenderer, TestPipe)
{ {
std::string renderer("llvmpipe (LLVM 11.0.0, 256 bits)"); const std::string renderer("llvmpipe (LLVM 11.0.0, 128 bits)");
std::string expectation("llvmpipe (LLVM 11.0.0, 256 bits)"); const std::string expectation("llvmpipe");
mozilla::dom::SanitizeRenderer(renderer); const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(renderer, expectation); EXPECT_EQ(sanitized, expectation);
}
// -
TEST(SanitizeRenderer, TestAngleVega)
{
const std::string renderer("ANGLE (Radeon RX Vega Direct3D11 vs_5_0 ps_5_0)");
const std::string expectation(
"ANGLE (Radeon R9 200 Series Direct3D11 vs_5_0 ps_5_0)");
const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(sanitized, expectation);
}
TEST(SanitizeRenderer, TestAngleWarp)
{
const std::string renderer(
"ANGLE (Microsoft Basic Render Driver Direct3D11 vs_5_0 ps_5_0)");
const std::string expectation = renderer;
const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(sanitized, expectation);
}
TEST(SanitizeRenderer, TestAngle3070)
{
const std::string renderer(
"ANGLE (NVIDIA GeForce RTX 3070 Direct3D11 vs_5_0 ps_5_0)");
const std::string expectation(
"ANGLE (NVIDIA GeForce GTX 980 Direct3D11 vs_5_0 ps_5_0)");
const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(sanitized, expectation);
}
TEST(SanitizeRenderer, TestWindows3070)
{
const std::string renderer("GeForce RTX 3070/PCIe/SSE2");
const std::string expectation("GeForce GTX 980/PCIe/SSE2");
const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(sanitized, expectation);
}
TEST(SanitizeRenderer, TestAngleK600)
{
const std::string renderer(
"ANGLE (NVIDIA Quadro K600 Direct3D11 vs_5_0 ps_5_0)");
const std::string expectation(
"ANGLE (NVIDIA GeForce GTX 480 Direct3D11 vs_5_0 ps_5_0)");
const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(sanitized, expectation);
}
TEST(SanitizeRenderer, TestLinuxK600)
{
const std::string renderer("NVE7");
const std::string expectation("GeForce GTX 480");
const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(sanitized, expectation);
}
TEST(SanitizeRenderer, TestLinux980)
{
const std::string renderer("NV124");
const std::string expectation("GeForce GTX 980");
const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(sanitized, expectation);
}
TEST(SanitizeRenderer, TestAdreno512)
{
const std::string renderer("Adreno (TM) 512");
const std::string expectation("Adreno (TM) 540");
const auto sanitized = mozilla::webgl::SanitizeRenderer(renderer);
EXPECT_EQ(sanitized, expectation);
} }

Просмотреть файл

@ -62,7 +62,6 @@ EXPORTS.mozilla.dom += [
"IpdlQueue.h", "IpdlQueue.h",
"OffscreenCanvas.h", "OffscreenCanvas.h",
"QueueParamTraits.h", "QueueParamTraits.h",
"SanitizeRenderer.h",
"TextMetrics.h", "TextMetrics.h",
"WebGLChild.h", "WebGLChild.h",
"WebGLCommandQueue.h", "WebGLCommandQueue.h",
@ -99,6 +98,7 @@ UNIFIED_SOURCES += [
"ClientWebGLContext.cpp", "ClientWebGLContext.cpp",
"ClientWebGLExtensions.cpp", "ClientWebGLExtensions.cpp",
"HostWebGLContext.cpp", "HostWebGLContext.cpp",
"SanitizeRenderer.cpp",
"TexUnpackBlob.cpp", "TexUnpackBlob.cpp",
"WebGL2Context.cpp", "WebGL2Context.cpp",
"WebGL2ContextBuffers.cpp", "WebGL2ContextBuffers.cpp",