external/swiftshader
Revisión | 700a1a67d569fd5a4960ec36fce9c35d2b59aca2 (tree) |
---|---|
Tiempo | 2018-06-16 02:33:47 |
Autor | Nicolas Capens <capn@goog...> |
Commiter | Nicolas Capens |
Fix clearing of dirty textures.
When clear operations fall back to the slow path (i.e. neither fastClear
nor blitReactor is used), we were copying a rectangle the size of the
destination image. It should only sample within the 1x1 source pixel
instead.
Bug chromium:852641, chromium:851707
Change-Id: I9f247483f6167f92be8308b8470c021f5641b657
Reviewed-on: https://swiftshader-review.googlesource.com/19448
Reviewed-by: Alexis Hétu <sugoi@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
@@ -39,7 +39,7 @@ namespace sw | ||
39 | 39 | } |
40 | 40 | |
41 | 41 | sw::Surface *color = sw::Surface::create(1, 1, 1, format, pixel, sw::Surface::bytes(format), sw::Surface::bytes(format)); |
42 | - SliceRectF sRect((float)dRect.x0, (float)dRect.y0, (float)dRect.x1, (float)dRect.y1, 0); | |
42 | + SliceRectF sRect(0.5f, 0.5f, 0.5f, 0.5f, 0); // Sample from the middle. | |
43 | 43 | blit(color, sRect, dest, dRect, {rgbaMask}); |
44 | 44 | delete color; |
45 | 45 | } |
@@ -44,6 +44,8 @@ namespace sw | ||
44 | 44 | |
45 | 45 | void Surface::Buffer::write(int x, int y, int z, const Color<float> &color) |
46 | 46 | { |
47 | + ASSERT(x < width && y < height && z < depth); | |
48 | + | |
47 | 49 | byte *element = (byte*)buffer + (x + border) * bytes + (y + border) * pitchB + z * samples * sliceB; |
48 | 50 | |
49 | 51 | for(int i = 0; i < samples; i++) |
@@ -55,6 +57,8 @@ namespace sw | ||
55 | 57 | |
56 | 58 | void Surface::Buffer::write(int x, int y, const Color<float> &color) |
57 | 59 | { |
60 | + ASSERT(x < width && y < height); | |
61 | + | |
58 | 62 | byte *element = (byte*)buffer + (x + border) * bytes + (y + border) * pitchB; |
59 | 63 | |
60 | 64 | for(int i = 0; i < samples; i++) |
@@ -396,6 +400,8 @@ namespace sw | ||
396 | 400 | |
397 | 401 | Color<float> Surface::Buffer::read(int x, int y, int z) const |
398 | 402 | { |
403 | + ASSERT(x < width && y < height && z < depth); | |
404 | + | |
399 | 405 | void *element = (unsigned char*)buffer + (x + border) * bytes + (y + border) * pitchB + z * samples * sliceB; |
400 | 406 | |
401 | 407 | return read(element); |
@@ -403,6 +409,8 @@ namespace sw | ||
403 | 409 | |
404 | 410 | Color<float> Surface::Buffer::read(int x, int y) const |
405 | 411 | { |
412 | + ASSERT(x < width && y < height); | |
413 | + | |
406 | 414 | void *element = (unsigned char*)buffer + (x + border) * bytes + (y + border) * pitchB; |
407 | 415 | |
408 | 416 | return read(element); |
@@ -49,10 +49,22 @@ protected: | ||
49 | 49 | #endif |
50 | 50 | } |
51 | 51 | |
52 | - void compareColor(unsigned char referenceColor[4]) | |
52 | + void expectFramebufferColor(const unsigned char referenceColor[4], GLint x = 0, GLint y = 0) | |
53 | 53 | { |
54 | 54 | unsigned char color[4] = { 0 }; |
55 | - glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &color); | |
55 | + glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &color); | |
56 | + EXPECT_GLENUM_EQ(GL_NONE, glGetError()); | |
57 | + EXPECT_EQ(color[0], referenceColor[0]); | |
58 | + EXPECT_EQ(color[1], referenceColor[1]); | |
59 | + EXPECT_EQ(color[2], referenceColor[2]); | |
60 | + EXPECT_EQ(color[3], referenceColor[3]); | |
61 | + } | |
62 | + | |
63 | + void expectFramebufferColor(const float referenceColor[4], GLint x = 0, GLint y = 0) | |
64 | + { | |
65 | + float color[4] = { 0 }; | |
66 | + glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, &color); | |
67 | + EXPECT_GLENUM_EQ(GL_NONE, glGetError()); | |
56 | 68 | EXPECT_EQ(color[0], referenceColor[0]); |
57 | 69 | EXPECT_EQ(color[1], referenceColor[1]); |
58 | 70 | EXPECT_EQ(color[2], referenceColor[2]); |
@@ -383,7 +395,7 @@ TEST_F(SwiftShaderTest, UnrollLoop) | ||
383 | 395 | |
384 | 396 | deleteProgram(ph); |
385 | 397 | |
386 | - compareColor(green); | |
398 | + expectFramebufferColor(green); | |
387 | 399 | |
388 | 400 | EXPECT_GLENUM_EQ(GL_NONE, glGetError()); |
389 | 401 |
@@ -448,7 +460,7 @@ TEST_F(SwiftShaderTest, DynamicLoop) | ||
448 | 460 | |
449 | 461 | deleteProgram(ph); |
450 | 462 | |
451 | - compareColor(green); | |
463 | + expectFramebufferColor(green); | |
452 | 464 | |
453 | 465 | EXPECT_GLENUM_EQ(GL_NONE, glGetError()); |
454 | 466 |
@@ -505,13 +517,44 @@ TEST_F(SwiftShaderTest, DynamicIndexing) | ||
505 | 517 | |
506 | 518 | deleteProgram(ph); |
507 | 519 | |
508 | - compareColor(green); | |
520 | + expectFramebufferColor(green); | |
509 | 521 | |
510 | 522 | EXPECT_GLENUM_EQ(GL_NONE, glGetError()); |
511 | 523 | |
512 | 524 | Uninitialize(); |
513 | 525 | } |
514 | 526 | |
527 | +// Tests clearing of a texture with 'dirty' content. | |
528 | +TEST_F(SwiftShaderTest, ClearDirtyTexture) | |
529 | +{ | |
530 | + Initialize(3, false); | |
531 | + | |
532 | + GLuint tex = 1; | |
533 | + glBindTexture(GL_TEXTURE_2D, tex); | |
534 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_R11F_G11F_B10F, 256, 256, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, nullptr); | |
535 | + EXPECT_GLENUM_EQ(GL_NONE, glGetError()); | |
536 | + | |
537 | + GLuint fbo = 1; | |
538 | + glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
539 | + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0); | |
540 | + EXPECT_GLENUM_EQ(GL_NONE, glGetError()); | |
541 | + EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); | |
542 | + | |
543 | + float dirty_color[3] = { 128 / 255.0f, 64 / 255.0f, 192 / 255.0f }; | |
544 | + GLint dirty_x = 8; | |
545 | + GLint dirty_y = 12; | |
546 | + glTexSubImage2D(GL_TEXTURE_2D, 0, dirty_x, dirty_y, 1, 1, GL_RGB, GL_FLOAT, dirty_color); | |
547 | + | |
548 | + const float clear_color[4] = { 1.0f, 32.0f, 0.5f, 1.0f }; | |
549 | + glClearColor(clear_color[0], clear_color[1], clear_color[2], 1.0f); | |
550 | + glClear(GL_COLOR_BUFFER_BIT); | |
551 | + EXPECT_GLENUM_EQ(GL_NONE, glGetError()); | |
552 | + | |
553 | + expectFramebufferColor(clear_color, dirty_x, dirty_y); | |
554 | + | |
555 | + Uninitialize(); | |
556 | +} | |
557 | + | |
515 | 558 | // Tests construction of a structure containing a single matrix |
516 | 559 | TEST_F(SwiftShaderTest, MatrixInStruct) |
517 | 560 | { |
@@ -593,7 +636,7 @@ TEST_F(SwiftShaderTest, SamplerArrayInStructArrayAsFunctionArg) | ||
593 | 636 | |
594 | 637 | deleteProgram(ph); |
595 | 638 | |
596 | - compareColor(green); | |
639 | + expectFramebufferColor(green); | |
597 | 640 | |
598 | 641 | EXPECT_GLENUM_EQ(GL_NONE, glGetError()); |
599 | 642 |
@@ -647,7 +690,7 @@ TEST_F(SwiftShaderTest, AtanCornerCases) | ||
647 | 690 | deleteProgram(ph); |
648 | 691 | |
649 | 692 | unsigned char grey[4] = { 128, 128, 128, 128 }; |
650 | - compareColor(grey); | |
693 | + expectFramebufferColor(grey); | |
651 | 694 | |
652 | 695 | EXPECT_GLENUM_EQ(GL_NONE, glGetError()); |
653 | 696 |
@@ -910,7 +953,7 @@ TEST_F(SwiftShaderTest, TextureRectangle_SamplingFromRectangle) | ||
910 | 953 | |
911 | 954 | deleteProgram(ph); |
912 | 955 | |
913 | - compareColor(green); | |
956 | + expectFramebufferColor(green); | |
914 | 957 | |
915 | 958 | EXPECT_GLENUM_EQ(GL_NONE, glGetError()); |
916 | 959 |
@@ -964,7 +1007,7 @@ TEST_F(SwiftShaderTest, TextureRectangle_SamplingFromRectangleESSL3) | ||
964 | 1007 | |
965 | 1008 | deleteProgram(ph); |
966 | 1009 | |
967 | - compareColor(green); | |
1010 | + expectFramebufferColor(green); | |
968 | 1011 | |
969 | 1012 | EXPECT_GLENUM_EQ(GL_NONE, glGetError()); |
970 | 1013 |
@@ -992,7 +1035,7 @@ TEST_F(SwiftShaderTest, TextureRectangle_RenderToRectangle) | ||
992 | 1035 | glClear(GL_COLOR_BUFFER_BIT); |
993 | 1036 | |
994 | 1037 | unsigned char green[4] = { 0, 255, 0, 255 }; |
995 | - compareColor(green); | |
1038 | + expectFramebufferColor(green); | |
996 | 1039 | EXPECT_GLENUM_EQ(GL_NONE, glGetError()); |
997 | 1040 | |
998 | 1041 | Uninitialize(); |
@@ -1046,7 +1089,7 @@ TEST_F(SwiftShaderTest, TextureRectangle_CopyTexImage) | ||
1046 | 1089 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, tex, 0); |
1047 | 1090 | |
1048 | 1091 | unsigned char green[4] = { 0, 255, 0, 255 }; |
1049 | - compareColor(green); | |
1092 | + expectFramebufferColor(green); | |
1050 | 1093 | EXPECT_GLENUM_EQ(GL_NONE, glGetError()); |
1051 | 1094 | |
1052 | 1095 | Uninitialize(); |
@@ -1080,7 +1123,7 @@ TEST_F(SwiftShaderTest, TextureRectangle_CopyTexSubImage) | ||
1080 | 1123 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, tex, 0); |
1081 | 1124 | |
1082 | 1125 | unsigned char green[4] = { 0, 255, 0, 255 }; |
1083 | - compareColor(green); | |
1126 | + expectFramebufferColor(green); | |
1084 | 1127 | EXPECT_GLENUM_EQ(GL_NONE, glGetError()); |
1085 | 1128 | |
1086 | 1129 | Uninitialize(); |