Пример #1
0
TEST(Log2, Basics) {
  for (int i = 0; i < 32; ++i) {
    uint32_t ui = 1u << i;
    EXPECT_EQ(i, Log2Int(ui));
  }

  for (int i = 1; i < 31; ++i) {
    uint32_t ui = 1u << i;
    EXPECT_EQ(i, Log2Int(ui + 1));
  }
}
Пример #2
0
// KdTreeAccel Method Definitions
KdTreeAccel::
    KdTreeAccel(const vector<Reference<Primitive> > &p,
		int icost, int tcost,
		float ebonus, int maxp, int maxDepth)
	: isectCost(icost), traversalCost(tcost),
	maxPrims(maxp), emptyBonus(ebonus) {
	vector<Reference<Primitive > > prims;
	for (u_int i = 0; i < p.size(); ++i)
		p[i]->FullyRefine(prims);
	// Initialize mailboxes for _KdTreeAccel_
	curMailboxId = 0;
	nMailboxes = prims.size();
	mailboxPrims = (MailboxPrim *)AllocAligned(nMailboxes *
		sizeof(MailboxPrim));
	for (u_int i = 0; i < nMailboxes; ++i)
		new (&mailboxPrims[i]) MailboxPrim(prims[i]);
	// Build kd-tree for accelerator
	nextFreeNode = nAllocedNodes = 0;
	if (maxDepth <= 0)
		maxDepth =
		    Round2Int(8 + 1.3f * Log2Int(float(prims.size())));
	// Compute bounds for kd-tree construction
	vector<BBox> primBounds;
	primBounds.reserve(prims.size());
	for (u_int i = 0; i < prims.size(); ++i) {
		BBox b = prims[i]->WorldBound();
		bounds = Union(bounds, b);
		primBounds.push_back(b);
	}
	// Allocate working memory for kd-tree construction
	BoundEdge *edges[3];
	for (int i = 0; i < 3; ++i)
		edges[i] = new BoundEdge[2*prims.size()];
	int *prims0 = new int[prims.size()];
	int *prims1 = new int[(maxDepth+1) * prims.size()];
	// Initialize _primNums_ for kd-tree construction
	int *primNums = new int[prims.size()];
	for (u_int i = 0; i < prims.size(); ++i)
		primNums[i] = i;
	// Start recursive construction of kd-tree
	buildTree(0, bounds, primBounds, primNums,
	          prims.size(), maxDepth, edges,
			  prims0, prims1);
	// Free working memory for kd-tree construction
	delete[] primNums;
	for (int i = 0; i < 3; ++i)
		delete[] edges[i];
	delete[] prims0;
	delete[] prims1;
}
Пример #3
0
// KDTree Method Definitions
KDTree::KDTree(Primitive** a_Primitives, unsigned int a_NumPrimitives, int icost, int tcost, float ebonus, int maxp, int md)
    : isectCost(icost), traversalCost(tcost), maxPrims(maxp), maxDepth(md),
      emptyBonus(ebonus) 
{
	g_candidates = 0;
	m_sName = "KDTree";
	m_pPrimitives = a_Primitives;
	m_uiNumPrimitives = a_NumPrimitives;

// Build kd-tree
    nextFreeNode = nAllocedNodes = 0;
    if (maxDepth <= 0)
		maxDepth = Round2Int(8 + 1.3f * Log2Int(float(m_uiNumPrimitives)));
	
	totalNodes = 0;
}
Пример #4
0
void ReportProfilerResults(FILE *dest) {
#ifndef PBRT_IS_WINDOWS
    uint64_t overallCount = 0;
    uint64_t eventCount[NumProfEvents] = {0};
    for (int i = 0; i < 1 << NumProfEvents; ++i) {
        uint64_t count = profileSamples[i].load();
        overallCount += count;
        for (int b = 0; b < NumProfEvents; ++b) {
            if (i & (1 << b)) eventCount[b] += count;
        }
    }

    std::map<std::string, uint64_t> flatResults;
    std::map<std::string, uint64_t> hierarchicalResults;
    for (int i = 0; i < 1 << NumProfEvents; ++i) {
        uint64_t count = profileSamples[i].load();
        if (count == 0) continue;

        std::string s;
        for (int b = 0; b < NumProfEvents; ++b) {
            if (i & (1 << b)) {
                if (s.size() > 0) {
                    // contribute to the parents...
                    hierarchicalResults[s] += count;
                    s += "/";
                }
                s += ProfNames[b];
            }
        }
        if (s == "") s = "Startup and scene construction";
        hierarchicalResults[s] = count;

        if (i == 0)
            flatResults[s] += count;
        else {
            // We actually want 31 - count of leading zeros, but this does
            // nicely.
            int innerIndex = Log2Int(i);
            flatResults[ProfNames[innerIndex]] += count;
        }
    }

    fprintf(dest, "  Profile\n");
    for (const auto &r : hierarchicalResults) {
        float pct = (100.f * r.second) / overallCount;
        int indent = 4;
        int slashIndex = r.first.find_last_of("/");
        if (slashIndex == std::string::npos)
            slashIndex = -1;
        else
            indent += 2 * std::count(r.first.begin(), r.first.end(), '/');
        const char *toPrint = r.first.c_str() + slashIndex + 1;
        fprintf(dest, "%*c%s%*c %5.2f %%\n", indent, ' ', toPrint,
                std::max(0, int(67 - strlen(toPrint) - indent)), ' ', pct);
    }

    fprintf(dest, "  Profile (flattened)\n");
    for (const auto &r : flatResults) {
        float pct = (100.f * r.second) / overallCount;
        int indent = 4;
        const char *toPrint = r.first.c_str();
        fprintf(dest, "%*c%s%*c %5.2f %%\n", indent, ' ', toPrint,
                std::max(0, int(67 - strlen(toPrint) - indent)), ' ', pct);
    }
    fprintf(dest, "\n");
#endif
}