Hash :
d193d51b
Author :
Date :
2024-06-17T22:46:08
Replace issue ids post migration to new issue tracker This change replaces anglebug.com/NNNN links. Bug: None Change-Id: I8ac3aec8d2a8a844b3d7b99fc0a6b2be8da31761 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5637912 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
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 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
//
// Copyright 2015 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.
//
#include "test_utils/ANGLETest.h"
#include <vector>
#include "test_utils/gl_raii.h"
using namespace angle;
class IncompleteTextureTest : public ANGLETest<>
{
protected:
IncompleteTextureTest()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
void testSetUp() override
{
constexpr char kVS[] = R"(precision highp float;
attribute vec4 position;
varying vec2 texcoord;
void main()
{
gl_Position = position;
texcoord = (position.xy * 0.5) + 0.5;
})";
constexpr char kFS[] = R"(precision highp float;
uniform sampler2D tex;
varying vec2 texcoord;
void main()
{
gl_FragColor = texture2D(tex, texcoord);
})";
mProgram = CompileProgram(kVS, kFS);
if (mProgram == 0)
{
FAIL() << "shader compilation failed.";
}
mTextureUniformLocation = glGetUniformLocation(mProgram, "tex");
}
void testTearDown() override { glDeleteProgram(mProgram); }
GLuint mProgram;
GLint mTextureUniformLocation;
};
class IncompleteTextureTestES3 : public ANGLETest<>
{
protected:
IncompleteTextureTestES3()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
public:
void setupFramebuffer(const GLenum sizedInternalFormat)
{
glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, sizedInternalFormat, getWindowWidth(),
getWindowHeight());
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
mRenderbuffer);
glViewport(0, 0, getWindowWidth(), getWindowHeight());
ASSERT_GL_NO_ERROR();
}
private:
GLRenderbuffer mRenderbuffer;
GLFramebuffer mFramebuffer;
};
class IncompleteTextureTestES31 : public ANGLETest<>
{
protected:
IncompleteTextureTestES31()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
};
// Test rendering with an incomplete texture.
TEST_P(IncompleteTextureTest, IncompleteTexture2D)
{
GLTexture tex;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glUseProgram(mProgram);
glUniform1i(mTextureUniformLocation, 0);
constexpr GLsizei kTextureSize = 2;
std::vector<GLColor> textureData(kTextureSize * kTextureSize, GLColor::red);
// Make a complete texture.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kTextureSize, kTextureSize, 0, GL_RGBA,
GL_UNSIGNED_BYTE, textureData.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// Should be complete - expect red.
drawQuad(mProgram, "position", 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red) << "complete texture should be red";
// Make texture incomplete.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
// Should be incomplete - expect black.
drawQuad(mProgram, "position", 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black) << "incomplete texture should be black";
// Make texture complete by defining the second mip.
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, kTextureSize >> 1, kTextureSize >> 1, 0, GL_RGBA,
GL_UNSIGNED_BYTE, textureData.data());
// Should be complete - expect red.
drawQuad(mProgram, "position", 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red) << "mip-complete texture should be red";
}
// Tests redefining a texture with half the size works as expected.
TEST_P(IncompleteTextureTest, UpdateTexture)
{
GLTexture tex;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glUseProgram(mProgram);
glUniform1i(mTextureUniformLocation, 0);
constexpr GLsizei redTextureSize = 64;
std::vector<GLColor> redTextureData(redTextureSize * redTextureSize, GLColor::red);
for (GLint mip = 0; mip < 7; ++mip)
{
const GLsizei mipSize = redTextureSize >> mip;
glTexImage2D(GL_TEXTURE_2D, mip, GL_RGBA, mipSize, mipSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
redTextureData.data());
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
drawQuad(mProgram, "position", 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
constexpr GLsizei greenTextureSize = 32;
std::vector<GLColor> greenTextureData(greenTextureSize * greenTextureSize, GLColor::green);
for (GLint mip = 0; mip < 6; ++mip)
{
const GLsizei mipSize = greenTextureSize >> mip;
glTexSubImage2D(GL_TEXTURE_2D, mip, mipSize, mipSize, mipSize, mipSize, GL_RGBA,
GL_UNSIGNED_BYTE, greenTextureData.data());
}
drawQuad(mProgram, "position", 0.5f);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - greenTextureSize, getWindowHeight() - greenTextureSize,
GLColor::green);
}
// Tests that incomplete textures don't get initialized with the unpack buffer contents.
TEST_P(IncompleteTextureTestES3, UnpackBufferBound)
{
std::vector<GLColor> red(16, GLColor::red);
GLBuffer unpackBuffer;
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer);
glBufferData(GL_PIXEL_UNPACK_BUFFER, red.size() * sizeof(GLColor), red.data(), GL_STATIC_DRAW);
draw2DTexturedQuad(0.5f, 1.0f, true);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
}
// Tests that the incomplete multisample texture has the correct alpha value.
TEST_P(IncompleteTextureTestES31, MultisampleTexture)
{
constexpr char kVS[] = R"(#version 310 es
in vec2 position;
out vec2 texCoord;
void main()
{
gl_Position = vec4(position, 0, 1);
texCoord = (position * 0.5) + 0.5;
})";
constexpr char kFS[] = R"(#version 310 es
precision mediump float;
in vec2 texCoord;
out vec4 color;
uniform mediump sampler2DMS tex;
void main()
{
ivec2 texSize = textureSize(tex);
ivec2 texel = ivec2(vec2(texSize) * texCoord);
color = texelFetch(tex, texel, 0);
})";
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
// The zero texture will be incomplete by default.
ANGLE_GL_PROGRAM(program, kVS, kFS);
drawQuad(program, "position", 0.5f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
}
// This mirrors a scenario seen in GFXBench Car Chase where a
// default CUBE_MAP_ARRAY texture is used without being setup.
// Its ends up sampling from an incomplete texture.
TEST_P(IncompleteTextureTestES31, IncompleteTextureCubeMapArray)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_cube_map_array"));
constexpr char kVS[] =
R"(#version 310 es
precision mediump float;
in vec3 pos;
void main() {
gl_Position = vec4(pos, 1.0);
})";
constexpr char kFS[] =
R"(#version 310 es
#extension GL_EXT_texture_cube_map_array : enable
precision mediump float;
out vec4 color;
uniform lowp samplerCubeArray uTex;
void main(){
vec4 outColor = vec4(0.0);
// Pull a color from each cube face to ensure they are all initialized
outColor += texture(uTex, vec4(1.0, 0.0, 0.0, 0.0));
outColor += texture(uTex, vec4(-1.0, 0.0, 0.0, 0.0));
outColor += texture(uTex, vec4(0.0, 1.0, 0.0, 0.0));
outColor += texture(uTex, vec4(0.0, -1.0, 0.0, 0.0));
outColor += texture(uTex, vec4(0.0, 0.0, 1.0, 0.0));
outColor += texture(uTex, vec4(0.0, 0.0, -1.0, 0.0));
color = outColor;
})";
ANGLE_GL_PROGRAM(program, kVS, kFS);
glUseProgram(program);
glUniform1i(glGetUniformLocation(program, "uTex"), 0);
glActiveTexture(GL_TEXTURE0);
// Bind the default texture and don't set it up. This ends up being incomplete.
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, 0);
drawQuad(program, "pos", 0.5f, 1.0f, true);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::black);
}
// Verifies that an incomplete integer texture has a signed integer type default value.
TEST_P(IncompleteTextureTestES3, IntegerType)
{
// GLES backend on Adreno has a problem to create a incomplete texture, although it doesn't go
// through the routine which creates a incomplete texture in the ANGLE driver.
ANGLE_SKIP_TEST_IF(IsAdreno() && IsAndroid() && IsOpenGLES());
// http://crbug.com/1168370
ANGLE_SKIP_TEST_IF(IsMac() && IsARM64() && IsOpenGL());
constexpr char kVS[] = R"(#version 300 es
in highp vec2 position;
out highp vec2 texCoord;
void main()
{
gl_Position = vec4(position, 0, 1);
texCoord = (position * 0.5) + 0.5;
})";
constexpr char kFS[] = R"(#version 300 es
in highp vec2 texCoord;
out highp ivec4 color;
uniform highp isampler2D tex;
void main()
{
ivec2 texSize = textureSize(tex, 0);
ivec2 texel = ivec2(vec2(texSize) * texCoord);
color = texelFetch(tex, texel, 0);
})";
constexpr GLint clearColori[4] = {-10, 20, -30, 40};
constexpr GLint blackColori[4] = {0, 0, 0, 127};
setupFramebuffer(GL_RGBA8I);
glClearBufferiv(GL_COLOR, 0, clearColori);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_8I(0, 0, clearColori[0], clearColori[1], clearColori[2], clearColori[3]);
// Since no texture attachment has been specified, it is incomplete by definition
ANGLE_GL_PROGRAM(program, kVS, kFS);
glUseProgram(program);
drawQuad(program, "position", 0.5f);
ASSERT_GL_NO_ERROR();
const int width = getWindowWidth() - 1;
const int height = getWindowHeight() - 1;
EXPECT_PIXEL_8I(0, 0, blackColori[0], blackColori[1], blackColori[2], blackColori[3]);
EXPECT_PIXEL_8I(width, 0, blackColori[0], blackColori[1], blackColori[2], blackColori[3]);
EXPECT_PIXEL_8I(0, height, blackColori[0], blackColori[1], blackColori[2], blackColori[3]);
EXPECT_PIXEL_8I(width, height, blackColori[0], blackColori[1], blackColori[2], blackColori[3]);
}
// Verifies that an incomplete unsigned integer texture has an unsigned integer type default value.
TEST_P(IncompleteTextureTestES3, UnsignedIntegerType)
{
// GLES backend on Adreno has a problem to create a incomplete texture, although it doesn't go
// through the routine which creates a incomplete texture in the ANGLE driver.
ANGLE_SKIP_TEST_IF(IsAdreno() && IsAndroid() && IsOpenGLES());
// http://crbug.com/1168370
ANGLE_SKIP_TEST_IF(IsMac() && IsARM64() && IsOpenGL());
constexpr char kVS[] = R"(#version 300 es
in highp vec2 position;
out highp vec2 texCoord;
void main()
{
gl_Position = vec4(position, 0, 1);
texCoord = (position * 0.5) + 0.5;
})";
constexpr char kFS[] = R"(#version 300 es
in highp vec2 texCoord;
out highp uvec4 color;
uniform highp usampler2D tex;
void main()
{
ivec2 texSize = textureSize(tex, 0);
ivec2 texel = ivec2(vec2(texSize) * texCoord);
color = texelFetch(tex, texel, 0);
})";
constexpr GLuint clearColorui[4] = {40, 30, 20, 10};
constexpr GLuint blackColorui[4] = {0, 0, 0, 255};
setupFramebuffer(GL_RGBA8UI);
glClearBufferuiv(GL_COLOR, 0, clearColorui);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_8UI(0, 0, clearColorui[0], clearColorui[1], clearColorui[2], clearColorui[3]);
// Since no texture attachment has been specified, it is incomplete by definition
ANGLE_GL_PROGRAM(program, kVS, kFS);
glUseProgram(program);
drawQuad(program, "position", 0.5f);
ASSERT_GL_NO_ERROR();
const int width = getWindowWidth() - 1;
const int height = getWindowHeight() - 1;
EXPECT_PIXEL_8UI(0, 0, blackColorui[0], blackColorui[1], blackColorui[2], blackColorui[3]);
EXPECT_PIXEL_8UI(width, 0, blackColorui[0], blackColorui[1], blackColorui[2], blackColorui[3]);
EXPECT_PIXEL_8UI(0, height, blackColorui[0], blackColorui[1], blackColorui[2], blackColorui[3]);
EXPECT_PIXEL_8UI(width, height, blackColorui[0], blackColorui[1], blackColorui[2],
blackColorui[3]);
}
// Verifies that we are able to create an incomplete shadow texture.
TEST_P(IncompleteTextureTestES3, ShadowType)
{
// GLES backend on Adreno has a problem to create a incomplete texture, although it doesn't go
// through the routine which creates a incomplete texture in the ANGLE driver.
ANGLE_SKIP_TEST_IF(IsAdreno() && IsAndroid() && IsOpenGLES());
// http://anglebug.com/42264125
ANGLE_SKIP_TEST_IF(IsD3D11());
constexpr char kVS[] = R"(#version 300 es
in highp vec2 position;
out highp vec3 texCoord;
void main()
{
gl_Position = vec4(position, 0, 1);
texCoord = vec3(((position * 0.5) + 0.5), 0.5);
})";
constexpr char kFS[] = R"(#version 300 es
in highp vec3 texCoord;
out highp vec4 color;
uniform highp sampler2DShadow tex;
void main()
{
color = vec4(vec3(texture(tex, texCoord)), 1.0f);
})";
constexpr GLColor clearColor = {10, 40, 20, 30};
constexpr GLColor blackColor = {0, 0, 0, 255};
setupFramebuffer(GL_RGBA8);
glClearBufferfv(GL_COLOR, 0, clearColor.toNormalizedVector().data());
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(0, 0, clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
// Since no texture attachment has been specified, it is incomplete by definition
ANGLE_GL_PROGRAM(program, kVS, kFS);
glUseProgram(program);
glUniform1i(glGetUniformLocation(program, "tex"), 1);
ASSERT_GL_NO_ERROR();
drawQuad(program, "position", 0.5f);
ASSERT_GL_NO_ERROR();
const int width = getWindowWidth() - 1;
const int height = getWindowHeight() - 1;
EXPECT_PIXEL_EQ(0, 0, blackColor[0], blackColor[1], blackColor[2], blackColor[3]);
EXPECT_PIXEL_EQ(width, 0, blackColor[0], blackColor[1], blackColor[2], blackColor[3]);
EXPECT_PIXEL_EQ(0, height, blackColor[0], blackColor[1], blackColor[2], blackColor[3]);
EXPECT_PIXEL_EQ(width, height, blackColor[0], blackColor[1], blackColor[2], blackColor[3]);
}
ANGLE_INSTANTIATE_TEST_ES2(IncompleteTextureTest);
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(IncompleteTextureTestES3);
ANGLE_INSTANTIATE_TEST_ES3(IncompleteTextureTestES3);
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(IncompleteTextureTestES31);
ANGLE_INSTANTIATE_TEST_ES31(IncompleteTextureTestES31);