From dbabd5e399b132654e75a3ca9589f35eca09f6cb Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Wed, 6 Mar 2013 20:58:01 -0500 Subject: [PATCH] Add command line option to choose atomics path for compression. --- CLTool/src/clwin32.cpp | 9 +++++++++ Core/src/TexComp.cpp | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CLTool/src/clwin32.cpp b/CLTool/src/clwin32.cpp index 7185746..5cb6663 100644 --- a/CLTool/src/clwin32.cpp +++ b/CLTool/src/clwin32.cpp @@ -59,6 +59,7 @@ void PrintUsage() { fprintf(stderr, "\t-n \tCompress the image num times and give the average time and PSNR. Default: 1\n"); fprintf(stderr, "\t-simd\t\tUse SIMD compression path\n"); fprintf(stderr, "\t-t \tCompress the image using threads. Default: 1\n"); + fprintf(stderr, "\t-a \tCompress the image using synchronization via atomic operations. Default: Off\n"); fprintf(stderr, "\t-j \tUse blocks for each work item in a worker queue threading model. Default: (Blocks / Threads)\n"); } @@ -91,6 +92,7 @@ int _tmain(int argc, _TCHAR* argv[]) int numCompressions = 1; bool bUseSIMD = false; bool bSaveLog = false; + bool bUseAtomics = false; bool knowArg = false; do { @@ -162,6 +164,12 @@ int _tmain(int argc, _TCHAR* argv[]) continue; } + if(strcmp(argv[fileArg], "-a") == 0) { + fileArg++; + bUseAtomics = true; + knowArg = true; + continue; + } } while(knowArg && fileArg < argc); if(numThreads > 1 && bSaveLog) { @@ -194,6 +202,7 @@ int _tmain(int argc, _TCHAR* argv[]) SCompressionSettings settings; settings.bUseSIMD = bUseSIMD; + settings.bUseAtomics = bUseAtomics; settings.iNumThreads = numThreads; settings.iQuality = quality; settings.iNumCompressions = numCompressions; diff --git a/Core/src/TexComp.cpp b/Core/src/TexComp.cpp index 80d19f9..9434a40 100644 --- a/Core/src/TexComp.cpp +++ b/Core/src/TexComp.cpp @@ -184,13 +184,15 @@ class AtomicThreadUnit : public TCCallable { m_OutBuf(outBuf), m_Height(height), m_Width(width), - m_Barrier(barrier) + m_Barrier(barrier), + m_NumCompressions(nCompressions), + m_CmpFnc(f) { } virtual ~AtomicThreadUnit() { } virtual void operator()() { m_Barrier->Wait(); - for(int i = 0; i < m_NumCompressions; i++) + for(uint32 i = 0; i < m_NumCompressions; i++) (*m_CmpFnc)(m_InBuf, m_OutBuf, m_Width, m_Height); } }; @@ -374,7 +376,14 @@ bool CompressImageData( double cmpMSTime = 0.0; if(settings.iNumThreads > 1) { - if(settings.iJobSize > 0) + if(settings.bUseAtomics) { + //!KLUDGE! + unsigned int height = 4; + unsigned int width = dataSz / 16; + + cmpMSTime = CompressImageWithAtomics(data, width, height, settings, cmpData); + } + else if(settings.iJobSize > 0) cmpMSTime = CompressImageWithWorkerQueue(data, dataSz, settings, cmpData); else cmpMSTime = CompressImageWithThreads(data, dataSz, settings, cmpData);