From 4db0f654edc639890ce28bd8cd735132aac098a9 Mon Sep 17 00:00:00 2001 From: thejinchao Date: Fri, 27 Jun 2025 11:04:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=85=89=E6=A0=85=E5=8C=96?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unit/dvt_unit_rasterizer.cpp | 46 +++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/test/unit/dvt_unit_rasterizer.cpp b/test/unit/dvt_unit_rasterizer.cpp index 795a4ef..9ca5fff 100644 --- a/test/unit/dvt_unit_rasterizer.cpp +++ b/test/unit/dvt_unit_rasterizer.cpp @@ -1,6 +1,5 @@ -#include -#include - +#include "pipe/dvc_rasterizer.h" +#include "buffer/dvu_dump_buffer.h" #include #include @@ -224,19 +223,19 @@ public: if (debug) { bool succ = true; - uint32_t* colBuf = new uint32_t[m_width*m_height]; for (int32_t i = 0; i < m_width*m_height; i++) { - colBuf[i] = m_pixelBuf[i].load(); if (m_pixelBuf[i] == 0) { if (debug) printf("error: %d,%d=%d\n", i%m_width, i/ m_width, m_pixelBuf[(size_t)i].load()); succ = false; - //return false; + break; } } - davinci_utils::dump_pixel_buffer("debug.png", m_width, m_height, colBuf, PF_UINT8_RGBA); - delete[] colBuf; + if (!succ) { + return false; + } + return succ; } else { @@ -262,6 +261,27 @@ public: return true; } + bool dumpToPNG(const char* szFileName, bool binary) + { + uint32_t* pixelBuffer = new uint32_t[m_width * m_height]; + for (int32_t i = 0; i < m_width * m_height; i++) + { + if (binary) { + pixelBuffer[i] = m_pixelBuf[i].load() != 0 ? 0xFF000000 : 0; + } + else { + pixelBuffer[i] = m_pixelBuf[i].load(); + } + } + + if (!davinci_utils::dump_pixel_buffer(szFileName, m_width, m_height, pixelBuffer, PF_UINT8_RGBA)) + { + delete[] pixelBuffer; + return false; + } + delete[] pixelBuffer; + return true; + } private: int32_t m_width, m_height; std::atomic* m_pixelBuf; @@ -271,7 +291,7 @@ private: }; //------------------------------------------------------------------------------------- -static bool _triangleRasterizationRules(Canvas& canvas, const Triangle& triangle, const PixelBuf& pixelExpect, bool ccw=true) +static bool _triangleRasterizationRules(Canvas& canvas, const Triangle& triangle, const PixelBuf& pixelExpect, bool ccw=true, const char* dumpPNGName=nullptr) { auto razFunc = std::bind(&Canvas::razFunction_fetchadd, &canvas, std::placeholders::_1, std::placeholders::_2); @@ -281,6 +301,11 @@ static bool _triangleRasterizationRules(Canvas& canvas, const Triangle& triangle triangle.p1, triangle.p2, triangle.p3, razFunc, ccw); + if (dumpPNGName != nullptr) + { + canvas.dumpToPNG(dumpPNGName, true); + } + return canvas.checkResult(pixelExpect); } @@ -376,9 +401,6 @@ TEST(Rasterizer, Basic) //------------------------------------------------------------------------------------- TEST(Rasterizer, Delaunay) { - //seed=1499743811, counts=5, range=0.8f; - //seed=1499670829, counts=5, range=1.f; - const int32_t width = 1024, height = 1024; const int32_t verticesCounts = MathUtil::rangeRandom(5, 30);