OSDN Git Service

Fix clearing all samples of multisample render targets.
authorNicolas Capens <capn@google.com>
Thu, 20 Jul 2017 18:14:09 +0000 (14:14 -0400)
committerNicolas Capens <nicolascapens@google.com>
Fri, 21 Jul 2017 16:37:44 +0000 (16:37 +0000)
Only libGLESv2 was clearing all the samples of a multisample buffer.
Since all known APIs always clear all the samples, this could be
handled in the Renderer.

Bug swiftshader:77

Change-Id: Ib9adc3c61d263420ed0a0ae4828a693bd360b076
Reviewed-on: https://swiftshader-review.googlesource.com/10788
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
src/D3D8/Direct3DDevice8.cpp
src/D3D9/Direct3DDevice9.cpp
src/OpenGL/libGL/Device.cpp
src/OpenGL/libGLES_CM/Device.cpp
src/OpenGL/libGLESv2/Context.cpp
src/OpenGL/libGLESv2/Device.cpp
src/Renderer/Renderer.cpp
src/Renderer/Renderer.hpp
src/Renderer/Surface.cpp
src/Renderer/Surface.hpp

index 6294fbb..7f6e769 100644 (file)
@@ -365,7 +365,7 @@ namespace D3D8
 
                for(unsigned int i = 0; i < count; i++)
                {
-                       sw::SliceRect clearRect(rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2, 0);
+                       sw::Rect clearRect(rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2);
 
                        clearRect.clip(viewport.X, viewport.Y, viewport.X + viewport.Width, viewport.Y + viewport.Height);
 
index 9b68c47..4be7955 100644 (file)
@@ -396,7 +396,7 @@ namespace D3D9
 
                for(unsigned int i = 0; i < count; i++)
                {
-                       sw::SliceRect clearRect(rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2, 0);
+                       sw::Rect clearRect(rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2);
 
                        clearRect.clip(viewport.X, viewport.Y, viewport.X + viewport.Width, viewport.Y + viewport.Height);
 
index f75b060..736bb99 100644 (file)
@@ -201,7 +201,7 @@ namespace gl
                        return;
                }
 
-               sw::SliceRect clearRect = renderTarget->getRect();
+               sw::Rect clearRect = renderTarget->getRect();
 
                if(scissorEnable)
                {
@@ -225,7 +225,7 @@ namespace gl
                }
 
                z = clamp01(z);
-               sw::SliceRect clearRect = depthStencil->getRect();
+               sw::Rect clearRect = depthStencil->getRect();
 
                if(scissorEnable)
                {
@@ -242,7 +242,7 @@ namespace gl
                        return;
                }
 
-               sw::SliceRect clearRect = depthStencil->getRect();
+               sw::Rect clearRect = depthStencil->getRect();
 
                if(scissorEnable)
                {
index cb95d0c..26f53bc 100644 (file)
@@ -172,7 +172,7 @@ namespace es1
                rgba[2] = blue;
                rgba[3] = alpha;
 
-               sw::SliceRect clearRect = renderTarget->getRect();
+               sw::Rect clearRect = renderTarget->getRect();
 
                if(scissorEnable)
                {
@@ -190,7 +190,7 @@ namespace es1
                }
 
                z = clamp01(z);
-               sw::SliceRect clearRect = depthBuffer->getRect();
+               sw::Rect clearRect = depthBuffer->getRect();
 
                if(scissorEnable)
                {
@@ -207,7 +207,7 @@ namespace es1
                        return;
                }
 
-               sw::SliceRect clearRect = stencilBuffer->getRect();
+               sw::Rect clearRect = stencilBuffer->getRect();
 
                if(scissorEnable)
                {
index c139068..c3f3b66 100644 (file)
@@ -3329,7 +3329,7 @@ void Context::clearColorBuffer(GLint drawbuffer, void *value, sw::Format format)
 
                if(colorbuffer)
                {
-                       sw::SliceRect clearRect = colorbuffer->getRect();
+                       sw::Rect clearRect = colorbuffer->getRect();
 
                        if(mState.scissorTestEnabled)
                        {
@@ -3368,7 +3368,7 @@ void Context::clearDepthBuffer(const GLfloat value)
                if(depthbuffer)
                {
                        float depth = clamp01(value);
-                       sw::SliceRect clearRect = depthbuffer->getRect();
+                       sw::Rect clearRect = depthbuffer->getRect();
 
                        if(mState.scissorTestEnabled)
                        {
@@ -3392,7 +3392,7 @@ void Context::clearStencilBuffer(const GLint value)
                if(stencilbuffer)
                {
                        unsigned char stencil = value < 0 ? 0 : static_cast<unsigned char>(value & 0x000000FF);
-                       sw::SliceRect clearRect = stencilbuffer->getRect();
+                       sw::Rect clearRect = stencilbuffer->getRect();
 
                        if(mState.scissorTestEnabled)
                        {
index 8b8f016..53c794c 100644 (file)
@@ -202,18 +202,14 @@ namespace es2
                {
                        if(renderTarget[i])
                        {
-                               sw::SliceRect clearRect = renderTarget[i]->getRect();
+                               sw::Rect clearRect = renderTarget[i]->getRect();
 
                                if(scissorEnable)
                                {
                                        clearRect.clip(scissorRect.x0, scissorRect.y0, scissorRect.x1, scissorRect.y1);
                                }
 
-                               int depth = sw::max(renderTarget[i]->getDepth(), 1);
-                               for(clearRect.slice = 0; clearRect.slice < depth; clearRect.slice++)
-                               {
-                                       clear(rgba, FORMAT_A32B32G32R32F, renderTarget[i], clearRect, rgbaMask);
-                               }
+                               clear(rgba, FORMAT_A32B32G32R32F, renderTarget[i], clearRect, rgbaMask);
                        }
                }
        }
@@ -226,7 +222,7 @@ namespace es2
                }
 
                z = clamp01(z);
-               sw::SliceRect clearRect = depthBuffer->getRect();
+               sw::Rect clearRect = depthBuffer->getRect();
 
                if(scissorEnable)
                {
@@ -243,7 +239,7 @@ namespace es2
                        return;
                }
 
-               sw::SliceRect clearRect = stencilBuffer->getRect();
+               sw::Rect clearRect = stencilBuffer->getRect();
 
                if(scissorEnable)
                {
index 7afbb9f..252d744 100644 (file)
@@ -672,9 +672,15 @@ namespace sw
                }
        }
 
-       void Renderer::clear(void *pixel, Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask)
+       void Renderer::clear(void *value, Format format, Surface *dest, const Rect &clearRect, unsigned int rgbaMask)
        {
-               blitter->clear(pixel, format, dest, dRect, rgbaMask);
+               SliceRect rect = clearRect;
+               int samples = dest->getDepth();
+
+               for(rect.slice = 0; rect.slice < samples; rect.slice++)
+               {
+                       blitter->clear(value, format, dest, rect, rgbaMask);
+               }
        }
 
        void Renderer::blit(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil)
index dedd17a..d796475 100644 (file)
@@ -326,7 +326,7 @@ namespace sw
 
                void draw(DrawType drawType, unsigned int indexOffset, unsigned int count, bool update = true);
 
-               void clear(void* pixel, Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask);
+               void clear(void *value, Format format, Surface *dest, const Rect &rect, unsigned int rgbaMask);
                void blit(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil = false);
                void blit3D(Surface *source, Surface *dest);
 
index 1a63ff9..6bcc657 100644 (file)
@@ -3193,14 +3193,14 @@ namespace sw
                resource->unlock();
        }
 
-       bool Surface::isEntire(const SliceRect& rect) const
+       bool Surface::isEntire(const Rect& rect) const
        {
                return (rect.x0 == 0 && rect.y0 == 0 && rect.x1 == internal.width && rect.y1 == internal.height && internal.depth == 1);
        }
 
-       SliceRect Surface::getRect() const
+       Rect Surface::getRect() const
        {
-               return SliceRect(0, 0, internal.width, internal.height, 0);
+               return Rect(0, 0, internal.width, internal.height);
        }
 
        void Surface::clearDepth(float depth, int x0, int y0, int width, int height)
index b54565e..6418c08 100644 (file)
@@ -299,8 +299,8 @@ namespace sw
                inline int getMultiSampleCount() const;
                inline int getSuperSampleCount() const;
 
-               bool isEntire(const SliceRect& rect) const;
-               SliceRect getRect() const;
+               bool isEntire(const Rect& rect) const;
+               Rect getRect() const;
                void clearDepth(float depth, int x0, int y0, int width, int height);
                void clearStencil(unsigned char stencil, unsigned char mask, int x0, int y0, int width, int height);
                void fill(const Color<float> &color, int x0, int y0, int width, int height);