Improve combined depth stencil image handling.
authorJarkko Pöyry <jpoyry@google.com>
Tue, 12 May 2015 00:34:57 +0000 (17:34 -0700)
committerJarkko Pöyry <jpoyry@google.com>
Tue, 12 May 2015 01:06:22 +0000 (18:06 -0700)
- Allow logging DS images. This will result in separate D and S images.
- Add depth and stencil multisample resolve.
- Do not resolve D and S attachments as a color attachment.

Bug: 21038103
Change-Id: Ib7840126094abf947043d73b3bada76c55988b02

framework/common/tcuTestLog.cpp
framework/common/tcuTestLog.hpp
framework/referencerenderer/rrMultisamplePixelBufferAccess.cpp
framework/referencerenderer/rrMultisamplePixelBufferAccess.hpp
modules/internal/ditFrameworkTests.cpp

index fc1ea0f80eeaa918f8de4ebbf865bfea7b28d480..a4c679ae9a842ae1895106e9b49a0e6a6f3353bf 100644 (file)
@@ -63,7 +63,77 @@ LogImage::LogImage (const std::string& name, const std::string& description, con
        , m_bias                (0.0f, 0.0f, 0.0f, 0.0f)
        , m_compression (compression)
 {
-       computePixelScaleBias(access, m_scale, m_bias);
+       // Simplify combined formats that only use a single channel
+       if (tcu::isCombinedDepthStencilType(m_access.getFormat().type))
+       {
+               if (m_access.getFormat().order == tcu::TextureFormat::D)
+                       m_access = tcu::getEffectiveDepthStencilAccess(m_access, tcu::Sampler::MODE_DEPTH);
+               else if (m_access.getFormat().order == tcu::TextureFormat::S)
+                       m_access = tcu::getEffectiveDepthStencilAccess(m_access, tcu::Sampler::MODE_STENCIL);
+       }
+
+       // Implicit scale and bias
+       if (m_access.getFormat().order != tcu::TextureFormat::DS)
+               computePixelScaleBias(m_access, m_scale, m_bias);
+       else
+       {
+               // Pack D and S bias and scale to R and G
+               const ConstPixelBufferAccess    depthAccess             = tcu::getEffectiveDepthStencilAccess(m_access, tcu::Sampler::MODE_DEPTH);
+               const ConstPixelBufferAccess    stencilAccess   = tcu::getEffectiveDepthStencilAccess(m_access, tcu::Sampler::MODE_STENCIL);
+               tcu::Vec4                                               depthScale;
+               tcu::Vec4                                               depthBias;
+               tcu::Vec4                                               stencilScale;
+               tcu::Vec4                                               stencilBias;
+
+               computePixelScaleBias(depthAccess, depthScale, depthBias);
+               computePixelScaleBias(stencilAccess, stencilScale, stencilBias);
+
+               m_scale = tcu::Vec4(depthScale.x(), stencilScale.x(), 0.0f, 0.0f);
+               m_bias = tcu::Vec4(depthBias.x(), stencilBias.x(), 0.0f, 0.0f);
+       }
+}
+
+LogImage::LogImage (const std::string& name, const std::string& description, const ConstPixelBufferAccess& access, const Vec4& scale, const Vec4& bias, qpImageCompressionMode compression)
+       : m_name                (name)
+       , m_description (description)
+       , m_access              (access)
+       , m_scale               (scale)
+       , m_bias                (bias)
+       , m_compression (compression)
+{
+       // Cannot set scale and bias of combined formats
+       DE_ASSERT(access.getFormat().order != tcu::TextureFormat::DS);
+
+       // Simplify access
+       if (tcu::isCombinedDepthStencilType(access.getFormat().type))
+       {
+               if (access.getFormat().order == tcu::TextureFormat::D)
+                       m_access = tcu::getEffectiveDepthStencilAccess(access, tcu::Sampler::MODE_DEPTH);
+               if (access.getFormat().order == tcu::TextureFormat::S)
+                       m_access = tcu::getEffectiveDepthStencilAccess(access, tcu::Sampler::MODE_STENCIL);
+               else
+               {
+                       // Cannot log a DS format
+                       DE_ASSERT(false);
+                       return;
+               }
+       }
+}
+
+void LogImage::write (TestLog& log) const
+{
+       if (m_access.getFormat().order != tcu::TextureFormat::DS)
+               log.writeImage(m_name.c_str(), m_description.c_str(), m_access, m_scale, m_bias, m_compression);
+       else
+       {
+               const ConstPixelBufferAccess    depthAccess             = tcu::getEffectiveDepthStencilAccess(m_access, tcu::Sampler::MODE_DEPTH);
+               const ConstPixelBufferAccess    stencilAccess   = tcu::getEffectiveDepthStencilAccess(m_access, tcu::Sampler::MODE_STENCIL);
+
+               log.startImageSet(m_name.c_str(), m_description.c_str());
+               log.writeImage("Depth", "Depth channel", depthAccess, m_scale.swizzle(0, 0, 0, 0), m_bias.swizzle(0, 0, 0, 0), m_compression);
+               log.writeImage("Stencil", "Stencil channel", stencilAccess, m_scale.swizzle(1, 1, 1, 1), m_bias.swizzle(1, 1, 1, 1), m_compression);
+               log.endImageSet();
+       }
 }
 
 // MessageBuilder
@@ -170,6 +240,9 @@ void TestLog::writeImage (const char* name, const char* description, const Const
        int                                             height          = access.getHeight();
        int                                             depth           = access.getDepth();
 
+       // Writing a combined image does not make sense
+       DE_ASSERT(!tcu::isCombinedDepthStencilType(access.getFormat().type));
+
        // Do not bother with preprocessing if images are not stored
        if ((qpTestLog_getLogFlags(m_log) & QP_TEST_LOG_EXCLUDE_IMAGES) != 0)
                return;
index dc7e0451fc6c7ffd001ee5d0b90bbcf96a8bb662..7d76921abf7a51b8d68db8b5a64be4a243946ba3 100644 (file)
@@ -253,15 +253,7 @@ public:
 
        LogImage (const std::string& name, const std::string& description, const ConstPixelBufferAccess& access, qpImageCompressionMode compression = QP_IMAGE_COMPRESSION_MODE_BEST);
 
-       LogImage (const std::string& name, const std::string& description, const ConstPixelBufferAccess& access, const Vec4& scale, const Vec4& bias, qpImageCompressionMode compression = QP_IMAGE_COMPRESSION_MODE_BEST)
-               : m_name                (name)
-               , m_description (description)
-               , m_access              (access)
-               , m_scale               (scale)
-               , m_bias                (bias)
-               , m_compression (compression)
-       {
-       }
+       LogImage (const std::string& name, const std::string& description, const ConstPixelBufferAccess& access, const Vec4& scale, const Vec4& bias, qpImageCompressionMode compression = QP_IMAGE_COMPRESSION_MODE_BEST);
 
        void write (TestLog& log) const;
 
@@ -478,11 +470,6 @@ inline void LogImageSet::write (TestLog& log) const
        log.startImageSet(m_name.c_str(), m_description.c_str());
 }
 
-inline void LogImage::write (TestLog& log) const
-{
-       log.writeImage(m_name.c_str(), m_description.c_str(), m_access, m_scale, m_bias, m_compression);
-}
-
 inline void LogSection::write (TestLog& log) const
 {
        log.startSection(m_name.c_str(), m_description.c_str());
index f7effbde7b765ac8cc9c476100f9bf0b7e0d8929..26122fc3eb6eb4c1a2b1b730b9598c20ed1688cd 100644 (file)
@@ -150,6 +150,80 @@ void resolveMultisampleColorBuffer (const tcu::PixelBufferAccess& dst, const Mul
        }
 }
 
+void resolveMultisampleDepthBuffer (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src)
+{
+       DE_ASSERT(dst.getWidth() == src.raw().getHeight());
+       DE_ASSERT(dst.getHeight() == src.raw().getDepth());
+
+       const tcu::ConstPixelBufferAccess       effectiveSrc = tcu::getEffectiveDepthStencilAccess(src.raw(), tcu::Sampler::MODE_DEPTH);
+       const tcu::PixelBufferAccess            effectiveDst = tcu::getEffectiveDepthStencilAccess(dst, tcu::Sampler::MODE_DEPTH);
+
+       if (src.getNumSamples() == 1)
+       {
+               // fast-path for non-multisampled cases
+               tcu::copy(effectiveDst, MultisampleConstPixelBufferAccess::fromMultisampleAccess(effectiveSrc).toSinglesampleAccess());
+       }
+       else
+       {
+               const float numSamplesInv = 1.0f / (float)src.getNumSamples();
+
+               for (int y = 0; y < dst.getHeight(); y++)
+               for (int x = 0; x < dst.getWidth(); x++)
+               {
+                       float sum = 0.0f;
+                       for (int s = 0; s < src.getNumSamples(); s++)
+                               sum += effectiveSrc.getPixDepth(s, x, y);
+
+                       effectiveDst.setPixDepth(sum*numSamplesInv, x, y);
+               }
+       }
+}
+
+void resolveMultisampleStencilBuffer (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src)
+{
+       DE_ASSERT(dst.getWidth() == src.raw().getHeight());
+       DE_ASSERT(dst.getHeight() == src.raw().getDepth());
+
+       const tcu::ConstPixelBufferAccess       effectiveSrc = tcu::getEffectiveDepthStencilAccess(src.raw(), tcu::Sampler::MODE_STENCIL);
+       const tcu::PixelBufferAccess            effectiveDst = tcu::getEffectiveDepthStencilAccess(dst, tcu::Sampler::MODE_STENCIL);
+
+       if (src.getNumSamples() == 1)
+       {
+               // fast-path for non-multisampled cases
+               tcu::copy(effectiveDst, MultisampleConstPixelBufferAccess::fromMultisampleAccess(effectiveSrc).toSinglesampleAccess());
+       }
+       else
+       {
+               // Resolve by selecting one
+               for (int y = 0; y < dst.getHeight(); y++)
+               for (int x = 0; x < dst.getWidth(); x++)
+                       effectiveDst.setPixStencil(effectiveSrc.getPixStencil(0, x, y), x, y);
+       }
+}
+
+void resolveMultisampleBuffer (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src)
+{
+       switch (src.raw().getFormat().order)
+       {
+               case tcu::TextureFormat::D:
+                       resolveMultisampleDepthBuffer(dst, src);
+                       return;
+
+               case tcu::TextureFormat::S:
+                       resolveMultisampleStencilBuffer(dst, src);
+                       return;
+
+               case tcu::TextureFormat::DS:
+                       resolveMultisampleDepthBuffer(dst, src);
+                       resolveMultisampleStencilBuffer(dst, src);
+                       return;
+
+               default:
+                       resolveMultisampleColorBuffer(dst, src);
+                       return;
+       }
+}
+
 tcu::Vec4 resolveMultisamplePixel (const MultisampleConstPixelBufferAccess& access, int x, int y)
 {
        tcu::Vec4 sum;
index 975ef8038e3ef7a39313282b73204c500b584cab..517c1f732d0dca44c8dba70c5d339ab718a5ce49 100644 (file)
@@ -90,6 +90,9 @@ MultisamplePixelBufferAccess          getSubregion                                    (const MultisamplePixelBufferAcce
 MultisampleConstPixelBufferAccess      getSubregion                                    (const MultisampleConstPixelBufferAccess& access, int x, int y, int width, int height);
 
 void                                                           resolveMultisampleColorBuffer   (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src);
+void                                                           resolveMultisampleDepthBuffer   (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src);
+void                                                           resolveMultisampleStencilBuffer (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src);
+void                                                           resolveMultisampleBuffer                (const tcu::PixelBufferAccess& dst, const MultisampleConstPixelBufferAccess& src);
 tcu::Vec4                                                      resolveMultisamplePixel                 (const MultisampleConstPixelBufferAccess& access, int x, int y);
 
 void                                                           clear                                                   (const MultisamplePixelBufferAccess& access, const tcu::Vec4& color);
index fdf23dcace68d00124e81e63a492cc60b8185cbb..2b55b1564cd1309f0c93a00f110ad6dfd682dc54 100644 (file)
@@ -791,8 +791,8 @@ protected:
                                                                                                                                          (subCase.vtx[1].z() == subCase.vtx[2].z());
                        const float                                             refDepth                                = subCase.vtx[0].z()*(zf - zn)/2.0f + (zn + zf)/2.0f;
 
-                       rr::resolveMultisampleColorBuffer(resolvedColor.getAccess(), rr::MultisampleConstPixelBufferAccess::fromMultisampleAccess(interpolated.getAccess()));
-                       rr::resolveMultisampleColorBuffer(resolvedDepthStencil.getAccess(), rr::MultisampleConstPixelBufferAccess::fromMultisampleAccess(depthStencil.getAccess()));
+                       rr::resolveMultisampleBuffer(resolvedColor.getAccess(), rr::MultisampleConstPixelBufferAccess::fromMultisampleAccess(interpolated.getAccess()));
+                       rr::resolveMultisampleBuffer(resolvedDepthStencil.getAccess(), rr::MultisampleConstPixelBufferAccess::fromMultisampleAccess(depthStencil.getAccess()));
                        clear(errorAccess, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
 
                        for (int y = 0; y < height; y++)