Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/compiler_tests/OES_sample_variables_test.cpp
1693 views
1
//
2
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
5
//
6
// OES_sample_variables_test.cpp:
7
// Test for OES_sample_variables
8
//
9
10
#include "tests/test_utils/ShaderExtensionTest.h"
11
12
namespace
13
{
14
const char OESPragma[] = "#extension GL_OES_sample_variables : require\n";
15
16
// Shader using gl_SampleMask with non-constant index
17
// This shader is in the deqp test
18
// (functional_shaders_sample_variables_sample_mask_discard_half_per_sample_default_framebuffer)
19
const char ESSL310_GLSampleMaskShader[] =
20
R"(
21
layout(location = 0) out mediump vec4 fragColor;
22
void main (void)
23
{
24
for (int i = 0; i < gl_SampleMask.length(); ++i)
25
gl_SampleMask[i] = int(0xAAAAAAAA);
26
27
// force per-sample shading
28
highp float blue = float(gl_SampleID);
29
30
fragColor = vec4(0.0, 1.0, blue, 1.0);
31
})";
32
33
// Shader using gl_SampleMask with non-constant index
34
// This shader is based on the deqp test on below
35
// (functional_shaders_sample_variables_sample_mask_in_bit_count_per_sample_multisample_texture_2)
36
const char ESSL310_GLSampleMaskInShader[] =
37
R"(
38
layout(location = 0) out mediump vec4 fragColor;
39
void main (void)
40
{
41
mediump int maskBitCount = 0;
42
for (int j = 0; j < gl_SampleMaskIn.length(); ++j)
43
{
44
for (int i = 0; i < 32; ++i)
45
{
46
if (((gl_SampleMaskIn[j] >> i) & 0x01) == 0x01)
47
{
48
++maskBitCount;
49
}
50
}
51
}
52
53
// force per-sample shading
54
highp float blue = float(gl_SampleID);
55
56
if (maskBitCount != 1)
57
fragColor = vec4(1.0, 0.0, blue, 1.0);
58
else
59
fragColor = vec4(0.0, 1.0, blue, 1.0);
60
})";
61
62
class OESSampleVariablesTest : public sh::ShaderExtensionTest
63
{
64
public:
65
void InitializeCompiler() { InitializeCompiler(SH_GLSL_450_CORE_OUTPUT); }
66
void InitializeCompiler(ShShaderOutput shaderOutputType)
67
{
68
DestroyCompiler();
69
70
mCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, testing::get<0>(GetParam()),
71
shaderOutputType, &mResources);
72
ASSERT_TRUE(mCompiler != nullptr) << "Compiler could not be constructed.";
73
}
74
75
testing::AssertionResult TestShaderCompile(const char *pragma)
76
{
77
const char *shaderStrings[] = {testing::get<1>(GetParam()), pragma,
78
testing::get<2>(GetParam())};
79
bool success = sh::Compile(mCompiler, shaderStrings, 3, SH_VARIABLES | SH_OBJECT_CODE);
80
if (success)
81
{
82
return ::testing::AssertionSuccess() << "Compilation success";
83
}
84
return ::testing::AssertionFailure() << sh::GetInfoLog(mCompiler);
85
}
86
};
87
88
// GLES3 needs OES_sample_variables extension
89
class OESSampleVariablesTestES31 : public OESSampleVariablesTest
90
{};
91
92
// Extension flag is required to compile properly. Expect failure when it is
93
// not present.
94
TEST_P(OESSampleVariablesTestES31, CompileFailsWithoutExtension)
95
{
96
mResources.OES_sample_variables = 0;
97
InitializeCompiler();
98
EXPECT_FALSE(TestShaderCompile(OESPragma));
99
}
100
101
// Extension directive is required to compile properly. Expect failure when
102
// it is not present.
103
TEST_P(OESSampleVariablesTestES31, CompileFailsWithExtensionWithoutPragma)
104
{
105
mResources.OES_sample_variables = 1;
106
InitializeCompiler();
107
EXPECT_FALSE(TestShaderCompile(""));
108
}
109
110
// With extension flag and extension directive, compiling succeeds.
111
// Also test that the extension directive state is reset correctly.
112
#ifdef ANGLE_ENABLE_VULKAN
113
TEST_P(OESSampleVariablesTestES31, CompileSucceedsWithExtensionAndPragmaOnVulkan)
114
{
115
mResources.OES_sample_variables = 1;
116
InitializeCompiler(SH_SPIRV_VULKAN_OUTPUT);
117
EXPECT_TRUE(TestShaderCompile(OESPragma));
118
// Test reset functionality.
119
EXPECT_FALSE(TestShaderCompile(""));
120
EXPECT_TRUE(TestShaderCompile(OESPragma));
121
}
122
#endif
123
124
INSTANTIATE_TEST_SUITE_P(CorrectESSL310Shaders,
125
OESSampleVariablesTestES31,
126
Combine(Values(SH_GLES3_1_SPEC),
127
Values(sh::ESSLVersion310),
128
Values(ESSL310_GLSampleMaskShader, ESSL310_GLSampleMaskInShader)));
129
130
} // anonymous namespace
131
132