void
ShaderInstance::compute_run_lazily (const ShaderGroup &group)
{
    if (shadingsys().m_lazylayers) {
        // lazylayers option turned on: unconditionally run shaders with no
        // outgoing connections ("root" nodes, including the last in the
        // group) or shaders that alter global variables (unless
        // 'lazyglobals' is turned on).
        if (shadingsys().m_lazyglobals) {
            if (group[group.nlayers()-1] == this)
                run_lazily (false);  // force run of last group
            else
                run_lazily ((outgoing_connections() && ! renderer_outputs())
                            || empty_instance() || merged_unused());
        }
        else
            run_lazily (outgoing_connections() && ! writes_globals()
                        && ! renderer_outputs());
#if 0
        // Suggested warning below... but are there use cases where people
        // want these to run (because they will extract the results they
        // want from output params)?
        if (! outgoing_connections() && ! empty_instance() &&
                ! writes_globals() && ! renderer_outputs())
            shadingsys().warning ("Layer \"%s\" (shader %s) will run even though it appears to have no used results",
                                  layername(), shadername());
#endif
    } else {
        // lazylayers option turned off: never run lazily
        run_lazily (false);
    }
}
예제 #2
0
std::string
ShaderInstance::print ()
{
    std::stringstream out;
    out << "Shader " << shadername() << "\n";
    out << "  symbols:\n";
    for (size_t i = 0;  i < m_instsymbols.size();  ++i) {
        const Symbol &s (*symbol(i));
        s.print (out);
    }
#if 0
    out << "  int consts:\n    ";
    for (size_t i = 0;  i < m_iconsts.size();  ++i)
        out << m_iconsts[i] << ' ';
    out << "\n";
    out << "  float consts:\n    ";
    for (size_t i = 0;  i < m_fconsts.size();  ++i)
        out << m_fconsts[i] << ' ';
    out << "\n";
    out << "  string consts:\n    ";
    for (size_t i = 0;  i < m_sconsts.size();  ++i)
        out << "\"" << Strutil::escape_chars(m_sconsts[i]) << "\" ";
    out << "\n";
#endif
    out << "  code:\n";
    for (size_t i = 0;  i < m_instops.size();  ++i) {
        const Opcode &op (m_instops[i]);
        if (i == (size_t)maincodebegin())
            out << "(main)\n";
        out << "    " << i << ": " << op.opname();
        bool allconst = true;
        for (int a = 0;  a < op.nargs();  ++a) {
            const Symbol *s (argsymbol(op.firstarg()+a));
            out << " " << s->name();
            if (s->symtype() == SymTypeConst) {
                out << " (";
                s->print_vals(out);
                out << ")";
            }
            if (op.argread(a))
                allconst &= s->is_constant();
        }
        for (size_t j = 0;  j < Opcode::max_jumps;  ++j)
            if (op.jump(j) >= 0)
                out << " " << op.jump(j);
//        out << "    rw " << Strutil::format("%x",op.argread_bits())
//            << ' ' << op.argwrite_bits();
        if (op.argtakesderivs_all())
            out << " %derivs(" << op.argtakesderivs_all() << ") ";
        if (allconst)
            out << "  CONST";
        std::string filename = op.sourcefile().string();
        size_t slash = filename.find_last_of ("/");
        if (slash != std::string::npos)
            filename.erase (0, slash+1);
        out << "  (" << filename << ":" << op.sourceline() << ")";
        out << "\n";
    }
    return out.str ();
}
예제 #3
0
bool ExplosionEffect::loadData()
{
    mInited = true;
    if (!ShaderManager::instance()->isValid()) {
        return false;
    }
    QString shadername("explosion");
    const QString fragmentshader =  KGlobal::dirs()->findResource("data", "kwin/explosion.frag");
    QString starttexture =  KGlobal::dirs()->findResource("data", "kwin/explosion-start.png");
    QString endtexture =  KGlobal::dirs()->findResource("data", "kwin/explosion-end.png");
    if (starttexture.isEmpty() || endtexture.isEmpty()) {
        kError(1212) << "Couldn't locate texture files" << endl;
        return false;
    }

    mShader = ShaderManager::instance()->loadFragmentShader(ShaderManager::GenericShader, fragmentshader);
    if (!mShader->isValid()) {
        kError(1212) << "The shader failed to load!" << endl;
        return false;
    } else {
        ShaderManager::instance()->pushShader(mShader);
        mShader->setUniform("startOffsetTexture", 4);
        mShader->setUniform("endOffsetTexture", 5);
        ShaderManager::instance()->popShader();
    }

    mStartOffsetTex = new GLTexture(starttexture);
    mEndOffsetTex = new GLTexture(endtexture);
    if (mStartOffsetTex->isNull() || mEndOffsetTex->isNull()) {
        kError(1212) << "The textures failed to load!" << endl;
        return false;
    } else {
        mStartOffsetTex->setFilter(GL_LINEAR);
        mEndOffsetTex->setFilter(GL_LINEAR);
    }

    return true;
}
예제 #4
0
std::string
ShaderInstance::print ()
{
    std::stringstream out;
    out << "Shader " << shadername() << "\n";
    out << "  symbols:\n";
    for (size_t i = 0;  i < m_instsymbols.size();  ++i) {
        const Symbol &s (*symbol(i));
        out << "    " << i << ": " << Symbol::symtype_shortname(s.symtype())
            << " " << s.typespec().string() << " " << s.name();
        if (s.everused())
            out << " (used " << s.firstuse() << ' ' << s.lastuse() 
                << " read " << s.firstread() << ' ' << s.lastread() 
                << " write " << s.firstwrite() << ' ' << s.lastwrite();
        else
            out << " (unused";
        out << (s.has_derivs() ? " derivs" : "") << ")";
        if (s.symtype() == SymTypeParam || s.symtype() == SymTypeOutputParam) {
            if (s.has_init_ops())
                out << " init [" << s.initbegin() << ',' << s.initend() << ")";
            if (s.connected())
                out << " connected";
            if (s.connected_down())
                out << " down-connected";
            if (!s.connected() && !s.connected_down())
                out << " unconnected";
        }
        out << "\n";
        if (s.symtype() == SymTypeConst || 
            ((s.symtype() == SymTypeParam || s.symtype() == SymTypeOutputParam) &&
             s.valuesource() == Symbol::DefaultVal && !s.has_init_ops())) {
            if (s.symtype() == SymTypeConst)
                out << "\tconst: ";
            else
                out << "\tdefault: ";
            out << print_vals (s);
            out << "\n";
        }
    }
#if 0
    out << "  int consts:\n    ";
    for (size_t i = 0;  i < m_iconsts.size();  ++i)
        out << m_iconsts[i] << ' ';
    out << "\n";
    out << "  float consts:\n    ";
    for (size_t i = 0;  i < m_fconsts.size();  ++i)
        out << m_fconsts[i] << ' ';
    out << "\n";
    out << "  string consts:\n    ";
    for (size_t i = 0;  i < m_sconsts.size();  ++i)
        out << "\"" << m_sconsts[i] << "\" ";
    out << "\n";
#endif
    out << "  code:\n";
    for (size_t i = 0;  i < m_instops.size();  ++i) {
        const Opcode &op (m_instops[i]);
        out << "    " << i << ": " << op.opname();
        bool allconst = true;
        for (int a = 0;  a < op.nargs();  ++a) {
            const Symbol *s (argsymbol(op.firstarg()+a));
            out << " " << s->name();
            if (s->symtype() == SymTypeConst)
                out << " (" << print_vals(*s) << ")";
            if (op.argread(a))
                allconst &= s->is_constant();
        }
        for (size_t j = 0;  j < Opcode::max_jumps;  ++j)
            if (op.jump(j) >= 0)
                out << " " << op.jump(j);
//        out << "    rw " << Strutil::format("%x",op.argread_bits())
//            << ' ' << op.argwrite_bits();
        if (op.argtakesderivs_all())
            out << " %derivs(" << op.argtakesderivs_all() << ") ";
        if (allconst)
            out << "  CONST";
        std::string filename = op.sourcefile().string();
        size_t slash = filename.find_last_of ("/");
        if (slash != std::string::npos)
            filename.erase (0, slash+1);
        out << "  (" << filename << ":" << op.sourceline() << ")";
        out << "\n";
    }
    return out.str ();
}
std::string
ShaderInstance::print (const ShaderGroup &group)
{
    std::stringstream out;
    out << "Shader " << shadername() << "\n";
    out << "  symbols:\n";
    for (size_t i = 0;  i < m_instsymbols.size();  ++i) {
        const Symbol &s (*symbol(i));
        s.print (out, 256);
    }
#if 0
    out << "  int consts:\n    ";
    for (size_t i = 0;  i < m_iconsts.size();  ++i)
        out << m_iconsts[i] << ' ';
    out << "\n";
    out << "  float consts:\n    ";
    for (size_t i = 0;  i < m_fconsts.size();  ++i)
        out << m_fconsts[i] << ' ';
    out << "\n";
    out << "  string consts:\n    ";
    for (size_t i = 0;  i < m_sconsts.size();  ++i)
        out << "\"" << Strutil::escape_chars(m_sconsts[i]) << "\" ";
    out << "\n";
#endif
    out << "  code:\n";
    for (size_t i = 0;  i < m_instops.size();  ++i) {
        const Opcode &op (m_instops[i]);
        if (i == (size_t)maincodebegin())
            out << "(main)\n";
        out << "    " << i << ": " << op.opname();
        bool allconst = true;
        for (int a = 0;  a < op.nargs();  ++a) {
            const Symbol *s (argsymbol(op.firstarg()+a));
            out << " " << s->name();
            if (s->symtype() == SymTypeConst) {
                out << " (";
                s->print_vals(out,16);
                out << ")";
            }
            if (op.argread(a))
                allconst &= s->is_constant();
        }
        for (size_t j = 0;  j < Opcode::max_jumps;  ++j)
            if (op.jump(j) >= 0)
                out << " " << op.jump(j);
//        out << "    rw " << Strutil::format("%x",op.argread_bits())
//            << ' ' << op.argwrite_bits();
        if (op.argtakesderivs_all())
            out << " %derivs(" << op.argtakesderivs_all() << ") ";
        if (allconst)
            out << "  CONST";
        std::string filename = op.sourcefile().string();
        size_t slash = filename.find_last_of ("/");
        if (slash != std::string::npos)
            filename.erase (0, slash+1);
        if (filename.length())
            out << "  (" << filename << ":" << op.sourceline() << ")";
        out << "\n";
    }
    if (nconnections()) {
        out << "  connections upstream:\n";
        for (int i = 0, e = nconnections(); i < e; ++i) {
            const Connection &c (connection(i));
            out << "    " << c.dst.type.c_str() << ' '
                << symbol(c.dst.param)->name();
            if (c.dst.arrayindex >= 0)
                out << '[' << c.dst.arrayindex << ']';
            out << " upconnected from layer " << c.srclayer << ' ';
            const ShaderInstance *up = group[c.srclayer];
            out << "(" << up->layername() << ") ";
            out << "    " << c.src.type.c_str() << ' '
                << up->symbol(c.src.param)->name();
            if (c.src.arrayindex >= 0)
                out << '[' << c.src.arrayindex << ']';
            out << "\n";
        }
    }
    return out.str ();
}