Path: blob/main_old/src/tests/gl_tests/ActiveTextureCacheTest.cpp
1693 views
//1// Copyright 2020 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// ActiveTextureCacheTest.cpp: Regression tests of ANGLE's ActiveTextureCache inside gl::State.67#include "test_utils/ANGLETest.h"8#include "test_utils/gl_raii.h"910namespace angle11{1213class ActiveTextureCacheTest : public ANGLETest14{15protected:16ActiveTextureCacheTest()17{18setWindowWidth(128);19setWindowHeight(128);20setConfigRedBits(8);21setConfigGreenBits(8);22setConfigBlueBits(8);23setConfigAlphaBits(8);24}2526void testSetUp() override27{28constexpr char kVS[] =29"precision highp float;\n"30"\n"31"void main()\n"32"{\n"33" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);\n"34"}\n";3536constexpr char k2DFS[] =37"precision highp float;\n"38"uniform sampler2D tex2D;\n"39"uniform samplerCube texCube;\n"40"\n"41"void main()\n"42"{\n"43" gl_FragColor = texture2D(tex2D, vec2(0.0, 0.0)) + textureCube(texCube, vec3(0.0, "44"0.0, 0.0));\n"45"}\n";4647mProgram = CompileProgram(kVS, k2DFS);48ASSERT_NE(0u, mProgram);4950m2DTextureLocation = glGetUniformLocation(mProgram, "tex2D");51ASSERT_NE(-1, m2DTextureLocation);5253mCubeTextureLocation = glGetUniformLocation(mProgram, "texCube");54ASSERT_NE(-1, mCubeTextureLocation);55}5657void testTearDown() override { glDeleteProgram(mProgram); }5859GLuint mProgram = 0;60GLint m2DTextureLocation = -1;61GLint mCubeTextureLocation = -1;62};6364// Regression test for a bug that causes the ActiveTexturesCache to get out of sync with the65// currently bound textures when changing program uniforms in such a way that the program becomes66// invalid.67TEST_P(ActiveTextureCacheTest, UniformChangeUpdatesActiveTextureCache)68{69glUseProgram(mProgram);7071// Generate two textures and reset the texture binding72GLuint tex0 = 0;73glGenTextures(1, &tex0);74glBindTexture(GL_TEXTURE_2D, tex0);75glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);7677GLuint tex1 = 0;78glGenTextures(1, &tex1);79glBindTexture(GL_TEXTURE_2D, tex1);80glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);81glBindTexture(GL_TEXTURE_2D, 0);8283// Set the active texture to 1 and bind tex0.84glActiveTexture(GL_TEXTURE1);85glBindTexture(GL_TEXTURE_2D, tex0);8687// Point the program's 2D sampler at texture binding 1. The texture will be added to the88// ActiveTexturesCache because it matches the program's sampler type for this texture binding.89glUniform1i(m2DTextureLocation, 1);9091// Point the program's cube sampler to texture binding 1 as well. This causes the program's92// samplers become invalid and the ActiveTexturesCache is NOT updated.93glUniform1i(mCubeTextureLocation, 1);9495// Bind tex1. ActiveTexturesCache is NOT updated (still contains tex0). The current texture96// bindings do not match ActiveTexturesCache's state.97glBindTexture(GL_TEXTURE_2D, tex1);9899// Delete tex0. The ActiveTexturesCache entry that points to tex0 is not cleared because tex0 is100// not currently bound.101glDeleteTextures(1, &tex0);102103// Use-after-free occurs during context destruction when the ActiveTexturesCache is cleared.104}105106// Use this to select which configurations (e.g. which renderer, which GLES major version) these107// tests should be run against.108ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(ActiveTextureCacheTest);109110} // namespace angle111112113