Log SPIR-V assembly source.
authorDejan Mircevski <deki@google.com>
Mon, 8 Feb 2016 15:23:49 +0000 (10:23 -0500)
committerDejan Mircevski <deki@google.com>
Mon, 8 Feb 2016 18:43:22 +0000 (13:43 -0500)
We weren't previously logging the source of a SPIR-V module, which made
it hard to debug compilation errors.

Extend executor to handle the new XML element.

Bump the log-format version to 0.3.4.

Change-Id: I4ace0a88820d08febd0500c60d1f2fe97b635635

executor/xeTestCaseResult.hpp
executor/xeTestLogWriter.cpp
executor/xeTestResultParser.cpp
external/vulkancts/framework/vulkan/vkSpirVProgram.cpp
framework/common/tcuTestLog.cpp
framework/common/tcuTestLog.hpp
framework/qphelper/qpTestLog.c
framework/qphelper/qpTestLog.h

index 76c028c..11d68ce 100644 (file)
@@ -142,6 +142,7 @@ enum Type
        TYPE_SHADER,
        TYPE_SHADERPROGRAM,
        TYPE_SHADERSOURCE,
+       TYPE_SPIRVSOURCE,
        TYPE_INFOLOG,
        TYPE_EGLCONFIG,
        TYPE_EGLCONFIGSET,
@@ -289,6 +290,15 @@ public:
        std::string                     source;
 };
 
+class SpirVSource : public Item
+{
+public:
+                                               SpirVSource                     (void) : Item(TYPE_SPIRVSOURCE) {}
+                                               ~SpirVSource            (void) {}
+
+       std::string                     source;
+};
+
 class InfoLog : public Item
 {
 public:
index dcb3ee6..bcb33fd 100644 (file)
@@ -335,6 +335,10 @@ static void writeResultItem (const ri::Item& item, xml::Writer& dst)
                        dst << Writer::BeginElement("ShaderSource") << static_cast<const ri::ShaderSource&>(item).source << Writer::EndElement;
                        break;
 
+               case ri::TYPE_SPIRVSOURCE:
+                       dst << Writer::BeginElement("SpirVAssemblySource") << static_cast<const ri::SpirVSource&>(item).source << Writer::EndElement;
+                       break;
+
                case ri::TYPE_INFOLOG:
                        dst << Writer::BeginElement("InfoLog") << static_cast<const ri::InfoLog&>(item).log << Writer::EndElement;
                        break;
index 0b95b8e..eba5ffd 100644 (file)
@@ -115,6 +115,7 @@ static const EnumMapEntry s_resultItemMap[] =
        { 0x6c1415d9,   "ComputeShader",                ri::TYPE_SHADER                 },
        { 0x72863a54,   "ShaderProgram",                ri::TYPE_SHADERPROGRAM  },
        { 0xb4efc08d,   "ShaderSource",                 ri::TYPE_SHADERSOURCE   },
+       { 0xaee4380a,   "SpirVAssemblySource",  ri::TYPE_SPIRVSOURCE    },
        { 0xff265913,   "InfoLog",                              ri::TYPE_INFOLOG                },
        { 0x84159b73,   "EglConfig",                    ri::TYPE_EGLCONFIG              },
        { 0xdd34391f,   "EglConfigSet",                 ri::TYPE_EGLCONFIGSET   },
@@ -545,7 +546,7 @@ void TestResultParser::handleElementStart (void)
                        case ri::TYPE_SHADER:
                        {
                                if (parentType != ri::TYPE_SHADERPROGRAM)
-                                       throw TestResultParseError("<VertexShader> outside of <ShaderProgram>");
+                                       throw TestResultParseError(string("<") + elemName + "> outside of <ShaderProgram>");
 
                                ri::Shader* shader = curList->allocItem<ri::Shader>();
 
@@ -556,6 +557,14 @@ void TestResultParser::handleElementStart (void)
                                break;
                        }
 
+                       case ri::TYPE_SPIRVSOURCE:
+                       {
+                               if (parentType != ri::TYPE_SHADERPROGRAM)
+                                       throw TestResultParseError(string("<") + elemName + "> outside of <ShaderProgram>");
+                               item = curList->allocItem<ri::SpirVSource>();
+                               break;
+                       }
+
                        case ri::TYPE_SHADERSOURCE:
                                if (parentType == ri::TYPE_SHADER)
                                        item = &static_cast<ri::Shader*>(parentItem)->source;
@@ -776,6 +785,10 @@ void TestResultParser::handleData (void)
                        m_xmlParser.appendDataStr(static_cast<ri::ShaderSource*>(curItem)->source);
                        break;
 
+               case ri::TYPE_SPIRVSOURCE:
+                       m_xmlParser.appendDataStr(static_cast<ri::SpirVSource*>(curItem)->source);
+                       break;
+
                case ri::TYPE_INFOLOG:
                        m_xmlParser.appendDataStr(static_cast<ri::InfoLog*>(curItem)->log);
                        break;
index cd73668..1c95249 100644 (file)
@@ -41,7 +41,7 @@ namespace vk
 
 tcu::TestLog& operator<< (tcu::TestLog& log, const SpirVProgramInfo& shaderInfo)
 {
-       log << tcu::TestLog::ShaderProgram(shaderInfo.compileOk , shaderInfo.infoLog) << tcu::TestLog::EndShaderProgram;
+       log << tcu::TestLog::ShaderProgram(shaderInfo.compileOk , shaderInfo.infoLog) << tcu::TestLog::SpirVAssemblySource(shaderInfo.source->program.str()) << tcu::TestLog::EndShaderProgram;
 
        // Write statistics
        log << tcu::TestLog::Float(     "SpirVAssemblyTime",
index a6f41bc..df60b50 100644 (file)
@@ -393,6 +393,12 @@ void TestLog::writeShader (qpShaderType type, const char* source, bool compileOk
                throw LogWriteFailedError();
 }
 
+void TestLog::writeSpirVAssemblySource (const char* source)
+{
+       if (qpTestLog_writeSpirVAssemblySource(m_log, source) == DE_FALSE)
+               throw LogWriteFailedError();
+}
+
 void TestLog::writeKernelSource (const char* source)
 {
        if (qpTestLog_writeKernelSource(m_log, source) == DE_FALSE)
index 7d76921..5b2bc3c 100644 (file)
@@ -39,6 +39,7 @@ class LogImage;
 class LogSection;
 class LogShaderProgram;
 class LogShader;
+class LogSpirVAssemblySource;
 class LogKernelSource;
 class LogSampleList;
 class LogValueInfo;
@@ -89,16 +90,17 @@ public:
        static const class EndSampleListToken {}                EndSampleList;
 
        // Typedefs.
-       typedef LogImageSet                     ImageSet;
-       typedef LogImage                        Image;
-       typedef LogSection                      Section;
-       typedef LogShaderProgram        ShaderProgram;
-       typedef LogShader                       Shader;
-       typedef LogKernelSource         KernelSource;
-       typedef LogSampleList           SampleList;
-       typedef LogValueInfo            ValueInfo;
-       typedef LogNumber<float>        Float;
-       typedef LogNumber<deInt64>      Integer;
+       typedef LogImageSet                             ImageSet;
+       typedef LogImage                                Image;
+       typedef LogSection                              Section;
+       typedef LogShaderProgram                ShaderProgram;
+       typedef LogShader                               Shader;
+       typedef LogSpirVAssemblySource  SpirVAssemblySource;
+       typedef LogKernelSource                 KernelSource;
+       typedef LogSampleList                   SampleList;
+       typedef LogValueInfo                    ValueInfo;
+       typedef LogNumber<float>                Float;
+       typedef LogNumber<deInt64>              Integer;
 
        explicit                        TestLog                                 (const char* fileName, deUint32 flags = 0);
                                                ~TestLog                                (void);
@@ -116,6 +118,7 @@ public:
        TestLog&                        operator<<                              (const ShaderProgram& shaderProgram);
        TestLog&                        operator<<                              (const EndShaderProgramToken&);
        TestLog&                        operator<<                              (const Shader& shader);
+       TestLog&                        operator<<                              (const SpirVAssemblySource& module);
 
        TestLog&                        operator<<                              (const KernelSource& kernelSrc);
 
@@ -143,7 +146,7 @@ public:
        void                            startShaderProgram              (bool linkOk, const char* linkInfoLog);
        void                            endShaderProgram                (void);
        void                            writeShader                             (qpShaderType type, const char* source, bool compileOk, const char* infoLog);
-
+       void                            writeSpirVAssemblySource(const char* source);
        void                            writeKernelSource               (const char* source);
        void                            writeCompileInfo                (const char* name, const char* description, bool compileOk, const char* infoLog);
 
@@ -318,6 +321,20 @@ private:
        std::string             m_infoLog;
 };
 
+class LogSpirVAssemblySource
+{
+public:
+       LogSpirVAssemblySource (const std::string& source)
+               : m_source              (source)
+       {
+       }
+
+       void write (TestLog& log) const;
+
+private:
+       std::string             m_source;
+};
+
 class LogKernelSource
 {
 public:
@@ -420,6 +437,7 @@ inline TestLog& TestLog::operator<< (const EndSectionToken&)                        { endSection();
 inline TestLog& TestLog::operator<< (const ShaderProgram& shaderProg)  { shaderProg.write(*this);      return *this;   }
 inline TestLog& TestLog::operator<< (const EndShaderProgramToken&)             { endShaderProgram();           return *this;   }
 inline TestLog& TestLog::operator<< (const Shader& shader)                             { shader.write(*this);          return *this;   }
+inline TestLog& TestLog::operator<< (const SpirVAssemblySource& module)        { module.write(*this);          return *this;   }
 inline TestLog& TestLog::operator<< (const KernelSource& kernelSrc)            { kernelSrc.write(*this);       return *this;   }
 inline TestLog&        TestLog::operator<<     (const SampleList& sampleList)          { sampleList.write(*this);      return *this;   }
 inline TestLog&        TestLog::operator<<     (const SampleInfoToken&)                        { startSampleInfo();            return *this;   }
@@ -485,6 +503,11 @@ inline void LogShader::write (TestLog& log) const
        log.writeShader(m_type, m_source.c_str(), m_compileOk, m_infoLog.c_str());
 }
 
+inline void LogSpirVAssemblySource::write (TestLog& log) const
+{
+       log.writeSpirVAssemblySource(m_source.c_str());
+}
+
 inline void LogKernelSource::write (TestLog& log) const
 {
        log.writeKernelSource(m_source.c_str());
index 77e182a..26c7923 100644 (file)
@@ -144,7 +144,7 @@ typedef struct qpKeyStringMap_s
        char*   string;
 } qpKeyStringMap;
 
-static const char* LOG_FORMAT_VERSION = "0.3.3";
+static const char* LOG_FORMAT_VERSION = "0.3.4";
 
 /* Mapping enum to above strings... */
 static const qpKeyStringMap s_qpTestTypeMap[] =
@@ -1234,6 +1234,26 @@ deBool qpTestLog_writeKernelSource (qpTestLog* log, const char* source)
 }
 
 /*--------------------------------------------------------------------*//*!
+ * \brief Write a SPIR-V module assembly source into the log.
+ *//*--------------------------------------------------------------------*/
+deBool qpTestLog_writeSpirVAssemblySource (qpTestLog* log, const char* source)
+{
+       DE_ASSERT(log);
+       DE_ASSERT(ContainerStack_getTop(&log->containerStack) == CONTAINERTYPE_SHADERPROGRAM);
+       deMutex_lock(log->lock);
+
+       if (!qpXmlWriter_writeStringElement(log->writer, "SpirVAssemblySource", source))
+       {
+               qpPrintf("qpTestLog_writeSpirVAssemblySource(): Writing XML failed\n");
+               deMutex_unlock(log->lock);
+               return DE_FALSE;
+       }
+
+       deMutex_unlock(log->lock);
+       return DE_TRUE;
+}
+
+/*--------------------------------------------------------------------*//*!
  * \brief Write OpenCL kernel compilation results into the log
  *//*--------------------------------------------------------------------*/
 deBool qpTestLog_writeCompileInfo (qpTestLog* log, const char* name, const char* description, deBool compileOk, const char* infoLog)
index d03dfdd..aa74fa7 100644 (file)
@@ -216,6 +216,7 @@ deBool                      qpTestLog_endShaderProgram              (qpTestLog* log);
 deBool                         qpTestLog_writeShader                   (qpTestLog* log, qpShaderType type, const char* source, deBool compileOk, const char* infoLog);
 
 deBool                         qpTestLog_writeKernelSource             (qpTestLog* log, const char* source);
+deBool                         qpTestLog_writeSpirVAssemblySource      (qpTestLog* log, const char* source);
 deBool                         qpTestLog_writeCompileInfo              (qpTestLog* log, const char* name, const char* description, deBool compileOk, const char* infoLog);
 
 deBool                 qpTestLog_startSampleList               (qpTestLog* log, const char* name, const char* description);