b948dcdc
Levin Li
committed
succeeded
1 changed file
variable_rasterization_rate_map.patch
/variable_rasterization_rate_map.patch-296+15
/variable_rasterization_rate_map.patch
Add comment 710 };
Add comment 711
Add comment 712 diff --git a/src/libANGLE/renderer/metal/ContextMtl.mm b/src/libANGLE/renderer/metal/ContextMtl.mm
Add comment 713 Minus  index 35ed007fcf..640fa9050c 100644
Add comment 713 Plus  index 7b4b675d19..ab9d8be6a3 100644
Add comment 714 --- a/src/libANGLE/renderer/metal/ContextMtl.mm
Add comment 715 +++ b/src/libANGLE/renderer/metal/ContextMtl.mm
Add comment 716 @@ -261,6 +261,7 @@ void ContextMtl::onDestroy(const gl::Context *context)
Add comment 800 bool isAMDBronzeDriver() const;
Add comment 801 bool isAMDFireProDevice() const;
Add comment 802 diff --git a/src/libANGLE/renderer/metal/DisplayMtl.mm b/src/libANGLE/renderer/metal/DisplayMtl.mm
Add comment 803 Minus  index cfde4651c5..64b67e2b90 100644
Add comment 803 Plus  index 201927e4f0..7d063f8358 100644
Add comment 804 --- a/src/libANGLE/renderer/metal/DisplayMtl.mm
Add comment 805 +++ b/src/libANGLE/renderer/metal/DisplayMtl.mm
Add comment 806 @@ -1185,6 +1185,11 @@ void DisplayMtl::initializeExtensions() const
Add comment 842 bool DisplayMtl::isAMD() const
Add comment 843 {
Add comment 844 return angle::IsAMD(mMetalDeviceVendorId);
Add comment 845 Plus  diff --git a/src/libANGLE/renderer/metal/FrameBufferMtl.mm b/src/libANGLE/renderer/metal/FrameBufferMtl.mm
Add comment 846 Plus  index 4f508bdf9d..3b88ba8c5c 100644
Add comment 847 Plus  --- a/src/libANGLE/renderer/metal/FrameBufferMtl.mm
Add comment 848 Plus  +++ b/src/libANGLE/renderer/metal/FrameBufferMtl.mm
Add comment 849 Plus  @@ -518,6 +518,8 @@ angle::Result FramebufferMtl::blitWithDraw(const gl::Context *context,
Add comment 850 Plus   renderEncoder = ensureRenderPassStarted(context);
Add comment 851 Plus   }
Add comment 852 Plus  
Add comment 853 Plus  + renderEncoder->setRasterizationRateMap(nil);
Add comment 854 Plus  +
Add comment 855 Plus   // Blit color
Add comment 856 Plus   if (blitColorBuffer)
Add comment 857 Plus   {
Add comment 845 858 diff --git a/src/libANGLE/renderer/metal/mtl_command_buffer.h b/src/libANGLE/renderer/metal/mtl_command_buffer.h
Add comment 846 859 index 8d7bc2667e..38a27775ff 100644
Add comment 847 860 --- a/src/libANGLE/renderer/metal/mtl_command_buffer.h
Add comment 1330 1343 {"glBindProgramPipeline", P(GL_BindProgramPipeline)},
Add comment 1331 1344 {"glBindProgramPipelineEXT", P(GL_BindProgramPipelineEXT)},
Add comment 1332 1345 {"glBindRenderbuffer", P(GL_BindRenderbuffer)},
Add comment 1333 Minus  diff --git a/src/tests/angle_end2end_tests.gni b/src/tests/angle_end2end_tests.gni
Add comment 1334 Minus  index 3cdaf00014..14287a7b1b 100644
Add comment 1335 Minus  --- a/src/tests/angle_end2end_tests.gni
Add comment 1336 Minus  +++ b/src/tests/angle_end2end_tests.gni
Add comment 1337 Minus  @@ -221,6 +221,7 @@ angle_end2end_tests_mac_sources = [
Add comment 1338 Minus   "egl_tests/EGLSyncTestMetalSharedEvent.mm",
Add comment 1339 Minus   "egl_tests/EGLWaitUntilWorkScheduledTest.cpp",
Add comment 1340 Minus   "gl_tests/ImageTestMetal.mm",
Add comment 1341 Minus  + "gl_tests/VariableRasterizationRateTestMetal.mm",
Add comment 1342 Minus   ]
Add comment 1343 Minus   angle_end2end_tests_win_sources = [
Add comment 1344 Minus   "egl_tests/EGLDeviceTest.cpp",
Add comment 1345 Minus  diff --git a/src/tests/gl_tests/VariableRasterizationRateTestMetal.mm b/src/tests/gl_tests/VariableRasterizationRateTestMetal.mm
Add comment 1346 Minus  new file mode 100644
Add comment 1347 Minus  index 0000000000..4affa480be
Add comment 1348 Minus  --- /dev/null
Add comment 1349 Minus  +++ b/src/tests/gl_tests/VariableRasterizationRateTestMetal.mm
Add comment 1350 Minus  @@ -0,0 +1,276 @@
Add comment 1351 Minus  +//
Add comment 1352 Minus  +// Copyright 2023 The ANGLE Project Authors. All rights reserved.
Add comment 1353 Minus  +// Use of this source code is governed by a BSD-style license that can be
Add comment 1354 Minus  +// found in the LICENSE file.
Add comment 1355 Minus  +//
Add comment 1356 Minus  +// ImageTestMetal:
Add comment 1357 Minus  +// Tests the correctness of eglImage with native Metal texture extensions.
Add comment 1358 Minus  +//
Add comment 1359 Minus  +
Add comment 1360 Minus  +#include "test_utils/ANGLETest.h"
Add comment 1361 Minus  +
Add comment 1362 Minus  +#include "common/mathutil.h"
Add comment 1363 Minus  +#include "test_utils/gl_raii.h"
Add comment 1364 Minus  +#include "util/EGLWindow.h"
Add comment 1365 Minus  +
Add comment 1366 Minus  +#include <CoreFoundation/CoreFoundation.h>
Add comment 1367 Minus  +#include <Metal/Metal.h>
Add comment 1368 Minus  +
Add comment 1369 Minus  +namespace angle
Add comment 1370 Minus  +{
Add comment 1371 Minus  +namespace
Add comment 1372 Minus  +{
Add comment 1373 Minus  +constexpr int kTileSize = 32;
Add comment 1374 Minus  +constexpr int kWindowWidth = 8 * kTileSize;
Add comment 1375 Minus  +constexpr int kWindowHeight = kWindowWidth;
Add comment 1376 Minus  +constexpr int kZones = 7;
Add comment 1377 Minus  +constexpr float kQuality[kZones] = {0.24f, 0.24f, 0.24f, 0.24f, 0.49f, 0.49f, 0.49f};
Add comment 1378 Minus  +constexpr int kViewportWidth = 3 * kTileSize;
Add comment 1379 Minus  +constexpr int kViewportHeight = 3 * kTileSize;
Add comment 1380 Minus  +constexpr char kVariableRasterizationRateExt[] = "GL_ANGLE_variable_rasterization_rate_metal";
Add comment 1381 Minus  +constexpr char kVS[] = R"(precision highp float;
Add comment 1382 Minus  +attribute vec4 position;
Add comment 1383 Minus  +varying vec2 texcoord;
Add comment 1384 Minus  +
Add comment 1385 Minus  +void main()
Add comment 1386 Minus  +{
Add comment 1387 Minus  + gl_Position = position;
Add comment 1388 Minus  + texcoord = (position.xy * 0.5) + 0.5;
Add comment 1389 Minus  +})";
Add comment 1390 Minus  +constexpr char kCheckerBoardFS[] = R"(
Add comment 1391 Minus  +precision highp float;
Add comment 1392 Minus  +varying vec2 texcoord;
Add comment 1393 Minus  +uniform vec2 u_resolution;
Add comment 1394 Minus  +uniform float u_checkCount;
Add comment 1395 Minus  +
Add comment 1396 Minus  +void main()
Add comment 1397 Minus  +{
Add comment 1398 Minus  + vec2 uv = texcoord * u_checkCount;
Add comment 1399 Minus  +
Add comment 1400 Minus  + float u = 1.0 - floor(mod(uv.x, 2.0));
Add comment 1401 Minus  + float v = 1.0 - floor(mod(uv.y, 2.0));
Add comment 1402 Minus  + vec3 col = vec3(1.0);
Add comment 1403 Minus  +
Add comment 1404 Minus  + if(u == 1.0 && v < 1.0 || v == 1.0 && u < 1.0) {
Add comment 1405 Minus  + col = vec3(0.);
Add comment 1406 Minus  + }
Add comment 1407 Minus  + gl_FragColor = vec4(col,1.0);
Add comment 1408 Minus  +})";
Add comment 1409 Minus  +} // anonymous namespace
Add comment 1410 Minus  +
Add comment 1411 Minus  +class ScopeMetalRasterizationRateMapRef : angle::NonCopyable
Add comment 1412 Minus  +{
Add comment 1413 Minus  + public:
Add comment 1414 Minus  + explicit ScopeMetalRasterizationRateMapRef(id<MTLRasterizationRateMap> &&map) : mMap(map) {}
Add comment 1415 Minus  +
Add comment 1416 Minus  + ~ScopeMetalRasterizationRateMapRef()
Add comment 1417 Minus  + {
Add comment 1418 Minus  + if (mMap)
Add comment 1419 Minus  + {
Add comment 1420 Minus  + release();
Add comment 1421 Minus  + mMap = nil;
Add comment 1422 Minus  + }
Add comment 1423 Minus  + }
Add comment 1424 Minus  +
Add comment 1425 Minus  + operator GLMTLRasterizationRateMapANGLE() const
Add comment 1426 Minus  + {
Add comment 1427 Minus  + return reinterpret_cast<GLMTLRasterizationRateMapANGLE>(mMap);
Add comment 1428 Minus  + }
Add comment 1429 Minus  +
Add comment 1430 Minus  + NSUInteger layerCount() const { return mMap.layerCount; }
Add comment 1431 Minus  + MTLSize screenSize() const { return mMap.screenSize; }
Add comment 1432 Minus  + MTLSize physicalGranularity() const { return mMap.physicalGranularity; }
Add comment 1433 Minus  + MTLSize viewportSize() const { return [mMap physicalSizeForLayer:0]; }
Add comment 1434 Minus  + MTLCoordinate2D mapScreenToView(MTLCoordinate2D screenCoord)
Add comment 1435 Minus  + {
Add comment 1436 Minus  + return [mMap mapScreenToPhysicalCoordinates:screenCoord forLayer:0];
Add comment 1437 Minus  + }
Add comment 1438 Minus  + MTLCoordinate2D mapViewToScreen(MTLCoordinate2D viewCoord)
Add comment 1439 Minus  + {
Add comment 1440 Minus  + return [mMap mapPhysicalToScreenCoordinates:viewCoord forLayer:0];
Add comment 1441 Minus  + }
Add comment 1442 Minus  +
Add comment 1443 Minus  + private:
Add comment 1444 Minus  + void release()
Add comment 1445 Minus  + {
Add comment 1446 Minus  +#if !__has_feature(objc_arc)
Add comment 1447 Minus  + [mMap release];
Add comment 1448 Minus  +#endif
Add comment 1449 Minus  + }
Add comment 1450 Minus  +
Add comment 1451 Minus  + id<MTLRasterizationRateMap> mMap = nil;
Add comment 1452 Minus  +};
Add comment 1453 Minus  +
Add comment 1454 Minus  +ScopeMetalRasterizationRateMapRef CreateMetalRasterizationRateMap(id<MTLDevice> deviceMtl,
Add comment 1455 Minus  + int width,
Add comment 1456 Minus  + int height,
Add comment 1457 Minus  + int horizontalCount,
Add comment 1458 Minus  + const float *horizontal,
Add comment 1459 Minus  + int verticalCount,
Add comment 1460 Minus  + const float *vertical)
Add comment 1461 Minus  +{
Add comment 1462 Minus  + @autoreleasepool
Add comment 1463 Minus  + {
Add comment 1464 Minus  + MTLRasterizationRateLayerDescriptor *rrLayer = [[MTLRasterizationRateLayerDescriptor alloc]
Add comment 1465 Minus  + initWithSampleCount:MTLSizeMake(horizontalCount, verticalCount, 0)
Add comment 1466 Minus  + horizontal:horizontal
Add comment 1467 Minus  + vertical:vertical];
Add comment 1468 Minus  + MTLRasterizationRateMapDescriptor *rrDesc = [MTLRasterizationRateMapDescriptor
Add comment 1469 Minus  + rasterizationRateMapDescriptorWithScreenSize:MTLSizeMake(width, height, 0)
Add comment 1470 Minus  + layer:rrLayer];
Add comment 1471 Minus  + rrDesc.label = @"Test RasterizationRate";
Add comment 1472 Minus  +
Add comment 1473 Minus  + return ScopeMetalRasterizationRateMapRef(
Add comment 1474 Minus  + [deviceMtl newRasterizationRateMapWithDescriptor:rrDesc]);
Add comment 1475 Minus  + }
Add comment 1476 Minus  +}
Add comment 1477 Minus  +
Add comment 1478 Minus  +class VariableRasterizationRateTestMetal : public ANGLETest<>
Add comment 1479 Minus  +{
Add comment 1480 Minus  + protected:
Add comment 1481 Minus  + VariableRasterizationRateTestMetal()
Add comment 1482 Minus  + {
Add comment 1483 Minus  + setWindowWidth(kWindowWidth);
Add comment 1484 Minus  + setWindowHeight(kWindowHeight);
Add comment 1485 Minus  + setConfigRedBits(8);
Add comment 1486 Minus  + setConfigGreenBits(8);
Add comment 1487 Minus  + setConfigBlueBits(8);
Add comment 1488 Minus  + setConfigAlphaBits(8);
Add comment 1489 Minus  + setConfigDepthBits(24);
Add comment 1490 Minus  + }
Add comment 1491 Minus  +
Add comment 1492 Minus  + void testSetUp() override
Add comment 1493 Minus  + {
Add comment 1494 Minus  + mProgram = CompileProgram(kVS, kCheckerBoardFS);
Add comment 1495 Minus  + if (!mProgram)
Add comment 1496 Minus  + {
Add comment 1497 Minus  + FAIL() << "shader compilation failed.";
Add comment 1498 Minus  + }
Add comment 1499 Minus  + mUniformResolutionLocation = glGetUniformLocation(mProgram, "u_resolution");
Add comment 1500 Minus  + mUniformCheckCountLocation = glGetUniformLocation(mProgram, "u_checkCount");
Add comment 1501 Minus  +
Add comment 1502 Minus  + ASSERT_GL_NO_ERROR();
Add comment 1503 Minus  + }
Add comment 1504 Minus  +
Add comment 1505 Minus  + void testTearDown() override {}
Add comment 1506 Minus  +
Add comment 1507 Minus  + id<MTLDevice> getMtlDevice()
Add comment 1508 Minus  + {
Add comment 1509 Minus  + EGLAttrib angleDevice = 0;
Add comment 1510 Minus  + EGLAttrib device = 0;
Add comment 1511 Minus  + EXPECT_EGL_TRUE(
Add comment 1512 Minus  + eglQueryDisplayAttribEXT(getEGLWindow()->getDisplay(), EGL_DEVICE_EXT, &angleDevice));
Add comment 1513 Minus  +
Add comment 1514 Minus  + EXPECT_EGL_TRUE(eglQueryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(angleDevice),
Add comment 1515 Minus  + EGL_METAL_DEVICE_ANGLE, &device));
Add comment 1516 Minus  +
Add comment 1517 Minus  + return (__bridge id<MTLDevice>)reinterpret_cast<void *>(device);
Add comment 1518 Minus  + }
Add comment 1519 Minus  +
Add comment 1520 Minus  + template <size_t W, size_t H>
Add comment 1521 Minus  + ScopeMetalRasterizationRateMapRef createMetalRasterizationRateMap(int width,
Add comment 1522 Minus  + int height,
Add comment 1523 Minus  + const float (&horizontal)[W],
Add comment 1524 Minus  + const float (&vertical)[H])
Add comment 1525 Minus  + {
Add comment 1526 Minus  + id<MTLDevice> device = getMtlDevice();
Add comment 1527 Minus  +
Add comment 1528 Minus  + return CreateMetalRasterizationRateMap(device, width, height, W, horizontal, H, vertical);
Add comment 1529 Minus  + }
Add comment 1530 Minus  +
Add comment 1531 Minus  + GLuint mProgram;
Add comment 1532 Minus  + GLint mUniformResolutionLocation;
Add comment 1533 Minus  + GLint mUniformCheckCountLocation;
Add comment 1534 Minus  +};
Add comment 1535 Minus  +
Add comment 1536 Minus  +TEST_P(VariableRasterizationRateTestMetal, Basic)
Add comment 1537 Minus  +{
Add comment 1538 Minus  + ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled(kVariableRasterizationRateExt));
Add comment 1539 Minus  +
Add comment 1540 Minus  + // Default is disabled
Add comment 1541 Minus  + EXPECT_FALSE(glIsEnabled(GL_VARIABLE_RASTERIZATION_RATE_ANGLE));
Add comment 1542 Minus  +
Add comment 1543 Minus  + glEnable(GL_VARIABLE_RASTERIZATION_RATE_ANGLE);
Add comment 1544 Minus  + EXPECT_GL_NO_ERROR();
Add comment 1545 Minus  + EXPECT_TRUE(glIsEnabled(GL_VARIABLE_RASTERIZATION_RATE_ANGLE));
Add comment 1546 Minus  +
Add comment 1547 Minus  + glDisable(GL_VARIABLE_RASTERIZATION_RATE_ANGLE);
Add comment 1548 Minus  + EXPECT_GL_NO_ERROR();
Add comment 1549 Minus  + EXPECT_FALSE(glIsEnabled(GL_VARIABLE_RASTERIZATION_RATE_ANGLE));
Add comment 1550 Minus  +}
Add comment 1551 Minus  +
Add comment 1552 Minus  +TEST_P(VariableRasterizationRateTestMetal, Binding)
Add comment 1553 Minus  +{
Add comment 1554 Minus  + ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled(kVariableRasterizationRateExt));
Add comment 1555 Minus  +
Add comment 1556 Minus  + auto rateMapMtl =
Add comment 1557 Minus  + createMetalRasterizationRateMap(kWindowWidth, kWindowHeight, kQuality, kQuality);
Add comment 1558 Minus  + glBindMetalRasterizationRateMapANGLE(rateMapMtl);
Add comment 1559 Minus  + EXPECT_GL_NO_ERROR();
Add comment 1560 Minus  +
Add comment 1561 Minus  + GLMTLRasterizationRateMapANGLE rateMapBinding = nullptr;
Add comment 1562 Minus  + glGetPointerv(GL_METAL_RASTERIZATION_RATE_MAP_BINDING_ANGLE, &rateMapBinding);
Add comment 1563 Minus  + EXPECT_GL_NO_ERROR();
Add comment 1564 Minus  + EXPECT_EQ(rateMapMtl, rateMapBinding);
Add comment 1565 Minus  +}
Add comment 1566 Minus  +
Add comment 1567 Minus  +TEST_P(VariableRasterizationRateTestMetal, Rendering)
Add comment 1568 Minus  +{
Add comment 1569 Minus  + ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled(kVariableRasterizationRateExt));
Add comment 1570 Minus  + EXPECT_GL_NO_ERROR();
Add comment 1571 Minus  +
Add comment 1572 Minus  + auto rateMapMtl =
Add comment 1573 Minus  + createMetalRasterizationRateMap(kWindowWidth, kWindowHeight, kQuality, kQuality);
Add comment 1574 Minus  + auto screenSize = rateMapMtl.screenSize();
Add comment 1575 Minus  + EXPECT_EQ(screenSize.width, static_cast<NSUInteger>(kWindowWidth));
Add comment 1576 Minus  + EXPECT_EQ(screenSize.height, static_cast<NSUInteger>(kWindowHeight));
Add comment 1577 Minus  + auto viewportSize = rateMapMtl.viewportSize();
Add comment 1578 Minus  + EXPECT_EQ(viewportSize.width, static_cast<NSUInteger>(kViewportWidth));
Add comment 1579 Minus  + EXPECT_EQ(viewportSize.height, static_cast<NSUInteger>(kViewportHeight));
Add comment 1580 Minus  +
Add comment 1581 Minus  + GLTexture rbColor;
Add comment 1582 Minus  + glBindTexture(GL_TEXTURE_2D, rbColor);
Add comment 1583 Minus  + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, viewportSize.width, viewportSize.height, 0, GL_RGBA,
Add comment 1584 Minus  + GL_UNSIGNED_BYTE, nullptr);
Add comment 1585 Minus  +
Add comment 1586 Minus  + GLFramebuffer fbo;
Add comment 1587 Minus  + glBindFramebuffer(GL_FRAMEBUFFER, fbo);
Add comment 1588 Minus  + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rbColor, 0);
Add comment 1589 Minus  + EXPECT_GL_NO_ERROR();
Add comment 1590 Minus  +
Add comment 1591 Minus  + glBindMetalRasterizationRateMapANGLE(rateMapMtl);
Add comment 1592 Minus  + glEnable(GL_VARIABLE_RASTERIZATION_RATE_ANGLE);
Add comment 1593 Minus  +
Add comment 1594 Minus  + glScissor(0, 0, screenSize.width, screenSize.height);
Add comment 1595 Minus  + glViewport(0, 0, screenSize.width, screenSize.height);
Add comment 1596 Minus  +
Add comment 1597 Minus  + glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
Add comment 1598 Minus  + glClear(GL_COLOR_BUFFER_BIT);
Add comment 1599 Minus  + EXPECT_GL_NO_ERROR();
Add comment 1600 Minus  +
Add comment 1601 Minus  + glUseProgram(mProgram);
Add comment 1602 Minus  + if (mUniformResolutionLocation != -1)
Add comment 1603 Minus  + glUniform2f(mUniformResolutionLocation, viewportSize.width, viewportSize.height);
Add comment 1604 Minus  + if (mUniformCheckCountLocation != -1)
Add comment 1605 Minus  + glUniform1f(mUniformCheckCountLocation, 9.0f);
Add comment 1606 Minus  + drawQuad(mProgram, "position", 0.5f);
Add comment 1607 Minus  +
Add comment 1608 Minus  + // Sample a selection of pixels to confirm the expected warped checkerboard rendering
Add comment 1609 Minus  + for (int o : std::array{6, 38, 67})
Add comment 1610 Minus  + {
Add comment 1611 Minus  + EXPECT_PIXEL_COLOR_NEAR(o + 0, o + 0, GLColor::white, 1.0);
Add comment 1612 Minus  + EXPECT_PIXEL_COLOR_NEAR(o + 1, o + 0, GLColor::black, 1.0);
Add comment 1613 Minus  + EXPECT_PIXEL_COLOR_NEAR(o + 0, o + 1, GLColor::black, 1.0);
Add comment 1614 Minus  + EXPECT_PIXEL_COLOR_NEAR(o + 1, o + 1, GLColor::white, 1.0);
Add comment 1615 Minus  + }
Add comment 1616 Minus  +}
Add comment 1617 Minus  +
Add comment 1618 Minus  +// FIXME: Add test to verify behavior of VRR map created with a Metal device
Add comment 1619 Minus  +// different to the one used by ANGLE.
Add comment 1620 Minus  +
Add comment 1621 Minus  +// Use this to select which configurations (e.g. which renderer, which GLES major version) these
Add comment 1622 Minus  +// tests should be run against.
Add comment 1623 Minus  +ANGLE_INSTANTIATE_TEST(VariableRasterizationRateTestMetal, ES2_METAL(), ES3_METAL());
Add comment 1624 Minus  +
Add comment 1625 Minus  +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ImageTestMetal);
Add comment 1626 Minus  +} // namespace angle
Add comment 1627 1346 diff --git a/util/autogen/angle_features_autogen.cpp b/util/autogen/angle_features_autogen.cpp
Add comment 1628 1347 index 33805db2b2..15c8b37f11 100644
Add comment 1629 1348 --- a/util/autogen/angle_features_autogen.cpp