void LightingParser_ResolveGBuffer(
        Metal::DeviceContext& context, LightingParserContext& parserContext,
        MainTargetsBox& mainTargets, LightingResolveTextureBox& lightingResTargets)
    {
        Metal::GPUProfiler::DebugAnnotation anno(context, L"ResolveGBuffer");

        const bool doSampleFrequencyOptimisation = Tweakable("SampleFrequencyOptimisation", true);

        LightingResolveContext lightingResolveContext(mainTargets);
        const unsigned samplingCount = lightingResolveContext.GetSamplingCount();
        const bool useMsaaSamplers = lightingResolveContext.UseMsaaSamplers();

        auto& resolveRes = Techniques::FindCachedBoxDep2<LightingResolveResources>(samplingCount);

            //
            //    Our inputs is the prepared gbuffer 
            //        -- we resolve the lighting and write out a "lighting resolve texture"
            //

        if (doSampleFrequencyOptimisation && samplingCount>1) {
            context.Bind(resolveRes._alwaysWriteToStencil, 0xff);

                // todo --  instead of clearing the stencil every time, how 
                //          about doing a progressive walk through all of the bits!
            context.ClearStencil(mainTargets._secondaryDepthBuffer, 0);
            context.Bind(ResourceList<Metal::RenderTargetView, 0>(), &mainTargets._secondaryDepthBuffer);
            context.BindPS(MakeResourceList(mainTargets._msaaDepthBufferSRV, mainTargets._gbufferRTVsSRV[1]));
            SetupVertexGeneratorShader(context);
            CATCH_ASSETS_BEGIN
                context.Bind(*resolveRes._perSampleMask);
                context.Draw(4);
            CATCH_ASSETS_END(parserContext)
        }
DataProviderDTang<Dtype>::DataProviderDTang(const pose::DataProviderParameter& param) : DataProvider<Dtype>(param) {
  std::cout << "[INFO] read label file " << param.dtang_param().label_path() << std::endl;
  
  boost::filesystem::path label_path = param.dtang_param().label_path();
  
  std::ifstream label_file(label_path.c_str());
  std::string line;
  
  int idx = 0;
  
  while(std::getline(label_file, line)) {
    std::istringstream iss(line);
    
    std::string relative_depth_path;
    iss >> relative_depth_path;

    boost::filesystem::path depth_path = label_path.parent_path() / "Depth" / 
      boost::filesystem::path(relative_depth_path);
    
    std::vector<cv::Vec3f> anno(param.n_pts());
    for(int pt_idx = 0; pt_idx < anno.size(); ++pt_idx) {
      iss >> anno[pt_idx](0);
      iss >> anno[pt_idx](1);
      iss >> anno[pt_idx](2);
    }
    
    //only load original data - no rotated
    if(depth_path.parent_path().parent_path().filename().string() == "Depth" && (idx % this->param_.inc() == 0)) {
      depth_paths_.push_back(depth_path);
      annos_.push_back(anno);
    }
    
    idx++;
  }
  
  this->max_idx_ = depth_paths_.size();
  
  label_file.close();
  
  std::cout << "[INFO] label file " << label_path << " contained " << depth_paths_.size() << " annotated depth images" << std::endl;       
}
// Write the class attributes portion of ClassFile structure
// JVMSpec|     u2 attributes_count;
// JVMSpec|     attribute_info attributes[attributes_count];
void JvmtiClassFileReconstituter::write_class_attributes() {
  u2 inner_classes_length = inner_classes_attribute_length();
  Symbol* generic_signature = ikh()->generic_signature();
  typeArrayHandle anno(thread(), ikh()->class_annotations());

  int attr_count = 0;
  if (generic_signature != NULL) {
    ++attr_count;
  }
  if (ikh()->source_file_name() != NULL) {
    ++attr_count;
  }
  if (ikh()->source_debug_extension() != NULL) {
    ++attr_count;
  }
  if (inner_classes_length > 0) {
    ++attr_count;
  }
  if (anno.not_null()) {
    ++attr_count;     // has RuntimeVisibleAnnotations attribute
  }

  write_u2(attr_count);

  if (generic_signature != NULL) {
    write_signature_attribute(symbol_to_cpool_index(generic_signature));
  }
  if (ikh()->source_file_name() != NULL) {
    write_source_file_attribute();
  }
  if (ikh()->source_debug_extension() != NULL) {
    write_source_debug_extension_attribute();
  }
  if (inner_classes_length > 0) {
    write_inner_classes_attribute(inner_classes_length);
  }
  if (anno.not_null()) {
    write_annotations_attribute("RuntimeVisibleAnnotations", anno);
  }
}
// Write the field information portion of ClassFile structure
// JVMSpec|     u2 fields_count;
// JVMSpec|     field_info fields[fields_count];
void JvmtiClassFileReconstituter::write_field_infos() {
  HandleMark hm(thread());
  objArrayHandle fields_anno(thread(), ikh()->fields_annotations());

  // Compute the real number of Java fields
  int java_fields = ikh()->java_fields_count();

  write_u2(java_fields);
  for (JavaFieldStream fs(ikh()); !fs.done(); fs.next()) {
    AccessFlags access_flags = fs.access_flags();
    int name_index = fs.name_index();
    int signature_index = fs.signature_index();
    int initial_value_index = fs.initval_index();
    guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field");
    // int offset = ikh()->field_offset( index );
    int generic_signature_index = fs.generic_signature_index();
    typeArrayHandle anno(thread(), fields_anno.not_null() ?
                                 (typeArrayOop)(fields_anno->obj_at(fs.index())) :
                                 (typeArrayOop)NULL);

    // JVMSpec|   field_info {
    // JVMSpec|         u2 access_flags;
    // JVMSpec|         u2 name_index;
    // JVMSpec|         u2 descriptor_index;
    // JVMSpec|         u2 attributes_count;
    // JVMSpec|         attribute_info attributes[attributes_count];
    // JVMSpec|   }

    write_u2(access_flags.as_int() & JVM_RECOGNIZED_FIELD_MODIFIERS);
    write_u2(name_index);
    write_u2(signature_index);
    int attr_count = 0;
    if (initial_value_index != 0) {
      ++attr_count;
    }
    if (access_flags.is_synthetic()) {
      // ++attr_count;
    }
    if (generic_signature_index != 0) {
      ++attr_count;
    }
    if (anno.not_null()) {
      ++attr_count;     // has RuntimeVisibleAnnotations attribute
    }

    write_u2(attr_count);

    if (initial_value_index != 0) {
      write_attribute_name_index("ConstantValue");
      write_u4(2); //length always 2
      write_u2(initial_value_index);
    }
    if (access_flags.is_synthetic()) {
      // write_synthetic_attribute();
    }
    if (generic_signature_index != 0) {
      write_signature_attribute(generic_signature_index);
    }
    if (anno.not_null()) {
      write_annotations_attribute("RuntimeVisibleAnnotations", anno);
    }
  }
}
// Write one method_info structure
// JVMSpec|   method_info {
// JVMSpec|     u2 access_flags;
// JVMSpec|     u2 name_index;
// JVMSpec|     u2 descriptor_index;
// JVMSpec|     u2 attributes_count;
// JVMSpec|     attribute_info attributes[attributes_count];
// JVMSpec|   }
void JvmtiClassFileReconstituter::write_method_info(methodHandle method) {
  AccessFlags access_flags = method->access_flags();
  constMethodHandle const_method(thread(), method->constMethod());
  u2 generic_signature_index = const_method->generic_signature_index();
  typeArrayHandle anno(thread(), method->annotations());
  typeArrayHandle param_anno(thread(), method->parameter_annotations());
  typeArrayHandle default_anno(thread(), method->annotation_default());

  write_u2(access_flags.get_flags() & JVM_RECOGNIZED_METHOD_MODIFIERS);
  write_u2(const_method->name_index());
  write_u2(const_method->signature_index());

  // write attributes in the same order javac does, so we can test with byte for
  // byte comparison
  int attr_count = 0;
  if (const_method->code_size() != 0) {
    ++attr_count;     // has Code attribute
  }
  if (const_method->has_checked_exceptions()) {
    ++attr_count;     // has Exceptions attribute
  }
  if (default_anno.not_null()) {
    ++attr_count;     // has AnnotationDefault attribute
  }
  // Deprecated attribute would go here
  if (access_flags.is_synthetic()) { // FIXME
    // ++attr_count;
  }
  if (generic_signature_index != 0) {
    ++attr_count;
  }
  if (anno.not_null()) {
    ++attr_count;     // has RuntimeVisibleAnnotations attribute
  }
  if (param_anno.not_null()) {
    ++attr_count;     // has RuntimeVisibleParameterAnnotations attribute
  }

  write_u2(attr_count);
  if (const_method->code_size() > 0) {
    write_code_attribute(method);
  }
  if (const_method->has_checked_exceptions()) {
    write_exceptions_attribute(const_method);
  }
  if (default_anno.not_null()) {
    write_annotations_attribute("AnnotationDefault", default_anno);
  }
  // Deprecated attribute would go here
  if (access_flags.is_synthetic()) {
    // write_synthetic_attribute();
  }
  if (generic_signature_index != 0) {
    write_signature_attribute(generic_signature_index);
  }
  if (anno.not_null()) {
    write_annotations_attribute("RuntimeVisibleAnnotations", anno);
  }
  if (param_anno.not_null()) {
    write_annotations_attribute("RuntimeVisibleParameterAnnotations", param_anno);
  }
}
// Write the field information portion of ClassFile structure
// JVMSpec|   	u2 fields_count;
// JVMSpec|   	field_info fields[fields_count];
void JvmtiClassFileReconstituter::write_field_infos() {  
  HandleMark hm(thread());
  typeArrayHandle fields(thread(), ikh()->fields());
  int fields_length = fields->length();
  int num_fields = fields_length / instanceKlass::next_offset;
  objArrayHandle fields_anno(thread(), ikh()->fields_annotations());

  write_u2(num_fields);  
  for (int index = 0; index < fields_length; index += instanceKlass::next_offset) {
    AccessFlags access_flags;
    int flags = fields->ushort_at(index + instanceKlass::access_flags_offset);
    access_flags.set_flags(flags);
    int name_index = fields->ushort_at(index + instanceKlass::name_index_offset);
    int signature_index = fields->ushort_at(index + instanceKlass::signature_index_offset);
    int initial_value_index = fields->ushort_at(index + instanceKlass::initval_index_offset);
    guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field");
    int offset = ikh()->offset_from_fields( index );
    int generic_signature_index = 
                        fields->ushort_at(index + instanceKlass::generic_signature_offset);
    typeArrayHandle anno(thread(), fields_anno.not_null() ? 
                                 (typeArrayOop)(fields_anno->obj_at(index / instanceKlass::next_offset)) :
                                 (typeArrayOop)NULL);

    // JVMSpec|   field_info {
    // JVMSpec|   	u2 access_flags;
    // JVMSpec|   	u2 name_index;
    // JVMSpec|   	u2 descriptor_index;
    // JVMSpec|   	u2 attributes_count;
    // JVMSpec|   	attribute_info attributes[attributes_count];
    // JVMSpec|   }

    write_u2(flags & JVM_RECOGNIZED_FIELD_MODIFIERS); 
    write_u2(name_index); 
    write_u2(signature_index); 
    int attr_count = 0;
    if (initial_value_index != 0) {
      ++attr_count;
    }
    if (access_flags.is_synthetic()) {
      // ++attr_count;
    }
    if (generic_signature_index != 0) {
      ++attr_count;
    }
    if (anno.not_null()) {
      ++attr_count;     // has RuntimeVisibleAnnotations attribute
    }

    write_u2(attr_count); 

    if (initial_value_index != 0) {
      write_attribute_name_index("ConstantValue");
      write_u4(2); //length always 2
      write_u2(initial_value_index);
    }
    if (access_flags.is_synthetic()) {
      // write_synthetic_attribute();
    }
    if (generic_signature_index != 0) {
      write_signature_attribute(generic_signature_index);
    }
    if (anno.not_null()) {
      write_annotations_attribute("RuntimeVisibleAnnotations", anno);
    }
  }
}