Esempio n. 1
0
SamplerState::SamplerState()
{
    memset(this, 0, sizeof(SamplerState));

    setMinFilter(GL_NEAREST_MIPMAP_LINEAR);
    setMagFilter(GL_LINEAR);
    setWrapS(GL_REPEAT);
    setWrapT(GL_REPEAT);
    setWrapR(GL_REPEAT);
    setMaxAnisotropy(1.0f);
    setMinLod(-1000.0f);
    setMaxLod(1000.0f);
    setCompareMode(GL_NONE);
    setCompareFunc(GL_LEQUAL);
    setSRGBDecode(GL_DECODE_EXT);
}
bool ThreadedDynamicOutputManager::checkDynamicCancel(const Event* event,
                                                      int threadId) {
    //This method will just perform the LazyOutputManager::checkLazyCancelEvent.
    //Based on the bool result, a hit or miss will be recorded.
    //Messages are only suppressed when the current mode is Lazy and there is a hit.
    //The curMeasured will be kept track of using the filterdepth.
    //The event will not be inserted and events will not be cancelled.

    bool suppressMessage = false;
    bool lazyCancelHit = false;
    int numCancelledEvents = 0;
    SimulationObject* sender = getSimulationManager()->getObjectHandle(
                                   event->getSender());
    int objID = sender->getObjectID()->getSimulationObjectID();

    // Only do the check if there are any events to check.
    if ((lazyQueues[objID])->size() > 0) {
        if (!(*permanentlyAggressive[objID])) {
            setCompareMode(sender, *curCancelMode[objID] == Lazy);
            lazyCancelHit = ThreadedLazyOutputManager::checkLazyCancelEvent(
                                event, threadId);
            numCancelledEvents = (eventsToCancel[objID])->size();

            if (*curCancelMode[objID] == Lazy) {
                suppressMessage = lazyCancelHit;
                if (lazyCancelHit && getCompareMode(sender)) {
                    //Inserting the original event, reclaim this one.
                    sender->reclaimEvent(event);
                } else {
                    ThreadedOutputManagerImplementationBase::insert(event,
                                                                    threadId);
                }
                ThreadedLazyOutputManager::handleCancelEvents(sender, threadId);
            } else {
                eventsToCancel[objID]->clear();
                ThreadedOutputManagerImplementationBase::insert(event, threadId);
            }

            // Record a lazy hit.
            if (lazyCancelHit) {
                (*(comparisonResults[objID]))[(*curMeasured[objID])
                                              % filterDepth] = 1;
                *curMeasured[objID] = *curMeasured[objID] + 1;
            }

            // Record a lazy miss.
            // Misses may have to be recorded as the size of the cancellation queue eventsToCancel.
            for (int i = 0; i < numCancelledEvents; i++) {
                (*(comparisonResults[objID]))[(*curMeasured[objID])
                                              % filterDepth] = 0;
                *curMeasured[objID] = *curMeasured[objID] + 1;
            }

            if (*curMeasured[objID] >= filterDepth) {
                determinecancellationModes(objID, threadId);
                *curMeasured[objID] = 0;
            }
        } else {
            ThreadedOutputManagerImplementationBase::insert(event, threadId);
        }
    } else {
        ThreadedOutputManagerImplementationBase::insert(event, threadId);
    }

    return suppressMessage;
}
cancellationModes ThreadedDynamicOutputManager::determinecancellationModes(
    int objID, int threadId) {
    // Calculate the hit ratio. Based on the hitRatio, determine which
    // mode should be used. Return that mode.

    SimulationObject* object = getSimulationManager()->getObjectHandle(objID);
    bool lazyToAggr = false;
    bool aggrToLazy = false;

    *hitCount[objID] = 0;
    vector<int>* compRes = comparisonResults[objID];

    for (int i = 0; i < filterDepth; i++) {
        if ((*compRes)[i] == 1) {
            *hitCount[objID] = (*hitCount[objID]) + 1;
        }
    }

    *hitRatio[objID] = (float)(*hitCount[objID]) / filterDepth;
    debug::debugout << "Object " << objID << " Hit Ratio is " << *hitRatio[objID]
                    << endl;

    // If the hit ratio is between the AGGRESSIVE_TO_LAZY and LAZY_TO_AGGRESSIVE
    // values, then do not change the mode.
    if (thirdThreshold && *hitRatio[objID] < third_threshold) {
        if (*curCancelMode[objID] == Lazy) {
            debug::debugout << "Object " << objID
                            << " Switching from Lazy to Aggressive Output Manager PERMANENTLY.\n";
            lazyToAggr = true;
        }
        *curCancelMode[objID] = Aggressive;
        setCompareMode(object, false);
        *permanentlyAggressive[objID] = true;
    } else if ((*curCancelMode[objID]) == Lazy && (*hitRatio[objID])
               < lazy_to_aggressive) {
        debug::debugout << "Object " << objID
                        << " Switching from Lazy to Aggressive Output Manager.\n";
        *curCancelMode[objID] = Aggressive;
        setCompareMode(object, false);
        lazyToAggr = true;
    } else if ((*curCancelMode[objID]) == Aggressive && (*hitRatio[objID])
               > aggressive_to_lazy) {
        debug::debugout << "Object " << objID
                        << " Switching from Aggressive to Lazy Output Manager.\n";
        *curCancelMode[objID] = Lazy;
        setCompareMode(object, true);
        aggrToLazy = true;
    }

    // Any possible regenerated events remaining in the lazy cancel queue have
    // already been cancelled and need to be sent, so it is essentially remaining
    // in aggressive mode until the next rollback. End this current cancellation phase
    // by emptying the lazy cancel queue.
    if (aggrToLazy) {
        (lazyQueues[objID])->clear();
    }

    // Cancel the rest of the events in the lazy cancel queue. No proceeding
    // events will be suppressed.
    if (lazyToAggr) {
        (eventsToCancel[objID])->insert((eventsToCancel[objID])->end(),
                                        (lazyQueues[objID])->begin(), (lazyQueues[objID])->end());
        handleCancelEvents(object, threadId);
        (lazyQueues[objID])->clear();
    }

    *curMeasured[objID] = 0;

    return *curCancelMode[objID];
}