Path: blob/main_old/src/tests/compiler_tests/OES_sample_variables_test.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// OES_sample_variables_test.cpp:6// Test for OES_sample_variables7//89#include "tests/test_utils/ShaderExtensionTest.h"1011namespace12{13const char OESPragma[] = "#extension GL_OES_sample_variables : require\n";1415// Shader using gl_SampleMask with non-constant index16// This shader is in the deqp test17// (functional_shaders_sample_variables_sample_mask_discard_half_per_sample_default_framebuffer)18const char ESSL310_GLSampleMaskShader[] =19R"(20layout(location = 0) out mediump vec4 fragColor;21void main (void)22{23for (int i = 0; i < gl_SampleMask.length(); ++i)24gl_SampleMask[i] = int(0xAAAAAAAA);2526// force per-sample shading27highp float blue = float(gl_SampleID);2829fragColor = vec4(0.0, 1.0, blue, 1.0);30})";3132// Shader using gl_SampleMask with non-constant index33// This shader is based on the deqp test on below34// (functional_shaders_sample_variables_sample_mask_in_bit_count_per_sample_multisample_texture_2)35const char ESSL310_GLSampleMaskInShader[] =36R"(37layout(location = 0) out mediump vec4 fragColor;38void main (void)39{40mediump int maskBitCount = 0;41for (int j = 0; j < gl_SampleMaskIn.length(); ++j)42{43for (int i = 0; i < 32; ++i)44{45if (((gl_SampleMaskIn[j] >> i) & 0x01) == 0x01)46{47++maskBitCount;48}49}50}5152// force per-sample shading53highp float blue = float(gl_SampleID);5455if (maskBitCount != 1)56fragColor = vec4(1.0, 0.0, blue, 1.0);57else58fragColor = vec4(0.0, 1.0, blue, 1.0);59})";6061class OESSampleVariablesTest : public sh::ShaderExtensionTest62{63public:64void InitializeCompiler() { InitializeCompiler(SH_GLSL_450_CORE_OUTPUT); }65void InitializeCompiler(ShShaderOutput shaderOutputType)66{67DestroyCompiler();6869mCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, testing::get<0>(GetParam()),70shaderOutputType, &mResources);71ASSERT_TRUE(mCompiler != nullptr) << "Compiler could not be constructed.";72}7374testing::AssertionResult TestShaderCompile(const char *pragma)75{76const char *shaderStrings[] = {testing::get<1>(GetParam()), pragma,77testing::get<2>(GetParam())};78bool success = sh::Compile(mCompiler, shaderStrings, 3, SH_VARIABLES | SH_OBJECT_CODE);79if (success)80{81return ::testing::AssertionSuccess() << "Compilation success";82}83return ::testing::AssertionFailure() << sh::GetInfoLog(mCompiler);84}85};8687// GLES3 needs OES_sample_variables extension88class OESSampleVariablesTestES31 : public OESSampleVariablesTest89{};9091// Extension flag is required to compile properly. Expect failure when it is92// not present.93TEST_P(OESSampleVariablesTestES31, CompileFailsWithoutExtension)94{95mResources.OES_sample_variables = 0;96InitializeCompiler();97EXPECT_FALSE(TestShaderCompile(OESPragma));98}99100// Extension directive is required to compile properly. Expect failure when101// it is not present.102TEST_P(OESSampleVariablesTestES31, CompileFailsWithExtensionWithoutPragma)103{104mResources.OES_sample_variables = 1;105InitializeCompiler();106EXPECT_FALSE(TestShaderCompile(""));107}108109// With extension flag and extension directive, compiling succeeds.110// Also test that the extension directive state is reset correctly.111#ifdef ANGLE_ENABLE_VULKAN112TEST_P(OESSampleVariablesTestES31, CompileSucceedsWithExtensionAndPragmaOnVulkan)113{114mResources.OES_sample_variables = 1;115InitializeCompiler(SH_SPIRV_VULKAN_OUTPUT);116EXPECT_TRUE(TestShaderCompile(OESPragma));117// Test reset functionality.118EXPECT_FALSE(TestShaderCompile(""));119EXPECT_TRUE(TestShaderCompile(OESPragma));120}121#endif122123INSTANTIATE_TEST_SUITE_P(CorrectESSL310Shaders,124OESSampleVariablesTestES31,125Combine(Values(SH_GLES3_1_SPEC),126Values(sh::ESSLVersion310),127Values(ESSL310_GLSampleMaskShader, ESSL310_GLSampleMaskInShader)));128129} // anonymous namespace130131132