Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-swiftshader: Commit

external/swiftshader


Commit MetaInfo

Revisión700a1a67d569fd5a4960ec36fce9c35d2b59aca2 (tree)
Tiempo2018-06-16 02:33:47
AutorNicolas Capens <capn@goog...>
CommiterNicolas Capens

Log Message

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>

Cambiar Resumen

Diferencia incremental

--- a/src/Renderer/Blitter.cpp
+++ b/src/Renderer/Blitter.cpp
@@ -39,7 +39,7 @@ namespace sw
3939 }
4040
4141 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.
4343 blit(color, sRect, dest, dRect, {rgbaMask});
4444 delete color;
4545 }
--- a/src/Renderer/Surface.cpp
+++ b/src/Renderer/Surface.cpp
@@ -44,6 +44,8 @@ namespace sw
4444
4545 void Surface::Buffer::write(int x, int y, int z, const Color<float> &color)
4646 {
47+ ASSERT(x < width && y < height && z < depth);
48+
4749 byte *element = (byte*)buffer + (x + border) * bytes + (y + border) * pitchB + z * samples * sliceB;
4850
4951 for(int i = 0; i < samples; i++)
@@ -55,6 +57,8 @@ namespace sw
5557
5658 void Surface::Buffer::write(int x, int y, const Color<float> &color)
5759 {
60+ ASSERT(x < width && y < height);
61+
5862 byte *element = (byte*)buffer + (x + border) * bytes + (y + border) * pitchB;
5963
6064 for(int i = 0; i < samples; i++)
@@ -396,6 +400,8 @@ namespace sw
396400
397401 Color<float> Surface::Buffer::read(int x, int y, int z) const
398402 {
403+ ASSERT(x < width && y < height && z < depth);
404+
399405 void *element = (unsigned char*)buffer + (x + border) * bytes + (y + border) * pitchB + z * samples * sliceB;
400406
401407 return read(element);
@@ -403,6 +409,8 @@ namespace sw
403409
404410 Color<float> Surface::Buffer::read(int x, int y) const
405411 {
412+ ASSERT(x < width && y < height);
413+
406414 void *element = (unsigned char*)buffer + (x + border) * bytes + (y + border) * pitchB;
407415
408416 return read(element);
--- a/tests/unittests/unittests.cpp
+++ b/tests/unittests/unittests.cpp
@@ -49,10 +49,22 @@ protected:
4949 #endif
5050 }
5151
52- void compareColor(unsigned char referenceColor[4])
52+ void expectFramebufferColor(const unsigned char referenceColor[4], GLint x = 0, GLint y = 0)
5353 {
5454 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());
5668 EXPECT_EQ(color[0], referenceColor[0]);
5769 EXPECT_EQ(color[1], referenceColor[1]);
5870 EXPECT_EQ(color[2], referenceColor[2]);
@@ -383,7 +395,7 @@ TEST_F(SwiftShaderTest, UnrollLoop)
383395
384396 deleteProgram(ph);
385397
386- compareColor(green);
398+ expectFramebufferColor(green);
387399
388400 EXPECT_GLENUM_EQ(GL_NONE, glGetError());
389401
@@ -448,7 +460,7 @@ TEST_F(SwiftShaderTest, DynamicLoop)
448460
449461 deleteProgram(ph);
450462
451- compareColor(green);
463+ expectFramebufferColor(green);
452464
453465 EXPECT_GLENUM_EQ(GL_NONE, glGetError());
454466
@@ -505,13 +517,44 @@ TEST_F(SwiftShaderTest, DynamicIndexing)
505517
506518 deleteProgram(ph);
507519
508- compareColor(green);
520+ expectFramebufferColor(green);
509521
510522 EXPECT_GLENUM_EQ(GL_NONE, glGetError());
511523
512524 Uninitialize();
513525 }
514526
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+
515558 // Tests construction of a structure containing a single matrix
516559 TEST_F(SwiftShaderTest, MatrixInStruct)
517560 {
@@ -593,7 +636,7 @@ TEST_F(SwiftShaderTest, SamplerArrayInStructArrayAsFunctionArg)
593636
594637 deleteProgram(ph);
595638
596- compareColor(green);
639+ expectFramebufferColor(green);
597640
598641 EXPECT_GLENUM_EQ(GL_NONE, glGetError());
599642
@@ -647,7 +690,7 @@ TEST_F(SwiftShaderTest, AtanCornerCases)
647690 deleteProgram(ph);
648691
649692 unsigned char grey[4] = { 128, 128, 128, 128 };
650- compareColor(grey);
693+ expectFramebufferColor(grey);
651694
652695 EXPECT_GLENUM_EQ(GL_NONE, glGetError());
653696
@@ -910,7 +953,7 @@ TEST_F(SwiftShaderTest, TextureRectangle_SamplingFromRectangle)
910953
911954 deleteProgram(ph);
912955
913- compareColor(green);
956+ expectFramebufferColor(green);
914957
915958 EXPECT_GLENUM_EQ(GL_NONE, glGetError());
916959
@@ -964,7 +1007,7 @@ TEST_F(SwiftShaderTest, TextureRectangle_SamplingFromRectangleESSL3)
9641007
9651008 deleteProgram(ph);
9661009
967- compareColor(green);
1010+ expectFramebufferColor(green);
9681011
9691012 EXPECT_GLENUM_EQ(GL_NONE, glGetError());
9701013
@@ -992,7 +1035,7 @@ TEST_F(SwiftShaderTest, TextureRectangle_RenderToRectangle)
9921035 glClear(GL_COLOR_BUFFER_BIT);
9931036
9941037 unsigned char green[4] = { 0, 255, 0, 255 };
995- compareColor(green);
1038+ expectFramebufferColor(green);
9961039 EXPECT_GLENUM_EQ(GL_NONE, glGetError());
9971040
9981041 Uninitialize();
@@ -1046,7 +1089,7 @@ TEST_F(SwiftShaderTest, TextureRectangle_CopyTexImage)
10461089 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, tex, 0);
10471090
10481091 unsigned char green[4] = { 0, 255, 0, 255 };
1049- compareColor(green);
1092+ expectFramebufferColor(green);
10501093 EXPECT_GLENUM_EQ(GL_NONE, glGetError());
10511094
10521095 Uninitialize();
@@ -1080,7 +1123,7 @@ TEST_F(SwiftShaderTest, TextureRectangle_CopyTexSubImage)
10801123 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, tex, 0);
10811124
10821125 unsigned char green[4] = { 0, 255, 0, 255 };
1083- compareColor(green);
1126+ expectFramebufferColor(green);
10841127 EXPECT_GLENUM_EQ(GL_NONE, glGetError());
10851128
10861129 Uninitialize();
Show on old repository browser