Path: blob/main_old/src/tests/gl_tests/D3D11InputLayoutCacheTest.cpp
1693 views
//1// Copyright 2015 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// D3D11InputLayoutCacheTest:6// Stress to to reproduce a bug where we weren't fluing the case correctly.7//89#include <sstream>1011#include "libANGLE/Context.h"12#include "libANGLE/renderer/d3d/d3d11/Context11.h"13#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"14#include "test_utils/ANGLETest.h"15#include "test_utils/angle_test_instantiate.h"16#include "util/EGLWindow.h"1718using namespace angle;1920namespace21{2223class D3D11InputLayoutCacheTest : public ANGLETest24{25protected:26D3D11InputLayoutCacheTest()27{28setWindowWidth(64);29setWindowHeight(64);30setConfigRedBits(8);31setConfigAlphaBits(8);32}3334GLuint makeProgramWithAttribCount(unsigned int attribCount)35{36std::stringstream strstr;3738strstr << "attribute vec2 position;" << std::endl;39for (unsigned int attribIndex = 0; attribIndex < attribCount; ++attribIndex)40{41strstr << "attribute float a" << attribIndex << ";" << std::endl;42}43strstr << "varying float v;" << std::endl44<< "void main() {" << std::endl45<< " v = 0.0;" << std::endl;46for (unsigned int attribIndex = 0; attribIndex < attribCount; ++attribIndex)47{48strstr << " v += a" << attribIndex << ";" << std::endl;49}50strstr << " gl_Position = vec4(position, 0.0, 1.0);" << std::endl << "}" << std::endl;5152constexpr char kFS[] =53"varying highp float v;\n"54"void main() {"55" gl_FragColor = vec4(v / 255.0, 0.0, 0.0, 1.0);\n"56"}\n";5758return CompileProgram(strstr.str().c_str(), kFS);59}60};6162// Stress the cache by setting a small cache size and drawing with a bunch of shaders63// with different input signatures.64TEST_P(D3D11InputLayoutCacheTest, StressTest)65{66// Hack the ANGLE!67gl::Context *context = static_cast<gl::Context *>(getEGLWindow()->getContext());68rx::Context11 *context11 = rx::GetImplAs<rx::Context11>(context);69rx::Renderer11 *renderer11 = context11->getRenderer();70rx::InputLayoutCache *inputLayoutCache = renderer11->getStateManager()->getInputLayoutCache();7172// Clamp the cache size to something tiny73inputLayoutCache->setCacheSize(4);7475GLint maxAttribs = 0;76context->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxAttribs);7778// Reserve one attrib for position79unsigned int maxInputs = static_cast<unsigned int>(maxAttribs) - 2;8081std::vector<GLuint> programs;82for (unsigned int attribCount = 0; attribCount <= maxInputs; ++attribCount)83{84GLuint program = makeProgramWithAttribCount(attribCount);85ASSERT_NE(0u, program);86programs.push_back(program);87}8889// Iteratively do a simple drop operation, trying every attribute count from 0..MAX_ATTRIBS.90// This should thrash the cache.91for (unsigned int iterationCount = 0; iterationCount < 10; ++iterationCount)92{93ASSERT_GL_NO_ERROR();9495for (unsigned int attribCount = 0; attribCount <= maxInputs; ++attribCount)96{97GLuint program = programs[attribCount];98glUseProgram(program);99100for (unsigned int attribIndex = 0; attribIndex < attribCount; ++attribIndex)101{102std::stringstream attribNameStr;103attribNameStr << "a" << attribIndex;104std::string attribName = attribNameStr.str();105106GLint location = glGetAttribLocation(program, attribName.c_str());107ASSERT_NE(-1, location);108glVertexAttrib1f(location, 1.0f);109glDisableVertexAttribArray(location);110}111112drawQuad(program, "position", 0.5f);113EXPECT_PIXEL_EQ(0, 0, attribCount, 0, 0, 255u);114}115}116117for (GLuint program : programs)118{119glDeleteProgram(program);120}121}122123ANGLE_INSTANTIATE_TEST(D3D11InputLayoutCacheTest, ES2_D3D11(), ES3_D3D11(), ES31_D3D11());124125} // anonymous namespace126127128