Hash :
d37c97d1
Author :
Date :
2023-04-17T00:00:00
Metal: Implement OES_shader_multisample_interpolation * Added support for sample qualifier and shader interpolation functions * Added MSL-specific AST transformations * Adjusted minimum fragment interpolation offset state query test so that accurate limits could be reported * Drive-by: Y-flip gl_SamplePosition adjustment * Renamed ANGLESampleMaskEnabled function constant to ANGLEMultisampledRendering to correctly reflect its usage Bug: angleproject:8097 Bug: angleproject:8131 Change-Id: I25c9f36487e29f05bb9fe874e146d06378fef975 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4440827 Reviewed-by: Kenneth Russell <kbr@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
//
// Copyright 2023 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Test state requests and compilation of tokens added by OES_shader_multisample_interpolation
#include "common/mathutil.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
namespace
{
class SampleMultisampleInterpolationTest : public ANGLETest<>
{
protected:
SampleMultisampleInterpolationTest()
{
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setExtensionsEnabled(false);
}
};
// Test state queries
TEST_P(SampleMultisampleInterpolationTest, StateQueries)
{
// New state queries fail without the extension
{
GLint bits = 0;
glGetIntegerv(GL_FRAGMENT_INTERPOLATION_OFFSET_BITS_OES, &bits);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
EXPECT_EQ(bits, 0);
GLfloat minOffset = 0.0f;
glGetFloatv(GL_MIN_FRAGMENT_INTERPOLATION_OFFSET_OES, &minOffset);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
EXPECT_EQ(minOffset, 0.0f);
GLfloat maxOffset = 0.0f;
glGetFloatv(GL_MAX_FRAGMENT_INTERPOLATION_OFFSET_OES, &maxOffset);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
EXPECT_EQ(maxOffset, 0.0f);
ASSERT_GL_NO_ERROR();
}
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_OES_shader_multisample_interpolation"));
// Implementation-dependent values
{
GLint bits = 0;
glGetIntegerv(GL_FRAGMENT_INTERPOLATION_OFFSET_BITS_OES, &bits);
EXPECT_GE(bits, 4);
GLfloat minOffset = 0.0f;
glGetFloatv(GL_MIN_FRAGMENT_INTERPOLATION_OFFSET_OES, &minOffset);
EXPECT_LE(minOffset, -0.5f + std::pow(2, -bits));
GLfloat maxOffset = 0.0f;
glGetFloatv(GL_MAX_FRAGMENT_INTERPOLATION_OFFSET_OES, &maxOffset);
EXPECT_GE(maxOffset, 0.5f - std::pow(2, -bits));
ASSERT_GL_NO_ERROR();
}
}
// Test gl_SampleMaskIn values with per-sample shading
TEST_P(SampleMultisampleInterpolationTest, SampleMaskInPerSample)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_OES_sample_variables"));
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_OES_shader_multisample_interpolation"));
const char kVS[] = R"(#version 300 es
#extension GL_OES_shader_multisample_interpolation : require
in vec4 a_position;
sample out float interpolant;
void main()
{
gl_Position = a_position;
interpolant = 0.5;
})";
const char kFS[] = R"(#version 300 es
#extension GL_OES_sample_variables : require
#extension GL_OES_shader_multisample_interpolation : require
precision highp float;
sample in float interpolant;
out vec4 color;
bool isPow2(int v)
{
return v != 0 && (v & (v - 1)) == 0;
}
void main()
{
float r = float(isPow2(gl_SampleMaskIn[0]));
color = vec4(r, interpolant, 0, 1);
})";
ANGLE_GL_PROGRAM(program, kVS, kFS);
glUseProgram(program);
for (GLint sampleCount : {0, 4})
{
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLRenderbuffer rbo;
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_RGBA8, 1, 1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
drawQuad(program, "a_position", 0.0);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
GLubyte pixel[4];
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
ASSERT_GL_NO_ERROR();
EXPECT_EQ(pixel[0], 255) << "Samples: " << sampleCount;
}
}
// Test gl_SampleMaskIn values with per-sample noperspective shading
TEST_P(SampleMultisampleInterpolationTest, SampleMaskInPerSampleNoPerspective)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_OES_sample_variables"));
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_OES_shader_multisample_interpolation"));
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_NV_shader_noperspective_interpolation"));
const char kVS[] = R"(#version 300 es
#extension GL_OES_shader_multisample_interpolation : require
#extension GL_NV_shader_noperspective_interpolation : require
in vec4 a_position;
noperspective sample out float interpolant;
void main()
{
gl_Position = a_position;
interpolant = 0.5;
})";
const char kFS[] = R"(#version 300 es
#extension GL_OES_sample_variables : require
#extension GL_OES_shader_multisample_interpolation : require
#extension GL_NV_shader_noperspective_interpolation : require
precision highp float;
noperspective sample in float interpolant;
out vec4 color;
bool isPow2(int v)
{
return v != 0 && (v & (v - 1)) == 0;
}
void main()
{
float r = float(isPow2(gl_SampleMaskIn[0]));
color = vec4(r, interpolant, 0, 1);
})";
ANGLE_GL_PROGRAM(program, kVS, kFS);
glUseProgram(program);
for (GLint sampleCount : {0, 4})
{
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLRenderbuffer rbo;
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_RGBA8, 1, 1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
drawQuad(program, "a_position", 0.0);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
GLubyte pixel[4];
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
ASSERT_GL_NO_ERROR();
EXPECT_EQ(pixel[0], 255) << "Samples: " << sampleCount;
}
}
// Test that a shader with interpolateAt* calls and directly used interpolants compiles
// successfully.
TEST_P(SampleMultisampleInterpolationTest, CompileInterpolateAt)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_OES_shader_multisample_interpolation"));
EnsureGLExtensionEnabled("GL_NV_shader_noperspective_interpolation");
constexpr char kVS[] = R"(#version 300 es
#extension GL_OES_shader_multisample_interpolation : require
#extension GL_NV_shader_noperspective_interpolation : enable
precision highp float;
out float interpolant;
out float interpolantArray[2];
centroid out float interpolantCentroid;
centroid out float interpolantCentroidArray[2];
sample out float interpolantSample;
sample out float interpolantSampleArray[2];
smooth out float interpolantSmooth;
smooth out float interpolantSmoothArray[2];
flat out float interpolantFlat;
flat out float interpolantFlatArray[2];
#ifdef GL_NV_shader_noperspective_interpolation
noperspective out float interpolantNp;
noperspective out float interpolantNpArray[2];
noperspective centroid out float interpolantNpCentroid;
noperspective centroid out float interpolantNpCentroidArray[2];
noperspective sample out float interpolantNpSample;
noperspective sample out float interpolantNpSampleArray[2];
#endif
void main()
{
gl_Position = vec4(0, 0, 0, 1);
interpolant = 1.0;
interpolantArray[1] = 2.0;
interpolantCentroid = 3.0;
interpolantCentroidArray[1] = 4.0;
interpolantSample = 5.0;
interpolantSampleArray[1] = 6.0;
interpolantSmooth = 7.0;
interpolantSmoothArray[1] = 8.0;
interpolantFlat = 9.0;
interpolantFlatArray[1] = 10.0;
#ifdef GL_NV_shader_noperspective_interpolation
interpolantNp = 11.0;
interpolantNpArray[1] = 12.0;
interpolantNpCentroid = 13.0;
interpolantNpCentroidArray[1] = 14.0;
interpolantNpSample = 15.0;
interpolantNpSampleArray[1] = 16.0;
#endif
})";
constexpr char kFS[] = R"(#version 300 es
#extension GL_OES_shader_multisample_interpolation : require
#extension GL_NV_shader_noperspective_interpolation : enable
precision highp float;
in float interpolant;
in float interpolantArray[2];
centroid in float interpolantCentroid;
centroid in float interpolantCentroidArray[2];
sample in float interpolantSample;
sample in float interpolantSampleArray[2];
smooth in float interpolantSmooth;
smooth in float interpolantSmoothArray[2];
flat in float interpolantFlat;
flat in float interpolantFlatArray[2];
#ifdef GL_NV_shader_noperspective_interpolation
noperspective in float interpolantNp;
noperspective in float interpolantNpArray[2];
noperspective centroid in float interpolantNpCentroid;
noperspective centroid in float interpolantNpCentroidArray[2];
noperspective sample in float interpolantNpSample;
noperspective sample in float interpolantNpSampleArray[2];
#endif
out vec4 color;
void main()
{
float r;
r += interpolateAtCentroid(interpolant);
r += interpolateAtSample(interpolant, int(interpolant));
r += interpolateAtOffset(interpolant, vec2(interpolant));
r += interpolateAtCentroid(interpolantArray[1]);
r += interpolateAtSample(interpolantArray[1], int(interpolantArray[0]));
r += interpolateAtOffset(interpolantArray[1], vec2(interpolantArray[0]));
r += interpolateAtCentroid(interpolantCentroid);
r += interpolateAtSample(interpolantCentroid, int(interpolantCentroid));
r += interpolateAtOffset(interpolantCentroid, vec2(interpolantCentroid));
r += interpolateAtCentroid(interpolantCentroidArray[1]);
r += interpolateAtSample(interpolantCentroidArray[1], int(interpolantCentroidArray[0]));
r += interpolateAtOffset(interpolantCentroidArray[1], vec2(interpolantCentroidArray[0]));
r += interpolateAtCentroid(interpolantSample);
r += interpolateAtSample(interpolantSample, int(interpolantSample));
r += interpolateAtOffset(interpolantSample, vec2(interpolantSample));
r += interpolateAtCentroid(interpolantSampleArray[1]);
r += interpolateAtSample(interpolantSampleArray[1], int(interpolantSampleArray[0]));
r += interpolateAtOffset(interpolantSampleArray[1], vec2(interpolantSampleArray[0]));
r += interpolateAtCentroid(interpolantSmooth);
r += interpolateAtSample(interpolantSmooth, int(interpolantSmooth));
r += interpolateAtOffset(interpolantSmooth, vec2(interpolantSmooth));
r += interpolateAtCentroid(interpolantSmoothArray[1]);
r += interpolateAtSample(interpolantSmoothArray[1], int(interpolantSmoothArray[0]));
r += interpolateAtOffset(interpolantSmoothArray[1], vec2(interpolantSmoothArray[0]));
r += interpolateAtCentroid(interpolantFlat);
r += interpolateAtSample(interpolantFlat, int(interpolantFlat));
r += interpolateAtOffset(interpolantFlat, vec2(interpolantFlat));
r += interpolateAtCentroid(interpolantFlatArray[1]);
r += interpolateAtSample(interpolantFlatArray[1], int(interpolantFlatArray[0]));
r += interpolateAtOffset(interpolantFlatArray[1], vec2(interpolantFlatArray[0]));
#ifdef GL_NV_shader_noperspective_interpolation
r += interpolateAtCentroid(interpolantNp);
r += interpolateAtSample(interpolantNp, int(interpolantNp));
r += interpolateAtOffset(interpolantNp, vec2(interpolantNp));
r += interpolateAtCentroid(interpolantNpArray[1]);
r += interpolateAtSample(interpolantNpArray[1], int(interpolantNpArray[0]));
r += interpolateAtOffset(interpolantNpArray[1], vec2(interpolantNpArray[0]));
r += interpolateAtCentroid(interpolantNpCentroid);
r += interpolateAtSample(interpolantNpCentroid, int(interpolantNpCentroid));
r += interpolateAtOffset(interpolantNpCentroid, vec2(interpolantNpCentroid));
r += interpolateAtCentroid(interpolantNpCentroidArray[1]);
r += interpolateAtSample(interpolantNpCentroidArray[1], int(interpolantNpCentroidArray[0]));
r += interpolateAtOffset(interpolantNpCentroidArray[1], vec2(interpolantNpCentroidArray[0]));
r += interpolateAtCentroid(interpolantNpSample);
r += interpolateAtSample(interpolantNpSample, int(interpolantNpSample));
r += interpolateAtOffset(interpolantNpSample, vec2(interpolantNpSample));
r += interpolateAtCentroid(interpolantNpSampleArray[1]);
r += interpolateAtSample(interpolantNpSampleArray[1], int(interpolantNpSampleArray[0]));
r += interpolateAtOffset(interpolantNpSampleArray[1], vec2(interpolantNpSampleArray[0]));
#endif
color = vec4(r);
})";
ANGLE_GL_PROGRAM(program, kVS, kFS);
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SampleMultisampleInterpolationTest);
ANGLE_INSTANTIATE_TEST_ES3(SampleMultisampleInterpolationTest);
} // anonymous namespace