Beispiel #1
0
void Schedule::accept(IRVisitor *visitor) const {
    for (const ReductionVariable &r : rvars()) {
        if (r.min.defined()) {
            r.min.accept(visitor);
        }
        if (r.extent.defined()) {
            r.extent.accept(visitor);
        }
    }
    for (const Split &s : splits()) {
        if (s.factor.defined()) {
            s.factor.accept(visitor);
        }
    }
    for (const Bound &b : bounds()) {
        if (b.min.defined()) {
            b.min.accept(visitor);
        }
        if (b.extent.defined()) {
            b.extent.accept(visitor);
        }
        if (b.modulus.defined()) {
            b.modulus.accept(visitor);
        }
        if (b.remainder.defined()) {
            b.remainder.accept(visitor);
        }
    }
}
Beispiel #2
0
	// find a command implementation that matches the given command string either by full name or abbreviation
	// and return it. The command will be stripped by leading command identifier and delimeter and returned in params.
	static Command* find(const QString& cmdString, QString& params)
	{
		bool found = false;

		foreach(Command* cmd, s_attached) {
			if(cmd->delimeter().isNull()) {
				if(cmdString.startsWith(cmd->full())) {
					params = cmdString.mid(cmd->full().length());
					found = true;
				}
				else if(not cmd->abbrev().isEmpty() and cmdString.startsWith(cmd->abbrev(), Qt::CaseInsensitive)) {
					params = cmdString.mid(cmd->abbrev().length());
					found = true;
				}
			}
			else {
				QStringList splits(cmdString.split(cmd->delimeter()));
				if(not splits.isEmpty() and (splits.first() == cmd->full() or splits.first() == cmd->abbrev())) {
					splits.removeFirst();
					params = splits.join(cmd->delimeter());
					found = true;
				}
			}
			if(found)
				return cmd;
		}

		// none found.
		return 0;
	} // find
Beispiel #3
0
void KSplitTransactionDlg::updateSums()
{
    MyMoneyMoney splits(splitsValue());

    if (m_amountValid == false) {
        m_split.setValue(-splits);
        m_transaction.modifySplit(m_split);
    }

    splitSum->setText("<b>" + splits.formatMoney("", m_precision) + ' ');
    splitUnassigned->setText("<b>" + diffAmount().formatMoney("", m_precision) + ' ');
    transactionAmount->setText("<b>" + (-m_split.value()).formatMoney("", m_precision) + ' ');
}
Beispiel #4
0
void Schedule::accept(IRVisitor *visitor) const {
    for (const Split &s : splits()) {
        if (s.factor.defined()) {
            s.factor.accept(visitor);
        }
    }
    for (const Bound &b : bounds()) {
        if (b.min.defined()) {
            b.min.accept(visitor);
        }
        if (b.extent.defined()) {
            b.extent.accept(visitor);
        }
    }
    for (const Specialization &s : specializations()) {
        s.condition.accept(visitor);
    }
}
Beispiel #5
0
void StageSchedule::accept(IRVisitor *visitor) const {
    for (const ReductionVariable &r : rvars()) {
        if (r.min.defined()) {
            r.min.accept(visitor);
        }
        if (r.extent.defined()) {
            r.extent.accept(visitor);
        }
    }
    for (const Split &s : splits()) {
        if (s.factor.defined()) {
            s.factor.accept(visitor);
        }
    }
    for (const PrefetchDirective &p : prefetches()) {
        if (p.offset.defined()) {
            p.offset.accept(visitor);
        }
    }
}
Beispiel #6
0
void
diy::detail::KDTreeSamplingPartition<Block,Point>::
update_links(Block* b, const diy::ReduceProxy& srp, int dim, int round, int rounds, bool wrap, const Bounds& domain) const
{
    auto        log  = get_logger();
    int         gid  = srp.gid();
    int         lid  = srp.master()->lid(gid);
    RCLink*     link = static_cast<RCLink*>(srp.master()->link(lid));

    // (gid, dir) -> i
    std::map<std::pair<int,diy::Direction>, int> link_map;
    for (int i = 0; i < link->size(); ++i)
        link_map[std::make_pair(link->target(i).gid, link->direction(i))] = i;

    // NB: srp.enqueue(..., ...) should match the link
    std::vector<float>  splits(link->size());
    for (int i = 0; i < link->size(); ++i)
    {
        float split; diy::Direction dir;

        int in_gid = link->target(i).gid;
        while(srp.incoming(in_gid))
        {
            srp.dequeue(in_gid, split);
            srp.dequeue(in_gid, dir);

            // reverse dir
            for (int j = 0; j < dim_; ++j)
                dir[j] = -dir[j];

            int k = link_map[std::make_pair(in_gid, dir)];
            log->trace("{} {} {} -> {}", in_gid, dir, split, k);
            splits[k] = split;
        }
    }

    RCLink      new_link(dim_, link->core(), link->core());

    bool lower = !(gid & (1 << (rounds - 1 - round)));

    // fill out the new link
    for (int i = 0; i < link->size(); ++i)
    {
        diy::Direction  dir = link->direction(i);
        //diy::Direction  wrap_dir = link->wrap(i);     // we don't use existing wrap, but restore it from scratch
        if (dir[dim] != 0)
        {
            if ((dir[dim] < 0 && lower) || (dir[dim] > 0 && !lower))
            {
                int nbr_gid = divide_gid(link->target(i).gid, !lower, round, rounds);
                diy::BlockID nbr = { nbr_gid, srp.assigner().rank(nbr_gid) };
                new_link.add_neighbor(nbr);

                new_link.add_direction(dir);

                Bounds bounds = link->bounds(i);
                update_neighbor_bounds(bounds, splits[i], dim, !lower);
                new_link.add_bounds(bounds);

                if (wrap)
                    new_link.add_wrap(find_wrap(new_link.bounds(), bounds, domain));
                else
                    new_link.add_wrap(diy::Direction());
            }
        } else // non-aligned side
        {
            for (int j = 0; j < 2; ++j)
            {
                int nbr_gid = divide_gid(link->target(i).gid, j == 0, round, rounds);

                Bounds  bounds  = link->bounds(i);
                update_neighbor_bounds(bounds, splits[i], dim, j == 0);

                if (intersects(bounds, new_link.bounds(), dim, wrap, domain))
                {
                    diy::BlockID nbr = { nbr_gid, srp.assigner().rank(nbr_gid) };
                    new_link.add_neighbor(nbr);
                    new_link.add_direction(dir);
                    new_link.add_bounds(bounds);

                    if (wrap)
                        new_link.add_wrap(find_wrap(new_link.bounds(), bounds, domain));
                    else
                        new_link.add_wrap(diy::Direction());
                }
            }
        }
    }

    // add link to the dual block
    int dual_gid = divide_gid(gid, !lower, round, rounds);
    diy::BlockID dual = { dual_gid, srp.assigner().rank(dual_gid) };
    new_link.add_neighbor(dual);

    Bounds nbr_bounds = link->bounds();     // old block bounds
    update_neighbor_bounds(nbr_bounds, find_split(new_link.bounds(), nbr_bounds), dim, !lower);
    new_link.add_bounds(nbr_bounds);

    new_link.add_wrap(diy::Direction());    // dual block cannot be wrapped

    if (lower)
    {
        diy::Direction right;
        right[dim] = 1;
        new_link.add_direction(right);
    } else
    {
        diy::Direction left;
        left[dim] = -1;
        new_link.add_direction(left);
    }

    // update the link; notice that this won't conflict with anything since
    // reduce is using its own notion of the link constructed through the
    // partners
    link->swap(new_link);
}
Beispiel #7
0
void ShadowMap::render_cascaded(RenderContext const& ctx,
              SceneGraph const& scene_graph,
              math::vec3 const& center_of_interest,
              Frustum const& scene_frustum,
              Camera const& scene_camera,
              math::mat4 const& transform,
              unsigned map_size, float split_0,
              float split_1, float split_2,
              float split_3, float split_4,
              float near_clipping_in_sun_direction) {

  update_members(ctx, map_size*2);
  projection_view_matrices_ = std::vector<math::mat4>(4);

  buffer_->bind(ctx);
  buffer_->clear_depth_stencil_buffer(ctx);

  ctx.render_context->set_depth_stencil_state(depth_stencil_state_);
  ctx.render_context->set_rasterizer_state(rasterizer_state_);

  std::vector<float> splits({
    split_0, split_1, split_2, split_3, split_4
  });

  if (pipeline_->config.near_clip() > split_0 || pipeline_->config.far_clip() < split_4) {
    Logger::LOG_WARNING << "Splits of cascaded shadow maps are not inside clipping range! Fallback to equidistant splits used." << std::endl;
    float clipping_range(pipeline_->config.far_clip() - pipeline_->config.near_clip());
    splits = {
      pipeline_->config.near_clip(),
      pipeline_->config.near_clip() + clipping_range * 0.25f,
      pipeline_->config.near_clip() + clipping_range * 0.5f,
      pipeline_->config.near_clip() + clipping_range * 0.75f,
      pipeline_->config.far_clip()
    };
  }

  for (int y(0); y<2; ++y) {
    for (int x(0); x<2; ++x) {

      int cascade(y*2 + x);

      // render each cascade to a quarter of the shadow map
      ctx.render_context->set_viewport(scm::gl::viewport(
          math::vec2(x * map_size, y * map_size),
          math::vec2(map_size, map_size)));

      // set clipping of camera frustum according to current cascade
      Frustum cropped_frustum(Frustum::perspective(
        scene_frustum.get_camera_transform(),
        scene_frustum.get_screen_transform(),
        splits[cascade], splits[cascade+1]
      ));

      // transform cropped frustum tu sun space and calculate radius and bbox
      // of transformed frustum
      auto cropped_frustum_corners(cropped_frustum.get_corners());
      math::BoundingBox<math::vec3> extends_in_sun_space;
      float radius_in_sun_space = 0;
      std::vector<math::vec3> corners_in_sun_space;
      math::vec3 center_in_sun_space(0, 0, 0);

      auto inverse_sun_transform(scm::math::inverse(transform));
      for (auto const& corner: cropped_frustum_corners) {
        math::vec3 new_corner(inverse_sun_transform * corner);
        center_in_sun_space += new_corner/8;
        corners_in_sun_space.push_back(new_corner);
        extends_in_sun_space.expandBy(new_corner);
      }

      for (auto const& corner: corners_in_sun_space) {
        float radius = scm::math::length(corner-center_in_sun_space);
        if (radius > radius_in_sun_space)
          radius_in_sun_space = radius;
      }

      // center of front plane of frustum
      auto center(math::vec3((extends_in_sun_space.min[0] + extends_in_sun_space.max[0])/2,
                             (extends_in_sun_space.min[1] + extends_in_sun_space.max[1])/2,
                              extends_in_sun_space.max[2] + near_clipping_in_sun_direction));

      // eliminate sub-pixel movement
      float tex_coord_x = center.x * map_size / radius_in_sun_space / 2;
      float tex_coord_y = center.y * map_size / radius_in_sun_space / 2;

      float tex_coord_rounded_x = round(tex_coord_x);
      float tex_coord_rounded_y = round(tex_coord_y);

      float dx = tex_coord_rounded_x - tex_coord_x;
      float dy = tex_coord_rounded_y - tex_coord_y;

      dx /= map_size / radius_in_sun_space / 2;
      dy /= map_size / radius_in_sun_space / 2;

      center.x += dx;
      center.y += dy;

      // calculate transformation of shadow screen
      auto screen_in_sun_space(scm::math::make_translation(center) * scm::math::make_scale(radius_in_sun_space*2, radius_in_sun_space*2, 1.0f));
      auto sun_screen_transform(transform * screen_in_sun_space);

      // calculate transformation of shadow eye
      auto sun_eye_transform(scm::math::make_translation(sun_screen_transform.column(3)[0], sun_screen_transform.column(3)[1], sun_screen_transform.column(3)[2]));
      auto sun_eye_depth(transform * math::vec4(0, 0, extends_in_sun_space.max[2] - extends_in_sun_space.min[2] + near_clipping_in_sun_direction, 0.0f));

      auto shadow_frustum(
        Frustum::orthographic(
          sun_eye_transform,
          sun_screen_transform,
          0,
          scm::math::length(sun_eye_depth)
        )
      );

      // render geometries
      render_geometry(ctx, scene_graph, center_of_interest, shadow_frustum, scene_camera, cascade, map_size);
    }
  }

  ctx.render_context->reset_state_objects();

  buffer_->unbind(ctx);

}