chromium/gpu/command_buffer/service/program_manager_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "gpu/command_buffer/service/program_manager.h"

#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <memory>

#include "base/command_line.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "gpu/command_buffer/common/gles2_cmd_format.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/command_buffer/service/common_decoder.h"
#include "gpu/command_buffer/service/decoder_client.h"
#include "gpu/command_buffer/service/feature_info.h"
#include "gpu/command_buffer/service/gpu_service_test.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/command_buffer/service/mocks.h"
#include "gpu/command_buffer/service/shader_manager.h"
#include "gpu/command_buffer/service/test_helper.h"
#include "gpu/config/gpu_preferences.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/gl_mock.h"

_;
DoAll;
Exactly;
InSequence;
MatcherCast;
Pointee;
Return;
ReturnRef;
SetArrayArgument;
SetArgPointee;
StrEq;

namespace gpu {
namespace gles2 {

namespace {
const uint32_t kMaxVaryingVectors =;
const uint32_t kMaxDrawBuffers =;
const uint32_t kMaxDualSourceDrawBuffers =;
const uint32_t kMaxVertexAttribs =;

uint32_t ComputeOffset(const void* start, const void* position) {}

}  // namespace anonymous

class ProgramManagerTestBase : public GpuServiceTest, public DecoderClient {};

class ProgramManagerTest : public ProgramManagerTestBase {};

TEST_F(ProgramManagerTest, Basic) {}

TEST_F(ProgramManagerTest, Destroy) {}

TEST_F(ProgramManagerTest, DeleteBug) {}

TEST_F(ProgramManagerTest, Program) {}

class ProgramManagerWithShaderTest : public ProgramManagerTestBase {};

ProgramManagerWithShaderTest::AttribInfo
    ProgramManagerWithShaderTest::kAttribs[] =;

// GCC requires these declarations, but MSVC requires they not be present
#ifndef COMPILER_MSVC
const GLint ProgramManagerWithShaderTest::kNumVertexAttribs;
const GLuint ProgramManagerWithShaderTest::kClientProgramId;
const GLuint ProgramManagerWithShaderTest::kServiceProgramId;
const GLuint ProgramManagerWithShaderTest::kVertexShaderClientId;
const GLuint ProgramManagerWithShaderTest::kFragmentShaderClientId;
const GLuint ProgramManagerWithShaderTest::kVertexShaderServiceId;
const GLuint ProgramManagerWithShaderTest::kFragmentShaderServiceId;
const GLint ProgramManagerWithShaderTest::kAttrib1Size;
const GLint ProgramManagerWithShaderTest::kAttrib2Size;
const GLint ProgramManagerWithShaderTest::kAttrib3Size;
const GLint ProgramManagerWithShaderTest::kAttrib4Size;
const GLint ProgramManagerWithShaderTest::kAttrib1Location;
const GLint ProgramManagerWithShaderTest::kAttrib2Location;
const GLint ProgramManagerWithShaderTest::kAttrib3Location;
const GLint ProgramManagerWithShaderTest::kAttrib4Location;
const GLenum ProgramManagerWithShaderTest::kAttrib1Type;
const GLenum ProgramManagerWithShaderTest::kAttrib2Type;
const GLenum ProgramManagerWithShaderTest::kAttrib3Type;
const GLenum ProgramManagerWithShaderTest::kAttrib4Type;
const GLint ProgramManagerWithShaderTest::kInvalidAttribLocation;
const GLint ProgramManagerWithShaderTest::kBadAttribIndex;
const GLint ProgramManagerWithShaderTest::kUniform1Size;
const GLint ProgramManagerWithShaderTest::kUniform2Size;
const GLint ProgramManagerWithShaderTest::kUniform3Size;
const GLint ProgramManagerWithShaderTest::kUniform1FakeLocation;
const GLint ProgramManagerWithShaderTest::kUniform2FakeLocation;
const GLint ProgramManagerWithShaderTest::kUniform3FakeLocation;
const GLint ProgramManagerWithShaderTest::kUniform1RealLocation;
const GLint ProgramManagerWithShaderTest::kUniform2RealLocation;
const GLint ProgramManagerWithShaderTest::kUniform3RealLocation;
const GLint ProgramManagerWithShaderTest::kUniform1DesiredLocation;
const GLint ProgramManagerWithShaderTest::kUniform2DesiredLocation;
const GLint ProgramManagerWithShaderTest::kUniform3DesiredLocation;
const GLenum ProgramManagerWithShaderTest::kUniform1Type;
const GLenum ProgramManagerWithShaderTest::kUniform2Type;
const GLenum ProgramManagerWithShaderTest::kUniform3Type;
const GLint ProgramManagerWithShaderTest::kInvalidUniformLocation;
const GLint ProgramManagerWithShaderTest::kBadUniformIndex;
#endif

const size_t ProgramManagerWithShaderTest::kNumAttribs =;

ProgramManagerWithShaderTest::UniformInfo
    ProgramManagerWithShaderTest::kUniforms[] =;

const size_t ProgramManagerWithShaderTest::kNumUniforms =;

const char* ProgramManagerWithShaderTest::kAttrib1Name =;
const char* ProgramManagerWithShaderTest::kAttrib2Name =;
const char* ProgramManagerWithShaderTest::kAttrib3Name =;
const char* ProgramManagerWithShaderTest::kAttrib4Name =;
const char* ProgramManagerWithShaderTest::kUniform1Name =;
const char* ProgramManagerWithShaderTest::kUniform2Name =;
const char* ProgramManagerWithShaderTest::kUniform2NameWithArrayIndex =;
const char* ProgramManagerWithShaderTest::kUniform3Name =;
const char* ProgramManagerWithShaderTest::kUniform3NameWithArrayIndex =;
const char* ProgramManagerWithShaderTest::kOutputVariable1Name =;

TEST_F(ProgramManagerWithShaderTest, GetAttribInfos) {}

TEST_F(ProgramManagerWithShaderTest, GetAttribInfo) {}

TEST_F(ProgramManagerWithShaderTest, GetAttribInfoByLocation) {}

TEST_F(ProgramManagerWithShaderTest, GetAttribLocation) {}

TEST_F(ProgramManagerWithShaderTest, VertexArrayMasks) {}

TEST_F(ProgramManagerWithShaderTest, GetUniformInfo) {}

TEST_F(ProgramManagerWithShaderTest, AttachDetachShader) {}

TEST_F(ProgramManagerWithShaderTest, GetUniformFakeLocation) {}

TEST_F(ProgramManagerWithShaderTest, GetUniformInfoByFakeLocation) {}

// Ensure that when GL drivers correctly return gl_DepthRange, or other
// builtin uniforms, our implementation passes them back to the client.
TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsGLUnderscoreUniform) {}

// Test the bug comparing similar array names is fixed.
TEST_F(ProgramManagerWithShaderTest, SimilarArrayNames) {}

// Some GL drivers incorrectly return the wrong type. For example they return
// GL_FLOAT_VEC2 when they should return GL_FLOAT_MAT2. Check we handle this.
TEST_F(ProgramManagerWithShaderTest, GLDriverReturnsWrongTypeInfo) {}

TEST_F(ProgramManagerWithShaderTest, ProgramInfoUseCount) {}

TEST_F(ProgramManagerWithShaderTest, ProgramInfoUseCount2) {}

TEST_F(ProgramManagerWithShaderTest, ProgramInfoGetProgramInfo) {}

TEST_F(ProgramManagerWithShaderTest, ProgramInfoGetUniformBlocksNone) {}

TEST_F(ProgramManagerWithShaderTest, ProgramInfoGetUniformBlocksValid) {}

TEST_F(ProgramManagerWithShaderTest,
       ProgramInfoGetTransformFeedbackVaryingsNone) {}

TEST_F(ProgramManagerWithShaderTest,
       ProgramInfoGetTransformFeedbackVaryingsValid) {}

TEST_F(ProgramManagerWithShaderTest, ProgramInfoGetUniformsES3None) {}

TEST_F(ProgramManagerWithShaderTest, ProgramInfoGetUniformsES3Valid) {}

// Some drivers optimize out unused uniform array elements, so their
// location would be -1.
TEST_F(ProgramManagerWithShaderTest, UnusedUniformArrayElements) {}

TEST_F(ProgramManagerWithShaderTest, BindAttribLocationConflicts) {}

TEST_F(ProgramManagerWithShaderTest, UniformsPrecisionMismatch) {}

// If a varying has different type in the vertex and fragment
// shader, linking should fail.
TEST_F(ProgramManagerWithShaderTest, VaryingTypeMismatch) {}

// If a varying has different array size in the vertex and fragment
// shader, linking should fail.
TEST_F(ProgramManagerWithShaderTest, VaryingArraySizeMismatch) {}

// If a varying has different precision in the vertex and fragment
// shader, linking should succeed.
TEST_F(ProgramManagerWithShaderTest, VaryingPrecisionMismatch) {}

// If a varying is statically used in fragment shader but not
// declared in vertex shader, link should fail.
TEST_F(ProgramManagerWithShaderTest, VaryingMissing) {}

// If a varying is declared but not statically used in fragment
// shader, even if it's not declared in vertex shader, link should
// succeed.
TEST_F(ProgramManagerWithShaderTest, InactiveVarying) {}

// Uniforms and attributes are both global variables, thus sharing
// the same namespace. Any name conflicts should cause link
// failure.
TEST_F(ProgramManagerWithShaderTest, AttribUniformNameConflict) {}

TEST_F(ProgramManagerWithShaderTest, FragmentOutputTypes) {}

// Varyings go over 8 rows.
TEST_F(ProgramManagerWithShaderTest, TooManyVaryings) {}

// Varyings go over 8 rows but some are inactive
TEST_F(ProgramManagerWithShaderTest, TooManyInactiveVaryings) {}

TEST_F(ProgramManagerWithShaderTest, BindUniformLocation) {}

TEST_F(ProgramManagerWithShaderTest, ZeroSizeUniformMarkedInvalid) {}

class ProgramManagerWithCacheTest : public ProgramManagerTestBase {};

// GCC requires these declarations, but MSVC requires they not be present
#ifndef COMPILER_MSVC
const GLuint ProgramManagerWithCacheTest::kClientProgramId;
const GLuint ProgramManagerWithCacheTest::kServiceProgramId;
const GLuint ProgramManagerWithCacheTest::kVertexShaderClientId;
const GLuint ProgramManagerWithCacheTest::kFragmentShaderClientId;
const GLuint ProgramManagerWithCacheTest::kVertexShaderServiceId;
const GLuint ProgramManagerWithCacheTest::kFragmentShaderServiceId;
#endif

TEST_F(ProgramManagerWithCacheTest, CacheProgramOnSuccessfulLink) {}

TEST_F(ProgramManagerWithCacheTest, LoadProgramOnProgramCacheHit) {}

TEST_F(ProgramManagerWithCacheTest, RelinkOnChangedCompileOptions) {}

// For some compilers, using make_tuple("a", "bb") would end up
// instantiating make_tuple<char[1], char[2]>. This does not work.
namespace {
testing::tuple<const char*, const char*> make_gl_ext_tuple(
    const char* gl_version,
    const char* gl_extensions) {}
}

class ProgramManagerDualSourceBlendingTest
    : public ProgramManagerWithShaderTest,
      public testing::WithParamInterface<
          testing::tuple<const char*, const char*>> {};

class ProgramManagerDualSourceBlendingES2Test
    : public ProgramManagerDualSourceBlendingTest {};

TEST_P(ProgramManagerDualSourceBlendingES2Test, UseSecondaryFragCoord) {}

TEST_P(ProgramManagerDualSourceBlendingES2Test, UseSecondaryFragData) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace gles2
}  // namespace gpu