已开启
[ArkWeb][安全][自动提交] 修复 Chromium issue 496807874: Add split_level_0_pbo_full_sub_image_2d workaround. #461
[ArkWeb][安全][自动提交] 修复 Chromium issue 496807874: Add split_level_0_pbo_full_sub_image_2d workaround. #461
已开启
ringking0创建于 28 天前
3 个文件变更+138-140
@@ -1434,8 +1434,6 @@ angle::Result TextureGL::generateMipmap(const gl::Context *context)
1434 const gl::InternalFormat &baseLevelInternalFormat = *baseLevelDesc.format.info;1434 const gl::InternalFormat &baseLevelInternalFormat = *baseLevelDesc.format.info;
1435 1435 
1436 const LevelInfoGL &baseLevelInfo = getBaseLevelInfo();1436 const LevelInfoGL &baseLevelInfo = getBaseLevelInfo();
1437- 
1438- stateManager->bindTexture(getType(), mTextureID);
1439 if (features.useTempForNonZeroBaseLevelGenMipmapUsingCopyImageSubData.enabled &&1437 if (features.useTempForNonZeroBaseLevelGenMipmapUsingCopyImageSubData.enabled &&
1440 functions->copyImageSubData != nullptr && mState.getImmutableFormat() &&1438 functions->copyImageSubData != nullptr && mState.getImmutableFormat() &&
1441 getType() == gl::TextureType::_2D && effectiveBaseLevel > 0)1439 getType() == gl::TextureType::_2D && effectiveBaseLevel > 0)
@@ -2416,6 +2416,9 @@ void InitializeFeatures(const FunctionsGL *functions, angle::FeaturesGL *feature
2416 IsAndroid() || isAMD || !functions->hasExtension("GL_KHR_robust_buffer_access_behavior"));2416 IsAndroid() || isAMD || !functions->hasExtension("GL_KHR_robust_buffer_access_behavior"));
2417 2417 
2418 ANGLE_FEATURE_CONDITION(features, resetTexImage2DBaseLevel,2418 ANGLE_FEATURE_CONDITION(features, resetTexImage2DBaseLevel,
2419+ IsPowerVR(vendor));
2420+ 
2421+ ANGLE_FEATURE_CONDITION(features, useTempForNonZeroBaseLevelGenMipmapUsingCopyImageSubData,
2419 IsApple() && isIntel && GetMacOSVersion() >= OSVersion(10, 12, 4));2422 IsApple() && isIntel && GetMacOSVersion() >= OSVersion(10, 12, 4));
2420 2423 
2421 ANGLE_FEATURE_CONDITION(features, adjustSrcDstRegionForBlitFramebuffer,2424 ANGLE_FEATURE_CONDITION(features, adjustSrcDstRegionForBlitFramebuffer,
@@ -2569,9 +2572,6 @@ void InitializeFeatures(const FunctionsGL *functions, angle::FeaturesGL *feature
2569 // switching to workadround the driver issues.2572 // switching to workadround the driver issues.
2570 ANGLE_FEATURE_CONDITION(features, unbindFBOBeforeSwitchingContext, IsPowerVR(vendor));2573 ANGLE_FEATURE_CONDITION(features, unbindFBOBeforeSwitchingContext, IsPowerVR(vendor));
2571 2574 
2572- ANGLE_FEATURE_CONDITION(features, useTempForNonZeroBaseLevelGenMipmapUsingCopyImageSubData,
2573- IsPowerVR(vendor));
2574- 
2575 // http://crbug.com/1181068 and http://crbug.com/7839792575 // http://crbug.com/1181068 and http://crbug.com/783979
2576 ANGLE_FEATURE_CONDITION(features, flushOnFramebufferChange,2576 ANGLE_FEATURE_CONDITION(features, flushOnFramebufferChange,
2577 IsApple() && Has9thGenIntelGPU(systemInfo));2577 IsApple() && Has9thGenIntelGPU(systemInfo));
@@ -2639,6 +2639,141 @@ TEST_P(TextureCubeTest, CubeMapFBOScissoredClear)
2639 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);2639 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2640 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);2640 EXPECT_PIXEL_COLOR_EQ(kSize / 2 + 1, 0, GLColor::green);
2641 2641 
2642+class Texture2DTestES3_NonZeroBaseLevelGenMipmaps : public Texture2DTestES3
2643+{};
2644+ 
2645+// Test that performing an upload after draw, and glGenerateMipmap
2646+// with non-zero base level, does not crash.
2647+TEST_P(Texture2DTestES3_NonZeroBaseLevelGenMipmaps, UploadAfterDrawShouldNotCrash)
2648+{
2649+ for (int k = 0; k < 4; ++k)
2650+ {
2651+ GLTexture tex;
2652+ glBindTexture(GL_TEXTURE_2D, tex);
2653+ glTexStorage2D(GL_TEXTURE_2D, 12, GL_RGBA8, 3, 2048);
2654+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
2655+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2656+ 
2657+ drawQuad(mProgram, "position", 0.5f);
2658+ glFinish();
2659+ 
2660+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10);
2661+ glGenerateMipmap(GL_TEXTURE_2D);
2662+ glFinish();
2663+ EXPECT_GL_NO_ERROR();
2664+ 
2665+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2666+ std::vector<uint8_t> data(1 * 1024 * 4, 0x41);
2667+ glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 1, 1024, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
2668+ EXPECT_GL_NO_ERROR();
2669+ }
2670+}
2671+ 
2672+// Test that generating mipmaps with non-zero base level preserves texture contents across all mip
2673+// levels.
2674+TEST_P(Texture2DTestES3_NonZeroBaseLevelGenMipmaps, VerifyMipmapContents)
2675+{
2676+ GLTexture texture;
2677+ glBindTexture(GL_TEXTURE_2D, texture);
2678+ 
2679+ // Allocate 6 levels (levels 0 to 5) for a 32x32 immutable RGBA8 texture.
2680+ glTexStorage2D(GL_TEXTURE_2D, 6, GL_RGBA8, 32, 32);
2681+ 
2682+ // Set base level to 1 and max level to 4.
2683+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2684+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4);
2685+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
2686+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2687+ 
2688+ // Upload different data (e.g. solid blue) to level 0 (32x32).
2689+ std::vector<GLColor> level0Data(32 * 32, GLColor::blue);
2690+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 32, 32, GL_RGBA, GL_UNSIGNED_BYTE, level0Data.data());
2691+ 
2692+ // Upload distinct data (solid cyan) to level 5 (1x1) to verify it is untouched.
2693+ std::vector<GLColor> level5Data(1 * 1, GLColor::cyan);
2694+ glTexSubImage2D(GL_TEXTURE_2D, 5, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, level5Data.data());
2695+ 
2696+ // Upload a square 2x2 checkerboard pattern to level 1 (16x16).
2697+ // Top-left: Red, Top-right: Green, Bottom-left: Yellow, Bottom-right: Magenta.
2698+ std::vector<GLColor> level1Data(16 * 16);
2699+ for (int y = 0; y < 16; ++y)
2700+ {
2701+ for (int x = 0; x < 16; ++x)
2702+ {
2703+ if (x < 8 && y < 8)
2704+ {
2705+ level1Data[y * 16 + x] = GLColor::red;
2706+ }
2707+ else if (x >= 8 && y < 8)
2708+ {
2709+ level1Data[y * 16 + x] = GLColor::green;
2710+ }
2711+ else if (x < 8 && y >= 8)
2712+ {
2713+ level1Data[y * 16 + x] = GLColor::yellow;
2714+ }
2715+ else
2716+ {
2717+ level1Data[y * 16 + x] = GLColor::magenta;
2718+ }
2719+ }
2720+ }
2721+ glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, level1Data.data());
2722+ 
2723+ // Generate mipmaps with base level = 1 and max level = 4.
2724+ glGenerateMipmap(GL_TEXTURE_2D);
2725+ ASSERT_GL_NO_ERROR();
2726+ 
2727+ // Verify that the four colors are preserved correctly in each quadrant up to max level (level
2728+ // 4).
2729+ GLFramebuffer fbo;
2730+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2731+ 
2732+ for (int level = 1; level <= 4; ++level)
2733+ {
2734+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
2735+ ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2736+ 
2737+ int dim = 32 >> level; // level 1: 16, level 2: 8, level 3: 4, level 4: 2
2738+ int half = dim / 2;
2739+ 
2740+ // Top-left quadrant (Red)
2741+ EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2742+ EXPECT_PIXEL_COLOR_EQ(half - 1, half - 1, GLColor::red);
2743+ 
2744+ // Top-right quadrant (Green)
2745+ EXPECT_PIXEL_COLOR_EQ(half, 0, GLColor::green);
2746+ EXPECT_PIXEL_COLOR_EQ(dim - 1, half - 1, GLColor::green);
2747+ 
2748+ // Bottom-left quadrant (Yellow)
2749+ EXPECT_PIXEL_COLOR_EQ(0, half, GLColor::yellow);
2750+ EXPECT_PIXEL_COLOR_EQ(half - 1, dim - 1, GLColor::yellow);
2751+ 
2752+ // Bottom-right quadrant (Magenta)
2753+ EXPECT_PIXEL_COLOR_EQ(half, half, GLColor::magenta);
2754+ EXPECT_PIXEL_COLOR_EQ(dim - 1, dim - 1, GLColor::magenta);
2755+ }
2756+ 
2757+ // At the end of the test, verify that level 0's contents and level 5's contents were preserved.
2758+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
2759+ ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2760+ EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
2761+ EXPECT_PIXEL_COLOR_EQ(15, 15, GLColor::blue);
2762+ EXPECT_PIXEL_COLOR_EQ(31, 31, GLColor::blue);
2763+ 
2764+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 5);
2765+ ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2766+ EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2767+ 
2768+ EXPECT_GL_NO_ERROR();
2769+}
2770+ 
2771+GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(Texture2DTestES3_NonZeroBaseLevelGenMipmaps);
2772+ANGLE_INSTANTIATE_TEST_ES3_AND(
2773+ Texture2DTestES3_NonZeroBaseLevelGenMipmaps,
2774+ ES3_OPENGL().enable(Feature::UseTempForNonZeroBaseLevelGenMipmapUsingCopyImageSubData),
2775+ ES3_OPENGLES().enable(Feature::UseTempForNonZeroBaseLevelGenMipmapUsingCopyImageSubData));
2776+ 
2642 ASSERT_GL_NO_ERROR();2777 ASSERT_GL_NO_ERROR();
2643}2778}
2644 2779 
@@ -19047,141 +19182,6 @@ TEST_P(CopyImageTestES31, Norm16ToCompressed)
19047 CopyImageCompressedWithNorm16(false);19182 CopyImageCompressedWithNorm16(false);
19048}19183}
19049 19184 
19050-class Texture2DTestES3_NonZeroBaseLevelGenMipmaps : public Texture2DTestES3
19051-{};
19052- 
19053-// Test that performing an upload after draw, and glGenerateMipmap
19054-// with non-zero base level, does not crash.
19055-TEST_P(Texture2DTestES3_NonZeroBaseLevelGenMipmaps, UploadAfterDrawShouldNotCrash)
19056-{
19057- for (int k = 0; k < 4; ++k)
19058- {
19059- GLTexture tex;
19060- glBindTexture(GL_TEXTURE_2D, tex);
19061- glTexStorage2D(GL_TEXTURE_2D, 12, GL_RGBA8, 3, 2048);
19062- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
19063- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
19064- 
19065- drawQuad(mProgram, "position", 0.5f);
19066- glFinish();
19067- 
19068- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10);
19069- glGenerateMipmap(GL_TEXTURE_2D);
19070- glFinish();
19071- EXPECT_GL_NO_ERROR();
19072- 
19073- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
19074- std::vector<uint8_t> data(1 * 1024 * 4, 0x41);
19075- glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 1, 1024, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
19076- EXPECT_GL_NO_ERROR();
19077- }
19078-}
19079- 
19080-// Test that generating mipmaps with non-zero base level preserves texture contents across all mip
19081-// levels.
19082-TEST_P(Texture2DTestES3_NonZeroBaseLevelGenMipmaps, VerifyMipmapContents)
19083-{
19084- GLTexture texture;
19085- glBindTexture(GL_TEXTURE_2D, texture);
19086- 
19087- // Allocate 6 levels (levels 0 to 5) for a 32x32 immutable RGBA8 texture.
19088- glTexStorage2D(GL_TEXTURE_2D, 6, GL_RGBA8, 32, 32);
19089- 
19090- // Set base level to 1 and max level to 4.
19091- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
19092- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4);
19093- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
19094- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
19095- 
19096- // Upload different data (e.g. solid blue) to level 0 (32x32).
19097- std::vector<GLColor> level0Data(32 * 32, GLColor::blue);
19098- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 32, 32, GL_RGBA, GL_UNSIGNED_BYTE, level0Data.data());
19099- 
19100- // Upload distinct data (solid cyan) to level 5 (1x1) to verify it is untouched.
19101- std::vector<GLColor> level5Data(1 * 1, GLColor::cyan);
19102- glTexSubImage2D(GL_TEXTURE_2D, 5, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, level5Data.data());
19103- 
19104- // Upload a square 2x2 checkerboard pattern to level 1 (16x16).
19105- // Top-left: Red, Top-right: Green, Bottom-left: Yellow, Bottom-right: Magenta.
19106- std::vector<GLColor> level1Data(16 * 16);
19107- for (int y = 0; y < 16; ++y)
19108- {
19109- for (int x = 0; x < 16; ++x)
19110- {
19111- if (x < 8 && y < 8)
19112- {
19113- level1Data[y * 16 + x] = GLColor::red;
19114- }
19115- else if (x >= 8 && y < 8)
19116- {
19117- level1Data[y * 16 + x] = GLColor::green;
19118- }
19119- else if (x < 8 && y >= 8)
19120- {
19121- level1Data[y * 16 + x] = GLColor::yellow;
19122- }
19123- else
19124- {
19125- level1Data[y * 16 + x] = GLColor::magenta;
19126- }
19127- }
19128- }
19129- glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 16, 16, GL_RGBA, GL_UNSIGNED_BYTE, level1Data.data());
19130- 
19131- // Generate mipmaps with base level = 1 and max level = 4.
19132- glGenerateMipmap(GL_TEXTURE_2D);
19133- ASSERT_GL_NO_ERROR();
19134- 
19135- // Verify that the four colors are preserved correctly in each quadrant up to max level (level
19136- // 4).
19137- GLFramebuffer fbo;
19138- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
19139- 
19140- for (int level = 1; level <= 4; ++level)
19141- {
19142- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, level);
19143- ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
19144- 
19145- int dim = 32 >> level; // level 1: 16, level 2: 8, level 3: 4, level 4: 2
19146- int half = dim / 2;
19147- 
19148- // Top-left quadrant (Red)
19149- EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
19150- EXPECT_PIXEL_COLOR_EQ(half - 1, half - 1, GLColor::red);
19151- 
19152- // Top-right quadrant (Green)
19153- EXPECT_PIXEL_COLOR_EQ(half, 0, GLColor::green);
19154- EXPECT_PIXEL_COLOR_EQ(dim - 1, half - 1, GLColor::green);
19155- 
19156- // Bottom-left quadrant (Yellow)
19157- EXPECT_PIXEL_COLOR_EQ(0, half, GLColor::yellow);
19158- EXPECT_PIXEL_COLOR_EQ(half - 1, dim - 1, GLColor::yellow);
19159- 
19160- // Bottom-right quadrant (Magenta)
19161- EXPECT_PIXEL_COLOR_EQ(half, half, GLColor::magenta);
19162- EXPECT_PIXEL_COLOR_EQ(dim - 1, dim - 1, GLColor::magenta);
19163- }
19164- 
19165- // At the end of the test, verify that level 0's contents and level 5's contents were preserved.
19166- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
19167- ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
19168- EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
19169- EXPECT_PIXEL_COLOR_EQ(15, 15, GLColor::blue);
19170- EXPECT_PIXEL_COLOR_EQ(31, 31, GLColor::blue);
19171- 
19172- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 5);
19173- ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
19174- EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
19175- 
19176- EXPECT_GL_NO_ERROR();
19177-}
19178- 
19179-GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(Texture2DTestES3_NonZeroBaseLevelGenMipmaps);
19180-ANGLE_INSTANTIATE_TEST_ES3_AND(
19181- Texture2DTestES3_NonZeroBaseLevelGenMipmaps,
19182- ES3_OPENGL().enable(Feature::UseTempForNonZeroBaseLevelGenMipmapUsingCopyImageSubData),
19183- ES3_OPENGLES().enable(Feature::UseTempForNonZeroBaseLevelGenMipmapUsingCopyImageSubData));
19184- 
19185class TextureChangeStorageUploadTest : public ANGLETest<>19185class TextureChangeStorageUploadTest : public ANGLETest<>
19186{19186{
19187 protected:19187 protected: