当前位置: 首页>>代码示例>>C++>>正文


C++ ProgramFactory::CreateFromFile方法代码示例

本文整理汇总了C++中ProgramFactory::CreateFromFile方法的典型用法代码示例。如果您正苦于以下问题:C++ ProgramFactory::CreateFromFile方法的具体用法?C++ ProgramFactory::CreateFromFile怎么用?C++ ProgramFactory::CreateFromFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProgramFactory的用法示例。


在下文中一共展示了ProgramFactory::CreateFromFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mNumColumns

GpuMassSpringVolume::GpuMassSpringVolume(ProgramFactory& factory,
        int numColumns, int numRows, int numSlices, float step, float viscosity,
        Environment& environment, bool& created)
    :
    mNumColumns(numColumns),
    mNumRows(numRows),
    mNumSlices(numSlices)
{
    created = false;

    // Create the shaders.
    std::string path = environment.GetPath("RungeKutta.hlsl");
    int const numThreads = 4;
    factory.PushDefines();
    factory.defines.Set("NUM_X_THREADS", numThreads);
    factory.defines.Set("NUM_Y_THREADS", numThreads);
    factory.defines.Set("NUM_Z_THREADS", numThreads);

    for (int i = 0; i < 8; ++i)
    {
        factory.csEntry = "RK4Step";
        factory.csEntry += std::to_string(1 + i/2);
        factory.csEntry += ((i & 1) == 0 ? "a" : "b");
        mRK4Shader[i] = factory.CreateFromFile(path);
        if (!mRK4Shader[i])
        {
            return;
        }
    }

    // The cbuffer is tightly packed.  Only time, halfTime, and fullTime vary.
    mParameters = std::make_shared<ConstantBuffer>(sizeof(SimulationParameters),
                  true);
    SimulationParameters& p = *mParameters->Get<SimulationParameters>();
    p.dimensions[0] = numColumns;
    p.dimensions[1] = numRows;
    p.dimensions[2] = numSlices;
    p.dimensions[3] = numColumns * numRows;
    p.viscosity = viscosity;
    p.time = 0.0f;
    p.delta = step;
    p.halfDelta = p.delta / 2.0f;
    p.sixthDelta = p.delta / 6.0f;
    p.halfTime = p.time + p.halfDelta;
    p.fullTime = p.time + p.delta;

    unsigned int const numParticles = p.dimensions[2] * p.dimensions[3];
    size_t const vecsize = sizeof(Vector3<float>);
    mMass = std::make_shared<StructuredBuffer>(numParticles, sizeof(float));
    mInvMass = std::make_shared<StructuredBuffer>(numParticles,
               sizeof(float));
    mPosition = std::make_shared<StructuredBuffer>(numParticles, vecsize);
    mPosition->SetUsage(Resource::SHADER_OUTPUT);
    mPosition->SetCopyType(Resource::COPY_STAGING_TO_CPU);
    mVelocity = std::make_shared<StructuredBuffer>(numParticles, vecsize);
    mVelocity->SetUsage(Resource::SHADER_OUTPUT);
    mConstantC = std::make_shared<StructuredBuffer>(numParticles,
                 sizeof(float));
    mLengthC = std::make_shared<StructuredBuffer>(numParticles,
               sizeof(float));
    mConstantR = std::make_shared<StructuredBuffer>(numParticles,
                 sizeof(float));
    mLengthR = std::make_shared<StructuredBuffer>(numParticles,
               sizeof(float));
    mConstantS = std::make_shared<StructuredBuffer>(numParticles,
                 sizeof(float));
    mLengthS = std::make_shared<StructuredBuffer>(numParticles,
               sizeof(float));

    mPTmp = std::make_shared<StructuredBuffer>(numParticles, vecsize, true);
    mPTmp->SetUsage(Resource::SHADER_OUTPUT);
    mPTmp->SetCopyType(Resource::COPY_STAGING_TO_CPU);
    mPAllTmp = std::make_shared<StructuredBuffer>(numParticles, 4 * vecsize,
               true);
    mPAllTmp->SetUsage(Resource::SHADER_OUTPUT);
    mPAllTmp->SetCopyType(Resource::COPY_STAGING_TO_CPU);
    mVTmp = std::make_shared<StructuredBuffer>(numParticles, vecsize, true);
    mVTmp->SetUsage(Resource::SHADER_OUTPUT);
    mVTmp->SetCopyType(Resource::COPY_STAGING_TO_CPU);
    mVAllTmp = std::make_shared<StructuredBuffer>(numParticles, 4 * vecsize,
               true);
    mVAllTmp->SetUsage(Resource::SHADER_OUTPUT);
    mVAllTmp->SetCopyType(Resource::COPY_STAGING_TO_CPU);

    mNumXGroups = p.dimensions[0] / numThreads;
    mNumYGroups = p.dimensions[1] / numThreads;
    mNumZGroups = p.dimensions[2] / numThreads;

    std::shared_ptr<ComputeShader> cshader = mRK4Shader[0]->GetCShader();
    cshader->Set("SimulationParameters", mParameters);
    cshader->Set("invMass", mInvMass);
    cshader->Set("constantC", mConstantC);
    cshader->Set("lengthC", mLengthC);
    cshader->Set("constantR", mConstantR);
    cshader->Set("lengthR", mLengthR);
    cshader->Set("constantS", mConstantS);
    cshader->Set("lengthS", mLengthS);
    cshader->Set("pAllTmp", mPAllTmp);
    cshader->Set("vAllTmp", mVAllTmp);
    cshader->Set("position", mPosition);
//.........这里部分代码省略.........
开发者ID:yimogod,项目名称:gt_learn,代码行数:101,代码来源:GpuMassSpringVolume.cpp

示例2: mSize

GpuShortestPath::GpuShortestPath(ProgramFactory& factory,
    std::shared_ptr<Texture2> const& weights, Environment const& env,
    bool& created)
    :
    mSize(static_cast<int>(weights->GetWidth()))
{
    created = false;
    mLogSize = Log2OfPowerOfTwo(mSize);

    mDistance = std::make_shared<Texture2>(DF_R32_FLOAT, mSize, mSize);
    mDistance->SetUsage(Resource::SHADER_OUTPUT);
    memset(mDistance->GetData(), 0, mDistance->GetNumBytes());

    mPrevious = std::make_shared<Texture2>(DF_R32G32_SINT, mSize, mSize);
    mPrevious->SetUsage(Resource::SHADER_OUTPUT);
    mPrevious->SetCopyType(Resource::COPY_STAGING_TO_CPU);

    mSegment = std::make_shared<ConstantBuffer>(3 * sizeof(int), true);

    factory.PushDefines();
    factory.defines.Set("ISIZE", mSize);
    mInitializeDiagToRow = factory.CreateFromFile(
        env.GetPath("InitializeDiagToRow.hlsl"));
    if (!mInitializeDiagToRow)
    {
        return;
    }
    std::shared_ptr<ComputeShader> cshader =
        mInitializeDiagToRow->GetCShader();
    cshader->Set("weights", weights);
    cshader->Set("previous", mPrevious);
    cshader->Set("sum", mDistance);

    mInitializeDiagToCol = factory.CreateFromFile(
        env.GetPath("InitializeDiagToCol.hlsl"));
    if (!mInitializeDiagToCol)
    {
        return;
    }
    cshader = mInitializeDiagToCol->GetCShader();
    cshader->Set("weights", weights);
    cshader->Set("previous", mPrevious);
    cshader->Set("sum", mDistance);

    mPartialSumDiagToRow.resize(mLogSize);
    mPartialSumDiagToCol.resize(mLogSize);
    for (int i = 0; i < mLogSize; ++i)
    {
        factory.defines.Set("LOGN", mLogSize);
        factory.defines.Set("P", i + 1);
        mPartialSumDiagToRow[i] = factory.CreateFromFile(
            env.GetPath("PartialSumsDiagToRow.hlsl"));
        if (!mPartialSumDiagToRow[i])
        {
            return;
        }
        mPartialSumDiagToRow[i]->GetCShader()->Set("sum", mDistance);

        mPartialSumDiagToCol[i] = factory.CreateFromFile(
            env.GetPath("PartialSumsDiagToCol.hlsl"));
        if (!mPartialSumDiagToCol[i])
        {
            return;
        }
        mPartialSumDiagToCol[i]->GetCShader()->Set("sum", mDistance);
    }

    mUpdate = factory.CreateFromFile(env.GetPath("UpdateShader.hlsl"));
    if (!mUpdate)
    {
        return;
    }
    cshader = mUpdate->GetCShader();
    cshader->Set("Segment", mSegment);
    cshader->Set("weights", weights);
    cshader->Set("distance", mDistance);
    cshader->Set("previous", mPrevious);

    factory.PopDefines();
    created = true;
}
开发者ID:c0g,项目名称:FaceWarpApp,代码行数:81,代码来源:GpuShortestPath.cpp


注:本文中的ProgramFactory::CreateFromFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。