do not serialize zero image/sampler info into binary
authorGuo Yejun <yejun.guo@intel.com>
Tue, 6 May 2014 19:34:37 +0000 (03:34 +0800)
committerZhigang Gong <zhigang.gong@intel.com>
Fri, 9 May 2014 02:34:19 +0000 (10:34 +0800)
if there is no image/sampler used in kernel source, it is not
necessary to serialize the zero image/sampler info into kernel binary.

Signed-off-by: Guo Yejun <yejun.guo@intel.com>
Signed-off-by: Zhigang Gong <zhigang.gong@intel.com>
backend/src/backend/program.cpp
backend/src/backend/program.hpp
backend/src/ir/image.hpp
backend/src/ir/sampler.hpp

index 79622e0..bdc7d34 100644 (file)
@@ -267,7 +267,7 @@ namespace gbe {
     OUT_UPDATE_SZ(compileWgSize[1]);
     OUT_UPDATE_SZ(compileWgSize[2]);
     /* samplers. */
-    if (samplerSet) {
+    if (!samplerSet->empty()) {   //samplerSet is always valid, allocated in Function::Function
       has_samplerset = 1;
       OUT_UPDATE_SZ(has_samplerset);
       size_t sz = samplerSet->serializeToBin(outs);
@@ -280,7 +280,7 @@ namespace gbe {
     }
 
     /* images. */
-    if (imageSet) {
+    if (!imageSet->empty()) {   //imageSet is always valid, allocated in Function::Function
       has_imageset = 1;
       OUT_UPDATE_SZ(has_imageset);
       size_t sz = imageSet->serializeToBin(outs);
@@ -369,6 +369,8 @@ namespace gbe {
 
       total_size += sz;
     }
+    else
+      samplerSet = NULL;
 
     IN_UPDATE_SZ(has_imageset);
     if (has_imageset) {
@@ -380,6 +382,8 @@ namespace gbe {
 
       total_size += sz;
     }
+    else
+      imageSet = NULL;
 
     IN_UPDATE_SZ(code_size);
     if (code_size) {
index 0e01256..fe945a6 100644 (file)
@@ -125,7 +125,7 @@ namespace gbe {
       samplerSet = from;
     }
     /*! Get defined sampler size */
-    size_t getSamplerSize(void) const { return samplerSet->getDataSize(); }
+    size_t getSamplerSize(void) const { return (samplerSet == NULL ? 0 : samplerSet->getDataSize()); }
     /*! Get defined sampler value array */
     void getSamplerData(uint32_t *samplers) const { samplerSet->getData(samplers); }
     /*! Set image set. */
@@ -145,7 +145,7 @@ namespace gbe {
        wg_sz[2] = compileWgSize[2];
     }
     /*! Get defined image size */
-    size_t getImageSize(void) const { return imageSet->getDataSize(); }
+    size_t getImageSize(void) const { return (imageSet == NULL ? 0 : imageSet->getDataSize()); }
     /*! Get defined image value array */
     void getImageData(ImageInfo *images) const { imageSet->getData(images); }
 
index cf388d4..a79e0a3 100644 (file)
@@ -61,6 +61,9 @@ namespace ir {
     void operator = (const ImageSet& other) {
       regMap.insert(other.regMap.begin(), other.regMap.end());
     }
+
+    bool empty() const { return regMap.empty(); }
+
     ImageSet(const ImageSet& other) : regMap(other.regMap.begin(), other.regMap.end()) { }
     ImageSet() {}
     ~ImageSet();
index dd1f3b6..2b51ce3 100644 (file)
@@ -56,6 +56,8 @@ namespace ir {
       samplerMap.insert(other.samplerMap.begin(), other.samplerMap.end());
     }
 
+    bool empty() const { return samplerMap.empty(); }
+
     SamplerSet(const SamplerSet& other) : samplerMap(other.samplerMap.begin(), other.samplerMap.end()) { }
     SamplerSet() {}